1 /* Hitachi SH specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Contributed by Ian Lance Taylor, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 static bfd_reloc_status_type sh_elf_reloc
30 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 bfd_boolean sh_elf_set_private_flags
38 PARAMS ((bfd
*, flagword
));
39 static bfd_boolean sh_elf_copy_private_data
40 PARAMS ((bfd
*, bfd
*));
41 static bfd_boolean sh_elf_merge_private_data
42 PARAMS ((bfd
*, bfd
*));
43 static bfd_boolean sh_elf_set_mach_from_flags
45 static bfd_boolean sh_elf_relax_section
46 PARAMS ((bfd
*, asection
*, struct bfd_link_info
*, bfd_boolean
*));
47 static bfd_boolean sh_elf_relax_delete_bytes
48 PARAMS ((bfd
*, asection
*, bfd_vma
, int));
49 static bfd_boolean sh_elf_align_loads
50 PARAMS ((bfd
*, asection
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_boolean
*));
51 static bfd_boolean sh_elf_swap_insns
52 PARAMS ((bfd
*, asection
*, PTR
, bfd_byte
*, bfd_vma
));
53 static bfd_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
*, bfd_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 bfd_boolean sh_elf_mkobject
66 static bfd_boolean sh_elf_object_p
68 static bfd_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 bfd_boolean sh_elf_adjust_dynamic_symbol
76 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
77 static bfd_boolean sh_elf_size_dynamic_sections
78 PARAMS ((bfd
*, struct bfd_link_info
*));
79 static bfd_boolean sh_elf_finish_dynamic_symbol
80 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
82 static bfd_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 bfd_boolean create_got_section
88 PARAMS ((bfd
*, struct bfd_link_info
*));
89 static bfd_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 bfd_boolean sh_elf_gc_sweep_hook
97 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
98 const Elf_Internal_Rela
*));
99 static bfd_boolean allocate_dynrelocs
100 PARAMS ((struct elf_link_hash_entry
*, PTR
));
101 static bfd_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 *));
108 static bfd_boolean elf32_shlin_grok_prstatus
109 PARAMS ((bfd
*abfd
, Elf_Internal_Note
*note
));
110 static bfd_boolean elf32_shlin_grok_psinfo
111 PARAMS ((bfd
*abfd
, Elf_Internal_Note
*note
));
113 /* The name of the dynamic interpreter. This is put in the .interp
116 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
118 static reloc_howto_type sh_elf_howto_table
[] =
121 HOWTO (R_SH_NONE
, /* type */
123 0, /* size (0 = byte, 1 = short, 2 = long) */
125 FALSE
, /* pc_relative */
127 complain_overflow_dont
, /* complain_on_overflow */
128 sh_elf_ignore_reloc
, /* special_function */
129 "R_SH_NONE", /* name */
130 FALSE
, /* partial_inplace */
133 FALSE
), /* pcrel_offset */
135 /* 32 bit absolute relocation. Setting partial_inplace to TRUE and
136 src_mask to a non-zero value is similar to the COFF toolchain. */
137 HOWTO (R_SH_DIR32
, /* type */
139 2, /* size (0 = byte, 1 = short, 2 = long) */
141 FALSE
, /* pc_relative */
143 complain_overflow_bitfield
, /* complain_on_overflow */
144 sh_elf_reloc
, /* special_function */
145 "R_SH_DIR32", /* name */
146 TRUE
, /* partial_inplace */
147 0xffffffff, /* src_mask */
148 0xffffffff, /* dst_mask */
149 FALSE
), /* pcrel_offset */
151 /* 32 bit PC relative relocation. */
152 HOWTO (R_SH_REL32
, /* type */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
156 TRUE
, /* pc_relative */
158 complain_overflow_signed
, /* complain_on_overflow */
159 sh_elf_ignore_reloc
, /* special_function */
160 "R_SH_REL32", /* name */
161 TRUE
, /* partial_inplace */
162 0xffffffff, /* src_mask */
163 0xffffffff, /* dst_mask */
164 TRUE
), /* pcrel_offset */
166 /* 8 bit PC relative branch divided by 2. */
167 HOWTO (R_SH_DIR8WPN
, /* type */
169 1, /* size (0 = byte, 1 = short, 2 = long) */
171 TRUE
, /* pc_relative */
173 complain_overflow_signed
, /* complain_on_overflow */
174 sh_elf_ignore_reloc
, /* special_function */
175 "R_SH_DIR8WPN", /* name */
176 TRUE
, /* partial_inplace */
179 TRUE
), /* pcrel_offset */
181 /* 12 bit PC relative branch divided by 2. */
182 HOWTO (R_SH_IND12W
, /* type */
184 1, /* size (0 = byte, 1 = short, 2 = long) */
186 TRUE
, /* pc_relative */
188 complain_overflow_signed
, /* complain_on_overflow */
189 sh_elf_reloc
, /* special_function */
190 "R_SH_IND12W", /* name */
191 TRUE
, /* partial_inplace */
192 0xfff, /* src_mask */
193 0xfff, /* dst_mask */
194 TRUE
), /* pcrel_offset */
196 /* 8 bit unsigned PC relative divided by 4. */
197 HOWTO (R_SH_DIR8WPL
, /* type */
199 1, /* size (0 = byte, 1 = short, 2 = long) */
201 TRUE
, /* pc_relative */
203 complain_overflow_unsigned
, /* complain_on_overflow */
204 sh_elf_ignore_reloc
, /* special_function */
205 "R_SH_DIR8WPL", /* name */
206 TRUE
, /* partial_inplace */
209 TRUE
), /* pcrel_offset */
211 /* 8 bit unsigned PC relative divided by 2. */
212 HOWTO (R_SH_DIR8WPZ
, /* type */
214 1, /* size (0 = byte, 1 = short, 2 = long) */
216 TRUE
, /* pc_relative */
218 complain_overflow_unsigned
, /* complain_on_overflow */
219 sh_elf_ignore_reloc
, /* special_function */
220 "R_SH_DIR8WPZ", /* name */
221 TRUE
, /* partial_inplace */
224 TRUE
), /* pcrel_offset */
226 /* 8 bit GBR relative. FIXME: This only makes sense if we have some
227 special symbol for the GBR relative area, and that is not
229 HOWTO (R_SH_DIR8BP
, /* type */
231 1, /* size (0 = byte, 1 = short, 2 = long) */
233 FALSE
, /* pc_relative */
235 complain_overflow_unsigned
, /* complain_on_overflow */
236 sh_elf_ignore_reloc
, /* special_function */
237 "R_SH_DIR8BP", /* name */
238 FALSE
, /* partial_inplace */
241 TRUE
), /* pcrel_offset */
243 /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if
244 we have some special symbol for the GBR relative area, and that
245 is not implemented. */
246 HOWTO (R_SH_DIR8W
, /* type */
248 1, /* size (0 = byte, 1 = short, 2 = long) */
250 FALSE
, /* pc_relative */
252 complain_overflow_unsigned
, /* complain_on_overflow */
253 sh_elf_ignore_reloc
, /* special_function */
254 "R_SH_DIR8W", /* name */
255 FALSE
, /* partial_inplace */
258 TRUE
), /* pcrel_offset */
260 /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if
261 we have some special symbol for the GBR relative area, and that
262 is not implemented. */
263 HOWTO (R_SH_DIR8L
, /* type */
265 1, /* size (0 = byte, 1 = short, 2 = long) */
267 FALSE
, /* pc_relative */
269 complain_overflow_unsigned
, /* complain_on_overflow */
270 sh_elf_ignore_reloc
, /* special_function */
271 "R_SH_DIR8L", /* name */
272 FALSE
, /* partial_inplace */
275 TRUE
), /* pcrel_offset */
293 /* The remaining relocs are a GNU extension used for relaxing. The
294 final pass of the linker never needs to do anything with any of
295 these relocs. Any required operations are handled by the
298 /* A 16 bit switch table entry. This is generated for an expression
299 such as ``.word L1 - L2''. The offset holds the difference
300 between the reloc address and L2. */
301 HOWTO (R_SH_SWITCH16
, /* type */
303 1, /* size (0 = byte, 1 = short, 2 = long) */
305 FALSE
, /* pc_relative */
307 complain_overflow_unsigned
, /* complain_on_overflow */
308 sh_elf_ignore_reloc
, /* special_function */
309 "R_SH_SWITCH16", /* name */
310 FALSE
, /* partial_inplace */
313 TRUE
), /* pcrel_offset */
315 /* A 32 bit switch table entry. This is generated for an expression
316 such as ``.long L1 - L2''. The offset holds the difference
317 between the reloc address and L2. */
318 HOWTO (R_SH_SWITCH32
, /* type */
320 2, /* size (0 = byte, 1 = short, 2 = long) */
322 FALSE
, /* pc_relative */
324 complain_overflow_unsigned
, /* complain_on_overflow */
325 sh_elf_ignore_reloc
, /* special_function */
326 "R_SH_SWITCH32", /* name */
327 FALSE
, /* partial_inplace */
330 TRUE
), /* pcrel_offset */
332 /* Indicates a .uses pseudo-op. The compiler will generate .uses
333 pseudo-ops when it finds a function call which can be relaxed.
334 The offset field holds the PC relative offset to the instruction
335 which loads the register used in the function call. */
336 HOWTO (R_SH_USES
, /* type */
338 1, /* size (0 = byte, 1 = short, 2 = long) */
340 FALSE
, /* pc_relative */
342 complain_overflow_unsigned
, /* complain_on_overflow */
343 sh_elf_ignore_reloc
, /* special_function */
344 "R_SH_USES", /* name */
345 FALSE
, /* partial_inplace */
348 TRUE
), /* pcrel_offset */
350 /* The assembler will generate this reloc for addresses referred to
351 by the register loads associated with USES relocs. The offset
352 field holds the number of times the address is referenced in the
354 HOWTO (R_SH_COUNT
, /* type */
356 1, /* size (0 = byte, 1 = short, 2 = long) */
358 FALSE
, /* pc_relative */
360 complain_overflow_unsigned
, /* complain_on_overflow */
361 sh_elf_ignore_reloc
, /* special_function */
362 "R_SH_COUNT", /* name */
363 FALSE
, /* partial_inplace */
366 TRUE
), /* pcrel_offset */
368 /* Indicates an alignment statement. The offset field is the power
369 of 2 to which subsequent portions of the object file must be
371 HOWTO (R_SH_ALIGN
, /* type */
373 1, /* size (0 = byte, 1 = short, 2 = long) */
375 FALSE
, /* pc_relative */
377 complain_overflow_unsigned
, /* complain_on_overflow */
378 sh_elf_ignore_reloc
, /* special_function */
379 "R_SH_ALIGN", /* name */
380 FALSE
, /* partial_inplace */
383 TRUE
), /* pcrel_offset */
385 /* The assembler will generate this reloc before a block of
386 instructions. A section should be processed as assumining it
387 contains data, unless this reloc is seen. */
388 HOWTO (R_SH_CODE
, /* type */
390 1, /* size (0 = byte, 1 = short, 2 = long) */
392 FALSE
, /* pc_relative */
394 complain_overflow_unsigned
, /* complain_on_overflow */
395 sh_elf_ignore_reloc
, /* special_function */
396 "R_SH_CODE", /* name */
397 FALSE
, /* partial_inplace */
400 TRUE
), /* pcrel_offset */
402 /* The assembler will generate this reloc after a block of
403 instructions when it sees data that is not instructions. */
404 HOWTO (R_SH_DATA
, /* type */
406 1, /* size (0 = byte, 1 = short, 2 = long) */
408 FALSE
, /* pc_relative */
410 complain_overflow_unsigned
, /* complain_on_overflow */
411 sh_elf_ignore_reloc
, /* special_function */
412 "R_SH_DATA", /* name */
413 FALSE
, /* partial_inplace */
416 TRUE
), /* pcrel_offset */
418 /* The assembler generates this reloc for each label within a block
419 of instructions. This permits the linker to avoid swapping
420 instructions which are the targets of branches. */
421 HOWTO (R_SH_LABEL
, /* type */
423 1, /* size (0 = byte, 1 = short, 2 = long) */
425 FALSE
, /* pc_relative */
427 complain_overflow_unsigned
, /* complain_on_overflow */
428 sh_elf_ignore_reloc
, /* special_function */
429 "R_SH_LABEL", /* name */
430 FALSE
, /* partial_inplace */
433 TRUE
), /* pcrel_offset */
435 /* An 8 bit switch table entry. This is generated for an expression
436 such as ``.word L1 - L2''. The offset holds the difference
437 between the reloc address and L2. */
438 HOWTO (R_SH_SWITCH8
, /* type */
440 0, /* size (0 = byte, 1 = short, 2 = long) */
442 FALSE
, /* pc_relative */
444 complain_overflow_unsigned
, /* complain_on_overflow */
445 sh_elf_ignore_reloc
, /* special_function */
446 "R_SH_SWITCH8", /* name */
447 FALSE
, /* partial_inplace */
450 TRUE
), /* pcrel_offset */
452 /* GNU extension to record C++ vtable hierarchy */
453 HOWTO (R_SH_GNU_VTINHERIT
, /* type */
455 2, /* size (0 = byte, 1 = short, 2 = long) */
457 FALSE
, /* pc_relative */
459 complain_overflow_dont
, /* complain_on_overflow */
460 NULL
, /* special_function */
461 "R_SH_GNU_VTINHERIT", /* name */
462 FALSE
, /* partial_inplace */
465 FALSE
), /* pcrel_offset */
467 /* GNU extension to record C++ vtable member usage */
468 HOWTO (R_SH_GNU_VTENTRY
, /* type */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
472 FALSE
, /* pc_relative */
474 complain_overflow_dont
, /* complain_on_overflow */
475 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
476 "R_SH_GNU_VTENTRY", /* name */
477 FALSE
, /* partial_inplace */
480 FALSE
), /* pcrel_offset */
482 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
483 HOWTO (R_SH_LOOP_START
, /* type */
485 1, /* size (0 = byte, 1 = short, 2 = long) */
487 FALSE
, /* pc_relative */
489 complain_overflow_signed
, /* complain_on_overflow */
490 sh_elf_ignore_reloc
, /* special_function */
491 "R_SH_LOOP_START", /* name */
492 TRUE
, /* partial_inplace */
495 TRUE
), /* pcrel_offset */
497 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
498 HOWTO (R_SH_LOOP_END
, /* type */
500 1, /* size (0 = byte, 1 = short, 2 = long) */
502 FALSE
, /* pc_relative */
504 complain_overflow_signed
, /* complain_on_overflow */
505 sh_elf_ignore_reloc
, /* special_function */
506 "R_SH_LOOP_END", /* name */
507 TRUE
, /* partial_inplace */
510 TRUE
), /* pcrel_offset */
520 #ifdef INCLUDE_SHMEDIA
521 /* Used in SHLLI.L and SHLRI.L. */
522 HOWTO (R_SH_DIR5U
, /* type */
524 2, /* size (0 = byte, 1 = short, 2 = long) */
526 FALSE
, /* pc_relative */
528 complain_overflow_unsigned
, /* complain_on_overflow */
529 bfd_elf_generic_reloc
, /* special_function */
530 "R_SH_DIR5U", /* name */
531 FALSE
, /* partial_inplace */
533 0xfc00, /* dst_mask */
534 FALSE
), /* pcrel_offset */
536 /* Used in SHARI, SHLLI et al. */
537 HOWTO (R_SH_DIR6U
, /* type */
539 2, /* size (0 = byte, 1 = short, 2 = long) */
541 FALSE
, /* pc_relative */
543 complain_overflow_unsigned
, /* complain_on_overflow */
544 bfd_elf_generic_reloc
, /* special_function */
545 "R_SH_DIR6U", /* name */
546 FALSE
, /* partial_inplace */
548 0xfc00, /* dst_mask */
549 FALSE
), /* pcrel_offset */
551 /* Used in BxxI, LDHI.L et al. */
552 HOWTO (R_SH_DIR6S
, /* type */
554 2, /* size (0 = byte, 1 = short, 2 = long) */
556 FALSE
, /* pc_relative */
558 complain_overflow_signed
, /* complain_on_overflow */
559 bfd_elf_generic_reloc
, /* special_function */
560 "R_SH_DIR6S", /* name */
561 FALSE
, /* partial_inplace */
563 0xfc00, /* dst_mask */
564 FALSE
), /* pcrel_offset */
566 /* Used in ADDI, ANDI et al. */
567 HOWTO (R_SH_DIR10S
, /* type */
569 2, /* size (0 = byte, 1 = short, 2 = long) */
571 FALSE
, /* pc_relative */
573 complain_overflow_signed
, /* complain_on_overflow */
574 bfd_elf_generic_reloc
, /* special_function */
575 "R_SH_DIR10S", /* name */
576 FALSE
, /* partial_inplace */
578 0xffc00, /* dst_mask */
579 FALSE
), /* pcrel_offset */
581 /* Used in LD.UW, ST.W et al. */
582 HOWTO (R_SH_DIR10SW
, /* type */
584 2, /* size (0 = byte, 1 = short, 2 = long) */
586 FALSE
, /* pc_relative */
588 complain_overflow_signed
, /* complain_on_overflow */
589 bfd_elf_generic_reloc
, /* special_function */
590 "R_SH_DIR10SW", /* name */
591 FALSE
, /* partial_inplace */
593 0xffc00, /* dst_mask */
594 FALSE
), /* pcrel_offset */
596 /* Used in LD.L, FLD.S et al. */
597 HOWTO (R_SH_DIR10SL
, /* type */
599 2, /* size (0 = byte, 1 = short, 2 = long) */
601 FALSE
, /* pc_relative */
603 complain_overflow_signed
, /* complain_on_overflow */
604 bfd_elf_generic_reloc
, /* special_function */
605 "R_SH_DIR10SL", /* name */
606 FALSE
, /* partial_inplace */
608 0xffc00, /* dst_mask */
609 FALSE
), /* pcrel_offset */
611 /* Used in FLD.D, FST.P et al. */
612 HOWTO (R_SH_DIR10SQ
, /* type */
614 2, /* size (0 = byte, 1 = short, 2 = long) */
616 FALSE
, /* pc_relative */
618 complain_overflow_signed
, /* complain_on_overflow */
619 bfd_elf_generic_reloc
, /* special_function */
620 "R_SH_DIR10SQ", /* name */
621 FALSE
, /* partial_inplace */
623 0xffc00, /* dst_mask */
624 FALSE
), /* pcrel_offset */
729 HOWTO (R_SH_TLS_GD_32
, /* type */
731 2, /* size (0 = byte, 1 = short, 2 = long) */
733 FALSE
, /* pc_relative */
735 complain_overflow_bitfield
, /* complain_on_overflow */
736 bfd_elf_generic_reloc
, /* */
737 "R_SH_TLS_GD_32", /* name */
738 TRUE
, /* partial_inplace */
739 0xffffffff, /* src_mask */
740 0xffffffff, /* dst_mask */
741 FALSE
), /* pcrel_offset */
743 HOWTO (R_SH_TLS_LD_32
, /* type */
745 2, /* size (0 = byte, 1 = short, 2 = long) */
747 FALSE
, /* pc_relative */
749 complain_overflow_bitfield
, /* complain_on_overflow */
750 bfd_elf_generic_reloc
, /* */
751 "R_SH_TLS_LD_32", /* name */
752 TRUE
, /* partial_inplace */
753 0xffffffff, /* src_mask */
754 0xffffffff, /* dst_mask */
755 FALSE
), /* pcrel_offset */
757 HOWTO (R_SH_TLS_LDO_32
, /* type */
759 2, /* size (0 = byte, 1 = short, 2 = long) */
761 FALSE
, /* pc_relative */
763 complain_overflow_bitfield
, /* complain_on_overflow */
764 bfd_elf_generic_reloc
, /* */
765 "R_SH_TLS_LDO_32", /* name */
766 TRUE
, /* partial_inplace */
767 0xffffffff, /* src_mask */
768 0xffffffff, /* dst_mask */
769 FALSE
), /* pcrel_offset */
771 HOWTO (R_SH_TLS_IE_32
, /* type */
773 2, /* size (0 = byte, 1 = short, 2 = long) */
775 FALSE
, /* pc_relative */
777 complain_overflow_bitfield
, /* complain_on_overflow */
778 bfd_elf_generic_reloc
, /* */
779 "R_SH_TLS_IE_32", /* name */
780 TRUE
, /* partial_inplace */
781 0xffffffff, /* src_mask */
782 0xffffffff, /* dst_mask */
783 FALSE
), /* pcrel_offset */
785 HOWTO (R_SH_TLS_LE_32
, /* type */
787 2, /* size (0 = byte, 1 = short, 2 = long) */
789 FALSE
, /* pc_relative */
791 complain_overflow_bitfield
, /* complain_on_overflow */
792 bfd_elf_generic_reloc
, /* */
793 "R_SH_TLS_LE_32", /* name */
794 TRUE
, /* partial_inplace */
795 0xffffffff, /* src_mask */
796 0xffffffff, /* dst_mask */
797 FALSE
), /* pcrel_offset */
799 HOWTO (R_SH_TLS_DTPMOD32
, /* type */
801 2, /* size (0 = byte, 1 = short, 2 = long) */
803 FALSE
, /* pc_relative */
805 complain_overflow_bitfield
, /* complain_on_overflow */
806 bfd_elf_generic_reloc
, /* */
807 "R_SH_TLS_DTPMOD32", /* name */
808 TRUE
, /* partial_inplace */
809 0xffffffff, /* src_mask */
810 0xffffffff, /* dst_mask */
811 FALSE
), /* pcrel_offset */
813 HOWTO (R_SH_TLS_DTPOFF32
, /* type */
815 2, /* size (0 = byte, 1 = short, 2 = long) */
817 FALSE
, /* pc_relative */
819 complain_overflow_bitfield
, /* complain_on_overflow */
820 bfd_elf_generic_reloc
, /* */
821 "R_SH_TLS_DTPOFF32", /* name */
822 TRUE
, /* partial_inplace */
823 0xffffffff, /* src_mask */
824 0xffffffff, /* dst_mask */
825 FALSE
), /* pcrel_offset */
827 HOWTO (R_SH_TLS_TPOFF32
, /* type */
829 2, /* size (0 = byte, 1 = short, 2 = long) */
831 FALSE
, /* pc_relative */
833 complain_overflow_bitfield
, /* complain_on_overflow */
834 bfd_elf_generic_reloc
, /* */
835 "R_SH_TLS_TPOFF32", /* name */
836 TRUE
, /* partial_inplace */
837 0xffffffff, /* src_mask */
838 0xffffffff, /* dst_mask */
839 FALSE
), /* pcrel_offset */
850 HOWTO (R_SH_GOT32
, /* type */
852 2, /* size (0 = byte, 1 = short, 2 = long) */
854 FALSE
, /* pc_relative */
856 complain_overflow_bitfield
, /* complain_on_overflow */
857 bfd_elf_generic_reloc
, /* */
858 "R_SH_GOT32", /* name */
859 TRUE
, /* partial_inplace */
860 0xffffffff, /* src_mask */
861 0xffffffff, /* dst_mask */
862 FALSE
), /* pcrel_offset */
864 HOWTO (R_SH_PLT32
, /* type */
866 2, /* size (0 = byte, 1 = short, 2 = long) */
868 TRUE
, /* pc_relative */
870 complain_overflow_bitfield
, /* complain_on_overflow */
871 bfd_elf_generic_reloc
, /* */
872 "R_SH_PLT32", /* name */
873 TRUE
, /* partial_inplace */
874 0xffffffff, /* src_mask */
875 0xffffffff, /* dst_mask */
876 TRUE
), /* pcrel_offset */
878 HOWTO (R_SH_COPY
, /* type */
880 2, /* size (0 = byte, 1 = short, 2 = long) */
882 FALSE
, /* pc_relative */
884 complain_overflow_bitfield
, /* complain_on_overflow */
885 bfd_elf_generic_reloc
, /* */
886 "R_SH_COPY", /* name */
887 TRUE
, /* partial_inplace */
888 0xffffffff, /* src_mask */
889 0xffffffff, /* dst_mask */
890 FALSE
), /* pcrel_offset */
892 HOWTO (R_SH_GLOB_DAT
, /* type */
894 2, /* size (0 = byte, 1 = short, 2 = long) */
896 FALSE
, /* pc_relative */
898 complain_overflow_bitfield
, /* complain_on_overflow */
899 bfd_elf_generic_reloc
, /* */
900 "R_SH_GLOB_DAT", /* name */
901 TRUE
, /* partial_inplace */
902 0xffffffff, /* src_mask */
903 0xffffffff, /* dst_mask */
904 FALSE
), /* pcrel_offset */
906 HOWTO (R_SH_JMP_SLOT
, /* type */
908 2, /* size (0 = byte, 1 = short, 2 = long) */
910 FALSE
, /* pc_relative */
912 complain_overflow_bitfield
, /* complain_on_overflow */
913 bfd_elf_generic_reloc
, /* */
914 "R_SH_JMP_SLOT", /* name */
915 TRUE
, /* partial_inplace */
916 0xffffffff, /* src_mask */
917 0xffffffff, /* dst_mask */
918 FALSE
), /* pcrel_offset */
920 HOWTO (R_SH_RELATIVE
, /* type */
922 2, /* size (0 = byte, 1 = short, 2 = long) */
924 FALSE
, /* pc_relative */
926 complain_overflow_bitfield
, /* complain_on_overflow */
927 bfd_elf_generic_reloc
, /* */
928 "R_SH_RELATIVE", /* name */
929 TRUE
, /* partial_inplace */
930 0xffffffff, /* src_mask */
931 0xffffffff, /* dst_mask */
932 FALSE
), /* pcrel_offset */
934 HOWTO (R_SH_GOTOFF
, /* type */
936 2, /* size (0 = byte, 1 = short, 2 = long) */
938 FALSE
, /* pc_relative */
940 complain_overflow_bitfield
, /* complain_on_overflow */
941 bfd_elf_generic_reloc
, /* */
942 "R_SH_GOTOFF", /* name */
943 TRUE
, /* partial_inplace */
944 0xffffffff, /* src_mask */
945 0xffffffff, /* dst_mask */
946 FALSE
), /* pcrel_offset */
948 HOWTO (R_SH_GOTPC
, /* type */
950 2, /* size (0 = byte, 1 = short, 2 = long) */
952 TRUE
, /* pc_relative */
954 complain_overflow_bitfield
, /* complain_on_overflow */
955 bfd_elf_generic_reloc
, /* */
956 "R_SH_GOTPC", /* name */
957 TRUE
, /* partial_inplace */
958 0xffffffff, /* src_mask */
959 0xffffffff, /* dst_mask */
960 TRUE
), /* pcrel_offset */
962 HOWTO (R_SH_GOTPLT32
, /* type */
964 2, /* size (0 = byte, 1 = short, 2 = long) */
966 FALSE
, /* pc_relative */
968 complain_overflow_bitfield
, /* complain_on_overflow */
969 bfd_elf_generic_reloc
, /* */
970 "R_SH_GOTPLT32", /* name */
971 FALSE
, /* partial_inplace */
972 0xffffffff, /* src_mask */
973 0xffffffff, /* dst_mask */
974 FALSE
), /* pcrel_offset */
976 #ifdef INCLUDE_SHMEDIA
977 /* Used in MOVI and SHORI (x & 65536). */
978 HOWTO (R_SH_GOT_LOW16
, /* type */
980 2, /* size (0 = byte, 1 = short, 2 = long) */
982 FALSE
, /* pc_relative */
984 complain_overflow_dont
, /* complain_on_overflow */
985 bfd_elf_generic_reloc
, /* special_function */
986 "R_SH_GOT_LOW16", /* name */
987 FALSE
, /* partial_inplace */
989 0x3fffc00, /* dst_mask */
990 FALSE
), /* pcrel_offset */
992 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
993 HOWTO (R_SH_GOT_MEDLOW16
, /* type */
995 2, /* size (0 = byte, 1 = short, 2 = long) */
997 FALSE
, /* pc_relative */
999 complain_overflow_dont
, /* complain_on_overflow */
1000 bfd_elf_generic_reloc
, /* special_function */
1001 "R_SH_GOT_MEDLOW16", /* name */
1002 FALSE
, /* partial_inplace */
1004 0x3fffc00, /* dst_mask */
1005 FALSE
), /* pcrel_offset */
1007 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1008 HOWTO (R_SH_GOT_MEDHI16
, /* type */
1009 32, /* rightshift */
1010 2, /* size (0 = byte, 1 = short, 2 = long) */
1012 FALSE
, /* pc_relative */
1014 complain_overflow_dont
, /* complain_on_overflow */
1015 bfd_elf_generic_reloc
, /* special_function */
1016 "R_SH_GOT_MEDHI16", /* name */
1017 FALSE
, /* partial_inplace */
1019 0x3fffc00, /* dst_mask */
1020 FALSE
), /* pcrel_offset */
1022 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1023 HOWTO (R_SH_GOT_HI16
, /* type */
1024 48, /* rightshift */
1025 2, /* size (0 = byte, 1 = short, 2 = long) */
1027 FALSE
, /* pc_relative */
1029 complain_overflow_dont
, /* complain_on_overflow */
1030 bfd_elf_generic_reloc
, /* special_function */
1031 "R_SH_GOT_HI16", /* name */
1032 FALSE
, /* partial_inplace */
1034 0x3fffc00, /* dst_mask */
1035 FALSE
), /* pcrel_offset */
1037 /* Used in MOVI and SHORI (x & 65536). */
1038 HOWTO (R_SH_GOTPLT_LOW16
, /* type */
1040 2, /* size (0 = byte, 1 = short, 2 = long) */
1042 FALSE
, /* pc_relative */
1044 complain_overflow_dont
, /* complain_on_overflow */
1045 bfd_elf_generic_reloc
, /* special_function */
1046 "R_SH_GOTPLT_LOW16", /* name */
1047 FALSE
, /* partial_inplace */
1049 0x3fffc00, /* dst_mask */
1050 FALSE
), /* pcrel_offset */
1052 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1053 HOWTO (R_SH_GOTPLT_MEDLOW16
, /* type */
1054 16, /* rightshift */
1055 2, /* size (0 = byte, 1 = short, 2 = long) */
1057 FALSE
, /* pc_relative */
1059 complain_overflow_dont
, /* complain_on_overflow */
1060 bfd_elf_generic_reloc
, /* special_function */
1061 "R_SH_GOTPLT_MEDLOW16", /* name */
1062 FALSE
, /* partial_inplace */
1064 0x3fffc00, /* dst_mask */
1065 FALSE
), /* pcrel_offset */
1067 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1068 HOWTO (R_SH_GOTPLT_MEDHI16
, /* type */
1069 32, /* rightshift */
1070 2, /* size (0 = byte, 1 = short, 2 = long) */
1072 FALSE
, /* pc_relative */
1074 complain_overflow_dont
, /* complain_on_overflow */
1075 bfd_elf_generic_reloc
, /* special_function */
1076 "R_SH_GOTPLT_MEDHI16", /* name */
1077 FALSE
, /* partial_inplace */
1079 0x3fffc00, /* dst_mask */
1080 FALSE
), /* pcrel_offset */
1082 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1083 HOWTO (R_SH_GOTPLT_HI16
, /* type */
1084 48, /* rightshift */
1085 2, /* size (0 = byte, 1 = short, 2 = long) */
1087 FALSE
, /* pc_relative */
1089 complain_overflow_dont
, /* complain_on_overflow */
1090 bfd_elf_generic_reloc
, /* special_function */
1091 "R_SH_GOTPLT_HI16", /* name */
1092 FALSE
, /* partial_inplace */
1094 0x3fffc00, /* dst_mask */
1095 FALSE
), /* pcrel_offset */
1097 /* Used in MOVI and SHORI (x & 65536). */
1098 HOWTO (R_SH_PLT_LOW16
, /* type */
1100 2, /* size (0 = byte, 1 = short, 2 = long) */
1102 TRUE
, /* pc_relative */
1104 complain_overflow_dont
, /* complain_on_overflow */
1105 bfd_elf_generic_reloc
, /* special_function */
1106 "R_SH_PLT_LOW16", /* name */
1107 FALSE
, /* partial_inplace */
1109 0x3fffc00, /* dst_mask */
1110 TRUE
), /* pcrel_offset */
1112 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1113 HOWTO (R_SH_PLT_MEDLOW16
, /* type */
1114 16, /* rightshift */
1115 2, /* size (0 = byte, 1 = short, 2 = long) */
1117 TRUE
, /* pc_relative */
1119 complain_overflow_dont
, /* complain_on_overflow */
1120 bfd_elf_generic_reloc
, /* special_function */
1121 "R_SH_PLT_MEDLOW16", /* name */
1122 FALSE
, /* partial_inplace */
1124 0x3fffc00, /* dst_mask */
1125 TRUE
), /* pcrel_offset */
1127 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1128 HOWTO (R_SH_PLT_MEDHI16
, /* type */
1129 32, /* rightshift */
1130 2, /* size (0 = byte, 1 = short, 2 = long) */
1132 TRUE
, /* pc_relative */
1134 complain_overflow_dont
, /* complain_on_overflow */
1135 bfd_elf_generic_reloc
, /* special_function */
1136 "R_SH_PLT_MEDHI16", /* name */
1137 FALSE
, /* partial_inplace */
1139 0x3fffc00, /* dst_mask */
1140 TRUE
), /* pcrel_offset */
1142 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1143 HOWTO (R_SH_PLT_HI16
, /* type */
1144 48, /* rightshift */
1145 2, /* size (0 = byte, 1 = short, 2 = long) */
1147 TRUE
, /* pc_relative */
1149 complain_overflow_dont
, /* complain_on_overflow */
1150 bfd_elf_generic_reloc
, /* special_function */
1151 "R_SH_PLT_HI16", /* name */
1152 FALSE
, /* partial_inplace */
1154 0x3fffc00, /* dst_mask */
1155 TRUE
), /* pcrel_offset */
1157 /* Used in MOVI and SHORI (x & 65536). */
1158 HOWTO (R_SH_GOTOFF_LOW16
, /* type */
1160 2, /* size (0 = byte, 1 = short, 2 = long) */
1162 FALSE
, /* pc_relative */
1164 complain_overflow_dont
, /* complain_on_overflow */
1165 bfd_elf_generic_reloc
, /* special_function */
1166 "R_SH_GOTOFF_LOW16", /* name */
1167 FALSE
, /* partial_inplace */
1169 0x3fffc00, /* dst_mask */
1170 FALSE
), /* pcrel_offset */
1172 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1173 HOWTO (R_SH_GOTOFF_MEDLOW16
, /* type */
1174 16, /* rightshift */
1175 2, /* size (0 = byte, 1 = short, 2 = long) */
1177 FALSE
, /* pc_relative */
1179 complain_overflow_dont
, /* complain_on_overflow */
1180 bfd_elf_generic_reloc
, /* special_function */
1181 "R_SH_GOTOFF_MEDLOW16", /* name */
1182 FALSE
, /* partial_inplace */
1184 0x3fffc00, /* dst_mask */
1185 FALSE
), /* pcrel_offset */
1187 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1188 HOWTO (R_SH_GOTOFF_MEDHI16
, /* type */
1189 32, /* rightshift */
1190 2, /* size (0 = byte, 1 = short, 2 = long) */
1192 FALSE
, /* pc_relative */
1194 complain_overflow_dont
, /* complain_on_overflow */
1195 bfd_elf_generic_reloc
, /* special_function */
1196 "R_SH_GOTOFF_MEDHI16", /* name */
1197 FALSE
, /* partial_inplace */
1199 0x3fffc00, /* dst_mask */
1200 FALSE
), /* pcrel_offset */
1202 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1203 HOWTO (R_SH_GOTOFF_HI16
, /* type */
1204 48, /* rightshift */
1205 2, /* size (0 = byte, 1 = short, 2 = long) */
1207 FALSE
, /* pc_relative */
1209 complain_overflow_dont
, /* complain_on_overflow */
1210 bfd_elf_generic_reloc
, /* special_function */
1211 "R_SH_GOTOFF_HI16", /* name */
1212 FALSE
, /* partial_inplace */
1214 0x3fffc00, /* dst_mask */
1215 FALSE
), /* pcrel_offset */
1217 /* Used in MOVI and SHORI (x & 65536). */
1218 HOWTO (R_SH_GOTPC_LOW16
, /* type */
1220 2, /* size (0 = byte, 1 = short, 2 = long) */
1222 TRUE
, /* pc_relative */
1224 complain_overflow_dont
, /* complain_on_overflow */
1225 bfd_elf_generic_reloc
, /* special_function */
1226 "R_SH_GOTPC_LOW16", /* name */
1227 FALSE
, /* partial_inplace */
1229 0x3fffc00, /* dst_mask */
1230 TRUE
), /* pcrel_offset */
1232 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1233 HOWTO (R_SH_GOTPC_MEDLOW16
, /* type */
1234 16, /* rightshift */
1235 2, /* size (0 = byte, 1 = short, 2 = long) */
1237 TRUE
, /* pc_relative */
1239 complain_overflow_dont
, /* complain_on_overflow */
1240 bfd_elf_generic_reloc
, /* special_function */
1241 "R_SH_GOTPC_MEDLOW16", /* name */
1242 FALSE
, /* partial_inplace */
1244 0x3fffc00, /* dst_mask */
1245 TRUE
), /* pcrel_offset */
1247 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1248 HOWTO (R_SH_GOTPC_MEDHI16
, /* type */
1249 32, /* rightshift */
1250 2, /* size (0 = byte, 1 = short, 2 = long) */
1252 TRUE
, /* pc_relative */
1254 complain_overflow_dont
, /* complain_on_overflow */
1255 bfd_elf_generic_reloc
, /* special_function */
1256 "R_SH_GOTPC_MEDHI16", /* name */
1257 FALSE
, /* partial_inplace */
1259 0x3fffc00, /* dst_mask */
1260 TRUE
), /* pcrel_offset */
1262 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1263 HOWTO (R_SH_GOTPC_HI16
, /* type */
1264 48, /* rightshift */
1265 2, /* size (0 = byte, 1 = short, 2 = long) */
1267 TRUE
, /* pc_relative */
1269 complain_overflow_dont
, /* complain_on_overflow */
1270 bfd_elf_generic_reloc
, /* special_function */
1271 "R_SH_GOTPC_HI16", /* name */
1272 FALSE
, /* partial_inplace */
1274 0x3fffc00, /* dst_mask */
1275 TRUE
), /* pcrel_offset */
1277 /* Used in LD.L, FLD.S et al. */
1278 HOWTO (R_SH_GOT10BY4
, /* type */
1280 2, /* size (0 = byte, 1 = short, 2 = long) */
1282 FALSE
, /* pc_relative */
1284 complain_overflow_signed
, /* complain_on_overflow */
1285 bfd_elf_generic_reloc
, /* special_function */
1286 "R_SH_GOT10BY4", /* name */
1287 FALSE
, /* partial_inplace */
1289 0xffc00, /* dst_mask */
1290 FALSE
), /* pcrel_offset */
1292 /* Used in LD.L, FLD.S et al. */
1293 HOWTO (R_SH_GOTPLT10BY4
, /* type */
1295 2, /* size (0 = byte, 1 = short, 2 = long) */
1297 FALSE
, /* pc_relative */
1299 complain_overflow_signed
, /* complain_on_overflow */
1300 bfd_elf_generic_reloc
, /* special_function */
1301 "R_SH_GOTPLT10BY4", /* name */
1302 FALSE
, /* partial_inplace */
1304 0xffc00, /* dst_mask */
1305 FALSE
), /* pcrel_offset */
1307 /* Used in FLD.D, FST.P et al. */
1308 HOWTO (R_SH_GOT10BY8
, /* type */
1310 2, /* size (0 = byte, 1 = short, 2 = long) */
1312 FALSE
, /* pc_relative */
1314 complain_overflow_signed
, /* complain_on_overflow */
1315 bfd_elf_generic_reloc
, /* special_function */
1316 "R_SH_GOT10BY8", /* name */
1317 FALSE
, /* partial_inplace */
1319 0xffc00, /* dst_mask */
1320 FALSE
), /* pcrel_offset */
1322 /* Used in FLD.D, FST.P et al. */
1323 HOWTO (R_SH_GOTPLT10BY8
, /* type */
1325 2, /* size (0 = byte, 1 = short, 2 = long) */
1327 FALSE
, /* pc_relative */
1329 complain_overflow_signed
, /* complain_on_overflow */
1330 bfd_elf_generic_reloc
, /* special_function */
1331 "R_SH_GOTPLT10BY8", /* name */
1332 FALSE
, /* partial_inplace */
1334 0xffc00, /* dst_mask */
1335 FALSE
), /* pcrel_offset */
1337 HOWTO (R_SH_COPY64
, /* type */
1339 4, /* size (0 = byte, 1 = short, 2 = long) */
1341 FALSE
, /* pc_relative */
1343 complain_overflow_dont
, /* complain_on_overflow */
1344 bfd_elf_generic_reloc
, /* special_function */
1345 "R_SH_COPY64", /* name */
1346 FALSE
, /* partial_inplace */
1348 ((bfd_vma
) 0) - 1, /* dst_mask */
1349 FALSE
), /* pcrel_offset */
1351 HOWTO (R_SH_GLOB_DAT64
, /* type */
1353 4, /* size (0 = byte, 1 = short, 2 = long) */
1355 FALSE
, /* pc_relative */
1357 complain_overflow_dont
, /* complain_on_overflow */
1358 bfd_elf_generic_reloc
, /* special_function */
1359 "R_SH_GLOB_DAT64", /* name */
1360 FALSE
, /* partial_inplace */
1362 ((bfd_vma
) 0) - 1, /* dst_mask */
1363 FALSE
), /* pcrel_offset */
1365 HOWTO (R_SH_JMP_SLOT64
, /* type */
1367 4, /* size (0 = byte, 1 = short, 2 = long) */
1369 FALSE
, /* pc_relative */
1371 complain_overflow_dont
, /* complain_on_overflow */
1372 bfd_elf_generic_reloc
, /* special_function */
1373 "R_SH_JMP_SLOT64", /* name */
1374 FALSE
, /* partial_inplace */
1376 ((bfd_vma
) 0) - 1, /* dst_mask */
1377 FALSE
), /* pcrel_offset */
1379 HOWTO (R_SH_RELATIVE64
, /* type */
1381 4, /* size (0 = byte, 1 = short, 2 = long) */
1383 FALSE
, /* pc_relative */
1385 complain_overflow_dont
, /* complain_on_overflow */
1386 bfd_elf_generic_reloc
, /* special_function */
1387 "R_SH_RELATIVE64", /* name */
1388 FALSE
, /* partial_inplace */
1390 ((bfd_vma
) 0) - 1, /* dst_mask */
1391 FALSE
), /* pcrel_offset */
1439 /* Relocations for SHmedia code. None of these are partial_inplace or
1440 use the field being relocated (except R_SH_PT_16). */
1442 /* The assembler will generate this reloc before a block of SHmedia
1443 instructions. A section should be processed as assuming it contains
1444 data, unless this reloc is seen. Note that a block of SHcompact
1445 instructions are instead preceded by R_SH_CODE.
1446 This is currently not implemented, but should be used for SHmedia
1447 linker relaxation. */
1448 HOWTO (R_SH_SHMEDIA_CODE
, /* type */
1450 1, /* size (0 = byte, 1 = short, 2 = long) */
1452 FALSE
, /* pc_relative */
1454 complain_overflow_unsigned
, /* complain_on_overflow */
1455 sh_elf_ignore_reloc
, /* special_function */
1456 "R_SH_SHMEDIA_CODE", /* name */
1457 FALSE
, /* partial_inplace */
1460 FALSE
), /* pcrel_offset */
1462 /* The assembler will generate this reloc at a PTA or PTB instruction,
1463 and the linker checks the right type of target, or changes a PTA to a
1464 PTB, if the original insn was PT. */
1465 HOWTO (R_SH_PT_16
, /* type */
1467 2, /* size (0 = byte, 1 = short, 2 = long) */
1469 TRUE
, /* pc_relative */
1471 complain_overflow_signed
, /* complain_on_overflow */
1472 bfd_elf_generic_reloc
, /* special_function */
1473 "R_SH_PT_16", /* name */
1474 FALSE
, /* partial_inplace */
1476 0x3fffc00, /* dst_mask */
1477 TRUE
), /* pcrel_offset */
1479 /* Used in unexpanded MOVI. */
1480 HOWTO (R_SH_IMMS16
, /* type */
1482 2, /* size (0 = byte, 1 = short, 2 = long) */
1484 FALSE
, /* pc_relative */
1486 complain_overflow_signed
, /* complain_on_overflow */
1487 bfd_elf_generic_reloc
, /* special_function */
1488 "R_SH_IMMS16", /* name */
1489 FALSE
, /* partial_inplace */
1491 0x3fffc00, /* dst_mask */
1492 FALSE
), /* pcrel_offset */
1494 /* Used in SHORI. */
1495 HOWTO (R_SH_IMMU16
, /* type */
1497 2, /* size (0 = byte, 1 = short, 2 = long) */
1499 FALSE
, /* pc_relative */
1501 complain_overflow_unsigned
, /* complain_on_overflow */
1502 bfd_elf_generic_reloc
, /* special_function */
1503 "R_SH_IMMU16", /* name */
1504 FALSE
, /* partial_inplace */
1506 0x3fffc00, /* dst_mask */
1507 FALSE
), /* pcrel_offset */
1509 /* Used in MOVI and SHORI (x & 65536). */
1510 HOWTO (R_SH_IMM_LOW16
, /* type */
1512 2, /* size (0 = byte, 1 = short, 2 = long) */
1514 FALSE
, /* pc_relative */
1516 complain_overflow_dont
, /* complain_on_overflow */
1517 bfd_elf_generic_reloc
, /* special_function */
1518 "R_SH_IMM_LOW16", /* name */
1519 FALSE
, /* partial_inplace */
1521 0x3fffc00, /* dst_mask */
1522 FALSE
), /* pcrel_offset */
1524 /* Used in MOVI and SHORI ((x - $) & 65536). */
1525 HOWTO (R_SH_IMM_LOW16_PCREL
, /* type */
1527 2, /* size (0 = byte, 1 = short, 2 = long) */
1529 TRUE
, /* pc_relative */
1531 complain_overflow_dont
, /* complain_on_overflow */
1532 bfd_elf_generic_reloc
, /* special_function */
1533 "R_SH_IMM_LOW16_PCREL", /* name */
1534 FALSE
, /* partial_inplace */
1536 0x3fffc00, /* dst_mask */
1537 TRUE
), /* pcrel_offset */
1539 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1540 HOWTO (R_SH_IMM_MEDLOW16
, /* type */
1541 16, /* rightshift */
1542 2, /* size (0 = byte, 1 = short, 2 = long) */
1544 FALSE
, /* pc_relative */
1546 complain_overflow_dont
, /* complain_on_overflow */
1547 bfd_elf_generic_reloc
, /* special_function */
1548 "R_SH_IMM_MEDLOW16", /* name */
1549 FALSE
, /* partial_inplace */
1551 0x3fffc00, /* dst_mask */
1552 FALSE
), /* pcrel_offset */
1554 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1555 HOWTO (R_SH_IMM_MEDLOW16_PCREL
, /* type */
1556 16, /* rightshift */
1557 2, /* size (0 = byte, 1 = short, 2 = long) */
1559 TRUE
, /* pc_relative */
1561 complain_overflow_dont
, /* complain_on_overflow */
1562 bfd_elf_generic_reloc
, /* special_function */
1563 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1564 FALSE
, /* partial_inplace */
1566 0x3fffc00, /* dst_mask */
1567 TRUE
), /* pcrel_offset */
1569 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1570 HOWTO (R_SH_IMM_MEDHI16
, /* type */
1571 32, /* rightshift */
1572 2, /* size (0 = byte, 1 = short, 2 = long) */
1574 FALSE
, /* pc_relative */
1576 complain_overflow_dont
, /* complain_on_overflow */
1577 bfd_elf_generic_reloc
, /* special_function */
1578 "R_SH_IMM_MEDHI16", /* name */
1579 FALSE
, /* partial_inplace */
1581 0x3fffc00, /* dst_mask */
1582 FALSE
), /* pcrel_offset */
1584 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1585 HOWTO (R_SH_IMM_MEDHI16_PCREL
, /* type */
1586 32, /* rightshift */
1587 2, /* size (0 = byte, 1 = short, 2 = long) */
1589 TRUE
, /* pc_relative */
1591 complain_overflow_dont
, /* complain_on_overflow */
1592 bfd_elf_generic_reloc
, /* special_function */
1593 "R_SH_IMM_MEDHI16_PCREL", /* name */
1594 FALSE
, /* partial_inplace */
1596 0x3fffc00, /* dst_mask */
1597 TRUE
), /* pcrel_offset */
1599 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1600 HOWTO (R_SH_IMM_HI16
, /* type */
1601 48, /* rightshift */
1602 2, /* size (0 = byte, 1 = short, 2 = long) */
1604 FALSE
, /* pc_relative */
1606 complain_overflow_dont
, /* complain_on_overflow */
1607 bfd_elf_generic_reloc
, /* special_function */
1608 "R_SH_IMM_HI16", /* name */
1609 FALSE
, /* partial_inplace */
1611 0x3fffc00, /* dst_mask */
1612 FALSE
), /* pcrel_offset */
1614 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1615 HOWTO (R_SH_IMM_HI16_PCREL
, /* type */
1616 48, /* rightshift */
1617 2, /* size (0 = byte, 1 = short, 2 = long) */
1619 TRUE
, /* pc_relative */
1621 complain_overflow_dont
, /* complain_on_overflow */
1622 bfd_elf_generic_reloc
, /* special_function */
1623 "R_SH_IMM_HI16_PCREL", /* name */
1624 FALSE
, /* partial_inplace */
1626 0x3fffc00, /* dst_mask */
1627 TRUE
), /* pcrel_offset */
1629 /* For the .uaquad pseudo. */
1630 HOWTO (R_SH_64
, /* type */
1632 4, /* size (0 = byte, 1 = short, 2 = long) */
1634 FALSE
, /* pc_relative */
1636 complain_overflow_dont
, /* complain_on_overflow */
1637 bfd_elf_generic_reloc
, /* special_function */
1638 "R_SH_64", /* name */
1639 FALSE
, /* partial_inplace */
1641 ((bfd_vma
) 0) - 1, /* dst_mask */
1642 FALSE
), /* pcrel_offset */
1644 /* For the .uaquad pseudo, (x - $). */
1645 HOWTO (R_SH_64_PCREL
, /* type */
1646 48, /* rightshift */
1647 2, /* size (0 = byte, 1 = short, 2 = long) */
1649 TRUE
, /* pc_relative */
1651 complain_overflow_dont
, /* complain_on_overflow */
1652 bfd_elf_generic_reloc
, /* special_function */
1653 "R_SH_64_PCREL", /* name */
1654 FALSE
, /* partial_inplace */
1656 ((bfd_vma
) 0) - 1, /* dst_mask */
1657 TRUE
), /* pcrel_offset */
1662 static bfd_reloc_status_type
1663 sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
, addr
,
1664 symbol_section
, start
, end
)
1665 int r_type ATTRIBUTE_UNUSED
;
1667 asection
*input_section
;
1670 asection
*symbol_section
;
1673 static bfd_vma last_addr
;
1674 static asection
*last_symbol_section
;
1675 bfd_byte
*start_ptr
, *ptr
, *last_ptr
;
1680 /* Sanity check the address. */
1681 if (addr
> input_section
->_raw_size
)
1682 return bfd_reloc_outofrange
;
1684 /* We require the start and end relocations to be processed consecutively -
1685 although we allow then to be processed forwards or backwards. */
1689 last_symbol_section
= symbol_section
;
1690 return bfd_reloc_ok
;
1692 if (last_addr
!= addr
)
1696 if (! symbol_section
|| last_symbol_section
!= symbol_section
|| end
< start
)
1697 return bfd_reloc_outofrange
;
1699 /* Get the symbol_section contents. */
1700 if (symbol_section
!= input_section
)
1702 if (elf_section_data (symbol_section
)->this_hdr
.contents
!= NULL
)
1703 contents
= elf_section_data (symbol_section
)->this_hdr
.contents
;
1706 contents
= (bfd_byte
*) bfd_malloc (symbol_section
->_raw_size
);
1707 if (contents
== NULL
)
1708 return bfd_reloc_outofrange
;
1709 if (! bfd_get_section_contents (input_bfd
, symbol_section
, contents
,
1711 symbol_section
->_raw_size
))
1714 return bfd_reloc_outofrange
;
1718 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
1719 start_ptr
= contents
+ start
;
1720 for (cum_diff
= -6, ptr
= contents
+ end
; cum_diff
< 0 && ptr
> start_ptr
;)
1722 for (last_ptr
= ptr
, ptr
-= 4; ptr
>= start_ptr
&& IS_PPI (ptr
);)
1725 diff
= (last_ptr
- ptr
) >> 1;
1726 cum_diff
+= diff
& 1;
1729 /* Calculate the start / end values to load into rs / re minus four -
1730 so that will cancel out the four we would otherwise have to add to
1731 addr to get the value to subtract in order to get relative addressing. */
1735 end
= (ptr
+ cum_diff
* 2) - contents
;
1739 bfd_vma start0
= start
- 4;
1741 while (start0
&& IS_PPI (contents
+ start0
))
1743 start0
= start
- 2 - ((start
- start0
) & 2);
1744 start
= start0
- cum_diff
- 2;
1748 if (contents
!= NULL
1749 && elf_section_data (symbol_section
)->this_hdr
.contents
!= contents
)
1752 insn
= bfd_get_16 (input_bfd
, contents
+ addr
);
1754 x
= (insn
& 0x200 ? end
: start
) - addr
;
1755 if (input_section
!= symbol_section
)
1756 x
+= ((symbol_section
->output_section
->vma
+ symbol_section
->output_offset
)
1757 - (input_section
->output_section
->vma
1758 + input_section
->output_offset
));
1760 if (x
< -128 || x
> 127)
1761 return bfd_reloc_overflow
;
1763 x
= (insn
& ~0xff) | (x
& 0xff);
1764 bfd_put_16 (input_bfd
, (bfd_vma
) x
, contents
+ addr
);
1766 return bfd_reloc_ok
;
1769 /* This function is used for normal relocs. This used to be like the COFF
1770 function, and is almost certainly incorrect for other ELF targets. */
1772 static bfd_reloc_status_type
1773 sh_elf_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
1776 arelent
*reloc_entry
;
1779 asection
*input_section
;
1781 char **error_message ATTRIBUTE_UNUSED
;
1785 enum elf_sh_reloc_type r_type
;
1786 bfd_vma addr
= reloc_entry
->address
;
1787 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
1789 r_type
= (enum elf_sh_reloc_type
) reloc_entry
->howto
->type
;
1791 if (output_bfd
!= NULL
)
1793 /* Partial linking--do nothing. */
1794 reloc_entry
->address
+= input_section
->output_offset
;
1795 return bfd_reloc_ok
;
1798 /* Almost all relocs have to do with relaxing. If any work must be
1799 done for them, it has been done in sh_relax_section. */
1800 if (r_type
== R_SH_IND12W
&& (symbol_in
->flags
& BSF_LOCAL
) != 0)
1801 return bfd_reloc_ok
;
1803 if (symbol_in
!= NULL
1804 && bfd_is_und_section (symbol_in
->section
))
1805 return bfd_reloc_undefined
;
1807 if (bfd_is_com_section (symbol_in
->section
))
1810 sym_value
= (symbol_in
->value
+
1811 symbol_in
->section
->output_section
->vma
+
1812 symbol_in
->section
->output_offset
);
1817 insn
= bfd_get_32 (abfd
, hit_data
);
1818 insn
+= sym_value
+ reloc_entry
->addend
;
1819 bfd_put_32 (abfd
, (bfd_vma
) insn
, hit_data
);
1822 insn
= bfd_get_16 (abfd
, hit_data
);
1823 sym_value
+= reloc_entry
->addend
;
1824 sym_value
-= (input_section
->output_section
->vma
1825 + input_section
->output_offset
1828 sym_value
+= (insn
& 0xfff) << 1;
1830 sym_value
-= 0x1000;
1831 insn
= (insn
& 0xf000) | (sym_value
& 0xfff);
1832 bfd_put_16 (abfd
, (bfd_vma
) insn
, hit_data
);
1833 if (sym_value
< (bfd_vma
) -0x1000 || sym_value
>= 0x1000)
1834 return bfd_reloc_overflow
;
1841 return bfd_reloc_ok
;
1844 /* This function is used for relocs which are only used for relaxing,
1845 which the linker should otherwise ignore. */
1847 static bfd_reloc_status_type
1848 sh_elf_ignore_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1849 output_bfd
, error_message
)
1850 bfd
*abfd ATTRIBUTE_UNUSED
;
1851 arelent
*reloc_entry
;
1852 asymbol
*symbol ATTRIBUTE_UNUSED
;
1853 PTR data ATTRIBUTE_UNUSED
;
1854 asection
*input_section
;
1856 char **error_message ATTRIBUTE_UNUSED
;
1858 if (output_bfd
!= NULL
)
1859 reloc_entry
->address
+= input_section
->output_offset
;
1860 return bfd_reloc_ok
;
1863 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
1865 struct elf_reloc_map
1867 bfd_reloc_code_real_type bfd_reloc_val
;
1868 unsigned char elf_reloc_val
;
1871 /* An array mapping BFD reloc codes to SH ELF relocs. */
1873 static const struct elf_reloc_map sh_reloc_map
[] =
1875 { BFD_RELOC_NONE
, R_SH_NONE
},
1876 { BFD_RELOC_32
, R_SH_DIR32
},
1877 { BFD_RELOC_CTOR
, R_SH_DIR32
},
1878 { BFD_RELOC_32_PCREL
, R_SH_REL32
},
1879 { BFD_RELOC_SH_PCDISP8BY2
, R_SH_DIR8WPN
},
1880 { BFD_RELOC_SH_PCDISP12BY2
, R_SH_IND12W
},
1881 { BFD_RELOC_SH_PCRELIMM8BY2
, R_SH_DIR8WPZ
},
1882 { BFD_RELOC_SH_PCRELIMM8BY4
, R_SH_DIR8WPL
},
1883 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
1884 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
1885 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
1886 { BFD_RELOC_SH_USES
, R_SH_USES
},
1887 { BFD_RELOC_SH_COUNT
, R_SH_COUNT
},
1888 { BFD_RELOC_SH_ALIGN
, R_SH_ALIGN
},
1889 { BFD_RELOC_SH_CODE
, R_SH_CODE
},
1890 { BFD_RELOC_SH_DATA
, R_SH_DATA
},
1891 { BFD_RELOC_SH_LABEL
, R_SH_LABEL
},
1892 { BFD_RELOC_VTABLE_INHERIT
, R_SH_GNU_VTINHERIT
},
1893 { BFD_RELOC_VTABLE_ENTRY
, R_SH_GNU_VTENTRY
},
1894 { BFD_RELOC_SH_LOOP_START
, R_SH_LOOP_START
},
1895 { BFD_RELOC_SH_LOOP_END
, R_SH_LOOP_END
},
1896 { BFD_RELOC_SH_TLS_GD_32
, R_SH_TLS_GD_32
},
1897 { BFD_RELOC_SH_TLS_LD_32
, R_SH_TLS_LD_32
},
1898 { BFD_RELOC_SH_TLS_LDO_32
, R_SH_TLS_LDO_32
},
1899 { BFD_RELOC_SH_TLS_IE_32
, R_SH_TLS_IE_32
},
1900 { BFD_RELOC_SH_TLS_LE_32
, R_SH_TLS_LE_32
},
1901 { BFD_RELOC_SH_TLS_DTPMOD32
, R_SH_TLS_DTPMOD32
},
1902 { BFD_RELOC_SH_TLS_DTPOFF32
, R_SH_TLS_DTPOFF32
},
1903 { BFD_RELOC_SH_TLS_TPOFF32
, R_SH_TLS_TPOFF32
},
1904 { BFD_RELOC_32_GOT_PCREL
, R_SH_GOT32
},
1905 { BFD_RELOC_32_PLT_PCREL
, R_SH_PLT32
},
1906 { BFD_RELOC_SH_COPY
, R_SH_COPY
},
1907 { BFD_RELOC_SH_GLOB_DAT
, R_SH_GLOB_DAT
},
1908 { BFD_RELOC_SH_JMP_SLOT
, R_SH_JMP_SLOT
},
1909 { BFD_RELOC_SH_RELATIVE
, R_SH_RELATIVE
},
1910 { BFD_RELOC_32_GOTOFF
, R_SH_GOTOFF
},
1911 { BFD_RELOC_SH_GOTPC
, R_SH_GOTPC
},
1912 { BFD_RELOC_SH_GOTPLT32
, R_SH_GOTPLT32
},
1913 #ifdef INCLUDE_SHMEDIA
1914 { BFD_RELOC_SH_GOT_LOW16
, R_SH_GOT_LOW16
},
1915 { BFD_RELOC_SH_GOT_MEDLOW16
, R_SH_GOT_MEDLOW16
},
1916 { BFD_RELOC_SH_GOT_MEDHI16
, R_SH_GOT_MEDHI16
},
1917 { BFD_RELOC_SH_GOT_HI16
, R_SH_GOT_HI16
},
1918 { BFD_RELOC_SH_GOTPLT_LOW16
, R_SH_GOTPLT_LOW16
},
1919 { BFD_RELOC_SH_GOTPLT_MEDLOW16
, R_SH_GOTPLT_MEDLOW16
},
1920 { BFD_RELOC_SH_GOTPLT_MEDHI16
, R_SH_GOTPLT_MEDHI16
},
1921 { BFD_RELOC_SH_GOTPLT_HI16
, R_SH_GOTPLT_HI16
},
1922 { BFD_RELOC_SH_PLT_LOW16
, R_SH_PLT_LOW16
},
1923 { BFD_RELOC_SH_PLT_MEDLOW16
, R_SH_PLT_MEDLOW16
},
1924 { BFD_RELOC_SH_PLT_MEDHI16
, R_SH_PLT_MEDHI16
},
1925 { BFD_RELOC_SH_PLT_HI16
, R_SH_PLT_HI16
},
1926 { BFD_RELOC_SH_GOTOFF_LOW16
, R_SH_GOTOFF_LOW16
},
1927 { BFD_RELOC_SH_GOTOFF_MEDLOW16
, R_SH_GOTOFF_MEDLOW16
},
1928 { BFD_RELOC_SH_GOTOFF_MEDHI16
, R_SH_GOTOFF_MEDHI16
},
1929 { BFD_RELOC_SH_GOTOFF_HI16
, R_SH_GOTOFF_HI16
},
1930 { BFD_RELOC_SH_GOTPC_LOW16
, R_SH_GOTPC_LOW16
},
1931 { BFD_RELOC_SH_GOTPC_MEDLOW16
, R_SH_GOTPC_MEDLOW16
},
1932 { BFD_RELOC_SH_GOTPC_MEDHI16
, R_SH_GOTPC_MEDHI16
},
1933 { BFD_RELOC_SH_GOTPC_HI16
, R_SH_GOTPC_HI16
},
1934 { BFD_RELOC_SH_COPY64
, R_SH_COPY64
},
1935 { BFD_RELOC_SH_GLOB_DAT64
, R_SH_GLOB_DAT64
},
1936 { BFD_RELOC_SH_JMP_SLOT64
, R_SH_JMP_SLOT64
},
1937 { BFD_RELOC_SH_RELATIVE64
, R_SH_RELATIVE64
},
1938 { BFD_RELOC_SH_GOT10BY4
, R_SH_GOT10BY4
},
1939 { BFD_RELOC_SH_GOT10BY8
, R_SH_GOT10BY8
},
1940 { BFD_RELOC_SH_GOTPLT10BY4
, R_SH_GOTPLT10BY4
},
1941 { BFD_RELOC_SH_GOTPLT10BY8
, R_SH_GOTPLT10BY8
},
1942 { BFD_RELOC_SH_PT_16
, R_SH_PT_16
},
1943 { BFD_RELOC_SH_SHMEDIA_CODE
, R_SH_SHMEDIA_CODE
},
1944 { BFD_RELOC_SH_IMMU5
, R_SH_DIR5U
},
1945 { BFD_RELOC_SH_IMMS6
, R_SH_DIR6S
},
1946 { BFD_RELOC_SH_IMMU6
, R_SH_DIR6U
},
1947 { BFD_RELOC_SH_IMMS10
, R_SH_DIR10S
},
1948 { BFD_RELOC_SH_IMMS10BY2
, R_SH_DIR10SW
},
1949 { BFD_RELOC_SH_IMMS10BY4
, R_SH_DIR10SL
},
1950 { BFD_RELOC_SH_IMMS10BY8
, R_SH_DIR10SQ
},
1951 { BFD_RELOC_SH_IMMS16
, R_SH_IMMS16
},
1952 { BFD_RELOC_SH_IMMU16
, R_SH_IMMU16
},
1953 { BFD_RELOC_SH_IMM_LOW16
, R_SH_IMM_LOW16
},
1954 { BFD_RELOC_SH_IMM_LOW16_PCREL
, R_SH_IMM_LOW16_PCREL
},
1955 { BFD_RELOC_SH_IMM_MEDLOW16
, R_SH_IMM_MEDLOW16
},
1956 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL
, R_SH_IMM_MEDLOW16_PCREL
},
1957 { BFD_RELOC_SH_IMM_MEDHI16
, R_SH_IMM_MEDHI16
},
1958 { BFD_RELOC_SH_IMM_MEDHI16_PCREL
, R_SH_IMM_MEDHI16_PCREL
},
1959 { BFD_RELOC_SH_IMM_HI16
, R_SH_IMM_HI16
},
1960 { BFD_RELOC_SH_IMM_HI16_PCREL
, R_SH_IMM_HI16_PCREL
},
1961 { BFD_RELOC_64
, R_SH_64
},
1962 { BFD_RELOC_64_PCREL
, R_SH_64_PCREL
},
1963 #endif /* not INCLUDE_SHMEDIA */
1966 /* Given a BFD reloc code, return the howto structure for the
1967 corresponding SH ELf reloc. */
1969 static reloc_howto_type
*
1970 sh_elf_reloc_type_lookup (abfd
, code
)
1971 bfd
*abfd ATTRIBUTE_UNUSED
;
1972 bfd_reloc_code_real_type code
;
1976 for (i
= 0; i
< sizeof (sh_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1978 if (sh_reloc_map
[i
].bfd_reloc_val
== code
)
1979 return &sh_elf_howto_table
[(int) sh_reloc_map
[i
].elf_reloc_val
];
1985 /* Given an ELF reloc, fill in the howto field of a relent. */
1988 sh_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1989 bfd
*abfd ATTRIBUTE_UNUSED
;
1991 Elf_Internal_Rela
*dst
;
1995 r
= ELF32_R_TYPE (dst
->r_info
);
1997 BFD_ASSERT (r
< (unsigned int) R_SH_max
);
1998 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC
|| r
> R_SH_LAST_INVALID_RELOC
);
1999 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_2
|| r
> R_SH_LAST_INVALID_RELOC_2
);
2000 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_3
|| r
> R_SH_LAST_INVALID_RELOC_3
);
2001 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_4
|| r
> R_SH_LAST_INVALID_RELOC_4
);
2002 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_5
|| r
> R_SH_LAST_INVALID_RELOC_5
);
2004 cache_ptr
->howto
= &sh_elf_howto_table
[r
];
2007 /* This function handles relaxing for SH ELF. See the corresponding
2008 function in coff-sh.c for a description of what this does. FIXME:
2009 There is a lot of duplication here between this code and the COFF
2010 specific code. The format of relocs and symbols is wound deeply
2011 into this code, but it would still be better if the duplication
2012 could be eliminated somehow. Note in particular that although both
2013 functions use symbols like R_SH_CODE, those symbols have different
2014 values; in coff-sh.c they come from include/coff/sh.h, whereas here
2015 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
2018 sh_elf_relax_section (abfd
, sec
, link_info
, again
)
2021 struct bfd_link_info
*link_info
;
2024 Elf_Internal_Shdr
*symtab_hdr
;
2025 Elf_Internal_Rela
*internal_relocs
;
2026 bfd_boolean have_code
;
2027 Elf_Internal_Rela
*irel
, *irelend
;
2028 bfd_byte
*contents
= NULL
;
2029 Elf_Internal_Sym
*isymbuf
= NULL
;
2033 if (link_info
->relocateable
2034 || (sec
->flags
& SEC_RELOC
) == 0
2035 || sec
->reloc_count
== 0)
2038 #ifdef INCLUDE_SHMEDIA
2039 if (elf_section_data (sec
)->this_hdr
.sh_flags
2040 & (SHF_SH5_ISA32
| SHF_SH5_ISA32_MIXED
))
2046 /* If this is the first time we have been called for this section,
2047 initialize the cooked size. */
2048 if (sec
->_cooked_size
== 0)
2049 sec
->_cooked_size
= sec
->_raw_size
;
2051 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2053 internal_relocs
= (_bfd_elf32_link_read_relocs
2054 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
2055 link_info
->keep_memory
));
2056 if (internal_relocs
== NULL
)
2061 irelend
= internal_relocs
+ sec
->reloc_count
;
2062 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2064 bfd_vma laddr
, paddr
, symval
;
2065 unsigned short insn
;
2066 Elf_Internal_Rela
*irelfn
, *irelscan
, *irelcount
;
2067 bfd_signed_vma foff
;
2069 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_CODE
)
2072 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_USES
)
2075 /* Get the section contents. */
2076 if (contents
== NULL
)
2078 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2079 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2082 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
2083 if (contents
== NULL
)
2086 if (! bfd_get_section_contents (abfd
, sec
, contents
,
2087 (file_ptr
) 0, sec
->_raw_size
))
2092 /* The r_addend field of the R_SH_USES reloc will point us to
2093 the register load. The 4 is because the r_addend field is
2094 computed as though it were a jump offset, which are based
2095 from 4 bytes after the jump instruction. */
2096 laddr
= irel
->r_offset
+ 4 + irel
->r_addend
;
2097 if (laddr
>= sec
->_raw_size
)
2099 (*_bfd_error_handler
) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),
2100 bfd_archive_filename (abfd
),
2101 (unsigned long) irel
->r_offset
);
2104 insn
= bfd_get_16 (abfd
, contents
+ laddr
);
2106 /* If the instruction is not mov.l NN,rN, we don't know what to
2108 if ((insn
& 0xf000) != 0xd000)
2110 ((*_bfd_error_handler
)
2111 (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
2112 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
, insn
));
2116 /* Get the address from which the register is being loaded. The
2117 displacement in the mov.l instruction is quadrupled. It is a
2118 displacement from four bytes after the movl instruction, but,
2119 before adding in the PC address, two least significant bits
2120 of the PC are cleared. We assume that the section is aligned
2121 on a four byte boundary. */
2122 paddr
= insn
& 0xff;
2124 paddr
+= (laddr
+ 4) &~ (bfd_vma
) 3;
2125 if (paddr
>= sec
->_raw_size
)
2127 ((*_bfd_error_handler
)
2128 (_("%s: 0x%lx: warning: bad R_SH_USES load offset"),
2129 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
2133 /* Get the reloc for the address from which the register is
2134 being loaded. This reloc will tell us which function is
2135 actually being called. */
2136 for (irelfn
= internal_relocs
; irelfn
< irelend
; irelfn
++)
2137 if (irelfn
->r_offset
== paddr
2138 && ELF32_R_TYPE (irelfn
->r_info
) == (int) R_SH_DIR32
)
2140 if (irelfn
>= irelend
)
2142 ((*_bfd_error_handler
)
2143 (_("%s: 0x%lx: warning: could not find expected reloc"),
2144 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2148 /* Read this BFD's symbols if we haven't done so already. */
2149 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
2151 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2152 if (isymbuf
== NULL
)
2153 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2154 symtab_hdr
->sh_info
, 0,
2156 if (isymbuf
== NULL
)
2160 /* Get the value of the symbol referred to by the reloc. */
2161 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
2163 /* A local symbol. */
2164 Elf_Internal_Sym
*isym
;
2166 isym
= isymbuf
+ ELF32_R_SYM (irelfn
->r_info
);
2168 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd
, sec
))
2170 ((*_bfd_error_handler
)
2171 (_("%s: 0x%lx: warning: symbol in unexpected section"),
2172 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2176 symval
= (isym
->st_value
2177 + sec
->output_section
->vma
2178 + sec
->output_offset
);
2183 struct elf_link_hash_entry
*h
;
2185 indx
= ELF32_R_SYM (irelfn
->r_info
) - symtab_hdr
->sh_info
;
2186 h
= elf_sym_hashes (abfd
)[indx
];
2187 BFD_ASSERT (h
!= NULL
);
2188 if (h
->root
.type
!= bfd_link_hash_defined
2189 && h
->root
.type
!= bfd_link_hash_defweak
)
2191 /* This appears to be a reference to an undefined
2192 symbol. Just ignore it--it will be caught by the
2193 regular reloc processing. */
2197 symval
= (h
->root
.u
.def
.value
2198 + h
->root
.u
.def
.section
->output_section
->vma
2199 + h
->root
.u
.def
.section
->output_offset
);
2202 symval
+= bfd_get_32 (abfd
, contents
+ paddr
);
2204 /* See if this function call can be shortened. */
2207 + sec
->output_section
->vma
2208 + sec
->output_offset
2210 if (foff
< -0x1000 || foff
>= 0x1000)
2212 /* After all that work, we can't shorten this function call. */
2216 /* Shorten the function call. */
2218 /* For simplicity of coding, we are going to modify the section
2219 contents, the section relocs, and the BFD symbol table. We
2220 must tell the rest of the code not to free up this
2221 information. It would be possible to instead create a table
2222 of changes which have to be made, as is done in coff-mips.c;
2223 that would be more work, but would require less memory when
2224 the linker is run. */
2226 elf_section_data (sec
)->relocs
= internal_relocs
;
2227 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2228 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2230 /* Replace the jsr with a bsr. */
2232 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
2233 replace the jsr with a bsr. */
2234 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irelfn
->r_info
), R_SH_IND12W
);
2235 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
2237 /* If this needs to be changed because of future relaxing,
2238 it will be handled here like other internal IND12W
2241 (bfd_vma
) 0xb000 | ((foff
>> 1) & 0xfff),
2242 contents
+ irel
->r_offset
);
2246 /* We can't fully resolve this yet, because the external
2247 symbol value may be changed by future relaxing. We let
2248 the final link phase handle it. */
2249 bfd_put_16 (abfd
, (bfd_vma
) 0xb000, contents
+ irel
->r_offset
);
2252 /* See if there is another R_SH_USES reloc referring to the same
2254 for (irelscan
= internal_relocs
; irelscan
< irelend
; irelscan
++)
2255 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_USES
2256 && laddr
== irelscan
->r_offset
+ 4 + irelscan
->r_addend
)
2258 if (irelscan
< irelend
)
2260 /* Some other function call depends upon this register load,
2261 and we have not yet converted that function call.
2262 Indeed, we may never be able to convert it. There is
2263 nothing else we can do at this point. */
2267 /* Look for a R_SH_COUNT reloc on the location where the
2268 function address is stored. Do this before deleting any
2269 bytes, to avoid confusion about the address. */
2270 for (irelcount
= internal_relocs
; irelcount
< irelend
; irelcount
++)
2271 if (irelcount
->r_offset
== paddr
2272 && ELF32_R_TYPE (irelcount
->r_info
) == (int) R_SH_COUNT
)
2275 /* Delete the register load. */
2276 if (! sh_elf_relax_delete_bytes (abfd
, sec
, laddr
, 2))
2279 /* That will change things, so, just in case it permits some
2280 other function call to come within range, we should relax
2281 again. Note that this is not required, and it may be slow. */
2284 /* Now check whether we got a COUNT reloc. */
2285 if (irelcount
>= irelend
)
2287 ((*_bfd_error_handler
)
2288 (_("%s: 0x%lx: warning: could not find expected COUNT reloc"),
2289 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2293 /* The number of uses is stored in the r_addend field. We've
2294 just deleted one. */
2295 if (irelcount
->r_addend
== 0)
2297 ((*_bfd_error_handler
) (_("%s: 0x%lx: warning: bad count"),
2298 bfd_archive_filename (abfd
),
2299 (unsigned long) paddr
));
2303 --irelcount
->r_addend
;
2305 /* If there are no more uses, we can delete the address. Reload
2306 the address from irelfn, in case it was changed by the
2307 previous call to sh_elf_relax_delete_bytes. */
2308 if (irelcount
->r_addend
== 0)
2310 if (! sh_elf_relax_delete_bytes (abfd
, sec
, irelfn
->r_offset
, 4))
2314 /* We've done all we can with that function call. */
2317 /* Look for load and store instructions that we can align on four
2321 bfd_boolean swapped
;
2323 /* Get the section contents. */
2324 if (contents
== NULL
)
2326 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2327 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2330 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
2331 if (contents
== NULL
)
2334 if (! bfd_get_section_contents (abfd
, sec
, contents
,
2335 (file_ptr
) 0, sec
->_raw_size
))
2340 if (! sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
,
2346 elf_section_data (sec
)->relocs
= internal_relocs
;
2347 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2348 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2353 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2355 if (! link_info
->keep_memory
)
2359 /* Cache the symbols for elf_link_input_bfd. */
2360 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2364 if (contents
!= NULL
2365 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2367 if (! link_info
->keep_memory
)
2371 /* Cache the section contents for elf_link_input_bfd. */
2372 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2376 if (internal_relocs
!= NULL
2377 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2378 free (internal_relocs
);
2384 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2386 if (contents
!= NULL
2387 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2389 if (internal_relocs
!= NULL
2390 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2391 free (internal_relocs
);
2396 /* Delete some bytes from a section while relaxing. FIXME: There is a
2397 lot of duplication between this function and sh_relax_delete_bytes
2401 sh_elf_relax_delete_bytes (abfd
, sec
, addr
, count
)
2407 Elf_Internal_Shdr
*symtab_hdr
;
2408 unsigned int sec_shndx
;
2410 Elf_Internal_Rela
*irel
, *irelend
;
2411 Elf_Internal_Rela
*irelalign
;
2413 Elf_Internal_Sym
*isymbuf
, *isym
, *isymend
;
2414 struct elf_link_hash_entry
**sym_hashes
;
2415 struct elf_link_hash_entry
**end_hashes
;
2416 unsigned int symcount
;
2419 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2420 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2422 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
2424 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2426 /* The deletion must stop at the next ALIGN reloc for an aligment
2427 power larger than the number of bytes we are deleting. */
2430 toaddr
= sec
->_cooked_size
;
2432 irel
= elf_section_data (sec
)->relocs
;
2433 irelend
= irel
+ sec
->reloc_count
;
2434 for (; irel
< irelend
; irel
++)
2436 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
2437 && irel
->r_offset
> addr
2438 && count
< (1 << irel
->r_addend
))
2441 toaddr
= irel
->r_offset
;
2446 /* Actually delete the bytes. */
2447 memmove (contents
+ addr
, contents
+ addr
+ count
,
2448 (size_t) (toaddr
- addr
- count
));
2449 if (irelalign
== NULL
)
2450 sec
->_cooked_size
-= count
;
2455 #define NOP_OPCODE (0x0009)
2457 BFD_ASSERT ((count
& 1) == 0);
2458 for (i
= 0; i
< count
; i
+= 2)
2459 bfd_put_16 (abfd
, (bfd_vma
) NOP_OPCODE
, contents
+ toaddr
- count
+ i
);
2462 /* Adjust all the relocs. */
2463 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
2465 bfd_vma nraddr
, stop
;
2468 int off
, adjust
, oinsn
;
2469 bfd_signed_vma voff
= 0;
2470 bfd_boolean overflow
;
2472 /* Get the new reloc address. */
2473 nraddr
= irel
->r_offset
;
2474 if ((irel
->r_offset
> addr
2475 && irel
->r_offset
< toaddr
)
2476 || (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
2477 && irel
->r_offset
== toaddr
))
2480 /* See if this reloc was for the bytes we have deleted, in which
2481 case we no longer care about it. Don't delete relocs which
2482 represent addresses, though. */
2483 if (irel
->r_offset
>= addr
2484 && irel
->r_offset
< addr
+ count
2485 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_ALIGN
2486 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
2487 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_DATA
2488 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_LABEL
)
2489 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
2492 /* If this is a PC relative reloc, see if the range it covers
2493 includes the bytes we have deleted. */
2494 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2503 start
= irel
->r_offset
;
2504 insn
= bfd_get_16 (abfd
, contents
+ nraddr
);
2508 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2511 start
= stop
= addr
;
2515 /* If this reloc is against a symbol defined in this
2516 section, and the symbol will not be adjusted below, we
2517 must check the addend to see it will put the value in
2518 range to be adjusted, and hence must be changed. */
2519 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
2521 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
2522 if (isym
->st_shndx
== sec_shndx
2523 && (isym
->st_value
<= addr
2524 || isym
->st_value
>= toaddr
))
2528 val
= bfd_get_32 (abfd
, contents
+ nraddr
);
2529 val
+= isym
->st_value
;
2530 if (val
> addr
&& val
< toaddr
)
2531 bfd_put_32 (abfd
, val
- count
, contents
+ nraddr
);
2534 start
= stop
= addr
;
2541 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
2545 if (ELF32_R_SYM (irel
->r_info
) >= symtab_hdr
->sh_info
)
2546 start
= stop
= addr
;
2552 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
2558 stop
= start
+ 4 + off
* 2;
2563 stop
= (start
& ~(bfd_vma
) 3) + 4 + off
* 4;
2569 /* These relocs types represent
2571 The r_addend field holds the difference between the reloc
2572 address and L1. That is the start of the reloc, and
2573 adding in the contents gives us the top. We must adjust
2574 both the r_offset field and the section contents.
2575 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
2576 and the elf bfd r_offset is called r_vaddr. */
2578 stop
= irel
->r_offset
;
2579 start
= (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irel
->r_addend
);
2583 && (stop
<= addr
|| stop
>= toaddr
))
2584 irel
->r_addend
+= count
;
2585 else if (stop
> addr
2587 && (start
<= addr
|| start
>= toaddr
))
2588 irel
->r_addend
-= count
;
2590 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH16
)
2591 voff
= bfd_get_signed_16 (abfd
, contents
+ nraddr
);
2592 else if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH8
)
2593 voff
= bfd_get_8 (abfd
, contents
+ nraddr
);
2595 voff
= bfd_get_signed_32 (abfd
, contents
+ nraddr
);
2596 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
2601 start
= irel
->r_offset
;
2602 stop
= (bfd_vma
) ((bfd_signed_vma
) start
2603 + (long) irel
->r_addend
2610 && (stop
<= addr
|| stop
>= toaddr
))
2612 else if (stop
> addr
2614 && (start
<= addr
|| start
>= toaddr
))
2623 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2632 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2634 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2639 if ((oinsn
& 0xf000) != (insn
& 0xf000))
2641 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2645 BFD_ASSERT (adjust
== count
|| count
>= 4);
2650 if ((irel
->r_offset
& 3) == 0)
2653 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2655 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2660 if (voff
< 0 || voff
>= 0xff)
2662 bfd_put_8 (abfd
, voff
, contents
+ nraddr
);
2667 if (voff
< - 0x8000 || voff
>= 0x8000)
2669 bfd_put_signed_16 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
2674 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
2678 irel
->r_addend
+= adjust
;
2684 ((*_bfd_error_handler
)
2685 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
2686 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
2687 bfd_set_error (bfd_error_bad_value
);
2692 irel
->r_offset
= nraddr
;
2695 /* Look through all the other sections. If there contain any IMM32
2696 relocs against internal symbols which we are not going to adjust
2697 below, we may need to adjust the addends. */
2698 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2700 Elf_Internal_Rela
*internal_relocs
;
2701 Elf_Internal_Rela
*irelscan
, *irelscanend
;
2702 bfd_byte
*ocontents
;
2705 || (o
->flags
& SEC_RELOC
) == 0
2706 || o
->reloc_count
== 0)
2709 /* We always cache the relocs. Perhaps, if info->keep_memory is
2710 FALSE, we should free them, if we are permitted to, when we
2711 leave sh_coff_relax_section. */
2712 internal_relocs
= (_bfd_elf32_link_read_relocs
2713 (abfd
, o
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
2715 if (internal_relocs
== NULL
)
2719 irelscanend
= internal_relocs
+ o
->reloc_count
;
2720 for (irelscan
= internal_relocs
; irelscan
< irelscanend
; irelscan
++)
2722 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
2723 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_SWITCH32
)
2725 bfd_vma start
, stop
;
2726 bfd_signed_vma voff
;
2728 if (ocontents
== NULL
)
2730 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
2731 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
2734 /* We always cache the section contents.
2735 Perhaps, if info->keep_memory is FALSE, we
2736 should free them, if we are permitted to,
2737 when we leave sh_coff_relax_section. */
2738 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
2739 if (ocontents
== NULL
)
2741 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
2745 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
2749 stop
= irelscan
->r_offset
;
2751 = (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irelscan
->r_addend
);
2753 /* STOP is in a different section, so it won't change. */
2754 if (start
> addr
&& start
< toaddr
)
2755 irelscan
->r_addend
+= count
;
2757 voff
= bfd_get_signed_32 (abfd
, ocontents
+ irelscan
->r_offset
);
2758 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
2762 && (stop
<= addr
|| stop
>= toaddr
))
2763 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
+ count
,
2764 ocontents
+ irelscan
->r_offset
);
2765 else if (stop
> addr
2767 && (start
<= addr
|| start
>= toaddr
))
2768 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
- count
,
2769 ocontents
+ irelscan
->r_offset
);
2772 if (ELF32_R_TYPE (irelscan
->r_info
) != (int) R_SH_DIR32
)
2775 if (ELF32_R_SYM (irelscan
->r_info
) >= symtab_hdr
->sh_info
)
2779 isym
= isymbuf
+ ELF32_R_SYM (irelscan
->r_info
);
2780 if (isym
->st_shndx
== sec_shndx
2781 && (isym
->st_value
<= addr
2782 || isym
->st_value
>= toaddr
))
2786 if (ocontents
== NULL
)
2788 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
2789 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
2792 /* We always cache the section contents.
2793 Perhaps, if info->keep_memory is FALSE, we
2794 should free them, if we are permitted to,
2795 when we leave sh_coff_relax_section. */
2796 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
2797 if (ocontents
== NULL
)
2799 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
2803 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
2807 val
= bfd_get_32 (abfd
, ocontents
+ irelscan
->r_offset
);
2808 val
+= isym
->st_value
;
2809 if (val
> addr
&& val
< toaddr
)
2810 bfd_put_32 (abfd
, val
- count
,
2811 ocontents
+ irelscan
->r_offset
);
2816 /* Adjust the local symbols defined in this section. */
2817 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
2818 for (isym
= isymbuf
; isym
< isymend
; isym
++)
2820 if (isym
->st_shndx
== sec_shndx
2821 && isym
->st_value
> addr
2822 && isym
->st_value
< toaddr
)
2823 isym
->st_value
-= count
;
2826 /* Now adjust the global symbols defined in this section. */
2827 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2828 - symtab_hdr
->sh_info
);
2829 sym_hashes
= elf_sym_hashes (abfd
);
2830 end_hashes
= sym_hashes
+ symcount
;
2831 for (; sym_hashes
< end_hashes
; sym_hashes
++)
2833 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
2834 if ((sym_hash
->root
.type
== bfd_link_hash_defined
2835 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
2836 && sym_hash
->root
.u
.def
.section
== sec
2837 && sym_hash
->root
.u
.def
.value
> addr
2838 && sym_hash
->root
.u
.def
.value
< toaddr
)
2840 sym_hash
->root
.u
.def
.value
-= count
;
2844 /* See if we can move the ALIGN reloc forward. We have adjusted
2845 r_offset for it already. */
2846 if (irelalign
!= NULL
)
2848 bfd_vma alignto
, alignaddr
;
2850 alignto
= BFD_ALIGN (toaddr
, 1 << irelalign
->r_addend
);
2851 alignaddr
= BFD_ALIGN (irelalign
->r_offset
,
2852 1 << irelalign
->r_addend
);
2853 if (alignto
!= alignaddr
)
2855 /* Tail recursion. */
2856 return sh_elf_relax_delete_bytes (abfd
, sec
, alignaddr
,
2857 (int) (alignto
- alignaddr
));
2864 /* Look for loads and stores which we can align to four byte
2865 boundaries. This is like sh_align_loads in coff-sh.c. */
2868 sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
, pswapped
)
2869 bfd
*abfd ATTRIBUTE_UNUSED
;
2871 Elf_Internal_Rela
*internal_relocs
;
2872 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2873 bfd_boolean
*pswapped
;
2875 Elf_Internal_Rela
*irel
, *irelend
;
2876 bfd_vma
*labels
= NULL
;
2877 bfd_vma
*label
, *label_end
;
2882 irelend
= internal_relocs
+ sec
->reloc_count
;
2884 /* Get all the addresses with labels on them. */
2885 amt
= sec
->reloc_count
;
2886 amt
*= sizeof (bfd_vma
);
2887 labels
= (bfd_vma
*) bfd_malloc (amt
);
2891 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2893 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_LABEL
)
2895 *label_end
= irel
->r_offset
;
2900 /* Note that the assembler currently always outputs relocs in
2901 address order. If that ever changes, this code will need to sort
2902 the label values and the relocs. */
2906 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2908 bfd_vma start
, stop
;
2910 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
)
2913 start
= irel
->r_offset
;
2915 for (irel
++; irel
< irelend
; irel
++)
2916 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_DATA
)
2919 stop
= irel
->r_offset
;
2921 stop
= sec
->_cooked_size
;
2923 if (! _bfd_sh_align_load_span (abfd
, sec
, contents
, sh_elf_swap_insns
,
2924 (PTR
) internal_relocs
, &label
,
2925 label_end
, start
, stop
, pswapped
))
2939 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
2942 sh_elf_swap_insns (abfd
, sec
, relocs
, contents
, addr
)
2949 Elf_Internal_Rela
*internal_relocs
= (Elf_Internal_Rela
*) relocs
;
2950 unsigned short i1
, i2
;
2951 Elf_Internal_Rela
*irel
, *irelend
;
2953 /* Swap the instructions themselves. */
2954 i1
= bfd_get_16 (abfd
, contents
+ addr
);
2955 i2
= bfd_get_16 (abfd
, contents
+ addr
+ 2);
2956 bfd_put_16 (abfd
, (bfd_vma
) i2
, contents
+ addr
);
2957 bfd_put_16 (abfd
, (bfd_vma
) i1
, contents
+ addr
+ 2);
2959 /* Adjust all reloc addresses. */
2960 irelend
= internal_relocs
+ sec
->reloc_count
;
2961 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2963 enum elf_sh_reloc_type type
;
2966 /* There are a few special types of relocs that we don't want to
2967 adjust. These relocs do not apply to the instruction itself,
2968 but are only associated with the address. */
2969 type
= (enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
);
2970 if (type
== R_SH_ALIGN
2971 || type
== R_SH_CODE
2972 || type
== R_SH_DATA
2973 || type
== R_SH_LABEL
)
2976 /* If an R_SH_USES reloc points to one of the addresses being
2977 swapped, we must adjust it. It would be incorrect to do this
2978 for a jump, though, since we want to execute both
2979 instructions after the jump. (We have avoided swapping
2980 around a label, so the jump will not wind up executing an
2981 instruction it shouldn't). */
2982 if (type
== R_SH_USES
)
2986 off
= irel
->r_offset
+ 4 + irel
->r_addend
;
2988 irel
->r_offset
+= 2;
2989 else if (off
== addr
+ 2)
2990 irel
->r_offset
-= 2;
2993 if (irel
->r_offset
== addr
)
2995 irel
->r_offset
+= 2;
2998 else if (irel
->r_offset
== addr
+ 2)
3000 irel
->r_offset
-= 2;
3009 unsigned short insn
, oinsn
;
3010 bfd_boolean overflow
;
3012 loc
= contents
+ irel
->r_offset
;
3021 insn
= bfd_get_16 (abfd
, loc
);
3024 if ((oinsn
& 0xff00) != (insn
& 0xff00))
3026 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3030 insn
= bfd_get_16 (abfd
, loc
);
3033 if ((oinsn
& 0xf000) != (insn
& 0xf000))
3035 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3039 /* This reloc ignores the least significant 3 bits of
3040 the program counter before adding in the offset.
3041 This means that if ADDR is at an even address, the
3042 swap will not affect the offset. If ADDR is an at an
3043 odd address, then the instruction will be crossing a
3044 four byte boundary, and must be adjusted. */
3045 if ((addr
& 3) != 0)
3047 insn
= bfd_get_16 (abfd
, loc
);
3050 if ((oinsn
& 0xff00) != (insn
& 0xff00))
3052 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3060 ((*_bfd_error_handler
)
3061 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
3062 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
3063 bfd_set_error (bfd_error_bad_value
);
3072 #ifdef INCLUDE_SHMEDIA
3074 /* The size in bytes of an entry in the procedure linkage table. */
3076 #define PLT_ENTRY_SIZE 64
3078 /* First entry in an absolute procedure linkage table look like this. */
3080 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3082 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
3083 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
3084 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3085 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3086 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3087 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
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 */
3094 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3095 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3096 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3097 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3100 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3102 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
3103 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
3104 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3105 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3106 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3107 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
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 */
3114 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3115 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3116 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3117 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3120 /* Sebsequent entries in an absolute procedure linkage table look like
3123 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3125 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
3126 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
3127 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
3128 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3129 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3130 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3131 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3132 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3133 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
3134 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
3135 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3136 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3137 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3138 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3139 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3140 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3143 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3145 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3146 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3147 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
3148 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3149 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3150 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3151 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3152 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3153 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
3154 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
3155 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3156 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3157 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3158 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3159 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3160 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3163 /* Entries in a PIC procedure linkage table look like this. */
3165 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3167 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3168 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3169 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
3170 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3171 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3172 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3173 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3174 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3175 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3176 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
3177 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3178 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3179 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3180 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3181 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3182 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3185 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3187 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3188 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3189 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
3190 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3191 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3192 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3193 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3194 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3195 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3196 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
3197 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3198 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3199 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3200 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3201 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3202 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3205 static const bfd_byte
*elf_sh_plt0_entry
;
3206 static const bfd_byte
*elf_sh_plt_entry
;
3207 static const bfd_byte
*elf_sh_pic_plt_entry
;
3209 /* Return size of a PLT entry. */
3210 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3212 /* Return offset of the PLT0 address in an absolute PLT entry. */
3213 #define elf_sh_plt_plt0_offset(info) 32
3215 /* Return offset of the linker in PLT0 entry. */
3216 #define elf_sh_plt0_gotplt_offset(info) 0
3218 /* Return offset of the trampoline in PLT entry */
3219 #define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
3221 /* Return offset of the symbol in PLT entry. */
3222 #define elf_sh_plt_symbol_offset(info) 0
3224 /* Return offset of the relocation in PLT entry. */
3225 #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
3228 movi_shori_putval (output_bfd
, value
, addr
)
3230 unsigned long value
;
3233 bfd_put_32 (output_bfd
,
3234 bfd_get_32 (output_bfd
, addr
)
3235 | ((value
>> 6) & 0x3fffc00),
3237 bfd_put_32 (output_bfd
,
3238 bfd_get_32 (output_bfd
, addr
+ 4)
3239 | ((value
<< 10) & 0x3fffc00),
3244 /* The size in bytes of an entry in the procedure linkage table. */
3246 #define PLT_ENTRY_SIZE 28
3248 /* First entry in an absolute procedure linkage table look like this. */
3251 /* Note - this code has been "optimised" not to use r2. r2 is used by
3252 GCC to return the address of large strutcures, so it should not be
3253 corrupted here. This does mean however, that this PLT does not conform
3254 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
3255 and r2 contains the GOT id. This version stores the GOT id in r0 and
3256 ignores the type. Loaders can easily detect this difference however,
3257 since the type will always be 0 or 8, and the GOT ids will always be
3258 greater than or equal to 12. */
3259 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3261 0xd0, 0x05, /* mov.l 2f,r0 */
3262 0x60, 0x02, /* mov.l @r0,r0 */
3263 0x2f, 0x06, /* mov.l r0,@-r15 */
3264 0xd0, 0x03, /* mov.l 1f,r0 */
3265 0x60, 0x02, /* mov.l @r0,r0 */
3266 0x40, 0x2b, /* jmp @r0 */
3267 0x60, 0xf6, /* mov.l @r15+,r0 */
3268 0x00, 0x09, /* nop */
3269 0x00, 0x09, /* nop */
3270 0x00, 0x09, /* nop */
3271 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3272 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3275 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3277 0x05, 0xd0, /* mov.l 2f,r0 */
3278 0x02, 0x60, /* mov.l @r0,r0 */
3279 0x06, 0x2f, /* mov.l r0,@-r15 */
3280 0x03, 0xd0, /* mov.l 1f,r0 */
3281 0x02, 0x60, /* mov.l @r0,r0 */
3282 0x2b, 0x40, /* jmp @r0 */
3283 0xf6, 0x60, /* mov.l @r15+,r0 */
3284 0x09, 0x00, /* nop */
3285 0x09, 0x00, /* nop */
3286 0x09, 0x00, /* nop */
3287 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3288 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3291 /* Sebsequent entries in an absolute procedure linkage table look like
3294 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3296 0xd0, 0x04, /* mov.l 1f,r0 */
3297 0x60, 0x02, /* mov.l @r0,r0 */
3298 0xd1, 0x02, /* mov.l 0f,r1 */
3299 0x40, 0x2b, /* jmp @r0 */
3300 0x60, 0x13, /* mov r1,r0 */
3301 0xd1, 0x03, /* mov.l 2f,r1 */
3302 0x40, 0x2b, /* jmp @r0 */
3303 0x00, 0x09, /* nop */
3304 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3305 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3306 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3309 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3311 0x04, 0xd0, /* mov.l 1f,r0 */
3312 0x02, 0x60, /* mov.l @r0,r0 */
3313 0x02, 0xd1, /* mov.l 0f,r1 */
3314 0x2b, 0x40, /* jmp @r0 */
3315 0x13, 0x60, /* mov r1,r0 */
3316 0x03, 0xd1, /* mov.l 2f,r1 */
3317 0x2b, 0x40, /* jmp @r0 */
3318 0x09, 0x00, /* nop */
3319 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3320 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3321 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3324 /* Entries in a PIC procedure linkage table look like this. */
3326 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3328 0xd0, 0x04, /* mov.l 1f,r0 */
3329 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3330 0x40, 0x2b, /* jmp @r0 */
3331 0x00, 0x09, /* nop */
3332 0x50, 0xc2, /* mov.l @(8,r12),r0 */
3333 0xd1, 0x03, /* mov.l 2f,r1 */
3334 0x40, 0x2b, /* jmp @r0 */
3335 0x50, 0xc1, /* mov.l @(4,r12),r0 */
3336 0x00, 0x09, /* nop */
3337 0x00, 0x09, /* nop */
3338 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3339 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3342 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3344 0x04, 0xd0, /* mov.l 1f,r0 */
3345 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3346 0x2b, 0x40, /* jmp @r0 */
3347 0x09, 0x00, /* nop */
3348 0xc2, 0x50, /* mov.l @(8,r12),r0 */
3349 0x03, 0xd1, /* mov.l 2f,r1 */
3350 0x2b, 0x40, /* jmp @r0 */
3351 0xc1, 0x50, /* mov.l @(4,r12),r0 */
3352 0x09, 0x00, /* nop */
3353 0x09, 0x00, /* nop */
3354 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3355 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3358 #else /* These are the old style PLT entries. */
3359 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3361 0xd0, 0x04, /* mov.l 1f,r0 */
3362 0xd2, 0x05, /* mov.l 2f,r2 */
3363 0x60, 0x02, /* mov.l @r0,r0 */
3364 0x62, 0x22, /* mov.l @r2,r2 */
3365 0x40, 0x2b, /* jmp @r0 */
3366 0xe0, 0x00, /* mov #0,r0 */
3367 0x00, 0x09, /* nop */
3368 0x00, 0x09, /* nop */
3369 0x00, 0x09, /* nop */
3370 0x00, 0x09, /* nop */
3371 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3372 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3375 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3377 0x04, 0xd0, /* mov.l 1f,r0 */
3378 0x05, 0xd2, /* mov.l 2f,r2 */
3379 0x02, 0x60, /* mov.l @r0,r0 */
3380 0x22, 0x62, /* mov.l @r2,r2 */
3381 0x2b, 0x40, /* jmp @r0 */
3382 0x00, 0xe0, /* mov #0,r0 */
3383 0x09, 0x00, /* nop */
3384 0x09, 0x00, /* nop */
3385 0x09, 0x00, /* nop */
3386 0x09, 0x00, /* nop */
3387 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3388 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3391 /* Sebsequent entries in an absolute procedure linkage table look like
3394 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3396 0xd0, 0x04, /* mov.l 1f,r0 */
3397 0x60, 0x02, /* mov.l @r0,r0 */
3398 0xd2, 0x02, /* mov.l 0f,r2 */
3399 0x40, 0x2b, /* jmp @r0 */
3400 0x60, 0x23, /* mov r2,r0 */
3401 0xd1, 0x03, /* mov.l 2f,r1 */
3402 0x40, 0x2b, /* jmp @r0 */
3403 0x00, 0x09, /* nop */
3404 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3405 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3406 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3409 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3411 0x04, 0xd0, /* mov.l 1f,r0 */
3412 0x02, 0x60, /* mov.l @r0,r0 */
3413 0x02, 0xd2, /* mov.l 0f,r2 */
3414 0x2b, 0x40, /* jmp @r0 */
3415 0x23, 0x60, /* mov r2,r0 */
3416 0x03, 0xd1, /* mov.l 2f,r1 */
3417 0x2b, 0x40, /* jmp @r0 */
3418 0x09, 0x00, /* nop */
3419 0, 0, 0, 0, /* 0: replaced with address of .PLT. */
3420 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3421 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3424 /* Entries in a PIC procedure linkage table look like this. */
3426 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3428 0xd0, 0x04, /* mov.l 1f,r0 */
3429 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3430 0x40, 0x2b, /* jmp @r0 */
3431 0x00, 0x09, /* nop */
3432 0x50, 0xc2, /* 0: mov.l @(8,r12),r0 */
3433 0x52, 0xc1, /* 1: mov.l @(4,r12),r2 */
3434 0xd1, 0x02, /* mov.l 2f,r1 */
3435 0x40, 0x2b, /* jmp @r0 */
3436 0xe0, 0x00, /* mov #0,r0 ! shows the type of PLT. */
3437 0x00, 0x09, /* nop */
3438 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3439 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3442 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3444 0x04, 0xd0, /* mov.l 1f,r0 */
3445 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3446 0x2b, 0x40, /* jmp @r0 */
3447 0x09, 0x00, /* nop */
3448 0xc2, 0x50, /* 0: mov.l @(8,r12),r0 */
3449 0xc1, 0x52, /* 1: mov.l @(4,r12),r2 */
3450 0x02, 0xd1, /* mov.l 2f,r1 */
3451 0x2b, 0x40, /* jmp @r0 */
3452 0x00, 0xe0, /* mov #0,r0 ! shows the type of PLT. */
3453 0x09, 0x00, /* nop */
3454 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3455 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3457 #endif /* old style PLT entries. */
3459 static const bfd_byte
*elf_sh_plt0_entry
;
3460 static const bfd_byte
*elf_sh_plt_entry
;
3461 static const bfd_byte
*elf_sh_pic_plt_entry
;
3463 /* Return size of a PLT entry. */
3464 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3466 /* Return offset of the PLT0 address in an absolute PLT entry. */
3467 #define elf_sh_plt_plt0_offset(info) 16
3469 /* Return offset of the linker in PLT0 entry. */
3470 #define elf_sh_plt0_linker_offset(info) 20
3472 /* Return offset of the GOT id in PLT0 entry. */
3473 #define elf_sh_plt0_gotid_offset(info) 24
3475 /* Return offset of the tempoline in PLT entry */
3476 #define elf_sh_plt_temp_offset(info) 8
3478 /* Return offset of the symbol in PLT entry. */
3479 #define elf_sh_plt_symbol_offset(info) 20
3481 /* Return offset of the relocation in PLT entry. */
3482 #define elf_sh_plt_reloc_offset(info) 24
3485 /* The sh linker needs to keep track of the number of relocs that it
3486 decides to copy as dynamic relocs in check_relocs for each symbol.
3487 This is so that it can later discard them if they are found to be
3488 unnecessary. We store the information in a field extending the
3489 regular ELF linker hash table. */
3491 struct elf_sh_dyn_relocs
3493 struct elf_sh_dyn_relocs
*next
;
3495 /* The input section of the reloc. */
3498 /* Total number of relocs copied for the input section. */
3499 bfd_size_type count
;
3501 /* Number of pc-relative relocs copied for the input section. */
3502 bfd_size_type pc_count
;
3505 /* sh ELF linker hash entry. */
3507 struct elf_sh_link_hash_entry
3509 struct elf_link_hash_entry root
;
3511 #ifdef INCLUDE_SHMEDIA
3514 bfd_signed_vma refcount
;
3519 /* Track dynamic relocs copied for this symbol. */
3520 struct elf_sh_dyn_relocs
*dyn_relocs
;
3522 bfd_signed_vma gotplt_refcount
;
3525 GOT_UNKNOWN
= 0, GOT_NORMAL
, GOT_TLS_GD
, GOT_TLS_IE
3528 /* If TRUE, R_SH_TLS_TPOFF32 relocation is generated. */
3529 bfd_boolean tls_tpoff32
;
3532 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
3534 struct sh_elf_obj_tdata
3536 struct elf_obj_tdata root
;
3538 /* tls_type for each local got entry. */
3539 char *local_got_tls_type
;
3542 #define sh_elf_tdata(abfd) \
3543 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
3545 #define sh_elf_local_got_tls_type(abfd) \
3546 (sh_elf_tdata (abfd)->local_got_tls_type)
3548 /* Override the generic function because we need to store sh_elf_obj_tdata
3549 as the specific tdata. */
3552 sh_elf_mkobject (abfd
)
3555 bfd_size_type amt
= sizeof (struct sh_elf_obj_tdata
);
3556 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
3557 if (abfd
->tdata
.any
== NULL
)
3562 /* sh ELF linker hash table. */
3564 struct elf_sh_link_hash_table
3566 struct elf_link_hash_table root
;
3568 /* Short-cuts to get to dynamic linker sections. */
3577 /* Small local sym to section mapping cache. */
3578 struct sym_sec_cache sym_sec
;
3580 /* A counter or offset to track a TLS got entry. */
3583 bfd_signed_vma refcount
;
3588 /* Traverse an sh ELF linker hash table. */
3590 #define sh_elf_link_hash_traverse(table, func, info) \
3591 (elf_link_hash_traverse \
3593 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3596 /* Get the sh ELF linker hash table from a link_info structure. */
3598 #define sh_elf_hash_table(p) \
3599 ((struct elf_sh_link_hash_table *) ((p)->hash))
3601 /* Create an entry in an sh ELF linker hash table. */
3603 static struct bfd_hash_entry
*
3604 sh_elf_link_hash_newfunc (entry
, table
, string
)
3605 struct bfd_hash_entry
*entry
;
3606 struct bfd_hash_table
*table
;
3609 struct elf_sh_link_hash_entry
*ret
=
3610 (struct elf_sh_link_hash_entry
*) entry
;
3612 /* Allocate the structure if it has not already been allocated by a
3614 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3615 ret
= ((struct elf_sh_link_hash_entry
*)
3616 bfd_hash_allocate (table
,
3617 sizeof (struct elf_sh_link_hash_entry
)));
3618 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3619 return (struct bfd_hash_entry
*) ret
;
3621 /* Call the allocation method of the superclass. */
3622 ret
= ((struct elf_sh_link_hash_entry
*)
3623 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3625 if (ret
!= (struct elf_sh_link_hash_entry
*) NULL
)
3627 ret
->dyn_relocs
= NULL
;
3628 ret
->gotplt_refcount
= 0;
3629 #ifdef INCLUDE_SHMEDIA
3630 ret
->datalabel_got
.refcount
= ret
->root
.got
.refcount
;
3632 ret
->tls_type
= GOT_UNKNOWN
;
3633 ret
->tls_tpoff32
= FALSE
;
3636 return (struct bfd_hash_entry
*) ret
;
3639 /* Create an sh ELF linker hash table. */
3641 static struct bfd_link_hash_table
*
3642 sh_elf_link_hash_table_create (abfd
)
3645 struct elf_sh_link_hash_table
*ret
;
3646 bfd_size_type amt
= sizeof (struct elf_sh_link_hash_table
);
3648 ret
= (struct elf_sh_link_hash_table
*) bfd_malloc (amt
);
3649 if (ret
== (struct elf_sh_link_hash_table
*) NULL
)
3652 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3653 sh_elf_link_hash_newfunc
))
3660 ret
->sgotplt
= NULL
;
3661 ret
->srelgot
= NULL
;
3663 ret
->srelplt
= NULL
;
3664 ret
->sdynbss
= NULL
;
3665 ret
->srelbss
= NULL
;
3666 ret
->sym_sec
.abfd
= NULL
;
3667 ret
->tls_ldm_got
.refcount
= 0;
3669 return &ret
->root
.root
;
3672 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
3673 shortcuts to them in our hash table. */
3676 create_got_section (dynobj
, info
)
3678 struct bfd_link_info
*info
;
3680 struct elf_sh_link_hash_table
*htab
;
3682 if (! _bfd_elf_create_got_section (dynobj
, info
))
3685 htab
= sh_elf_hash_table (info
);
3686 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
3687 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
3688 if (! htab
->sgot
|| ! htab
->sgotplt
)
3691 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
3692 if (htab
->srelgot
== NULL
3693 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
3698 | SEC_LINKER_CREATED
3700 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
3705 /* Create dynamic sections when linking against a dynamic object. */
3708 sh_elf_create_dynamic_sections (abfd
, info
)
3710 struct bfd_link_info
*info
;
3712 struct elf_sh_link_hash_table
*htab
;
3713 flagword flags
, pltflags
;
3714 register asection
*s
;
3715 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3718 switch (bed
->s
->arch_size
)
3729 bfd_set_error (bfd_error_bad_value
);
3733 htab
= sh_elf_hash_table (info
);
3735 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3736 .rel[a].bss sections. */
3738 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3739 | SEC_LINKER_CREATED
);
3742 pltflags
|= SEC_CODE
;
3743 if (bed
->plt_not_loaded
)
3744 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
3745 if (bed
->plt_readonly
)
3746 pltflags
|= SEC_READONLY
;
3748 s
= bfd_make_section (abfd
, ".plt");
3751 || ! bfd_set_section_flags (abfd
, s
, pltflags
)
3752 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3755 if (bed
->want_plt_sym
)
3757 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3759 struct elf_link_hash_entry
*h
;
3760 struct bfd_link_hash_entry
*bh
= NULL
;
3762 if (! (_bfd_generic_link_add_one_symbol
3763 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3764 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
3765 get_elf_backend_data (abfd
)->collect
, &bh
)))
3768 h
= (struct elf_link_hash_entry
*) bh
;
3769 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3770 h
->type
= STT_OBJECT
;
3773 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
3777 s
= bfd_make_section (abfd
,
3778 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt");
3781 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3782 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3785 if (! create_got_section (abfd
, info
))
3789 const char *secname
;
3794 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3796 secflags
= bfd_get_section_flags (abfd
, sec
);
3797 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3798 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3800 secname
= bfd_get_section_name (abfd
, sec
);
3801 relname
= (char *) bfd_malloc ((bfd_size_type
) strlen (secname
) + 6);
3802 strcpy (relname
, ".rela");
3803 strcat (relname
, secname
);
3804 s
= bfd_make_section (abfd
, relname
);
3806 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3807 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3812 if (bed
->want_dynbss
)
3814 /* The .dynbss section is a place to put symbols which are defined
3815 by dynamic objects, are referenced by regular objects, and are
3816 not functions. We must allocate space for them in the process
3817 image and use a R_*_COPY reloc to tell the dynamic linker to
3818 initialize them at run time. The linker script puts the .dynbss
3819 section into the .bss section of the final image. */
3820 s
= bfd_make_section (abfd
, ".dynbss");
3823 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
3826 /* The .rel[a].bss section holds copy relocs. This section is not
3827 normally needed. We need to create it here, though, so that the
3828 linker will map it to an output section. We can't just create it
3829 only if we need it, because we will not know whether we need it
3830 until we have seen all the input files, and the first time the
3831 main linker code calls BFD after examining all the input files
3832 (size_dynamic_sections) the input sections have already been
3833 mapped to the output sections. If the section turns out not to
3834 be needed, we can discard it later. We will never need this
3835 section when generating a shared object, since they do not use
3839 s
= bfd_make_section (abfd
,
3840 (bed
->default_use_rela_p
3841 ? ".rela.bss" : ".rel.bss"));
3844 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3845 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3853 /* Adjust a symbol defined by a dynamic object and referenced by a
3854 regular object. The current definition is in some section of the
3855 dynamic object, but we're not including those sections. We have to
3856 change the definition to something the rest of the link can
3860 sh_elf_adjust_dynamic_symbol (info
, h
)
3861 struct bfd_link_info
*info
;
3862 struct elf_link_hash_entry
*h
;
3864 struct elf_sh_link_hash_table
*htab
;
3865 struct elf_sh_link_hash_entry
*eh
;
3866 struct elf_sh_dyn_relocs
*p
;
3869 unsigned int power_of_two
;
3871 dynobj
= elf_hash_table (info
)->dynobj
;
3873 /* Make sure we know what is going on here. */
3874 BFD_ASSERT (dynobj
!= NULL
3875 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
3876 || h
->weakdef
!= NULL
3877 || ((h
->elf_link_hash_flags
3878 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3879 && (h
->elf_link_hash_flags
3880 & ELF_LINK_HASH_REF_REGULAR
) != 0
3881 && (h
->elf_link_hash_flags
3882 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
3884 /* If this is a function, put it in the procedure linkage table. We
3885 will fill in the contents of the procedure linkage table later,
3886 when we know the address of the .got section. */
3887 if (h
->type
== STT_FUNC
3888 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3890 if (h
->plt
.refcount
<= 0
3892 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3893 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0
3894 && h
->root
.type
!= bfd_link_hash_undefweak
3895 && h
->root
.type
!= bfd_link_hash_undefined
))
3897 /* This case can occur if we saw a PLT reloc in an input
3898 file, but the symbol was never referred to by a dynamic
3899 object. In such a case, we don't actually need to build
3900 a procedure linkage table, and we can just do a REL32
3902 h
->plt
.offset
= (bfd_vma
) -1;
3903 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3909 h
->plt
.offset
= (bfd_vma
) -1;
3911 /* If this is a weak symbol, and there is a real definition, the
3912 processor independent code will have arranged for us to see the
3913 real definition first, and we can just use the same value. */
3914 if (h
->weakdef
!= NULL
)
3916 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3917 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3918 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3919 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3923 /* This is a reference to a symbol defined by a dynamic object which
3924 is not a function. */
3926 /* If we are creating a shared library, we must presume that the
3927 only references to the symbol are via the global offset table.
3928 For such cases we need not do anything here; the relocations will
3929 be handled correctly by relocate_section. */
3933 /* If there are no references to this symbol that do not use the
3934 GOT, we don't need to generate a copy reloc. */
3935 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
3938 /* If -z nocopyreloc was given, we won't generate them either. */
3939 if (info
->nocopyreloc
)
3941 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3945 eh
= (struct elf_sh_link_hash_entry
*) h
;
3946 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3948 s
= p
->sec
->output_section
;
3949 if (s
!= NULL
&& (s
->flags
& (SEC_READONLY
| SEC_HAS_CONTENTS
)) != 0)
3953 /* If we didn't find any dynamic relocs in sections which needs the
3954 copy reloc, then we'll be keeping the dynamic relocs and avoiding
3958 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3962 /* We must allocate the symbol in our .dynbss section, which will
3963 become part of the .bss section of the executable. There will be
3964 an entry for this symbol in the .dynsym section. The dynamic
3965 object will contain position independent code, so all references
3966 from the dynamic object to this symbol will go through the global
3967 offset table. The dynamic linker will use the .dynsym entry to
3968 determine the address it must put in the global offset table, so
3969 both the dynamic object and the regular object will refer to the
3970 same memory location for the variable. */
3972 htab
= sh_elf_hash_table (info
);
3974 BFD_ASSERT (s
!= NULL
);
3976 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3977 copy the initial value out of the dynamic object and into the
3978 runtime process image. We need to remember the offset into the
3979 .rela.bss section we are going to use. */
3980 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3984 srel
= htab
->srelbss
;
3985 BFD_ASSERT (srel
!= NULL
);
3986 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
3987 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3990 /* We need to figure out the alignment required for this symbol. I
3991 have no idea how ELF linkers handle this. */
3992 power_of_two
= bfd_log2 (h
->size
);
3993 if (power_of_two
> 3)
3996 /* Apply the required alignment. */
3997 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
3998 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
4000 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
4004 /* Define the symbol as being at this point in the section. */
4005 h
->root
.u
.def
.section
= s
;
4006 h
->root
.u
.def
.value
= s
->_raw_size
;
4008 /* Increment the section size to make room for the symbol. */
4009 s
->_raw_size
+= h
->size
;
4014 /* This is the condition under which sh_elf_finish_dynamic_symbol
4015 will be called from elflink.h. If elflink.h doesn't call our
4016 finish_dynamic_symbol routine, we'll need to do something about
4017 initializing any .plt and .got entries in sh_elf_relocate_section. */
4018 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
4020 && ((INFO)->shared \
4021 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
4022 && ((H)->dynindx != -1 \
4023 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
4025 /* Allocate space in .plt, .got and associated reloc sections for
4029 allocate_dynrelocs (h
, inf
)
4030 struct elf_link_hash_entry
*h
;
4033 struct bfd_link_info
*info
;
4034 struct elf_sh_link_hash_table
*htab
;
4035 struct elf_sh_link_hash_entry
*eh
;
4036 struct elf_sh_dyn_relocs
*p
;
4038 if (h
->root
.type
== bfd_link_hash_indirect
)
4041 if (h
->root
.type
== bfd_link_hash_warning
)
4042 /* When warning symbols are created, they **replace** the "real"
4043 entry in the hash table, thus we never get to see the real
4044 symbol in a hash traversal. So look at it now. */
4045 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4047 info
= (struct bfd_link_info
*) inf
;
4048 htab
= sh_elf_hash_table (info
);
4050 eh
= (struct elf_sh_link_hash_entry
*) h
;
4051 if ((h
->got
.refcount
> 0
4052 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
4053 && eh
->gotplt_refcount
> 0)
4055 /* The symbol has been forced local, or we have some direct got refs,
4056 so treat all the gotplt refs as got refs. */
4057 h
->got
.refcount
+= eh
->gotplt_refcount
;
4058 if (h
->plt
.refcount
>= eh
->gotplt_refcount
)
4059 h
->plt
.refcount
-= eh
->gotplt_refcount
;
4062 if (htab
->root
.dynamic_sections_created
4063 && h
->plt
.refcount
> 0)
4065 /* Make sure this symbol is output as a dynamic symbol.
4066 Undefined weak syms won't yet be marked as dynamic. */
4067 if (h
->dynindx
== -1
4068 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4070 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4074 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
4076 asection
*s
= htab
->splt
;
4078 /* If this is the first .plt entry, make room for the special
4080 if (s
->_raw_size
== 0)
4081 s
->_raw_size
+= PLT_ENTRY_SIZE
;
4083 h
->plt
.offset
= s
->_raw_size
;
4085 /* If this symbol is not defined in a regular file, and we are
4086 not generating a shared library, then set the symbol to this
4087 location in the .plt. This is required to make function
4088 pointers compare as equal between the normal executable and
4089 the shared library. */
4091 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4093 h
->root
.u
.def
.section
= s
;
4094 h
->root
.u
.def
.value
= h
->plt
.offset
;
4097 /* Make room for this entry. */
4098 s
->_raw_size
+= PLT_ENTRY_SIZE
;
4100 /* We also need to make an entry in the .got.plt section, which
4101 will be placed in the .got section by the linker script. */
4102 htab
->sgotplt
->_raw_size
+= 4;
4104 /* We also need to make an entry in the .rel.plt section. */
4105 htab
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
4109 h
->plt
.offset
= (bfd_vma
) -1;
4110 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4115 h
->plt
.offset
= (bfd_vma
) -1;
4116 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4119 if (h
->got
.refcount
> 0)
4123 int tls_type
= sh_elf_hash_entry (h
)->tls_type
;
4125 /* Make sure this symbol is output as a dynamic symbol.
4126 Undefined weak syms won't yet be marked as dynamic. */
4127 if (h
->dynindx
== -1
4128 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4130 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4135 h
->got
.offset
= s
->_raw_size
;
4137 /* R_SH_TLS_GD needs 2 consecutive GOT slots. */
4138 if (tls_type
== GOT_TLS_GD
)
4140 dyn
= htab
->root
.dynamic_sections_created
;
4141 /* R_SH_TLS_IE_32 needs one dynamic relocation,
4142 R_SH_TLS_GD needs one if local symbol and two if global. */
4143 if ((tls_type
== GOT_TLS_GD
&& h
->dynindx
== -1)
4144 || tls_type
== GOT_TLS_IE
)
4145 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4146 else if (tls_type
== GOT_TLS_GD
)
4147 htab
->srelgot
->_raw_size
+= 2 * sizeof (Elf32_External_Rela
);
4148 else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
4149 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4152 h
->got
.offset
= (bfd_vma
) -1;
4154 #ifdef INCLUDE_SHMEDIA
4155 if (eh
->datalabel_got
.refcount
> 0)
4160 /* Make sure this symbol is output as a dynamic symbol.
4161 Undefined weak syms won't yet be marked as dynamic. */
4162 if (h
->dynindx
== -1
4163 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4165 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4170 eh
->datalabel_got
.offset
= s
->_raw_size
;
4172 dyn
= htab
->root
.dynamic_sections_created
;
4173 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
4174 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4177 eh
->datalabel_got
.offset
= (bfd_vma
) -1;
4180 if (eh
->dyn_relocs
== NULL
)
4183 /* In the shared -Bsymbolic case, discard space allocated for
4184 dynamic pc-relative relocs against symbols which turn out to be
4185 defined in regular objects. For the normal shared case, discard
4186 space for pc-relative relocs that have become local due to symbol
4187 visibility changes. */
4191 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
4192 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
4195 struct elf_sh_dyn_relocs
**pp
;
4197 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
4199 p
->count
-= p
->pc_count
;
4210 if (sh_elf_hash_entry (h
)->tls_tpoff32
)
4213 /* For the non-shared case, discard space for relocs against
4214 symbols which turn out to need copy relocs or are not
4217 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
4218 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4219 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4220 || (htab
->root
.dynamic_sections_created
4221 && (h
->root
.type
== bfd_link_hash_undefweak
4222 || h
->root
.type
== bfd_link_hash_undefined
))))
4224 /* Make sure this symbol is output as a dynamic symbol.
4225 Undefined weak syms won't yet be marked as dynamic. */
4226 if (h
->dynindx
== -1
4227 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4229 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4233 /* If that succeeded, we know we'll be keeping all the
4235 if (h
->dynindx
!= -1)
4239 eh
->dyn_relocs
= NULL
;
4244 /* Finally, allocate space. */
4245 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4247 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
4248 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
4254 /* Find any dynamic relocs that apply to read-only sections. */
4257 readonly_dynrelocs (h
, inf
)
4258 struct elf_link_hash_entry
*h
;
4261 struct elf_sh_link_hash_entry
*eh
;
4262 struct elf_sh_dyn_relocs
*p
;
4264 if (h
->root
.type
== bfd_link_hash_warning
)
4265 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4267 eh
= (struct elf_sh_link_hash_entry
*) h
;
4268 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4270 asection
*s
= p
->sec
->output_section
;
4272 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4274 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4276 info
->flags
|= DF_TEXTREL
;
4278 /* Not an error, just cut short the traversal. */
4285 /* Set the sizes of the dynamic sections. */
4288 sh_elf_size_dynamic_sections (output_bfd
, info
)
4289 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4290 struct bfd_link_info
*info
;
4292 struct elf_sh_link_hash_table
*htab
;
4298 htab
= sh_elf_hash_table (info
);
4299 dynobj
= htab
->root
.dynobj
;
4300 BFD_ASSERT (dynobj
!= NULL
);
4302 if (htab
->root
.dynamic_sections_created
)
4304 /* Set the contents of the .interp section to the interpreter. */
4307 s
= bfd_get_section_by_name (dynobj
, ".interp");
4308 BFD_ASSERT (s
!= NULL
);
4309 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4310 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4314 /* Set up .got offsets for local syms, and space for local dynamic
4316 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4318 bfd_signed_vma
*local_got
;
4319 bfd_signed_vma
*end_local_got
;
4320 char *local_tls_type
;
4321 bfd_size_type locsymcount
;
4322 Elf_Internal_Shdr
*symtab_hdr
;
4325 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
4328 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4330 struct elf_sh_dyn_relocs
*p
;
4332 for (p
= ((struct elf_sh_dyn_relocs
*)
4333 elf_section_data (s
)->local_dynrel
);
4337 if (! bfd_is_abs_section (p
->sec
)
4338 && bfd_is_abs_section (p
->sec
->output_section
))
4340 /* Input section has been discarded, either because
4341 it is a copy of a linkonce section or due to
4342 linker script /DISCARD/, so we'll be discarding
4345 else if (p
->count
!= 0)
4347 srel
= elf_section_data (p
->sec
)->sreloc
;
4348 srel
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
4349 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
4350 info
->flags
|= DF_TEXTREL
;
4355 local_got
= elf_local_got_refcounts (ibfd
);
4359 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4360 locsymcount
= symtab_hdr
->sh_info
;
4361 #ifdef INCLUDE_SHMEDIA
4362 /* Count datalabel local GOT. */
4365 end_local_got
= local_got
+ locsymcount
;
4366 local_tls_type
= sh_elf_local_got_tls_type (ibfd
);
4368 srel
= htab
->srelgot
;
4369 for (; local_got
< end_local_got
; ++local_got
)
4373 *local_got
= s
->_raw_size
;
4375 if (*local_tls_type
== GOT_TLS_GD
)
4378 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
4381 *local_got
= (bfd_vma
) -1;
4386 if (htab
->tls_ldm_got
.refcount
> 0)
4388 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
4390 htab
->tls_ldm_got
.offset
= htab
->sgot
->_raw_size
;
4391 htab
->sgot
->_raw_size
+= 8;
4392 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4395 htab
->tls_ldm_got
.offset
= -1;
4397 /* Allocate global sym .plt and .got entries, and space for global
4398 sym dynamic relocs. */
4399 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
4401 /* We now have determined the sizes of the various dynamic sections.
4402 Allocate memory for them. */
4404 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4406 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4411 || s
== htab
->sgotplt
)
4413 /* Strip this section if we don't need it; see the
4416 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4418 if (s
->_raw_size
!= 0 && s
!= htab
->srelplt
)
4421 /* We use the reloc_count field as a counter if we need
4422 to copy relocs into the output file. */
4427 /* It's not one of our sections, so don't allocate space. */
4431 if (s
->_raw_size
== 0)
4433 /* If we don't need this section, strip it from the
4434 output file. This is mostly to handle .rela.bss and
4435 .rela.plt. We must create both sections in
4436 create_dynamic_sections, because they must be created
4437 before the linker maps input sections to output
4438 sections. The linker does that before
4439 adjust_dynamic_symbol is called, and it is that
4440 function which decides whether anything needs to go
4441 into these sections. */
4443 _bfd_strip_section_from_output (info
, s
);
4447 /* Allocate memory for the section contents. We use bfd_zalloc
4448 here in case unused entries are not reclaimed before the
4449 section's contents are written out. This should not happen,
4450 but this way if it does, we get a R_SH_NONE reloc instead
4452 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4453 if (s
->contents
== NULL
)
4457 if (htab
->root
.dynamic_sections_created
)
4459 /* Add some entries to the .dynamic section. We fill in the
4460 values later, in sh_elf_finish_dynamic_sections, but we
4461 must add the entries now so that we get the correct size for
4462 the .dynamic section. The DT_DEBUG entry is filled in by the
4463 dynamic linker and used by the debugger. */
4464 #define add_dynamic_entry(TAG, VAL) \
4465 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4469 if (! add_dynamic_entry (DT_DEBUG
, 0))
4473 if (htab
->splt
->_raw_size
!= 0)
4475 if (! add_dynamic_entry (DT_PLTGOT
, 0)
4476 || ! add_dynamic_entry (DT_PLTRELSZ
, 0)
4477 || ! add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4478 || ! add_dynamic_entry (DT_JMPREL
, 0))
4484 if (! add_dynamic_entry (DT_RELA
, 0)
4485 || ! add_dynamic_entry (DT_RELASZ
, 0)
4486 || ! add_dynamic_entry (DT_RELAENT
,
4487 sizeof (Elf32_External_Rela
)))
4490 /* If any dynamic relocs apply to a read-only section,
4491 then we need a DT_TEXTREL entry. */
4492 if ((info
->flags
& DF_TEXTREL
) == 0)
4493 elf_link_hash_traverse (&htab
->root
, readonly_dynrelocs
,
4496 if ((info
->flags
& DF_TEXTREL
) != 0)
4498 if (! add_dynamic_entry (DT_TEXTREL
, 0))
4503 #undef add_dynamic_entry
4508 /* Relocate an SH ELF section. */
4511 sh_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4512 contents
, relocs
, local_syms
, local_sections
)
4514 struct bfd_link_info
*info
;
4516 asection
*input_section
;
4518 Elf_Internal_Rela
*relocs
;
4519 Elf_Internal_Sym
*local_syms
;
4520 asection
**local_sections
;
4522 struct elf_sh_link_hash_table
*htab
;
4523 Elf_Internal_Shdr
*symtab_hdr
;
4524 struct elf_link_hash_entry
**sym_hashes
;
4525 Elf_Internal_Rela
*rel
, *relend
;
4527 bfd_vma
*local_got_offsets
;
4534 htab
= sh_elf_hash_table (info
);
4535 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4536 sym_hashes
= elf_sym_hashes (input_bfd
);
4537 dynobj
= htab
->root
.dynobj
;
4538 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4541 sgotplt
= htab
->sgotplt
;
4547 relend
= relocs
+ input_section
->reloc_count
;
4548 for (; rel
< relend
; rel
++)
4551 reloc_howto_type
*howto
;
4552 unsigned long r_symndx
;
4553 Elf_Internal_Sym
*sym
;
4555 struct elf_link_hash_entry
*h
;
4557 bfd_vma addend
= (bfd_vma
) 0;
4558 bfd_reloc_status_type r
;
4559 int seen_stt_datalabel
= 0;
4563 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4565 r_type
= ELF32_R_TYPE (rel
->r_info
);
4567 /* Many of the relocs are only used for relaxing, and are
4568 handled entirely by the relaxation code. */
4569 if (r_type
> (int) R_SH_LAST_INVALID_RELOC
4570 && r_type
< (int) R_SH_LOOP_START
)
4572 if (r_type
== (int) R_SH_NONE
)
4576 || r_type
>= R_SH_max
4577 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
4578 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
4579 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_3
4580 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_3
)
4581 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_4
4582 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_4
)
4583 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_5
4584 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_5
)
4585 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_2
4586 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_2
))
4588 bfd_set_error (bfd_error_bad_value
);
4592 howto
= sh_elf_howto_table
+ r_type
;
4594 /* For relocs that aren't partial_inplace, we get the addend from
4596 if (! howto
->partial_inplace
)
4597 addend
= rel
->r_addend
;
4602 if (r_symndx
< symtab_hdr
->sh_info
)
4604 sym
= local_syms
+ r_symndx
;
4605 sec
= local_sections
[r_symndx
];
4606 relocation
= (sec
->output_section
->vma
4607 + sec
->output_offset
4609 /* A local symbol never has STO_SH5_ISA32, so we don't need
4610 datalabel processing here. Make sure this does not change
4612 if ((sym
->st_other
& STO_SH5_ISA32
) != 0)
4613 ((*info
->callbacks
->reloc_dangerous
)
4615 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4616 input_bfd
, input_section
, rel
->r_offset
));
4617 if (info
->relocateable
)
4619 /* This is a relocateable link. We don't have to change
4620 anything, unless the reloc is against a section symbol,
4621 in which case we have to adjust according to where the
4622 section symbol winds up in the output section. */
4623 sym
= local_syms
+ r_symndx
;
4624 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4626 if (! howto
->partial_inplace
)
4628 /* For relocations with the addend in the
4629 relocation, we need just to update the addend.
4630 All real relocs are of type partial_inplace; this
4631 code is mostly for completeness. */
4632 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
4637 /* Relocs of type partial_inplace need to pick up the
4638 contents in the contents and add the offset resulting
4639 from the changed location of the section symbol.
4640 Using _bfd_final_link_relocate (e.g. goto
4641 final_link_relocate) here would be wrong, because
4642 relocations marked pc_relative would get the current
4643 location subtracted, and we must only do that at the
4645 r
= _bfd_relocate_contents (howto
, input_bfd
,
4648 contents
+ rel
->r_offset
);
4649 goto relocation_done
;
4654 else if (! howto
->partial_inplace
)
4656 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
4657 addend
= rel
->r_addend
;
4659 else if ((sec
->flags
& SEC_MERGE
)
4660 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4664 if (howto
->rightshift
|| howto
->src_mask
!= 0xffffffff)
4666 (*_bfd_error_handler
)
4667 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
4668 bfd_archive_filename (input_bfd
),
4669 bfd_get_section_name (input_bfd
, input_section
),
4670 (long) rel
->r_offset
, howto
->name
);
4674 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4677 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
4679 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
4680 bfd_put_32 (input_bfd
, addend
, contents
+ rel
->r_offset
);
4686 /* Section symbol are never (?) placed in the hash table, so
4687 we can just ignore hash relocations when creating a
4688 relocateable object file. */
4689 if (info
->relocateable
)
4692 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4693 while (h
->root
.type
== bfd_link_hash_indirect
4694 || h
->root
.type
== bfd_link_hash_warning
)
4696 #ifdef INCLUDE_SHMEDIA
4697 /* If the reference passes a symbol marked with
4698 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4700 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
4702 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4704 if (h
->root
.type
== bfd_link_hash_defined
4705 || h
->root
.type
== bfd_link_hash_defweak
)
4709 dyn
= htab
->root
.dynamic_sections_created
;
4710 sec
= h
->root
.u
.def
.section
;
4711 /* In these cases, we don't need the relocation value.
4712 We check specially because in some obscure cases
4713 sec->output_section will be NULL. */
4714 if (r_type
== R_SH_GOTPC
4715 || r_type
== R_SH_GOTPC_LOW16
4716 || r_type
== R_SH_GOTPC_MEDLOW16
4717 || r_type
== R_SH_GOTPC_MEDHI16
4718 || r_type
== R_SH_GOTPC_HI16
4719 || ((r_type
== R_SH_PLT32
4720 || r_type
== R_SH_PLT_LOW16
4721 || r_type
== R_SH_PLT_MEDLOW16
4722 || r_type
== R_SH_PLT_MEDHI16
4723 || r_type
== R_SH_PLT_HI16
)
4724 && h
->plt
.offset
!= (bfd_vma
) -1)
4725 || ((r_type
== R_SH_GOT32
4726 || r_type
== R_SH_GOT_LOW16
4727 || r_type
== R_SH_GOT_MEDLOW16
4728 || r_type
== R_SH_GOT_MEDHI16
4729 || r_type
== R_SH_GOT_HI16
)
4730 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
4732 || (! info
->symbolic
&& h
->dynindx
!= -1)
4733 || (h
->elf_link_hash_flags
4734 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4735 /* The cases above are those in which relocation is
4736 overwritten in the switch block below. The cases
4737 below are those in which we must defer relocation
4738 to run-time, because we can't resolve absolute
4739 addresses when creating a shared library. */
4741 && ((! info
->symbolic
&& h
->dynindx
!= -1)
4742 || (h
->elf_link_hash_flags
4743 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
4744 && ((r_type
== R_SH_DIR32
4745 && (h
->elf_link_hash_flags
4746 & ELF_LINK_FORCED_LOCAL
) == 0)
4747 || r_type
== R_SH_REL32
)
4748 && ((input_section
->flags
& SEC_ALLOC
) != 0
4749 /* DWARF will emit R_SH_DIR32 relocations in its
4750 sections against symbols defined externally
4751 in shared libraries. We can't do anything
4753 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
4754 && (h
->elf_link_hash_flags
4755 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)))
4756 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4757 sections because such sections are not SEC_ALLOC and
4758 thus ld.so will not process them. */
4759 || (sec
->output_section
== NULL
4760 && ((input_section
->flags
& SEC_DEBUGGING
) != 0
4761 && (h
->elf_link_hash_flags
4762 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
4763 || (sec
->output_section
== NULL
4764 && (sh_elf_hash_entry (h
)->tls_type
== GOT_TLS_IE
4765 || sh_elf_hash_entry (h
)->tls_type
== GOT_TLS_GD
)))
4767 else if (sec
->output_section
== NULL
)
4769 (*_bfd_error_handler
)
4770 (_("%s: unresolvable relocation against symbol `%s' from %s section"),
4771 bfd_archive_filename (input_bfd
), h
->root
.root
.string
,
4772 bfd_get_section_name (input_bfd
, input_section
));
4776 relocation
= ((h
->root
.u
.def
.value
4777 + sec
->output_section
->vma
4778 + sec
->output_offset
)
4779 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4780 symbol value, unless we've seen
4781 STT_DATALABEL on the way to it. */
4782 | ((h
->other
& STO_SH5_ISA32
) != 0
4783 && ! seen_stt_datalabel
));
4785 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4787 else if (info
->shared
4788 && (! info
->symbolic
|| info
->allow_shlib_undefined
)
4789 && ! info
->no_undefined
4790 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4794 if (! ((*info
->callbacks
->undefined_symbol
)
4795 (info
, h
->root
.root
.string
, input_bfd
,
4796 input_section
, rel
->r_offset
,
4797 (!info
->shared
|| info
->no_undefined
4798 || ELF_ST_VISIBILITY (h
->other
)))))
4804 switch ((int) r_type
)
4806 final_link_relocate
:
4807 /* COFF relocs don't use the addend. The addend is used for
4808 R_SH_DIR32 to be compatible with other compilers. */
4809 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4810 contents
, rel
->r_offset
,
4811 relocation
, addend
);
4816 goto final_link_relocate
;
4821 /* If the reloc is against the start of this section, then
4822 the assembler has already taken care of it and the reloc
4823 is here only to assist in relaxing. If the reloc is not
4824 against the start of this section, then it's against an
4825 external symbol and we must deal with it ourselves. */
4826 if (input_section
->output_section
->vma
+ input_section
->output_offset
4829 int disp
= (relocation
4830 - input_section
->output_section
->vma
4831 - input_section
->output_offset
4837 case R_SH_DIR8WPZ
: mask
= 1; break;
4838 case R_SH_DIR8WPL
: mask
= 3; break;
4839 default: mask
= 0; break;
4843 ((*_bfd_error_handler
)
4844 (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4845 bfd_archive_filename (input_section
->owner
),
4846 (unsigned long) rel
->r_offset
));
4847 bfd_set_error (bfd_error_bad_value
);
4851 goto final_link_relocate
;
4857 #ifdef INCLUDE_SHMEDIA
4858 if (shmedia_prepare_reloc (info
, input_bfd
, input_section
,
4859 contents
, rel
, &relocation
))
4860 goto final_link_relocate
;
4862 bfd_set_error (bfd_error_bad_value
);
4869 && (input_section
->flags
& SEC_ALLOC
) != 0
4870 && (r_type
!= R_SH_REL32
4873 && (! info
->symbolic
4874 || (h
->elf_link_hash_flags
4875 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
4877 Elf_Internal_Rela outrel
;
4879 bfd_boolean skip
, relocate
;
4881 /* When generating a shared object, these relocations
4882 are copied into the output file to be resolved at run
4889 name
= (bfd_elf_string_from_elf_section
4891 elf_elfheader (input_bfd
)->e_shstrndx
,
4892 elf_section_data (input_section
)->rel_hdr
.sh_name
));
4896 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
4897 && strcmp (bfd_get_section_name (input_bfd
,
4901 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4902 BFD_ASSERT (sreloc
!= NULL
);
4909 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4911 if (outrel
.r_offset
== (bfd_vma
) -1)
4913 else if (outrel
.r_offset
== (bfd_vma
) -2)
4914 skip
= TRUE
, relocate
= TRUE
;
4915 outrel
.r_offset
+= (input_section
->output_section
->vma
4916 + input_section
->output_offset
);
4919 memset (&outrel
, 0, sizeof outrel
);
4920 else if (r_type
== R_SH_REL32
)
4922 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
4923 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_REL32
);
4925 = bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4929 /* h->dynindx may be -1 if this symbol was marked to
4932 || ((info
->symbolic
|| h
->dynindx
== -1)
4933 && (h
->elf_link_hash_flags
4934 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
4937 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
4939 = relocation
+ bfd_get_32 (input_bfd
,
4940 contents
+ rel
->r_offset
);
4944 BFD_ASSERT (h
->dynindx
!= -1);
4945 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_DIR32
);
4947 = relocation
+ bfd_get_32 (input_bfd
,
4948 contents
+ rel
->r_offset
);
4952 loc
= sreloc
->contents
;
4953 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4954 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4956 /* If this reloc is against an external symbol, we do
4957 not want to fiddle with the addend. Otherwise, we
4958 need to include the symbol value so that it becomes
4959 an addend for the dynamic reloc. */
4963 goto final_link_relocate
;
4966 #ifdef INCLUDE_SHMEDIA
4967 case R_SH_GOTPLT_LOW16
:
4968 case R_SH_GOTPLT_MEDLOW16
:
4969 case R_SH_GOTPLT_MEDHI16
:
4970 case R_SH_GOTPLT_HI16
:
4971 case R_SH_GOTPLT10BY4
:
4972 case R_SH_GOTPLT10BY8
:
4974 /* Relocation is to the entry for this symbol in the
4975 procedure linkage table. */
4978 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
4982 || h
->plt
.offset
== (bfd_vma
) -1
4983 || h
->got
.offset
!= (bfd_vma
) -1)
4986 /* Relocation is to the entry for this symbol in the global
4987 offset table extension for the procedure linkage table. */
4989 BFD_ASSERT (sgotplt
!= NULL
);
4990 relocation
= (sgotplt
->output_offset
4991 + ((h
->plt
.offset
/ elf_sh_sizeof_plt (info
)
4995 relocation
-= GOT_BIAS
;
4998 goto final_link_relocate
;
5002 #ifdef INCLUDE_SHMEDIA
5003 case R_SH_GOT_LOW16
:
5004 case R_SH_GOT_MEDLOW16
:
5005 case R_SH_GOT_MEDHI16
:
5010 /* Relocation is to the entry for this symbol in the global
5013 BFD_ASSERT (sgot
!= NULL
);
5019 off
= h
->got
.offset
;
5020 #ifdef INCLUDE_SHMEDIA
5021 if (seen_stt_datalabel
)
5023 struct elf_sh_link_hash_entry
*hsh
;
5025 hsh
= (struct elf_sh_link_hash_entry
*)h
;
5026 off
= hsh
->datalabel_got
.offset
;
5029 BFD_ASSERT (off
!= (bfd_vma
) -1);
5031 dyn
= htab
->root
.dynamic_sections_created
;
5032 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
5034 && (info
->symbolic
|| h
->dynindx
== -1
5035 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
5036 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
5038 /* This is actually a static link, or it is a
5039 -Bsymbolic link and the symbol is defined
5040 locally, or the symbol was forced to be local
5041 because of a version file. We must initialize
5042 this entry in the global offset table. Since the
5043 offset must always be a multiple of 4, we use the
5044 least significant bit to record whether we have
5045 initialized it already.
5047 When doing a dynamic link, we create a .rela.got
5048 relocation entry to initialize the value. This
5049 is done in the finish_dynamic_symbol routine. */
5054 bfd_put_32 (output_bfd
, relocation
,
5055 sgot
->contents
+ off
);
5056 #ifdef INCLUDE_SHMEDIA
5057 if (seen_stt_datalabel
)
5059 struct elf_sh_link_hash_entry
*hsh
;
5061 hsh
= (struct elf_sh_link_hash_entry
*)h
;
5062 hsh
->datalabel_got
.offset
|= 1;
5070 relocation
= sgot
->output_offset
+ off
;
5074 #ifdef INCLUDE_SHMEDIA
5077 BFD_ASSERT (local_got_offsets
!= NULL
5078 && (local_got_offsets
[symtab_hdr
->sh_info
5082 off
= local_got_offsets
[symtab_hdr
->sh_info
5088 BFD_ASSERT (local_got_offsets
!= NULL
5089 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
5091 off
= local_got_offsets
[r_symndx
];
5092 #ifdef INCLUDE_SHMEDIA
5096 /* The offset must always be a multiple of 4. We use
5097 the least significant bit to record whether we have
5098 already generated the necessary reloc. */
5103 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
5107 Elf_Internal_Rela outrel
;
5110 if (srelgot
== NULL
)
5112 srelgot
= bfd_get_section_by_name (dynobj
,
5114 BFD_ASSERT (srelgot
!= NULL
);
5117 outrel
.r_offset
= (sgot
->output_section
->vma
5118 + sgot
->output_offset
5120 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
5121 outrel
.r_addend
= relocation
;
5122 loc
= srelgot
->contents
;
5123 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5124 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5127 #ifdef INCLUDE_SHMEDIA
5129 local_got_offsets
[symtab_hdr
->sh_info
+ r_symndx
] |= 1;
5132 local_got_offsets
[r_symndx
] |= 1;
5135 relocation
= sgot
->output_offset
+ off
;
5139 relocation
-= GOT_BIAS
;
5142 goto final_link_relocate
;
5145 #ifdef INCLUDE_SHMEDIA
5146 case R_SH_GOTOFF_LOW16
:
5147 case R_SH_GOTOFF_MEDLOW16
:
5148 case R_SH_GOTOFF_MEDHI16
:
5149 case R_SH_GOTOFF_HI16
:
5151 /* Relocation is relative to the start of the global offset
5154 BFD_ASSERT (sgot
!= NULL
);
5156 /* Note that sgot->output_offset is not involved in this
5157 calculation. We always want the start of .got. If we
5158 defined _GLOBAL_OFFSET_TABLE in a different way, as is
5159 permitted by the ABI, we might have to change this
5161 relocation
-= sgot
->output_section
->vma
;
5164 relocation
-= GOT_BIAS
;
5167 addend
= rel
->r_addend
;
5169 goto final_link_relocate
;
5172 #ifdef INCLUDE_SHMEDIA
5173 case R_SH_GOTPC_LOW16
:
5174 case R_SH_GOTPC_MEDLOW16
:
5175 case R_SH_GOTPC_MEDHI16
:
5176 case R_SH_GOTPC_HI16
:
5178 /* Use global offset table as symbol value. */
5180 BFD_ASSERT (sgot
!= NULL
);
5181 relocation
= sgot
->output_section
->vma
;
5184 relocation
+= GOT_BIAS
;
5187 addend
= rel
->r_addend
;
5189 goto final_link_relocate
;
5192 #ifdef INCLUDE_SHMEDIA
5193 case R_SH_PLT_LOW16
:
5194 case R_SH_PLT_MEDLOW16
:
5195 case R_SH_PLT_MEDHI16
:
5198 /* Relocation is to the entry for this symbol in the
5199 procedure linkage table. */
5201 /* Resolve a PLT reloc against a local symbol directly,
5202 without using the procedure linkage table. */
5204 goto final_link_relocate
;
5206 if (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
5207 goto final_link_relocate
;
5209 if (h
->plt
.offset
== (bfd_vma
) -1)
5211 /* We didn't make a PLT entry for this symbol. This
5212 happens when statically linking PIC code, or when
5213 using -Bsymbolic. */
5214 goto final_link_relocate
;
5217 BFD_ASSERT (splt
!= NULL
);
5218 relocation
= (splt
->output_section
->vma
5219 + splt
->output_offset
5222 #ifdef INCLUDE_SHMEDIA
5226 addend
= rel
->r_addend
;
5228 goto final_link_relocate
;
5230 case R_SH_LOOP_START
:
5232 static bfd_vma start
, end
;
5234 start
= (relocation
+ rel
->r_addend
5235 - (sec
->output_section
->vma
+ sec
->output_offset
));
5236 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5237 rel
->r_offset
, sec
, start
, end
);
5241 end
= (relocation
+ rel
->r_addend
5242 - (sec
->output_section
->vma
+ sec
->output_offset
));
5243 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5244 rel
->r_offset
, sec
, start
, end
);
5248 case R_SH_TLS_GD_32
:
5249 case R_SH_TLS_IE_32
:
5250 r_type
= sh_elf_optimized_tls_reloc (info
, r_type
, h
== NULL
);
5251 tls_type
= GOT_UNKNOWN
;
5252 if (h
== NULL
&& local_got_offsets
)
5253 tls_type
= sh_elf_local_got_tls_type (input_bfd
) [r_symndx
];
5256 tls_type
= sh_elf_hash_entry (h
)->tls_type
;
5258 && (h
->dynindx
== -1
5259 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
5260 && (tls_type
== GOT_TLS_IE
5261 || sh_elf_hash_entry (h
)->tls_tpoff32
))
5262 r_type
= R_SH_TLS_LE_32
;
5265 if (r_type
== R_SH_TLS_GD_32
&& tls_type
== GOT_TLS_IE
)
5266 r_type
= R_SH_TLS_IE_32
;
5268 if (r_type
== R_SH_TLS_LE_32
)
5271 unsigned short insn
;
5273 Elf_Internal_Rela outrel
;
5276 if (ELF32_R_TYPE (rel
->r_info
) == R_SH_TLS_GD_32
)
5278 /* GD->LE transition:
5279 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5280 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5281 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5283 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5285 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
5287 offset
= rel
->r_offset
;
5288 BFD_ASSERT (offset
>= 16);
5289 /* Size of GD instructions is 16 or 18. */
5291 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5292 if ((insn
& 0xff00) == 0xc700)
5294 BFD_ASSERT (offset
>= 2);
5296 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5299 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5300 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5301 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5302 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5303 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5304 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5305 BFD_ASSERT (insn
== 0x310c);
5306 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5307 BFD_ASSERT (insn
== 0x410b);
5308 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5309 BFD_ASSERT (insn
== 0x34cc);
5311 bfd_put_16 (output_bfd
, 0x0012, contents
+ offset
+ 2);
5312 bfd_put_16 (output_bfd
, 0x304c, contents
+ offset
+ 4);
5313 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 6);
5314 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5315 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5321 /* IE->LE transition:
5322 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5323 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5325 mov.l .Ln,rM; stc gbr,rN; nop; ...;
5328 offset
= rel
->r_offset
;
5329 BFD_ASSERT (offset
>= 16);
5330 /* Size of IE instructions is 10 or 12. */
5332 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5333 if ((insn
& 0xf0ff) == 0x0012)
5335 BFD_ASSERT (offset
>= 2);
5337 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5340 BFD_ASSERT ((insn
& 0xff00) == 0xd000);
5341 index
= insn
& 0x00ff;
5342 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5343 BFD_ASSERT ((insn
& 0xf0ff) == 0x0012);
5344 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5345 BFD_ASSERT ((insn
& 0xf0ff) == 0x00ce);
5346 insn
= 0xd000 | (insn
& 0x0f00) | index
;
5347 bfd_put_16 (output_bfd
, insn
, contents
+ offset
+ 0);
5348 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 4);
5355 name
= (bfd_elf_string_from_elf_section
5357 elf_elfheader (input_bfd
)->e_shstrndx
,
5358 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5362 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5363 && strcmp (bfd_get_section_name (input_bfd
,
5367 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5368 BFD_ASSERT (sreloc
!= NULL
);
5371 indx
= (h
&& h
->dynindx
!= -1) ? h
->dynindx
: 0;
5372 outrel
.r_offset
= (input_section
->output_section
->vma
5373 + input_section
->output_offset
5375 outrel
.r_info
= ELF32_R_INFO (indx
, R_SH_TLS_TPOFF32
);
5377 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5379 outrel
.r_addend
= 0;
5381 loc
= sreloc
->contents
;
5382 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5383 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5392 off
= h
->got
.offset
;
5395 if (local_got_offsets
== NULL
)
5398 off
= local_got_offsets
[r_symndx
];
5405 Elf_Internal_Rela outrel
;
5409 if (srelgot
== NULL
)
5411 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
5412 BFD_ASSERT (srelgot
!= NULL
);
5415 outrel
.r_offset
= (sgot
->output_section
->vma
5416 + sgot
->output_offset
+ off
);
5418 indx
= (h
&& h
->dynindx
!= -1) ? h
->dynindx
: 0;
5419 dr_type
= (r_type
== R_SH_TLS_GD_32
? R_SH_TLS_DTPMOD32
:
5421 if (dr_type
== R_SH_TLS_TPOFF32
&& indx
== 0)
5422 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5424 outrel
.r_addend
= 0;
5425 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
5426 loc
= srelgot
->contents
;
5427 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5428 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5430 if (r_type
== R_SH_TLS_GD_32
)
5434 bfd_put_32 (output_bfd
,
5435 relocation
- dtpoff_base (info
),
5436 sgot
->contents
+ off
+ 4);
5440 outrel
.r_info
= ELF32_R_INFO (indx
,
5442 outrel
.r_offset
+= 4;
5443 outrel
.r_addend
= 0;
5444 srelgot
->reloc_count
++;
5445 loc
+= sizeof (Elf32_External_Rela
);
5446 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5453 local_got_offsets
[r_symndx
] |= 1;
5456 if (off
>= (bfd_vma
) -2)
5459 if (r_type
== (int) ELF32_R_TYPE (rel
->r_info
))
5460 relocation
= sgot
->output_offset
+ off
;
5464 unsigned short insn
;
5466 /* GD->IE transition:
5467 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5468 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5469 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5471 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5472 nop; nop; bra 3f; nop; .align 2;
5473 1: .long x@TPOFF; 2:...; 3:. */
5475 offset
= rel
->r_offset
;
5476 BFD_ASSERT (offset
>= 16);
5477 /* Size of GD instructions is 16 or 18. */
5479 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5480 if ((insn
& 0xff00) == 0xc700)
5482 BFD_ASSERT (offset
>= 2);
5484 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5487 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5489 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
5490 bfd_put_16 (output_bfd
, insn
& 0xf0ff, contents
+ offset
);
5492 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5493 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5494 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5495 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5496 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5497 BFD_ASSERT (insn
== 0x310c);
5498 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5499 BFD_ASSERT (insn
== 0x410b);
5500 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5501 BFD_ASSERT (insn
== 0x34cc);
5503 bfd_put_16 (output_bfd
, 0x0412, contents
+ offset
+ 2);
5504 bfd_put_16 (output_bfd
, 0x00ce, contents
+ offset
+ 4);
5505 bfd_put_16 (output_bfd
, 0x304c, contents
+ offset
+ 6);
5506 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5507 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5509 bfd_put_32 (output_bfd
, sgot
->output_offset
+ off
,
5510 contents
+ rel
->r_offset
);
5515 addend
= rel
->r_addend
;
5517 goto final_link_relocate
;
5519 case R_SH_TLS_LD_32
:
5523 unsigned short insn
;
5525 /* LD->LE transition:
5526 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5527 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5528 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5530 stc gbr,r0; nop; nop; nop;
5531 nop; nop; bra 3f; ...; 3:. */
5533 offset
= rel
->r_offset
;
5534 BFD_ASSERT (offset
>= 16);
5535 /* Size of LD instructions is 16 or 18. */
5537 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5538 if ((insn
& 0xff00) == 0xc700)
5540 BFD_ASSERT (offset
>= 2);
5542 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5545 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5546 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5547 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5548 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5549 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5550 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5551 BFD_ASSERT (insn
== 0x310c);
5552 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5553 BFD_ASSERT (insn
== 0x410b);
5554 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5555 BFD_ASSERT (insn
== 0x34cc);
5557 bfd_put_16 (output_bfd
, 0x0012, contents
+ offset
+ 0);
5558 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 2);
5559 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 4);
5560 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 6);
5561 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5562 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5571 off
= htab
->tls_ldm_got
.offset
;
5576 Elf_Internal_Rela outrel
;
5579 srelgot
= htab
->srelgot
;
5580 if (srelgot
== NULL
)
5583 outrel
.r_offset
= (sgot
->output_section
->vma
5584 + sgot
->output_offset
+ off
);
5585 outrel
.r_addend
= 0;
5586 outrel
.r_info
= ELF32_R_INFO (0, R_SH_TLS_DTPMOD32
);
5587 loc
= srelgot
->contents
;
5588 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5589 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5590 htab
->tls_ldm_got
.offset
|= 1;
5593 relocation
= sgot
->output_offset
+ off
;
5594 addend
= rel
->r_addend
;
5596 goto final_link_relocate
;
5598 case R_SH_TLS_LDO_32
:
5602 Elf_Internal_Rela outrel
;
5609 name
= (bfd_elf_string_from_elf_section
5611 elf_elfheader (input_bfd
)->e_shstrndx
,
5612 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5616 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5617 && strcmp (bfd_get_section_name (input_bfd
,
5621 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5622 BFD_ASSERT (sreloc
!= NULL
);
5625 indx
= (h
&& h
->dynindx
!= -1) ? h
->dynindx
: 0;
5626 outrel
.r_offset
= (input_section
->output_section
->vma
5627 + input_section
->output_offset
5629 outrel
.r_info
= ELF32_R_INFO (indx
, R_SH_TLS_TPOFF32
);
5631 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5633 outrel
.r_addend
= 0;
5635 loc
= sreloc
->contents
;
5636 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5637 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5641 relocation
-= dtpoff_base (info
);
5643 addend
= rel
->r_addend
;
5644 goto final_link_relocate
;
5646 case R_SH_TLS_LE_32
:
5649 Elf_Internal_Rela outrel
;
5656 name
= (bfd_elf_string_from_elf_section
5658 elf_elfheader (input_bfd
)->e_shstrndx
,
5659 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5663 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5664 && strcmp (bfd_get_section_name (input_bfd
,
5668 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5669 BFD_ASSERT (sreloc
!= NULL
);
5672 indx
= (h
&& h
->dynindx
!= -1) ? h
->dynindx
: 0;
5673 outrel
.r_offset
= (input_section
->output_section
->vma
5674 + input_section
->output_offset
5676 outrel
.r_info
= ELF32_R_INFO (indx
, R_SH_TLS_TPOFF32
);
5678 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5680 outrel
.r_addend
= 0;
5682 loc
= sreloc
->contents
;
5683 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5684 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5690 if (r
!= bfd_reloc_ok
)
5695 case bfd_reloc_outofrange
:
5697 case bfd_reloc_overflow
:
5702 name
= h
->root
.root
.string
;
5705 name
= (bfd_elf_string_from_elf_section
5706 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5710 name
= bfd_section_name (input_bfd
, sec
);
5712 if (! ((*info
->callbacks
->reloc_overflow
)
5713 (info
, name
, howto
->name
, (bfd_vma
) 0,
5714 input_bfd
, input_section
, rel
->r_offset
)))
5725 /* This is a version of bfd_generic_get_relocated_section_contents
5726 which uses sh_elf_relocate_section. */
5729 sh_elf_get_relocated_section_contents (output_bfd
, link_info
, link_order
,
5730 data
, relocateable
, symbols
)
5732 struct bfd_link_info
*link_info
;
5733 struct bfd_link_order
*link_order
;
5735 bfd_boolean relocateable
;
5738 Elf_Internal_Shdr
*symtab_hdr
;
5739 asection
*input_section
= link_order
->u
.indirect
.section
;
5740 bfd
*input_bfd
= input_section
->owner
;
5741 asection
**sections
= NULL
;
5742 Elf_Internal_Rela
*internal_relocs
= NULL
;
5743 Elf_Internal_Sym
*isymbuf
= NULL
;
5745 /* We only need to handle the case of relaxing, or of having a
5746 particular set of section contents, specially. */
5748 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
5749 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
5754 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5756 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
5757 (size_t) input_section
->_raw_size
);
5759 if ((input_section
->flags
& SEC_RELOC
) != 0
5760 && input_section
->reloc_count
> 0)
5763 Elf_Internal_Sym
*isym
, *isymend
;
5766 internal_relocs
= (_bfd_elf32_link_read_relocs
5767 (input_bfd
, input_section
, (PTR
) NULL
,
5768 (Elf_Internal_Rela
*) NULL
, FALSE
));
5769 if (internal_relocs
== NULL
)
5772 if (symtab_hdr
->sh_info
!= 0)
5774 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5775 if (isymbuf
== NULL
)
5776 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
5777 symtab_hdr
->sh_info
, 0,
5779 if (isymbuf
== NULL
)
5783 amt
= symtab_hdr
->sh_info
;
5784 amt
*= sizeof (asection
*);
5785 sections
= (asection
**) bfd_malloc (amt
);
5786 if (sections
== NULL
&& amt
!= 0)
5789 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
5790 for (isym
= isymbuf
, secpp
= sections
; isym
< isymend
; ++isym
, ++secpp
)
5794 if (isym
->st_shndx
== SHN_UNDEF
)
5795 isec
= bfd_und_section_ptr
;
5796 else if (isym
->st_shndx
== SHN_ABS
)
5797 isec
= bfd_abs_section_ptr
;
5798 else if (isym
->st_shndx
== SHN_COMMON
)
5799 isec
= bfd_com_section_ptr
;
5801 isec
= bfd_section_from_elf_index (input_bfd
, isym
->st_shndx
);
5806 if (! sh_elf_relocate_section (output_bfd
, link_info
, input_bfd
,
5807 input_section
, data
, internal_relocs
,
5811 if (sections
!= NULL
)
5814 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5816 if (elf_section_data (input_section
)->relocs
!= internal_relocs
)
5817 free (internal_relocs
);
5823 if (sections
!= NULL
)
5826 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5828 if (internal_relocs
!= NULL
5829 && elf_section_data (input_section
)->relocs
!= internal_relocs
)
5830 free (internal_relocs
);
5834 /* Return the base VMA address which should be subtracted from real addresses
5835 when resolving @dtpoff relocation.
5836 This is PT_TLS segment p_vaddr. */
5840 struct bfd_link_info
*info
;
5842 /* If tls_segment is NULL, we should have signalled an error already. */
5843 if (elf_hash_table (info
)->tls_segment
== NULL
)
5845 return elf_hash_table (info
)->tls_segment
->start
;
5849 sh_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
5851 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
5852 Elf_Internal_Rela
*rel
;
5853 struct elf_link_hash_entry
*h
;
5854 Elf_Internal_Sym
*sym
;
5858 switch (ELF32_R_TYPE (rel
->r_info
))
5860 case R_SH_GNU_VTINHERIT
:
5861 case R_SH_GNU_VTENTRY
:
5865 #ifdef INCLUDE_SHMEDIA
5866 while (h
->root
.type
== bfd_link_hash_indirect
5867 && h
->root
.u
.i
.link
)
5868 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5870 switch (h
->root
.type
)
5872 case bfd_link_hash_defined
:
5873 case bfd_link_hash_defweak
:
5874 return h
->root
.u
.def
.section
;
5876 case bfd_link_hash_common
:
5877 return h
->root
.u
.c
.p
->section
;
5885 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5890 /* Update the got entry reference counts for the section being removed. */
5893 sh_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
5895 struct bfd_link_info
*info
;
5897 const Elf_Internal_Rela
*relocs
;
5899 Elf_Internal_Shdr
*symtab_hdr
;
5900 struct elf_link_hash_entry
**sym_hashes
;
5901 bfd_signed_vma
*local_got_refcounts
;
5902 const Elf_Internal_Rela
*rel
, *relend
;
5903 unsigned long r_symndx
;
5904 struct elf_link_hash_entry
*h
;
5905 struct elf_sh_link_hash_entry
*eh
;
5907 elf_section_data (sec
)->local_dynrel
= NULL
;
5909 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5910 sym_hashes
= elf_sym_hashes (abfd
);
5911 local_got_refcounts
= elf_local_got_refcounts (abfd
);
5913 relend
= relocs
+ sec
->reloc_count
;
5914 for (rel
= relocs
; rel
< relend
; rel
++)
5916 #ifdef INCLUDE_SHMEDIA
5917 int seen_stt_datalabel
= 0;
5920 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5921 if (r_symndx
< symtab_hdr
->sh_info
)
5925 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5926 #ifdef INCLUDE_SHMEDIA
5927 while (h
->root
.type
== bfd_link_hash_indirect
5928 || h
->root
.type
== bfd_link_hash_warning
)
5930 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
5931 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5935 eh
= (struct elf_sh_link_hash_entry
*) h
;
5937 switch (sh_elf_optimized_tls_reloc (info
, ELF32_R_TYPE (rel
->r_info
),
5938 ELF32_R_SYM (rel
->r_info
)
5939 >= symtab_hdr
->sh_info
))
5941 case R_SH_TLS_LD_32
:
5942 if (sh_elf_hash_table (info
)->tls_ldm_got
.refcount
> 0)
5943 sh_elf_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
5949 #ifdef INCLUDE_SHMEDIA
5950 case R_SH_GOT_LOW16
:
5951 case R_SH_GOT_MEDLOW16
:
5952 case R_SH_GOT_MEDHI16
:
5956 case R_SH_GOTOFF_LOW16
:
5957 case R_SH_GOTOFF_MEDLOW16
:
5958 case R_SH_GOTOFF_MEDHI16
:
5959 case R_SH_GOTOFF_HI16
:
5960 case R_SH_GOTPC_LOW16
:
5961 case R_SH_GOTPC_MEDLOW16
:
5962 case R_SH_GOTPC_MEDHI16
:
5963 case R_SH_GOTPC_HI16
:
5965 case R_SH_TLS_GD_32
:
5966 case R_SH_TLS_IE_32
:
5969 #ifdef INCLUDE_SHMEDIA
5970 if (seen_stt_datalabel
)
5972 if (eh
->datalabel_got
.refcount
> 0)
5973 eh
->datalabel_got
.refcount
-= 1;
5977 if (h
->got
.refcount
> 0)
5978 h
->got
.refcount
-= 1;
5980 else if (local_got_refcounts
!= NULL
)
5982 #ifdef INCLUDE_SHMEDIA
5983 if (rel
->r_addend
& 1)
5985 if (local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] > 0)
5986 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] -= 1;
5990 if (local_got_refcounts
[r_symndx
] > 0)
5991 local_got_refcounts
[r_symndx
] -= 1;
5999 struct elf_sh_dyn_relocs
**pp
;
6000 struct elf_sh_dyn_relocs
*p
;
6003 if (!info
->shared
&& h
->plt
.refcount
> 0)
6004 h
->plt
.refcount
-= 1;
6006 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
6009 if (ELF32_R_TYPE (rel
->r_info
) == R_SH_REL32
)
6020 #ifdef INCLUDE_SHMEDIA
6021 case R_SH_PLT_LOW16
:
6022 case R_SH_PLT_MEDLOW16
:
6023 case R_SH_PLT_MEDHI16
:
6028 if (h
->plt
.refcount
> 0)
6029 h
->plt
.refcount
-= 1;
6034 #ifdef INCLUDE_SHMEDIA
6035 case R_SH_GOTPLT_LOW16
:
6036 case R_SH_GOTPLT_MEDLOW16
:
6037 case R_SH_GOTPLT_MEDHI16
:
6038 case R_SH_GOTPLT_HI16
:
6039 case R_SH_GOTPLT10BY4
:
6040 case R_SH_GOTPLT10BY8
:
6044 if (eh
->gotplt_refcount
> 0)
6046 eh
->gotplt_refcount
-= 1;
6047 if (h
->plt
.refcount
> 0)
6048 h
->plt
.refcount
-= 1;
6050 #ifdef INCLUDE_SHMEDIA
6051 else if (seen_stt_datalabel
)
6053 if (eh
->datalabel_got
.refcount
> 0)
6054 eh
->datalabel_got
.refcount
-= 1;
6057 else if (h
->got
.refcount
> 0)
6058 h
->got
.refcount
-= 1;
6060 else if (local_got_refcounts
!= NULL
)
6062 #ifdef INCLUDE_SHMEDIA
6063 if (rel
->r_addend
& 1)
6065 if (local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] > 0)
6066 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] -= 1;
6070 if (local_got_refcounts
[r_symndx
] > 0)
6071 local_got_refcounts
[r_symndx
] -= 1;
6083 /* Copy the extra info we tack onto an elf_link_hash_entry. */
6086 sh_elf_copy_indirect_symbol (bed
, dir
, ind
)
6087 struct elf_backend_data
*bed
;
6088 struct elf_link_hash_entry
*dir
, *ind
;
6090 struct elf_sh_link_hash_entry
*edir
, *eind
;
6091 #ifdef INCLUDE_SHMEDIA
6095 edir
= (struct elf_sh_link_hash_entry
*) dir
;
6096 eind
= (struct elf_sh_link_hash_entry
*) ind
;
6098 if (eind
->dyn_relocs
!= NULL
)
6100 if (edir
->dyn_relocs
!= NULL
)
6102 struct elf_sh_dyn_relocs
**pp
;
6103 struct elf_sh_dyn_relocs
*p
;
6105 BFD_ASSERT (ind
->root
.type
!= bfd_link_hash_indirect
);
6107 /* Add reloc counts against the weak sym to the strong sym
6108 list. Merge any entries against the same section. */
6109 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
6111 struct elf_sh_dyn_relocs
*q
;
6113 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
6114 if (q
->sec
== p
->sec
)
6116 q
->pc_count
+= p
->pc_count
;
6117 q
->count
+= p
->count
;
6124 *pp
= edir
->dyn_relocs
;
6127 edir
->dyn_relocs
= eind
->dyn_relocs
;
6128 eind
->dyn_relocs
= NULL
;
6130 edir
->gotplt_refcount
= eind
->gotplt_refcount
;
6131 eind
->gotplt_refcount
= 0;
6132 #ifdef INCLUDE_SHMEDIA
6133 tmp
= edir
->datalabel_got
.refcount
;
6136 edir
->datalabel_got
.refcount
= eind
->datalabel_got
.refcount
;
6137 eind
->datalabel_got
.refcount
= tmp
;
6140 BFD_ASSERT (eind
->datalabel_got
.refcount
< 1);
6143 if (ind
->root
.type
== bfd_link_hash_indirect
6144 && dir
->got
.refcount
<= 0)
6146 edir
->tls_type
= eind
->tls_type
;
6147 eind
->tls_type
= GOT_UNKNOWN
;
6150 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
6154 sh_elf_optimized_tls_reloc (info
, r_type
, is_local
)
6155 struct bfd_link_info
*info
;
6164 case R_SH_TLS_GD_32
:
6165 case R_SH_TLS_IE_32
:
6167 return R_SH_TLS_LE_32
;
6168 return R_SH_TLS_IE_32
;
6169 case R_SH_TLS_LD_32
:
6170 return R_SH_TLS_LE_32
;
6176 /* Look through the relocs for a section during the first phase.
6177 Since we don't do .gots or .plts, we just need to consider the
6178 virtual table relocs for gc. */
6181 sh_elf_check_relocs (abfd
, info
, sec
, relocs
)
6183 struct bfd_link_info
*info
;
6185 const Elf_Internal_Rela
*relocs
;
6187 Elf_Internal_Shdr
*symtab_hdr
;
6188 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
6189 struct elf_sh_link_hash_table
*htab
;
6190 const Elf_Internal_Rela
*rel
;
6191 const Elf_Internal_Rela
*rel_end
;
6193 bfd_vma
*local_got_offsets
;
6197 unsigned int r_type
;
6198 int tls_type
, old_tls_type
;
6204 if (info
->relocateable
)
6207 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6208 sym_hashes
= elf_sym_hashes (abfd
);
6209 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof (Elf32_External_Sym
);
6210 if (!elf_bad_symtab (abfd
))
6211 sym_hashes_end
-= symtab_hdr
->sh_info
;
6213 htab
= sh_elf_hash_table (info
);
6214 dynobj
= htab
->root
.dynobj
;
6215 local_got_offsets
= elf_local_got_offsets (abfd
);
6217 rel_end
= relocs
+ sec
->reloc_count
;
6218 for (rel
= relocs
; rel
< rel_end
; rel
++)
6220 struct elf_link_hash_entry
*h
;
6221 unsigned long r_symndx
;
6222 #ifdef INCLUDE_SHMEDIA
6223 int seen_stt_datalabel
= 0;
6226 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6227 r_type
= ELF32_R_TYPE (rel
->r_info
);
6229 if (r_symndx
< symtab_hdr
->sh_info
)
6233 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6234 #ifdef INCLUDE_SHMEDIA
6235 while (h
->root
.type
== bfd_link_hash_indirect
6236 || h
->root
.type
== bfd_link_hash_warning
)
6238 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
6239 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6244 r_type
= sh_elf_optimized_tls_reloc (info
, r_type
, h
== NULL
);
6246 && r_type
== R_SH_TLS_IE_32
6248 && h
->root
.type
!= bfd_link_hash_undefined
6249 && h
->root
.type
!= bfd_link_hash_undefweak
6250 && (h
->dynindx
== -1
6251 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
6252 r_type
= R_SH_TLS_LE_32
;
6254 /* Some relocs require a global offset table. */
6255 if (htab
->sgot
== NULL
)
6263 #ifdef INCLUDE_SHMEDIA
6264 case R_SH_GOTPLT_LOW16
:
6265 case R_SH_GOTPLT_MEDLOW16
:
6266 case R_SH_GOTPLT_MEDHI16
:
6267 case R_SH_GOTPLT_HI16
:
6268 case R_SH_GOTPLT10BY4
:
6269 case R_SH_GOTPLT10BY8
:
6270 case R_SH_GOT_LOW16
:
6271 case R_SH_GOT_MEDLOW16
:
6272 case R_SH_GOT_MEDHI16
:
6276 case R_SH_GOTOFF_LOW16
:
6277 case R_SH_GOTOFF_MEDLOW16
:
6278 case R_SH_GOTOFF_MEDHI16
:
6279 case R_SH_GOTOFF_HI16
:
6280 case R_SH_GOTPC_LOW16
:
6281 case R_SH_GOTPC_MEDLOW16
:
6282 case R_SH_GOTPC_MEDHI16
:
6283 case R_SH_GOTPC_HI16
:
6285 case R_SH_TLS_GD_32
:
6286 case R_SH_TLS_LD_32
:
6287 case R_SH_TLS_IE_32
:
6289 htab
->root
.dynobj
= dynobj
= abfd
;
6290 if (! create_got_section (dynobj
, info
))
6301 /* This relocation describes the C++ object vtable hierarchy.
6302 Reconstruct it for later use during GC. */
6303 case R_SH_GNU_VTINHERIT
:
6304 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6308 /* This relocation describes which C++ vtable entries are actually
6309 used. Record for later use during GC. */
6310 case R_SH_GNU_VTENTRY
:
6311 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6316 case R_SH_TLS_IE_32
:
6318 info
->flags
|= DF_STATIC_TLS
;
6321 case R_SH_TLS_GD_32
:
6323 #ifdef INCLUDE_SHMEDIA
6324 case R_SH_GOT_LOW16
:
6325 case R_SH_GOT_MEDLOW16
:
6326 case R_SH_GOT_MEDHI16
:
6334 tls_type
= GOT_NORMAL
;
6336 case R_SH_TLS_GD_32
:
6337 tls_type
= GOT_TLS_GD
;
6339 case R_SH_TLS_IE_32
:
6340 tls_type
= GOT_TLS_IE
;
6346 #ifdef INCLUDE_SHMEDIA
6347 if (seen_stt_datalabel
)
6349 struct elf_sh_link_hash_entry
*eh
6350 = (struct elf_sh_link_hash_entry
*) h
;
6352 eh
->datalabel_got
.refcount
+= 1;
6356 h
->got
.refcount
+= 1;
6357 old_tls_type
= sh_elf_hash_entry (h
)->tls_type
;
6361 bfd_signed_vma
*local_got_refcounts
;
6363 /* This is a global offset table entry for a local
6365 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6366 if (local_got_refcounts
== NULL
)
6370 size
= symtab_hdr
->sh_info
;
6371 size
*= sizeof (bfd_signed_vma
);
6372 #ifdef INCLUDE_SHMEDIA
6373 /* Reserve space for both the datalabel and
6374 codelabel local GOT offsets. */
6377 size
+= symtab_hdr
->sh_info
;
6378 local_got_refcounts
= ((bfd_signed_vma
*)
6379 bfd_zalloc (abfd
, size
));
6380 if (local_got_refcounts
== NULL
)
6382 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
6383 #ifdef INCLUDE_SHMEDIA
6384 /* Take care of both the datalabel and codelabel local
6386 sh_elf_local_got_tls_type (abfd
)
6387 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
6389 sh_elf_local_got_tls_type (abfd
)
6390 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
6393 #ifdef INCLUDE_SHMEDIA
6394 if (rel
->r_addend
& 1)
6395 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] += 1;
6398 local_got_refcounts
[r_symndx
] += 1;
6399 old_tls_type
= sh_elf_local_got_tls_type (abfd
) [r_symndx
];
6402 /* If a TLS symbol is accessed using IE at least once,
6403 there is no point to use dynamic model for it. */
6404 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
6405 && (old_tls_type
!= GOT_TLS_GD
|| tls_type
!= GOT_TLS_IE
))
6407 if (old_tls_type
== GOT_TLS_IE
&& tls_type
== GOT_TLS_GD
)
6408 tls_type
= GOT_TLS_IE
;
6411 (*_bfd_error_handler
)
6412 (_("%s: `%s' accessed both as normal and thread local symbol"),
6413 bfd_archive_filename (abfd
), h
->root
.root
.string
);
6418 if (old_tls_type
!= tls_type
)
6421 sh_elf_hash_entry (h
)->tls_type
= tls_type
;
6423 sh_elf_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
6428 case R_SH_TLS_LD_32
:
6429 sh_elf_hash_table(info
)->tls_ldm_got
.refcount
+= 1;
6433 #ifdef INCLUDE_SHMEDIA
6434 case R_SH_GOTPLT_LOW16
:
6435 case R_SH_GOTPLT_MEDLOW16
:
6436 case R_SH_GOTPLT_MEDHI16
:
6437 case R_SH_GOTPLT_HI16
:
6438 case R_SH_GOTPLT10BY4
:
6439 case R_SH_GOTPLT10BY8
:
6441 /* If this is a local symbol, we resolve it directly without
6442 creating a procedure linkage table entry. */
6445 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
6448 || h
->dynindx
== -1)
6451 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6452 h
->plt
.refcount
+= 1;
6453 ((struct elf_sh_link_hash_entry
*) h
)->gotplt_refcount
+= 1;
6458 #ifdef INCLUDE_SHMEDIA
6459 case R_SH_PLT_LOW16
:
6460 case R_SH_PLT_MEDLOW16
:
6461 case R_SH_PLT_MEDHI16
:
6464 /* This symbol requires a procedure linkage table entry. We
6465 actually build the entry in adjust_dynamic_symbol,
6466 because this might be a case of linking PIC code which is
6467 never referenced by a dynamic object, in which case we
6468 don't need to generate a procedure linkage table entry
6471 /* If this is a local symbol, we resolve it directly without
6472 creating a procedure linkage table entry. */
6476 if (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
6479 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6480 h
->plt
.refcount
+= 1;
6485 if (h
!= NULL
&& ! info
->shared
)
6487 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
6488 h
->plt
.refcount
+= 1;
6491 /* If we are creating a shared library, and this is a reloc
6492 against a global symbol, or a non PC relative reloc
6493 against a local symbol, then we need to copy the reloc
6494 into the shared library. However, if we are linking with
6495 -Bsymbolic, we do not need to copy a reloc against a
6496 global symbol which is defined in an object we are
6497 including in the link (i.e., DEF_REGULAR is set). At
6498 this point we have not seen all the input files, so it is
6499 possible that DEF_REGULAR is not set now but will be set
6500 later (it is never cleared). We account for that
6501 possibility below by storing information in the
6502 dyn_relocs field of the hash table entry. A similar
6503 situation occurs when creating shared libraries and symbol
6504 visibility changes render the symbol local.
6506 If on the other hand, we are creating an executable, we
6507 may need to keep relocations for symbols satisfied by a
6508 dynamic library if we manage to avoid copy relocs for the
6511 && (sec
->flags
& SEC_ALLOC
) != 0
6512 && (r_type
!= R_SH_REL32
6514 && (! info
->symbolic
6515 || h
->root
.type
== bfd_link_hash_defweak
6516 || (h
->elf_link_hash_flags
6517 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
6519 && (sec
->flags
& SEC_ALLOC
) != 0
6521 && (h
->root
.type
== bfd_link_hash_defweak
6522 || (h
->elf_link_hash_flags
6523 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
6525 struct elf_sh_dyn_relocs
*p
;
6526 struct elf_sh_dyn_relocs
**head
;
6529 htab
->root
.dynobj
= dynobj
= abfd
;
6531 /* When creating a shared object, we must copy these
6532 reloc types into the output file. We create a reloc
6533 section in dynobj and make room for this reloc. */
6538 name
= (bfd_elf_string_from_elf_section
6540 elf_elfheader (abfd
)->e_shstrndx
,
6541 elf_section_data (sec
)->rel_hdr
.sh_name
));
6545 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
6546 && strcmp (bfd_get_section_name (abfd
, sec
),
6549 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6554 sreloc
= bfd_make_section (dynobj
, name
);
6555 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
6556 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
6557 if ((sec
->flags
& SEC_ALLOC
) != 0)
6558 flags
|= SEC_ALLOC
| SEC_LOAD
;
6560 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
6561 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
6564 if (sec
->flags
& SEC_READONLY
)
6565 info
->flags
|= DF_TEXTREL
;
6566 elf_section_data (sec
)->sreloc
= sreloc
;
6569 /* If this is a global symbol, we count the number of
6570 relocations we need for this symbol. */
6572 head
= &((struct elf_sh_link_hash_entry
*) h
)->dyn_relocs
;
6577 /* Track dynamic relocs needed for local syms too. */
6578 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
6583 head
= ((struct elf_sh_dyn_relocs
**)
6584 &elf_section_data (s
)->local_dynrel
);
6588 if (p
== NULL
|| p
->sec
!= sec
)
6590 bfd_size_type amt
= sizeof (*p
);
6591 p
= ((struct elf_sh_dyn_relocs
*) bfd_alloc (dynobj
, amt
));
6602 if (r_type
== R_SH_REL32
)
6608 case R_SH_TLS_LE_32
:
6611 (*_bfd_error_handler
) (_("%s: TLS local exec code cannot be linked into shared objects"),
6612 bfd_archive_filename (abfd
));
6616 if (ELF32_R_TYPE (rel
->r_info
) == R_SH_TLS_LD_32
)
6620 case R_SH_TLS_LDO_32
:
6621 /* We make a R_SH_TLS_TPOFF32 relocation. Count it as a
6625 struct elf_sh_dyn_relocs
*p
;
6626 struct elf_sh_dyn_relocs
**head
;
6629 htab
->root
.dynobj
= dynobj
= abfd
;
6635 name
= (bfd_elf_string_from_elf_section
6637 elf_elfheader (abfd
)->e_shstrndx
,
6638 elf_section_data (sec
)->rel_hdr
.sh_name
));
6642 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
6643 && strcmp (bfd_get_section_name (abfd
, sec
),
6646 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6651 sreloc
= bfd_make_section (dynobj
, name
);
6652 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
6653 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
6654 if ((sec
->flags
& SEC_ALLOC
) != 0)
6655 flags
|= SEC_ALLOC
| SEC_LOAD
;
6657 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
6658 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
6661 elf_section_data (sec
)->sreloc
= sreloc
;
6662 if (sec
->flags
& SEC_READONLY
)
6663 info
->flags
|= DF_TEXTREL
;
6666 /* If this is a global symbol, we count the number of
6667 relocations we need for this symbol. */
6669 head
= &((struct elf_sh_link_hash_entry
*) h
)->dyn_relocs
;
6674 /* Track dynamic relocs needed for local syms too. */
6675 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
6680 head
= ((struct elf_sh_dyn_relocs
**)
6681 &elf_section_data (s
)->local_dynrel
);
6685 if (p
== NULL
|| p
->sec
!= sec
)
6687 bfd_size_type amt
= sizeof (*p
);
6688 p
= ((struct elf_sh_dyn_relocs
*) bfd_alloc (dynobj
, amt
));
6700 sh_elf_hash_entry (h
)->tls_tpoff32
= TRUE
;
6712 #ifndef sh_elf_set_mach_from_flags
6714 sh_elf_set_mach_from_flags (abfd
)
6717 flagword flags
= elf_elfheader (abfd
)->e_flags
;
6719 switch (flags
& EF_SH_MACH_MASK
)
6722 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh
);
6725 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh2
);
6728 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh2e
);
6731 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh_dsp
);
6734 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3
);
6737 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3_dsp
);
6740 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3e
);
6744 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh4
);
6751 #endif /* not sh_elf_set_mach_from_flags */
6753 #ifndef sh_elf_set_private_flags
6754 /* Function to keep SH specific file flags. */
6757 sh_elf_set_private_flags (abfd
, flags
)
6761 BFD_ASSERT (! elf_flags_init (abfd
)
6762 || elf_elfheader (abfd
)->e_flags
== flags
);
6764 elf_elfheader (abfd
)->e_flags
= flags
;
6765 elf_flags_init (abfd
) = TRUE
;
6766 return sh_elf_set_mach_from_flags (abfd
);
6768 #endif /* not sh_elf_set_private_flags */
6770 #ifndef sh_elf_copy_private_data
6771 /* Copy backend specific data from one object module to another */
6774 sh_elf_copy_private_data (ibfd
, obfd
)
6778 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6779 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6782 return sh_elf_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
6784 #endif /* not sh_elf_copy_private_data */
6786 #ifndef sh_elf_merge_private_data
6787 /* This routine checks for linking big and little endian objects
6788 together, and for linking sh-dsp with sh3e / sh4 objects. */
6791 sh_elf_merge_private_data (ibfd
, obfd
)
6795 flagword old_flags
, new_flags
;
6797 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
6800 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6801 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6804 if (! elf_flags_init (obfd
))
6806 /* This happens when ld starts out with a 'blank' output file. */
6807 elf_flags_init (obfd
) = TRUE
;
6808 elf_elfheader (obfd
)->e_flags
= EF_SH1
;
6810 old_flags
= elf_elfheader (obfd
)->e_flags
;
6811 new_flags
= elf_elfheader (ibfd
)->e_flags
;
6812 if ((EF_SH_HAS_DSP (old_flags
) && EF_SH_HAS_FP (new_flags
))
6813 || (EF_SH_HAS_DSP (new_flags
) && EF_SH_HAS_FP (old_flags
)))
6815 (*_bfd_error_handler
)
6816 ("%s: uses %s instructions while previous modules use %s instructions",
6817 bfd_archive_filename (ibfd
),
6818 EF_SH_HAS_DSP (new_flags
) ? "dsp" : "floating point",
6819 EF_SH_HAS_DSP (new_flags
) ? "floating point" : "dsp");
6820 bfd_set_error (bfd_error_bad_value
);
6823 elf_elfheader (obfd
)->e_flags
= EF_SH_MERGE_MACH (old_flags
, new_flags
);
6825 return sh_elf_set_mach_from_flags (obfd
);
6827 #endif /* not sh_elf_merge_private_data */
6829 /* Override the generic function because we need to store sh_elf_obj_tdata
6830 as the specific tdata. We set also the machine architecture from flags
6834 sh_elf_object_p (abfd
)
6837 struct sh_elf_obj_tdata
*new_tdata
;
6838 bfd_size_type amt
= sizeof (struct sh_elf_obj_tdata
);
6840 if (!sh_elf_set_mach_from_flags (abfd
))
6843 /* Allocate our special target data. */
6844 new_tdata
= bfd_zalloc (abfd
, amt
);
6845 if (new_tdata
== NULL
)
6847 new_tdata
->root
= *abfd
->tdata
.elf_obj_data
;
6848 abfd
->tdata
.any
= new_tdata
;
6852 /* Finish up dynamic symbol handling. We set the contents of various
6853 dynamic sections here. */
6856 sh_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
6858 struct bfd_link_info
*info
;
6859 struct elf_link_hash_entry
*h
;
6860 Elf_Internal_Sym
*sym
;
6862 struct elf_sh_link_hash_table
*htab
;
6865 htab
= sh_elf_hash_table (info
);
6866 dynobj
= htab
->root
.dynobj
;
6868 if (h
->plt
.offset
!= (bfd_vma
) -1)
6876 Elf_Internal_Rela rel
;
6879 /* This symbol has an entry in the procedure linkage table. Set
6882 BFD_ASSERT (h
->dynindx
!= -1);
6885 sgot
= htab
->sgotplt
;
6886 srel
= htab
->srelplt
;
6887 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
6889 /* Get the index in the procedure linkage table which
6890 corresponds to this symbol. This is the index of this symbol
6891 in all the symbols for which we are making plt entries. The
6892 first entry in the procedure linkage table is reserved. */
6893 plt_index
= h
->plt
.offset
/ elf_sh_sizeof_plt (info
) - 1;
6895 /* Get the offset into the .got table of the entry that
6896 corresponds to this function. Each .got entry is 4 bytes.
6897 The first three are reserved. */
6898 got_offset
= (plt_index
+ 3) * 4;
6902 got_offset
-= GOT_BIAS
;
6905 /* Fill in the entry in the procedure linkage table. */
6908 if (elf_sh_plt_entry
== NULL
)
6910 elf_sh_plt_entry
= (bfd_big_endian (output_bfd
) ?
6911 elf_sh_plt_entry_be
: elf_sh_plt_entry_le
);
6913 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_plt_entry
,
6914 elf_sh_sizeof_plt (info
));
6915 #ifdef INCLUDE_SHMEDIA
6916 movi_shori_putval (output_bfd
,
6917 (sgot
->output_section
->vma
6918 + sgot
->output_offset
6920 (splt
->contents
+ h
->plt
.offset
6921 + elf_sh_plt_symbol_offset (info
)));
6923 /* Set bottom bit because its for a branch to SHmedia */
6924 movi_shori_putval (output_bfd
,
6925 (splt
->output_section
->vma
+ splt
->output_offset
)
6927 (splt
->contents
+ h
->plt
.offset
6928 + elf_sh_plt_plt0_offset (info
)));
6930 bfd_put_32 (output_bfd
,
6931 (sgot
->output_section
->vma
6932 + sgot
->output_offset
6934 (splt
->contents
+ h
->plt
.offset
6935 + elf_sh_plt_symbol_offset (info
)));
6937 bfd_put_32 (output_bfd
,
6938 (splt
->output_section
->vma
+ splt
->output_offset
),
6939 (splt
->contents
+ h
->plt
.offset
6940 + elf_sh_plt_plt0_offset (info
)));
6945 if (elf_sh_pic_plt_entry
== NULL
)
6947 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
6948 elf_sh_pic_plt_entry_be
:
6949 elf_sh_pic_plt_entry_le
);
6951 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_pic_plt_entry
,
6952 elf_sh_sizeof_plt (info
));
6953 #ifdef INCLUDE_SHMEDIA
6954 movi_shori_putval (output_bfd
, got_offset
,
6955 (splt
->contents
+ h
->plt
.offset
6956 + elf_sh_plt_symbol_offset (info
)));
6958 bfd_put_32 (output_bfd
, got_offset
,
6959 (splt
->contents
+ h
->plt
.offset
6960 + elf_sh_plt_symbol_offset (info
)));
6966 got_offset
+= GOT_BIAS
;
6969 #ifdef INCLUDE_SHMEDIA
6970 movi_shori_putval (output_bfd
,
6971 plt_index
* sizeof (Elf32_External_Rela
),
6972 (splt
->contents
+ h
->plt
.offset
6973 + elf_sh_plt_reloc_offset (info
)));
6975 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
6976 (splt
->contents
+ h
->plt
.offset
6977 + elf_sh_plt_reloc_offset (info
)));
6980 /* Fill in the entry in the global offset table. */
6981 bfd_put_32 (output_bfd
,
6982 (splt
->output_section
->vma
6983 + splt
->output_offset
6985 + elf_sh_plt_temp_offset (info
)),
6986 sgot
->contents
+ got_offset
);
6988 /* Fill in the entry in the .rela.plt section. */
6989 rel
.r_offset
= (sgot
->output_section
->vma
6990 + sgot
->output_offset
6992 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_JMP_SLOT
);
6995 rel
.r_addend
= GOT_BIAS
;
6997 loc
= srel
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
6998 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7000 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
7002 /* Mark the symbol as undefined, rather than as defined in
7003 the .plt section. Leave the value alone. */
7004 sym
->st_shndx
= SHN_UNDEF
;
7008 if (h
->got
.offset
!= (bfd_vma
) -1
7009 && sh_elf_hash_entry (h
)->tls_type
!= GOT_TLS_GD
7010 && sh_elf_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
7014 Elf_Internal_Rela rel
;
7017 /* This symbol has an entry in the global offset table. Set it
7021 srel
= htab
->srelgot
;
7022 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
7024 rel
.r_offset
= (sgot
->output_section
->vma
7025 + sgot
->output_offset
7026 + (h
->got
.offset
&~ (bfd_vma
) 1));
7028 /* If this is a static link, or it is a -Bsymbolic link and the
7029 symbol is defined locally or was forced to be local because
7030 of a version file, we just want to emit a RELATIVE reloc.
7031 The entry in the global offset table will already have been
7032 initialized in the relocate_section function. */
7036 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
7037 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
7039 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
7040 rel
.r_addend
= (h
->root
.u
.def
.value
7041 + h
->root
.u
.def
.section
->output_section
->vma
7042 + h
->root
.u
.def
.section
->output_offset
);
7046 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
7047 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
7051 loc
= srel
->contents
;
7052 loc
+= srel
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7053 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7056 #ifdef INCLUDE_SHMEDIA
7058 struct elf_sh_link_hash_entry
*eh
;
7060 eh
= (struct elf_sh_link_hash_entry
*) h
;
7061 if (eh
->datalabel_got
.offset
!= (bfd_vma
) -1)
7065 Elf_Internal_Rela rel
;
7068 /* This symbol has a datalabel entry in the global offset table.
7072 srel
= htab
->srelgot
;
7073 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
7075 rel
.r_offset
= (sgot
->output_section
->vma
7076 + sgot
->output_offset
7077 + (eh
->datalabel_got
.offset
&~ (bfd_vma
) 1));
7079 /* If this is a static link, or it is a -Bsymbolic link and the
7080 symbol is defined locally or was forced to be local because
7081 of a version file, we just want to emit a RELATIVE reloc.
7082 The entry in the global offset table will already have been
7083 initialized in the relocate_section function. */
7087 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
7088 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
7090 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
7091 rel
.r_addend
= (h
->root
.u
.def
.value
7092 + h
->root
.u
.def
.section
->output_section
->vma
7093 + h
->root
.u
.def
.section
->output_offset
);
7097 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
7098 + eh
->datalabel_got
.offset
);
7099 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
7103 loc
= srel
->contents
;
7104 loc
+= srel
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7105 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7110 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
7113 Elf_Internal_Rela rel
;
7116 /* This symbol needs a copy reloc. Set it up. */
7118 BFD_ASSERT (h
->dynindx
!= -1
7119 && (h
->root
.type
== bfd_link_hash_defined
7120 || h
->root
.type
== bfd_link_hash_defweak
));
7122 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
7124 BFD_ASSERT (s
!= NULL
);
7126 rel
.r_offset
= (h
->root
.u
.def
.value
7127 + h
->root
.u
.def
.section
->output_section
->vma
7128 + h
->root
.u
.def
.section
->output_offset
);
7129 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_COPY
);
7131 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7132 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7135 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7136 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
7137 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
7138 sym
->st_shndx
= SHN_ABS
;
7143 /* Finish up the dynamic sections. */
7146 sh_elf_finish_dynamic_sections (output_bfd
, info
)
7148 struct bfd_link_info
*info
;
7150 struct elf_sh_link_hash_table
*htab
;
7155 htab
= sh_elf_hash_table (info
);
7156 dynobj
= htab
->root
.dynobj
;
7158 sgot
= htab
->sgotplt
;
7159 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7161 if (htab
->root
.dynamic_sections_created
)
7164 Elf32_External_Dyn
*dyncon
, *dynconend
;
7166 BFD_ASSERT (sgot
!= NULL
&& sdyn
!= NULL
);
7168 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7169 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7170 for (; dyncon
< dynconend
; dyncon
++)
7172 Elf_Internal_Dyn dyn
;
7174 #ifdef INCLUDE_SHMEDIA
7178 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7185 #ifdef INCLUDE_SHMEDIA
7187 name
= info
->init_function
;
7191 name
= info
->fini_function
;
7193 if (dyn
.d_un
.d_val
!= 0)
7195 struct elf_link_hash_entry
*h
;
7197 h
= elf_link_hash_lookup (&htab
->root
, name
,
7198 FALSE
, FALSE
, TRUE
);
7199 if (h
!= NULL
&& (h
->other
& STO_SH5_ISA32
))
7201 dyn
.d_un
.d_val
|= 1;
7202 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7209 s
= htab
->sgot
->output_section
;
7213 s
= htab
->srelplt
->output_section
;
7215 BFD_ASSERT (s
!= NULL
);
7216 dyn
.d_un
.d_ptr
= s
->vma
;
7217 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7221 s
= htab
->srelplt
->output_section
;
7222 BFD_ASSERT (s
!= NULL
);
7223 if (s
->_cooked_size
!= 0)
7224 dyn
.d_un
.d_val
= s
->_cooked_size
;
7226 dyn
.d_un
.d_val
= s
->_raw_size
;
7227 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7231 /* My reading of the SVR4 ABI indicates that the
7232 procedure linkage table relocs (DT_JMPREL) should be
7233 included in the overall relocs (DT_RELA). This is
7234 what Solaris does. However, UnixWare can not handle
7235 that case. Therefore, we override the DT_RELASZ entry
7236 here to make it not include the JMPREL relocs. Since
7237 the linker script arranges for .rela.plt to follow all
7238 other relocation sections, we don't have to worry
7239 about changing the DT_RELA entry. */
7240 if (htab
->srelplt
!= NULL
)
7242 s
= htab
->srelplt
->output_section
;
7243 if (s
->_cooked_size
!= 0)
7244 dyn
.d_un
.d_val
-= s
->_cooked_size
;
7246 dyn
.d_un
.d_val
-= s
->_raw_size
;
7248 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7253 /* Fill in the first entry in the procedure linkage table. */
7255 if (splt
&& splt
->_raw_size
> 0)
7259 if (elf_sh_pic_plt_entry
== NULL
)
7261 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
7262 elf_sh_pic_plt_entry_be
:
7263 elf_sh_pic_plt_entry_le
);
7265 memcpy (splt
->contents
, elf_sh_pic_plt_entry
,
7266 elf_sh_sizeof_plt (info
));
7270 if (elf_sh_plt0_entry
== NULL
)
7272 elf_sh_plt0_entry
= (bfd_big_endian (output_bfd
) ?
7273 elf_sh_plt0_entry_be
:
7274 elf_sh_plt0_entry_le
);
7276 memcpy (splt
->contents
, elf_sh_plt0_entry
, PLT_ENTRY_SIZE
);
7277 #ifdef INCLUDE_SHMEDIA
7278 movi_shori_putval (output_bfd
,
7279 sgot
->output_section
->vma
7280 + sgot
->output_offset
,
7282 + elf_sh_plt0_gotplt_offset (info
));
7284 bfd_put_32 (output_bfd
,
7285 sgot
->output_section
->vma
+ sgot
->output_offset
+ 4,
7286 splt
->contents
+ elf_sh_plt0_gotid_offset (info
));
7287 bfd_put_32 (output_bfd
,
7288 sgot
->output_section
->vma
+ sgot
->output_offset
+ 8,
7289 splt
->contents
+ elf_sh_plt0_linker_offset (info
));
7293 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7294 really seem like the right value. */
7295 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
7299 /* Fill in the first three entries in the global offset table. */
7300 if (sgot
&& sgot
->_raw_size
> 0)
7303 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7305 bfd_put_32 (output_bfd
,
7306 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
7308 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
7309 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
7311 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7317 static enum elf_reloc_type_class
7318 sh_elf_reloc_type_class (rela
)
7319 const Elf_Internal_Rela
*rela
;
7321 switch ((int) ELF32_R_TYPE (rela
->r_info
))
7324 return reloc_class_relative
;
7326 return reloc_class_plt
;
7328 return reloc_class_copy
;
7330 return reloc_class_normal
;
7334 /* Support for Linux core dump NOTE sections. */
7336 elf32_shlin_grok_prstatus (abfd
, note
)
7338 Elf_Internal_Note
*note
;
7341 unsigned int raw_size
;
7343 switch (note
->descsz
)
7348 case 168: /* Linux/SH */
7350 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
7353 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
7362 /* Make a ".reg/999" section. */
7363 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
7364 raw_size
, note
->descpos
+ offset
);
7368 elf32_shlin_grok_psinfo (abfd
, note
)
7370 Elf_Internal_Note
*note
;
7372 switch (note
->descsz
)
7377 case 124: /* Linux/SH elf_prpsinfo */
7378 elf_tdata (abfd
)->core_program
7379 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
7380 elf_tdata (abfd
)->core_command
7381 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
7384 /* Note that for some reason, a spurious space is tacked
7385 onto the end of the args in some (at least one anyway)
7386 implementations, so strip it off if it exists. */
7389 char *command
= elf_tdata (abfd
)->core_command
;
7390 int n
= strlen (command
);
7392 if (0 < n
&& command
[n
- 1] == ' ')
7393 command
[n
- 1] = '\0';
7399 #define TARGET_BIG_SYM bfd_elf32_sh_vec
7400 #define TARGET_BIG_NAME "elf32-sh"
7401 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
7402 #define TARGET_LITTLE_NAME "elf32-shl"
7403 #define ELF_ARCH bfd_arch_sh
7404 #define ELF_MACHINE_CODE EM_SH
7405 #define ELF_MAXPAGESIZE 128
7407 #define elf_symbol_leading_char '_'
7409 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7410 #define elf_info_to_howto sh_elf_info_to_howto
7411 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
7412 #define elf_backend_relocate_section sh_elf_relocate_section
7413 #define bfd_elf32_bfd_get_relocated_section_contents \
7414 sh_elf_get_relocated_section_contents
7415 #define bfd_elf32_mkobject sh_elf_mkobject
7416 #define elf_backend_object_p sh_elf_object_p
7417 #define bfd_elf32_bfd_set_private_bfd_flags \
7418 sh_elf_set_private_flags
7419 #define bfd_elf32_bfd_copy_private_bfd_data \
7420 sh_elf_copy_private_data
7421 #define bfd_elf32_bfd_merge_private_bfd_data \
7422 sh_elf_merge_private_data
7424 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
7425 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
7426 #define elf_backend_check_relocs sh_elf_check_relocs
7427 #define elf_backend_copy_indirect_symbol \
7428 sh_elf_copy_indirect_symbol
7429 #define elf_backend_create_dynamic_sections \
7430 sh_elf_create_dynamic_sections
7431 #define bfd_elf32_bfd_link_hash_table_create \
7432 sh_elf_link_hash_table_create
7433 #define elf_backend_adjust_dynamic_symbol \
7434 sh_elf_adjust_dynamic_symbol
7435 #define elf_backend_size_dynamic_sections \
7436 sh_elf_size_dynamic_sections
7437 #define elf_backend_finish_dynamic_symbol \
7438 sh_elf_finish_dynamic_symbol
7439 #define elf_backend_finish_dynamic_sections \
7440 sh_elf_finish_dynamic_sections
7441 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
7443 #define elf_backend_can_gc_sections 1
7444 #define elf_backend_can_refcount 1
7445 #define elf_backend_want_got_plt 1
7446 #define elf_backend_plt_readonly 1
7447 #define elf_backend_want_plt_sym 0
7448 #define elf_backend_got_header_size 12
7449 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
7451 #ifndef INCLUDE_SHMEDIA
7453 #include "elf32-target.h"
7455 /* NetBSD support. */
7456 #undef TARGET_BIG_SYM
7457 #define TARGET_BIG_SYM bfd_elf32_shnbsd_vec
7458 #undef TARGET_BIG_NAME
7459 #define TARGET_BIG_NAME "elf32-sh-nbsd"
7460 #undef TARGET_LITTLE_SYM
7461 #define TARGET_LITTLE_SYM bfd_elf32_shlnbsd_vec
7462 #undef TARGET_LITTLE_NAME
7463 #define TARGET_LITTLE_NAME "elf32-shl-nbsd"
7464 #undef ELF_MAXPAGESIZE
7465 #define ELF_MAXPAGESIZE 0x10000
7466 #undef elf_symbol_leading_char
7467 #define elf_symbol_leading_char 0
7469 #define elf32_bed elf32_sh_nbsd_bed
7471 #include "elf32-target.h"
7474 /* Linux support. */
7475 #undef TARGET_BIG_SYM
7476 #define TARGET_BIG_SYM bfd_elf32_shblin_vec
7477 #undef TARGET_BIG_NAME
7478 #define TARGET_BIG_NAME "elf32-shbig-linux"
7479 #undef TARGET_LITTLE_SYM
7480 #define TARGET_LITTLE_SYM bfd_elf32_shlin_vec
7481 #undef TARGET_LITTLE_NAME
7482 #define TARGET_LITTLE_NAME "elf32-sh-linux"
7484 #undef elf_backend_grok_prstatus
7485 #define elf_backend_grok_prstatus elf32_shlin_grok_prstatus
7486 #undef elf_backend_grok_psinfo
7487 #define elf_backend_grok_psinfo elf32_shlin_grok_psinfo
7489 #define elf32_bed elf32_sh_lin_bed
7491 #include "elf32-target.h"
7493 #endif /* INCLUDE_SHMEDIA */