1 /* Renesas 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 /* This cannot be partial_inplace because relaxation can't know the
183 eventual value of a symbol. */
184 HOWTO (R_SH_IND12W
, /* type */
186 1, /* size (0 = byte, 1 = short, 2 = long) */
188 TRUE
, /* pc_relative */
190 complain_overflow_signed
, /* complain_on_overflow */
191 NULL
, /* special_function */
192 "R_SH_IND12W", /* name */
193 FALSE
, /* partial_inplace */
195 0xfff, /* dst_mask */
196 TRUE
), /* pcrel_offset */
198 /* 8 bit unsigned PC relative divided by 4. */
199 HOWTO (R_SH_DIR8WPL
, /* type */
201 1, /* size (0 = byte, 1 = short, 2 = long) */
203 TRUE
, /* pc_relative */
205 complain_overflow_unsigned
, /* complain_on_overflow */
206 sh_elf_ignore_reloc
, /* special_function */
207 "R_SH_DIR8WPL", /* name */
208 TRUE
, /* partial_inplace */
211 TRUE
), /* pcrel_offset */
213 /* 8 bit unsigned PC relative divided by 2. */
214 HOWTO (R_SH_DIR8WPZ
, /* type */
216 1, /* size (0 = byte, 1 = short, 2 = long) */
218 TRUE
, /* pc_relative */
220 complain_overflow_unsigned
, /* complain_on_overflow */
221 sh_elf_ignore_reloc
, /* special_function */
222 "R_SH_DIR8WPZ", /* name */
223 TRUE
, /* partial_inplace */
226 TRUE
), /* pcrel_offset */
228 /* 8 bit GBR relative. FIXME: This only makes sense if we have some
229 special symbol for the GBR relative area, and that is not
231 HOWTO (R_SH_DIR8BP
, /* type */
233 1, /* size (0 = byte, 1 = short, 2 = long) */
235 FALSE
, /* pc_relative */
237 complain_overflow_unsigned
, /* complain_on_overflow */
238 sh_elf_ignore_reloc
, /* special_function */
239 "R_SH_DIR8BP", /* name */
240 FALSE
, /* partial_inplace */
243 TRUE
), /* pcrel_offset */
245 /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if
246 we have some special symbol for the GBR relative area, and that
247 is not implemented. */
248 HOWTO (R_SH_DIR8W
, /* type */
250 1, /* size (0 = byte, 1 = short, 2 = long) */
252 FALSE
, /* pc_relative */
254 complain_overflow_unsigned
, /* complain_on_overflow */
255 sh_elf_ignore_reloc
, /* special_function */
256 "R_SH_DIR8W", /* name */
257 FALSE
, /* partial_inplace */
260 TRUE
), /* pcrel_offset */
262 /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if
263 we have some special symbol for the GBR relative area, and that
264 is not implemented. */
265 HOWTO (R_SH_DIR8L
, /* type */
267 1, /* size (0 = byte, 1 = short, 2 = long) */
269 FALSE
, /* pc_relative */
271 complain_overflow_unsigned
, /* complain_on_overflow */
272 sh_elf_ignore_reloc
, /* special_function */
273 "R_SH_DIR8L", /* name */
274 FALSE
, /* partial_inplace */
277 TRUE
), /* pcrel_offset */
295 /* The remaining relocs are a GNU extension used for relaxing. The
296 final pass of the linker never needs to do anything with any of
297 these relocs. Any required operations are handled by the
300 /* A 16 bit switch table entry. This is generated for an expression
301 such as ``.word L1 - L2''. The offset holds the difference
302 between the reloc address and L2. */
303 HOWTO (R_SH_SWITCH16
, /* type */
305 1, /* size (0 = byte, 1 = short, 2 = long) */
307 FALSE
, /* pc_relative */
309 complain_overflow_unsigned
, /* complain_on_overflow */
310 sh_elf_ignore_reloc
, /* special_function */
311 "R_SH_SWITCH16", /* name */
312 FALSE
, /* partial_inplace */
315 TRUE
), /* pcrel_offset */
317 /* A 32 bit switch table entry. This is generated for an expression
318 such as ``.long L1 - L2''. The offset holds the difference
319 between the reloc address and L2. */
320 HOWTO (R_SH_SWITCH32
, /* type */
322 2, /* size (0 = byte, 1 = short, 2 = long) */
324 FALSE
, /* pc_relative */
326 complain_overflow_unsigned
, /* complain_on_overflow */
327 sh_elf_ignore_reloc
, /* special_function */
328 "R_SH_SWITCH32", /* name */
329 FALSE
, /* partial_inplace */
332 TRUE
), /* pcrel_offset */
334 /* Indicates a .uses pseudo-op. The compiler will generate .uses
335 pseudo-ops when it finds a function call which can be relaxed.
336 The offset field holds the PC relative offset to the instruction
337 which loads the register used in the function call. */
338 HOWTO (R_SH_USES
, /* type */
340 1, /* size (0 = byte, 1 = short, 2 = long) */
342 FALSE
, /* pc_relative */
344 complain_overflow_unsigned
, /* complain_on_overflow */
345 sh_elf_ignore_reloc
, /* special_function */
346 "R_SH_USES", /* name */
347 FALSE
, /* partial_inplace */
350 TRUE
), /* pcrel_offset */
352 /* The assembler will generate this reloc for addresses referred to
353 by the register loads associated with USES relocs. The offset
354 field holds the number of times the address is referenced in the
356 HOWTO (R_SH_COUNT
, /* type */
358 1, /* size (0 = byte, 1 = short, 2 = long) */
360 FALSE
, /* pc_relative */
362 complain_overflow_unsigned
, /* complain_on_overflow */
363 sh_elf_ignore_reloc
, /* special_function */
364 "R_SH_COUNT", /* name */
365 FALSE
, /* partial_inplace */
368 TRUE
), /* pcrel_offset */
370 /* Indicates an alignment statement. The offset field is the power
371 of 2 to which subsequent portions of the object file must be
373 HOWTO (R_SH_ALIGN
, /* type */
375 1, /* size (0 = byte, 1 = short, 2 = long) */
377 FALSE
, /* pc_relative */
379 complain_overflow_unsigned
, /* complain_on_overflow */
380 sh_elf_ignore_reloc
, /* special_function */
381 "R_SH_ALIGN", /* name */
382 FALSE
, /* partial_inplace */
385 TRUE
), /* pcrel_offset */
387 /* The assembler will generate this reloc before a block of
388 instructions. A section should be processed as assumining it
389 contains data, unless this reloc is seen. */
390 HOWTO (R_SH_CODE
, /* type */
392 1, /* size (0 = byte, 1 = short, 2 = long) */
394 FALSE
, /* pc_relative */
396 complain_overflow_unsigned
, /* complain_on_overflow */
397 sh_elf_ignore_reloc
, /* special_function */
398 "R_SH_CODE", /* name */
399 FALSE
, /* partial_inplace */
402 TRUE
), /* pcrel_offset */
404 /* The assembler will generate this reloc after a block of
405 instructions when it sees data that is not instructions. */
406 HOWTO (R_SH_DATA
, /* type */
408 1, /* size (0 = byte, 1 = short, 2 = long) */
410 FALSE
, /* pc_relative */
412 complain_overflow_unsigned
, /* complain_on_overflow */
413 sh_elf_ignore_reloc
, /* special_function */
414 "R_SH_DATA", /* name */
415 FALSE
, /* partial_inplace */
418 TRUE
), /* pcrel_offset */
420 /* The assembler generates this reloc for each label within a block
421 of instructions. This permits the linker to avoid swapping
422 instructions which are the targets of branches. */
423 HOWTO (R_SH_LABEL
, /* type */
425 1, /* size (0 = byte, 1 = short, 2 = long) */
427 FALSE
, /* pc_relative */
429 complain_overflow_unsigned
, /* complain_on_overflow */
430 sh_elf_ignore_reloc
, /* special_function */
431 "R_SH_LABEL", /* name */
432 FALSE
, /* partial_inplace */
435 TRUE
), /* pcrel_offset */
437 /* An 8 bit switch table entry. This is generated for an expression
438 such as ``.word L1 - L2''. The offset holds the difference
439 between the reloc address and L2. */
440 HOWTO (R_SH_SWITCH8
, /* type */
442 0, /* size (0 = byte, 1 = short, 2 = long) */
444 FALSE
, /* pc_relative */
446 complain_overflow_unsigned
, /* complain_on_overflow */
447 sh_elf_ignore_reloc
, /* special_function */
448 "R_SH_SWITCH8", /* name */
449 FALSE
, /* partial_inplace */
452 TRUE
), /* pcrel_offset */
454 /* GNU extension to record C++ vtable hierarchy */
455 HOWTO (R_SH_GNU_VTINHERIT
, /* type */
457 2, /* size (0 = byte, 1 = short, 2 = long) */
459 FALSE
, /* pc_relative */
461 complain_overflow_dont
, /* complain_on_overflow */
462 NULL
, /* special_function */
463 "R_SH_GNU_VTINHERIT", /* name */
464 FALSE
, /* partial_inplace */
467 FALSE
), /* pcrel_offset */
469 /* GNU extension to record C++ vtable member usage */
470 HOWTO (R_SH_GNU_VTENTRY
, /* type */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
474 FALSE
, /* pc_relative */
476 complain_overflow_dont
, /* complain_on_overflow */
477 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
478 "R_SH_GNU_VTENTRY", /* name */
479 FALSE
, /* partial_inplace */
482 FALSE
), /* pcrel_offset */
484 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
485 HOWTO (R_SH_LOOP_START
, /* type */
487 1, /* size (0 = byte, 1 = short, 2 = long) */
489 FALSE
, /* pc_relative */
491 complain_overflow_signed
, /* complain_on_overflow */
492 sh_elf_ignore_reloc
, /* special_function */
493 "R_SH_LOOP_START", /* name */
494 TRUE
, /* partial_inplace */
497 TRUE
), /* pcrel_offset */
499 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
500 HOWTO (R_SH_LOOP_END
, /* type */
502 1, /* size (0 = byte, 1 = short, 2 = long) */
504 FALSE
, /* pc_relative */
506 complain_overflow_signed
, /* complain_on_overflow */
507 sh_elf_ignore_reloc
, /* special_function */
508 "R_SH_LOOP_END", /* name */
509 TRUE
, /* partial_inplace */
512 TRUE
), /* pcrel_offset */
522 #ifdef INCLUDE_SHMEDIA
523 /* Used in SHLLI.L and SHLRI.L. */
524 HOWTO (R_SH_DIR5U
, /* type */
526 2, /* size (0 = byte, 1 = short, 2 = long) */
528 FALSE
, /* pc_relative */
530 complain_overflow_unsigned
, /* complain_on_overflow */
531 bfd_elf_generic_reloc
, /* special_function */
532 "R_SH_DIR5U", /* name */
533 FALSE
, /* partial_inplace */
535 0xfc00, /* dst_mask */
536 FALSE
), /* pcrel_offset */
538 /* Used in SHARI, SHLLI et al. */
539 HOWTO (R_SH_DIR6U
, /* type */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
543 FALSE
, /* pc_relative */
545 complain_overflow_unsigned
, /* complain_on_overflow */
546 bfd_elf_generic_reloc
, /* special_function */
547 "R_SH_DIR6U", /* name */
548 FALSE
, /* partial_inplace */
550 0xfc00, /* dst_mask */
551 FALSE
), /* pcrel_offset */
553 /* Used in BxxI, LDHI.L et al. */
554 HOWTO (R_SH_DIR6S
, /* type */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
558 FALSE
, /* pc_relative */
560 complain_overflow_signed
, /* complain_on_overflow */
561 bfd_elf_generic_reloc
, /* special_function */
562 "R_SH_DIR6S", /* name */
563 FALSE
, /* partial_inplace */
565 0xfc00, /* dst_mask */
566 FALSE
), /* pcrel_offset */
568 /* Used in ADDI, ANDI et al. */
569 HOWTO (R_SH_DIR10S
, /* type */
571 2, /* size (0 = byte, 1 = short, 2 = long) */
573 FALSE
, /* pc_relative */
575 complain_overflow_signed
, /* complain_on_overflow */
576 bfd_elf_generic_reloc
, /* special_function */
577 "R_SH_DIR10S", /* name */
578 FALSE
, /* partial_inplace */
580 0xffc00, /* dst_mask */
581 FALSE
), /* pcrel_offset */
583 /* Used in LD.UW, ST.W et al. */
584 HOWTO (R_SH_DIR10SW
, /* type */
586 2, /* size (0 = byte, 1 = short, 2 = long) */
588 FALSE
, /* pc_relative */
590 complain_overflow_signed
, /* complain_on_overflow */
591 bfd_elf_generic_reloc
, /* special_function */
592 "R_SH_DIR10SW", /* name */
593 FALSE
, /* partial_inplace */
595 0xffc00, /* dst_mask */
596 FALSE
), /* pcrel_offset */
598 /* Used in LD.L, FLD.S et al. */
599 HOWTO (R_SH_DIR10SL
, /* type */
601 2, /* size (0 = byte, 1 = short, 2 = long) */
603 FALSE
, /* pc_relative */
605 complain_overflow_signed
, /* complain_on_overflow */
606 bfd_elf_generic_reloc
, /* special_function */
607 "R_SH_DIR10SL", /* name */
608 FALSE
, /* partial_inplace */
610 0xffc00, /* dst_mask */
611 FALSE
), /* pcrel_offset */
613 /* Used in FLD.D, FST.P et al. */
614 HOWTO (R_SH_DIR10SQ
, /* type */
616 2, /* size (0 = byte, 1 = short, 2 = long) */
618 FALSE
, /* pc_relative */
620 complain_overflow_signed
, /* complain_on_overflow */
621 bfd_elf_generic_reloc
, /* special_function */
622 "R_SH_DIR10SQ", /* name */
623 FALSE
, /* partial_inplace */
625 0xffc00, /* dst_mask */
626 FALSE
), /* pcrel_offset */
731 HOWTO (R_SH_TLS_GD_32
, /* type */
733 2, /* size (0 = byte, 1 = short, 2 = long) */
735 FALSE
, /* pc_relative */
737 complain_overflow_bitfield
, /* complain_on_overflow */
738 bfd_elf_generic_reloc
, /* */
739 "R_SH_TLS_GD_32", /* name */
740 TRUE
, /* partial_inplace */
741 0xffffffff, /* src_mask */
742 0xffffffff, /* dst_mask */
743 FALSE
), /* pcrel_offset */
745 HOWTO (R_SH_TLS_LD_32
, /* type */
747 2, /* size (0 = byte, 1 = short, 2 = long) */
749 FALSE
, /* pc_relative */
751 complain_overflow_bitfield
, /* complain_on_overflow */
752 bfd_elf_generic_reloc
, /* */
753 "R_SH_TLS_LD_32", /* name */
754 TRUE
, /* partial_inplace */
755 0xffffffff, /* src_mask */
756 0xffffffff, /* dst_mask */
757 FALSE
), /* pcrel_offset */
759 HOWTO (R_SH_TLS_LDO_32
, /* type */
761 2, /* size (0 = byte, 1 = short, 2 = long) */
763 FALSE
, /* pc_relative */
765 complain_overflow_bitfield
, /* complain_on_overflow */
766 bfd_elf_generic_reloc
, /* */
767 "R_SH_TLS_LDO_32", /* name */
768 TRUE
, /* partial_inplace */
769 0xffffffff, /* src_mask */
770 0xffffffff, /* dst_mask */
771 FALSE
), /* pcrel_offset */
773 HOWTO (R_SH_TLS_IE_32
, /* type */
775 2, /* size (0 = byte, 1 = short, 2 = long) */
777 FALSE
, /* pc_relative */
779 complain_overflow_bitfield
, /* complain_on_overflow */
780 bfd_elf_generic_reloc
, /* */
781 "R_SH_TLS_IE_32", /* name */
782 TRUE
, /* partial_inplace */
783 0xffffffff, /* src_mask */
784 0xffffffff, /* dst_mask */
785 FALSE
), /* pcrel_offset */
787 HOWTO (R_SH_TLS_LE_32
, /* type */
789 2, /* size (0 = byte, 1 = short, 2 = long) */
791 FALSE
, /* pc_relative */
793 complain_overflow_bitfield
, /* complain_on_overflow */
794 bfd_elf_generic_reloc
, /* */
795 "R_SH_TLS_LE_32", /* name */
796 TRUE
, /* partial_inplace */
797 0xffffffff, /* src_mask */
798 0xffffffff, /* dst_mask */
799 FALSE
), /* pcrel_offset */
801 HOWTO (R_SH_TLS_DTPMOD32
, /* type */
803 2, /* size (0 = byte, 1 = short, 2 = long) */
805 FALSE
, /* pc_relative */
807 complain_overflow_bitfield
, /* complain_on_overflow */
808 bfd_elf_generic_reloc
, /* */
809 "R_SH_TLS_DTPMOD32", /* name */
810 TRUE
, /* partial_inplace */
811 0xffffffff, /* src_mask */
812 0xffffffff, /* dst_mask */
813 FALSE
), /* pcrel_offset */
815 HOWTO (R_SH_TLS_DTPOFF32
, /* type */
817 2, /* size (0 = byte, 1 = short, 2 = long) */
819 FALSE
, /* pc_relative */
821 complain_overflow_bitfield
, /* complain_on_overflow */
822 bfd_elf_generic_reloc
, /* */
823 "R_SH_TLS_DTPOFF32", /* name */
824 TRUE
, /* partial_inplace */
825 0xffffffff, /* src_mask */
826 0xffffffff, /* dst_mask */
827 FALSE
), /* pcrel_offset */
829 HOWTO (R_SH_TLS_TPOFF32
, /* type */
831 2, /* size (0 = byte, 1 = short, 2 = long) */
833 FALSE
, /* pc_relative */
835 complain_overflow_bitfield
, /* complain_on_overflow */
836 bfd_elf_generic_reloc
, /* */
837 "R_SH_TLS_TPOFF32", /* name */
838 TRUE
, /* partial_inplace */
839 0xffffffff, /* src_mask */
840 0xffffffff, /* dst_mask */
841 FALSE
), /* pcrel_offset */
852 HOWTO (R_SH_GOT32
, /* type */
854 2, /* size (0 = byte, 1 = short, 2 = long) */
856 FALSE
, /* pc_relative */
858 complain_overflow_bitfield
, /* complain_on_overflow */
859 bfd_elf_generic_reloc
, /* */
860 "R_SH_GOT32", /* name */
861 TRUE
, /* partial_inplace */
862 0xffffffff, /* src_mask */
863 0xffffffff, /* dst_mask */
864 FALSE
), /* pcrel_offset */
866 HOWTO (R_SH_PLT32
, /* type */
868 2, /* size (0 = byte, 1 = short, 2 = long) */
870 TRUE
, /* pc_relative */
872 complain_overflow_bitfield
, /* complain_on_overflow */
873 bfd_elf_generic_reloc
, /* */
874 "R_SH_PLT32", /* name */
875 TRUE
, /* partial_inplace */
876 0xffffffff, /* src_mask */
877 0xffffffff, /* dst_mask */
878 TRUE
), /* pcrel_offset */
880 HOWTO (R_SH_COPY
, /* type */
882 2, /* size (0 = byte, 1 = short, 2 = long) */
884 FALSE
, /* pc_relative */
886 complain_overflow_bitfield
, /* complain_on_overflow */
887 bfd_elf_generic_reloc
, /* */
888 "R_SH_COPY", /* name */
889 TRUE
, /* partial_inplace */
890 0xffffffff, /* src_mask */
891 0xffffffff, /* dst_mask */
892 FALSE
), /* pcrel_offset */
894 HOWTO (R_SH_GLOB_DAT
, /* type */
896 2, /* size (0 = byte, 1 = short, 2 = long) */
898 FALSE
, /* pc_relative */
900 complain_overflow_bitfield
, /* complain_on_overflow */
901 bfd_elf_generic_reloc
, /* */
902 "R_SH_GLOB_DAT", /* name */
903 TRUE
, /* partial_inplace */
904 0xffffffff, /* src_mask */
905 0xffffffff, /* dst_mask */
906 FALSE
), /* pcrel_offset */
908 HOWTO (R_SH_JMP_SLOT
, /* type */
910 2, /* size (0 = byte, 1 = short, 2 = long) */
912 FALSE
, /* pc_relative */
914 complain_overflow_bitfield
, /* complain_on_overflow */
915 bfd_elf_generic_reloc
, /* */
916 "R_SH_JMP_SLOT", /* name */
917 TRUE
, /* partial_inplace */
918 0xffffffff, /* src_mask */
919 0xffffffff, /* dst_mask */
920 FALSE
), /* pcrel_offset */
922 HOWTO (R_SH_RELATIVE
, /* type */
924 2, /* size (0 = byte, 1 = short, 2 = long) */
926 FALSE
, /* pc_relative */
928 complain_overflow_bitfield
, /* complain_on_overflow */
929 bfd_elf_generic_reloc
, /* */
930 "R_SH_RELATIVE", /* name */
931 TRUE
, /* partial_inplace */
932 0xffffffff, /* src_mask */
933 0xffffffff, /* dst_mask */
934 FALSE
), /* pcrel_offset */
936 HOWTO (R_SH_GOTOFF
, /* type */
938 2, /* size (0 = byte, 1 = short, 2 = long) */
940 FALSE
, /* pc_relative */
942 complain_overflow_bitfield
, /* complain_on_overflow */
943 bfd_elf_generic_reloc
, /* */
944 "R_SH_GOTOFF", /* name */
945 TRUE
, /* partial_inplace */
946 0xffffffff, /* src_mask */
947 0xffffffff, /* dst_mask */
948 FALSE
), /* pcrel_offset */
950 HOWTO (R_SH_GOTPC
, /* type */
952 2, /* size (0 = byte, 1 = short, 2 = long) */
954 TRUE
, /* pc_relative */
956 complain_overflow_bitfield
, /* complain_on_overflow */
957 bfd_elf_generic_reloc
, /* */
958 "R_SH_GOTPC", /* name */
959 TRUE
, /* partial_inplace */
960 0xffffffff, /* src_mask */
961 0xffffffff, /* dst_mask */
962 TRUE
), /* pcrel_offset */
964 HOWTO (R_SH_GOTPLT32
, /* type */
966 2, /* size (0 = byte, 1 = short, 2 = long) */
968 FALSE
, /* pc_relative */
970 complain_overflow_bitfield
, /* complain_on_overflow */
971 bfd_elf_generic_reloc
, /* */
972 "R_SH_GOTPLT32", /* name */
973 FALSE
, /* partial_inplace */
974 0xffffffff, /* src_mask */
975 0xffffffff, /* dst_mask */
976 FALSE
), /* pcrel_offset */
978 #ifdef INCLUDE_SHMEDIA
979 /* Used in MOVI and SHORI (x & 65536). */
980 HOWTO (R_SH_GOT_LOW16
, /* type */
982 2, /* size (0 = byte, 1 = short, 2 = long) */
984 FALSE
, /* pc_relative */
986 complain_overflow_dont
, /* complain_on_overflow */
987 bfd_elf_generic_reloc
, /* special_function */
988 "R_SH_GOT_LOW16", /* name */
989 FALSE
, /* partial_inplace */
991 0x3fffc00, /* dst_mask */
992 FALSE
), /* pcrel_offset */
994 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
995 HOWTO (R_SH_GOT_MEDLOW16
, /* type */
997 2, /* size (0 = byte, 1 = short, 2 = long) */
999 FALSE
, /* pc_relative */
1001 complain_overflow_dont
, /* complain_on_overflow */
1002 bfd_elf_generic_reloc
, /* special_function */
1003 "R_SH_GOT_MEDLOW16", /* name */
1004 FALSE
, /* partial_inplace */
1006 0x3fffc00, /* dst_mask */
1007 FALSE
), /* pcrel_offset */
1009 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1010 HOWTO (R_SH_GOT_MEDHI16
, /* type */
1011 32, /* rightshift */
1012 2, /* size (0 = byte, 1 = short, 2 = long) */
1014 FALSE
, /* pc_relative */
1016 complain_overflow_dont
, /* complain_on_overflow */
1017 bfd_elf_generic_reloc
, /* special_function */
1018 "R_SH_GOT_MEDHI16", /* name */
1019 FALSE
, /* partial_inplace */
1021 0x3fffc00, /* dst_mask */
1022 FALSE
), /* pcrel_offset */
1024 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1025 HOWTO (R_SH_GOT_HI16
, /* type */
1026 48, /* rightshift */
1027 2, /* size (0 = byte, 1 = short, 2 = long) */
1029 FALSE
, /* pc_relative */
1031 complain_overflow_dont
, /* complain_on_overflow */
1032 bfd_elf_generic_reloc
, /* special_function */
1033 "R_SH_GOT_HI16", /* name */
1034 FALSE
, /* partial_inplace */
1036 0x3fffc00, /* dst_mask */
1037 FALSE
), /* pcrel_offset */
1039 /* Used in MOVI and SHORI (x & 65536). */
1040 HOWTO (R_SH_GOTPLT_LOW16
, /* type */
1042 2, /* size (0 = byte, 1 = short, 2 = long) */
1044 FALSE
, /* pc_relative */
1046 complain_overflow_dont
, /* complain_on_overflow */
1047 bfd_elf_generic_reloc
, /* special_function */
1048 "R_SH_GOTPLT_LOW16", /* name */
1049 FALSE
, /* partial_inplace */
1051 0x3fffc00, /* dst_mask */
1052 FALSE
), /* pcrel_offset */
1054 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1055 HOWTO (R_SH_GOTPLT_MEDLOW16
, /* type */
1056 16, /* rightshift */
1057 2, /* size (0 = byte, 1 = short, 2 = long) */
1059 FALSE
, /* pc_relative */
1061 complain_overflow_dont
, /* complain_on_overflow */
1062 bfd_elf_generic_reloc
, /* special_function */
1063 "R_SH_GOTPLT_MEDLOW16", /* name */
1064 FALSE
, /* partial_inplace */
1066 0x3fffc00, /* dst_mask */
1067 FALSE
), /* pcrel_offset */
1069 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1070 HOWTO (R_SH_GOTPLT_MEDHI16
, /* type */
1071 32, /* rightshift */
1072 2, /* size (0 = byte, 1 = short, 2 = long) */
1074 FALSE
, /* pc_relative */
1076 complain_overflow_dont
, /* complain_on_overflow */
1077 bfd_elf_generic_reloc
, /* special_function */
1078 "R_SH_GOTPLT_MEDHI16", /* name */
1079 FALSE
, /* partial_inplace */
1081 0x3fffc00, /* dst_mask */
1082 FALSE
), /* pcrel_offset */
1084 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1085 HOWTO (R_SH_GOTPLT_HI16
, /* type */
1086 48, /* rightshift */
1087 2, /* size (0 = byte, 1 = short, 2 = long) */
1089 FALSE
, /* pc_relative */
1091 complain_overflow_dont
, /* complain_on_overflow */
1092 bfd_elf_generic_reloc
, /* special_function */
1093 "R_SH_GOTPLT_HI16", /* name */
1094 FALSE
, /* partial_inplace */
1096 0x3fffc00, /* dst_mask */
1097 FALSE
), /* pcrel_offset */
1099 /* Used in MOVI and SHORI (x & 65536). */
1100 HOWTO (R_SH_PLT_LOW16
, /* type */
1102 2, /* size (0 = byte, 1 = short, 2 = long) */
1104 TRUE
, /* pc_relative */
1106 complain_overflow_dont
, /* complain_on_overflow */
1107 bfd_elf_generic_reloc
, /* special_function */
1108 "R_SH_PLT_LOW16", /* name */
1109 FALSE
, /* partial_inplace */
1111 0x3fffc00, /* dst_mask */
1112 TRUE
), /* pcrel_offset */
1114 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1115 HOWTO (R_SH_PLT_MEDLOW16
, /* type */
1116 16, /* rightshift */
1117 2, /* size (0 = byte, 1 = short, 2 = long) */
1119 TRUE
, /* pc_relative */
1121 complain_overflow_dont
, /* complain_on_overflow */
1122 bfd_elf_generic_reloc
, /* special_function */
1123 "R_SH_PLT_MEDLOW16", /* name */
1124 FALSE
, /* partial_inplace */
1126 0x3fffc00, /* dst_mask */
1127 TRUE
), /* pcrel_offset */
1129 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1130 HOWTO (R_SH_PLT_MEDHI16
, /* type */
1131 32, /* rightshift */
1132 2, /* size (0 = byte, 1 = short, 2 = long) */
1134 TRUE
, /* pc_relative */
1136 complain_overflow_dont
, /* complain_on_overflow */
1137 bfd_elf_generic_reloc
, /* special_function */
1138 "R_SH_PLT_MEDHI16", /* name */
1139 FALSE
, /* partial_inplace */
1141 0x3fffc00, /* dst_mask */
1142 TRUE
), /* pcrel_offset */
1144 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1145 HOWTO (R_SH_PLT_HI16
, /* type */
1146 48, /* rightshift */
1147 2, /* size (0 = byte, 1 = short, 2 = long) */
1149 TRUE
, /* pc_relative */
1151 complain_overflow_dont
, /* complain_on_overflow */
1152 bfd_elf_generic_reloc
, /* special_function */
1153 "R_SH_PLT_HI16", /* name */
1154 FALSE
, /* partial_inplace */
1156 0x3fffc00, /* dst_mask */
1157 TRUE
), /* pcrel_offset */
1159 /* Used in MOVI and SHORI (x & 65536). */
1160 HOWTO (R_SH_GOTOFF_LOW16
, /* type */
1162 2, /* size (0 = byte, 1 = short, 2 = long) */
1164 FALSE
, /* pc_relative */
1166 complain_overflow_dont
, /* complain_on_overflow */
1167 bfd_elf_generic_reloc
, /* special_function */
1168 "R_SH_GOTOFF_LOW16", /* name */
1169 FALSE
, /* partial_inplace */
1171 0x3fffc00, /* dst_mask */
1172 FALSE
), /* pcrel_offset */
1174 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1175 HOWTO (R_SH_GOTOFF_MEDLOW16
, /* type */
1176 16, /* rightshift */
1177 2, /* size (0 = byte, 1 = short, 2 = long) */
1179 FALSE
, /* pc_relative */
1181 complain_overflow_dont
, /* complain_on_overflow */
1182 bfd_elf_generic_reloc
, /* special_function */
1183 "R_SH_GOTOFF_MEDLOW16", /* name */
1184 FALSE
, /* partial_inplace */
1186 0x3fffc00, /* dst_mask */
1187 FALSE
), /* pcrel_offset */
1189 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1190 HOWTO (R_SH_GOTOFF_MEDHI16
, /* type */
1191 32, /* rightshift */
1192 2, /* size (0 = byte, 1 = short, 2 = long) */
1194 FALSE
, /* pc_relative */
1196 complain_overflow_dont
, /* complain_on_overflow */
1197 bfd_elf_generic_reloc
, /* special_function */
1198 "R_SH_GOTOFF_MEDHI16", /* name */
1199 FALSE
, /* partial_inplace */
1201 0x3fffc00, /* dst_mask */
1202 FALSE
), /* pcrel_offset */
1204 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1205 HOWTO (R_SH_GOTOFF_HI16
, /* type */
1206 48, /* rightshift */
1207 2, /* size (0 = byte, 1 = short, 2 = long) */
1209 FALSE
, /* pc_relative */
1211 complain_overflow_dont
, /* complain_on_overflow */
1212 bfd_elf_generic_reloc
, /* special_function */
1213 "R_SH_GOTOFF_HI16", /* name */
1214 FALSE
, /* partial_inplace */
1216 0x3fffc00, /* dst_mask */
1217 FALSE
), /* pcrel_offset */
1219 /* Used in MOVI and SHORI (x & 65536). */
1220 HOWTO (R_SH_GOTPC_LOW16
, /* type */
1222 2, /* size (0 = byte, 1 = short, 2 = long) */
1224 TRUE
, /* pc_relative */
1226 complain_overflow_dont
, /* complain_on_overflow */
1227 bfd_elf_generic_reloc
, /* special_function */
1228 "R_SH_GOTPC_LOW16", /* name */
1229 FALSE
, /* partial_inplace */
1231 0x3fffc00, /* dst_mask */
1232 TRUE
), /* pcrel_offset */
1234 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1235 HOWTO (R_SH_GOTPC_MEDLOW16
, /* type */
1236 16, /* rightshift */
1237 2, /* size (0 = byte, 1 = short, 2 = long) */
1239 TRUE
, /* pc_relative */
1241 complain_overflow_dont
, /* complain_on_overflow */
1242 bfd_elf_generic_reloc
, /* special_function */
1243 "R_SH_GOTPC_MEDLOW16", /* name */
1244 FALSE
, /* partial_inplace */
1246 0x3fffc00, /* dst_mask */
1247 TRUE
), /* pcrel_offset */
1249 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1250 HOWTO (R_SH_GOTPC_MEDHI16
, /* type */
1251 32, /* rightshift */
1252 2, /* size (0 = byte, 1 = short, 2 = long) */
1254 TRUE
, /* pc_relative */
1256 complain_overflow_dont
, /* complain_on_overflow */
1257 bfd_elf_generic_reloc
, /* special_function */
1258 "R_SH_GOTPC_MEDHI16", /* name */
1259 FALSE
, /* partial_inplace */
1261 0x3fffc00, /* dst_mask */
1262 TRUE
), /* pcrel_offset */
1264 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1265 HOWTO (R_SH_GOTPC_HI16
, /* type */
1266 48, /* rightshift */
1267 2, /* size (0 = byte, 1 = short, 2 = long) */
1269 TRUE
, /* pc_relative */
1271 complain_overflow_dont
, /* complain_on_overflow */
1272 bfd_elf_generic_reloc
, /* special_function */
1273 "R_SH_GOTPC_HI16", /* name */
1274 FALSE
, /* partial_inplace */
1276 0x3fffc00, /* dst_mask */
1277 TRUE
), /* pcrel_offset */
1279 /* Used in LD.L, FLD.S et al. */
1280 HOWTO (R_SH_GOT10BY4
, /* type */
1282 2, /* size (0 = byte, 1 = short, 2 = long) */
1284 FALSE
, /* pc_relative */
1286 complain_overflow_signed
, /* complain_on_overflow */
1287 bfd_elf_generic_reloc
, /* special_function */
1288 "R_SH_GOT10BY4", /* name */
1289 FALSE
, /* partial_inplace */
1291 0xffc00, /* dst_mask */
1292 FALSE
), /* pcrel_offset */
1294 /* Used in LD.L, FLD.S et al. */
1295 HOWTO (R_SH_GOTPLT10BY4
, /* type */
1297 2, /* size (0 = byte, 1 = short, 2 = long) */
1299 FALSE
, /* pc_relative */
1301 complain_overflow_signed
, /* complain_on_overflow */
1302 bfd_elf_generic_reloc
, /* special_function */
1303 "R_SH_GOTPLT10BY4", /* name */
1304 FALSE
, /* partial_inplace */
1306 0xffc00, /* dst_mask */
1307 FALSE
), /* pcrel_offset */
1309 /* Used in FLD.D, FST.P et al. */
1310 HOWTO (R_SH_GOT10BY8
, /* type */
1312 2, /* size (0 = byte, 1 = short, 2 = long) */
1314 FALSE
, /* pc_relative */
1316 complain_overflow_signed
, /* complain_on_overflow */
1317 bfd_elf_generic_reloc
, /* special_function */
1318 "R_SH_GOT10BY8", /* name */
1319 FALSE
, /* partial_inplace */
1321 0xffc00, /* dst_mask */
1322 FALSE
), /* pcrel_offset */
1324 /* Used in FLD.D, FST.P et al. */
1325 HOWTO (R_SH_GOTPLT10BY8
, /* type */
1327 2, /* size (0 = byte, 1 = short, 2 = long) */
1329 FALSE
, /* pc_relative */
1331 complain_overflow_signed
, /* complain_on_overflow */
1332 bfd_elf_generic_reloc
, /* special_function */
1333 "R_SH_GOTPLT10BY8", /* name */
1334 FALSE
, /* partial_inplace */
1336 0xffc00, /* dst_mask */
1337 FALSE
), /* pcrel_offset */
1339 HOWTO (R_SH_COPY64
, /* type */
1341 4, /* size (0 = byte, 1 = short, 2 = long) */
1343 FALSE
, /* pc_relative */
1345 complain_overflow_dont
, /* complain_on_overflow */
1346 bfd_elf_generic_reloc
, /* special_function */
1347 "R_SH_COPY64", /* name */
1348 FALSE
, /* partial_inplace */
1350 ((bfd_vma
) 0) - 1, /* dst_mask */
1351 FALSE
), /* pcrel_offset */
1353 HOWTO (R_SH_GLOB_DAT64
, /* type */
1355 4, /* size (0 = byte, 1 = short, 2 = long) */
1357 FALSE
, /* pc_relative */
1359 complain_overflow_dont
, /* complain_on_overflow */
1360 bfd_elf_generic_reloc
, /* special_function */
1361 "R_SH_GLOB_DAT64", /* name */
1362 FALSE
, /* partial_inplace */
1364 ((bfd_vma
) 0) - 1, /* dst_mask */
1365 FALSE
), /* pcrel_offset */
1367 HOWTO (R_SH_JMP_SLOT64
, /* type */
1369 4, /* size (0 = byte, 1 = short, 2 = long) */
1371 FALSE
, /* pc_relative */
1373 complain_overflow_dont
, /* complain_on_overflow */
1374 bfd_elf_generic_reloc
, /* special_function */
1375 "R_SH_JMP_SLOT64", /* name */
1376 FALSE
, /* partial_inplace */
1378 ((bfd_vma
) 0) - 1, /* dst_mask */
1379 FALSE
), /* pcrel_offset */
1381 HOWTO (R_SH_RELATIVE64
, /* type */
1383 4, /* size (0 = byte, 1 = short, 2 = long) */
1385 FALSE
, /* pc_relative */
1387 complain_overflow_dont
, /* complain_on_overflow */
1388 bfd_elf_generic_reloc
, /* special_function */
1389 "R_SH_RELATIVE64", /* name */
1390 FALSE
, /* partial_inplace */
1392 ((bfd_vma
) 0) - 1, /* dst_mask */
1393 FALSE
), /* pcrel_offset */
1441 /* Relocations for SHmedia code. None of these are partial_inplace or
1442 use the field being relocated (except R_SH_PT_16). */
1444 /* The assembler will generate this reloc before a block of SHmedia
1445 instructions. A section should be processed as assuming it contains
1446 data, unless this reloc is seen. Note that a block of SHcompact
1447 instructions are instead preceded by R_SH_CODE.
1448 This is currently not implemented, but should be used for SHmedia
1449 linker relaxation. */
1450 HOWTO (R_SH_SHMEDIA_CODE
, /* type */
1452 1, /* size (0 = byte, 1 = short, 2 = long) */
1454 FALSE
, /* pc_relative */
1456 complain_overflow_unsigned
, /* complain_on_overflow */
1457 sh_elf_ignore_reloc
, /* special_function */
1458 "R_SH_SHMEDIA_CODE", /* name */
1459 FALSE
, /* partial_inplace */
1462 FALSE
), /* pcrel_offset */
1464 /* The assembler will generate this reloc at a PTA or PTB instruction,
1465 and the linker checks the right type of target, or changes a PTA to a
1466 PTB, if the original insn was PT. */
1467 HOWTO (R_SH_PT_16
, /* type */
1469 2, /* size (0 = byte, 1 = short, 2 = long) */
1471 TRUE
, /* pc_relative */
1473 complain_overflow_signed
, /* complain_on_overflow */
1474 bfd_elf_generic_reloc
, /* special_function */
1475 "R_SH_PT_16", /* name */
1476 FALSE
, /* partial_inplace */
1478 0x3fffc00, /* dst_mask */
1479 TRUE
), /* pcrel_offset */
1481 /* Used in unexpanded MOVI. */
1482 HOWTO (R_SH_IMMS16
, /* type */
1484 2, /* size (0 = byte, 1 = short, 2 = long) */
1486 FALSE
, /* pc_relative */
1488 complain_overflow_signed
, /* complain_on_overflow */
1489 bfd_elf_generic_reloc
, /* special_function */
1490 "R_SH_IMMS16", /* name */
1491 FALSE
, /* partial_inplace */
1493 0x3fffc00, /* dst_mask */
1494 FALSE
), /* pcrel_offset */
1496 /* Used in SHORI. */
1497 HOWTO (R_SH_IMMU16
, /* type */
1499 2, /* size (0 = byte, 1 = short, 2 = long) */
1501 FALSE
, /* pc_relative */
1503 complain_overflow_unsigned
, /* complain_on_overflow */
1504 bfd_elf_generic_reloc
, /* special_function */
1505 "R_SH_IMMU16", /* name */
1506 FALSE
, /* partial_inplace */
1508 0x3fffc00, /* dst_mask */
1509 FALSE
), /* pcrel_offset */
1511 /* Used in MOVI and SHORI (x & 65536). */
1512 HOWTO (R_SH_IMM_LOW16
, /* type */
1514 2, /* size (0 = byte, 1 = short, 2 = long) */
1516 FALSE
, /* pc_relative */
1518 complain_overflow_dont
, /* complain_on_overflow */
1519 bfd_elf_generic_reloc
, /* special_function */
1520 "R_SH_IMM_LOW16", /* name */
1521 FALSE
, /* partial_inplace */
1523 0x3fffc00, /* dst_mask */
1524 FALSE
), /* pcrel_offset */
1526 /* Used in MOVI and SHORI ((x - $) & 65536). */
1527 HOWTO (R_SH_IMM_LOW16_PCREL
, /* type */
1529 2, /* size (0 = byte, 1 = short, 2 = long) */
1531 TRUE
, /* pc_relative */
1533 complain_overflow_dont
, /* complain_on_overflow */
1534 bfd_elf_generic_reloc
, /* special_function */
1535 "R_SH_IMM_LOW16_PCREL", /* name */
1536 FALSE
, /* partial_inplace */
1538 0x3fffc00, /* dst_mask */
1539 TRUE
), /* pcrel_offset */
1541 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1542 HOWTO (R_SH_IMM_MEDLOW16
, /* type */
1543 16, /* rightshift */
1544 2, /* size (0 = byte, 1 = short, 2 = long) */
1546 FALSE
, /* pc_relative */
1548 complain_overflow_dont
, /* complain_on_overflow */
1549 bfd_elf_generic_reloc
, /* special_function */
1550 "R_SH_IMM_MEDLOW16", /* name */
1551 FALSE
, /* partial_inplace */
1553 0x3fffc00, /* dst_mask */
1554 FALSE
), /* pcrel_offset */
1556 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1557 HOWTO (R_SH_IMM_MEDLOW16_PCREL
, /* type */
1558 16, /* rightshift */
1559 2, /* size (0 = byte, 1 = short, 2 = long) */
1561 TRUE
, /* pc_relative */
1563 complain_overflow_dont
, /* complain_on_overflow */
1564 bfd_elf_generic_reloc
, /* special_function */
1565 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1566 FALSE
, /* partial_inplace */
1568 0x3fffc00, /* dst_mask */
1569 TRUE
), /* pcrel_offset */
1571 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1572 HOWTO (R_SH_IMM_MEDHI16
, /* type */
1573 32, /* rightshift */
1574 2, /* size (0 = byte, 1 = short, 2 = long) */
1576 FALSE
, /* pc_relative */
1578 complain_overflow_dont
, /* complain_on_overflow */
1579 bfd_elf_generic_reloc
, /* special_function */
1580 "R_SH_IMM_MEDHI16", /* name */
1581 FALSE
, /* partial_inplace */
1583 0x3fffc00, /* dst_mask */
1584 FALSE
), /* pcrel_offset */
1586 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1587 HOWTO (R_SH_IMM_MEDHI16_PCREL
, /* type */
1588 32, /* rightshift */
1589 2, /* size (0 = byte, 1 = short, 2 = long) */
1591 TRUE
, /* pc_relative */
1593 complain_overflow_dont
, /* complain_on_overflow */
1594 bfd_elf_generic_reloc
, /* special_function */
1595 "R_SH_IMM_MEDHI16_PCREL", /* name */
1596 FALSE
, /* partial_inplace */
1598 0x3fffc00, /* dst_mask */
1599 TRUE
), /* pcrel_offset */
1601 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1602 HOWTO (R_SH_IMM_HI16
, /* type */
1603 48, /* rightshift */
1604 2, /* size (0 = byte, 1 = short, 2 = long) */
1606 FALSE
, /* pc_relative */
1608 complain_overflow_dont
, /* complain_on_overflow */
1609 bfd_elf_generic_reloc
, /* special_function */
1610 "R_SH_IMM_HI16", /* name */
1611 FALSE
, /* partial_inplace */
1613 0x3fffc00, /* dst_mask */
1614 FALSE
), /* pcrel_offset */
1616 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1617 HOWTO (R_SH_IMM_HI16_PCREL
, /* type */
1618 48, /* rightshift */
1619 2, /* size (0 = byte, 1 = short, 2 = long) */
1621 TRUE
, /* pc_relative */
1623 complain_overflow_dont
, /* complain_on_overflow */
1624 bfd_elf_generic_reloc
, /* special_function */
1625 "R_SH_IMM_HI16_PCREL", /* name */
1626 FALSE
, /* partial_inplace */
1628 0x3fffc00, /* dst_mask */
1629 TRUE
), /* pcrel_offset */
1631 /* For the .uaquad pseudo. */
1632 HOWTO (R_SH_64
, /* type */
1634 4, /* size (0 = byte, 1 = short, 2 = long) */
1636 FALSE
, /* pc_relative */
1638 complain_overflow_dont
, /* complain_on_overflow */
1639 bfd_elf_generic_reloc
, /* special_function */
1640 "R_SH_64", /* name */
1641 FALSE
, /* partial_inplace */
1643 ((bfd_vma
) 0) - 1, /* dst_mask */
1644 FALSE
), /* pcrel_offset */
1646 /* For the .uaquad pseudo, (x - $). */
1647 HOWTO (R_SH_64_PCREL
, /* type */
1648 48, /* rightshift */
1649 2, /* size (0 = byte, 1 = short, 2 = long) */
1651 TRUE
, /* pc_relative */
1653 complain_overflow_dont
, /* complain_on_overflow */
1654 bfd_elf_generic_reloc
, /* special_function */
1655 "R_SH_64_PCREL", /* name */
1656 FALSE
, /* partial_inplace */
1658 ((bfd_vma
) 0) - 1, /* dst_mask */
1659 TRUE
), /* pcrel_offset */
1664 static bfd_reloc_status_type
1665 sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
, addr
,
1666 symbol_section
, start
, end
)
1667 int r_type ATTRIBUTE_UNUSED
;
1669 asection
*input_section
;
1672 asection
*symbol_section
;
1675 static bfd_vma last_addr
;
1676 static asection
*last_symbol_section
;
1677 bfd_byte
*start_ptr
, *ptr
, *last_ptr
;
1682 /* Sanity check the address. */
1683 if (addr
> input_section
->_raw_size
)
1684 return bfd_reloc_outofrange
;
1686 /* We require the start and end relocations to be processed consecutively -
1687 although we allow then to be processed forwards or backwards. */
1691 last_symbol_section
= symbol_section
;
1692 return bfd_reloc_ok
;
1694 if (last_addr
!= addr
)
1698 if (! symbol_section
|| last_symbol_section
!= symbol_section
|| end
< start
)
1699 return bfd_reloc_outofrange
;
1701 /* Get the symbol_section contents. */
1702 if (symbol_section
!= input_section
)
1704 if (elf_section_data (symbol_section
)->this_hdr
.contents
!= NULL
)
1705 contents
= elf_section_data (symbol_section
)->this_hdr
.contents
;
1708 contents
= (bfd_byte
*) bfd_malloc (symbol_section
->_raw_size
);
1709 if (contents
== NULL
)
1710 return bfd_reloc_outofrange
;
1711 if (! bfd_get_section_contents (input_bfd
, symbol_section
, contents
,
1713 symbol_section
->_raw_size
))
1716 return bfd_reloc_outofrange
;
1720 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
1721 start_ptr
= contents
+ start
;
1722 for (cum_diff
= -6, ptr
= contents
+ end
; cum_diff
< 0 && ptr
> start_ptr
;)
1724 for (last_ptr
= ptr
, ptr
-= 4; ptr
>= start_ptr
&& IS_PPI (ptr
);)
1727 diff
= (last_ptr
- ptr
) >> 1;
1728 cum_diff
+= diff
& 1;
1731 /* Calculate the start / end values to load into rs / re minus four -
1732 so that will cancel out the four we would otherwise have to add to
1733 addr to get the value to subtract in order to get relative addressing. */
1737 end
= (ptr
+ cum_diff
* 2) - contents
;
1741 bfd_vma start0
= start
- 4;
1743 while (start0
&& IS_PPI (contents
+ start0
))
1745 start0
= start
- 2 - ((start
- start0
) & 2);
1746 start
= start0
- cum_diff
- 2;
1750 if (contents
!= NULL
1751 && elf_section_data (symbol_section
)->this_hdr
.contents
!= contents
)
1754 insn
= bfd_get_16 (input_bfd
, contents
+ addr
);
1756 x
= (insn
& 0x200 ? end
: start
) - addr
;
1757 if (input_section
!= symbol_section
)
1758 x
+= ((symbol_section
->output_section
->vma
+ symbol_section
->output_offset
)
1759 - (input_section
->output_section
->vma
1760 + input_section
->output_offset
));
1762 if (x
< -128 || x
> 127)
1763 return bfd_reloc_overflow
;
1765 x
= (insn
& ~0xff) | (x
& 0xff);
1766 bfd_put_16 (input_bfd
, (bfd_vma
) x
, contents
+ addr
);
1768 return bfd_reloc_ok
;
1771 /* This function is used for normal relocs. This used to be like the COFF
1772 function, and is almost certainly incorrect for other ELF targets. */
1774 static bfd_reloc_status_type
1775 sh_elf_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
1778 arelent
*reloc_entry
;
1781 asection
*input_section
;
1783 char **error_message ATTRIBUTE_UNUSED
;
1787 enum elf_sh_reloc_type r_type
;
1788 bfd_vma addr
= reloc_entry
->address
;
1789 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
1791 r_type
= (enum elf_sh_reloc_type
) reloc_entry
->howto
->type
;
1793 if (output_bfd
!= NULL
)
1795 /* Partial linking--do nothing. */
1796 reloc_entry
->address
+= input_section
->output_offset
;
1797 return bfd_reloc_ok
;
1800 /* Almost all relocs have to do with relaxing. If any work must be
1801 done for them, it has been done in sh_relax_section. */
1802 if (r_type
== R_SH_IND12W
&& (symbol_in
->flags
& BSF_LOCAL
) != 0)
1803 return bfd_reloc_ok
;
1805 if (symbol_in
!= NULL
1806 && bfd_is_und_section (symbol_in
->section
))
1807 return bfd_reloc_undefined
;
1809 if (bfd_is_com_section (symbol_in
->section
))
1812 sym_value
= (symbol_in
->value
+
1813 symbol_in
->section
->output_section
->vma
+
1814 symbol_in
->section
->output_offset
);
1819 insn
= bfd_get_32 (abfd
, hit_data
);
1820 insn
+= sym_value
+ reloc_entry
->addend
;
1821 bfd_put_32 (abfd
, (bfd_vma
) insn
, hit_data
);
1824 insn
= bfd_get_16 (abfd
, hit_data
);
1825 sym_value
+= reloc_entry
->addend
;
1826 sym_value
-= (input_section
->output_section
->vma
1827 + input_section
->output_offset
1830 sym_value
+= (insn
& 0xfff) << 1;
1832 sym_value
-= 0x1000;
1833 insn
= (insn
& 0xf000) | (sym_value
& 0xfff);
1834 bfd_put_16 (abfd
, (bfd_vma
) insn
, hit_data
);
1835 if (sym_value
< (bfd_vma
) -0x1000 || sym_value
>= 0x1000)
1836 return bfd_reloc_overflow
;
1843 return bfd_reloc_ok
;
1846 /* This function is used for relocs which are only used for relaxing,
1847 which the linker should otherwise ignore. */
1849 static bfd_reloc_status_type
1850 sh_elf_ignore_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1851 output_bfd
, error_message
)
1852 bfd
*abfd ATTRIBUTE_UNUSED
;
1853 arelent
*reloc_entry
;
1854 asymbol
*symbol ATTRIBUTE_UNUSED
;
1855 PTR data ATTRIBUTE_UNUSED
;
1856 asection
*input_section
;
1858 char **error_message ATTRIBUTE_UNUSED
;
1860 if (output_bfd
!= NULL
)
1861 reloc_entry
->address
+= input_section
->output_offset
;
1862 return bfd_reloc_ok
;
1865 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
1867 struct elf_reloc_map
1869 bfd_reloc_code_real_type bfd_reloc_val
;
1870 unsigned char elf_reloc_val
;
1873 /* An array mapping BFD reloc codes to SH ELF relocs. */
1875 static const struct elf_reloc_map sh_reloc_map
[] =
1877 { BFD_RELOC_NONE
, R_SH_NONE
},
1878 { BFD_RELOC_32
, R_SH_DIR32
},
1879 { BFD_RELOC_CTOR
, R_SH_DIR32
},
1880 { BFD_RELOC_32_PCREL
, R_SH_REL32
},
1881 { BFD_RELOC_SH_PCDISP8BY2
, R_SH_DIR8WPN
},
1882 { BFD_RELOC_SH_PCDISP12BY2
, R_SH_IND12W
},
1883 { BFD_RELOC_SH_PCRELIMM8BY2
, R_SH_DIR8WPZ
},
1884 { BFD_RELOC_SH_PCRELIMM8BY4
, R_SH_DIR8WPL
},
1885 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
1886 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
1887 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
1888 { BFD_RELOC_SH_USES
, R_SH_USES
},
1889 { BFD_RELOC_SH_COUNT
, R_SH_COUNT
},
1890 { BFD_RELOC_SH_ALIGN
, R_SH_ALIGN
},
1891 { BFD_RELOC_SH_CODE
, R_SH_CODE
},
1892 { BFD_RELOC_SH_DATA
, R_SH_DATA
},
1893 { BFD_RELOC_SH_LABEL
, R_SH_LABEL
},
1894 { BFD_RELOC_VTABLE_INHERIT
, R_SH_GNU_VTINHERIT
},
1895 { BFD_RELOC_VTABLE_ENTRY
, R_SH_GNU_VTENTRY
},
1896 { BFD_RELOC_SH_LOOP_START
, R_SH_LOOP_START
},
1897 { BFD_RELOC_SH_LOOP_END
, R_SH_LOOP_END
},
1898 { BFD_RELOC_SH_TLS_GD_32
, R_SH_TLS_GD_32
},
1899 { BFD_RELOC_SH_TLS_LD_32
, R_SH_TLS_LD_32
},
1900 { BFD_RELOC_SH_TLS_LDO_32
, R_SH_TLS_LDO_32
},
1901 { BFD_RELOC_SH_TLS_IE_32
, R_SH_TLS_IE_32
},
1902 { BFD_RELOC_SH_TLS_LE_32
, R_SH_TLS_LE_32
},
1903 { BFD_RELOC_SH_TLS_DTPMOD32
, R_SH_TLS_DTPMOD32
},
1904 { BFD_RELOC_SH_TLS_DTPOFF32
, R_SH_TLS_DTPOFF32
},
1905 { BFD_RELOC_SH_TLS_TPOFF32
, R_SH_TLS_TPOFF32
},
1906 { BFD_RELOC_32_GOT_PCREL
, R_SH_GOT32
},
1907 { BFD_RELOC_32_PLT_PCREL
, R_SH_PLT32
},
1908 { BFD_RELOC_SH_COPY
, R_SH_COPY
},
1909 { BFD_RELOC_SH_GLOB_DAT
, R_SH_GLOB_DAT
},
1910 { BFD_RELOC_SH_JMP_SLOT
, R_SH_JMP_SLOT
},
1911 { BFD_RELOC_SH_RELATIVE
, R_SH_RELATIVE
},
1912 { BFD_RELOC_32_GOTOFF
, R_SH_GOTOFF
},
1913 { BFD_RELOC_SH_GOTPC
, R_SH_GOTPC
},
1914 { BFD_RELOC_SH_GOTPLT32
, R_SH_GOTPLT32
},
1915 #ifdef INCLUDE_SHMEDIA
1916 { BFD_RELOC_SH_GOT_LOW16
, R_SH_GOT_LOW16
},
1917 { BFD_RELOC_SH_GOT_MEDLOW16
, R_SH_GOT_MEDLOW16
},
1918 { BFD_RELOC_SH_GOT_MEDHI16
, R_SH_GOT_MEDHI16
},
1919 { BFD_RELOC_SH_GOT_HI16
, R_SH_GOT_HI16
},
1920 { BFD_RELOC_SH_GOTPLT_LOW16
, R_SH_GOTPLT_LOW16
},
1921 { BFD_RELOC_SH_GOTPLT_MEDLOW16
, R_SH_GOTPLT_MEDLOW16
},
1922 { BFD_RELOC_SH_GOTPLT_MEDHI16
, R_SH_GOTPLT_MEDHI16
},
1923 { BFD_RELOC_SH_GOTPLT_HI16
, R_SH_GOTPLT_HI16
},
1924 { BFD_RELOC_SH_PLT_LOW16
, R_SH_PLT_LOW16
},
1925 { BFD_RELOC_SH_PLT_MEDLOW16
, R_SH_PLT_MEDLOW16
},
1926 { BFD_RELOC_SH_PLT_MEDHI16
, R_SH_PLT_MEDHI16
},
1927 { BFD_RELOC_SH_PLT_HI16
, R_SH_PLT_HI16
},
1928 { BFD_RELOC_SH_GOTOFF_LOW16
, R_SH_GOTOFF_LOW16
},
1929 { BFD_RELOC_SH_GOTOFF_MEDLOW16
, R_SH_GOTOFF_MEDLOW16
},
1930 { BFD_RELOC_SH_GOTOFF_MEDHI16
, R_SH_GOTOFF_MEDHI16
},
1931 { BFD_RELOC_SH_GOTOFF_HI16
, R_SH_GOTOFF_HI16
},
1932 { BFD_RELOC_SH_GOTPC_LOW16
, R_SH_GOTPC_LOW16
},
1933 { BFD_RELOC_SH_GOTPC_MEDLOW16
, R_SH_GOTPC_MEDLOW16
},
1934 { BFD_RELOC_SH_GOTPC_MEDHI16
, R_SH_GOTPC_MEDHI16
},
1935 { BFD_RELOC_SH_GOTPC_HI16
, R_SH_GOTPC_HI16
},
1936 { BFD_RELOC_SH_COPY64
, R_SH_COPY64
},
1937 { BFD_RELOC_SH_GLOB_DAT64
, R_SH_GLOB_DAT64
},
1938 { BFD_RELOC_SH_JMP_SLOT64
, R_SH_JMP_SLOT64
},
1939 { BFD_RELOC_SH_RELATIVE64
, R_SH_RELATIVE64
},
1940 { BFD_RELOC_SH_GOT10BY4
, R_SH_GOT10BY4
},
1941 { BFD_RELOC_SH_GOT10BY8
, R_SH_GOT10BY8
},
1942 { BFD_RELOC_SH_GOTPLT10BY4
, R_SH_GOTPLT10BY4
},
1943 { BFD_RELOC_SH_GOTPLT10BY8
, R_SH_GOTPLT10BY8
},
1944 { BFD_RELOC_SH_PT_16
, R_SH_PT_16
},
1945 { BFD_RELOC_SH_SHMEDIA_CODE
, R_SH_SHMEDIA_CODE
},
1946 { BFD_RELOC_SH_IMMU5
, R_SH_DIR5U
},
1947 { BFD_RELOC_SH_IMMS6
, R_SH_DIR6S
},
1948 { BFD_RELOC_SH_IMMU6
, R_SH_DIR6U
},
1949 { BFD_RELOC_SH_IMMS10
, R_SH_DIR10S
},
1950 { BFD_RELOC_SH_IMMS10BY2
, R_SH_DIR10SW
},
1951 { BFD_RELOC_SH_IMMS10BY4
, R_SH_DIR10SL
},
1952 { BFD_RELOC_SH_IMMS10BY8
, R_SH_DIR10SQ
},
1953 { BFD_RELOC_SH_IMMS16
, R_SH_IMMS16
},
1954 { BFD_RELOC_SH_IMMU16
, R_SH_IMMU16
},
1955 { BFD_RELOC_SH_IMM_LOW16
, R_SH_IMM_LOW16
},
1956 { BFD_RELOC_SH_IMM_LOW16_PCREL
, R_SH_IMM_LOW16_PCREL
},
1957 { BFD_RELOC_SH_IMM_MEDLOW16
, R_SH_IMM_MEDLOW16
},
1958 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL
, R_SH_IMM_MEDLOW16_PCREL
},
1959 { BFD_RELOC_SH_IMM_MEDHI16
, R_SH_IMM_MEDHI16
},
1960 { BFD_RELOC_SH_IMM_MEDHI16_PCREL
, R_SH_IMM_MEDHI16_PCREL
},
1961 { BFD_RELOC_SH_IMM_HI16
, R_SH_IMM_HI16
},
1962 { BFD_RELOC_SH_IMM_HI16_PCREL
, R_SH_IMM_HI16_PCREL
},
1963 { BFD_RELOC_64
, R_SH_64
},
1964 { BFD_RELOC_64_PCREL
, R_SH_64_PCREL
},
1965 #endif /* not INCLUDE_SHMEDIA */
1968 /* Given a BFD reloc code, return the howto structure for the
1969 corresponding SH ELf reloc. */
1971 static reloc_howto_type
*
1972 sh_elf_reloc_type_lookup (abfd
, code
)
1973 bfd
*abfd ATTRIBUTE_UNUSED
;
1974 bfd_reloc_code_real_type code
;
1978 for (i
= 0; i
< sizeof (sh_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1980 if (sh_reloc_map
[i
].bfd_reloc_val
== code
)
1981 return &sh_elf_howto_table
[(int) sh_reloc_map
[i
].elf_reloc_val
];
1987 /* Given an ELF reloc, fill in the howto field of a relent. */
1990 sh_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1991 bfd
*abfd ATTRIBUTE_UNUSED
;
1993 Elf_Internal_Rela
*dst
;
1997 r
= ELF32_R_TYPE (dst
->r_info
);
1999 BFD_ASSERT (r
< (unsigned int) R_SH_max
);
2000 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC
|| r
> R_SH_LAST_INVALID_RELOC
);
2001 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_2
|| r
> R_SH_LAST_INVALID_RELOC_2
);
2002 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_3
|| r
> R_SH_LAST_INVALID_RELOC_3
);
2003 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_4
|| r
> R_SH_LAST_INVALID_RELOC_4
);
2004 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_5
|| r
> R_SH_LAST_INVALID_RELOC_5
);
2006 cache_ptr
->howto
= &sh_elf_howto_table
[r
];
2009 /* This function handles relaxing for SH ELF. See the corresponding
2010 function in coff-sh.c for a description of what this does. FIXME:
2011 There is a lot of duplication here between this code and the COFF
2012 specific code. The format of relocs and symbols is wound deeply
2013 into this code, but it would still be better if the duplication
2014 could be eliminated somehow. Note in particular that although both
2015 functions use symbols like R_SH_CODE, those symbols have different
2016 values; in coff-sh.c they come from include/coff/sh.h, whereas here
2017 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
2020 sh_elf_relax_section (abfd
, sec
, link_info
, again
)
2023 struct bfd_link_info
*link_info
;
2026 Elf_Internal_Shdr
*symtab_hdr
;
2027 Elf_Internal_Rela
*internal_relocs
;
2028 bfd_boolean have_code
;
2029 Elf_Internal_Rela
*irel
, *irelend
;
2030 bfd_byte
*contents
= NULL
;
2031 Elf_Internal_Sym
*isymbuf
= NULL
;
2035 if (link_info
->relocateable
2036 || (sec
->flags
& SEC_RELOC
) == 0
2037 || sec
->reloc_count
== 0)
2040 #ifdef INCLUDE_SHMEDIA
2041 if (elf_section_data (sec
)->this_hdr
.sh_flags
2042 & (SHF_SH5_ISA32
| SHF_SH5_ISA32_MIXED
))
2048 /* If this is the first time we have been called for this section,
2049 initialize the cooked size. */
2050 if (sec
->_cooked_size
== 0)
2051 sec
->_cooked_size
= sec
->_raw_size
;
2053 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2055 internal_relocs
= (_bfd_elf32_link_read_relocs
2056 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
2057 link_info
->keep_memory
));
2058 if (internal_relocs
== NULL
)
2063 irelend
= internal_relocs
+ sec
->reloc_count
;
2064 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2066 bfd_vma laddr
, paddr
, symval
;
2067 unsigned short insn
;
2068 Elf_Internal_Rela
*irelfn
, *irelscan
, *irelcount
;
2069 bfd_signed_vma foff
;
2071 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_CODE
)
2074 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_USES
)
2077 /* Get the section contents. */
2078 if (contents
== NULL
)
2080 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2081 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2084 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
2085 if (contents
== NULL
)
2088 if (! bfd_get_section_contents (abfd
, sec
, contents
,
2089 (file_ptr
) 0, sec
->_raw_size
))
2094 /* The r_addend field of the R_SH_USES reloc will point us to
2095 the register load. The 4 is because the r_addend field is
2096 computed as though it were a jump offset, which are based
2097 from 4 bytes after the jump instruction. */
2098 laddr
= irel
->r_offset
+ 4 + irel
->r_addend
;
2099 if (laddr
>= sec
->_raw_size
)
2101 (*_bfd_error_handler
) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),
2102 bfd_archive_filename (abfd
),
2103 (unsigned long) irel
->r_offset
);
2106 insn
= bfd_get_16 (abfd
, contents
+ laddr
);
2108 /* If the instruction is not mov.l NN,rN, we don't know what to
2110 if ((insn
& 0xf000) != 0xd000)
2112 ((*_bfd_error_handler
)
2113 (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
2114 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
, insn
));
2118 /* Get the address from which the register is being loaded. The
2119 displacement in the mov.l instruction is quadrupled. It is a
2120 displacement from four bytes after the movl instruction, but,
2121 before adding in the PC address, two least significant bits
2122 of the PC are cleared. We assume that the section is aligned
2123 on a four byte boundary. */
2124 paddr
= insn
& 0xff;
2126 paddr
+= (laddr
+ 4) &~ (bfd_vma
) 3;
2127 if (paddr
>= sec
->_raw_size
)
2129 ((*_bfd_error_handler
)
2130 (_("%s: 0x%lx: warning: bad R_SH_USES load offset"),
2131 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
2135 /* Get the reloc for the address from which the register is
2136 being loaded. This reloc will tell us which function is
2137 actually being called. */
2138 for (irelfn
= internal_relocs
; irelfn
< irelend
; irelfn
++)
2139 if (irelfn
->r_offset
== paddr
2140 && ELF32_R_TYPE (irelfn
->r_info
) == (int) R_SH_DIR32
)
2142 if (irelfn
>= irelend
)
2144 ((*_bfd_error_handler
)
2145 (_("%s: 0x%lx: warning: could not find expected reloc"),
2146 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2150 /* Read this BFD's symbols if we haven't done so already. */
2151 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
2153 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2154 if (isymbuf
== NULL
)
2155 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2156 symtab_hdr
->sh_info
, 0,
2158 if (isymbuf
== NULL
)
2162 /* Get the value of the symbol referred to by the reloc. */
2163 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
2165 /* A local symbol. */
2166 Elf_Internal_Sym
*isym
;
2168 isym
= isymbuf
+ ELF32_R_SYM (irelfn
->r_info
);
2170 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd
, sec
))
2172 ((*_bfd_error_handler
)
2173 (_("%s: 0x%lx: warning: symbol in unexpected section"),
2174 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2178 symval
= (isym
->st_value
2179 + sec
->output_section
->vma
2180 + sec
->output_offset
);
2185 struct elf_link_hash_entry
*h
;
2187 indx
= ELF32_R_SYM (irelfn
->r_info
) - symtab_hdr
->sh_info
;
2188 h
= elf_sym_hashes (abfd
)[indx
];
2189 BFD_ASSERT (h
!= NULL
);
2190 if (h
->root
.type
!= bfd_link_hash_defined
2191 && h
->root
.type
!= bfd_link_hash_defweak
)
2193 /* This appears to be a reference to an undefined
2194 symbol. Just ignore it--it will be caught by the
2195 regular reloc processing. */
2199 symval
= (h
->root
.u
.def
.value
2200 + h
->root
.u
.def
.section
->output_section
->vma
2201 + h
->root
.u
.def
.section
->output_offset
);
2204 symval
+= bfd_get_32 (abfd
, contents
+ paddr
);
2206 /* See if this function call can be shortened. */
2209 + sec
->output_section
->vma
2210 + sec
->output_offset
2212 if (foff
< -0x1000 || foff
>= 0x1000)
2214 /* After all that work, we can't shorten this function call. */
2218 /* Shorten the function call. */
2220 /* For simplicity of coding, we are going to modify the section
2221 contents, the section relocs, and the BFD symbol table. We
2222 must tell the rest of the code not to free up this
2223 information. It would be possible to instead create a table
2224 of changes which have to be made, as is done in coff-mips.c;
2225 that would be more work, but would require less memory when
2226 the linker is run. */
2228 elf_section_data (sec
)->relocs
= internal_relocs
;
2229 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2230 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2232 /* Replace the jsr with a bsr. */
2234 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
2235 replace the jsr with a bsr. */
2236 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irelfn
->r_info
), R_SH_IND12W
);
2237 /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2238 here, but that only checks if the symbol is an external symbol,
2239 not if the symbol is in a different section. Besides, we need
2240 a consistent meaning for the relocation, so we just assume here that
2241 the value of the symbol is not available. */
2243 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
2245 /* If this needs to be changed because of future relaxing,
2246 it will be handled here like other internal IND12W
2249 (bfd_vma
) 0xb000 | ((foff
>> 1) & 0xfff),
2250 contents
+ irel
->r_offset
);
2255 /* We can't fully resolve this yet, because the external
2256 symbol value may be changed by future relaxing. We let
2257 the final link phase handle it. */
2258 bfd_put_16 (abfd
, (bfd_vma
) 0xb000, contents
+ irel
->r_offset
);
2260 irel
->r_addend
= -4;
2262 /* See if there is another R_SH_USES reloc referring to the same
2264 for (irelscan
= internal_relocs
; irelscan
< irelend
; irelscan
++)
2265 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_USES
2266 && laddr
== irelscan
->r_offset
+ 4 + irelscan
->r_addend
)
2268 if (irelscan
< irelend
)
2270 /* Some other function call depends upon this register load,
2271 and we have not yet converted that function call.
2272 Indeed, we may never be able to convert it. There is
2273 nothing else we can do at this point. */
2277 /* Look for a R_SH_COUNT reloc on the location where the
2278 function address is stored. Do this before deleting any
2279 bytes, to avoid confusion about the address. */
2280 for (irelcount
= internal_relocs
; irelcount
< irelend
; irelcount
++)
2281 if (irelcount
->r_offset
== paddr
2282 && ELF32_R_TYPE (irelcount
->r_info
) == (int) R_SH_COUNT
)
2285 /* Delete the register load. */
2286 if (! sh_elf_relax_delete_bytes (abfd
, sec
, laddr
, 2))
2289 /* That will change things, so, just in case it permits some
2290 other function call to come within range, we should relax
2291 again. Note that this is not required, and it may be slow. */
2294 /* Now check whether we got a COUNT reloc. */
2295 if (irelcount
>= irelend
)
2297 ((*_bfd_error_handler
)
2298 (_("%s: 0x%lx: warning: could not find expected COUNT reloc"),
2299 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2303 /* The number of uses is stored in the r_addend field. We've
2304 just deleted one. */
2305 if (irelcount
->r_addend
== 0)
2307 ((*_bfd_error_handler
) (_("%s: 0x%lx: warning: bad count"),
2308 bfd_archive_filename (abfd
),
2309 (unsigned long) paddr
));
2313 --irelcount
->r_addend
;
2315 /* If there are no more uses, we can delete the address. Reload
2316 the address from irelfn, in case it was changed by the
2317 previous call to sh_elf_relax_delete_bytes. */
2318 if (irelcount
->r_addend
== 0)
2320 if (! sh_elf_relax_delete_bytes (abfd
, sec
, irelfn
->r_offset
, 4))
2324 /* We've done all we can with that function call. */
2327 /* Look for load and store instructions that we can align on four
2329 if ((elf_elfheader (abfd
)->e_flags
& EF_SH_MACH_MASK
) != EF_SH4
2332 bfd_boolean swapped
;
2334 /* Get the section contents. */
2335 if (contents
== NULL
)
2337 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2338 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2341 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
2342 if (contents
== NULL
)
2345 if (! bfd_get_section_contents (abfd
, sec
, contents
,
2346 (file_ptr
) 0, sec
->_raw_size
))
2351 if (! sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
,
2357 elf_section_data (sec
)->relocs
= internal_relocs
;
2358 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2359 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2364 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2366 if (! link_info
->keep_memory
)
2370 /* Cache the symbols for elf_link_input_bfd. */
2371 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2375 if (contents
!= NULL
2376 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2378 if (! link_info
->keep_memory
)
2382 /* Cache the section contents for elf_link_input_bfd. */
2383 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2387 if (internal_relocs
!= NULL
2388 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2389 free (internal_relocs
);
2395 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2397 if (contents
!= NULL
2398 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2400 if (internal_relocs
!= NULL
2401 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2402 free (internal_relocs
);
2407 /* Delete some bytes from a section while relaxing. FIXME: There is a
2408 lot of duplication between this function and sh_relax_delete_bytes
2412 sh_elf_relax_delete_bytes (abfd
, sec
, addr
, count
)
2418 Elf_Internal_Shdr
*symtab_hdr
;
2419 unsigned int sec_shndx
;
2421 Elf_Internal_Rela
*irel
, *irelend
;
2422 Elf_Internal_Rela
*irelalign
;
2424 Elf_Internal_Sym
*isymbuf
, *isym
, *isymend
;
2425 struct elf_link_hash_entry
**sym_hashes
;
2426 struct elf_link_hash_entry
**end_hashes
;
2427 unsigned int symcount
;
2430 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2431 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2433 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
2435 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2437 /* The deletion must stop at the next ALIGN reloc for an aligment
2438 power larger than the number of bytes we are deleting. */
2441 toaddr
= sec
->_cooked_size
;
2443 irel
= elf_section_data (sec
)->relocs
;
2444 irelend
= irel
+ sec
->reloc_count
;
2445 for (; irel
< irelend
; irel
++)
2447 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
2448 && irel
->r_offset
> addr
2449 && count
< (1 << irel
->r_addend
))
2452 toaddr
= irel
->r_offset
;
2457 /* Actually delete the bytes. */
2458 memmove (contents
+ addr
, contents
+ addr
+ count
,
2459 (size_t) (toaddr
- addr
- count
));
2460 if (irelalign
== NULL
)
2461 sec
->_cooked_size
-= count
;
2466 #define NOP_OPCODE (0x0009)
2468 BFD_ASSERT ((count
& 1) == 0);
2469 for (i
= 0; i
< count
; i
+= 2)
2470 bfd_put_16 (abfd
, (bfd_vma
) NOP_OPCODE
, contents
+ toaddr
- count
+ i
);
2473 /* Adjust all the relocs. */
2474 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
2476 bfd_vma nraddr
, stop
;
2479 int off
, adjust
, oinsn
;
2480 bfd_signed_vma voff
= 0;
2481 bfd_boolean overflow
;
2483 /* Get the new reloc address. */
2484 nraddr
= irel
->r_offset
;
2485 if ((irel
->r_offset
> addr
2486 && irel
->r_offset
< toaddr
)
2487 || (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
2488 && irel
->r_offset
== toaddr
))
2491 /* See if this reloc was for the bytes we have deleted, in which
2492 case we no longer care about it. Don't delete relocs which
2493 represent addresses, though. */
2494 if (irel
->r_offset
>= addr
2495 && irel
->r_offset
< addr
+ count
2496 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_ALIGN
2497 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
2498 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_DATA
2499 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_LABEL
)
2500 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
2503 /* If this is a PC relative reloc, see if the range it covers
2504 includes the bytes we have deleted. */
2505 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2514 start
= irel
->r_offset
;
2515 insn
= bfd_get_16 (abfd
, contents
+ nraddr
);
2519 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2522 start
= stop
= addr
;
2526 /* If this reloc is against a symbol defined in this
2527 section, and the symbol will not be adjusted below, we
2528 must check the addend to see it will put the value in
2529 range to be adjusted, and hence must be changed. */
2530 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
2532 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
2533 if (isym
->st_shndx
== sec_shndx
2534 && (isym
->st_value
<= addr
2535 || isym
->st_value
>= toaddr
))
2539 val
= bfd_get_32 (abfd
, contents
+ nraddr
);
2540 val
+= isym
->st_value
;
2541 if (val
> addr
&& val
< toaddr
)
2542 bfd_put_32 (abfd
, val
- count
, contents
+ nraddr
);
2545 start
= stop
= addr
;
2552 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
2559 /* This has been made by previous relaxation. Since the
2560 relocation will be against an external symbol, the
2561 final relocation will just do the right thing. */
2562 start
= stop
= addr
;
2568 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
2570 /* The addend will be against the section symbol, thus
2571 for adjusting the addend, the relevant start is the
2572 start of the section.
2573 N.B. If we want to abandom in-place changes here and
2574 test directly using symbol + addend, we have to take into
2575 account that the addend has already been adjusted by -4. */
2576 if (stop
> addr
&& stop
< toaddr
)
2577 irel
->r_addend
-= count
;
2583 stop
= start
+ 4 + off
* 2;
2588 stop
= (start
& ~(bfd_vma
) 3) + 4 + off
* 4;
2594 /* These relocs types represent
2596 The r_addend field holds the difference between the reloc
2597 address and L1. That is the start of the reloc, and
2598 adding in the contents gives us the top. We must adjust
2599 both the r_offset field and the section contents.
2600 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
2601 and the elf bfd r_offset is called r_vaddr. */
2603 stop
= irel
->r_offset
;
2604 start
= (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irel
->r_addend
);
2608 && (stop
<= addr
|| stop
>= toaddr
))
2609 irel
->r_addend
+= count
;
2610 else if (stop
> addr
2612 && (start
<= addr
|| start
>= toaddr
))
2613 irel
->r_addend
-= count
;
2615 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH16
)
2616 voff
= bfd_get_signed_16 (abfd
, contents
+ nraddr
);
2617 else if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH8
)
2618 voff
= bfd_get_8 (abfd
, contents
+ nraddr
);
2620 voff
= bfd_get_signed_32 (abfd
, contents
+ nraddr
);
2621 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
2626 start
= irel
->r_offset
;
2627 stop
= (bfd_vma
) ((bfd_signed_vma
) start
2628 + (long) irel
->r_addend
2635 && (stop
<= addr
|| stop
>= toaddr
))
2637 else if (stop
> addr
2639 && (start
<= addr
|| start
>= toaddr
))
2648 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2657 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2659 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2664 if ((oinsn
& 0xf000) != (insn
& 0xf000))
2666 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2670 BFD_ASSERT (adjust
== count
|| count
>= 4);
2675 if ((irel
->r_offset
& 3) == 0)
2678 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2680 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2685 if (voff
< 0 || voff
>= 0xff)
2687 bfd_put_8 (abfd
, voff
, contents
+ nraddr
);
2692 if (voff
< - 0x8000 || voff
>= 0x8000)
2694 bfd_put_signed_16 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
2699 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
2703 irel
->r_addend
+= adjust
;
2709 ((*_bfd_error_handler
)
2710 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
2711 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
2712 bfd_set_error (bfd_error_bad_value
);
2717 irel
->r_offset
= nraddr
;
2720 /* Look through all the other sections. If there contain any IMM32
2721 relocs against internal symbols which we are not going to adjust
2722 below, we may need to adjust the addends. */
2723 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2725 Elf_Internal_Rela
*internal_relocs
;
2726 Elf_Internal_Rela
*irelscan
, *irelscanend
;
2727 bfd_byte
*ocontents
;
2730 || (o
->flags
& SEC_RELOC
) == 0
2731 || o
->reloc_count
== 0)
2734 /* We always cache the relocs. Perhaps, if info->keep_memory is
2735 FALSE, we should free them, if we are permitted to, when we
2736 leave sh_coff_relax_section. */
2737 internal_relocs
= (_bfd_elf32_link_read_relocs
2738 (abfd
, o
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
2740 if (internal_relocs
== NULL
)
2744 irelscanend
= internal_relocs
+ o
->reloc_count
;
2745 for (irelscan
= internal_relocs
; irelscan
< irelscanend
; irelscan
++)
2747 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
2748 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_SWITCH32
)
2750 bfd_vma start
, stop
;
2751 bfd_signed_vma voff
;
2753 if (ocontents
== NULL
)
2755 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
2756 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
2759 /* We always cache the section contents.
2760 Perhaps, if info->keep_memory is FALSE, we
2761 should free them, if we are permitted to,
2762 when we leave sh_coff_relax_section. */
2763 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
2764 if (ocontents
== NULL
)
2766 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
2770 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
2774 stop
= irelscan
->r_offset
;
2776 = (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irelscan
->r_addend
);
2778 /* STOP is in a different section, so it won't change. */
2779 if (start
> addr
&& start
< toaddr
)
2780 irelscan
->r_addend
+= count
;
2782 voff
= bfd_get_signed_32 (abfd
, ocontents
+ irelscan
->r_offset
);
2783 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
2787 && (stop
<= addr
|| stop
>= toaddr
))
2788 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
+ count
,
2789 ocontents
+ irelscan
->r_offset
);
2790 else if (stop
> addr
2792 && (start
<= addr
|| start
>= toaddr
))
2793 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
- count
,
2794 ocontents
+ irelscan
->r_offset
);
2797 if (ELF32_R_TYPE (irelscan
->r_info
) != (int) R_SH_DIR32
)
2800 if (ELF32_R_SYM (irelscan
->r_info
) >= symtab_hdr
->sh_info
)
2804 isym
= isymbuf
+ ELF32_R_SYM (irelscan
->r_info
);
2805 if (isym
->st_shndx
== sec_shndx
2806 && (isym
->st_value
<= addr
2807 || isym
->st_value
>= toaddr
))
2811 if (ocontents
== NULL
)
2813 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
2814 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
2817 /* We always cache the section contents.
2818 Perhaps, if info->keep_memory is FALSE, we
2819 should free them, if we are permitted to,
2820 when we leave sh_coff_relax_section. */
2821 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
2822 if (ocontents
== NULL
)
2824 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
2828 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
2832 val
= bfd_get_32 (abfd
, ocontents
+ irelscan
->r_offset
);
2833 val
+= isym
->st_value
;
2834 if (val
> addr
&& val
< toaddr
)
2835 bfd_put_32 (abfd
, val
- count
,
2836 ocontents
+ irelscan
->r_offset
);
2841 /* Adjust the local symbols defined in this section. */
2842 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
2843 for (isym
= isymbuf
; isym
< isymend
; isym
++)
2845 if (isym
->st_shndx
== sec_shndx
2846 && isym
->st_value
> addr
2847 && isym
->st_value
< toaddr
)
2848 isym
->st_value
-= count
;
2851 /* Now adjust the global symbols defined in this section. */
2852 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2853 - symtab_hdr
->sh_info
);
2854 sym_hashes
= elf_sym_hashes (abfd
);
2855 end_hashes
= sym_hashes
+ symcount
;
2856 for (; sym_hashes
< end_hashes
; sym_hashes
++)
2858 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
2859 if ((sym_hash
->root
.type
== bfd_link_hash_defined
2860 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
2861 && sym_hash
->root
.u
.def
.section
== sec
2862 && sym_hash
->root
.u
.def
.value
> addr
2863 && sym_hash
->root
.u
.def
.value
< toaddr
)
2865 sym_hash
->root
.u
.def
.value
-= count
;
2869 /* See if we can move the ALIGN reloc forward. We have adjusted
2870 r_offset for it already. */
2871 if (irelalign
!= NULL
)
2873 bfd_vma alignto
, alignaddr
;
2875 alignto
= BFD_ALIGN (toaddr
, 1 << irelalign
->r_addend
);
2876 alignaddr
= BFD_ALIGN (irelalign
->r_offset
,
2877 1 << irelalign
->r_addend
);
2878 if (alignto
!= alignaddr
)
2880 /* Tail recursion. */
2881 return sh_elf_relax_delete_bytes (abfd
, sec
, alignaddr
,
2882 (int) (alignto
- alignaddr
));
2889 /* Look for loads and stores which we can align to four byte
2890 boundaries. This is like sh_align_loads in coff-sh.c. */
2893 sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
, pswapped
)
2894 bfd
*abfd ATTRIBUTE_UNUSED
;
2896 Elf_Internal_Rela
*internal_relocs
;
2897 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2898 bfd_boolean
*pswapped
;
2900 Elf_Internal_Rela
*irel
, *irelend
;
2901 bfd_vma
*labels
= NULL
;
2902 bfd_vma
*label
, *label_end
;
2907 irelend
= internal_relocs
+ sec
->reloc_count
;
2909 /* Get all the addresses with labels on them. */
2910 amt
= sec
->reloc_count
;
2911 amt
*= sizeof (bfd_vma
);
2912 labels
= (bfd_vma
*) bfd_malloc (amt
);
2916 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2918 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_LABEL
)
2920 *label_end
= irel
->r_offset
;
2925 /* Note that the assembler currently always outputs relocs in
2926 address order. If that ever changes, this code will need to sort
2927 the label values and the relocs. */
2931 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2933 bfd_vma start
, stop
;
2935 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
)
2938 start
= irel
->r_offset
;
2940 for (irel
++; irel
< irelend
; irel
++)
2941 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_DATA
)
2944 stop
= irel
->r_offset
;
2946 stop
= sec
->_cooked_size
;
2948 if (! _bfd_sh_align_load_span (abfd
, sec
, contents
, sh_elf_swap_insns
,
2949 (PTR
) internal_relocs
, &label
,
2950 label_end
, start
, stop
, pswapped
))
2964 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
2967 sh_elf_swap_insns (abfd
, sec
, relocs
, contents
, addr
)
2974 Elf_Internal_Rela
*internal_relocs
= (Elf_Internal_Rela
*) relocs
;
2975 unsigned short i1
, i2
;
2976 Elf_Internal_Rela
*irel
, *irelend
;
2978 /* Swap the instructions themselves. */
2979 i1
= bfd_get_16 (abfd
, contents
+ addr
);
2980 i2
= bfd_get_16 (abfd
, contents
+ addr
+ 2);
2981 bfd_put_16 (abfd
, (bfd_vma
) i2
, contents
+ addr
);
2982 bfd_put_16 (abfd
, (bfd_vma
) i1
, contents
+ addr
+ 2);
2984 /* Adjust all reloc addresses. */
2985 irelend
= internal_relocs
+ sec
->reloc_count
;
2986 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2988 enum elf_sh_reloc_type type
;
2991 /* There are a few special types of relocs that we don't want to
2992 adjust. These relocs do not apply to the instruction itself,
2993 but are only associated with the address. */
2994 type
= (enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
);
2995 if (type
== R_SH_ALIGN
2996 || type
== R_SH_CODE
2997 || type
== R_SH_DATA
2998 || type
== R_SH_LABEL
)
3001 /* If an R_SH_USES reloc points to one of the addresses being
3002 swapped, we must adjust it. It would be incorrect to do this
3003 for a jump, though, since we want to execute both
3004 instructions after the jump. (We have avoided swapping
3005 around a label, so the jump will not wind up executing an
3006 instruction it shouldn't). */
3007 if (type
== R_SH_USES
)
3011 off
= irel
->r_offset
+ 4 + irel
->r_addend
;
3013 irel
->r_offset
+= 2;
3014 else if (off
== addr
+ 2)
3015 irel
->r_offset
-= 2;
3018 if (irel
->r_offset
== addr
)
3020 irel
->r_offset
+= 2;
3023 else if (irel
->r_offset
== addr
+ 2)
3025 irel
->r_offset
-= 2;
3034 unsigned short insn
, oinsn
;
3035 bfd_boolean overflow
;
3037 loc
= contents
+ irel
->r_offset
;
3046 insn
= bfd_get_16 (abfd
, loc
);
3049 if ((oinsn
& 0xff00) != (insn
& 0xff00))
3051 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3055 insn
= bfd_get_16 (abfd
, loc
);
3058 if ((oinsn
& 0xf000) != (insn
& 0xf000))
3060 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3064 /* This reloc ignores the least significant 3 bits of
3065 the program counter before adding in the offset.
3066 This means that if ADDR is at an even address, the
3067 swap will not affect the offset. If ADDR is an at an
3068 odd address, then the instruction will be crossing a
3069 four byte boundary, and must be adjusted. */
3070 if ((addr
& 3) != 0)
3072 insn
= bfd_get_16 (abfd
, loc
);
3075 if ((oinsn
& 0xff00) != (insn
& 0xff00))
3077 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3085 ((*_bfd_error_handler
)
3086 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
3087 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
3088 bfd_set_error (bfd_error_bad_value
);
3097 #ifdef INCLUDE_SHMEDIA
3099 /* The size in bytes of an entry in the procedure linkage table. */
3101 #define PLT_ENTRY_SIZE 64
3103 /* First entry in an absolute procedure linkage table look like this. */
3105 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3107 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
3108 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
3109 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3110 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3111 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3112 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3113 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3114 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3115 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3116 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3117 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3118 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3119 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3120 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3121 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3122 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3125 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3127 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
3128 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
3129 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3130 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3131 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3132 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3133 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3134 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3135 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3136 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3137 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3138 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3139 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3140 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3141 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3142 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3145 /* Sebsequent entries in an absolute procedure linkage table look like
3148 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3150 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
3151 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
3152 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
3153 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3154 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3155 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3156 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3157 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3158 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
3159 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
3160 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3161 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3162 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3163 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3164 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3165 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3168 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3170 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3171 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3172 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
3173 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3174 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3175 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3176 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3177 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3178 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
3179 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
3180 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3181 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3182 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3183 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3184 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3185 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3188 /* Entries in a PIC procedure linkage table look like this. */
3190 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3192 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3193 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3194 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
3195 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3196 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3197 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3198 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3199 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3200 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3201 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
3202 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3203 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3204 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3205 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3206 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3207 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3210 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3212 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3213 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3214 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
3215 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3216 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3217 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3218 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3219 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3220 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3221 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
3222 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3223 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3224 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3225 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3226 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3227 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3230 static const bfd_byte
*elf_sh_plt0_entry
;
3231 static const bfd_byte
*elf_sh_plt_entry
;
3232 static const bfd_byte
*elf_sh_pic_plt_entry
;
3234 /* Return size of a PLT entry. */
3235 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3237 /* Return offset of the PLT0 address in an absolute PLT entry. */
3238 #define elf_sh_plt_plt0_offset(info) 32
3240 /* Return offset of the linker in PLT0 entry. */
3241 #define elf_sh_plt0_gotplt_offset(info) 0
3243 /* Return offset of the trampoline in PLT entry */
3244 #define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
3246 /* Return offset of the symbol in PLT entry. */
3247 #define elf_sh_plt_symbol_offset(info) 0
3249 /* Return offset of the relocation in PLT entry. */
3250 #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
3253 movi_shori_putval (output_bfd
, value
, addr
)
3255 unsigned long value
;
3258 bfd_put_32 (output_bfd
,
3259 bfd_get_32 (output_bfd
, addr
)
3260 | ((value
>> 6) & 0x3fffc00),
3262 bfd_put_32 (output_bfd
,
3263 bfd_get_32 (output_bfd
, addr
+ 4)
3264 | ((value
<< 10) & 0x3fffc00),
3269 /* The size in bytes of an entry in the procedure linkage table. */
3271 #define PLT_ENTRY_SIZE 28
3273 /* First entry in an absolute procedure linkage table look like this. */
3276 /* Note - this code has been "optimised" not to use r2. r2 is used by
3277 GCC to return the address of large strutcures, so it should not be
3278 corrupted here. This does mean however, that this PLT does not conform
3279 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
3280 and r2 contains the GOT id. This version stores the GOT id in r0 and
3281 ignores the type. Loaders can easily detect this difference however,
3282 since the type will always be 0 or 8, and the GOT ids will always be
3283 greater than or equal to 12. */
3284 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3286 0xd0, 0x05, /* mov.l 2f,r0 */
3287 0x60, 0x02, /* mov.l @r0,r0 */
3288 0x2f, 0x06, /* mov.l r0,@-r15 */
3289 0xd0, 0x03, /* mov.l 1f,r0 */
3290 0x60, 0x02, /* mov.l @r0,r0 */
3291 0x40, 0x2b, /* jmp @r0 */
3292 0x60, 0xf6, /* mov.l @r15+,r0 */
3293 0x00, 0x09, /* nop */
3294 0x00, 0x09, /* nop */
3295 0x00, 0x09, /* nop */
3296 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3297 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3300 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3302 0x05, 0xd0, /* mov.l 2f,r0 */
3303 0x02, 0x60, /* mov.l @r0,r0 */
3304 0x06, 0x2f, /* mov.l r0,@-r15 */
3305 0x03, 0xd0, /* mov.l 1f,r0 */
3306 0x02, 0x60, /* mov.l @r0,r0 */
3307 0x2b, 0x40, /* jmp @r0 */
3308 0xf6, 0x60, /* mov.l @r15+,r0 */
3309 0x09, 0x00, /* nop */
3310 0x09, 0x00, /* nop */
3311 0x09, 0x00, /* nop */
3312 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3313 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3316 /* Sebsequent entries in an absolute procedure linkage table look like
3319 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3321 0xd0, 0x04, /* mov.l 1f,r0 */
3322 0x60, 0x02, /* mov.l @r0,r0 */
3323 0xd1, 0x02, /* mov.l 0f,r1 */
3324 0x40, 0x2b, /* jmp @r0 */
3325 0x60, 0x13, /* mov r1,r0 */
3326 0xd1, 0x03, /* mov.l 2f,r1 */
3327 0x40, 0x2b, /* jmp @r0 */
3328 0x00, 0x09, /* nop */
3329 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3330 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3331 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3334 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3336 0x04, 0xd0, /* mov.l 1f,r0 */
3337 0x02, 0x60, /* mov.l @r0,r0 */
3338 0x02, 0xd1, /* mov.l 0f,r1 */
3339 0x2b, 0x40, /* jmp @r0 */
3340 0x13, 0x60, /* mov r1,r0 */
3341 0x03, 0xd1, /* mov.l 2f,r1 */
3342 0x2b, 0x40, /* jmp @r0 */
3343 0x09, 0x00, /* nop */
3344 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3345 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3346 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3349 /* Entries in a PIC procedure linkage table look like this. */
3351 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3353 0xd0, 0x04, /* mov.l 1f,r0 */
3354 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3355 0x40, 0x2b, /* jmp @r0 */
3356 0x00, 0x09, /* nop */
3357 0x50, 0xc2, /* mov.l @(8,r12),r0 */
3358 0xd1, 0x03, /* mov.l 2f,r1 */
3359 0x40, 0x2b, /* jmp @r0 */
3360 0x50, 0xc1, /* mov.l @(4,r12),r0 */
3361 0x00, 0x09, /* nop */
3362 0x00, 0x09, /* nop */
3363 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3364 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3367 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3369 0x04, 0xd0, /* mov.l 1f,r0 */
3370 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3371 0x2b, 0x40, /* jmp @r0 */
3372 0x09, 0x00, /* nop */
3373 0xc2, 0x50, /* mov.l @(8,r12),r0 */
3374 0x03, 0xd1, /* mov.l 2f,r1 */
3375 0x2b, 0x40, /* jmp @r0 */
3376 0xc1, 0x50, /* mov.l @(4,r12),r0 */
3377 0x09, 0x00, /* nop */
3378 0x09, 0x00, /* nop */
3379 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3380 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3383 #else /* These are the old style PLT entries. */
3384 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3386 0xd0, 0x04, /* mov.l 1f,r0 */
3387 0xd2, 0x05, /* mov.l 2f,r2 */
3388 0x60, 0x02, /* mov.l @r0,r0 */
3389 0x62, 0x22, /* mov.l @r2,r2 */
3390 0x40, 0x2b, /* jmp @r0 */
3391 0xe0, 0x00, /* mov #0,r0 */
3392 0x00, 0x09, /* nop */
3393 0x00, 0x09, /* nop */
3394 0x00, 0x09, /* nop */
3395 0x00, 0x09, /* nop */
3396 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3397 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3400 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3402 0x04, 0xd0, /* mov.l 1f,r0 */
3403 0x05, 0xd2, /* mov.l 2f,r2 */
3404 0x02, 0x60, /* mov.l @r0,r0 */
3405 0x22, 0x62, /* mov.l @r2,r2 */
3406 0x2b, 0x40, /* jmp @r0 */
3407 0x00, 0xe0, /* mov #0,r0 */
3408 0x09, 0x00, /* nop */
3409 0x09, 0x00, /* nop */
3410 0x09, 0x00, /* nop */
3411 0x09, 0x00, /* nop */
3412 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3413 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3416 /* Sebsequent entries in an absolute procedure linkage table look like
3419 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3421 0xd0, 0x04, /* mov.l 1f,r0 */
3422 0x60, 0x02, /* mov.l @r0,r0 */
3423 0xd2, 0x02, /* mov.l 0f,r2 */
3424 0x40, 0x2b, /* jmp @r0 */
3425 0x60, 0x23, /* mov r2,r0 */
3426 0xd1, 0x03, /* mov.l 2f,r1 */
3427 0x40, 0x2b, /* jmp @r0 */
3428 0x00, 0x09, /* nop */
3429 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3430 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3431 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3434 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3436 0x04, 0xd0, /* mov.l 1f,r0 */
3437 0x02, 0x60, /* mov.l @r0,r0 */
3438 0x02, 0xd2, /* mov.l 0f,r2 */
3439 0x2b, 0x40, /* jmp @r0 */
3440 0x23, 0x60, /* mov r2,r0 */
3441 0x03, 0xd1, /* mov.l 2f,r1 */
3442 0x2b, 0x40, /* jmp @r0 */
3443 0x09, 0x00, /* nop */
3444 0, 0, 0, 0, /* 0: replaced with address of .PLT. */
3445 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3446 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3449 /* Entries in a PIC procedure linkage table look like this. */
3451 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3453 0xd0, 0x04, /* mov.l 1f,r0 */
3454 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3455 0x40, 0x2b, /* jmp @r0 */
3456 0x00, 0x09, /* nop */
3457 0x50, 0xc2, /* 0: mov.l @(8,r12),r0 */
3458 0x52, 0xc1, /* 1: mov.l @(4,r12),r2 */
3459 0xd1, 0x02, /* mov.l 2f,r1 */
3460 0x40, 0x2b, /* jmp @r0 */
3461 0xe0, 0x00, /* mov #0,r0 ! shows the type of PLT. */
3462 0x00, 0x09, /* nop */
3463 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3464 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3467 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3469 0x04, 0xd0, /* mov.l 1f,r0 */
3470 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3471 0x2b, 0x40, /* jmp @r0 */
3472 0x09, 0x00, /* nop */
3473 0xc2, 0x50, /* 0: mov.l @(8,r12),r0 */
3474 0xc1, 0x52, /* 1: mov.l @(4,r12),r2 */
3475 0x02, 0xd1, /* mov.l 2f,r1 */
3476 0x2b, 0x40, /* jmp @r0 */
3477 0x00, 0xe0, /* mov #0,r0 ! shows the type of PLT. */
3478 0x09, 0x00, /* nop */
3479 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3480 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3482 #endif /* old style PLT entries. */
3484 static const bfd_byte
*elf_sh_plt0_entry
;
3485 static const bfd_byte
*elf_sh_plt_entry
;
3486 static const bfd_byte
*elf_sh_pic_plt_entry
;
3488 /* Return size of a PLT entry. */
3489 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3491 /* Return offset of the PLT0 address in an absolute PLT entry. */
3492 #define elf_sh_plt_plt0_offset(info) 16
3494 /* Return offset of the linker in PLT0 entry. */
3495 #define elf_sh_plt0_linker_offset(info) 20
3497 /* Return offset of the GOT id in PLT0 entry. */
3498 #define elf_sh_plt0_gotid_offset(info) 24
3500 /* Return offset of the tempoline in PLT entry */
3501 #define elf_sh_plt_temp_offset(info) 8
3503 /* Return offset of the symbol in PLT entry. */
3504 #define elf_sh_plt_symbol_offset(info) 20
3506 /* Return offset of the relocation in PLT entry. */
3507 #define elf_sh_plt_reloc_offset(info) 24
3510 /* The sh linker needs to keep track of the number of relocs that it
3511 decides to copy as dynamic relocs in check_relocs for each symbol.
3512 This is so that it can later discard them if they are found to be
3513 unnecessary. We store the information in a field extending the
3514 regular ELF linker hash table. */
3516 struct elf_sh_dyn_relocs
3518 struct elf_sh_dyn_relocs
*next
;
3520 /* The input section of the reloc. */
3523 /* Total number of relocs copied for the input section. */
3524 bfd_size_type count
;
3526 /* Number of pc-relative relocs copied for the input section. */
3527 bfd_size_type pc_count
;
3529 /* If TRUE, R_SH_TLS_TPOFF32 relocation is generated. */
3530 bfd_boolean tls_tpoff32
;
3533 /* sh ELF linker hash entry. */
3535 struct elf_sh_link_hash_entry
3537 struct elf_link_hash_entry root
;
3539 #ifdef INCLUDE_SHMEDIA
3542 bfd_signed_vma refcount
;
3547 /* Track dynamic relocs copied for this symbol. */
3548 struct elf_sh_dyn_relocs
*dyn_relocs
;
3550 bfd_signed_vma gotplt_refcount
;
3553 GOT_UNKNOWN
= 0, GOT_NORMAL
, GOT_TLS_GD
, GOT_TLS_IE
3557 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
3559 struct sh_elf_obj_tdata
3561 struct elf_obj_tdata root
;
3563 /* tls_type for each local got entry. */
3564 char *local_got_tls_type
;
3567 #define sh_elf_tdata(abfd) \
3568 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
3570 #define sh_elf_local_got_tls_type(abfd) \
3571 (sh_elf_tdata (abfd)->local_got_tls_type)
3573 /* Override the generic function because we need to store sh_elf_obj_tdata
3574 as the specific tdata. */
3577 sh_elf_mkobject (abfd
)
3580 bfd_size_type amt
= sizeof (struct sh_elf_obj_tdata
);
3581 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
3582 if (abfd
->tdata
.any
== NULL
)
3587 /* sh ELF linker hash table. */
3589 struct elf_sh_link_hash_table
3591 struct elf_link_hash_table root
;
3593 /* Short-cuts to get to dynamic linker sections. */
3602 /* Small local sym to section mapping cache. */
3603 struct sym_sec_cache sym_sec
;
3605 /* A counter or offset to track a TLS got entry. */
3608 bfd_signed_vma refcount
;
3613 /* Traverse an sh ELF linker hash table. */
3615 #define sh_elf_link_hash_traverse(table, func, info) \
3616 (elf_link_hash_traverse \
3618 (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3621 /* Get the sh ELF linker hash table from a link_info structure. */
3623 #define sh_elf_hash_table(p) \
3624 ((struct elf_sh_link_hash_table *) ((p)->hash))
3626 /* Create an entry in an sh ELF linker hash table. */
3628 static struct bfd_hash_entry
*
3629 sh_elf_link_hash_newfunc (entry
, table
, string
)
3630 struct bfd_hash_entry
*entry
;
3631 struct bfd_hash_table
*table
;
3634 struct elf_sh_link_hash_entry
*ret
=
3635 (struct elf_sh_link_hash_entry
*) entry
;
3637 /* Allocate the structure if it has not already been allocated by a
3639 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3640 ret
= ((struct elf_sh_link_hash_entry
*)
3641 bfd_hash_allocate (table
,
3642 sizeof (struct elf_sh_link_hash_entry
)));
3643 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3644 return (struct bfd_hash_entry
*) ret
;
3646 /* Call the allocation method of the superclass. */
3647 ret
= ((struct elf_sh_link_hash_entry
*)
3648 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3650 if (ret
!= (struct elf_sh_link_hash_entry
*) NULL
)
3652 ret
->dyn_relocs
= NULL
;
3653 ret
->gotplt_refcount
= 0;
3654 #ifdef INCLUDE_SHMEDIA
3655 ret
->datalabel_got
.refcount
= ret
->root
.got
.refcount
;
3657 ret
->tls_type
= GOT_UNKNOWN
;
3660 return (struct bfd_hash_entry
*) ret
;
3663 /* Create an sh ELF linker hash table. */
3665 static struct bfd_link_hash_table
*
3666 sh_elf_link_hash_table_create (abfd
)
3669 struct elf_sh_link_hash_table
*ret
;
3670 bfd_size_type amt
= sizeof (struct elf_sh_link_hash_table
);
3672 ret
= (struct elf_sh_link_hash_table
*) bfd_malloc (amt
);
3673 if (ret
== (struct elf_sh_link_hash_table
*) NULL
)
3676 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3677 sh_elf_link_hash_newfunc
))
3684 ret
->sgotplt
= NULL
;
3685 ret
->srelgot
= NULL
;
3687 ret
->srelplt
= NULL
;
3688 ret
->sdynbss
= NULL
;
3689 ret
->srelbss
= NULL
;
3690 ret
->sym_sec
.abfd
= NULL
;
3691 ret
->tls_ldm_got
.refcount
= 0;
3693 return &ret
->root
.root
;
3696 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
3697 shortcuts to them in our hash table. */
3700 create_got_section (dynobj
, info
)
3702 struct bfd_link_info
*info
;
3704 struct elf_sh_link_hash_table
*htab
;
3706 if (! _bfd_elf_create_got_section (dynobj
, info
))
3709 htab
= sh_elf_hash_table (info
);
3710 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
3711 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
3712 if (! htab
->sgot
|| ! htab
->sgotplt
)
3715 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
3716 if (htab
->srelgot
== NULL
3717 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
3722 | SEC_LINKER_CREATED
3724 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
3729 /* Create dynamic sections when linking against a dynamic object. */
3732 sh_elf_create_dynamic_sections (abfd
, info
)
3734 struct bfd_link_info
*info
;
3736 struct elf_sh_link_hash_table
*htab
;
3737 flagword flags
, pltflags
;
3738 register asection
*s
;
3739 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3742 switch (bed
->s
->arch_size
)
3753 bfd_set_error (bfd_error_bad_value
);
3757 htab
= sh_elf_hash_table (info
);
3759 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3760 .rel[a].bss sections. */
3762 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3763 | SEC_LINKER_CREATED
);
3766 pltflags
|= SEC_CODE
;
3767 if (bed
->plt_not_loaded
)
3768 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
3769 if (bed
->plt_readonly
)
3770 pltflags
|= SEC_READONLY
;
3772 s
= bfd_make_section (abfd
, ".plt");
3775 || ! bfd_set_section_flags (abfd
, s
, pltflags
)
3776 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3779 if (bed
->want_plt_sym
)
3781 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3783 struct elf_link_hash_entry
*h
;
3784 struct bfd_link_hash_entry
*bh
= NULL
;
3786 if (! (_bfd_generic_link_add_one_symbol
3787 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3788 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
3789 get_elf_backend_data (abfd
)->collect
, &bh
)))
3792 h
= (struct elf_link_hash_entry
*) bh
;
3793 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3794 h
->type
= STT_OBJECT
;
3797 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
3801 s
= bfd_make_section (abfd
,
3802 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt");
3805 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3806 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3809 if (! create_got_section (abfd
, info
))
3813 const char *secname
;
3818 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3820 secflags
= bfd_get_section_flags (abfd
, sec
);
3821 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3822 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3824 secname
= bfd_get_section_name (abfd
, sec
);
3825 relname
= (char *) bfd_malloc ((bfd_size_type
) strlen (secname
) + 6);
3826 strcpy (relname
, ".rela");
3827 strcat (relname
, secname
);
3828 s
= bfd_make_section (abfd
, relname
);
3830 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3831 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3836 if (bed
->want_dynbss
)
3838 /* The .dynbss section is a place to put symbols which are defined
3839 by dynamic objects, are referenced by regular objects, and are
3840 not functions. We must allocate space for them in the process
3841 image and use a R_*_COPY reloc to tell the dynamic linker to
3842 initialize them at run time. The linker script puts the .dynbss
3843 section into the .bss section of the final image. */
3844 s
= bfd_make_section (abfd
, ".dynbss");
3847 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
3850 /* The .rel[a].bss section holds copy relocs. This section is not
3851 normally needed. We need to create it here, though, so that the
3852 linker will map it to an output section. We can't just create it
3853 only if we need it, because we will not know whether we need it
3854 until we have seen all the input files, and the first time the
3855 main linker code calls BFD after examining all the input files
3856 (size_dynamic_sections) the input sections have already been
3857 mapped to the output sections. If the section turns out not to
3858 be needed, we can discard it later. We will never need this
3859 section when generating a shared object, since they do not use
3863 s
= bfd_make_section (abfd
,
3864 (bed
->default_use_rela_p
3865 ? ".rela.bss" : ".rel.bss"));
3868 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3869 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3877 /* Adjust a symbol defined by a dynamic object and referenced by a
3878 regular object. The current definition is in some section of the
3879 dynamic object, but we're not including those sections. We have to
3880 change the definition to something the rest of the link can
3884 sh_elf_adjust_dynamic_symbol (info
, h
)
3885 struct bfd_link_info
*info
;
3886 struct elf_link_hash_entry
*h
;
3888 struct elf_sh_link_hash_table
*htab
;
3889 struct elf_sh_link_hash_entry
*eh
;
3890 struct elf_sh_dyn_relocs
*p
;
3893 unsigned int power_of_two
;
3895 dynobj
= elf_hash_table (info
)->dynobj
;
3897 /* Make sure we know what is going on here. */
3898 BFD_ASSERT (dynobj
!= NULL
3899 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
3900 || h
->weakdef
!= NULL
3901 || ((h
->elf_link_hash_flags
3902 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3903 && (h
->elf_link_hash_flags
3904 & ELF_LINK_HASH_REF_REGULAR
) != 0
3905 && (h
->elf_link_hash_flags
3906 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
3908 /* If this is a function, put it in the procedure linkage table. We
3909 will fill in the contents of the procedure linkage table later,
3910 when we know the address of the .got section. */
3911 if (h
->type
== STT_FUNC
3912 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3914 if (h
->plt
.refcount
<= 0
3916 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3917 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0
3918 && h
->root
.type
!= bfd_link_hash_undefweak
3919 && h
->root
.type
!= bfd_link_hash_undefined
))
3921 /* This case can occur if we saw a PLT reloc in an input
3922 file, but the symbol was never referred to by a dynamic
3923 object. In such a case, we don't actually need to build
3924 a procedure linkage table, and we can just do a REL32
3926 h
->plt
.offset
= (bfd_vma
) -1;
3927 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3933 h
->plt
.offset
= (bfd_vma
) -1;
3935 /* If this is a weak symbol, and there is a real definition, the
3936 processor independent code will have arranged for us to see the
3937 real definition first, and we can just use the same value. */
3938 if (h
->weakdef
!= NULL
)
3940 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3941 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3942 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3943 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3947 /* This is a reference to a symbol defined by a dynamic object which
3948 is not a function. */
3950 /* If we are creating a shared library, we must presume that the
3951 only references to the symbol are via the global offset table.
3952 For such cases we need not do anything here; the relocations will
3953 be handled correctly by relocate_section. */
3957 /* If there are no references to this symbol that do not use the
3958 GOT, we don't need to generate a copy reloc. */
3959 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
3962 /* If -z nocopyreloc was given, we won't generate them either. */
3963 if (info
->nocopyreloc
)
3965 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3969 eh
= (struct elf_sh_link_hash_entry
*) h
;
3970 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3972 s
= p
->sec
->output_section
;
3973 if (s
!= NULL
&& (s
->flags
& (SEC_READONLY
| SEC_HAS_CONTENTS
)) != 0)
3977 /* If we didn't find any dynamic relocs in sections which needs the
3978 copy reloc, then we'll be keeping the dynamic relocs and avoiding
3982 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3986 /* We must allocate the symbol in our .dynbss section, which will
3987 become part of the .bss section of the executable. There will be
3988 an entry for this symbol in the .dynsym section. The dynamic
3989 object will contain position independent code, so all references
3990 from the dynamic object to this symbol will go through the global
3991 offset table. The dynamic linker will use the .dynsym entry to
3992 determine the address it must put in the global offset table, so
3993 both the dynamic object and the regular object will refer to the
3994 same memory location for the variable. */
3996 htab
= sh_elf_hash_table (info
);
3998 BFD_ASSERT (s
!= NULL
);
4000 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
4001 copy the initial value out of the dynamic object and into the
4002 runtime process image. We need to remember the offset into the
4003 .rela.bss section we are going to use. */
4004 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
4008 srel
= htab
->srelbss
;
4009 BFD_ASSERT (srel
!= NULL
);
4010 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
4011 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
4014 /* We need to figure out the alignment required for this symbol. I
4015 have no idea how ELF linkers handle this. */
4016 power_of_two
= bfd_log2 (h
->size
);
4017 if (power_of_two
> 3)
4020 /* Apply the required alignment. */
4021 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
4022 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
4024 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
4028 /* Define the symbol as being at this point in the section. */
4029 h
->root
.u
.def
.section
= s
;
4030 h
->root
.u
.def
.value
= s
->_raw_size
;
4032 /* Increment the section size to make room for the symbol. */
4033 s
->_raw_size
+= h
->size
;
4038 /* This is the condition under which sh_elf_finish_dynamic_symbol
4039 will be called from elflink.h. If elflink.h doesn't call our
4040 finish_dynamic_symbol routine, we'll need to do something about
4041 initializing any .plt and .got entries in sh_elf_relocate_section. */
4042 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
4044 && ((INFO)->shared \
4045 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
4046 && ((H)->dynindx != -1 \
4047 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
4049 /* Allocate space in .plt, .got and associated reloc sections for
4053 allocate_dynrelocs (h
, inf
)
4054 struct elf_link_hash_entry
*h
;
4057 struct bfd_link_info
*info
;
4058 struct elf_sh_link_hash_table
*htab
;
4059 struct elf_sh_link_hash_entry
*eh
;
4060 struct elf_sh_dyn_relocs
*p
;
4062 if (h
->root
.type
== bfd_link_hash_indirect
)
4065 if (h
->root
.type
== bfd_link_hash_warning
)
4066 /* When warning symbols are created, they **replace** the "real"
4067 entry in the hash table, thus we never get to see the real
4068 symbol in a hash traversal. So look at it now. */
4069 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4071 info
= (struct bfd_link_info
*) inf
;
4072 htab
= sh_elf_hash_table (info
);
4074 eh
= (struct elf_sh_link_hash_entry
*) h
;
4075 if ((h
->got
.refcount
> 0
4076 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
4077 && eh
->gotplt_refcount
> 0)
4079 /* The symbol has been forced local, or we have some direct got refs,
4080 so treat all the gotplt refs as got refs. */
4081 h
->got
.refcount
+= eh
->gotplt_refcount
;
4082 if (h
->plt
.refcount
>= eh
->gotplt_refcount
)
4083 h
->plt
.refcount
-= eh
->gotplt_refcount
;
4086 if (htab
->root
.dynamic_sections_created
4087 && h
->plt
.refcount
> 0)
4089 /* Make sure this symbol is output as a dynamic symbol.
4090 Undefined weak syms won't yet be marked as dynamic. */
4091 if (h
->dynindx
== -1
4092 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4094 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4098 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
4100 asection
*s
= htab
->splt
;
4102 /* If this is the first .plt entry, make room for the special
4104 if (s
->_raw_size
== 0)
4105 s
->_raw_size
+= PLT_ENTRY_SIZE
;
4107 h
->plt
.offset
= s
->_raw_size
;
4109 /* If this symbol is not defined in a regular file, and we are
4110 not generating a shared library, then set the symbol to this
4111 location in the .plt. This is required to make function
4112 pointers compare as equal between the normal executable and
4113 the shared library. */
4115 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4117 h
->root
.u
.def
.section
= s
;
4118 h
->root
.u
.def
.value
= h
->plt
.offset
;
4121 /* Make room for this entry. */
4122 s
->_raw_size
+= PLT_ENTRY_SIZE
;
4124 /* We also need to make an entry in the .got.plt section, which
4125 will be placed in the .got section by the linker script. */
4126 htab
->sgotplt
->_raw_size
+= 4;
4128 /* We also need to make an entry in the .rel.plt section. */
4129 htab
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
4133 h
->plt
.offset
= (bfd_vma
) -1;
4134 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4139 h
->plt
.offset
= (bfd_vma
) -1;
4140 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4143 if (h
->got
.refcount
> 0)
4147 int tls_type
= sh_elf_hash_entry (h
)->tls_type
;
4149 /* Make sure this symbol is output as a dynamic symbol.
4150 Undefined weak syms won't yet be marked as dynamic. */
4151 if (h
->dynindx
== -1
4152 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4154 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4159 h
->got
.offset
= s
->_raw_size
;
4161 /* R_SH_TLS_GD needs 2 consecutive GOT slots. */
4162 if (tls_type
== GOT_TLS_GD
)
4164 dyn
= htab
->root
.dynamic_sections_created
;
4165 /* R_SH_TLS_IE_32 needs one dynamic relocation,
4166 R_SH_TLS_GD needs one if local symbol and two if global. */
4167 if ((tls_type
== GOT_TLS_GD
&& h
->dynindx
== -1)
4168 || tls_type
== GOT_TLS_IE
)
4169 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4170 else if (tls_type
== GOT_TLS_GD
)
4171 htab
->srelgot
->_raw_size
+= 2 * sizeof (Elf32_External_Rela
);
4172 else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
4173 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4176 h
->got
.offset
= (bfd_vma
) -1;
4178 #ifdef INCLUDE_SHMEDIA
4179 if (eh
->datalabel_got
.refcount
> 0)
4184 /* Make sure this symbol is output as a dynamic symbol.
4185 Undefined weak syms won't yet be marked as dynamic. */
4186 if (h
->dynindx
== -1
4187 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4189 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4194 eh
->datalabel_got
.offset
= s
->_raw_size
;
4196 dyn
= htab
->root
.dynamic_sections_created
;
4197 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
4198 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4201 eh
->datalabel_got
.offset
= (bfd_vma
) -1;
4204 if (eh
->dyn_relocs
== NULL
)
4207 /* In the shared -Bsymbolic case, discard space allocated for
4208 dynamic pc-relative relocs against symbols which turn out to be
4209 defined in regular objects. For the normal shared case, discard
4210 space for pc-relative relocs that have become local due to symbol
4211 visibility changes. */
4215 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
4216 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
4219 struct elf_sh_dyn_relocs
**pp
;
4221 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
4223 p
->count
-= p
->pc_count
;
4234 for (p
= eh
->dyn_relocs
; p
; p
= p
->next
)
4238 /* For the non-shared case, discard space for relocs against
4239 symbols which turn out to need copy relocs or are not
4242 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
4243 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4244 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4245 || (htab
->root
.dynamic_sections_created
4246 && (h
->root
.type
== bfd_link_hash_undefweak
4247 || h
->root
.type
== bfd_link_hash_undefined
))))
4249 /* Make sure this symbol is output as a dynamic symbol.
4250 Undefined weak syms won't yet be marked as dynamic. */
4251 if (h
->dynindx
== -1
4252 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4254 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4258 /* If that succeeded, we know we'll be keeping all the
4260 if (h
->dynindx
!= -1)
4264 eh
->dyn_relocs
= NULL
;
4269 /* Finally, allocate space. */
4270 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4272 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
4273 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
4279 /* Find any dynamic relocs that apply to read-only sections. */
4282 readonly_dynrelocs (h
, inf
)
4283 struct elf_link_hash_entry
*h
;
4286 struct elf_sh_link_hash_entry
*eh
;
4287 struct elf_sh_dyn_relocs
*p
;
4289 if (h
->root
.type
== bfd_link_hash_warning
)
4290 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4292 eh
= (struct elf_sh_link_hash_entry
*) h
;
4293 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4295 asection
*s
= p
->sec
->output_section
;
4297 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4299 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4301 info
->flags
|= DF_TEXTREL
;
4303 /* Not an error, just cut short the traversal. */
4310 /* Set the sizes of the dynamic sections. */
4313 sh_elf_size_dynamic_sections (output_bfd
, info
)
4314 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4315 struct bfd_link_info
*info
;
4317 struct elf_sh_link_hash_table
*htab
;
4323 htab
= sh_elf_hash_table (info
);
4324 dynobj
= htab
->root
.dynobj
;
4325 BFD_ASSERT (dynobj
!= NULL
);
4327 if (htab
->root
.dynamic_sections_created
)
4329 /* Set the contents of the .interp section to the interpreter. */
4332 s
= bfd_get_section_by_name (dynobj
, ".interp");
4333 BFD_ASSERT (s
!= NULL
);
4334 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4335 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4339 /* Set up .got offsets for local syms, and space for local dynamic
4341 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4343 bfd_signed_vma
*local_got
;
4344 bfd_signed_vma
*end_local_got
;
4345 char *local_tls_type
;
4346 bfd_size_type locsymcount
;
4347 Elf_Internal_Shdr
*symtab_hdr
;
4350 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
4353 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4355 struct elf_sh_dyn_relocs
*p
;
4357 for (p
= ((struct elf_sh_dyn_relocs
*)
4358 elf_section_data (s
)->local_dynrel
);
4362 if (! bfd_is_abs_section (p
->sec
)
4363 && bfd_is_abs_section (p
->sec
->output_section
))
4365 /* Input section has been discarded, either because
4366 it is a copy of a linkonce section or due to
4367 linker script /DISCARD/, so we'll be discarding
4370 else if (p
->count
!= 0)
4372 srel
= elf_section_data (p
->sec
)->sreloc
;
4373 srel
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
4374 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
4375 info
->flags
|= DF_TEXTREL
;
4380 local_got
= elf_local_got_refcounts (ibfd
);
4384 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4385 locsymcount
= symtab_hdr
->sh_info
;
4386 #ifdef INCLUDE_SHMEDIA
4387 /* Count datalabel local GOT. */
4390 end_local_got
= local_got
+ locsymcount
;
4391 local_tls_type
= sh_elf_local_got_tls_type (ibfd
);
4393 srel
= htab
->srelgot
;
4394 for (; local_got
< end_local_got
; ++local_got
)
4398 *local_got
= s
->_raw_size
;
4400 if (*local_tls_type
== GOT_TLS_GD
)
4403 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
4406 *local_got
= (bfd_vma
) -1;
4411 if (htab
->tls_ldm_got
.refcount
> 0)
4413 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
4415 htab
->tls_ldm_got
.offset
= htab
->sgot
->_raw_size
;
4416 htab
->sgot
->_raw_size
+= 8;
4417 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4420 htab
->tls_ldm_got
.offset
= -1;
4422 /* Allocate global sym .plt and .got entries, and space for global
4423 sym dynamic relocs. */
4424 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
4426 /* We now have determined the sizes of the various dynamic sections.
4427 Allocate memory for them. */
4429 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4431 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4436 || s
== htab
->sgotplt
)
4438 /* Strip this section if we don't need it; see the
4441 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4443 if (s
->_raw_size
!= 0 && s
!= htab
->srelplt
)
4446 /* We use the reloc_count field as a counter if we need
4447 to copy relocs into the output file. */
4452 /* It's not one of our sections, so don't allocate space. */
4456 if (s
->_raw_size
== 0)
4458 /* If we don't need this section, strip it from the
4459 output file. This is mostly to handle .rela.bss and
4460 .rela.plt. We must create both sections in
4461 create_dynamic_sections, because they must be created
4462 before the linker maps input sections to output
4463 sections. The linker does that before
4464 adjust_dynamic_symbol is called, and it is that
4465 function which decides whether anything needs to go
4466 into these sections. */
4468 _bfd_strip_section_from_output (info
, s
);
4472 /* Allocate memory for the section contents. We use bfd_zalloc
4473 here in case unused entries are not reclaimed before the
4474 section's contents are written out. This should not happen,
4475 but this way if it does, we get a R_SH_NONE reloc instead
4477 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4478 if (s
->contents
== NULL
)
4482 if (htab
->root
.dynamic_sections_created
)
4484 /* Add some entries to the .dynamic section. We fill in the
4485 values later, in sh_elf_finish_dynamic_sections, but we
4486 must add the entries now so that we get the correct size for
4487 the .dynamic section. The DT_DEBUG entry is filled in by the
4488 dynamic linker and used by the debugger. */
4489 #define add_dynamic_entry(TAG, VAL) \
4490 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4494 if (! add_dynamic_entry (DT_DEBUG
, 0))
4498 if (htab
->splt
->_raw_size
!= 0)
4500 if (! add_dynamic_entry (DT_PLTGOT
, 0)
4501 || ! add_dynamic_entry (DT_PLTRELSZ
, 0)
4502 || ! add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4503 || ! add_dynamic_entry (DT_JMPREL
, 0))
4509 if (! add_dynamic_entry (DT_RELA
, 0)
4510 || ! add_dynamic_entry (DT_RELASZ
, 0)
4511 || ! add_dynamic_entry (DT_RELAENT
,
4512 sizeof (Elf32_External_Rela
)))
4515 /* If any dynamic relocs apply to a read-only section,
4516 then we need a DT_TEXTREL entry. */
4517 if ((info
->flags
& DF_TEXTREL
) == 0)
4518 elf_link_hash_traverse (&htab
->root
, readonly_dynrelocs
,
4521 if ((info
->flags
& DF_TEXTREL
) != 0)
4523 if (! add_dynamic_entry (DT_TEXTREL
, 0))
4528 #undef add_dynamic_entry
4533 /* Relocate an SH ELF section. */
4536 sh_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4537 contents
, relocs
, local_syms
, local_sections
)
4539 struct bfd_link_info
*info
;
4541 asection
*input_section
;
4543 Elf_Internal_Rela
*relocs
;
4544 Elf_Internal_Sym
*local_syms
;
4545 asection
**local_sections
;
4547 struct elf_sh_link_hash_table
*htab
;
4548 Elf_Internal_Shdr
*symtab_hdr
;
4549 struct elf_link_hash_entry
**sym_hashes
;
4550 Elf_Internal_Rela
*rel
, *relend
;
4552 bfd_vma
*local_got_offsets
;
4559 htab
= sh_elf_hash_table (info
);
4560 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4561 sym_hashes
= elf_sym_hashes (input_bfd
);
4562 dynobj
= htab
->root
.dynobj
;
4563 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4566 sgotplt
= htab
->sgotplt
;
4572 relend
= relocs
+ input_section
->reloc_count
;
4573 for (; rel
< relend
; rel
++)
4576 reloc_howto_type
*howto
;
4577 unsigned long r_symndx
;
4578 Elf_Internal_Sym
*sym
;
4580 struct elf_link_hash_entry
*h
;
4582 bfd_vma addend
= (bfd_vma
) 0;
4583 bfd_reloc_status_type r
;
4584 int seen_stt_datalabel
= 0;
4588 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4590 r_type
= ELF32_R_TYPE (rel
->r_info
);
4592 /* Many of the relocs are only used for relaxing, and are
4593 handled entirely by the relaxation code. */
4594 if (r_type
> (int) R_SH_LAST_INVALID_RELOC
4595 && r_type
< (int) R_SH_LOOP_START
)
4597 if (r_type
== (int) R_SH_NONE
)
4601 || r_type
>= R_SH_max
4602 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
4603 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
4604 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_3
4605 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_3
)
4606 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_4
4607 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_4
)
4608 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_5
4609 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_5
)
4610 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_2
4611 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_2
))
4613 bfd_set_error (bfd_error_bad_value
);
4617 howto
= sh_elf_howto_table
+ r_type
;
4619 /* For relocs that aren't partial_inplace, we get the addend from
4621 if (! howto
->partial_inplace
)
4622 addend
= rel
->r_addend
;
4627 if (r_symndx
< symtab_hdr
->sh_info
)
4629 sym
= local_syms
+ r_symndx
;
4630 sec
= local_sections
[r_symndx
];
4631 relocation
= (sec
->output_section
->vma
4632 + sec
->output_offset
4634 /* A local symbol never has STO_SH5_ISA32, so we don't need
4635 datalabel processing here. Make sure this does not change
4637 if ((sym
->st_other
& STO_SH5_ISA32
) != 0)
4638 ((*info
->callbacks
->reloc_dangerous
)
4640 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4641 input_bfd
, input_section
, rel
->r_offset
));
4642 if (info
->relocateable
)
4644 /* This is a relocateable link. We don't have to change
4645 anything, unless the reloc is against a section symbol,
4646 in which case we have to adjust according to where the
4647 section symbol winds up in the output section. */
4648 sym
= local_syms
+ r_symndx
;
4649 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4651 if (! howto
->partial_inplace
)
4653 /* For relocations with the addend in the
4654 relocation, we need just to update the addend.
4655 All real relocs are of type partial_inplace; this
4656 code is mostly for completeness. */
4657 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
4662 /* Relocs of type partial_inplace need to pick up the
4663 contents in the contents and add the offset resulting
4664 from the changed location of the section symbol.
4665 Using _bfd_final_link_relocate (e.g. goto
4666 final_link_relocate) here would be wrong, because
4667 relocations marked pc_relative would get the current
4668 location subtracted, and we must only do that at the
4670 r
= _bfd_relocate_contents (howto
, input_bfd
,
4673 contents
+ rel
->r_offset
);
4674 goto relocation_done
;
4679 else if (! howto
->partial_inplace
)
4681 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
4682 addend
= rel
->r_addend
;
4684 else if ((sec
->flags
& SEC_MERGE
)
4685 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4689 if (howto
->rightshift
|| howto
->src_mask
!= 0xffffffff)
4691 (*_bfd_error_handler
)
4692 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
4693 bfd_archive_filename (input_bfd
),
4694 bfd_get_section_name (input_bfd
, input_section
),
4695 (long) rel
->r_offset
, howto
->name
);
4699 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4702 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
4704 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
4705 bfd_put_32 (input_bfd
, addend
, contents
+ rel
->r_offset
);
4711 /* Section symbol are never (?) placed in the hash table, so
4712 we can just ignore hash relocations when creating a
4713 relocateable object file. */
4714 if (info
->relocateable
)
4717 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4718 while (h
->root
.type
== bfd_link_hash_indirect
4719 || h
->root
.type
== bfd_link_hash_warning
)
4721 #ifdef INCLUDE_SHMEDIA
4722 /* If the reference passes a symbol marked with
4723 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4725 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
4727 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4729 if (h
->root
.type
== bfd_link_hash_defined
4730 || h
->root
.type
== bfd_link_hash_defweak
)
4734 dyn
= htab
->root
.dynamic_sections_created
;
4735 sec
= h
->root
.u
.def
.section
;
4736 /* In these cases, we don't need the relocation value.
4737 We check specially because in some obscure cases
4738 sec->output_section will be NULL. */
4739 if (r_type
== R_SH_GOTPC
4740 || r_type
== R_SH_GOTPC_LOW16
4741 || r_type
== R_SH_GOTPC_MEDLOW16
4742 || r_type
== R_SH_GOTPC_MEDHI16
4743 || r_type
== R_SH_GOTPC_HI16
4744 || ((r_type
== R_SH_PLT32
4745 || r_type
== R_SH_PLT_LOW16
4746 || r_type
== R_SH_PLT_MEDLOW16
4747 || r_type
== R_SH_PLT_MEDHI16
4748 || r_type
== R_SH_PLT_HI16
)
4749 && h
->plt
.offset
!= (bfd_vma
) -1)
4750 || ((r_type
== R_SH_GOT32
4751 || r_type
== R_SH_GOT_LOW16
4752 || r_type
== R_SH_GOT_MEDLOW16
4753 || r_type
== R_SH_GOT_MEDHI16
4754 || r_type
== R_SH_GOT_HI16
)
4755 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
4757 || (! info
->symbolic
&& h
->dynindx
!= -1)
4758 || (h
->elf_link_hash_flags
4759 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4760 /* The cases above are those in which relocation is
4761 overwritten in the switch block below. The cases
4762 below are those in which we must defer relocation
4763 to run-time, because we can't resolve absolute
4764 addresses when creating a shared library. */
4766 && ((! info
->symbolic
&& h
->dynindx
!= -1)
4767 || (h
->elf_link_hash_flags
4768 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
4769 && ((r_type
== R_SH_DIR32
4770 && (h
->elf_link_hash_flags
4771 & ELF_LINK_FORCED_LOCAL
) == 0)
4772 || r_type
== R_SH_REL32
)
4773 && ((input_section
->flags
& SEC_ALLOC
) != 0
4774 /* DWARF will emit R_SH_DIR32 relocations in its
4775 sections against symbols defined externally
4776 in shared libraries. We can't do anything
4778 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
4779 && (h
->elf_link_hash_flags
4780 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)))
4781 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4782 sections because such sections are not SEC_ALLOC and
4783 thus ld.so will not process them. */
4784 || (sec
->output_section
== NULL
4785 && ((input_section
->flags
& SEC_DEBUGGING
) != 0
4786 && (h
->elf_link_hash_flags
4787 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
4788 || (sec
->output_section
== NULL
4789 && (sh_elf_hash_entry (h
)->tls_type
== GOT_TLS_IE
4790 || sh_elf_hash_entry (h
)->tls_type
== GOT_TLS_GD
)))
4792 else if (sec
->output_section
== NULL
)
4794 (*_bfd_error_handler
)
4795 (_("%s: unresolvable relocation against symbol `%s' from %s section"),
4796 bfd_archive_filename (input_bfd
), h
->root
.root
.string
,
4797 bfd_get_section_name (input_bfd
, input_section
));
4801 relocation
= ((h
->root
.u
.def
.value
4802 + sec
->output_section
->vma
4803 + sec
->output_offset
)
4804 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4805 symbol value, unless we've seen
4806 STT_DATALABEL on the way to it. */
4807 | ((h
->other
& STO_SH5_ISA32
) != 0
4808 && ! seen_stt_datalabel
));
4810 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4812 else if (info
->shared
4813 && ! info
->no_undefined
4814 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4818 if (! ((*info
->callbacks
->undefined_symbol
)
4819 (info
, h
->root
.root
.string
, input_bfd
,
4820 input_section
, rel
->r_offset
,
4821 (!info
->shared
|| info
->no_undefined
4822 || ELF_ST_VISIBILITY (h
->other
)))))
4828 switch ((int) r_type
)
4830 final_link_relocate
:
4831 /* COFF relocs don't use the addend. The addend is used for
4832 R_SH_DIR32 to be compatible with other compilers. */
4833 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4834 contents
, rel
->r_offset
,
4835 relocation
, addend
);
4839 goto final_link_relocate
;
4844 /* If the reloc is against the start of this section, then
4845 the assembler has already taken care of it and the reloc
4846 is here only to assist in relaxing. If the reloc is not
4847 against the start of this section, then it's against an
4848 external symbol and we must deal with it ourselves. */
4849 if (input_section
->output_section
->vma
+ input_section
->output_offset
4852 int disp
= (relocation
4853 - input_section
->output_section
->vma
4854 - input_section
->output_offset
4860 case R_SH_DIR8WPZ
: mask
= 1; break;
4861 case R_SH_DIR8WPL
: mask
= 3; break;
4862 default: mask
= 0; break;
4866 ((*_bfd_error_handler
)
4867 (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4868 bfd_archive_filename (input_section
->owner
),
4869 (unsigned long) rel
->r_offset
));
4870 bfd_set_error (bfd_error_bad_value
);
4874 goto final_link_relocate
;
4880 #ifdef INCLUDE_SHMEDIA
4881 if (shmedia_prepare_reloc (info
, input_bfd
, input_section
,
4882 contents
, rel
, &relocation
))
4883 goto final_link_relocate
;
4885 bfd_set_error (bfd_error_bad_value
);
4892 && (input_section
->flags
& SEC_ALLOC
) != 0
4893 && (r_type
!= R_SH_REL32
4896 && (! info
->symbolic
4897 || (h
->elf_link_hash_flags
4898 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
4900 Elf_Internal_Rela outrel
;
4902 bfd_boolean skip
, relocate
;
4904 /* When generating a shared object, these relocations
4905 are copied into the output file to be resolved at run
4912 name
= (bfd_elf_string_from_elf_section
4914 elf_elfheader (input_bfd
)->e_shstrndx
,
4915 elf_section_data (input_section
)->rel_hdr
.sh_name
));
4919 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
4920 && strcmp (bfd_get_section_name (input_bfd
,
4924 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4925 BFD_ASSERT (sreloc
!= NULL
);
4932 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4934 if (outrel
.r_offset
== (bfd_vma
) -1)
4936 else if (outrel
.r_offset
== (bfd_vma
) -2)
4937 skip
= TRUE
, relocate
= TRUE
;
4938 outrel
.r_offset
+= (input_section
->output_section
->vma
4939 + input_section
->output_offset
);
4942 memset (&outrel
, 0, sizeof outrel
);
4943 else if (r_type
== R_SH_REL32
)
4945 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
4946 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_REL32
);
4948 = bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4952 /* h->dynindx may be -1 if this symbol was marked to
4955 || ((info
->symbolic
|| h
->dynindx
== -1)
4956 && (h
->elf_link_hash_flags
4957 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
4960 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
4962 = relocation
+ bfd_get_32 (input_bfd
,
4963 contents
+ rel
->r_offset
);
4967 BFD_ASSERT (h
->dynindx
!= -1);
4968 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_DIR32
);
4970 = relocation
+ bfd_get_32 (input_bfd
,
4971 contents
+ rel
->r_offset
);
4975 loc
= sreloc
->contents
;
4976 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4977 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4979 /* If this reloc is against an external symbol, we do
4980 not want to fiddle with the addend. Otherwise, we
4981 need to include the symbol value so that it becomes
4982 an addend for the dynamic reloc. */
4986 goto final_link_relocate
;
4989 #ifdef INCLUDE_SHMEDIA
4990 case R_SH_GOTPLT_LOW16
:
4991 case R_SH_GOTPLT_MEDLOW16
:
4992 case R_SH_GOTPLT_MEDHI16
:
4993 case R_SH_GOTPLT_HI16
:
4994 case R_SH_GOTPLT10BY4
:
4995 case R_SH_GOTPLT10BY8
:
4997 /* Relocation is to the entry for this symbol in the
4998 procedure linkage table. */
5001 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
5005 || h
->plt
.offset
== (bfd_vma
) -1
5006 || h
->got
.offset
!= (bfd_vma
) -1)
5009 /* Relocation is to the entry for this symbol in the global
5010 offset table extension for the procedure linkage table. */
5012 BFD_ASSERT (sgotplt
!= NULL
);
5013 relocation
= (sgotplt
->output_offset
5014 + ((h
->plt
.offset
/ elf_sh_sizeof_plt (info
)
5018 relocation
-= GOT_BIAS
;
5021 goto final_link_relocate
;
5025 #ifdef INCLUDE_SHMEDIA
5026 case R_SH_GOT_LOW16
:
5027 case R_SH_GOT_MEDLOW16
:
5028 case R_SH_GOT_MEDHI16
:
5033 /* Relocation is to the entry for this symbol in the global
5036 BFD_ASSERT (sgot
!= NULL
);
5042 off
= h
->got
.offset
;
5043 #ifdef INCLUDE_SHMEDIA
5044 if (seen_stt_datalabel
)
5046 struct elf_sh_link_hash_entry
*hsh
;
5048 hsh
= (struct elf_sh_link_hash_entry
*)h
;
5049 off
= hsh
->datalabel_got
.offset
;
5052 BFD_ASSERT (off
!= (bfd_vma
) -1);
5054 dyn
= htab
->root
.dynamic_sections_created
;
5055 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
5057 && (info
->symbolic
|| h
->dynindx
== -1
5058 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
5059 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
5061 /* This is actually a static link, or it is a
5062 -Bsymbolic link and the symbol is defined
5063 locally, or the symbol was forced to be local
5064 because of a version file. We must initialize
5065 this entry in the global offset table. Since the
5066 offset must always be a multiple of 4, we use the
5067 least significant bit to record whether we have
5068 initialized it already.
5070 When doing a dynamic link, we create a .rela.got
5071 relocation entry to initialize the value. This
5072 is done in the finish_dynamic_symbol routine. */
5077 bfd_put_32 (output_bfd
, relocation
,
5078 sgot
->contents
+ off
);
5079 #ifdef INCLUDE_SHMEDIA
5080 if (seen_stt_datalabel
)
5082 struct elf_sh_link_hash_entry
*hsh
;
5084 hsh
= (struct elf_sh_link_hash_entry
*)h
;
5085 hsh
->datalabel_got
.offset
|= 1;
5093 relocation
= sgot
->output_offset
+ off
;
5097 #ifdef INCLUDE_SHMEDIA
5100 BFD_ASSERT (local_got_offsets
!= NULL
5101 && (local_got_offsets
[symtab_hdr
->sh_info
5105 off
= local_got_offsets
[symtab_hdr
->sh_info
5111 BFD_ASSERT (local_got_offsets
!= NULL
5112 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
5114 off
= local_got_offsets
[r_symndx
];
5115 #ifdef INCLUDE_SHMEDIA
5119 /* The offset must always be a multiple of 4. We use
5120 the least significant bit to record whether we have
5121 already generated the necessary reloc. */
5126 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
5130 Elf_Internal_Rela outrel
;
5133 if (srelgot
== NULL
)
5135 srelgot
= bfd_get_section_by_name (dynobj
,
5137 BFD_ASSERT (srelgot
!= NULL
);
5140 outrel
.r_offset
= (sgot
->output_section
->vma
5141 + sgot
->output_offset
5143 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
5144 outrel
.r_addend
= relocation
;
5145 loc
= srelgot
->contents
;
5146 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5147 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5150 #ifdef INCLUDE_SHMEDIA
5152 local_got_offsets
[symtab_hdr
->sh_info
+ r_symndx
] |= 1;
5155 local_got_offsets
[r_symndx
] |= 1;
5158 relocation
= sgot
->output_offset
+ off
;
5162 relocation
-= GOT_BIAS
;
5165 goto final_link_relocate
;
5168 #ifdef INCLUDE_SHMEDIA
5169 case R_SH_GOTOFF_LOW16
:
5170 case R_SH_GOTOFF_MEDLOW16
:
5171 case R_SH_GOTOFF_MEDHI16
:
5172 case R_SH_GOTOFF_HI16
:
5174 /* Relocation is relative to the start of the global offset
5177 BFD_ASSERT (sgot
!= NULL
);
5179 /* Note that sgot->output_offset is not involved in this
5180 calculation. We always want the start of .got. If we
5181 defined _GLOBAL_OFFSET_TABLE in a different way, as is
5182 permitted by the ABI, we might have to change this
5184 relocation
-= sgot
->output_section
->vma
;
5187 relocation
-= GOT_BIAS
;
5190 addend
= rel
->r_addend
;
5192 goto final_link_relocate
;
5195 #ifdef INCLUDE_SHMEDIA
5196 case R_SH_GOTPC_LOW16
:
5197 case R_SH_GOTPC_MEDLOW16
:
5198 case R_SH_GOTPC_MEDHI16
:
5199 case R_SH_GOTPC_HI16
:
5201 /* Use global offset table as symbol value. */
5203 BFD_ASSERT (sgot
!= NULL
);
5204 relocation
= sgot
->output_section
->vma
;
5207 relocation
+= GOT_BIAS
;
5210 addend
= rel
->r_addend
;
5212 goto final_link_relocate
;
5215 #ifdef INCLUDE_SHMEDIA
5216 case R_SH_PLT_LOW16
:
5217 case R_SH_PLT_MEDLOW16
:
5218 case R_SH_PLT_MEDHI16
:
5221 /* Relocation is to the entry for this symbol in the
5222 procedure linkage table. */
5224 /* Resolve a PLT reloc against a local symbol directly,
5225 without using the procedure linkage table. */
5227 goto final_link_relocate
;
5229 if (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
5230 goto final_link_relocate
;
5232 if (h
->plt
.offset
== (bfd_vma
) -1)
5234 /* We didn't make a PLT entry for this symbol. This
5235 happens when statically linking PIC code, or when
5236 using -Bsymbolic. */
5237 goto final_link_relocate
;
5240 BFD_ASSERT (splt
!= NULL
);
5241 relocation
= (splt
->output_section
->vma
5242 + splt
->output_offset
5245 #ifdef INCLUDE_SHMEDIA
5249 addend
= rel
->r_addend
;
5251 goto final_link_relocate
;
5253 case R_SH_LOOP_START
:
5255 static bfd_vma start
, end
;
5257 start
= (relocation
+ rel
->r_addend
5258 - (sec
->output_section
->vma
+ sec
->output_offset
));
5259 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5260 rel
->r_offset
, sec
, start
, end
);
5264 end
= (relocation
+ rel
->r_addend
5265 - (sec
->output_section
->vma
+ sec
->output_offset
));
5266 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5267 rel
->r_offset
, sec
, start
, end
);
5271 case R_SH_TLS_GD_32
:
5272 case R_SH_TLS_IE_32
:
5273 r_type
= sh_elf_optimized_tls_reloc (info
, r_type
, h
== NULL
);
5274 tls_type
= GOT_UNKNOWN
;
5275 if (h
== NULL
&& local_got_offsets
)
5276 tls_type
= sh_elf_local_got_tls_type (input_bfd
) [r_symndx
];
5279 tls_type
= sh_elf_hash_entry (h
)->tls_type
;
5281 && (h
->dynindx
== -1
5282 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
5284 struct elf_sh_dyn_relocs
*p
;
5286 /* If TPOFF32 relocation can be created, convert it. */
5287 for (p
= sh_elf_hash_entry (h
)->dyn_relocs
; p
; p
= p
->next
)
5288 if (p
->sec
== input_section
&& p
->tls_tpoff32
)
5290 r_type
= R_SH_TLS_LE_32
;
5296 if (r_type
== R_SH_TLS_GD_32
&& tls_type
== GOT_TLS_IE
)
5297 r_type
= R_SH_TLS_IE_32
;
5299 if (r_type
== R_SH_TLS_LE_32
)
5302 unsigned short insn
;
5304 Elf_Internal_Rela outrel
;
5307 if (ELF32_R_TYPE (rel
->r_info
) == R_SH_TLS_GD_32
)
5309 /* GD->LE transition:
5310 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5311 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5312 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5314 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5316 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
5318 offset
= rel
->r_offset
;
5319 BFD_ASSERT (offset
>= 16);
5320 /* Size of GD instructions is 16 or 18. */
5322 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5323 if ((insn
& 0xff00) == 0xc700)
5325 BFD_ASSERT (offset
>= 2);
5327 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5330 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5331 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5332 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5333 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5334 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5335 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5336 BFD_ASSERT (insn
== 0x310c);
5337 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5338 BFD_ASSERT (insn
== 0x410b);
5339 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5340 BFD_ASSERT (insn
== 0x34cc);
5342 bfd_put_16 (output_bfd
, 0x0012, contents
+ offset
+ 2);
5343 bfd_put_16 (output_bfd
, 0x304c, contents
+ offset
+ 4);
5344 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 6);
5345 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5346 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5352 /* IE->LE transition:
5353 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5354 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5356 mov.l .Ln,rM; stc gbr,rN; nop; ...;
5359 offset
= rel
->r_offset
;
5360 BFD_ASSERT (offset
>= 16);
5361 /* Size of IE instructions is 10 or 12. */
5363 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5364 if ((insn
& 0xf0ff) == 0x0012)
5366 BFD_ASSERT (offset
>= 2);
5368 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5371 BFD_ASSERT ((insn
& 0xff00) == 0xd000);
5372 index
= insn
& 0x00ff;
5373 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5374 BFD_ASSERT ((insn
& 0xf0ff) == 0x0012);
5375 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5376 BFD_ASSERT ((insn
& 0xf0ff) == 0x00ce);
5377 insn
= 0xd000 | (insn
& 0x0f00) | index
;
5378 bfd_put_16 (output_bfd
, insn
, contents
+ offset
+ 0);
5379 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 4);
5386 name
= (bfd_elf_string_from_elf_section
5388 elf_elfheader (input_bfd
)->e_shstrndx
,
5389 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5393 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5394 && strcmp (bfd_get_section_name (input_bfd
,
5398 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5399 BFD_ASSERT (sreloc
!= NULL
);
5405 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
5409 outrel
.r_offset
= (input_section
->output_section
->vma
5410 + input_section
->output_offset
5412 outrel
.r_info
= ELF32_R_INFO (indx
, R_SH_TLS_TPOFF32
);
5414 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5416 outrel
.r_addend
= 0;
5418 loc
= sreloc
->contents
;
5419 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5420 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5429 off
= h
->got
.offset
;
5432 if (local_got_offsets
== NULL
)
5435 off
= local_got_offsets
[r_symndx
];
5442 Elf_Internal_Rela outrel
;
5446 if (srelgot
== NULL
)
5448 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
5449 BFD_ASSERT (srelgot
!= NULL
);
5452 outrel
.r_offset
= (sgot
->output_section
->vma
5453 + sgot
->output_offset
+ off
);
5458 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
5462 dr_type
= (r_type
== R_SH_TLS_GD_32
? R_SH_TLS_DTPMOD32
:
5464 if (dr_type
== R_SH_TLS_TPOFF32
&& indx
== 0)
5465 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5467 outrel
.r_addend
= 0;
5468 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
5469 loc
= srelgot
->contents
;
5470 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5471 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5473 if (r_type
== R_SH_TLS_GD_32
)
5477 bfd_put_32 (output_bfd
,
5478 relocation
- dtpoff_base (info
),
5479 sgot
->contents
+ off
+ 4);
5483 outrel
.r_info
= ELF32_R_INFO (indx
,
5485 outrel
.r_offset
+= 4;
5486 outrel
.r_addend
= 0;
5487 srelgot
->reloc_count
++;
5488 loc
+= sizeof (Elf32_External_Rela
);
5489 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5496 local_got_offsets
[r_symndx
] |= 1;
5499 if (off
>= (bfd_vma
) -2)
5502 if (r_type
== (int) ELF32_R_TYPE (rel
->r_info
))
5503 relocation
= sgot
->output_offset
+ off
;
5507 unsigned short insn
;
5509 /* GD->IE transition:
5510 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5511 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5512 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5514 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5515 nop; nop; bra 3f; nop; .align 2;
5516 1: .long x@TPOFF; 2:...; 3:. */
5518 offset
= rel
->r_offset
;
5519 BFD_ASSERT (offset
>= 16);
5520 /* Size of GD instructions is 16 or 18. */
5522 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5523 if ((insn
& 0xff00) == 0xc700)
5525 BFD_ASSERT (offset
>= 2);
5527 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5530 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5532 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
5533 bfd_put_16 (output_bfd
, insn
& 0xf0ff, contents
+ offset
);
5535 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5536 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5537 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5538 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5539 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5540 BFD_ASSERT (insn
== 0x310c);
5541 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5542 BFD_ASSERT (insn
== 0x410b);
5543 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5544 BFD_ASSERT (insn
== 0x34cc);
5546 bfd_put_16 (output_bfd
, 0x0412, contents
+ offset
+ 2);
5547 bfd_put_16 (output_bfd
, 0x00ce, contents
+ offset
+ 4);
5548 bfd_put_16 (output_bfd
, 0x304c, contents
+ offset
+ 6);
5549 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5550 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5552 bfd_put_32 (output_bfd
, sgot
->output_offset
+ off
,
5553 contents
+ rel
->r_offset
);
5558 addend
= rel
->r_addend
;
5560 goto final_link_relocate
;
5562 case R_SH_TLS_LD_32
:
5566 unsigned short insn
;
5568 /* LD->LE transition:
5569 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5570 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5571 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5573 stc gbr,r0; nop; nop; nop;
5574 nop; nop; bra 3f; ...; 3:. */
5576 offset
= rel
->r_offset
;
5577 BFD_ASSERT (offset
>= 16);
5578 /* Size of LD instructions is 16 or 18. */
5580 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5581 if ((insn
& 0xff00) == 0xc700)
5583 BFD_ASSERT (offset
>= 2);
5585 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5588 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5589 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5590 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5591 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5592 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5593 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5594 BFD_ASSERT (insn
== 0x310c);
5595 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5596 BFD_ASSERT (insn
== 0x410b);
5597 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5598 BFD_ASSERT (insn
== 0x34cc);
5600 bfd_put_16 (output_bfd
, 0x0012, contents
+ offset
+ 0);
5601 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 2);
5602 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 4);
5603 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 6);
5604 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5605 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5614 off
= htab
->tls_ldm_got
.offset
;
5619 Elf_Internal_Rela outrel
;
5622 srelgot
= htab
->srelgot
;
5623 if (srelgot
== NULL
)
5626 outrel
.r_offset
= (sgot
->output_section
->vma
5627 + sgot
->output_offset
+ off
);
5628 outrel
.r_addend
= 0;
5629 outrel
.r_info
= ELF32_R_INFO (0, R_SH_TLS_DTPMOD32
);
5630 loc
= srelgot
->contents
;
5631 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5632 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5633 htab
->tls_ldm_got
.offset
|= 1;
5636 relocation
= sgot
->output_offset
+ off
;
5637 addend
= rel
->r_addend
;
5639 goto final_link_relocate
;
5641 case R_SH_TLS_LDO_32
:
5645 Elf_Internal_Rela outrel
;
5652 name
= (bfd_elf_string_from_elf_section
5654 elf_elfheader (input_bfd
)->e_shstrndx
,
5655 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5659 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5660 && strcmp (bfd_get_section_name (input_bfd
,
5664 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5665 BFD_ASSERT (sreloc
!= NULL
);
5668 indx
= (h
&& h
->dynindx
!= -1) ? h
->dynindx
: 0;
5669 outrel
.r_offset
= (input_section
->output_section
->vma
5670 + input_section
->output_offset
5672 outrel
.r_info
= ELF32_R_INFO (indx
, R_SH_TLS_TPOFF32
);
5674 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5676 outrel
.r_addend
= 0;
5678 loc
= sreloc
->contents
;
5679 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5680 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5684 relocation
-= dtpoff_base (info
);
5686 addend
= rel
->r_addend
;
5687 goto final_link_relocate
;
5689 case R_SH_TLS_LE_32
:
5692 Elf_Internal_Rela outrel
;
5699 name
= (bfd_elf_string_from_elf_section
5701 elf_elfheader (input_bfd
)->e_shstrndx
,
5702 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5706 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5707 && strcmp (bfd_get_section_name (input_bfd
,
5711 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5712 BFD_ASSERT (sreloc
!= NULL
);
5715 indx
= (h
&& h
->dynindx
!= -1) ? h
->dynindx
: 0;
5716 outrel
.r_offset
= (input_section
->output_section
->vma
5717 + input_section
->output_offset
5719 outrel
.r_info
= ELF32_R_INFO (indx
, R_SH_TLS_TPOFF32
);
5721 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5723 outrel
.r_addend
= 0;
5725 loc
= sreloc
->contents
;
5726 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5727 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5733 if (r
!= bfd_reloc_ok
)
5738 case bfd_reloc_outofrange
:
5740 case bfd_reloc_overflow
:
5745 name
= h
->root
.root
.string
;
5748 name
= (bfd_elf_string_from_elf_section
5749 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5753 name
= bfd_section_name (input_bfd
, sec
);
5755 if (! ((*info
->callbacks
->reloc_overflow
)
5756 (info
, name
, howto
->name
, (bfd_vma
) 0,
5757 input_bfd
, input_section
, rel
->r_offset
)))
5768 /* This is a version of bfd_generic_get_relocated_section_contents
5769 which uses sh_elf_relocate_section. */
5772 sh_elf_get_relocated_section_contents (output_bfd
, link_info
, link_order
,
5773 data
, relocateable
, symbols
)
5775 struct bfd_link_info
*link_info
;
5776 struct bfd_link_order
*link_order
;
5778 bfd_boolean relocateable
;
5781 Elf_Internal_Shdr
*symtab_hdr
;
5782 asection
*input_section
= link_order
->u
.indirect
.section
;
5783 bfd
*input_bfd
= input_section
->owner
;
5784 asection
**sections
= NULL
;
5785 Elf_Internal_Rela
*internal_relocs
= NULL
;
5786 Elf_Internal_Sym
*isymbuf
= NULL
;
5788 /* We only need to handle the case of relaxing, or of having a
5789 particular set of section contents, specially. */
5791 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
5792 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
5797 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5799 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
5800 (size_t) input_section
->_raw_size
);
5802 if ((input_section
->flags
& SEC_RELOC
) != 0
5803 && input_section
->reloc_count
> 0)
5806 Elf_Internal_Sym
*isym
, *isymend
;
5809 internal_relocs
= (_bfd_elf32_link_read_relocs
5810 (input_bfd
, input_section
, (PTR
) NULL
,
5811 (Elf_Internal_Rela
*) NULL
, FALSE
));
5812 if (internal_relocs
== NULL
)
5815 if (symtab_hdr
->sh_info
!= 0)
5817 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5818 if (isymbuf
== NULL
)
5819 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
5820 symtab_hdr
->sh_info
, 0,
5822 if (isymbuf
== NULL
)
5826 amt
= symtab_hdr
->sh_info
;
5827 amt
*= sizeof (asection
*);
5828 sections
= (asection
**) bfd_malloc (amt
);
5829 if (sections
== NULL
&& amt
!= 0)
5832 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
5833 for (isym
= isymbuf
, secpp
= sections
; isym
< isymend
; ++isym
, ++secpp
)
5837 if (isym
->st_shndx
== SHN_UNDEF
)
5838 isec
= bfd_und_section_ptr
;
5839 else if (isym
->st_shndx
== SHN_ABS
)
5840 isec
= bfd_abs_section_ptr
;
5841 else if (isym
->st_shndx
== SHN_COMMON
)
5842 isec
= bfd_com_section_ptr
;
5844 isec
= bfd_section_from_elf_index (input_bfd
, isym
->st_shndx
);
5849 if (! sh_elf_relocate_section (output_bfd
, link_info
, input_bfd
,
5850 input_section
, data
, internal_relocs
,
5854 if (sections
!= NULL
)
5857 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5859 if (elf_section_data (input_section
)->relocs
!= internal_relocs
)
5860 free (internal_relocs
);
5866 if (sections
!= NULL
)
5869 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5871 if (internal_relocs
!= NULL
5872 && elf_section_data (input_section
)->relocs
!= internal_relocs
)
5873 free (internal_relocs
);
5877 /* Return the base VMA address which should be subtracted from real addresses
5878 when resolving @dtpoff relocation.
5879 This is PT_TLS segment p_vaddr. */
5883 struct bfd_link_info
*info
;
5885 /* If tls_segment is NULL, we should have signalled an error already. */
5886 if (elf_hash_table (info
)->tls_segment
== NULL
)
5888 return elf_hash_table (info
)->tls_segment
->start
;
5892 sh_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
5894 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
5895 Elf_Internal_Rela
*rel
;
5896 struct elf_link_hash_entry
*h
;
5897 Elf_Internal_Sym
*sym
;
5901 switch (ELF32_R_TYPE (rel
->r_info
))
5903 case R_SH_GNU_VTINHERIT
:
5904 case R_SH_GNU_VTENTRY
:
5908 #ifdef INCLUDE_SHMEDIA
5909 while (h
->root
.type
== bfd_link_hash_indirect
5910 && h
->root
.u
.i
.link
)
5911 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5913 switch (h
->root
.type
)
5915 case bfd_link_hash_defined
:
5916 case bfd_link_hash_defweak
:
5917 return h
->root
.u
.def
.section
;
5919 case bfd_link_hash_common
:
5920 return h
->root
.u
.c
.p
->section
;
5928 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5933 /* Update the got entry reference counts for the section being removed. */
5936 sh_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
5938 struct bfd_link_info
*info
;
5940 const Elf_Internal_Rela
*relocs
;
5942 Elf_Internal_Shdr
*symtab_hdr
;
5943 struct elf_link_hash_entry
**sym_hashes
;
5944 bfd_signed_vma
*local_got_refcounts
;
5945 const Elf_Internal_Rela
*rel
, *relend
;
5947 elf_section_data (sec
)->local_dynrel
= NULL
;
5949 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5950 sym_hashes
= elf_sym_hashes (abfd
);
5951 local_got_refcounts
= elf_local_got_refcounts (abfd
);
5953 relend
= relocs
+ sec
->reloc_count
;
5954 for (rel
= relocs
; rel
< relend
; rel
++)
5956 unsigned long r_symndx
;
5957 unsigned int r_type
;
5958 struct elf_link_hash_entry
*h
= NULL
;
5959 #ifdef INCLUDE_SHMEDIA
5960 int seen_stt_datalabel
= 0;
5963 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5964 if (r_symndx
>= symtab_hdr
->sh_info
)
5966 struct elf_sh_link_hash_entry
*eh
;
5967 struct elf_sh_dyn_relocs
**pp
;
5968 struct elf_sh_dyn_relocs
*p
;
5970 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5971 #ifdef INCLUDE_SHMEDIA
5972 while (h
->root
.type
== bfd_link_hash_indirect
5973 || h
->root
.type
== bfd_link_hash_warning
)
5975 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
5976 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5979 eh
= (struct elf_sh_link_hash_entry
*) h
;
5980 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5983 /* Everything must go for SEC. */
5989 r_type
= ELF32_R_TYPE (rel
->r_info
);
5990 switch (sh_elf_optimized_tls_reloc (info
, r_type
, h
!= NULL
))
5992 case R_SH_TLS_LD_32
:
5993 if (sh_elf_hash_table (info
)->tls_ldm_got
.refcount
> 0)
5994 sh_elf_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
6000 #ifdef INCLUDE_SHMEDIA
6001 case R_SH_GOT_LOW16
:
6002 case R_SH_GOT_MEDLOW16
:
6003 case R_SH_GOT_MEDHI16
:
6007 case R_SH_GOTOFF_LOW16
:
6008 case R_SH_GOTOFF_MEDLOW16
:
6009 case R_SH_GOTOFF_MEDHI16
:
6010 case R_SH_GOTOFF_HI16
:
6011 case R_SH_GOTPC_LOW16
:
6012 case R_SH_GOTPC_MEDLOW16
:
6013 case R_SH_GOTPC_MEDHI16
:
6014 case R_SH_GOTPC_HI16
:
6016 case R_SH_TLS_GD_32
:
6017 case R_SH_TLS_IE_32
:
6020 #ifdef INCLUDE_SHMEDIA
6021 if (seen_stt_datalabel
)
6023 struct elf_sh_link_hash_entry
*eh
;
6024 eh
= (struct elf_sh_link_hash_entry
*) h
;
6025 if (eh
->datalabel_got
.refcount
> 0)
6026 eh
->datalabel_got
.refcount
-= 1;
6030 if (h
->got
.refcount
> 0)
6031 h
->got
.refcount
-= 1;
6033 else if (local_got_refcounts
!= NULL
)
6035 #ifdef INCLUDE_SHMEDIA
6036 if (rel
->r_addend
& 1)
6038 if (local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] > 0)
6039 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] -= 1;
6043 if (local_got_refcounts
[r_symndx
] > 0)
6044 local_got_refcounts
[r_symndx
] -= 1;
6055 #ifdef INCLUDE_SHMEDIA
6056 case R_SH_PLT_LOW16
:
6057 case R_SH_PLT_MEDLOW16
:
6058 case R_SH_PLT_MEDHI16
:
6063 if (h
->plt
.refcount
> 0)
6064 h
->plt
.refcount
-= 1;
6069 #ifdef INCLUDE_SHMEDIA
6070 case R_SH_GOTPLT_LOW16
:
6071 case R_SH_GOTPLT_MEDLOW16
:
6072 case R_SH_GOTPLT_MEDHI16
:
6073 case R_SH_GOTPLT_HI16
:
6074 case R_SH_GOTPLT10BY4
:
6075 case R_SH_GOTPLT10BY8
:
6079 struct elf_sh_link_hash_entry
*eh
;
6080 eh
= (struct elf_sh_link_hash_entry
*) h
;
6081 if (eh
->gotplt_refcount
> 0)
6083 eh
->gotplt_refcount
-= 1;
6084 if (h
->plt
.refcount
> 0)
6085 h
->plt
.refcount
-= 1;
6087 #ifdef INCLUDE_SHMEDIA
6088 else if (seen_stt_datalabel
)
6090 if (eh
->datalabel_got
.refcount
> 0)
6091 eh
->datalabel_got
.refcount
-= 1;
6094 else if (h
->got
.refcount
> 0)
6095 h
->got
.refcount
-= 1;
6097 else if (local_got_refcounts
!= NULL
)
6099 #ifdef INCLUDE_SHMEDIA
6100 if (rel
->r_addend
& 1)
6102 if (local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] > 0)
6103 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] -= 1;
6107 if (local_got_refcounts
[r_symndx
] > 0)
6108 local_got_refcounts
[r_symndx
] -= 1;
6120 /* Copy the extra info we tack onto an elf_link_hash_entry. */
6123 sh_elf_copy_indirect_symbol (bed
, dir
, ind
)
6124 struct elf_backend_data
*bed
;
6125 struct elf_link_hash_entry
*dir
, *ind
;
6127 struct elf_sh_link_hash_entry
*edir
, *eind
;
6128 #ifdef INCLUDE_SHMEDIA
6132 edir
= (struct elf_sh_link_hash_entry
*) dir
;
6133 eind
= (struct elf_sh_link_hash_entry
*) ind
;
6135 if (eind
->dyn_relocs
!= NULL
)
6137 if (edir
->dyn_relocs
!= NULL
)
6139 struct elf_sh_dyn_relocs
**pp
;
6140 struct elf_sh_dyn_relocs
*p
;
6142 BFD_ASSERT (ind
->root
.type
!= bfd_link_hash_indirect
);
6144 /* Add reloc counts against the weak sym to the strong sym
6145 list. Merge any entries against the same section. */
6146 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
6148 struct elf_sh_dyn_relocs
*q
;
6150 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
6151 if (q
->sec
== p
->sec
)
6153 q
->pc_count
+= p
->pc_count
;
6154 q
->count
+= p
->count
;
6161 *pp
= edir
->dyn_relocs
;
6164 edir
->dyn_relocs
= eind
->dyn_relocs
;
6165 eind
->dyn_relocs
= NULL
;
6167 edir
->gotplt_refcount
= eind
->gotplt_refcount
;
6168 eind
->gotplt_refcount
= 0;
6169 #ifdef INCLUDE_SHMEDIA
6170 tmp
= edir
->datalabel_got
.refcount
;
6173 edir
->datalabel_got
.refcount
= eind
->datalabel_got
.refcount
;
6174 eind
->datalabel_got
.refcount
= tmp
;
6177 BFD_ASSERT (eind
->datalabel_got
.refcount
< 1);
6180 if (ind
->root
.type
== bfd_link_hash_indirect
6181 && dir
->got
.refcount
<= 0)
6183 edir
->tls_type
= eind
->tls_type
;
6184 eind
->tls_type
= GOT_UNKNOWN
;
6187 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
6191 sh_elf_optimized_tls_reloc (info
, r_type
, is_local
)
6192 struct bfd_link_info
*info
;
6201 case R_SH_TLS_GD_32
:
6202 case R_SH_TLS_IE_32
:
6204 return R_SH_TLS_LE_32
;
6205 return R_SH_TLS_IE_32
;
6206 case R_SH_TLS_LD_32
:
6207 return R_SH_TLS_LE_32
;
6213 /* Look through the relocs for a section during the first phase.
6214 Since we don't do .gots or .plts, we just need to consider the
6215 virtual table relocs for gc. */
6218 sh_elf_check_relocs (abfd
, info
, sec
, relocs
)
6220 struct bfd_link_info
*info
;
6222 const Elf_Internal_Rela
*relocs
;
6224 Elf_Internal_Shdr
*symtab_hdr
;
6225 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
6226 struct elf_sh_link_hash_table
*htab
;
6227 const Elf_Internal_Rela
*rel
;
6228 const Elf_Internal_Rela
*rel_end
;
6230 bfd_vma
*local_got_offsets
;
6234 unsigned int r_type
;
6235 int tls_type
, old_tls_type
;
6241 if (info
->relocateable
)
6244 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6245 sym_hashes
= elf_sym_hashes (abfd
);
6246 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof (Elf32_External_Sym
);
6247 if (!elf_bad_symtab (abfd
))
6248 sym_hashes_end
-= symtab_hdr
->sh_info
;
6250 htab
= sh_elf_hash_table (info
);
6251 dynobj
= htab
->root
.dynobj
;
6252 local_got_offsets
= elf_local_got_offsets (abfd
);
6254 rel_end
= relocs
+ sec
->reloc_count
;
6255 for (rel
= relocs
; rel
< rel_end
; rel
++)
6257 struct elf_link_hash_entry
*h
;
6258 unsigned long r_symndx
;
6259 #ifdef INCLUDE_SHMEDIA
6260 int seen_stt_datalabel
= 0;
6263 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6264 r_type
= ELF32_R_TYPE (rel
->r_info
);
6266 if (r_symndx
< symtab_hdr
->sh_info
)
6270 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6271 #ifdef INCLUDE_SHMEDIA
6272 while (h
->root
.type
== bfd_link_hash_indirect
6273 || h
->root
.type
== bfd_link_hash_warning
)
6275 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
6276 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6281 r_type
= sh_elf_optimized_tls_reloc (info
, r_type
, h
== NULL
);
6283 && r_type
== R_SH_TLS_IE_32
6285 && h
->root
.type
!= bfd_link_hash_undefined
6286 && h
->root
.type
!= bfd_link_hash_undefweak
6287 && (h
->dynindx
== -1
6288 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
6289 r_type
= R_SH_TLS_LE_32
;
6291 /* Some relocs require a global offset table. */
6292 if (htab
->sgot
== NULL
)
6300 #ifdef INCLUDE_SHMEDIA
6301 case R_SH_GOTPLT_LOW16
:
6302 case R_SH_GOTPLT_MEDLOW16
:
6303 case R_SH_GOTPLT_MEDHI16
:
6304 case R_SH_GOTPLT_HI16
:
6305 case R_SH_GOTPLT10BY4
:
6306 case R_SH_GOTPLT10BY8
:
6307 case R_SH_GOT_LOW16
:
6308 case R_SH_GOT_MEDLOW16
:
6309 case R_SH_GOT_MEDHI16
:
6313 case R_SH_GOTOFF_LOW16
:
6314 case R_SH_GOTOFF_MEDLOW16
:
6315 case R_SH_GOTOFF_MEDHI16
:
6316 case R_SH_GOTOFF_HI16
:
6317 case R_SH_GOTPC_LOW16
:
6318 case R_SH_GOTPC_MEDLOW16
:
6319 case R_SH_GOTPC_MEDHI16
:
6320 case R_SH_GOTPC_HI16
:
6322 case R_SH_TLS_GD_32
:
6323 case R_SH_TLS_LD_32
:
6324 case R_SH_TLS_IE_32
:
6326 htab
->root
.dynobj
= dynobj
= abfd
;
6327 if (! create_got_section (dynobj
, info
))
6338 /* This relocation describes the C++ object vtable hierarchy.
6339 Reconstruct it for later use during GC. */
6340 case R_SH_GNU_VTINHERIT
:
6341 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6345 /* This relocation describes which C++ vtable entries are actually
6346 used. Record for later use during GC. */
6347 case R_SH_GNU_VTENTRY
:
6348 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6353 case R_SH_TLS_IE_32
:
6355 info
->flags
|= DF_STATIC_TLS
;
6358 case R_SH_TLS_GD_32
:
6360 #ifdef INCLUDE_SHMEDIA
6361 case R_SH_GOT_LOW16
:
6362 case R_SH_GOT_MEDLOW16
:
6363 case R_SH_GOT_MEDHI16
:
6371 tls_type
= GOT_NORMAL
;
6373 case R_SH_TLS_GD_32
:
6374 tls_type
= GOT_TLS_GD
;
6376 case R_SH_TLS_IE_32
:
6377 tls_type
= GOT_TLS_IE
;
6383 #ifdef INCLUDE_SHMEDIA
6384 if (seen_stt_datalabel
)
6386 struct elf_sh_link_hash_entry
*eh
6387 = (struct elf_sh_link_hash_entry
*) h
;
6389 eh
->datalabel_got
.refcount
+= 1;
6393 h
->got
.refcount
+= 1;
6394 old_tls_type
= sh_elf_hash_entry (h
)->tls_type
;
6398 bfd_signed_vma
*local_got_refcounts
;
6400 /* This is a global offset table entry for a local
6402 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6403 if (local_got_refcounts
== NULL
)
6407 size
= symtab_hdr
->sh_info
;
6408 size
*= sizeof (bfd_signed_vma
);
6409 #ifdef INCLUDE_SHMEDIA
6410 /* Reserve space for both the datalabel and
6411 codelabel local GOT offsets. */
6414 size
+= symtab_hdr
->sh_info
;
6415 local_got_refcounts
= ((bfd_signed_vma
*)
6416 bfd_zalloc (abfd
, size
));
6417 if (local_got_refcounts
== NULL
)
6419 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
6420 #ifdef INCLUDE_SHMEDIA
6421 /* Take care of both the datalabel and codelabel local
6423 sh_elf_local_got_tls_type (abfd
)
6424 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
6426 sh_elf_local_got_tls_type (abfd
)
6427 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
6430 #ifdef INCLUDE_SHMEDIA
6431 if (rel
->r_addend
& 1)
6432 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] += 1;
6435 local_got_refcounts
[r_symndx
] += 1;
6436 old_tls_type
= sh_elf_local_got_tls_type (abfd
) [r_symndx
];
6439 /* If a TLS symbol is accessed using IE at least once,
6440 there is no point to use dynamic model for it. */
6441 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
6442 && (old_tls_type
!= GOT_TLS_GD
|| tls_type
!= GOT_TLS_IE
))
6444 if (old_tls_type
== GOT_TLS_IE
&& tls_type
== GOT_TLS_GD
)
6445 tls_type
= GOT_TLS_IE
;
6448 (*_bfd_error_handler
)
6449 (_("%s: `%s' accessed both as normal and thread local symbol"),
6450 bfd_archive_filename (abfd
), h
->root
.root
.string
);
6455 if (old_tls_type
!= tls_type
)
6458 sh_elf_hash_entry (h
)->tls_type
= tls_type
;
6460 sh_elf_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
6465 case R_SH_TLS_LD_32
:
6466 sh_elf_hash_table(info
)->tls_ldm_got
.refcount
+= 1;
6470 #ifdef INCLUDE_SHMEDIA
6471 case R_SH_GOTPLT_LOW16
:
6472 case R_SH_GOTPLT_MEDLOW16
:
6473 case R_SH_GOTPLT_MEDHI16
:
6474 case R_SH_GOTPLT_HI16
:
6475 case R_SH_GOTPLT10BY4
:
6476 case R_SH_GOTPLT10BY8
:
6478 /* If this is a local symbol, we resolve it directly without
6479 creating a procedure linkage table entry. */
6482 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
6485 || h
->dynindx
== -1)
6488 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6489 h
->plt
.refcount
+= 1;
6490 ((struct elf_sh_link_hash_entry
*) h
)->gotplt_refcount
+= 1;
6495 #ifdef INCLUDE_SHMEDIA
6496 case R_SH_PLT_LOW16
:
6497 case R_SH_PLT_MEDLOW16
:
6498 case R_SH_PLT_MEDHI16
:
6501 /* This symbol requires a procedure linkage table entry. We
6502 actually build the entry in adjust_dynamic_symbol,
6503 because this might be a case of linking PIC code which is
6504 never referenced by a dynamic object, in which case we
6505 don't need to generate a procedure linkage table entry
6508 /* If this is a local symbol, we resolve it directly without
6509 creating a procedure linkage table entry. */
6513 if (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
6516 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6517 h
->plt
.refcount
+= 1;
6522 if (h
!= NULL
&& ! info
->shared
)
6524 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
6525 h
->plt
.refcount
+= 1;
6528 /* If we are creating a shared library, and this is a reloc
6529 against a global symbol, or a non PC relative reloc
6530 against a local symbol, then we need to copy the reloc
6531 into the shared library. However, if we are linking with
6532 -Bsymbolic, we do not need to copy a reloc against a
6533 global symbol which is defined in an object we are
6534 including in the link (i.e., DEF_REGULAR is set). At
6535 this point we have not seen all the input files, so it is
6536 possible that DEF_REGULAR is not set now but will be set
6537 later (it is never cleared). We account for that
6538 possibility below by storing information in the
6539 dyn_relocs field of the hash table entry. A similar
6540 situation occurs when creating shared libraries and symbol
6541 visibility changes render the symbol local.
6543 If on the other hand, we are creating an executable, we
6544 may need to keep relocations for symbols satisfied by a
6545 dynamic library if we manage to avoid copy relocs for the
6548 && (sec
->flags
& SEC_ALLOC
) != 0
6549 && (r_type
!= R_SH_REL32
6551 && (! info
->symbolic
6552 || h
->root
.type
== bfd_link_hash_defweak
6553 || (h
->elf_link_hash_flags
6554 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
6556 && (sec
->flags
& SEC_ALLOC
) != 0
6558 && (h
->root
.type
== bfd_link_hash_defweak
6559 || (h
->elf_link_hash_flags
6560 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
6562 struct elf_sh_dyn_relocs
*p
;
6563 struct elf_sh_dyn_relocs
**head
;
6566 htab
->root
.dynobj
= dynobj
= abfd
;
6568 /* When creating a shared object, we must copy these
6569 reloc types into the output file. We create a reloc
6570 section in dynobj and make room for this reloc. */
6575 name
= (bfd_elf_string_from_elf_section
6577 elf_elfheader (abfd
)->e_shstrndx
,
6578 elf_section_data (sec
)->rel_hdr
.sh_name
));
6582 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
6583 && strcmp (bfd_get_section_name (abfd
, sec
),
6586 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6591 sreloc
= bfd_make_section (dynobj
, name
);
6592 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
6593 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
6594 if ((sec
->flags
& SEC_ALLOC
) != 0)
6595 flags
|= SEC_ALLOC
| SEC_LOAD
;
6597 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
6598 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
6601 if (sec
->flags
& SEC_READONLY
)
6602 info
->flags
|= DF_TEXTREL
;
6603 elf_section_data (sec
)->sreloc
= sreloc
;
6606 /* If this is a global symbol, we count the number of
6607 relocations we need for this symbol. */
6609 head
= &((struct elf_sh_link_hash_entry
*) h
)->dyn_relocs
;
6614 /* Track dynamic relocs needed for local syms too. */
6615 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
6620 head
= ((struct elf_sh_dyn_relocs
**)
6621 &elf_section_data (s
)->local_dynrel
);
6625 if (p
== NULL
|| p
->sec
!= sec
)
6627 bfd_size_type amt
= sizeof (*p
);
6628 p
= ((struct elf_sh_dyn_relocs
*) bfd_alloc (dynobj
, amt
));
6636 p
->tls_tpoff32
= FALSE
;
6640 if (r_type
== R_SH_REL32
)
6646 case R_SH_TLS_LE_32
:
6649 (*_bfd_error_handler
) (_("%s: TLS local exec code cannot be linked into shared objects"),
6650 bfd_archive_filename (abfd
));
6654 if (ELF32_R_TYPE (rel
->r_info
) == R_SH_TLS_LD_32
)
6658 case R_SH_TLS_LDO_32
:
6659 /* We make a R_SH_TLS_TPOFF32 relocation. Count it as a
6663 struct elf_sh_dyn_relocs
*p
;
6664 struct elf_sh_dyn_relocs
**head
;
6667 htab
->root
.dynobj
= dynobj
= abfd
;
6673 name
= (bfd_elf_string_from_elf_section
6675 elf_elfheader (abfd
)->e_shstrndx
,
6676 elf_section_data (sec
)->rel_hdr
.sh_name
));
6680 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
6681 && strcmp (bfd_get_section_name (abfd
, sec
),
6684 sreloc
= bfd_get_section_by_name (dynobj
, name
);
6689 sreloc
= bfd_make_section (dynobj
, name
);
6690 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
6691 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
6692 if ((sec
->flags
& SEC_ALLOC
) != 0)
6693 flags
|= SEC_ALLOC
| SEC_LOAD
;
6695 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
6696 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
6699 elf_section_data (sec
)->sreloc
= sreloc
;
6700 if (sec
->flags
& SEC_READONLY
)
6701 info
->flags
|= DF_TEXTREL
;
6704 /* If this is a global symbol, we count the number of
6705 relocations we need for this symbol. */
6707 head
= &((struct elf_sh_link_hash_entry
*) h
)->dyn_relocs
;
6712 /* Track dynamic relocs needed for local syms too. */
6713 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
6718 head
= ((struct elf_sh_dyn_relocs
**)
6719 &elf_section_data (s
)->local_dynrel
);
6723 if (p
== NULL
|| p
->sec
!= sec
)
6725 bfd_size_type amt
= sizeof (*p
);
6726 p
= ((struct elf_sh_dyn_relocs
*) bfd_alloc (dynobj
, amt
));
6734 p
->tls_tpoff32
= FALSE
;
6738 p
->tls_tpoff32
= TRUE
;
6750 #ifndef sh_elf_set_mach_from_flags
6752 sh_elf_set_mach_from_flags (abfd
)
6755 flagword flags
= elf_elfheader (abfd
)->e_flags
;
6757 switch (flags
& EF_SH_MACH_MASK
)
6760 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh
);
6763 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh2
);
6766 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh2e
);
6769 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh_dsp
);
6772 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3
);
6775 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3_dsp
);
6778 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3e
);
6782 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh4
);
6789 #endif /* not sh_elf_set_mach_from_flags */
6791 #ifndef sh_elf_set_private_flags
6792 /* Function to keep SH specific file flags. */
6795 sh_elf_set_private_flags (abfd
, flags
)
6799 BFD_ASSERT (! elf_flags_init (abfd
)
6800 || elf_elfheader (abfd
)->e_flags
== flags
);
6802 elf_elfheader (abfd
)->e_flags
= flags
;
6803 elf_flags_init (abfd
) = TRUE
;
6804 return sh_elf_set_mach_from_flags (abfd
);
6806 #endif /* not sh_elf_set_private_flags */
6808 #ifndef sh_elf_copy_private_data
6809 /* Copy backend specific data from one object module to another */
6812 sh_elf_copy_private_data (ibfd
, obfd
)
6816 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6817 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6820 return sh_elf_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
6822 #endif /* not sh_elf_copy_private_data */
6824 #ifndef sh_elf_merge_private_data
6825 /* This routine checks for linking big and little endian objects
6826 together, and for linking sh-dsp with sh3e / sh4 objects. */
6829 sh_elf_merge_private_data (ibfd
, obfd
)
6833 flagword old_flags
, new_flags
;
6835 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
6838 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6839 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6842 if (! elf_flags_init (obfd
))
6844 /* This happens when ld starts out with a 'blank' output file. */
6845 elf_flags_init (obfd
) = TRUE
;
6846 elf_elfheader (obfd
)->e_flags
= EF_SH1
;
6848 old_flags
= elf_elfheader (obfd
)->e_flags
;
6849 new_flags
= elf_elfheader (ibfd
)->e_flags
;
6850 if ((EF_SH_HAS_DSP (old_flags
) && EF_SH_HAS_FP (new_flags
))
6851 || (EF_SH_HAS_DSP (new_flags
) && EF_SH_HAS_FP (old_flags
)))
6853 (*_bfd_error_handler
)
6854 ("%s: uses %s instructions while previous modules use %s instructions",
6855 bfd_archive_filename (ibfd
),
6856 EF_SH_HAS_DSP (new_flags
) ? "dsp" : "floating point",
6857 EF_SH_HAS_DSP (new_flags
) ? "floating point" : "dsp");
6858 bfd_set_error (bfd_error_bad_value
);
6861 elf_elfheader (obfd
)->e_flags
= EF_SH_MERGE_MACH (old_flags
, new_flags
);
6863 return sh_elf_set_mach_from_flags (obfd
);
6865 #endif /* not sh_elf_merge_private_data */
6867 /* Override the generic function because we need to store sh_elf_obj_tdata
6868 as the specific tdata. We set also the machine architecture from flags
6872 sh_elf_object_p (abfd
)
6875 struct sh_elf_obj_tdata
*new_tdata
;
6876 bfd_size_type amt
= sizeof (struct sh_elf_obj_tdata
);
6878 if (!sh_elf_set_mach_from_flags (abfd
))
6881 /* Allocate our special target data. */
6882 new_tdata
= bfd_zalloc (abfd
, amt
);
6883 if (new_tdata
== NULL
)
6885 new_tdata
->root
= *abfd
->tdata
.elf_obj_data
;
6886 abfd
->tdata
.any
= new_tdata
;
6890 /* Finish up dynamic symbol handling. We set the contents of various
6891 dynamic sections here. */
6894 sh_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
6896 struct bfd_link_info
*info
;
6897 struct elf_link_hash_entry
*h
;
6898 Elf_Internal_Sym
*sym
;
6900 struct elf_sh_link_hash_table
*htab
;
6903 htab
= sh_elf_hash_table (info
);
6904 dynobj
= htab
->root
.dynobj
;
6906 if (h
->plt
.offset
!= (bfd_vma
) -1)
6914 Elf_Internal_Rela rel
;
6917 /* This symbol has an entry in the procedure linkage table. Set
6920 BFD_ASSERT (h
->dynindx
!= -1);
6923 sgot
= htab
->sgotplt
;
6924 srel
= htab
->srelplt
;
6925 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
6927 /* Get the index in the procedure linkage table which
6928 corresponds to this symbol. This is the index of this symbol
6929 in all the symbols for which we are making plt entries. The
6930 first entry in the procedure linkage table is reserved. */
6931 plt_index
= h
->plt
.offset
/ elf_sh_sizeof_plt (info
) - 1;
6933 /* Get the offset into the .got table of the entry that
6934 corresponds to this function. Each .got entry is 4 bytes.
6935 The first three are reserved. */
6936 got_offset
= (plt_index
+ 3) * 4;
6940 got_offset
-= GOT_BIAS
;
6943 /* Fill in the entry in the procedure linkage table. */
6946 if (elf_sh_plt_entry
== NULL
)
6948 elf_sh_plt_entry
= (bfd_big_endian (output_bfd
) ?
6949 elf_sh_plt_entry_be
: elf_sh_plt_entry_le
);
6951 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_plt_entry
,
6952 elf_sh_sizeof_plt (info
));
6953 #ifdef INCLUDE_SHMEDIA
6954 movi_shori_putval (output_bfd
,
6955 (sgot
->output_section
->vma
6956 + sgot
->output_offset
6958 (splt
->contents
+ h
->plt
.offset
6959 + elf_sh_plt_symbol_offset (info
)));
6961 /* Set bottom bit because its for a branch to SHmedia */
6962 movi_shori_putval (output_bfd
,
6963 (splt
->output_section
->vma
+ splt
->output_offset
)
6965 (splt
->contents
+ h
->plt
.offset
6966 + elf_sh_plt_plt0_offset (info
)));
6968 bfd_put_32 (output_bfd
,
6969 (sgot
->output_section
->vma
6970 + sgot
->output_offset
6972 (splt
->contents
+ h
->plt
.offset
6973 + elf_sh_plt_symbol_offset (info
)));
6975 bfd_put_32 (output_bfd
,
6976 (splt
->output_section
->vma
+ splt
->output_offset
),
6977 (splt
->contents
+ h
->plt
.offset
6978 + elf_sh_plt_plt0_offset (info
)));
6983 if (elf_sh_pic_plt_entry
== NULL
)
6985 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
6986 elf_sh_pic_plt_entry_be
:
6987 elf_sh_pic_plt_entry_le
);
6989 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_pic_plt_entry
,
6990 elf_sh_sizeof_plt (info
));
6991 #ifdef INCLUDE_SHMEDIA
6992 movi_shori_putval (output_bfd
, got_offset
,
6993 (splt
->contents
+ h
->plt
.offset
6994 + elf_sh_plt_symbol_offset (info
)));
6996 bfd_put_32 (output_bfd
, got_offset
,
6997 (splt
->contents
+ h
->plt
.offset
6998 + elf_sh_plt_symbol_offset (info
)));
7004 got_offset
+= GOT_BIAS
;
7007 #ifdef INCLUDE_SHMEDIA
7008 movi_shori_putval (output_bfd
,
7009 plt_index
* sizeof (Elf32_External_Rela
),
7010 (splt
->contents
+ h
->plt
.offset
7011 + elf_sh_plt_reloc_offset (info
)));
7013 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
7014 (splt
->contents
+ h
->plt
.offset
7015 + elf_sh_plt_reloc_offset (info
)));
7018 /* Fill in the entry in the global offset table. */
7019 bfd_put_32 (output_bfd
,
7020 (splt
->output_section
->vma
7021 + splt
->output_offset
7023 + elf_sh_plt_temp_offset (info
)),
7024 sgot
->contents
+ got_offset
);
7026 /* Fill in the entry in the .rela.plt section. */
7027 rel
.r_offset
= (sgot
->output_section
->vma
7028 + sgot
->output_offset
7030 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_JMP_SLOT
);
7033 rel
.r_addend
= GOT_BIAS
;
7035 loc
= srel
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
7036 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7038 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
7040 /* Mark the symbol as undefined, rather than as defined in
7041 the .plt section. Leave the value alone. */
7042 sym
->st_shndx
= SHN_UNDEF
;
7046 if (h
->got
.offset
!= (bfd_vma
) -1
7047 && sh_elf_hash_entry (h
)->tls_type
!= GOT_TLS_GD
7048 && sh_elf_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
7052 Elf_Internal_Rela rel
;
7055 /* This symbol has an entry in the global offset table. Set it
7059 srel
= htab
->srelgot
;
7060 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
7062 rel
.r_offset
= (sgot
->output_section
->vma
7063 + sgot
->output_offset
7064 + (h
->got
.offset
&~ (bfd_vma
) 1));
7066 /* If this is a static link, or it is a -Bsymbolic link and the
7067 symbol is defined locally or was forced to be local because
7068 of a version file, we just want to emit a RELATIVE reloc.
7069 The entry in the global offset table will already have been
7070 initialized in the relocate_section function. */
7074 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
7075 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
7077 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
7078 rel
.r_addend
= (h
->root
.u
.def
.value
7079 + h
->root
.u
.def
.section
->output_section
->vma
7080 + h
->root
.u
.def
.section
->output_offset
);
7084 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
7085 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
7089 loc
= srel
->contents
;
7090 loc
+= srel
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7091 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7094 #ifdef INCLUDE_SHMEDIA
7096 struct elf_sh_link_hash_entry
*eh
;
7098 eh
= (struct elf_sh_link_hash_entry
*) h
;
7099 if (eh
->datalabel_got
.offset
!= (bfd_vma
) -1)
7103 Elf_Internal_Rela rel
;
7106 /* This symbol has a datalabel entry in the global offset table.
7110 srel
= htab
->srelgot
;
7111 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
7113 rel
.r_offset
= (sgot
->output_section
->vma
7114 + sgot
->output_offset
7115 + (eh
->datalabel_got
.offset
&~ (bfd_vma
) 1));
7117 /* If this is a static link, or it is a -Bsymbolic link and the
7118 symbol is defined locally or was forced to be local because
7119 of a version file, we just want to emit a RELATIVE reloc.
7120 The entry in the global offset table will already have been
7121 initialized in the relocate_section function. */
7125 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
7126 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
7128 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
7129 rel
.r_addend
= (h
->root
.u
.def
.value
7130 + h
->root
.u
.def
.section
->output_section
->vma
7131 + h
->root
.u
.def
.section
->output_offset
);
7135 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
7136 + eh
->datalabel_got
.offset
);
7137 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
7141 loc
= srel
->contents
;
7142 loc
+= srel
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7143 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7148 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
7151 Elf_Internal_Rela rel
;
7154 /* This symbol needs a copy reloc. Set it up. */
7156 BFD_ASSERT (h
->dynindx
!= -1
7157 && (h
->root
.type
== bfd_link_hash_defined
7158 || h
->root
.type
== bfd_link_hash_defweak
));
7160 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
7162 BFD_ASSERT (s
!= NULL
);
7164 rel
.r_offset
= (h
->root
.u
.def
.value
7165 + h
->root
.u
.def
.section
->output_section
->vma
7166 + h
->root
.u
.def
.section
->output_offset
);
7167 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_COPY
);
7169 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7170 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7173 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7174 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
7175 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
7176 sym
->st_shndx
= SHN_ABS
;
7181 /* Finish up the dynamic sections. */
7184 sh_elf_finish_dynamic_sections (output_bfd
, info
)
7186 struct bfd_link_info
*info
;
7188 struct elf_sh_link_hash_table
*htab
;
7193 htab
= sh_elf_hash_table (info
);
7194 dynobj
= htab
->root
.dynobj
;
7196 sgot
= htab
->sgotplt
;
7197 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
7199 if (htab
->root
.dynamic_sections_created
)
7202 Elf32_External_Dyn
*dyncon
, *dynconend
;
7204 BFD_ASSERT (sgot
!= NULL
&& sdyn
!= NULL
);
7206 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7207 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7208 for (; dyncon
< dynconend
; dyncon
++)
7210 Elf_Internal_Dyn dyn
;
7212 #ifdef INCLUDE_SHMEDIA
7216 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
7223 #ifdef INCLUDE_SHMEDIA
7225 name
= info
->init_function
;
7229 name
= info
->fini_function
;
7231 if (dyn
.d_un
.d_val
!= 0)
7233 struct elf_link_hash_entry
*h
;
7235 h
= elf_link_hash_lookup (&htab
->root
, name
,
7236 FALSE
, FALSE
, TRUE
);
7237 if (h
!= NULL
&& (h
->other
& STO_SH5_ISA32
))
7239 dyn
.d_un
.d_val
|= 1;
7240 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7247 s
= htab
->sgot
->output_section
;
7251 s
= htab
->srelplt
->output_section
;
7253 BFD_ASSERT (s
!= NULL
);
7254 dyn
.d_un
.d_ptr
= s
->vma
;
7255 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7259 s
= htab
->srelplt
->output_section
;
7260 BFD_ASSERT (s
!= NULL
);
7261 if (s
->_cooked_size
!= 0)
7262 dyn
.d_un
.d_val
= s
->_cooked_size
;
7264 dyn
.d_un
.d_val
= s
->_raw_size
;
7265 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7269 /* My reading of the SVR4 ABI indicates that the
7270 procedure linkage table relocs (DT_JMPREL) should be
7271 included in the overall relocs (DT_RELA). This is
7272 what Solaris does. However, UnixWare can not handle
7273 that case. Therefore, we override the DT_RELASZ entry
7274 here to make it not include the JMPREL relocs. Since
7275 the linker script arranges for .rela.plt to follow all
7276 other relocation sections, we don't have to worry
7277 about changing the DT_RELA entry. */
7278 if (htab
->srelplt
!= NULL
)
7280 s
= htab
->srelplt
->output_section
;
7281 if (s
->_cooked_size
!= 0)
7282 dyn
.d_un
.d_val
-= s
->_cooked_size
;
7284 dyn
.d_un
.d_val
-= s
->_raw_size
;
7286 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7291 /* Fill in the first entry in the procedure linkage table. */
7293 if (splt
&& splt
->_raw_size
> 0)
7297 if (elf_sh_pic_plt_entry
== NULL
)
7299 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
7300 elf_sh_pic_plt_entry_be
:
7301 elf_sh_pic_plt_entry_le
);
7303 memcpy (splt
->contents
, elf_sh_pic_plt_entry
,
7304 elf_sh_sizeof_plt (info
));
7308 if (elf_sh_plt0_entry
== NULL
)
7310 elf_sh_plt0_entry
= (bfd_big_endian (output_bfd
) ?
7311 elf_sh_plt0_entry_be
:
7312 elf_sh_plt0_entry_le
);
7314 memcpy (splt
->contents
, elf_sh_plt0_entry
, PLT_ENTRY_SIZE
);
7315 #ifdef INCLUDE_SHMEDIA
7316 movi_shori_putval (output_bfd
,
7317 sgot
->output_section
->vma
7318 + sgot
->output_offset
,
7320 + elf_sh_plt0_gotplt_offset (info
));
7322 bfd_put_32 (output_bfd
,
7323 sgot
->output_section
->vma
+ sgot
->output_offset
+ 4,
7324 splt
->contents
+ elf_sh_plt0_gotid_offset (info
));
7325 bfd_put_32 (output_bfd
,
7326 sgot
->output_section
->vma
+ sgot
->output_offset
+ 8,
7327 splt
->contents
+ elf_sh_plt0_linker_offset (info
));
7331 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7332 really seem like the right value. */
7333 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
7337 /* Fill in the first three entries in the global offset table. */
7338 if (sgot
&& sgot
->_raw_size
> 0)
7341 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7343 bfd_put_32 (output_bfd
,
7344 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
7346 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
7347 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
7349 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7355 static enum elf_reloc_type_class
7356 sh_elf_reloc_type_class (rela
)
7357 const Elf_Internal_Rela
*rela
;
7359 switch ((int) ELF32_R_TYPE (rela
->r_info
))
7362 return reloc_class_relative
;
7364 return reloc_class_plt
;
7366 return reloc_class_copy
;
7368 return reloc_class_normal
;
7372 /* Support for Linux core dump NOTE sections. */
7374 elf32_shlin_grok_prstatus (abfd
, note
)
7376 Elf_Internal_Note
*note
;
7379 unsigned int raw_size
;
7381 switch (note
->descsz
)
7386 case 168: /* Linux/SH */
7388 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
7391 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
7400 /* Make a ".reg/999" section. */
7401 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
7402 raw_size
, note
->descpos
+ offset
);
7406 elf32_shlin_grok_psinfo (abfd
, note
)
7408 Elf_Internal_Note
*note
;
7410 switch (note
->descsz
)
7415 case 124: /* Linux/SH elf_prpsinfo */
7416 elf_tdata (abfd
)->core_program
7417 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
7418 elf_tdata (abfd
)->core_command
7419 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
7422 /* Note that for some reason, a spurious space is tacked
7423 onto the end of the args in some (at least one anyway)
7424 implementations, so strip it off if it exists. */
7427 char *command
= elf_tdata (abfd
)->core_command
;
7428 int n
= strlen (command
);
7430 if (0 < n
&& command
[n
- 1] == ' ')
7431 command
[n
- 1] = '\0';
7437 #define TARGET_BIG_SYM bfd_elf32_sh_vec
7438 #define TARGET_BIG_NAME "elf32-sh"
7439 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
7440 #define TARGET_LITTLE_NAME "elf32-shl"
7441 #define ELF_ARCH bfd_arch_sh
7442 #define ELF_MACHINE_CODE EM_SH
7443 #define ELF_MAXPAGESIZE 128
7445 #define elf_symbol_leading_char '_'
7447 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7448 #define elf_info_to_howto sh_elf_info_to_howto
7449 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
7450 #define elf_backend_relocate_section sh_elf_relocate_section
7451 #define bfd_elf32_bfd_get_relocated_section_contents \
7452 sh_elf_get_relocated_section_contents
7453 #define bfd_elf32_mkobject sh_elf_mkobject
7454 #define elf_backend_object_p sh_elf_object_p
7455 #define bfd_elf32_bfd_set_private_bfd_flags \
7456 sh_elf_set_private_flags
7457 #define bfd_elf32_bfd_copy_private_bfd_data \
7458 sh_elf_copy_private_data
7459 #define bfd_elf32_bfd_merge_private_bfd_data \
7460 sh_elf_merge_private_data
7462 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
7463 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
7464 #define elf_backend_check_relocs sh_elf_check_relocs
7465 #define elf_backend_copy_indirect_symbol \
7466 sh_elf_copy_indirect_symbol
7467 #define elf_backend_create_dynamic_sections \
7468 sh_elf_create_dynamic_sections
7469 #define bfd_elf32_bfd_link_hash_table_create \
7470 sh_elf_link_hash_table_create
7471 #define elf_backend_adjust_dynamic_symbol \
7472 sh_elf_adjust_dynamic_symbol
7473 #define elf_backend_size_dynamic_sections \
7474 sh_elf_size_dynamic_sections
7475 #define elf_backend_finish_dynamic_symbol \
7476 sh_elf_finish_dynamic_symbol
7477 #define elf_backend_finish_dynamic_sections \
7478 sh_elf_finish_dynamic_sections
7479 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
7481 #define elf_backend_can_gc_sections 1
7482 #define elf_backend_can_refcount 1
7483 #define elf_backend_want_got_plt 1
7484 #define elf_backend_plt_readonly 1
7485 #define elf_backend_want_plt_sym 0
7486 #define elf_backend_got_header_size 12
7487 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
7489 #ifndef INCLUDE_SHMEDIA
7491 #include "elf32-target.h"
7493 /* NetBSD support. */
7494 #undef TARGET_BIG_SYM
7495 #define TARGET_BIG_SYM bfd_elf32_shnbsd_vec
7496 #undef TARGET_BIG_NAME
7497 #define TARGET_BIG_NAME "elf32-sh-nbsd"
7498 #undef TARGET_LITTLE_SYM
7499 #define TARGET_LITTLE_SYM bfd_elf32_shlnbsd_vec
7500 #undef TARGET_LITTLE_NAME
7501 #define TARGET_LITTLE_NAME "elf32-shl-nbsd"
7502 #undef ELF_MAXPAGESIZE
7503 #define ELF_MAXPAGESIZE 0x10000
7504 #undef elf_symbol_leading_char
7505 #define elf_symbol_leading_char 0
7507 #define elf32_bed elf32_sh_nbsd_bed
7509 #include "elf32-target.h"
7512 /* Linux support. */
7513 #undef TARGET_BIG_SYM
7514 #define TARGET_BIG_SYM bfd_elf32_shblin_vec
7515 #undef TARGET_BIG_NAME
7516 #define TARGET_BIG_NAME "elf32-shbig-linux"
7517 #undef TARGET_LITTLE_SYM
7518 #define TARGET_LITTLE_SYM bfd_elf32_shlin_vec
7519 #undef TARGET_LITTLE_NAME
7520 #define TARGET_LITTLE_NAME "elf32-sh-linux"
7522 #undef elf_backend_grok_prstatus
7523 #define elf_backend_grok_prstatus elf32_shlin_grok_prstatus
7524 #undef elf_backend_grok_psinfo
7525 #define elf_backend_grok_psinfo elf32_shlin_grok_psinfo
7527 #define elf32_bed elf32_sh_lin_bed
7529 #include "elf32-target.h"
7531 #endif /* INCLUDE_SHMEDIA */