1 /* Hitachi SH specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Ian Lance Taylor, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 static bfd_reloc_status_type sh_elf_reloc
30 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
31 static bfd_reloc_status_type sh_elf_ignore_reloc
32 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
33 static reloc_howto_type
*sh_elf_reloc_type_lookup
34 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
35 static void sh_elf_info_to_howto
36 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
37 static boolean sh_elf_set_private_flags
38 PARAMS ((bfd
*, flagword
));
39 static boolean sh_elf_copy_private_data
40 PARAMS ((bfd
*, bfd
*));
41 static boolean sh_elf_merge_private_data
42 PARAMS ((bfd
*, bfd
*));
43 static boolean sh_elf_set_mach_from_flags
45 static boolean sh_elf_relax_section
46 PARAMS ((bfd
*, asection
*, struct bfd_link_info
*, boolean
*));
47 static boolean sh_elf_relax_delete_bytes
48 PARAMS ((bfd
*, asection
*, bfd_vma
, int));
49 static boolean sh_elf_align_loads
50 PARAMS ((bfd
*, asection
*, Elf_Internal_Rela
*, bfd_byte
*, boolean
*));
51 static boolean sh_elf_swap_insns
52 PARAMS ((bfd
*, asection
*, PTR
, bfd_byte
*, bfd_vma
));
53 static boolean sh_elf_relocate_section
54 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
55 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
56 static bfd_byte
*sh_elf_get_relocated_section_contents
57 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
58 bfd_byte
*, boolean
, asymbol
**));
59 static boolean sh_elf_check_relocs
60 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
61 const Elf_Internal_Rela
*));
62 static struct bfd_hash_entry
*sh_elf_link_hash_newfunc
63 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
64 static struct bfd_link_hash_table
*sh_elf_link_hash_table_create
66 static boolean sh_elf_adjust_dynamic_symbol
67 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
68 static boolean sh_elf_size_dynamic_sections
69 PARAMS ((bfd
*, struct bfd_link_info
*));
70 static boolean sh_elf_finish_dynamic_symbol
71 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
73 static boolean sh_elf_finish_dynamic_sections
74 PARAMS ((bfd
*, struct bfd_link_info
*));
75 static bfd_reloc_status_type sh_elf_reloc_loop
76 PARAMS ((int, bfd
*, asection
*, bfd_byte
*, bfd_vma
, asection
*,
78 static boolean sh_elf_create_dynamic_sections
79 PARAMS ((bfd
*, struct bfd_link_info
*));
80 static asection
* sh_elf_gc_mark_hook
81 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
82 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
83 static boolean sh_elf_gc_sweep_hook
84 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
85 const Elf_Internal_Rela
*));
86 static enum elf_reloc_type_class sh_elf_reloc_type_class
87 PARAMS ((const Elf_Internal_Rela
*));
88 #ifdef INCLUDE_SHMEDIA
89 inline static void movi_shori_putval
PARAMS ((bfd
*, unsigned long, char *));
92 /* The name of the dynamic interpreter. This is put in the .interp
95 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
97 static reloc_howto_type sh_elf_howto_table
[] =
100 HOWTO (R_SH_NONE
, /* type */
102 0, /* size (0 = byte, 1 = short, 2 = long) */
104 false, /* pc_relative */
106 complain_overflow_dont
, /* complain_on_overflow */
107 sh_elf_ignore_reloc
, /* special_function */
108 "R_SH_NONE", /* name */
109 false, /* partial_inplace */
112 false), /* pcrel_offset */
114 /* 32 bit absolute relocation. Setting partial_inplace to true and
115 src_mask to a non-zero value is similar to the COFF toolchain. */
116 HOWTO (R_SH_DIR32
, /* type */
118 2, /* size (0 = byte, 1 = short, 2 = long) */
120 false, /* pc_relative */
122 complain_overflow_bitfield
, /* complain_on_overflow */
123 sh_elf_reloc
, /* special_function */
124 "R_SH_DIR32", /* name */
125 true, /* partial_inplace */
126 0xffffffff, /* src_mask */
127 0xffffffff, /* dst_mask */
128 false), /* pcrel_offset */
130 /* 32 bit PC relative relocation. */
131 HOWTO (R_SH_REL32
, /* type */
133 2, /* size (0 = byte, 1 = short, 2 = long) */
135 true, /* pc_relative */
137 complain_overflow_signed
, /* complain_on_overflow */
138 sh_elf_ignore_reloc
, /* special_function */
139 "R_SH_REL32", /* name */
140 true, /* partial_inplace */
141 0xffffffff, /* src_mask */
142 0xffffffff, /* dst_mask */
143 true), /* pcrel_offset */
145 /* 8 bit PC relative branch divided by 2. */
146 HOWTO (R_SH_DIR8WPN
, /* type */
148 1, /* size (0 = byte, 1 = short, 2 = long) */
150 true, /* pc_relative */
152 complain_overflow_signed
, /* complain_on_overflow */
153 sh_elf_ignore_reloc
, /* special_function */
154 "R_SH_DIR8WPN", /* name */
155 true, /* partial_inplace */
158 true), /* pcrel_offset */
160 /* 12 bit PC relative branch divided by 2. */
161 HOWTO (R_SH_IND12W
, /* type */
163 1, /* size (0 = byte, 1 = short, 2 = long) */
165 true, /* pc_relative */
167 complain_overflow_signed
, /* complain_on_overflow */
168 sh_elf_reloc
, /* special_function */
169 "R_SH_IND12W", /* name */
170 true, /* partial_inplace */
171 0xfff, /* src_mask */
172 0xfff, /* dst_mask */
173 true), /* pcrel_offset */
175 /* 8 bit unsigned PC relative divided by 4. */
176 HOWTO (R_SH_DIR8WPL
, /* type */
178 1, /* size (0 = byte, 1 = short, 2 = long) */
180 true, /* pc_relative */
182 complain_overflow_unsigned
, /* complain_on_overflow */
183 sh_elf_ignore_reloc
, /* special_function */
184 "R_SH_DIR8WPL", /* name */
185 true, /* partial_inplace */
188 true), /* pcrel_offset */
190 /* 8 bit unsigned PC relative divided by 2. */
191 HOWTO (R_SH_DIR8WPZ
, /* type */
193 1, /* size (0 = byte, 1 = short, 2 = long) */
195 true, /* pc_relative */
197 complain_overflow_unsigned
, /* complain_on_overflow */
198 sh_elf_ignore_reloc
, /* special_function */
199 "R_SH_DIR8WPZ", /* name */
200 true, /* partial_inplace */
203 true), /* pcrel_offset */
205 /* 8 bit GBR relative. FIXME: This only makes sense if we have some
206 special symbol for the GBR relative area, and that is not
208 HOWTO (R_SH_DIR8BP
, /* type */
210 1, /* size (0 = byte, 1 = short, 2 = long) */
212 false, /* pc_relative */
214 complain_overflow_unsigned
, /* complain_on_overflow */
215 sh_elf_ignore_reloc
, /* special_function */
216 "R_SH_DIR8BP", /* name */
217 false, /* partial_inplace */
220 true), /* pcrel_offset */
222 /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if
223 we have some special symbol for the GBR relative area, and that
224 is not implemented. */
225 HOWTO (R_SH_DIR8W
, /* type */
227 1, /* size (0 = byte, 1 = short, 2 = long) */
229 false, /* pc_relative */
231 complain_overflow_unsigned
, /* complain_on_overflow */
232 sh_elf_ignore_reloc
, /* special_function */
233 "R_SH_DIR8W", /* name */
234 false, /* partial_inplace */
237 true), /* pcrel_offset */
239 /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if
240 we have some special symbol for the GBR relative area, and that
241 is not implemented. */
242 HOWTO (R_SH_DIR8L
, /* type */
244 1, /* size (0 = byte, 1 = short, 2 = long) */
246 false, /* pc_relative */
248 complain_overflow_unsigned
, /* complain_on_overflow */
249 sh_elf_ignore_reloc
, /* special_function */
250 "R_SH_DIR8L", /* name */
251 false, /* partial_inplace */
254 true), /* pcrel_offset */
272 /* The remaining relocs are a GNU extension used for relaxing. The
273 final pass of the linker never needs to do anything with any of
274 these relocs. Any required operations are handled by the
277 /* A 16 bit switch table entry. This is generated for an expression
278 such as ``.word L1 - L2''. The offset holds the difference
279 between the reloc address and L2. */
280 HOWTO (R_SH_SWITCH16
, /* type */
282 1, /* size (0 = byte, 1 = short, 2 = long) */
284 false, /* pc_relative */
286 complain_overflow_unsigned
, /* complain_on_overflow */
287 sh_elf_ignore_reloc
, /* special_function */
288 "R_SH_SWITCH16", /* name */
289 false, /* partial_inplace */
292 true), /* pcrel_offset */
294 /* A 32 bit switch table entry. This is generated for an expression
295 such as ``.long L1 - L2''. The offset holds the difference
296 between the reloc address and L2. */
297 HOWTO (R_SH_SWITCH32
, /* type */
299 2, /* size (0 = byte, 1 = short, 2 = long) */
301 false, /* pc_relative */
303 complain_overflow_unsigned
, /* complain_on_overflow */
304 sh_elf_ignore_reloc
, /* special_function */
305 "R_SH_SWITCH32", /* name */
306 false, /* partial_inplace */
309 true), /* pcrel_offset */
311 /* Indicates a .uses pseudo-op. The compiler will generate .uses
312 pseudo-ops when it finds a function call which can be relaxed.
313 The offset field holds the PC relative offset to the instruction
314 which loads the register used in the function call. */
315 HOWTO (R_SH_USES
, /* type */
317 1, /* size (0 = byte, 1 = short, 2 = long) */
319 false, /* pc_relative */
321 complain_overflow_unsigned
, /* complain_on_overflow */
322 sh_elf_ignore_reloc
, /* special_function */
323 "R_SH_USES", /* name */
324 false, /* partial_inplace */
327 true), /* pcrel_offset */
329 /* The assembler will generate this reloc for addresses referred to
330 by the register loads associated with USES relocs. The offset
331 field holds the number of times the address is referenced in the
333 HOWTO (R_SH_COUNT
, /* type */
335 1, /* size (0 = byte, 1 = short, 2 = long) */
337 false, /* pc_relative */
339 complain_overflow_unsigned
, /* complain_on_overflow */
340 sh_elf_ignore_reloc
, /* special_function */
341 "R_SH_COUNT", /* name */
342 false, /* partial_inplace */
345 true), /* pcrel_offset */
347 /* Indicates an alignment statement. The offset field is the power
348 of 2 to which subsequent portions of the object file must be
350 HOWTO (R_SH_ALIGN
, /* type */
352 1, /* size (0 = byte, 1 = short, 2 = long) */
354 false, /* pc_relative */
356 complain_overflow_unsigned
, /* complain_on_overflow */
357 sh_elf_ignore_reloc
, /* special_function */
358 "R_SH_ALIGN", /* name */
359 false, /* partial_inplace */
362 true), /* pcrel_offset */
364 /* The assembler will generate this reloc before a block of
365 instructions. A section should be processed as assumining it
366 contains data, unless this reloc is seen. */
367 HOWTO (R_SH_CODE
, /* type */
369 1, /* size (0 = byte, 1 = short, 2 = long) */
371 false, /* pc_relative */
373 complain_overflow_unsigned
, /* complain_on_overflow */
374 sh_elf_ignore_reloc
, /* special_function */
375 "R_SH_CODE", /* name */
376 false, /* partial_inplace */
379 true), /* pcrel_offset */
381 /* The assembler will generate this reloc after a block of
382 instructions when it sees data that is not instructions. */
383 HOWTO (R_SH_DATA
, /* type */
385 1, /* size (0 = byte, 1 = short, 2 = long) */
387 false, /* pc_relative */
389 complain_overflow_unsigned
, /* complain_on_overflow */
390 sh_elf_ignore_reloc
, /* special_function */
391 "R_SH_DATA", /* name */
392 false, /* partial_inplace */
395 true), /* pcrel_offset */
397 /* The assembler generates this reloc for each label within a block
398 of instructions. This permits the linker to avoid swapping
399 instructions which are the targets of branches. */
400 HOWTO (R_SH_LABEL
, /* type */
402 1, /* size (0 = byte, 1 = short, 2 = long) */
404 false, /* pc_relative */
406 complain_overflow_unsigned
, /* complain_on_overflow */
407 sh_elf_ignore_reloc
, /* special_function */
408 "R_SH_LABEL", /* name */
409 false, /* partial_inplace */
412 true), /* pcrel_offset */
414 /* An 8 bit switch table entry. This is generated for an expression
415 such as ``.word L1 - L2''. The offset holds the difference
416 between the reloc address and L2. */
417 HOWTO (R_SH_SWITCH8
, /* type */
419 0, /* size (0 = byte, 1 = short, 2 = long) */
421 false, /* pc_relative */
423 complain_overflow_unsigned
, /* complain_on_overflow */
424 sh_elf_ignore_reloc
, /* special_function */
425 "R_SH_SWITCH8", /* name */
426 false, /* partial_inplace */
429 true), /* pcrel_offset */
431 /* GNU extension to record C++ vtable hierarchy */
432 HOWTO (R_SH_GNU_VTINHERIT
, /* type */
434 2, /* size (0 = byte, 1 = short, 2 = long) */
436 false, /* pc_relative */
438 complain_overflow_dont
, /* complain_on_overflow */
439 NULL
, /* special_function */
440 "R_SH_GNU_VTINHERIT", /* name */
441 false, /* partial_inplace */
444 false), /* pcrel_offset */
446 /* GNU extension to record C++ vtable member usage */
447 HOWTO (R_SH_GNU_VTENTRY
, /* type */
449 2, /* size (0 = byte, 1 = short, 2 = long) */
451 false, /* pc_relative */
453 complain_overflow_dont
, /* complain_on_overflow */
454 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
455 "R_SH_GNU_VTENTRY", /* name */
456 false, /* partial_inplace */
459 false), /* pcrel_offset */
461 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
462 HOWTO (R_SH_LOOP_START
, /* type */
464 1, /* size (0 = byte, 1 = short, 2 = long) */
466 false, /* pc_relative */
468 complain_overflow_signed
, /* complain_on_overflow */
469 sh_elf_ignore_reloc
, /* special_function */
470 "R_SH_LOOP_START", /* name */
471 true, /* partial_inplace */
474 true), /* pcrel_offset */
476 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
477 HOWTO (R_SH_LOOP_END
, /* type */
479 1, /* size (0 = byte, 1 = short, 2 = long) */
481 false, /* pc_relative */
483 complain_overflow_signed
, /* complain_on_overflow */
484 sh_elf_ignore_reloc
, /* special_function */
485 "R_SH_LOOP_END", /* name */
486 true, /* partial_inplace */
489 true), /* pcrel_offset */
499 #ifdef INCLUDE_SHMEDIA
500 /* Used in SHLLI.L and SHLRI.L. */
501 HOWTO (R_SH_DIR5U
, /* type */
503 2, /* size (0 = byte, 1 = short, 2 = long) */
505 false, /* pc_relative */
507 complain_overflow_unsigned
, /* complain_on_overflow */
508 bfd_elf_generic_reloc
, /* special_function */
509 "R_SH_DIR5U", /* name */
510 false, /* partial_inplace */
512 0xfc00, /* dst_mask */
513 false), /* pcrel_offset */
515 /* Used in SHARI, SHLLI et al. */
516 HOWTO (R_SH_DIR6U
, /* type */
518 2, /* size (0 = byte, 1 = short, 2 = long) */
520 false, /* pc_relative */
522 complain_overflow_unsigned
, /* complain_on_overflow */
523 bfd_elf_generic_reloc
, /* special_function */
524 "R_SH_DIR6U", /* name */
525 false, /* partial_inplace */
527 0xfc00, /* dst_mask */
528 false), /* pcrel_offset */
530 /* Used in BxxI, LDHI.L et al. */
531 HOWTO (R_SH_DIR6S
, /* type */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
535 false, /* pc_relative */
537 complain_overflow_signed
, /* complain_on_overflow */
538 bfd_elf_generic_reloc
, /* special_function */
539 "R_SH_DIR6S", /* name */
540 false, /* partial_inplace */
542 0xfc00, /* dst_mask */
543 false), /* pcrel_offset */
545 /* Used in ADDI, ANDI et al. */
546 HOWTO (R_SH_DIR10S
, /* type */
548 2, /* size (0 = byte, 1 = short, 2 = long) */
550 false, /* pc_relative */
552 complain_overflow_signed
, /* complain_on_overflow */
553 bfd_elf_generic_reloc
, /* special_function */
554 "R_SH_DIR10S", /* name */
555 false, /* partial_inplace */
557 0xffc00, /* dst_mask */
558 false), /* pcrel_offset */
560 /* Used in LD.UW, ST.W et al. */
561 HOWTO (R_SH_DIR10SW
, /* type */
563 2, /* size (0 = byte, 1 = short, 2 = long) */
565 false, /* pc_relative */
567 complain_overflow_signed
, /* complain_on_overflow */
568 bfd_elf_generic_reloc
, /* special_function */
569 "R_SH_DIR10SW", /* name */
570 false, /* partial_inplace */
572 0xffc00, /* dst_mask */
573 false), /* pcrel_offset */
575 /* Used in LD.L, FLD.S et al. */
576 HOWTO (R_SH_DIR10SL
, /* type */
578 2, /* size (0 = byte, 1 = short, 2 = long) */
580 false, /* pc_relative */
582 complain_overflow_signed
, /* complain_on_overflow */
583 bfd_elf_generic_reloc
, /* special_function */
584 "R_SH_DIR10SL", /* name */
585 false, /* partial_inplace */
587 0xffc00, /* dst_mask */
588 false), /* pcrel_offset */
590 /* Used in FLD.D, FST.P et al. */
591 HOWTO (R_SH_DIR10SQ
, /* type */
593 2, /* size (0 = byte, 1 = short, 2 = long) */
595 false, /* pc_relative */
597 complain_overflow_signed
, /* complain_on_overflow */
598 bfd_elf_generic_reloc
, /* special_function */
599 "R_SH_DIR10SQ", /* name */
600 false, /* partial_inplace */
602 0xffc00, /* dst_mask */
603 false), /* pcrel_offset */
724 HOWTO (R_SH_GOT32
, /* type */
726 2, /* size (0 = byte, 1 = short, 2 = long) */
728 false, /* pc_relative */
730 complain_overflow_bitfield
, /* complain_on_overflow */
731 bfd_elf_generic_reloc
, /* */
732 "R_SH_GOT32", /* name */
733 true, /* partial_inplace */
734 0xffffffff, /* src_mask */
735 0xffffffff, /* dst_mask */
736 false), /* pcrel_offset */
738 HOWTO (R_SH_PLT32
, /* type */
740 2, /* size (0 = byte, 1 = short, 2 = long) */
742 true, /* pc_relative */
744 complain_overflow_bitfield
, /* complain_on_overflow */
745 bfd_elf_generic_reloc
, /* */
746 "R_SH_PLT32", /* name */
747 true, /* partial_inplace */
748 0xffffffff, /* src_mask */
749 0xffffffff, /* dst_mask */
750 true), /* pcrel_offset */
752 HOWTO (R_SH_COPY
, /* type */
754 2, /* size (0 = byte, 1 = short, 2 = long) */
756 false, /* pc_relative */
758 complain_overflow_bitfield
, /* complain_on_overflow */
759 bfd_elf_generic_reloc
, /* */
760 "R_SH_COPY", /* name */
761 true, /* partial_inplace */
762 0xffffffff, /* src_mask */
763 0xffffffff, /* dst_mask */
764 false), /* pcrel_offset */
766 HOWTO (R_SH_GLOB_DAT
, /* type */
768 2, /* size (0 = byte, 1 = short, 2 = long) */
770 false, /* pc_relative */
772 complain_overflow_bitfield
, /* complain_on_overflow */
773 bfd_elf_generic_reloc
, /* */
774 "R_SH_GLOB_DAT", /* name */
775 true, /* partial_inplace */
776 0xffffffff, /* src_mask */
777 0xffffffff, /* dst_mask */
778 false), /* pcrel_offset */
780 HOWTO (R_SH_JMP_SLOT
, /* type */
782 2, /* size (0 = byte, 1 = short, 2 = long) */
784 false, /* pc_relative */
786 complain_overflow_bitfield
, /* complain_on_overflow */
787 bfd_elf_generic_reloc
, /* */
788 "R_SH_JMP_SLOT", /* name */
789 true, /* partial_inplace */
790 0xffffffff, /* src_mask */
791 0xffffffff, /* dst_mask */
792 false), /* pcrel_offset */
794 HOWTO (R_SH_RELATIVE
, /* type */
796 2, /* size (0 = byte, 1 = short, 2 = long) */
798 false, /* pc_relative */
800 complain_overflow_bitfield
, /* complain_on_overflow */
801 bfd_elf_generic_reloc
, /* */
802 "R_SH_RELATIVE", /* name */
803 true, /* partial_inplace */
804 0xffffffff, /* src_mask */
805 0xffffffff, /* dst_mask */
806 false), /* pcrel_offset */
808 HOWTO (R_SH_GOTOFF
, /* type */
810 2, /* size (0 = byte, 1 = short, 2 = long) */
812 false, /* pc_relative */
814 complain_overflow_bitfield
, /* complain_on_overflow */
815 bfd_elf_generic_reloc
, /* */
816 "R_SH_GOTOFF", /* name */
817 true, /* partial_inplace */
818 0xffffffff, /* src_mask */
819 0xffffffff, /* dst_mask */
820 false), /* pcrel_offset */
822 HOWTO (R_SH_GOTPC
, /* type */
824 2, /* size (0 = byte, 1 = short, 2 = long) */
826 true, /* pc_relative */
828 complain_overflow_bitfield
, /* complain_on_overflow */
829 bfd_elf_generic_reloc
, /* */
830 "R_SH_GOTPC", /* name */
831 true, /* partial_inplace */
832 0xffffffff, /* src_mask */
833 0xffffffff, /* dst_mask */
834 true), /* pcrel_offset */
836 HOWTO (R_SH_GOTPLT32
, /* type */
838 2, /* size (0 = byte, 1 = short, 2 = long) */
840 false, /* pc_relative */
842 complain_overflow_bitfield
, /* complain_on_overflow */
843 bfd_elf_generic_reloc
, /* */
844 "R_SH_GOTPLT32", /* name */
845 false, /* partial_inplace */
846 0xffffffff, /* src_mask */
847 0xffffffff, /* dst_mask */
848 false), /* pcrel_offset */
850 #ifdef INCLUDE_SHMEDIA
851 /* Used in MOVI and SHORI (x & 65536). */
852 HOWTO (R_SH_GOT_LOW16
, /* type */
854 2, /* size (0 = byte, 1 = short, 2 = long) */
856 false, /* pc_relative */
858 complain_overflow_dont
, /* complain_on_overflow */
859 bfd_elf_generic_reloc
, /* special_function */
860 "R_SH_GOT_LOW16", /* name */
861 false, /* partial_inplace */
863 0x3fffc00, /* dst_mask */
864 false), /* pcrel_offset */
866 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
867 HOWTO (R_SH_GOT_MEDLOW16
, /* type */
869 2, /* size (0 = byte, 1 = short, 2 = long) */
871 false, /* pc_relative */
873 complain_overflow_dont
, /* complain_on_overflow */
874 bfd_elf_generic_reloc
, /* special_function */
875 "R_SH_GOT_MEDLOW16", /* name */
876 false, /* partial_inplace */
878 0x3fffc00, /* dst_mask */
879 false), /* pcrel_offset */
881 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
882 HOWTO (R_SH_GOT_MEDHI16
, /* type */
884 2, /* size (0 = byte, 1 = short, 2 = long) */
886 false, /* pc_relative */
888 complain_overflow_dont
, /* complain_on_overflow */
889 bfd_elf_generic_reloc
, /* special_function */
890 "R_SH_GOT_MEDHI16", /* name */
891 false, /* partial_inplace */
893 0x3fffc00, /* dst_mask */
894 false), /* pcrel_offset */
896 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
897 HOWTO (R_SH_GOT_HI16
, /* type */
899 2, /* size (0 = byte, 1 = short, 2 = long) */
901 false, /* pc_relative */
903 complain_overflow_dont
, /* complain_on_overflow */
904 bfd_elf_generic_reloc
, /* special_function */
905 "R_SH_GOT_HI16", /* name */
906 false, /* partial_inplace */
908 0x3fffc00, /* dst_mask */
909 false), /* pcrel_offset */
911 /* Used in MOVI and SHORI (x & 65536). */
912 HOWTO (R_SH_GOTPLT_LOW16
, /* type */
914 2, /* size (0 = byte, 1 = short, 2 = long) */
916 false, /* pc_relative */
918 complain_overflow_dont
, /* complain_on_overflow */
919 bfd_elf_generic_reloc
, /* special_function */
920 "R_SH_GOTPLT_LOW16", /* name */
921 false, /* partial_inplace */
923 0x3fffc00, /* dst_mask */
924 false), /* pcrel_offset */
926 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
927 HOWTO (R_SH_GOTPLT_MEDLOW16
, /* type */
929 2, /* size (0 = byte, 1 = short, 2 = long) */
931 false, /* pc_relative */
933 complain_overflow_dont
, /* complain_on_overflow */
934 bfd_elf_generic_reloc
, /* special_function */
935 "R_SH_GOTPLT_MEDLOW16", /* name */
936 false, /* partial_inplace */
938 0x3fffc00, /* dst_mask */
939 false), /* pcrel_offset */
941 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
942 HOWTO (R_SH_GOTPLT_MEDHI16
, /* type */
944 2, /* size (0 = byte, 1 = short, 2 = long) */
946 false, /* pc_relative */
948 complain_overflow_dont
, /* complain_on_overflow */
949 bfd_elf_generic_reloc
, /* special_function */
950 "R_SH_GOTPLT_MEDHI16", /* name */
951 false, /* partial_inplace */
953 0x3fffc00, /* dst_mask */
954 false), /* pcrel_offset */
956 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
957 HOWTO (R_SH_GOTPLT_HI16
, /* type */
959 2, /* size (0 = byte, 1 = short, 2 = long) */
961 false, /* pc_relative */
963 complain_overflow_dont
, /* complain_on_overflow */
964 bfd_elf_generic_reloc
, /* special_function */
965 "R_SH_GOTPLT_HI16", /* name */
966 false, /* partial_inplace */
968 0x3fffc00, /* dst_mask */
969 false), /* pcrel_offset */
971 /* Used in MOVI and SHORI (x & 65536). */
972 HOWTO (R_SH_PLT_LOW16
, /* type */
974 2, /* size (0 = byte, 1 = short, 2 = long) */
976 true, /* pc_relative */
978 complain_overflow_dont
, /* complain_on_overflow */
979 bfd_elf_generic_reloc
, /* special_function */
980 "R_SH_PLT_LOW16", /* name */
981 false, /* partial_inplace */
983 0x3fffc00, /* dst_mask */
984 true), /* pcrel_offset */
986 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
987 HOWTO (R_SH_PLT_MEDLOW16
, /* type */
989 2, /* size (0 = byte, 1 = short, 2 = long) */
991 true, /* pc_relative */
993 complain_overflow_dont
, /* complain_on_overflow */
994 bfd_elf_generic_reloc
, /* special_function */
995 "R_SH_PLT_MEDLOW16", /* name */
996 false, /* partial_inplace */
998 0x3fffc00, /* dst_mask */
999 true), /* pcrel_offset */
1001 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1002 HOWTO (R_SH_PLT_MEDHI16
, /* type */
1003 32, /* rightshift */
1004 2, /* size (0 = byte, 1 = short, 2 = long) */
1006 true, /* pc_relative */
1008 complain_overflow_dont
, /* complain_on_overflow */
1009 bfd_elf_generic_reloc
, /* special_function */
1010 "R_SH_PLT_MEDHI16", /* name */
1011 false, /* partial_inplace */
1013 0x3fffc00, /* dst_mask */
1014 true), /* pcrel_offset */
1016 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1017 HOWTO (R_SH_PLT_HI16
, /* type */
1018 48, /* rightshift */
1019 2, /* size (0 = byte, 1 = short, 2 = long) */
1021 true, /* pc_relative */
1023 complain_overflow_dont
, /* complain_on_overflow */
1024 bfd_elf_generic_reloc
, /* special_function */
1025 "R_SH_PLT_HI16", /* name */
1026 false, /* partial_inplace */
1028 0x3fffc00, /* dst_mask */
1029 true), /* pcrel_offset */
1031 /* Used in MOVI and SHORI (x & 65536). */
1032 HOWTO (R_SH_GOTOFF_LOW16
, /* type */
1034 2, /* size (0 = byte, 1 = short, 2 = long) */
1036 false, /* pc_relative */
1038 complain_overflow_dont
, /* complain_on_overflow */
1039 bfd_elf_generic_reloc
, /* special_function */
1040 "R_SH_GOTOFF_LOW16", /* name */
1041 false, /* partial_inplace */
1043 0x3fffc00, /* dst_mask */
1044 false), /* pcrel_offset */
1046 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1047 HOWTO (R_SH_GOTOFF_MEDLOW16
, /* type */
1048 16, /* rightshift */
1049 2, /* size (0 = byte, 1 = short, 2 = long) */
1051 false, /* pc_relative */
1053 complain_overflow_dont
, /* complain_on_overflow */
1054 bfd_elf_generic_reloc
, /* special_function */
1055 "R_SH_GOTOFF_MEDLOW16", /* name */
1056 false, /* partial_inplace */
1058 0x3fffc00, /* dst_mask */
1059 false), /* pcrel_offset */
1061 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1062 HOWTO (R_SH_GOTOFF_MEDHI16
, /* type */
1063 32, /* rightshift */
1064 2, /* size (0 = byte, 1 = short, 2 = long) */
1066 false, /* pc_relative */
1068 complain_overflow_dont
, /* complain_on_overflow */
1069 bfd_elf_generic_reloc
, /* special_function */
1070 "R_SH_GOTOFF_MEDHI16", /* name */
1071 false, /* partial_inplace */
1073 0x3fffc00, /* dst_mask */
1074 false), /* pcrel_offset */
1076 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1077 HOWTO (R_SH_GOTOFF_HI16
, /* type */
1078 48, /* rightshift */
1079 2, /* size (0 = byte, 1 = short, 2 = long) */
1081 false, /* pc_relative */
1083 complain_overflow_dont
, /* complain_on_overflow */
1084 bfd_elf_generic_reloc
, /* special_function */
1085 "R_SH_GOTOFF_HI16", /* name */
1086 false, /* partial_inplace */
1088 0x3fffc00, /* dst_mask */
1089 false), /* pcrel_offset */
1091 /* Used in MOVI and SHORI (x & 65536). */
1092 HOWTO (R_SH_GOTPC_LOW16
, /* type */
1094 2, /* size (0 = byte, 1 = short, 2 = long) */
1096 true, /* pc_relative */
1098 complain_overflow_dont
, /* complain_on_overflow */
1099 bfd_elf_generic_reloc
, /* special_function */
1100 "R_SH_GOTPC_LOW16", /* name */
1101 false, /* partial_inplace */
1103 0x3fffc00, /* dst_mask */
1104 true), /* pcrel_offset */
1106 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1107 HOWTO (R_SH_GOTPC_MEDLOW16
, /* type */
1108 16, /* rightshift */
1109 2, /* size (0 = byte, 1 = short, 2 = long) */
1111 true, /* pc_relative */
1113 complain_overflow_dont
, /* complain_on_overflow */
1114 bfd_elf_generic_reloc
, /* special_function */
1115 "R_SH_GOTPC_MEDLOW16", /* name */
1116 false, /* partial_inplace */
1118 0x3fffc00, /* dst_mask */
1119 true), /* pcrel_offset */
1121 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1122 HOWTO (R_SH_GOTPC_MEDHI16
, /* type */
1123 32, /* rightshift */
1124 2, /* size (0 = byte, 1 = short, 2 = long) */
1126 true, /* pc_relative */
1128 complain_overflow_dont
, /* complain_on_overflow */
1129 bfd_elf_generic_reloc
, /* special_function */
1130 "R_SH_GOTPC_MEDHI16", /* name */
1131 false, /* partial_inplace */
1133 0x3fffc00, /* dst_mask */
1134 true), /* pcrel_offset */
1136 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1137 HOWTO (R_SH_GOTPC_HI16
, /* type */
1138 48, /* rightshift */
1139 2, /* size (0 = byte, 1 = short, 2 = long) */
1141 true, /* pc_relative */
1143 complain_overflow_dont
, /* complain_on_overflow */
1144 bfd_elf_generic_reloc
, /* special_function */
1145 "R_SH_GOTPC_HI16", /* name */
1146 false, /* partial_inplace */
1148 0x3fffc00, /* dst_mask */
1149 true), /* pcrel_offset */
1151 /* Used in LD.L, FLD.S et al. */
1152 HOWTO (R_SH_GOT10BY4
, /* type */
1154 2, /* size (0 = byte, 1 = short, 2 = long) */
1156 false, /* pc_relative */
1158 complain_overflow_signed
, /* complain_on_overflow */
1159 bfd_elf_generic_reloc
, /* special_function */
1160 "R_SH_GOT10BY4", /* name */
1161 false, /* partial_inplace */
1163 0xffc00, /* dst_mask */
1164 false), /* pcrel_offset */
1166 /* Used in LD.L, FLD.S et al. */
1167 HOWTO (R_SH_GOTPLT10BY4
, /* type */
1169 2, /* size (0 = byte, 1 = short, 2 = long) */
1171 false, /* pc_relative */
1173 complain_overflow_signed
, /* complain_on_overflow */
1174 bfd_elf_generic_reloc
, /* special_function */
1175 "R_SH_GOTPLT10BY4", /* name */
1176 false, /* partial_inplace */
1178 0xffc00, /* dst_mask */
1179 false), /* pcrel_offset */
1181 /* Used in FLD.D, FST.P et al. */
1182 HOWTO (R_SH_GOT10BY8
, /* type */
1184 2, /* size (0 = byte, 1 = short, 2 = long) */
1186 false, /* pc_relative */
1188 complain_overflow_signed
, /* complain_on_overflow */
1189 bfd_elf_generic_reloc
, /* special_function */
1190 "R_SH_GOT10BY8", /* name */
1191 false, /* partial_inplace */
1193 0xffc00, /* dst_mask */
1194 false), /* pcrel_offset */
1196 /* Used in FLD.D, FST.P et al. */
1197 HOWTO (R_SH_GOTPLT10BY8
, /* type */
1199 2, /* size (0 = byte, 1 = short, 2 = long) */
1201 false, /* pc_relative */
1203 complain_overflow_signed
, /* complain_on_overflow */
1204 bfd_elf_generic_reloc
, /* special_function */
1205 "R_SH_GOTPLT10BY8", /* name */
1206 false, /* partial_inplace */
1208 0xffc00, /* dst_mask */
1209 false), /* pcrel_offset */
1211 HOWTO (R_SH_COPY64
, /* type */
1213 4, /* size (0 = byte, 1 = short, 2 = long) */
1215 false, /* pc_relative */
1217 complain_overflow_dont
, /* complain_on_overflow */
1218 bfd_elf_generic_reloc
, /* special_function */
1219 "R_SH_COPY64", /* name */
1220 false, /* partial_inplace */
1222 ((bfd_vma
) 0) - 1, /* dst_mask */
1223 false), /* pcrel_offset */
1225 HOWTO (R_SH_GLOB_DAT64
, /* type */
1227 4, /* size (0 = byte, 1 = short, 2 = long) */
1229 false, /* pc_relative */
1231 complain_overflow_dont
, /* complain_on_overflow */
1232 bfd_elf_generic_reloc
, /* special_function */
1233 "R_SH_GLOB_DAT64", /* name */
1234 false, /* partial_inplace */
1236 ((bfd_vma
) 0) - 1, /* dst_mask */
1237 false), /* pcrel_offset */
1239 HOWTO (R_SH_JMP_SLOT64
, /* type */
1241 4, /* size (0 = byte, 1 = short, 2 = long) */
1243 false, /* pc_relative */
1245 complain_overflow_dont
, /* complain_on_overflow */
1246 bfd_elf_generic_reloc
, /* special_function */
1247 "R_SH_JMP_SLOT64", /* name */
1248 false, /* partial_inplace */
1250 ((bfd_vma
) 0) - 1, /* dst_mask */
1251 false), /* pcrel_offset */
1253 HOWTO (R_SH_RELATIVE64
, /* type */
1255 4, /* size (0 = byte, 1 = short, 2 = long) */
1257 false, /* pc_relative */
1259 complain_overflow_dont
, /* complain_on_overflow */
1260 bfd_elf_generic_reloc
, /* special_function */
1261 "R_SH_RELATIVE64", /* name */
1262 false, /* partial_inplace */
1264 ((bfd_vma
) 0) - 1, /* dst_mask */
1265 false), /* pcrel_offset */
1313 /* Relocations for SHmedia code. None of these are partial_inplace or
1314 use the field being relocated (except R_SH_PT_16). */
1316 /* The assembler will generate this reloc before a block of SHmedia
1317 instructions. A section should be processed as assuming it contains
1318 data, unless this reloc is seen. Note that a block of SHcompact
1319 instructions are instead preceded by R_SH_CODE.
1320 This is currently not implemented, but should be used for SHmedia
1321 linker relaxation. */
1322 HOWTO (R_SH_SHMEDIA_CODE
, /* type */
1324 1, /* size (0 = byte, 1 = short, 2 = long) */
1326 false, /* pc_relative */
1328 complain_overflow_unsigned
, /* complain_on_overflow */
1329 sh_elf_ignore_reloc
, /* special_function */
1330 "R_SH_SHMEDIA_CODE", /* name */
1331 false, /* partial_inplace */
1334 false), /* pcrel_offset */
1336 /* The assembler will generate this reloc at a PTA or PTB instruction,
1337 and the linker checks the right type of target, or changes a PTA to a
1338 PTB, if the original insn was PT. */
1339 HOWTO (R_SH_PT_16
, /* type */
1341 2, /* size (0 = byte, 1 = short, 2 = long) */
1343 true, /* pc_relative */
1345 complain_overflow_signed
, /* complain_on_overflow */
1346 bfd_elf_generic_reloc
, /* special_function */
1347 "R_SH_PT_16", /* name */
1348 false, /* partial_inplace */
1350 0x3fffc00, /* dst_mask */
1351 true), /* pcrel_offset */
1353 /* Used in unexpanded MOVI. */
1354 HOWTO (R_SH_IMMS16
, /* type */
1356 2, /* size (0 = byte, 1 = short, 2 = long) */
1358 false, /* pc_relative */
1360 complain_overflow_signed
, /* complain_on_overflow */
1361 bfd_elf_generic_reloc
, /* special_function */
1362 "R_SH_IMMS16", /* name */
1363 false, /* partial_inplace */
1365 0x3fffc00, /* dst_mask */
1366 false), /* pcrel_offset */
1368 /* Used in SHORI. */
1369 HOWTO (R_SH_IMMU16
, /* type */
1371 2, /* size (0 = byte, 1 = short, 2 = long) */
1373 false, /* pc_relative */
1375 complain_overflow_unsigned
, /* complain_on_overflow */
1376 bfd_elf_generic_reloc
, /* special_function */
1377 "R_SH_IMMU16", /* name */
1378 false, /* partial_inplace */
1380 0x3fffc00, /* dst_mask */
1381 false), /* pcrel_offset */
1383 /* Used in MOVI and SHORI (x & 65536). */
1384 HOWTO (R_SH_IMM_LOW16
, /* type */
1386 2, /* size (0 = byte, 1 = short, 2 = long) */
1388 false, /* pc_relative */
1390 complain_overflow_dont
, /* complain_on_overflow */
1391 bfd_elf_generic_reloc
, /* special_function */
1392 "R_SH_IMM_LOW16", /* name */
1393 false, /* partial_inplace */
1395 0x3fffc00, /* dst_mask */
1396 false), /* pcrel_offset */
1398 /* Used in MOVI and SHORI ((x - $) & 65536). */
1399 HOWTO (R_SH_IMM_LOW16_PCREL
, /* type */
1401 2, /* size (0 = byte, 1 = short, 2 = long) */
1403 true, /* pc_relative */
1405 complain_overflow_dont
, /* complain_on_overflow */
1406 bfd_elf_generic_reloc
, /* special_function */
1407 "R_SH_IMM_LOW16_PCREL", /* name */
1408 false, /* partial_inplace */
1410 0x3fffc00, /* dst_mask */
1411 true), /* pcrel_offset */
1413 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1414 HOWTO (R_SH_IMM_MEDLOW16
, /* type */
1415 16, /* rightshift */
1416 2, /* size (0 = byte, 1 = short, 2 = long) */
1418 false, /* pc_relative */
1420 complain_overflow_dont
, /* complain_on_overflow */
1421 bfd_elf_generic_reloc
, /* special_function */
1422 "R_SH_IMM_MEDLOW16", /* name */
1423 false, /* partial_inplace */
1425 0x3fffc00, /* dst_mask */
1426 false), /* pcrel_offset */
1428 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1429 HOWTO (R_SH_IMM_MEDLOW16_PCREL
, /* type */
1430 16, /* rightshift */
1431 2, /* size (0 = byte, 1 = short, 2 = long) */
1433 true, /* pc_relative */
1435 complain_overflow_dont
, /* complain_on_overflow */
1436 bfd_elf_generic_reloc
, /* special_function */
1437 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1438 false, /* partial_inplace */
1440 0x3fffc00, /* dst_mask */
1441 true), /* pcrel_offset */
1443 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1444 HOWTO (R_SH_IMM_MEDHI16
, /* type */
1445 32, /* rightshift */
1446 2, /* size (0 = byte, 1 = short, 2 = long) */
1448 false, /* pc_relative */
1450 complain_overflow_dont
, /* complain_on_overflow */
1451 bfd_elf_generic_reloc
, /* special_function */
1452 "R_SH_IMM_MEDHI16", /* name */
1453 false, /* partial_inplace */
1455 0x3fffc00, /* dst_mask */
1456 false), /* pcrel_offset */
1458 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1459 HOWTO (R_SH_IMM_MEDHI16_PCREL
, /* type */
1460 32, /* rightshift */
1461 2, /* size (0 = byte, 1 = short, 2 = long) */
1463 true, /* pc_relative */
1465 complain_overflow_dont
, /* complain_on_overflow */
1466 bfd_elf_generic_reloc
, /* special_function */
1467 "R_SH_IMM_MEDHI16_PCREL", /* name */
1468 false, /* partial_inplace */
1470 0x3fffc00, /* dst_mask */
1471 true), /* pcrel_offset */
1473 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1474 HOWTO (R_SH_IMM_HI16
, /* type */
1475 48, /* rightshift */
1476 2, /* size (0 = byte, 1 = short, 2 = long) */
1478 false, /* pc_relative */
1480 complain_overflow_dont
, /* complain_on_overflow */
1481 bfd_elf_generic_reloc
, /* special_function */
1482 "R_SH_IMM_HI16", /* name */
1483 false, /* partial_inplace */
1485 0x3fffc00, /* dst_mask */
1486 false), /* pcrel_offset */
1488 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1489 HOWTO (R_SH_IMM_HI16_PCREL
, /* type */
1490 48, /* rightshift */
1491 2, /* size (0 = byte, 1 = short, 2 = long) */
1493 true, /* pc_relative */
1495 complain_overflow_dont
, /* complain_on_overflow */
1496 bfd_elf_generic_reloc
, /* special_function */
1497 "R_SH_IMM_HI16_PCREL", /* name */
1498 false, /* partial_inplace */
1500 0x3fffc00, /* dst_mask */
1501 true), /* pcrel_offset */
1503 /* For the .uaquad pseudo. */
1504 HOWTO (R_SH_64
, /* type */
1506 4, /* size (0 = byte, 1 = short, 2 = long) */
1508 false, /* pc_relative */
1510 complain_overflow_dont
, /* complain_on_overflow */
1511 bfd_elf_generic_reloc
, /* special_function */
1512 "R_SH_64", /* name */
1513 false, /* partial_inplace */
1515 ((bfd_vma
) 0) - 1, /* dst_mask */
1516 false), /* pcrel_offset */
1518 /* For the .uaquad pseudo, (x - $). */
1519 HOWTO (R_SH_64_PCREL
, /* type */
1520 48, /* rightshift */
1521 2, /* size (0 = byte, 1 = short, 2 = long) */
1523 true, /* pc_relative */
1525 complain_overflow_dont
, /* complain_on_overflow */
1526 bfd_elf_generic_reloc
, /* special_function */
1527 "R_SH_64_PCREL", /* name */
1528 false, /* partial_inplace */
1530 ((bfd_vma
) 0) - 1, /* dst_mask */
1531 true), /* pcrel_offset */
1536 static bfd_reloc_status_type
1537 sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
, addr
,
1538 symbol_section
, start
, end
)
1539 int r_type ATTRIBUTE_UNUSED
;
1541 asection
*input_section
;
1544 asection
*symbol_section
;
1547 static bfd_vma last_addr
;
1548 static asection
*last_symbol_section
;
1549 bfd_byte
*free_contents
= NULL
;
1550 bfd_byte
*start_ptr
, *ptr
, *last_ptr
;
1555 /* Sanity check the address. */
1556 if (addr
> input_section
->_raw_size
)
1557 return bfd_reloc_outofrange
;
1559 /* We require the start and end relocations to be processed consecutively -
1560 although we allow then to be processed forwards or backwards. */
1564 last_symbol_section
= symbol_section
;
1565 return bfd_reloc_ok
;
1567 if (last_addr
!= addr
)
1571 if (! symbol_section
|| last_symbol_section
!= symbol_section
|| end
< start
)
1572 return bfd_reloc_outofrange
;
1574 /* Get the symbol_section contents. */
1575 if (symbol_section
!= input_section
)
1577 if (elf_section_data (symbol_section
)->this_hdr
.contents
!= NULL
)
1578 contents
= elf_section_data (symbol_section
)->this_hdr
.contents
;
1581 contents
= (bfd_byte
*) bfd_malloc (symbol_section
->_raw_size
);
1582 if (contents
== NULL
)
1583 return bfd_reloc_outofrange
;
1584 free_contents
= contents
;
1585 if (! bfd_get_section_contents (input_bfd
, symbol_section
, contents
,
1587 symbol_section
->_raw_size
))
1590 return bfd_reloc_outofrange
;
1594 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
1595 start_ptr
= contents
+ start
;
1596 for (cum_diff
= -6, ptr
= contents
+ end
; cum_diff
< 0 && ptr
> start_ptr
;)
1598 for (last_ptr
= ptr
, ptr
-= 4; ptr
>= start_ptr
&& IS_PPI (ptr
);)
1601 diff
= (last_ptr
- ptr
) >> 1;
1602 cum_diff
+= diff
& 1;
1605 /* Calculate the start / end values to load into rs / re minus four -
1606 so that will cancel out the four we would otherwise have to add to
1607 addr to get the value to subtract in order to get relative addressing. */
1611 end
= (ptr
+ cum_diff
* 2) - contents
;
1615 bfd_vma start0
= start
- 4;
1617 while (start0
&& IS_PPI (contents
+ start0
))
1619 start0
= start
- 2 - ((start
- start0
) & 2);
1620 start
= start0
- cum_diff
- 2;
1625 free (free_contents
);
1627 insn
= bfd_get_16 (input_bfd
, contents
+ addr
);
1629 x
= (insn
& 0x200 ? end
: start
) - addr
;
1630 if (input_section
!= symbol_section
)
1631 x
+= ((symbol_section
->output_section
->vma
+ symbol_section
->output_offset
)
1632 - (input_section
->output_section
->vma
1633 + input_section
->output_offset
));
1635 if (x
< -128 || x
> 127)
1636 return bfd_reloc_overflow
;
1638 x
= (insn
& ~0xff) | (x
& 0xff);
1639 bfd_put_16 (input_bfd
, (bfd_vma
) x
, contents
+ addr
);
1641 return bfd_reloc_ok
;
1644 /* This function is used for normal relocs. This used to be like the COFF
1645 function, and is almost certainly incorrect for other ELF targets. */
1647 static bfd_reloc_status_type
1648 sh_elf_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
1651 arelent
*reloc_entry
;
1654 asection
*input_section
;
1656 char **error_message ATTRIBUTE_UNUSED
;
1660 enum elf_sh_reloc_type r_type
;
1661 bfd_vma addr
= reloc_entry
->address
;
1662 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
1664 r_type
= (enum elf_sh_reloc_type
) reloc_entry
->howto
->type
;
1666 if (output_bfd
!= NULL
)
1668 /* Partial linking--do nothing. */
1669 reloc_entry
->address
+= input_section
->output_offset
;
1670 return bfd_reloc_ok
;
1673 /* Almost all relocs have to do with relaxing. If any work must be
1674 done for them, it has been done in sh_relax_section. */
1675 if (r_type
== R_SH_IND12W
&& (symbol_in
->flags
& BSF_LOCAL
) != 0)
1676 return bfd_reloc_ok
;
1678 if (symbol_in
!= NULL
1679 && bfd_is_und_section (symbol_in
->section
))
1680 return bfd_reloc_undefined
;
1682 if (bfd_is_com_section (symbol_in
->section
))
1685 sym_value
= (symbol_in
->value
+
1686 symbol_in
->section
->output_section
->vma
+
1687 symbol_in
->section
->output_offset
);
1692 insn
= bfd_get_32 (abfd
, hit_data
);
1693 insn
+= sym_value
+ reloc_entry
->addend
;
1694 bfd_put_32 (abfd
, (bfd_vma
) insn
, hit_data
);
1697 insn
= bfd_get_16 (abfd
, hit_data
);
1698 sym_value
+= reloc_entry
->addend
;
1699 sym_value
-= (input_section
->output_section
->vma
1700 + input_section
->output_offset
1703 sym_value
+= (insn
& 0xfff) << 1;
1705 sym_value
-= 0x1000;
1706 insn
= (insn
& 0xf000) | (sym_value
& 0xfff);
1707 bfd_put_16 (abfd
, (bfd_vma
) insn
, hit_data
);
1708 if (sym_value
< (bfd_vma
) -0x1000 || sym_value
>= 0x1000)
1709 return bfd_reloc_overflow
;
1716 return bfd_reloc_ok
;
1719 /* This function is used for relocs which are only used for relaxing,
1720 which the linker should otherwise ignore. */
1722 static bfd_reloc_status_type
1723 sh_elf_ignore_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1724 output_bfd
, error_message
)
1725 bfd
*abfd ATTRIBUTE_UNUSED
;
1726 arelent
*reloc_entry
;
1727 asymbol
*symbol ATTRIBUTE_UNUSED
;
1728 PTR data ATTRIBUTE_UNUSED
;
1729 asection
*input_section
;
1731 char **error_message ATTRIBUTE_UNUSED
;
1733 if (output_bfd
!= NULL
)
1734 reloc_entry
->address
+= input_section
->output_offset
;
1735 return bfd_reloc_ok
;
1738 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
1740 struct elf_reloc_map
1742 bfd_reloc_code_real_type bfd_reloc_val
;
1743 unsigned char elf_reloc_val
;
1746 /* An array mapping BFD reloc codes to SH ELF relocs. */
1748 static const struct elf_reloc_map sh_reloc_map
[] =
1750 { BFD_RELOC_NONE
, R_SH_NONE
},
1751 { BFD_RELOC_32
, R_SH_DIR32
},
1752 { BFD_RELOC_CTOR
, R_SH_DIR32
},
1753 { BFD_RELOC_32_PCREL
, R_SH_REL32
},
1754 { BFD_RELOC_SH_PCDISP8BY2
, R_SH_DIR8WPN
},
1755 { BFD_RELOC_SH_PCDISP12BY2
, R_SH_IND12W
},
1756 { BFD_RELOC_SH_PCRELIMM8BY2
, R_SH_DIR8WPZ
},
1757 { BFD_RELOC_SH_PCRELIMM8BY4
, R_SH_DIR8WPL
},
1758 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
1759 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
1760 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
1761 { BFD_RELOC_SH_USES
, R_SH_USES
},
1762 { BFD_RELOC_SH_COUNT
, R_SH_COUNT
},
1763 { BFD_RELOC_SH_ALIGN
, R_SH_ALIGN
},
1764 { BFD_RELOC_SH_CODE
, R_SH_CODE
},
1765 { BFD_RELOC_SH_DATA
, R_SH_DATA
},
1766 { BFD_RELOC_SH_LABEL
, R_SH_LABEL
},
1767 { BFD_RELOC_VTABLE_INHERIT
, R_SH_GNU_VTINHERIT
},
1768 { BFD_RELOC_VTABLE_ENTRY
, R_SH_GNU_VTENTRY
},
1769 { BFD_RELOC_SH_LOOP_START
, R_SH_LOOP_START
},
1770 { BFD_RELOC_SH_LOOP_END
, R_SH_LOOP_END
},
1771 { BFD_RELOC_32_GOT_PCREL
, R_SH_GOT32
},
1772 { BFD_RELOC_32_PLT_PCREL
, R_SH_PLT32
},
1773 { BFD_RELOC_SH_COPY
, R_SH_COPY
},
1774 { BFD_RELOC_SH_GLOB_DAT
, R_SH_GLOB_DAT
},
1775 { BFD_RELOC_SH_JMP_SLOT
, R_SH_JMP_SLOT
},
1776 { BFD_RELOC_SH_RELATIVE
, R_SH_RELATIVE
},
1777 { BFD_RELOC_32_GOTOFF
, R_SH_GOTOFF
},
1778 { BFD_RELOC_SH_GOTPC
, R_SH_GOTPC
},
1779 { BFD_RELOC_SH_GOTPLT32
, R_SH_GOTPLT32
},
1780 #ifdef INCLUDE_SHMEDIA
1781 { BFD_RELOC_SH_GOT_LOW16
, R_SH_GOT_LOW16
},
1782 { BFD_RELOC_SH_GOT_MEDLOW16
, R_SH_GOT_MEDLOW16
},
1783 { BFD_RELOC_SH_GOT_MEDHI16
, R_SH_GOT_MEDHI16
},
1784 { BFD_RELOC_SH_GOT_HI16
, R_SH_GOT_HI16
},
1785 { BFD_RELOC_SH_GOTPLT_LOW16
, R_SH_GOTPLT_LOW16
},
1786 { BFD_RELOC_SH_GOTPLT_MEDLOW16
, R_SH_GOTPLT_MEDLOW16
},
1787 { BFD_RELOC_SH_GOTPLT_MEDHI16
, R_SH_GOTPLT_MEDHI16
},
1788 { BFD_RELOC_SH_GOTPLT_HI16
, R_SH_GOTPLT_HI16
},
1789 { BFD_RELOC_SH_PLT_LOW16
, R_SH_PLT_LOW16
},
1790 { BFD_RELOC_SH_PLT_MEDLOW16
, R_SH_PLT_MEDLOW16
},
1791 { BFD_RELOC_SH_PLT_MEDHI16
, R_SH_PLT_MEDHI16
},
1792 { BFD_RELOC_SH_PLT_HI16
, R_SH_PLT_HI16
},
1793 { BFD_RELOC_SH_GOTOFF_LOW16
, R_SH_GOTOFF_LOW16
},
1794 { BFD_RELOC_SH_GOTOFF_MEDLOW16
, R_SH_GOTOFF_MEDLOW16
},
1795 { BFD_RELOC_SH_GOTOFF_MEDHI16
, R_SH_GOTOFF_MEDHI16
},
1796 { BFD_RELOC_SH_GOTOFF_HI16
, R_SH_GOTOFF_HI16
},
1797 { BFD_RELOC_SH_GOTPC_LOW16
, R_SH_GOTPC_LOW16
},
1798 { BFD_RELOC_SH_GOTPC_MEDLOW16
, R_SH_GOTPC_MEDLOW16
},
1799 { BFD_RELOC_SH_GOTPC_MEDHI16
, R_SH_GOTPC_MEDHI16
},
1800 { BFD_RELOC_SH_GOTPC_HI16
, R_SH_GOTPC_HI16
},
1801 { BFD_RELOC_SH_COPY64
, R_SH_COPY64
},
1802 { BFD_RELOC_SH_GLOB_DAT64
, R_SH_GLOB_DAT64
},
1803 { BFD_RELOC_SH_JMP_SLOT64
, R_SH_JMP_SLOT64
},
1804 { BFD_RELOC_SH_RELATIVE64
, R_SH_RELATIVE64
},
1805 { BFD_RELOC_SH_GOT10BY4
, R_SH_GOT10BY4
},
1806 { BFD_RELOC_SH_GOT10BY8
, R_SH_GOT10BY8
},
1807 { BFD_RELOC_SH_GOTPLT10BY4
, R_SH_GOTPLT10BY4
},
1808 { BFD_RELOC_SH_GOTPLT10BY8
, R_SH_GOTPLT10BY8
},
1809 { BFD_RELOC_SH_PT_16
, R_SH_PT_16
},
1810 { BFD_RELOC_SH_SHMEDIA_CODE
, R_SH_SHMEDIA_CODE
},
1811 { BFD_RELOC_SH_IMMU5
, R_SH_DIR5U
},
1812 { BFD_RELOC_SH_IMMS6
, R_SH_DIR6S
},
1813 { BFD_RELOC_SH_IMMU6
, R_SH_DIR6U
},
1814 { BFD_RELOC_SH_IMMS10
, R_SH_DIR10S
},
1815 { BFD_RELOC_SH_IMMS10BY2
, R_SH_DIR10SW
},
1816 { BFD_RELOC_SH_IMMS10BY4
, R_SH_DIR10SL
},
1817 { BFD_RELOC_SH_IMMS10BY8
, R_SH_DIR10SQ
},
1818 { BFD_RELOC_SH_IMMS16
, R_SH_IMMS16
},
1819 { BFD_RELOC_SH_IMMU16
, R_SH_IMMU16
},
1820 { BFD_RELOC_SH_IMM_LOW16
, R_SH_IMM_LOW16
},
1821 { BFD_RELOC_SH_IMM_LOW16_PCREL
, R_SH_IMM_LOW16_PCREL
},
1822 { BFD_RELOC_SH_IMM_MEDLOW16
, R_SH_IMM_MEDLOW16
},
1823 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL
, R_SH_IMM_MEDLOW16_PCREL
},
1824 { BFD_RELOC_SH_IMM_MEDHI16
, R_SH_IMM_MEDHI16
},
1825 { BFD_RELOC_SH_IMM_MEDHI16_PCREL
, R_SH_IMM_MEDHI16_PCREL
},
1826 { BFD_RELOC_SH_IMM_HI16
, R_SH_IMM_HI16
},
1827 { BFD_RELOC_SH_IMM_HI16_PCREL
, R_SH_IMM_HI16_PCREL
},
1828 { BFD_RELOC_64
, R_SH_64
},
1829 { BFD_RELOC_64_PCREL
, R_SH_64_PCREL
},
1830 #endif /* not INCLUDE_SHMEDIA */
1833 /* Given a BFD reloc code, return the howto structure for the
1834 corresponding SH ELf reloc. */
1836 static reloc_howto_type
*
1837 sh_elf_reloc_type_lookup (abfd
, code
)
1838 bfd
*abfd ATTRIBUTE_UNUSED
;
1839 bfd_reloc_code_real_type code
;
1843 for (i
= 0; i
< sizeof (sh_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1845 if (sh_reloc_map
[i
].bfd_reloc_val
== code
)
1846 return &sh_elf_howto_table
[(int) sh_reloc_map
[i
].elf_reloc_val
];
1852 /* Given an ELF reloc, fill in the howto field of a relent. */
1855 sh_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1856 bfd
*abfd ATTRIBUTE_UNUSED
;
1858 Elf_Internal_Rela
*dst
;
1862 r
= ELF32_R_TYPE (dst
->r_info
);
1864 BFD_ASSERT (r
< (unsigned int) R_SH_max
);
1865 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC
|| r
> R_SH_LAST_INVALID_RELOC
);
1866 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_2
|| r
> R_SH_LAST_INVALID_RELOC_2
);
1867 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_3
|| r
> R_SH_LAST_INVALID_RELOC_3
);
1868 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_4
|| r
> R_SH_LAST_INVALID_RELOC_4
);
1870 cache_ptr
->howto
= &sh_elf_howto_table
[r
];
1873 /* This function handles relaxing for SH ELF. See the corresponding
1874 function in coff-sh.c for a description of what this does. FIXME:
1875 There is a lot of duplication here between this code and the COFF
1876 specific code. The format of relocs and symbols is wound deeply
1877 into this code, but it would still be better if the duplication
1878 could be eliminated somehow. Note in particular that although both
1879 functions use symbols like R_SH_CODE, those symbols have different
1880 values; in coff-sh.c they come from include/coff/sh.h, whereas here
1881 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
1884 sh_elf_relax_section (abfd
, sec
, link_info
, again
)
1887 struct bfd_link_info
*link_info
;
1890 Elf_Internal_Shdr
*symtab_hdr
;
1891 Elf_Internal_Shdr
*shndx_hdr
;
1892 Elf_Internal_Rela
*internal_relocs
;
1893 Elf_Internal_Rela
*free_relocs
= NULL
;
1895 Elf_Internal_Rela
*irel
, *irelend
;
1896 bfd_byte
*contents
= NULL
;
1897 bfd_byte
*free_contents
= NULL
;
1898 Elf32_External_Sym
*extsyms
= NULL
;
1899 Elf32_External_Sym
*free_extsyms
= NULL
;
1900 Elf_External_Sym_Shndx
*shndx_buf
= NULL
;
1904 if (link_info
->relocateable
1905 || (sec
->flags
& SEC_RELOC
) == 0
1906 || sec
->reloc_count
== 0)
1909 #ifdef INCLUDE_SHMEDIA
1910 if (elf_section_data (sec
)->this_hdr
.sh_flags
1911 & (SHF_SH5_ISA32
| SHF_SH5_ISA32_MIXED
))
1917 /* If this is the first time we have been called for this section,
1918 initialize the cooked size. */
1919 if (sec
->_cooked_size
== 0)
1920 sec
->_cooked_size
= sec
->_raw_size
;
1922 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1923 shndx_hdr
= &elf_tdata (abfd
)->symtab_shndx_hdr
;
1925 internal_relocs
= (_bfd_elf32_link_read_relocs
1926 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
1927 link_info
->keep_memory
));
1928 if (internal_relocs
== NULL
)
1930 if (! link_info
->keep_memory
)
1931 free_relocs
= internal_relocs
;
1935 irelend
= internal_relocs
+ sec
->reloc_count
;
1936 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1938 bfd_vma laddr
, paddr
, symval
;
1939 unsigned short insn
;
1940 Elf_Internal_Rela
*irelfn
, *irelscan
, *irelcount
;
1941 bfd_signed_vma foff
;
1943 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_CODE
)
1946 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_USES
)
1949 /* Get the section contents. */
1950 if (contents
== NULL
)
1952 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1953 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1956 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
1957 if (contents
== NULL
)
1959 free_contents
= contents
;
1961 if (! bfd_get_section_contents (abfd
, sec
, contents
,
1962 (file_ptr
) 0, sec
->_raw_size
))
1967 /* The r_addend field of the R_SH_USES reloc will point us to
1968 the register load. The 4 is because the r_addend field is
1969 computed as though it were a jump offset, which are based
1970 from 4 bytes after the jump instruction. */
1971 laddr
= irel
->r_offset
+ 4 + irel
->r_addend
;
1972 if (laddr
>= sec
->_raw_size
)
1974 (*_bfd_error_handler
) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),
1975 bfd_archive_filename (abfd
),
1976 (unsigned long) irel
->r_offset
);
1979 insn
= bfd_get_16 (abfd
, contents
+ laddr
);
1981 /* If the instruction is not mov.l NN,rN, we don't know what to
1983 if ((insn
& 0xf000) != 0xd000)
1985 ((*_bfd_error_handler
)
1986 (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
1987 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
, insn
));
1991 /* Get the address from which the register is being loaded. The
1992 displacement in the mov.l instruction is quadrupled. It is a
1993 displacement from four bytes after the movl instruction, but,
1994 before adding in the PC address, two least significant bits
1995 of the PC are cleared. We assume that the section is aligned
1996 on a four byte boundary. */
1997 paddr
= insn
& 0xff;
1999 paddr
+= (laddr
+ 4) &~ (bfd_vma
) 3;
2000 if (paddr
>= sec
->_raw_size
)
2002 ((*_bfd_error_handler
)
2003 (_("%s: 0x%lx: warning: bad R_SH_USES load offset"),
2004 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
2008 /* Get the reloc for the address from which the register is
2009 being loaded. This reloc will tell us which function is
2010 actually being called. */
2011 for (irelfn
= internal_relocs
; irelfn
< irelend
; irelfn
++)
2012 if (irelfn
->r_offset
== paddr
2013 && ELF32_R_TYPE (irelfn
->r_info
) == (int) R_SH_DIR32
)
2015 if (irelfn
>= irelend
)
2017 ((*_bfd_error_handler
)
2018 (_("%s: 0x%lx: warning: could not find expected reloc"),
2019 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2023 /* Read this BFD's symbols if we haven't done so already. */
2024 if (extsyms
== NULL
)
2026 if (symtab_hdr
->contents
!= NULL
)
2027 extsyms
= (Elf32_External_Sym
*) symtab_hdr
->contents
;
2032 amt
= symtab_hdr
->sh_info
;
2033 amt
*= sizeof (Elf32_External_Sym
);
2034 extsyms
= (Elf32_External_Sym
*) bfd_malloc (amt
);
2035 if (extsyms
== NULL
)
2037 free_extsyms
= extsyms
;
2038 if (bfd_seek (abfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2039 || bfd_bread ((PTR
) extsyms
, amt
, abfd
) != amt
)
2041 symtab_hdr
->contents
= (bfd_byte
*) extsyms
;
2044 if (shndx_hdr
->sh_size
!= 0)
2048 amt
= symtab_hdr
->sh_info
;
2049 amt
*= sizeof (Elf_External_Sym_Shndx
);
2050 shndx_buf
= (Elf_External_Sym_Shndx
*) bfd_malloc (amt
);
2051 if (shndx_buf
== NULL
)
2053 if (bfd_seek (abfd
, shndx_hdr
->sh_offset
, SEEK_SET
) != 0
2054 || bfd_bread ((PTR
) shndx_buf
, amt
, abfd
) != amt
)
2056 shndx_hdr
->contents
= (bfd_byte
*) shndx_buf
;
2060 /* Get the value of the symbol referred to by the reloc. */
2061 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
2063 /* A local symbol. */
2064 Elf32_External_Sym
*esym
;
2065 Elf_External_Sym_Shndx
*shndx
;
2066 Elf_Internal_Sym isym
;
2068 esym
= extsyms
+ ELF32_R_SYM (irelfn
->r_info
);
2069 shndx
= shndx_buf
+ (shndx_buf
? ELF32_R_SYM (irelfn
->r_info
) : 0);
2070 bfd_elf32_swap_symbol_in (abfd
, (const PTR
) esym
, (const PTR
) shndx
,
2074 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd
, sec
))
2076 ((*_bfd_error_handler
)
2077 (_("%s: 0x%lx: warning: symbol in unexpected section"),
2078 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2082 symval
= (isym
.st_value
2083 + sec
->output_section
->vma
2084 + sec
->output_offset
);
2089 struct elf_link_hash_entry
*h
;
2091 indx
= ELF32_R_SYM (irelfn
->r_info
) - symtab_hdr
->sh_info
;
2092 h
= elf_sym_hashes (abfd
)[indx
];
2093 BFD_ASSERT (h
!= NULL
);
2094 if (h
->root
.type
!= bfd_link_hash_defined
2095 && h
->root
.type
!= bfd_link_hash_defweak
)
2097 /* This appears to be a reference to an undefined
2098 symbol. Just ignore it--it will be caught by the
2099 regular reloc processing. */
2103 symval
= (h
->root
.u
.def
.value
2104 + h
->root
.u
.def
.section
->output_section
->vma
2105 + h
->root
.u
.def
.section
->output_offset
);
2108 symval
+= bfd_get_32 (abfd
, contents
+ paddr
);
2110 /* See if this function call can be shortened. */
2113 + sec
->output_section
->vma
2114 + sec
->output_offset
2116 if (foff
< -0x1000 || foff
>= 0x1000)
2118 /* After all that work, we can't shorten this function call. */
2122 /* Shorten the function call. */
2124 /* For simplicity of coding, we are going to modify the section
2125 contents, the section relocs, and the BFD symbol table. We
2126 must tell the rest of the code not to free up this
2127 information. It would be possible to instead create a table
2128 of changes which have to be made, as is done in coff-mips.c;
2129 that would be more work, but would require less memory when
2130 the linker is run. */
2132 elf_section_data (sec
)->relocs
= internal_relocs
;
2135 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2136 free_contents
= NULL
;
2138 free_extsyms
= NULL
;
2140 /* Replace the jsr with a bsr. */
2142 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
2143 replace the jsr with a bsr. */
2144 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irelfn
->r_info
), R_SH_IND12W
);
2145 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
2147 /* If this needs to be changed because of future relaxing,
2148 it will be handled here like other internal IND12W
2151 (bfd_vma
) 0xb000 | ((foff
>> 1) & 0xfff),
2152 contents
+ irel
->r_offset
);
2156 /* We can't fully resolve this yet, because the external
2157 symbol value may be changed by future relaxing. We let
2158 the final link phase handle it. */
2159 bfd_put_16 (abfd
, (bfd_vma
) 0xb000, contents
+ irel
->r_offset
);
2162 /* See if there is another R_SH_USES reloc referring to the same
2164 for (irelscan
= internal_relocs
; irelscan
< irelend
; irelscan
++)
2165 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_USES
2166 && laddr
== irelscan
->r_offset
+ 4 + irelscan
->r_addend
)
2168 if (irelscan
< irelend
)
2170 /* Some other function call depends upon this register load,
2171 and we have not yet converted that function call.
2172 Indeed, we may never be able to convert it. There is
2173 nothing else we can do at this point. */
2177 /* Look for a R_SH_COUNT reloc on the location where the
2178 function address is stored. Do this before deleting any
2179 bytes, to avoid confusion about the address. */
2180 for (irelcount
= internal_relocs
; irelcount
< irelend
; irelcount
++)
2181 if (irelcount
->r_offset
== paddr
2182 && ELF32_R_TYPE (irelcount
->r_info
) == (int) R_SH_COUNT
)
2185 /* Delete the register load. */
2186 if (! sh_elf_relax_delete_bytes (abfd
, sec
, laddr
, 2))
2189 /* That will change things, so, just in case it permits some
2190 other function call to come within range, we should relax
2191 again. Note that this is not required, and it may be slow. */
2194 /* Now check whether we got a COUNT reloc. */
2195 if (irelcount
>= irelend
)
2197 ((*_bfd_error_handler
)
2198 (_("%s: 0x%lx: warning: could not find expected COUNT reloc"),
2199 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2203 /* The number of uses is stored in the r_addend field. We've
2204 just deleted one. */
2205 if (irelcount
->r_addend
== 0)
2207 ((*_bfd_error_handler
) (_("%s: 0x%lx: warning: bad count"),
2208 bfd_archive_filename (abfd
),
2209 (unsigned long) paddr
));
2213 --irelcount
->r_addend
;
2215 /* If there are no more uses, we can delete the address. Reload
2216 the address from irelfn, in case it was changed by the
2217 previous call to sh_elf_relax_delete_bytes. */
2218 if (irelcount
->r_addend
== 0)
2220 if (! sh_elf_relax_delete_bytes (abfd
, sec
, irelfn
->r_offset
, 4))
2224 /* We've done all we can with that function call. */
2227 /* Look for load and store instructions that we can align on four
2233 /* Get the section contents. */
2234 if (contents
== NULL
)
2236 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2237 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2240 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
2241 if (contents
== NULL
)
2243 free_contents
= contents
;
2245 if (! bfd_get_section_contents (abfd
, sec
, contents
,
2246 (file_ptr
) 0, sec
->_raw_size
))
2251 if (! sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
,
2257 elf_section_data (sec
)->relocs
= internal_relocs
;
2260 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2261 free_contents
= NULL
;
2263 free_extsyms
= NULL
;
2267 if (free_relocs
!= NULL
)
2270 if (free_contents
!= NULL
)
2272 if (! link_info
->keep_memory
)
2273 free (free_contents
);
2276 /* Cache the section contents for elf_link_input_bfd. */
2277 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2281 if (shndx_buf
!= NULL
)
2283 shndx_hdr
->contents
= NULL
;
2287 if (free_extsyms
!= NULL
)
2289 if (! link_info
->keep_memory
)
2291 symtab_hdr
->contents
= NULL
;
2292 free (free_extsyms
);
2299 if (free_relocs
!= NULL
)
2301 if (free_contents
!= NULL
)
2302 free (free_contents
);
2303 if (shndx_buf
!= NULL
)
2305 shndx_hdr
->contents
= NULL
;
2308 if (free_extsyms
!= NULL
)
2310 symtab_hdr
->contents
= NULL
;
2311 free (free_extsyms
);
2317 /* Delete some bytes from a section while relaxing. FIXME: There is a
2318 lot of duplication between this function and sh_relax_delete_bytes
2322 sh_elf_relax_delete_bytes (abfd
, sec
, addr
, count
)
2328 Elf_Internal_Shdr
*symtab_hdr
;
2329 Elf_Internal_Shdr
*shndx_hdr
;
2330 Elf32_External_Sym
*extsyms
;
2331 unsigned int sec_shndx
;
2333 Elf_Internal_Rela
*irel
, *irelend
;
2334 Elf_Internal_Rela
*irelalign
;
2336 Elf32_External_Sym
*esym
, *esymend
;
2337 Elf_External_Sym_Shndx
*shndx_buf
, *shndx
;
2338 struct elf_link_hash_entry
**sym_hashes
;
2339 struct elf_link_hash_entry
**end_hashes
;
2340 unsigned int symcount
;
2343 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2344 extsyms
= (Elf32_External_Sym
*) symtab_hdr
->contents
;
2346 shndx_hdr
= &elf_tdata (abfd
)->symtab_shndx_hdr
;
2347 shndx_buf
= (Elf_External_Sym_Shndx
*) shndx_hdr
->contents
;
2349 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
2351 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2353 /* The deletion must stop at the next ALIGN reloc for an aligment
2354 power larger than the number of bytes we are deleting. */
2357 toaddr
= sec
->_cooked_size
;
2359 irel
= elf_section_data (sec
)->relocs
;
2360 irelend
= irel
+ sec
->reloc_count
;
2361 for (; irel
< irelend
; irel
++)
2363 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
2364 && irel
->r_offset
> addr
2365 && count
< (1 << irel
->r_addend
))
2368 toaddr
= irel
->r_offset
;
2373 /* Actually delete the bytes. */
2374 memmove (contents
+ addr
, contents
+ addr
+ count
,
2375 (size_t) (toaddr
- addr
- count
));
2376 if (irelalign
== NULL
)
2377 sec
->_cooked_size
-= count
;
2382 #define NOP_OPCODE (0x0009)
2384 BFD_ASSERT ((count
& 1) == 0);
2385 for (i
= 0; i
< count
; i
+= 2)
2386 bfd_put_16 (abfd
, (bfd_vma
) NOP_OPCODE
, contents
+ toaddr
- count
+ i
);
2389 /* Adjust all the relocs. */
2390 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
2392 bfd_vma nraddr
, stop
;
2395 Elf_Internal_Sym sym
;
2396 int off
, adjust
, oinsn
;
2397 bfd_signed_vma voff
= 0;
2400 /* Get the new reloc address. */
2401 nraddr
= irel
->r_offset
;
2402 if ((irel
->r_offset
> addr
2403 && irel
->r_offset
< toaddr
)
2404 || (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
2405 && irel
->r_offset
== toaddr
))
2408 /* See if this reloc was for the bytes we have deleted, in which
2409 case we no longer care about it. Don't delete relocs which
2410 represent addresses, though. */
2411 if (irel
->r_offset
>= addr
2412 && irel
->r_offset
< addr
+ count
2413 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_ALIGN
2414 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
2415 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_DATA
2416 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_LABEL
)
2417 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
2420 /* If this is a PC relative reloc, see if the range it covers
2421 includes the bytes we have deleted. */
2422 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2431 start
= irel
->r_offset
;
2432 insn
= bfd_get_16 (abfd
, contents
+ nraddr
);
2436 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2439 start
= stop
= addr
;
2443 /* If this reloc is against a symbol defined in this
2444 section, and the symbol will not be adjusted below, we
2445 must check the addend to see it will put the value in
2446 range to be adjusted, and hence must be changed. */
2447 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
2449 esym
= extsyms
+ ELF32_R_SYM (irel
->r_info
);
2450 shndx
= shndx_buf
+ (shndx_buf
? ELF32_R_SYM (irel
->r_info
) : 0);
2451 bfd_elf32_swap_symbol_in (abfd
, (const PTR
) esym
,
2452 (const PTR
) shndx
, &sym
);
2454 if (sym
.st_shndx
== sec_shndx
2455 && (sym
.st_value
<= addr
2456 || sym
.st_value
>= toaddr
))
2460 val
= bfd_get_32 (abfd
, contents
+ nraddr
);
2461 val
+= sym
.st_value
;
2462 if (val
> addr
&& val
< toaddr
)
2463 bfd_put_32 (abfd
, val
- count
, contents
+ nraddr
);
2466 start
= stop
= addr
;
2473 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
2477 if (ELF32_R_SYM (irel
->r_info
) >= symtab_hdr
->sh_info
)
2478 start
= stop
= addr
;
2484 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
2490 stop
= start
+ 4 + off
* 2;
2495 stop
= (start
& ~(bfd_vma
) 3) + 4 + off
* 4;
2501 /* These relocs types represent
2503 The r_addend field holds the difference between the reloc
2504 address and L1. That is the start of the reloc, and
2505 adding in the contents gives us the top. We must adjust
2506 both the r_offset field and the section contents.
2507 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
2508 and the elf bfd r_offset is called r_vaddr. */
2510 stop
= irel
->r_offset
;
2511 start
= (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irel
->r_addend
);
2515 && (stop
<= addr
|| stop
>= toaddr
))
2516 irel
->r_addend
+= count
;
2517 else if (stop
> addr
2519 && (start
<= addr
|| start
>= toaddr
))
2520 irel
->r_addend
-= count
;
2522 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH16
)
2523 voff
= bfd_get_signed_16 (abfd
, contents
+ nraddr
);
2524 else if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH8
)
2525 voff
= bfd_get_8 (abfd
, contents
+ nraddr
);
2527 voff
= bfd_get_signed_32 (abfd
, contents
+ nraddr
);
2528 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
2533 start
= irel
->r_offset
;
2534 stop
= (bfd_vma
) ((bfd_signed_vma
) start
2535 + (long) irel
->r_addend
2542 && (stop
<= addr
|| stop
>= toaddr
))
2544 else if (stop
> addr
2546 && (start
<= addr
|| start
>= toaddr
))
2555 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2564 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2566 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2571 if ((oinsn
& 0xf000) != (insn
& 0xf000))
2573 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2577 BFD_ASSERT (adjust
== count
|| count
>= 4);
2582 if ((irel
->r_offset
& 3) == 0)
2585 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2587 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2592 if (voff
< 0 || voff
>= 0xff)
2594 bfd_put_8 (abfd
, voff
, contents
+ nraddr
);
2599 if (voff
< - 0x8000 || voff
>= 0x8000)
2601 bfd_put_signed_16 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
2606 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
2610 irel
->r_addend
+= adjust
;
2616 ((*_bfd_error_handler
)
2617 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
2618 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
2619 bfd_set_error (bfd_error_bad_value
);
2624 irel
->r_offset
= nraddr
;
2627 /* Look through all the other sections. If there contain any IMM32
2628 relocs against internal symbols which we are not going to adjust
2629 below, we may need to adjust the addends. */
2630 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2632 Elf_Internal_Rela
*internal_relocs
;
2633 Elf_Internal_Rela
*irelscan
, *irelscanend
;
2634 bfd_byte
*ocontents
;
2637 || (o
->flags
& SEC_RELOC
) == 0
2638 || o
->reloc_count
== 0)
2641 /* We always cache the relocs. Perhaps, if info->keep_memory is
2642 false, we should free them, if we are permitted to, when we
2643 leave sh_coff_relax_section. */
2644 internal_relocs
= (_bfd_elf32_link_read_relocs
2645 (abfd
, o
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
2647 if (internal_relocs
== NULL
)
2651 irelscanend
= internal_relocs
+ o
->reloc_count
;
2652 for (irelscan
= internal_relocs
; irelscan
< irelscanend
; irelscan
++)
2654 Elf_Internal_Sym sym
;
2656 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
2657 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_SWITCH32
)
2659 bfd_vma start
, stop
;
2660 bfd_signed_vma voff
;
2662 if (ocontents
== NULL
)
2664 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
2665 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
2668 /* We always cache the section contents.
2669 Perhaps, if info->keep_memory is false, we
2670 should free them, if we are permitted to,
2671 when we leave sh_coff_relax_section. */
2672 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
2673 if (ocontents
== NULL
)
2675 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
2679 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
2683 stop
= irelscan
->r_offset
;
2685 = (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irelscan
->r_addend
);
2687 /* STOP is in a different section, so it won't change. */
2688 if (start
> addr
&& start
< toaddr
)
2689 irelscan
->r_addend
+= count
;
2691 voff
= bfd_get_signed_32 (abfd
, ocontents
+ irelscan
->r_offset
);
2692 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
2696 && (stop
<= addr
|| stop
>= toaddr
))
2697 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
+ count
,
2698 ocontents
+ irelscan
->r_offset
);
2699 else if (stop
> addr
2701 && (start
<= addr
|| start
>= toaddr
))
2702 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
- count
,
2703 ocontents
+ irelscan
->r_offset
);
2706 if (ELF32_R_TYPE (irelscan
->r_info
) != (int) R_SH_DIR32
)
2709 if (ELF32_R_SYM (irelscan
->r_info
) >= symtab_hdr
->sh_info
)
2713 esym
= extsyms
+ ELF32_R_SYM (irelscan
->r_info
);
2714 shndx
= shndx_buf
+ (shndx_buf
? ELF32_R_SYM (irelscan
->r_info
) : 0);
2715 bfd_elf32_swap_symbol_in (abfd
, (const PTR
) esym
, (const PTR
) shndx
,
2718 if (sym
.st_shndx
== sec_shndx
2719 && (sym
.st_value
<= addr
2720 || sym
.st_value
>= toaddr
))
2724 if (ocontents
== NULL
)
2726 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
2727 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
2730 /* We always cache the section contents.
2731 Perhaps, if info->keep_memory is false, we
2732 should free them, if we are permitted to,
2733 when we leave sh_coff_relax_section. */
2734 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
2735 if (ocontents
== NULL
)
2737 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
2741 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
2745 val
= bfd_get_32 (abfd
, ocontents
+ irelscan
->r_offset
);
2746 val
+= sym
.st_value
;
2747 if (val
> addr
&& val
< toaddr
)
2748 bfd_put_32 (abfd
, val
- count
,
2749 ocontents
+ irelscan
->r_offset
);
2754 /* Adjust the local symbols defined in this section. */
2757 esymend
= esym
+ symtab_hdr
->sh_info
;
2758 for (; esym
< esymend
; esym
++, shndx
= (shndx
? shndx
+ 1 : NULL
))
2760 Elf_Internal_Sym isym
;
2761 Elf_External_Sym_Shndx dummy
;
2763 bfd_elf32_swap_symbol_in (abfd
, (const PTR
) esym
, (const PTR
) shndx
,
2766 if (isym
.st_shndx
== sec_shndx
2767 && isym
.st_value
> addr
2768 && isym
.st_value
< toaddr
)
2770 isym
.st_value
-= count
;
2771 bfd_elf32_swap_symbol_out (abfd
, &isym
, (PTR
) esym
, (PTR
) &dummy
);
2775 /* Now adjust the global symbols defined in this section. */
2776 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2777 - symtab_hdr
->sh_info
);
2778 sym_hashes
= elf_sym_hashes (abfd
);
2779 end_hashes
= sym_hashes
+ symcount
;
2780 for (; sym_hashes
< end_hashes
; sym_hashes
++)
2782 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
2783 if ((sym_hash
->root
.type
== bfd_link_hash_defined
2784 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
2785 && sym_hash
->root
.u
.def
.section
== sec
2786 && sym_hash
->root
.u
.def
.value
> addr
2787 && sym_hash
->root
.u
.def
.value
< toaddr
)
2789 sym_hash
->root
.u
.def
.value
-= count
;
2793 /* See if we can move the ALIGN reloc forward. We have adjusted
2794 r_offset for it already. */
2795 if (irelalign
!= NULL
)
2797 bfd_vma alignto
, alignaddr
;
2799 alignto
= BFD_ALIGN (toaddr
, 1 << irelalign
->r_addend
);
2800 alignaddr
= BFD_ALIGN (irelalign
->r_offset
,
2801 1 << irelalign
->r_addend
);
2802 if (alignto
!= alignaddr
)
2804 /* Tail recursion. */
2805 return sh_elf_relax_delete_bytes (abfd
, sec
, alignaddr
,
2806 (int) (alignto
- alignaddr
));
2813 /* Look for loads and stores which we can align to four byte
2814 boundaries. This is like sh_align_loads in coff-sh.c. */
2817 sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
, pswapped
)
2818 bfd
*abfd ATTRIBUTE_UNUSED
;
2820 Elf_Internal_Rela
*internal_relocs
;
2821 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2824 Elf_Internal_Rela
*irel
, *irelend
;
2825 bfd_vma
*labels
= NULL
;
2826 bfd_vma
*label
, *label_end
;
2831 irelend
= internal_relocs
+ sec
->reloc_count
;
2833 /* Get all the addresses with labels on them. */
2834 amt
= sec
->reloc_count
;
2835 amt
*= sizeof (bfd_vma
);
2836 labels
= (bfd_vma
*) bfd_malloc (amt
);
2840 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2842 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_LABEL
)
2844 *label_end
= irel
->r_offset
;
2849 /* Note that the assembler currently always outputs relocs in
2850 address order. If that ever changes, this code will need to sort
2851 the label values and the relocs. */
2855 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2857 bfd_vma start
, stop
;
2859 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
)
2862 start
= irel
->r_offset
;
2864 for (irel
++; irel
< irelend
; irel
++)
2865 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_DATA
)
2868 stop
= irel
->r_offset
;
2870 stop
= sec
->_cooked_size
;
2872 if (! _bfd_sh_align_load_span (abfd
, sec
, contents
, sh_elf_swap_insns
,
2873 (PTR
) internal_relocs
, &label
,
2874 label_end
, start
, stop
, pswapped
))
2888 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
2891 sh_elf_swap_insns (abfd
, sec
, relocs
, contents
, addr
)
2898 Elf_Internal_Rela
*internal_relocs
= (Elf_Internal_Rela
*) relocs
;
2899 unsigned short i1
, i2
;
2900 Elf_Internal_Rela
*irel
, *irelend
;
2902 /* Swap the instructions themselves. */
2903 i1
= bfd_get_16 (abfd
, contents
+ addr
);
2904 i2
= bfd_get_16 (abfd
, contents
+ addr
+ 2);
2905 bfd_put_16 (abfd
, (bfd_vma
) i2
, contents
+ addr
);
2906 bfd_put_16 (abfd
, (bfd_vma
) i1
, contents
+ addr
+ 2);
2908 /* Adjust all reloc addresses. */
2909 irelend
= internal_relocs
+ sec
->reloc_count
;
2910 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2912 enum elf_sh_reloc_type type
;
2915 /* There are a few special types of relocs that we don't want to
2916 adjust. These relocs do not apply to the instruction itself,
2917 but are only associated with the address. */
2918 type
= (enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
);
2919 if (type
== R_SH_ALIGN
2920 || type
== R_SH_CODE
2921 || type
== R_SH_DATA
2922 || type
== R_SH_LABEL
)
2925 /* If an R_SH_USES reloc points to one of the addresses being
2926 swapped, we must adjust it. It would be incorrect to do this
2927 for a jump, though, since we want to execute both
2928 instructions after the jump. (We have avoided swapping
2929 around a label, so the jump will not wind up executing an
2930 instruction it shouldn't). */
2931 if (type
== R_SH_USES
)
2935 off
= irel
->r_offset
+ 4 + irel
->r_addend
;
2937 irel
->r_offset
+= 2;
2938 else if (off
== addr
+ 2)
2939 irel
->r_offset
-= 2;
2942 if (irel
->r_offset
== addr
)
2944 irel
->r_offset
+= 2;
2947 else if (irel
->r_offset
== addr
+ 2)
2949 irel
->r_offset
-= 2;
2958 unsigned short insn
, oinsn
;
2961 loc
= contents
+ irel
->r_offset
;
2970 insn
= bfd_get_16 (abfd
, loc
);
2973 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2975 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
2979 insn
= bfd_get_16 (abfd
, loc
);
2982 if ((oinsn
& 0xf000) != (insn
& 0xf000))
2984 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
2988 /* This reloc ignores the least significant 3 bits of
2989 the program counter before adding in the offset.
2990 This means that if ADDR is at an even address, the
2991 swap will not affect the offset. If ADDR is an at an
2992 odd address, then the instruction will be crossing a
2993 four byte boundary, and must be adjusted. */
2994 if ((addr
& 3) != 0)
2996 insn
= bfd_get_16 (abfd
, loc
);
2999 if ((oinsn
& 0xff00) != (insn
& 0xff00))
3001 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3009 ((*_bfd_error_handler
)
3010 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
3011 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
3012 bfd_set_error (bfd_error_bad_value
);
3021 #ifdef INCLUDE_SHMEDIA
3023 /* The size in bytes of an entry in the procedure linkage table. */
3025 #define PLT_ENTRY_SIZE 64
3027 /* First entry in an absolute procedure linkage table look like this. */
3029 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3031 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
3032 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
3033 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3034 0x6b, 0xf1, 0x46, 0x00, /* ptabs r17, tr0 */
3035 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3036 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3037 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3038 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3039 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3040 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3041 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3042 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3043 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3044 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3045 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3046 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3049 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3051 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
3052 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
3053 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3054 0x00, 0x46, 0xf1, 0x6b, /* ptabs r17, tr0 */
3055 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3056 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3057 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3058 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3059 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3060 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3061 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3062 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3063 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3064 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3065 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3066 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3069 /* Sebsequent entries in an absolute procedure linkage table look like
3072 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3074 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
3075 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
3076 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
3077 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3078 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3079 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3080 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3081 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3082 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
3083 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
3084 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3085 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3086 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3087 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3088 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3089 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3092 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3094 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3095 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3096 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
3097 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3098 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3099 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3100 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3101 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3102 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
3103 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
3104 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3105 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3106 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3107 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3108 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3109 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3112 /* Entries in a PIC procedure linkage table look like this. */
3114 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3116 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3117 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3118 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
3119 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3120 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3121 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3122 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3123 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3124 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3125 0x00, 0xca, 0x45, 0x10, /* sub.l r12, r17, r17 */
3126 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3127 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3128 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3129 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3130 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3131 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3134 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3136 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3137 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3138 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
3139 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3140 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3141 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3142 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3143 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3144 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3145 0x10, 0x45, 0xca, 0x00, /* sub.l r12, r17, r17 */
3146 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3147 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3148 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3149 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3150 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3151 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3154 static const bfd_byte
*elf_sh_plt0_entry
;
3155 static const bfd_byte
*elf_sh_plt_entry
;
3156 static const bfd_byte
*elf_sh_pic_plt_entry
;
3158 /* Return size of a PLT entry. */
3159 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3161 /* Return offset of the PLT0 address in an absolute PLT entry. */
3162 #define elf_sh_plt_plt0_offset(info) 32
3164 /* Return offset of the linker in PLT0 entry. */
3165 #define elf_sh_plt0_gotplt_offset(info) 0
3167 /* Return offset of the trampoline in PLT entry */
3168 #define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
3170 /* Return offset of the symbol in PLT entry. */
3171 #define elf_sh_plt_symbol_offset(info) 0
3173 /* Return offset of the relocation in PLT entry. */
3174 #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
3177 movi_shori_putval (output_bfd
, value
, addr
)
3179 unsigned long value
;
3182 bfd_put_32 (output_bfd
,
3183 bfd_get_32 (output_bfd
, addr
)
3184 | ((value
>> 6) & 0x3fffc00),
3186 bfd_put_32 (output_bfd
,
3187 bfd_get_32 (output_bfd
, addr
+ 4)
3188 | ((value
<< 10) & 0x3fffc00),
3193 /* The size in bytes of an entry in the procedure linkage table. */
3195 #define PLT_ENTRY_SIZE 28
3197 /* First entry in an absolute procedure linkage table look like this. */
3200 /* Note - this code has been "optimised" not to use r2. r2 is used by
3201 GCC to return the address of large strutcures, so it should not be
3202 corrupted here. This does mean however, that this PLT does not conform
3203 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
3204 and r2 contains the GOT id. This version stores the GOT id in r0 and
3205 ignores the type. Loaders can easily detect this difference however,
3206 since the type will always be 0 or 8, and the GOT ids will always be
3207 greater than or equal to 12. */
3208 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3210 0xd0, 0x05, /* mov.l 2f,r0 */
3211 0x60, 0x02, /* mov.l @r0,r0 */
3212 0x2f, 0x06, /* mov.l r0,@-r15 */
3213 0xd0, 0x03, /* mov.l 1f,r0 */
3214 0x60, 0x02, /* mov.l @r0,r0 */
3215 0x40, 0x2b, /* jmp @r0 */
3216 0x60, 0xf6, /* mov.l @r15+,r0 */
3217 0x00, 0x09, /* nop */
3218 0x00, 0x09, /* nop */
3219 0x00, 0x09, /* nop */
3220 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3221 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3224 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3226 0x05, 0xd0, /* mov.l 2f,r0 */
3227 0x02, 0x60, /* mov.l @r0,r0 */
3228 0x06, 0x2f, /* mov.l r0,@-r15 */
3229 0x03, 0xd0, /* mov.l 1f,r0 */
3230 0x02, 0x60, /* mov.l @r0,r0 */
3231 0x2b, 0x40, /* jmp @r0 */
3232 0xf6, 0x60, /* mov.l @r15+,r0 */
3233 0x09, 0x00, /* nop */
3234 0x09, 0x00, /* nop */
3235 0x09, 0x00, /* nop */
3236 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3237 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3240 /* Sebsequent entries in an absolute procedure linkage table look like
3243 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3245 0xd0, 0x04, /* mov.l 1f,r0 */
3246 0x60, 0x02, /* mov.l @r0,r0 */
3247 0xd1, 0x02, /* mov.l 0f,r1 */
3248 0x40, 0x2b, /* jmp @r0 */
3249 0x60, 0x13, /* mov r1,r0 */
3250 0xd1, 0x03, /* mov.l 2f,r1 */
3251 0x40, 0x2b, /* jmp @r0 */
3252 0x00, 0x09, /* nop */
3253 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3254 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3255 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3258 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3260 0x04, 0xd0, /* mov.l 1f,r0 */
3261 0x02, 0x60, /* mov.l @r0,r0 */
3262 0x02, 0xd1, /* mov.l 0f,r1 */
3263 0x2b, 0x40, /* jmp @r0 */
3264 0x13, 0x60, /* mov r1,r0 */
3265 0x03, 0xd1, /* mov.l 2f,r1 */
3266 0x2b, 0x40, /* jmp @r0 */
3267 0x09, 0x00, /* nop */
3268 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3269 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3270 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3273 /* Entries in a PIC procedure linkage table look like this. */
3275 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3277 0xd0, 0x04, /* mov.l 1f,r0 */
3278 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3279 0x40, 0x2b, /* jmp @r0 */
3280 0x00, 0x09, /* nop */
3281 0x50, 0xc2, /* mov.l @(8,r12),r0 */
3282 0xd1, 0x03, /* mov.l 2f,r1 */
3283 0x40, 0x2b, /* jmp @r0 */
3284 0x50, 0xc1, /* mov.l @(4,r12),r0 */
3285 0x00, 0x09, /* nop */
3286 0x00, 0x09, /* nop */
3287 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3288 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3291 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3293 0x04, 0xd0, /* mov.l 1f,r0 */
3294 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3295 0x2b, 0x40, /* jmp @r0 */
3296 0x09, 0x00, /* nop */
3297 0xc2, 0x50, /* mov.l @(8,r12),r0 */
3298 0x03, 0xd1, /* mov.l 2f,r1 */
3299 0x2b, 0x40, /* jmp @r0 */
3300 0xc1, 0x50, /* mov.l @(4,r12),r0 */
3301 0x09, 0x00, /* nop */
3302 0x09, 0x00, /* nop */
3303 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3304 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3307 #else /* These are the old style PLT entries. */
3308 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3310 0xd0, 0x04, /* mov.l 1f,r0 */
3311 0xd2, 0x05, /* mov.l 2f,r2 */
3312 0x60, 0x02, /* mov.l @r0,r0 */
3313 0x62, 0x22, /* mov.l @r2,r2 */
3314 0x40, 0x2b, /* jmp @r0 */
3315 0xe0, 0x00, /* mov #0,r0 */
3316 0x00, 0x09, /* nop */
3317 0x00, 0x09, /* nop */
3318 0x00, 0x09, /* nop */
3319 0x00, 0x09, /* nop */
3320 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3321 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3324 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3326 0x04, 0xd0, /* mov.l 1f,r0 */
3327 0x05, 0xd2, /* mov.l 2f,r2 */
3328 0x02, 0x60, /* mov.l @r0,r0 */
3329 0x22, 0x62, /* mov.l @r2,r2 */
3330 0x2b, 0x40, /* jmp @r0 */
3331 0x00, 0xe0, /* mov #0,r0 */
3332 0x09, 0x00, /* nop */
3333 0x09, 0x00, /* nop */
3334 0x09, 0x00, /* nop */
3335 0x09, 0x00, /* nop */
3336 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3337 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3340 /* Sebsequent entries in an absolute procedure linkage table look like
3343 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3345 0xd0, 0x04, /* mov.l 1f,r0 */
3346 0x60, 0x02, /* mov.l @r0,r0 */
3347 0xd2, 0x02, /* mov.l 0f,r2 */
3348 0x40, 0x2b, /* jmp @r0 */
3349 0x60, 0x23, /* mov r2,r0 */
3350 0xd1, 0x03, /* mov.l 2f,r1 */
3351 0x40, 0x2b, /* jmp @r0 */
3352 0x00, 0x09, /* nop */
3353 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3354 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3355 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3358 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3360 0x04, 0xd0, /* mov.l 1f,r0 */
3361 0x02, 0x60, /* mov.l @r0,r0 */
3362 0x02, 0xd2, /* mov.l 0f,r2 */
3363 0x2b, 0x40, /* jmp @r0 */
3364 0x23, 0x60, /* mov r2,r0 */
3365 0x03, 0xd1, /* mov.l 2f,r1 */
3366 0x2b, 0x40, /* jmp @r0 */
3367 0x09, 0x00, /* nop */
3368 0, 0, 0, 0, /* 0: replaced with address of .PLT. */
3369 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3370 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3373 /* Entries in a PIC procedure linkage table look like this. */
3375 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3377 0xd0, 0x04, /* mov.l 1f,r0 */
3378 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3379 0x40, 0x2b, /* jmp @r0 */
3380 0x00, 0x09, /* nop */
3381 0x50, 0xc2, /* 0: mov.l @(8,r12),r0 */
3382 0x52, 0xc1, /* 1: mov.l @(4,r12),r2 */
3383 0xd1, 0x02, /* mov.l 2f,r1 */
3384 0x40, 0x2b, /* jmp @r0 */
3385 0xe0, 0x00, /* mov #0,r0 ! shows the type of PLT. */
3386 0x00, 0x09, /* nop */
3387 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3388 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3391 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3393 0x04, 0xd0, /* mov.l 1f,r0 */
3394 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3395 0x2b, 0x40, /* jmp @r0 */
3396 0x09, 0x00, /* nop */
3397 0xc2, 0x50, /* 0: mov.l @(8,r12),r0 */
3398 0xc1, 0x52, /* 1: mov.l @(4,r12),r2 */
3399 0x02, 0xd1, /* mov.l 2f,r1 */
3400 0x2b, 0x40, /* jmp @r0 */
3401 0x00, 0xe0, /* mov #0,r0 ! shows the type of PLT. */
3402 0x09, 0x00, /* nop */
3403 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3404 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3406 #endif /* old style PLT entries. */
3408 static const bfd_byte
*elf_sh_plt0_entry
;
3409 static const bfd_byte
*elf_sh_plt_entry
;
3410 static const bfd_byte
*elf_sh_pic_plt_entry
;
3412 /* Return size of a PLT entry. */
3413 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3415 /* Return offset of the PLT0 address in an absolute PLT entry. */
3416 #define elf_sh_plt_plt0_offset(info) 16
3418 /* Return offset of the linker in PLT0 entry. */
3419 #define elf_sh_plt0_linker_offset(info) 20
3421 /* Return offset of the GOT id in PLT0 entry. */
3422 #define elf_sh_plt0_gotid_offset(info) 24
3424 /* Return offset of the tempoline in PLT entry */
3425 #define elf_sh_plt_temp_offset(info) 8
3427 /* Return offset of the symbol in PLT entry. */
3428 #define elf_sh_plt_symbol_offset(info) 20
3430 /* Return offset of the relocation in PLT entry. */
3431 #define elf_sh_plt_reloc_offset(info) 24
3434 /* The sh linker needs to keep track of the number of relocs that it
3435 decides to copy in check_relocs for each symbol. This is so that
3436 it can discard PC relative relocs if it doesn't need them when
3437 linking with -Bsymbolic. We store the information in a field
3438 extending the regular ELF linker hash table. */
3440 /* This structure keeps track of the number of PC relative relocs we
3441 have copied for a given symbol. */
3443 struct elf_sh_pcrel_relocs_copied
3446 struct elf_sh_pcrel_relocs_copied
*next
;
3447 /* A section in dynobj. */
3449 /* Number of relocs copied in this section. */
3450 bfd_size_type count
;
3453 /* sh ELF linker hash entry. */
3455 struct elf_sh_link_hash_entry
3457 struct elf_link_hash_entry root
;
3459 #ifdef INCLUDE_SHMEDIA
3460 bfd_vma datalabel_got_offset
;
3463 /* Number of PC relative relocs copied for this symbol. */
3464 struct elf_sh_pcrel_relocs_copied
*pcrel_relocs_copied
;
3467 /* sh ELF linker hash table. */
3469 struct elf_sh_link_hash_table
3471 struct elf_link_hash_table root
;
3474 /* Declare this now that the above structures are defined. */
3476 static boolean sh_elf_discard_copies
3477 PARAMS ((struct elf_sh_link_hash_entry
*, PTR
));
3479 /* Traverse an sh ELF linker hash table. */
3481 #define sh_elf_link_hash_traverse(table, func, info) \
3482 (elf_link_hash_traverse \
3484 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3487 /* Get the sh ELF linker hash table from a link_info structure. */
3489 #define sh_elf_hash_table(p) \
3490 ((struct elf_sh_link_hash_table *) ((p)->hash))
3492 /* Create an entry in an sh ELF linker hash table. */
3494 static struct bfd_hash_entry
*
3495 sh_elf_link_hash_newfunc (entry
, table
, string
)
3496 struct bfd_hash_entry
*entry
;
3497 struct bfd_hash_table
*table
;
3500 struct elf_sh_link_hash_entry
*ret
=
3501 (struct elf_sh_link_hash_entry
*) entry
;
3503 /* Allocate the structure if it has not already been allocated by a
3505 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3506 ret
= ((struct elf_sh_link_hash_entry
*)
3507 bfd_hash_allocate (table
,
3508 sizeof (struct elf_sh_link_hash_entry
)));
3509 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3510 return (struct bfd_hash_entry
*) ret
;
3512 /* Call the allocation method of the superclass. */
3513 ret
= ((struct elf_sh_link_hash_entry
*)
3514 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3516 if (ret
!= (struct elf_sh_link_hash_entry
*) NULL
)
3518 ret
->pcrel_relocs_copied
= NULL
;
3519 #ifdef INCLUDE_SHMEDIA
3520 ret
->datalabel_got_offset
= (bfd_vma
) -1;
3524 return (struct bfd_hash_entry
*) ret
;
3527 /* Create an sh ELF linker hash table. */
3529 static struct bfd_link_hash_table
*
3530 sh_elf_link_hash_table_create (abfd
)
3533 struct elf_sh_link_hash_table
*ret
;
3534 bfd_size_type amt
= sizeof (struct elf_sh_link_hash_table
);
3536 ret
= (struct elf_sh_link_hash_table
*) bfd_malloc (amt
);
3537 if (ret
== (struct elf_sh_link_hash_table
*) NULL
)
3540 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3541 sh_elf_link_hash_newfunc
))
3547 return &ret
->root
.root
;
3550 /* Create dynamic sections when linking against a dynamic object. */
3553 sh_elf_create_dynamic_sections (abfd
, info
)
3555 struct bfd_link_info
*info
;
3557 flagword flags
, pltflags
;
3558 register asection
*s
;
3559 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3562 switch (bed
->s
->arch_size
)
3573 bfd_set_error (bfd_error_bad_value
);
3577 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3578 .rel[a].bss sections. */
3580 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3581 | SEC_LINKER_CREATED
);
3584 pltflags
|= SEC_CODE
;
3585 if (bed
->plt_not_loaded
)
3586 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
3587 if (bed
->plt_readonly
)
3588 pltflags
|= SEC_READONLY
;
3590 s
= bfd_make_section (abfd
, ".plt");
3592 || ! bfd_set_section_flags (abfd
, s
, pltflags
)
3593 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3596 if (bed
->want_plt_sym
)
3598 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3600 struct elf_link_hash_entry
*h
= NULL
;
3601 if (! (_bfd_generic_link_add_one_symbol
3602 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3603 (bfd_vma
) 0, (const char *) NULL
, false,
3604 get_elf_backend_data (abfd
)->collect
,
3605 (struct bfd_link_hash_entry
**) &h
)))
3607 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3608 h
->type
= STT_OBJECT
;
3611 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
3615 s
= bfd_make_section (abfd
,
3616 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt");
3618 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3619 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3622 if (! _bfd_elf_create_got_section (abfd
, info
))
3626 const char *secname
;
3631 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3633 secflags
= bfd_get_section_flags (abfd
, sec
);
3634 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3635 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3637 secname
= bfd_get_section_name (abfd
, sec
);
3638 relname
= (char *) bfd_malloc ((bfd_size_type
) strlen (secname
) + 6);
3639 strcpy (relname
, ".rela");
3640 strcat (relname
, secname
);
3641 s
= bfd_make_section (abfd
, relname
);
3643 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3644 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3649 if (bed
->want_dynbss
)
3651 /* The .dynbss section is a place to put symbols which are defined
3652 by dynamic objects, are referenced by regular objects, and are
3653 not functions. We must allocate space for them in the process
3654 image and use a R_*_COPY reloc to tell the dynamic linker to
3655 initialize them at run time. The linker script puts the .dynbss
3656 section into the .bss section of the final image. */
3657 s
= bfd_make_section (abfd
, ".dynbss");
3659 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
3662 /* The .rel[a].bss section holds copy relocs. This section is not
3663 normally needed. We need to create it here, though, so that the
3664 linker will map it to an output section. We can't just create it
3665 only if we need it, because we will not know whether we need it
3666 until we have seen all the input files, and the first time the
3667 main linker code calls BFD after examining all the input files
3668 (size_dynamic_sections) the input sections have already been
3669 mapped to the output sections. If the section turns out not to
3670 be needed, we can discard it later. We will never need this
3671 section when generating a shared object, since they do not use
3675 s
= bfd_make_section (abfd
,
3676 (bed
->default_use_rela_p
3677 ? ".rela.bss" : ".rel.bss"));
3679 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3680 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3688 /* Adjust a symbol defined by a dynamic object and referenced by a
3689 regular object. The current definition is in some section of the
3690 dynamic object, but we're not including those sections. We have to
3691 change the definition to something the rest of the link can
3695 sh_elf_adjust_dynamic_symbol (info
, h
)
3696 struct bfd_link_info
*info
;
3697 struct elf_link_hash_entry
*h
;
3701 unsigned int power_of_two
;
3703 dynobj
= elf_hash_table (info
)->dynobj
;
3705 /* Make sure we know what is going on here. */
3706 BFD_ASSERT (dynobj
!= NULL
3707 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
3708 || h
->weakdef
!= NULL
3709 || ((h
->elf_link_hash_flags
3710 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3711 && (h
->elf_link_hash_flags
3712 & ELF_LINK_HASH_REF_REGULAR
) != 0
3713 && (h
->elf_link_hash_flags
3714 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
3716 /* If this is a function, put it in the procedure linkage table. We
3717 will fill in the contents of the procedure linkage table later,
3718 when we know the address of the .got section. */
3719 if (h
->type
== STT_FUNC
3720 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3723 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3724 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0)
3726 /* This case can occur if we saw a PLT reloc in an input
3727 file, but the symbol was never referred to by a dynamic
3728 object. In such a case, we don't actually need to build
3729 a procedure linkage table, and we can just do a REL32
3731 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
3735 /* Make sure this symbol is output as a dynamic symbol. */
3736 if (h
->dynindx
== -1)
3738 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3742 s
= bfd_get_section_by_name (dynobj
, ".plt");
3743 BFD_ASSERT (s
!= NULL
);
3745 /* If this is the first .plt entry, make room for the special
3747 if (s
->_raw_size
== 0)
3748 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3750 /* If this symbol is not defined in a regular file, and we are
3751 not generating a shared library, then set the symbol to this
3752 location in the .plt. This is required to make function
3753 pointers compare as equal between the normal executable and
3754 the shared library. */
3756 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3758 h
->root
.u
.def
.section
= s
;
3759 h
->root
.u
.def
.value
= s
->_raw_size
;
3762 h
->plt
.offset
= s
->_raw_size
;
3764 /* Make room for this entry. */
3765 s
->_raw_size
+= elf_sh_sizeof_plt (info
);
3767 /* We also need to make an entry in the .got.plt section, which
3768 will be placed in the .got section by the linker script. */
3770 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
3771 BFD_ASSERT (s
!= NULL
);
3774 /* We also need to make an entry in the .rela.plt section. */
3776 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3777 BFD_ASSERT (s
!= NULL
);
3778 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
3783 /* If this is a weak symbol, and there is a real definition, the
3784 processor independent code will have arranged for us to see the
3785 real definition first, and we can just use the same value. */
3786 if (h
->weakdef
!= NULL
)
3788 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3789 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3790 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3791 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3795 /* This is a reference to a symbol defined by a dynamic object which
3796 is not a function. */
3798 /* If we are creating a shared library, we must presume that the
3799 only references to the symbol are via the global offset table.
3800 For such cases we need not do anything here; the relocations will
3801 be handled correctly by relocate_section. */
3805 /* If there are no references to this symbol that do not use the
3806 GOT, we don't need to generate a copy reloc. */
3807 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
3810 /* We must allocate the symbol in our .dynbss section, which will
3811 become part of the .bss section of the executable. There will be
3812 an entry for this symbol in the .dynsym section. The dynamic
3813 object will contain position independent code, so all references
3814 from the dynamic object to this symbol will go through the global
3815 offset table. The dynamic linker will use the .dynsym entry to
3816 determine the address it must put in the global offset table, so
3817 both the dynamic object and the regular object will refer to the
3818 same memory location for the variable. */
3820 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
3821 BFD_ASSERT (s
!= NULL
);
3823 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3824 copy the initial value out of the dynamic object and into the
3825 runtime process image. We need to remember the offset into the
3826 .rela.bss section we are going to use. */
3827 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3831 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
3832 BFD_ASSERT (srel
!= NULL
);
3833 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
3834 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3837 /* We need to figure out the alignment required for this symbol. I
3838 have no idea how ELF linkers handle this. */
3839 power_of_two
= bfd_log2 (h
->size
);
3840 if (power_of_two
> 3)
3843 /* Apply the required alignment. */
3844 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
3845 (bfd_size_type
) (1 << power_of_two
));
3846 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
3848 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
3852 /* Define the symbol as being at this point in the section. */
3853 h
->root
.u
.def
.section
= s
;
3854 h
->root
.u
.def
.value
= s
->_raw_size
;
3856 /* Increment the section size to make room for the symbol. */
3857 s
->_raw_size
+= h
->size
;
3862 /* Set the sizes of the dynamic sections. */
3865 sh_elf_size_dynamic_sections (output_bfd
, info
)
3866 bfd
*output_bfd ATTRIBUTE_UNUSED
;
3867 struct bfd_link_info
*info
;
3874 dynobj
= elf_hash_table (info
)->dynobj
;
3875 BFD_ASSERT (dynobj
!= NULL
);
3877 if (elf_hash_table (info
)->dynamic_sections_created
)
3879 /* Set the contents of the .interp section to the interpreter. */
3882 s
= bfd_get_section_by_name (dynobj
, ".interp");
3883 BFD_ASSERT (s
!= NULL
);
3884 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3885 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3890 /* We may have created entries in the .rela.got section.
3891 However, if we are not creating the dynamic sections, we will
3892 not actually use these entries. Reset the size of .rela.got,
3893 which will cause it to get stripped from the output file
3895 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
3900 /* If this is a -Bsymbolic shared link, then we need to discard all
3901 PC relative relocs against symbols defined in a regular object.
3902 We allocated space for them in the check_relocs routine, but we
3903 will not fill them in in the relocate_section routine. */
3904 if (info
->shared
&& info
->symbolic
)
3905 sh_elf_link_hash_traverse (sh_elf_hash_table (info
),
3906 sh_elf_discard_copies
,
3909 /* The check_relocs and adjust_dynamic_symbol entry points have
3910 determined the sizes of the various dynamic sections. Allocate
3914 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3919 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3922 /* It's OK to base decisions on the section name, because none
3923 of the dynobj section names depend upon the input files. */
3924 name
= bfd_get_section_name (dynobj
, s
);
3928 if (strcmp (name
, ".plt") == 0)
3930 if (s
->_raw_size
== 0)
3932 /* Strip this section if we don't need it; see the
3938 /* Remember whether there is a PLT. */
3942 else if (strncmp (name
, ".rela", 5) == 0)
3944 if (s
->_raw_size
== 0)
3946 /* If we don't need this section, strip it from the
3947 output file. This is mostly to handle .rela.bss and
3948 .rela.plt. We must create both sections in
3949 create_dynamic_sections, because they must be created
3950 before the linker maps input sections to output
3951 sections. The linker does that before
3952 adjust_dynamic_symbol is called, and it is that
3953 function which decides whether anything needs to go
3954 into these sections. */
3959 /* Remember whether there are any reloc sections other
3961 if (strcmp (name
, ".rela.plt") != 0)
3964 /* We use the reloc_count field as a counter if we need
3965 to copy relocs into the output file. */
3969 else if (strncmp (name
, ".got", 4) != 0)
3971 /* It's not one of our sections, so don't allocate space. */
3977 _bfd_strip_section_from_output (info
, s
);
3981 /* Allocate memory for the section contents. */
3982 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
3983 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
3987 if (elf_hash_table (info
)->dynamic_sections_created
)
3989 /* Add some entries to the .dynamic section. We fill in the
3990 values later, in sh_elf_finish_dynamic_sections, but we
3991 must add the entries now so that we get the correct size for
3992 the .dynamic section. The DT_DEBUG entry is filled in by the
3993 dynamic linker and used by the debugger. */
3994 #define add_dynamic_entry(TAG, VAL) \
3995 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
3999 if (!add_dynamic_entry (DT_DEBUG
, 0))
4005 if (!add_dynamic_entry (DT_PLTGOT
, 0)
4006 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4007 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4008 || !add_dynamic_entry (DT_JMPREL
, 0))
4014 if (!add_dynamic_entry (DT_RELA
, 0)
4015 || !add_dynamic_entry (DT_RELASZ
, 0)
4016 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
4020 if ((info
->flags
& DF_TEXTREL
) != 0)
4022 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4026 #undef add_dynamic_entry
4031 /* This function is called via sh_elf_link_hash_traverse if we are
4032 creating a shared object with -Bsymbolic. It discards the space
4033 allocated to copy PC relative relocs against symbols which are
4034 defined in regular objects. We allocated space for them in the
4035 check_relocs routine, but we won't fill them in in the
4036 relocate_section routine. */
4039 sh_elf_discard_copies (h
, ignore
)
4040 struct elf_sh_link_hash_entry
*h
;
4041 PTR ignore ATTRIBUTE_UNUSED
;
4043 struct elf_sh_pcrel_relocs_copied
*s
;
4045 if (h
->root
.root
.type
== bfd_link_hash_warning
)
4046 h
= (struct elf_sh_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4048 /* We only discard relocs for symbols defined in a regular object. */
4049 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4052 for (s
= h
->pcrel_relocs_copied
; s
!= NULL
; s
= s
->next
)
4053 s
->section
->_raw_size
-= s
->count
* sizeof (Elf32_External_Rela
);
4058 /* Relocate an SH ELF section. */
4061 sh_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4062 contents
, relocs
, local_syms
, local_sections
)
4064 struct bfd_link_info
*info
;
4066 asection
*input_section
;
4068 Elf_Internal_Rela
*relocs
;
4069 Elf_Internal_Sym
*local_syms
;
4070 asection
**local_sections
;
4072 Elf_Internal_Shdr
*symtab_hdr
;
4073 struct elf_link_hash_entry
**sym_hashes
;
4074 Elf_Internal_Rela
*rel
, *relend
;
4076 bfd_vma
*local_got_offsets
;
4082 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4083 sym_hashes
= elf_sym_hashes (input_bfd
);
4084 dynobj
= elf_hash_table (info
)->dynobj
;
4085 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4093 relend
= relocs
+ input_section
->reloc_count
;
4094 for (; rel
< relend
; rel
++)
4097 reloc_howto_type
*howto
;
4098 unsigned long r_symndx
;
4099 Elf_Internal_Sym
*sym
;
4101 struct elf_link_hash_entry
*h
;
4103 bfd_vma addend
= (bfd_vma
) 0;
4104 bfd_reloc_status_type r
;
4105 int seen_stt_datalabel
= 0;
4107 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4109 r_type
= ELF32_R_TYPE (rel
->r_info
);
4111 /* Many of the relocs are only used for relaxing, and are
4112 handled entirely by the relaxation code. */
4113 if (r_type
> (int) R_SH_LAST_INVALID_RELOC
4114 && r_type
< (int) R_SH_LOOP_START
)
4116 if (r_type
== (int) R_SH_NONE
)
4120 || r_type
>= R_SH_max
4121 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
4122 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
4123 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_3
4124 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_3
)
4125 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_4
4126 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_4
)
4127 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_2
4128 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_2
))
4130 bfd_set_error (bfd_error_bad_value
);
4134 howto
= sh_elf_howto_table
+ r_type
;
4136 /* For relocs that aren't partial_inplace, we get the addend from
4138 if (! howto
->partial_inplace
)
4139 addend
= rel
->r_addend
;
4144 if (r_symndx
< symtab_hdr
->sh_info
)
4146 sym
= local_syms
+ r_symndx
;
4147 sec
= local_sections
[r_symndx
];
4148 relocation
= (sec
->output_section
->vma
4149 + sec
->output_offset
4151 /* A local symbol never has STO_SH5_ISA32, so we don't need
4152 datalabel processing here. Make sure this does not change
4154 if ((sym
->st_other
& STO_SH5_ISA32
) != 0)
4155 ((*info
->callbacks
->reloc_dangerous
)
4157 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4158 input_bfd
, input_section
, rel
->r_offset
));
4159 if (info
->relocateable
)
4161 /* This is a relocateable link. We don't have to change
4162 anything, unless the reloc is against a section symbol,
4163 in which case we have to adjust according to where the
4164 section symbol winds up in the output section. */
4165 sym
= local_syms
+ r_symndx
;
4166 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4168 if (! howto
->partial_inplace
)
4170 /* For relocations with the addend in the
4171 relocation, we need just to update the addend.
4172 All real relocs are of type partial_inplace; this
4173 code is mostly for completeness. */
4174 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
4179 /* Relocs of type partial_inplace need to pick up the
4180 contents in the contents and add the offset resulting
4181 from the changed location of the section symbol.
4182 Using _bfd_final_link_relocate (e.g. goto
4183 final_link_relocate) here would be wrong, because
4184 relocations marked pc_relative would get the current
4185 location subtracted, and we must only do that at the
4187 r
= _bfd_relocate_contents (howto
, input_bfd
,
4190 contents
+ rel
->r_offset
);
4191 goto relocation_done
;
4196 else if (! howto
->partial_inplace
)
4198 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
4199 addend
= rel
->r_addend
;
4201 else if ((sec
->flags
& SEC_MERGE
)
4202 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4206 if (howto
->rightshift
|| howto
->src_mask
!= 0xffffffff)
4208 (*_bfd_error_handler
)
4209 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
4210 bfd_archive_filename (input_bfd
),
4211 bfd_get_section_name (input_bfd
, input_section
),
4212 (long) rel
->r_offset
, howto
->name
);
4216 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4219 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
4221 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
4222 bfd_put_32 (input_bfd
, addend
, contents
+ rel
->r_offset
);
4228 /* Section symbol are never (?) placed in the hash table, so
4229 we can just ignore hash relocations when creating a
4230 relocateable object file. */
4231 if (info
->relocateable
)
4234 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4235 while (h
->root
.type
== bfd_link_hash_indirect
4236 || h
->root
.type
== bfd_link_hash_warning
)
4238 #ifdef INCLUDE_SHMEDIA
4239 /* If the reference passes a symbol marked with
4240 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4242 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
4244 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4246 if (h
->root
.type
== bfd_link_hash_defined
4247 || h
->root
.type
== bfd_link_hash_defweak
)
4249 sec
= h
->root
.u
.def
.section
;
4250 /* In these cases, we don't need the relocation value.
4251 We check specially because in some obscure cases
4252 sec->output_section will be NULL. */
4253 if (r_type
== R_SH_GOTPC
4254 || r_type
== R_SH_GOTPC_LOW16
4255 || r_type
== R_SH_GOTPC_MEDLOW16
4256 || r_type
== R_SH_GOTPC_MEDHI16
4257 || r_type
== R_SH_GOTPC_HI16
4258 || ((r_type
== R_SH_PLT32
4259 || r_type
== R_SH_PLT_LOW16
4260 || r_type
== R_SH_PLT_MEDLOW16
4261 || r_type
== R_SH_PLT_MEDHI16
4262 || r_type
== R_SH_PLT_HI16
)
4263 && h
->plt
.offset
!= (bfd_vma
) -1)
4264 || ((r_type
== R_SH_GOT32
4265 || r_type
== R_SH_GOT_LOW16
4266 || r_type
== R_SH_GOT_MEDLOW16
4267 || r_type
== R_SH_GOT_MEDHI16
4268 || r_type
== R_SH_GOT_HI16
)
4269 && elf_hash_table (info
)->dynamic_sections_created
4271 || (! info
->symbolic
&& h
->dynindx
!= -1)
4272 || (h
->elf_link_hash_flags
4273 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4274 /* The cases above are those in which relocation is
4275 overwritten in the switch block below. The cases
4276 below are those in which we must defer relocation
4277 to run-time, because we can't resolve absolute
4278 addresses when creating a shared library. */
4280 && ((! info
->symbolic
&& h
->dynindx
!= -1)
4281 || (h
->elf_link_hash_flags
4282 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
4283 && ((r_type
== R_SH_DIR32
4284 && !(ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
4285 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
))
4286 || r_type
== R_SH_REL32
)
4287 && ((input_section
->flags
& SEC_ALLOC
) != 0
4288 /* DWARF will emit R_SH_DIR32 relocations in its
4289 sections against symbols defined externally
4290 in shared libraries. We can't do anything
4292 || (input_section
->flags
& SEC_DEBUGGING
) != 0)))
4294 else if (sec
->output_section
== NULL
)
4296 (*_bfd_error_handler
)
4297 (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
4298 bfd_archive_filename (input_bfd
), h
->root
.root
.string
,
4299 bfd_get_section_name (input_bfd
, input_section
));
4303 relocation
= ((h
->root
.u
.def
.value
4304 + sec
->output_section
->vma
4305 + sec
->output_offset
)
4306 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4307 symbol value, unless we've seen
4308 STT_DATALABEL on the way to it. */
4309 | ((h
->other
& STO_SH5_ISA32
) != 0
4310 && ! seen_stt_datalabel
));
4312 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4314 else if (info
->shared
4315 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
4316 && !info
->no_undefined
)
4320 if (! ((*info
->callbacks
->undefined_symbol
)
4321 (info
, h
->root
.root
.string
, input_bfd
,
4322 input_section
, rel
->r_offset
, true)))
4328 switch ((int) r_type
)
4330 final_link_relocate
:
4331 /* COFF relocs don't use the addend. The addend is used for
4332 R_SH_DIR32 to be compatible with other compilers. */
4333 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4334 contents
, rel
->r_offset
,
4335 relocation
, addend
);
4340 goto final_link_relocate
;
4345 /* If the reloc is against the start of this section, then
4346 the assembler has already taken care of it and the reloc
4347 is here only to assist in relaxing. If the reloc is not
4348 against the start of this section, then it's against an
4349 external symbol and we must deal with it ourselves. */
4350 if (input_section
->output_section
->vma
+ input_section
->output_offset
4353 int disp
= (relocation
4354 - input_section
->output_section
->vma
4355 - input_section
->output_offset
4361 case R_SH_DIR8WPZ
: mask
= 1; break;
4362 case R_SH_DIR8WPL
: mask
= 3; break;
4363 default: mask
= 0; break;
4367 ((*_bfd_error_handler
)
4368 (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4369 bfd_archive_filename (input_section
->owner
),
4370 (unsigned long) rel
->r_offset
));
4371 bfd_set_error (bfd_error_bad_value
);
4375 goto final_link_relocate
;
4381 #ifdef INCLUDE_SHMEDIA
4382 if (shmedia_prepare_reloc (info
, input_bfd
, input_section
,
4383 contents
, rel
, &relocation
))
4384 goto final_link_relocate
;
4386 bfd_set_error (bfd_error_bad_value
);
4393 && (input_section
->flags
& SEC_ALLOC
) != 0
4394 && (r_type
!= R_SH_REL32
4397 && (! info
->symbolic
4398 || (h
->elf_link_hash_flags
4399 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
4401 Elf_Internal_Rela outrel
;
4402 boolean skip
, relocate
;
4404 /* When generating a shared object, these relocations
4405 are copied into the output file to be resolved at run
4412 name
= (bfd_elf_string_from_elf_section
4414 elf_elfheader (input_bfd
)->e_shstrndx
,
4415 elf_section_data (input_section
)->rel_hdr
.sh_name
));
4419 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
4420 && strcmp (bfd_get_section_name (input_bfd
,
4424 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4425 BFD_ASSERT (sreloc
!= NULL
);
4432 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4434 if (outrel
.r_offset
== (bfd_vma
) -1)
4436 else if (outrel
.r_offset
== (bfd_vma
) -2)
4437 skip
= true, relocate
= true;
4438 outrel
.r_offset
+= (input_section
->output_section
->vma
4439 + input_section
->output_offset
);
4442 memset (&outrel
, 0, sizeof outrel
);
4443 else if (r_type
== R_SH_REL32
)
4445 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
4446 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_REL32
);
4448 = bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4452 /* h->dynindx may be -1 if this symbol was marked to
4455 || ((info
->symbolic
|| h
->dynindx
== -1)
4456 && (h
->elf_link_hash_flags
4457 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
4460 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
4462 = relocation
+ bfd_get_32 (input_bfd
,
4463 contents
+ rel
->r_offset
);
4467 BFD_ASSERT (h
->dynindx
!= -1);
4468 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_DIR32
);
4470 = relocation
+ bfd_get_32 (input_bfd
,
4471 contents
+ rel
->r_offset
);
4475 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
4476 (((Elf32_External_Rela
*)
4478 + sreloc
->reloc_count
));
4479 ++sreloc
->reloc_count
;
4481 /* If this reloc is against an external symbol, we do
4482 not want to fiddle with the addend. Otherwise, we
4483 need to include the symbol value so that it becomes
4484 an addend for the dynamic reloc. */
4488 goto final_link_relocate
;
4491 #ifdef INCLUDE_SHMEDIA
4492 case R_SH_GOTPLT_LOW16
:
4493 case R_SH_GOTPLT_MEDLOW16
:
4494 case R_SH_GOTPLT_MEDHI16
:
4495 case R_SH_GOTPLT_HI16
:
4496 case R_SH_GOTPLT10BY4
:
4497 case R_SH_GOTPLT10BY8
:
4499 /* Relocation is to the entry for this symbol in the
4500 procedure linkage table. */
4503 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
4504 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
4508 || h
->plt
.offset
== (bfd_vma
) -1
4509 || h
->got
.offset
!= (bfd_vma
) -1)
4512 /* Relocation is to the entry for this symbol in the global
4513 offset table extension for the procedure linkage table. */
4514 if (sgotplt
== NULL
)
4516 sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
4517 BFD_ASSERT (sgotplt
!= NULL
);
4520 relocation
= (sgotplt
->output_offset
4521 + ((h
->plt
.offset
/ elf_sh_sizeof_plt (info
)
4525 relocation
-= GOT_BIAS
;
4528 goto final_link_relocate
;
4532 #ifdef INCLUDE_SHMEDIA
4533 case R_SH_GOT_LOW16
:
4534 case R_SH_GOT_MEDLOW16
:
4535 case R_SH_GOT_MEDHI16
:
4540 /* Relocation is to the entry for this symbol in the global
4544 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4545 BFD_ASSERT (sgot
!= NULL
);
4552 off
= h
->got
.offset
;
4553 #ifdef INCLUDE_SHMEDIA
4554 if (seen_stt_datalabel
)
4556 struct elf_sh_link_hash_entry
*hsh
;
4558 hsh
= (struct elf_sh_link_hash_entry
*)h
;
4559 off
= hsh
->datalabel_got_offset
;
4562 BFD_ASSERT (off
!= (bfd_vma
) -1);
4564 if (! elf_hash_table (info
)->dynamic_sections_created
4566 && (info
->symbolic
|| h
->dynindx
== -1
4567 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
4568 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
4569 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
4571 /* This is actually a static link, or it is a
4572 -Bsymbolic link and the symbol is defined
4573 locally, or the symbol was forced to be local
4574 because of a version file. We must initialize
4575 this entry in the global offset table. Since the
4576 offset must always be a multiple of 4, we use the
4577 least significant bit to record whether we have
4578 initialized it already.
4580 When doing a dynamic link, we create a .rela.got
4581 relocation entry to initialize the value. This
4582 is done in the finish_dynamic_symbol routine. */
4587 bfd_put_32 (output_bfd
, relocation
,
4588 sgot
->contents
+ off
);
4589 #ifdef INCLUDE_SHMEDIA
4590 if (seen_stt_datalabel
)
4592 struct elf_sh_link_hash_entry
*hsh
;
4594 hsh
= (struct elf_sh_link_hash_entry
*)h
;
4595 hsh
->datalabel_got_offset
|= 1;
4603 relocation
= sgot
->output_offset
+ off
;
4609 #ifdef INCLUDE_SHMEDIA
4612 BFD_ASSERT (local_got_offsets
!= NULL
4613 && (local_got_offsets
[symtab_hdr
->sh_info
4617 off
= local_got_offsets
[symtab_hdr
->sh_info
4623 BFD_ASSERT (local_got_offsets
!= NULL
4624 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
4626 off
= local_got_offsets
[r_symndx
];
4627 #ifdef INCLUDE_SHMEDIA
4631 /* The offset must always be a multiple of 4. We use
4632 the least significant bit to record whether we have
4633 already generated the necessary reloc. */
4638 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
4643 Elf_Internal_Rela outrel
;
4645 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
4646 BFD_ASSERT (srelgot
!= NULL
);
4648 outrel
.r_offset
= (sgot
->output_section
->vma
4649 + sgot
->output_offset
4651 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
4652 outrel
.r_addend
= relocation
;
4653 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
4654 (((Elf32_External_Rela
*)
4656 + srelgot
->reloc_count
));
4657 ++srelgot
->reloc_count
;
4660 #ifdef INCLUDE_SHMEDIA
4662 local_got_offsets
[symtab_hdr
->sh_info
+ r_symndx
] |= 1;
4665 local_got_offsets
[r_symndx
] |= 1;
4668 relocation
= sgot
->output_offset
+ off
;
4672 relocation
-= GOT_BIAS
;
4675 goto final_link_relocate
;
4678 #ifdef INCLUDE_SHMEDIA
4679 case R_SH_GOTOFF_LOW16
:
4680 case R_SH_GOTOFF_MEDLOW16
:
4681 case R_SH_GOTOFF_MEDHI16
:
4682 case R_SH_GOTOFF_HI16
:
4684 /* Relocation is relative to the start of the global offset
4689 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4690 BFD_ASSERT (sgot
!= NULL
);
4693 /* Note that sgot->output_offset is not involved in this
4694 calculation. We always want the start of .got. If we
4695 defined _GLOBAL_OFFSET_TABLE in a different way, as is
4696 permitted by the ABI, we might have to change this
4698 relocation
-= sgot
->output_section
->vma
;
4701 relocation
-= GOT_BIAS
;
4704 addend
= rel
->r_addend
;
4706 goto final_link_relocate
;
4709 #ifdef INCLUDE_SHMEDIA
4710 case R_SH_GOTPC_LOW16
:
4711 case R_SH_GOTPC_MEDLOW16
:
4712 case R_SH_GOTPC_MEDHI16
:
4713 case R_SH_GOTPC_HI16
:
4715 /* Use global offset table as symbol value. */
4719 sgot
= bfd_get_section_by_name (dynobj
, ".got");
4720 BFD_ASSERT (sgot
!= NULL
);
4723 relocation
= sgot
->output_section
->vma
;
4726 relocation
+= GOT_BIAS
;
4729 addend
= rel
->r_addend
;
4731 goto final_link_relocate
;
4734 #ifdef INCLUDE_SHMEDIA
4735 case R_SH_PLT_LOW16
:
4736 case R_SH_PLT_MEDLOW16
:
4737 case R_SH_PLT_MEDHI16
:
4740 /* Relocation is to the entry for this symbol in the
4741 procedure linkage table. */
4743 /* Resolve a PLT reloc against a local symbol directly,
4744 without using the procedure linkage table. */
4746 goto final_link_relocate
;
4748 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
4749 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
4750 goto final_link_relocate
;
4752 if (h
->plt
.offset
== (bfd_vma
) -1)
4754 /* We didn't make a PLT entry for this symbol. This
4755 happens when statically linking PIC code, or when
4756 using -Bsymbolic. */
4757 goto final_link_relocate
;
4762 splt
= bfd_get_section_by_name (dynobj
, ".plt");
4763 BFD_ASSERT (splt
!= NULL
);
4766 relocation
= (splt
->output_section
->vma
4767 + splt
->output_offset
4770 #ifdef INCLUDE_SHMEDIA
4774 addend
= rel
->r_addend
;
4776 goto final_link_relocate
;
4778 case R_SH_LOOP_START
:
4780 static bfd_vma start
, end
;
4782 start
= (relocation
+ rel
->r_addend
4783 - (sec
->output_section
->vma
+ sec
->output_offset
));
4784 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
4785 rel
->r_offset
, sec
, start
, end
);
4789 end
= (relocation
+ rel
->r_addend
4790 - (sec
->output_section
->vma
+ sec
->output_offset
));
4791 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
4792 rel
->r_offset
, sec
, start
, end
);
4798 if (r
!= bfd_reloc_ok
)
4803 case bfd_reloc_outofrange
:
4805 case bfd_reloc_overflow
:
4810 name
= h
->root
.root
.string
;
4813 name
= (bfd_elf_string_from_elf_section
4814 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
4818 name
= bfd_section_name (input_bfd
, sec
);
4820 if (! ((*info
->callbacks
->reloc_overflow
)
4821 (info
, name
, howto
->name
, (bfd_vma
) 0,
4822 input_bfd
, input_section
, rel
->r_offset
)))
4833 /* This is a version of bfd_generic_get_relocated_section_contents
4834 which uses sh_elf_relocate_section. */
4837 sh_elf_get_relocated_section_contents (output_bfd
, link_info
, link_order
,
4838 data
, relocateable
, symbols
)
4840 struct bfd_link_info
*link_info
;
4841 struct bfd_link_order
*link_order
;
4843 boolean relocateable
;
4846 Elf_Internal_Shdr
*symtab_hdr
;
4847 Elf_Internal_Shdr
*shndx_hdr
;
4848 asection
*input_section
= link_order
->u
.indirect
.section
;
4849 bfd
*input_bfd
= input_section
->owner
;
4850 asection
**sections
= NULL
;
4851 Elf_Internal_Rela
*internal_relocs
= NULL
;
4852 Elf32_External_Sym
*external_syms
= NULL
;
4853 Elf_External_Sym_Shndx
*shndx_buf
= NULL
;
4854 Elf_External_Sym_Shndx
*shndx
;
4855 Elf_Internal_Sym
*internal_syms
= NULL
;
4857 /* We only need to handle the case of relaxing, or of having a
4858 particular set of section contents, specially. */
4860 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
4861 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
4866 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4867 shndx_hdr
= &elf_tdata (input_bfd
)->symtab_shndx_hdr
;
4869 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
4870 (size_t) input_section
->_raw_size
);
4872 if ((input_section
->flags
& SEC_RELOC
) != 0
4873 && input_section
->reloc_count
> 0)
4875 Elf_Internal_Sym
*isymp
;
4877 Elf32_External_Sym
*esym
, *esymend
;
4880 if (symtab_hdr
->contents
!= NULL
)
4881 external_syms
= (Elf32_External_Sym
*) symtab_hdr
->contents
;
4882 else if (symtab_hdr
->sh_info
!= 0)
4884 amt
= symtab_hdr
->sh_info
;
4885 amt
*= sizeof (Elf32_External_Sym
);
4886 external_syms
= (Elf32_External_Sym
*) bfd_malloc (amt
);
4887 if (external_syms
== NULL
)
4889 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
4890 || bfd_bread ((PTR
) external_syms
, amt
, input_bfd
) != amt
)
4894 if (symtab_hdr
->sh_info
!= 0 && shndx_hdr
->sh_size
!= 0)
4896 amt
= symtab_hdr
->sh_info
;
4897 amt
*= sizeof (Elf_External_Sym_Shndx
);
4898 shndx_buf
= (Elf_External_Sym_Shndx
*) bfd_malloc (amt
);
4899 if (shndx_buf
== NULL
)
4901 if (bfd_seek (input_bfd
, shndx_hdr
->sh_offset
, SEEK_SET
) != 0
4902 || bfd_bread ((PTR
) shndx_buf
, amt
, input_bfd
) != amt
)
4906 internal_relocs
= (_bfd_elf32_link_read_relocs
4907 (input_bfd
, input_section
, (PTR
) NULL
,
4908 (Elf_Internal_Rela
*) NULL
, false));
4909 if (internal_relocs
== NULL
)
4912 amt
= symtab_hdr
->sh_info
;
4913 amt
*= sizeof (Elf_Internal_Sym
);
4914 internal_syms
= (Elf_Internal_Sym
*) bfd_malloc (amt
);
4915 if (internal_syms
== NULL
&& amt
!= 0)
4918 amt
= symtab_hdr
->sh_info
;
4919 amt
*= sizeof (asection
*);
4920 sections
= (asection
**) bfd_malloc (amt
);
4921 if (sections
== NULL
&& amt
!= 0)
4924 for (isymp
= internal_syms
, secpp
= sections
, shndx
= shndx_buf
,
4925 esym
= external_syms
, esymend
= esym
+ symtab_hdr
->sh_info
;
4927 ++esym
, ++isymp
, ++secpp
, shndx
= (shndx
? shndx
+ 1 : NULL
))
4931 bfd_elf32_swap_symbol_in (input_bfd
, (const PTR
) esym
,
4932 (const PTR
) shndx
, isymp
);
4934 if (isymp
->st_shndx
== SHN_UNDEF
)
4935 isec
= bfd_und_section_ptr
;
4936 else if (isymp
->st_shndx
== SHN_ABS
)
4937 isec
= bfd_abs_section_ptr
;
4938 else if (isymp
->st_shndx
== SHN_COMMON
)
4939 isec
= bfd_com_section_ptr
;
4941 isec
= bfd_section_from_elf_index (input_bfd
, isymp
->st_shndx
);
4946 if (! sh_elf_relocate_section (output_bfd
, link_info
, input_bfd
,
4947 input_section
, data
, internal_relocs
,
4948 internal_syms
, sections
))
4951 if (sections
!= NULL
)
4953 if (internal_syms
!= NULL
)
4954 free (internal_syms
);
4955 if (shndx_buf
!= NULL
)
4957 if (external_syms
!= NULL
&& symtab_hdr
->contents
== NULL
)
4958 free (external_syms
);
4959 if (internal_relocs
!= elf_section_data (input_section
)->relocs
)
4960 free (internal_relocs
);
4966 if (internal_relocs
!= NULL
4967 && internal_relocs
!= elf_section_data (input_section
)->relocs
)
4968 free (internal_relocs
);
4969 if (shndx_buf
!= NULL
)
4971 if (external_syms
!= NULL
&& symtab_hdr
->contents
== NULL
)
4972 free (external_syms
);
4973 if (internal_syms
!= NULL
)
4974 free (internal_syms
);
4975 if (sections
!= NULL
)
4981 sh_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
4983 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
4984 Elf_Internal_Rela
*rel
;
4985 struct elf_link_hash_entry
*h
;
4986 Elf_Internal_Sym
*sym
;
4990 switch (ELF32_R_TYPE (rel
->r_info
))
4992 case R_SH_GNU_VTINHERIT
:
4993 case R_SH_GNU_VTENTRY
:
4997 switch (h
->root
.type
)
4999 case bfd_link_hash_defined
:
5000 case bfd_link_hash_defweak
:
5001 return h
->root
.u
.def
.section
;
5003 case bfd_link_hash_common
:
5004 return h
->root
.u
.c
.p
->section
;
5013 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
5019 /* Update the got entry reference counts for the section being removed. */
5022 sh_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
5023 bfd
*abfd ATTRIBUTE_UNUSED
;
5024 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
5025 asection
*sec ATTRIBUTE_UNUSED
;
5026 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
5028 /* We use got and plt entries for sh, but it would seem that the
5029 existing SH code does no sort of reference counting or whatnot on
5030 its GOT and PLT entries, so it is not possible to garbage collect
5031 them at this time. */
5035 /* Look through the relocs for a section during the first phase.
5036 Since we don't do .gots or .plts, we just need to consider the
5037 virtual table relocs for gc. */
5040 sh_elf_check_relocs (abfd
, info
, sec
, relocs
)
5042 struct bfd_link_info
*info
;
5044 const Elf_Internal_Rela
*relocs
;
5046 Elf_Internal_Shdr
*symtab_hdr
;
5047 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
5048 const Elf_Internal_Rela
*rel
;
5049 const Elf_Internal_Rela
*rel_end
;
5051 bfd_vma
*local_got_offsets
;
5060 if (info
->relocateable
)
5063 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5064 sym_hashes
= elf_sym_hashes (abfd
);
5065 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof (Elf32_External_Sym
);
5066 if (!elf_bad_symtab (abfd
))
5067 sym_hashes_end
-= symtab_hdr
->sh_info
;
5069 dynobj
= elf_hash_table (info
)->dynobj
;
5070 local_got_offsets
= elf_local_got_offsets (abfd
);
5072 rel_end
= relocs
+ sec
->reloc_count
;
5073 for (rel
= relocs
; rel
< rel_end
; rel
++)
5075 struct elf_link_hash_entry
*h
;
5076 unsigned long r_symndx
;
5078 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5079 if (r_symndx
< symtab_hdr
->sh_info
)
5082 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5084 /* Some relocs require a global offset table. */
5087 switch (ELF32_R_TYPE (rel
->r_info
))
5093 #ifdef INCLUDE_SHMEDIA
5094 case R_SH_GOTPLT_LOW16
:
5095 case R_SH_GOTPLT_MEDLOW16
:
5096 case R_SH_GOTPLT_MEDHI16
:
5097 case R_SH_GOTPLT_HI16
:
5098 case R_SH_GOTPLT10BY4
:
5099 case R_SH_GOTPLT10BY8
:
5100 case R_SH_GOT_LOW16
:
5101 case R_SH_GOT_MEDLOW16
:
5102 case R_SH_GOT_MEDHI16
:
5106 case R_SH_GOTOFF_LOW16
:
5107 case R_SH_GOTOFF_MEDLOW16
:
5108 case R_SH_GOTOFF_MEDHI16
:
5109 case R_SH_GOTOFF_HI16
:
5110 case R_SH_GOTPC_LOW16
:
5111 case R_SH_GOTPC_MEDLOW16
:
5112 case R_SH_GOTPC_MEDHI16
:
5113 case R_SH_GOTPC_HI16
:
5115 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
5116 if (! _bfd_elf_create_got_section (dynobj
, info
))
5125 switch (ELF32_R_TYPE (rel
->r_info
))
5127 /* This relocation describes the C++ object vtable hierarchy.
5128 Reconstruct it for later use during GC. */
5129 case R_SH_GNU_VTINHERIT
:
5130 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5134 /* This relocation describes which C++ vtable entries are actually
5135 used. Record for later use during GC. */
5136 case R_SH_GNU_VTENTRY
:
5137 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
5143 #ifdef INCLUDE_SHMEDIA
5144 case R_SH_GOT_LOW16
:
5145 case R_SH_GOT_MEDLOW16
:
5146 case R_SH_GOT_MEDHI16
:
5151 /* This symbol requires a global offset table entry. */
5155 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5156 BFD_ASSERT (sgot
!= NULL
);
5160 && (h
!= NULL
|| info
->shared
))
5162 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
5163 if (srelgot
== NULL
)
5165 srelgot
= bfd_make_section (dynobj
, ".rela.got");
5167 || ! bfd_set_section_flags (dynobj
, srelgot
,
5172 | SEC_LINKER_CREATED
5174 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
5181 #ifdef INCLUDE_SHMEDIA
5182 if (h
->type
== STT_DATALABEL
)
5184 struct elf_sh_link_hash_entry
*hsh
;
5186 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5187 hsh
= (struct elf_sh_link_hash_entry
*)h
;
5188 if (hsh
->datalabel_got_offset
!= (bfd_vma
) -1)
5191 hsh
->datalabel_got_offset
= sgot
->_raw_size
;
5196 if (h
->got
.offset
!= (bfd_vma
) -1)
5198 /* We have already allocated space in the .got. */
5201 h
->got
.offset
= sgot
->_raw_size
;
5202 #ifdef INCLUDE_SHMEDIA
5206 /* Make sure this symbol is output as a dynamic symbol. */
5207 if (h
->dynindx
== -1)
5209 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5213 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
5217 /* This is a global offset table entry for a local
5219 if (local_got_offsets
== NULL
)
5222 register unsigned int i
;
5224 size
= symtab_hdr
->sh_info
;
5225 size
*= sizeof (bfd_vma
);
5226 #ifdef INCLUDE_SHMEDIA
5227 /* Reserve space for both the datalabel and
5228 codelabel local GOT offsets. */
5231 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
5232 if (local_got_offsets
== NULL
)
5234 elf_local_got_offsets (abfd
) = local_got_offsets
;
5235 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
5236 local_got_offsets
[i
] = (bfd_vma
) -1;
5237 #ifdef INCLUDE_SHMEDIA
5238 for (; i
< 2 * symtab_hdr
->sh_info
; i
++)
5239 local_got_offsets
[i
] = (bfd_vma
) -1;
5242 #ifdef INCLUDE_SHMEDIA
5243 if ((rel
->r_addend
& 1) != 0)
5245 if (local_got_offsets
[symtab_hdr
->sh_info
5246 + r_symndx
] != (bfd_vma
) -1)
5248 /* We have already allocated space in the .got. */
5251 local_got_offsets
[symtab_hdr
->sh_info
5252 + r_symndx
] = sgot
->_raw_size
;
5257 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
5259 /* We have already allocated space in the .got. */
5262 local_got_offsets
[r_symndx
] = sgot
->_raw_size
;
5263 #ifdef INCLUDE_SHMEDIA
5269 /* If we are generating a shared object, we need to
5270 output a R_SH_RELATIVE reloc so that the dynamic
5271 linker can adjust this GOT entry. */
5272 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
5276 sgot
->_raw_size
+= 4;
5281 #ifdef INCLUDE_SHMEDIA
5282 case R_SH_GOTPLT_LOW16
:
5283 case R_SH_GOTPLT_MEDLOW16
:
5284 case R_SH_GOTPLT_MEDHI16
:
5285 case R_SH_GOTPLT_HI16
:
5286 case R_SH_GOTPLT10BY4
:
5287 case R_SH_GOTPLT10BY8
:
5289 /* If this is a local symbol, we resolve it directly without
5290 creating a procedure linkage table entry. */
5293 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
5294 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
5298 || h
->got
.offset
!= (bfd_vma
) -1)
5301 /* Make sure this symbol is output as a dynamic symbol. */
5302 if (h
->dynindx
== -1)
5304 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
5308 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
5313 #ifdef INCLUDE_SHMEDIA
5314 case R_SH_PLT_LOW16
:
5315 case R_SH_PLT_MEDLOW16
:
5316 case R_SH_PLT_MEDHI16
:
5319 /* This symbol requires a procedure linkage table entry. We
5320 actually build the entry in adjust_dynamic_symbol,
5321 because this might be a case of linking PIC code which is
5322 never referenced by a dynamic object, in which case we
5323 don't need to generate a procedure linkage table entry
5326 /* If this is a local symbol, we resolve it directly without
5327 creating a procedure linkage table entry. */
5331 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
5332 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
5335 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
5342 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
5344 /* If we are creating a shared library, and this is a reloc
5345 against a global symbol, or a non PC relative reloc
5346 against a local symbol, then we need to copy the reloc
5347 into the shared library. However, if we are linking with
5348 -Bsymbolic, we do not need to copy a reloc against a
5349 global symbol which is defined in an object we are
5350 including in the link (i.e., DEF_REGULAR is set). At
5351 this point we have not seen all the input files, so it is
5352 possible that DEF_REGULAR is not set now but will be set
5353 later (it is never cleared). We account for that
5354 possibility below by storing information in the
5355 pcrel_relocs_copied field of the hash table entry. */
5357 && (sec
->flags
& SEC_ALLOC
) != 0
5358 && (ELF32_R_TYPE (rel
->r_info
) != R_SH_REL32
5360 && (! info
->symbolic
5361 || (h
->elf_link_hash_flags
5362 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
5364 /* When creating a shared object, we must copy these
5365 reloc types into the output file. We create a reloc
5366 section in dynobj and make room for this reloc. */
5371 name
= (bfd_elf_string_from_elf_section
5373 elf_elfheader (abfd
)->e_shstrndx
,
5374 elf_section_data (sec
)->rel_hdr
.sh_name
));
5378 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5379 && strcmp (bfd_get_section_name (abfd
, sec
),
5382 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5387 sreloc
= bfd_make_section (dynobj
, name
);
5388 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
5389 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
5390 if ((sec
->flags
& SEC_ALLOC
) != 0)
5391 flags
|= SEC_ALLOC
| SEC_LOAD
;
5393 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
5394 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
5397 if (sec
->flags
& SEC_READONLY
)
5398 info
->flags
|= DF_TEXTREL
;
5401 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
5403 /* If we are linking with -Bsymbolic, and this is a
5404 global symbol, we count the number of PC relative
5405 relocations we have entered for this symbol, so that
5406 we can discard them again if the symbol is later
5407 defined by a regular object. Note that this function
5408 is only called if we are using an elf_sh linker
5409 hash table, which means that h is really a pointer to
5410 an elf_sh_link_hash_entry. */
5411 if (h
!= NULL
&& info
->symbolic
5412 && ELF32_R_TYPE (rel
->r_info
) == R_SH_REL32
)
5414 struct elf_sh_link_hash_entry
*eh
;
5415 struct elf_sh_pcrel_relocs_copied
*p
;
5417 eh
= (struct elf_sh_link_hash_entry
*) h
;
5419 for (p
= eh
->pcrel_relocs_copied
; p
!= NULL
; p
= p
->next
)
5420 if (p
->section
== sreloc
)
5425 p
= ((struct elf_sh_pcrel_relocs_copied
*)
5426 bfd_alloc (dynobj
, (bfd_size_type
) sizeof *p
));
5429 p
->next
= eh
->pcrel_relocs_copied
;
5430 eh
->pcrel_relocs_copied
= p
;
5431 p
->section
= sreloc
;
5446 #ifndef sh_elf_set_mach_from_flags
5448 sh_elf_set_mach_from_flags (abfd
)
5451 flagword flags
= elf_elfheader (abfd
)->e_flags
;
5453 switch (flags
& EF_SH_MACH_MASK
)
5456 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh
);
5459 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh2
);
5462 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh_dsp
);
5465 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3
);
5468 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3_dsp
);
5471 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3e
);
5475 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh4
);
5482 #endif /* not sh_elf_set_mach_from_flags */
5484 #ifndef sh_elf_set_private_flags
5485 /* Function to keep SH specific file flags. */
5488 sh_elf_set_private_flags (abfd
, flags
)
5492 BFD_ASSERT (! elf_flags_init (abfd
)
5493 || elf_elfheader (abfd
)->e_flags
== flags
);
5495 elf_elfheader (abfd
)->e_flags
= flags
;
5496 elf_flags_init (abfd
) = true;
5497 return sh_elf_set_mach_from_flags (abfd
);
5499 #endif /* not sh_elf_set_private_flags */
5501 #ifndef sh_elf_copy_private_data
5502 /* Copy backend specific data from one object module to another */
5505 sh_elf_copy_private_data (ibfd
, obfd
)
5509 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
5510 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
5513 return sh_elf_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
5515 #endif /* not sh_elf_copy_private_data */
5517 #ifndef sh_elf_merge_private_data
5518 /* This routine checks for linking big and little endian objects
5519 together, and for linking sh-dsp with sh3e / sh4 objects. */
5522 sh_elf_merge_private_data (ibfd
, obfd
)
5526 flagword old_flags
, new_flags
;
5528 if (_bfd_generic_verify_endian_match (ibfd
, obfd
) == false)
5531 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
5532 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
5535 if (! elf_flags_init (obfd
))
5537 /* This happens when ld starts out with a 'blank' output file. */
5538 elf_flags_init (obfd
) = true;
5539 elf_elfheader (obfd
)->e_flags
= EF_SH1
;
5541 old_flags
= elf_elfheader (obfd
)->e_flags
;
5542 new_flags
= elf_elfheader (ibfd
)->e_flags
;
5543 if ((EF_SH_HAS_DSP (old_flags
) && EF_SH_HAS_FP (new_flags
))
5544 || (EF_SH_HAS_DSP (new_flags
) && EF_SH_HAS_FP (old_flags
)))
5546 (*_bfd_error_handler
)
5547 ("%s: uses %s instructions while previous modules use %s instructions",
5548 bfd_archive_filename (ibfd
),
5549 EF_SH_HAS_DSP (new_flags
) ? "dsp" : "floating point",
5550 EF_SH_HAS_DSP (new_flags
) ? "floating point" : "dsp");
5551 bfd_set_error (bfd_error_bad_value
);
5554 elf_elfheader (obfd
)->e_flags
= EF_SH_MERGE_MACH (old_flags
, new_flags
);
5556 return sh_elf_set_mach_from_flags (obfd
);
5558 #endif /* not sh_elf_merge_private_data */
5560 /* Finish up dynamic symbol handling. We set the contents of various
5561 dynamic sections here. */
5564 sh_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5566 struct bfd_link_info
*info
;
5567 struct elf_link_hash_entry
*h
;
5568 Elf_Internal_Sym
*sym
;
5572 dynobj
= elf_hash_table (info
)->dynobj
;
5574 if (h
->plt
.offset
!= (bfd_vma
) -1)
5582 Elf_Internal_Rela rel
;
5584 /* This symbol has an entry in the procedure linkage table. Set
5587 BFD_ASSERT (h
->dynindx
!= -1);
5589 splt
= bfd_get_section_by_name (dynobj
, ".plt");
5590 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
5591 srel
= bfd_get_section_by_name (dynobj
, ".rela.plt");
5592 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
5594 /* Get the index in the procedure linkage table which
5595 corresponds to this symbol. This is the index of this symbol
5596 in all the symbols for which we are making plt entries. The
5597 first entry in the procedure linkage table is reserved. */
5598 plt_index
= h
->plt
.offset
/ elf_sh_sizeof_plt (info
) - 1;
5600 /* Get the offset into the .got table of the entry that
5601 corresponds to this function. Each .got entry is 4 bytes.
5602 The first three are reserved. */
5603 got_offset
= (plt_index
+ 3) * 4;
5606 got_offset
-= GOT_BIAS
;
5609 /* Fill in the entry in the procedure linkage table. */
5612 if (elf_sh_plt_entry
== NULL
)
5614 elf_sh_plt_entry
= (bfd_big_endian (output_bfd
) ?
5615 elf_sh_plt_entry_be
: elf_sh_plt_entry_le
);
5617 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_plt_entry
,
5618 elf_sh_sizeof_plt (info
));
5619 #ifdef INCLUDE_SHMEDIA
5620 movi_shori_putval (output_bfd
,
5621 (sgot
->output_section
->vma
5622 + sgot
->output_offset
5624 (splt
->contents
+ h
->plt
.offset
5625 + elf_sh_plt_symbol_offset (info
)));
5627 movi_shori_putval (output_bfd
,
5628 (splt
->output_section
->vma
+ splt
->output_offset
),
5629 (splt
->contents
+ h
->plt
.offset
5630 + elf_sh_plt_plt0_offset (info
)));
5632 bfd_put_32 (output_bfd
,
5633 (sgot
->output_section
->vma
5634 + sgot
->output_offset
5636 (splt
->contents
+ h
->plt
.offset
5637 + elf_sh_plt_symbol_offset (info
)));
5639 bfd_put_32 (output_bfd
,
5640 (splt
->output_section
->vma
+ splt
->output_offset
),
5641 (splt
->contents
+ h
->plt
.offset
5642 + elf_sh_plt_plt0_offset (info
)));
5647 if (elf_sh_pic_plt_entry
== NULL
)
5649 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
5650 elf_sh_pic_plt_entry_be
:
5651 elf_sh_pic_plt_entry_le
);
5653 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_pic_plt_entry
,
5654 elf_sh_sizeof_plt (info
));
5655 #ifdef INCLUDE_SHMEDIA
5656 movi_shori_putval (output_bfd
, got_offset
,
5657 (splt
->contents
+ h
->plt
.offset
5658 + elf_sh_plt_symbol_offset (info
)));
5660 bfd_put_32 (output_bfd
, got_offset
,
5661 (splt
->contents
+ h
->plt
.offset
5662 + elf_sh_plt_symbol_offset (info
)));
5667 got_offset
+= GOT_BIAS
;
5670 #ifdef INCLUDE_SHMEDIA
5671 movi_shori_putval (output_bfd
,
5672 plt_index
* sizeof (Elf32_External_Rela
),
5673 (splt
->contents
+ h
->plt
.offset
5674 + elf_sh_plt_reloc_offset (info
)));
5676 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
5677 (splt
->contents
+ h
->plt
.offset
5678 + elf_sh_plt_reloc_offset (info
)));
5681 /* Fill in the entry in the global offset table. */
5682 bfd_put_32 (output_bfd
,
5683 (splt
->output_section
->vma
5684 + splt
->output_offset
5686 + elf_sh_plt_temp_offset (info
)),
5687 sgot
->contents
+ got_offset
);
5689 /* Fill in the entry in the .rela.plt section. */
5690 rel
.r_offset
= (sgot
->output_section
->vma
5691 + sgot
->output_offset
5693 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_JMP_SLOT
);
5696 rel
.r_addend
= GOT_BIAS
;
5698 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
5699 ((Elf32_External_Rela
*) srel
->contents
5702 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5704 /* Mark the symbol as undefined, rather than as defined in
5705 the .plt section. Leave the value alone. */
5706 sym
->st_shndx
= SHN_UNDEF
;
5710 if (h
->got
.offset
!= (bfd_vma
) -1)
5714 Elf_Internal_Rela rel
;
5716 /* This symbol has an entry in the global offset table. Set it
5719 sgot
= bfd_get_section_by_name (dynobj
, ".got");
5720 srel
= bfd_get_section_by_name (dynobj
, ".rela.got");
5721 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
5723 rel
.r_offset
= (sgot
->output_section
->vma
5724 + sgot
->output_offset
5725 + (h
->got
.offset
&~ (bfd_vma
) 1));
5727 /* If this is a -Bsymbolic link, and the symbol is defined
5728 locally, we just want to emit a RELATIVE reloc. Likewise if
5729 the symbol was forced to be local because of a version file.
5730 The entry in the global offset table will already have been
5731 initialized in the relocate_section function. */
5733 && (info
->symbolic
|| h
->dynindx
== -1)
5734 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
5736 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
5737 rel
.r_addend
= (h
->root
.u
.def
.value
5738 + h
->root
.u
.def
.section
->output_section
->vma
5739 + h
->root
.u
.def
.section
->output_offset
);
5743 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
5744 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
5748 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
5749 ((Elf32_External_Rela
*) srel
->contents
5750 + srel
->reloc_count
));
5751 ++srel
->reloc_count
;
5754 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
5757 Elf_Internal_Rela rel
;
5759 /* This symbol needs a copy reloc. Set it up. */
5761 BFD_ASSERT (h
->dynindx
!= -1
5762 && (h
->root
.type
== bfd_link_hash_defined
5763 || h
->root
.type
== bfd_link_hash_defweak
));
5765 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
5767 BFD_ASSERT (s
!= NULL
);
5769 rel
.r_offset
= (h
->root
.u
.def
.value
5770 + h
->root
.u
.def
.section
->output_section
->vma
5771 + h
->root
.u
.def
.section
->output_offset
);
5772 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_COPY
);
5774 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
5775 ((Elf32_External_Rela
*) s
->contents
5780 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5781 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
5782 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
5783 sym
->st_shndx
= SHN_ABS
;
5788 /* Finish up the dynamic sections. */
5791 sh_elf_finish_dynamic_sections (output_bfd
, info
)
5793 struct bfd_link_info
*info
;
5799 dynobj
= elf_hash_table (info
)->dynobj
;
5801 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
5802 BFD_ASSERT (sgot
!= NULL
);
5803 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5805 if (elf_hash_table (info
)->dynamic_sections_created
)
5808 Elf32_External_Dyn
*dyncon
, *dynconend
;
5810 BFD_ASSERT (sdyn
!= NULL
);
5812 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
5813 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
5814 for (; dyncon
< dynconend
; dyncon
++)
5816 Elf_Internal_Dyn dyn
;
5820 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5834 s
= bfd_get_section_by_name (output_bfd
, name
);
5835 BFD_ASSERT (s
!= NULL
);
5836 dyn
.d_un
.d_ptr
= s
->vma
;
5837 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5841 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
5842 BFD_ASSERT (s
!= NULL
);
5843 if (s
->_cooked_size
!= 0)
5844 dyn
.d_un
.d_val
= s
->_cooked_size
;
5846 dyn
.d_un
.d_val
= s
->_raw_size
;
5847 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5851 /* My reading of the SVR4 ABI indicates that the
5852 procedure linkage table relocs (DT_JMPREL) should be
5853 included in the overall relocs (DT_RELA). This is
5854 what Solaris does. However, UnixWare can not handle
5855 that case. Therefore, we override the DT_RELASZ entry
5856 here to make it not include the JMPREL relocs. Since
5857 the linker script arranges for .rela.plt to follow all
5858 other relocation sections, we don't have to worry
5859 about changing the DT_RELA entry. */
5860 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
5863 if (s
->_cooked_size
!= 0)
5864 dyn
.d_un
.d_val
-= s
->_cooked_size
;
5866 dyn
.d_un
.d_val
-= s
->_raw_size
;
5868 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5873 /* Fill in the first entry in the procedure linkage table. */
5874 splt
= bfd_get_section_by_name (dynobj
, ".plt");
5875 if (splt
&& splt
->_raw_size
> 0)
5879 if (elf_sh_pic_plt_entry
== NULL
)
5881 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
5882 elf_sh_pic_plt_entry_be
:
5883 elf_sh_pic_plt_entry_le
);
5885 memcpy (splt
->contents
, elf_sh_pic_plt_entry
,
5886 elf_sh_sizeof_plt (info
));
5890 if (elf_sh_plt0_entry
== NULL
)
5892 elf_sh_plt0_entry
= (bfd_big_endian (output_bfd
) ?
5893 elf_sh_plt0_entry_be
:
5894 elf_sh_plt0_entry_le
);
5896 memcpy (splt
->contents
, elf_sh_plt0_entry
, PLT_ENTRY_SIZE
);
5897 #ifdef INCLUDE_SHMEDIA
5898 movi_shori_putval (output_bfd
,
5899 sgot
->output_section
->vma
5900 + sgot
->output_offset
,
5902 + elf_sh_plt0_gotplt_offset (info
));
5904 bfd_put_32 (output_bfd
,
5905 sgot
->output_section
->vma
+ sgot
->output_offset
+ 4,
5906 splt
->contents
+ elf_sh_plt0_gotid_offset (info
));
5907 bfd_put_32 (output_bfd
,
5908 sgot
->output_section
->vma
+ sgot
->output_offset
+ 8,
5909 splt
->contents
+ elf_sh_plt0_linker_offset (info
));
5913 /* UnixWare sets the entsize of .plt to 4, although that doesn't
5914 really seem like the right value. */
5915 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
5919 /* Fill in the first three entries in the global offset table. */
5920 if (sgot
->_raw_size
> 0)
5923 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
5925 bfd_put_32 (output_bfd
,
5926 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
5928 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
5929 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
5932 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
5937 static enum elf_reloc_type_class
5938 sh_elf_reloc_type_class (rela
)
5939 const Elf_Internal_Rela
*rela
;
5941 switch ((int) ELF32_R_TYPE (rela
->r_info
))
5944 return reloc_class_relative
;
5946 return reloc_class_plt
;
5948 return reloc_class_copy
;
5950 return reloc_class_normal
;
5955 #define TARGET_BIG_SYM bfd_elf32_sh_vec
5956 #define TARGET_BIG_NAME "elf32-sh"
5957 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
5958 #define TARGET_LITTLE_NAME "elf32-shl"
5959 #define ELF_ARCH bfd_arch_sh
5960 #define ELF_MACHINE_CODE EM_SH
5961 #define ELF_MAXPAGESIZE 128
5963 #define elf_symbol_leading_char '_'
5964 #endif /* ELF_ARCH */
5966 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
5967 #define elf_info_to_howto sh_elf_info_to_howto
5968 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
5969 #define elf_backend_relocate_section sh_elf_relocate_section
5970 #define bfd_elf32_bfd_get_relocated_section_contents \
5971 sh_elf_get_relocated_section_contents
5972 #define elf_backend_object_p sh_elf_set_mach_from_flags
5973 #define bfd_elf32_bfd_set_private_bfd_flags \
5974 sh_elf_set_private_flags
5975 #define bfd_elf32_bfd_copy_private_bfd_data \
5976 sh_elf_copy_private_data
5977 #define bfd_elf32_bfd_merge_private_bfd_data \
5978 sh_elf_merge_private_data
5980 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
5981 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
5982 #define elf_backend_check_relocs sh_elf_check_relocs
5984 #define elf_backend_can_gc_sections 1
5985 #define elf_backend_create_dynamic_sections \
5986 sh_elf_create_dynamic_sections
5987 #define bfd_elf32_bfd_link_hash_table_create \
5988 sh_elf_link_hash_table_create
5989 #define elf_backend_adjust_dynamic_symbol \
5990 sh_elf_adjust_dynamic_symbol
5991 #define elf_backend_size_dynamic_sections \
5992 sh_elf_size_dynamic_sections
5993 #define elf_backend_finish_dynamic_symbol \
5994 sh_elf_finish_dynamic_symbol
5995 #define elf_backend_finish_dynamic_sections \
5996 sh_elf_finish_dynamic_sections
5997 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
5999 #define elf_backend_want_got_plt 1
6000 #define elf_backend_plt_readonly 1
6001 #define elf_backend_want_plt_sym 0
6002 #define elf_backend_got_header_size 12
6003 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
6004 #include "elf32-target.h"