1 /* Hitachi SH specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Ian Lance Taylor, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 static bfd_reloc_status_type sh_elf_reloc
30 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
31 static bfd_reloc_status_type sh_elf_ignore_reloc
32 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
33 static reloc_howto_type
*sh_elf_reloc_type_lookup
34 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
35 static void sh_elf_info_to_howto
36 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
37 static boolean sh_elf_set_private_flags
38 PARAMS ((bfd
*, flagword
));
39 static boolean sh_elf_copy_private_data
40 PARAMS ((bfd
*, bfd
*));
41 static boolean sh_elf_merge_private_data
42 PARAMS ((bfd
*, bfd
*));
43 static boolean sh_elf_set_mach_from_flags
45 static boolean sh_elf_relax_section
46 PARAMS ((bfd
*, asection
*, struct bfd_link_info
*, boolean
*));
47 static boolean sh_elf_relax_delete_bytes
48 PARAMS ((bfd
*, asection
*, bfd_vma
, int));
49 static boolean sh_elf_align_loads
50 PARAMS ((bfd
*, asection
*, Elf_Internal_Rela
*, bfd_byte
*, boolean
*));
51 static boolean sh_elf_swap_insns
52 PARAMS ((bfd
*, asection
*, PTR
, bfd_byte
*, bfd_vma
));
53 static boolean sh_elf_relocate_section
54 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
55 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
56 static bfd_byte
*sh_elf_get_relocated_section_contents
57 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
58 bfd_byte
*, boolean
, asymbol
**));
59 static void sh_elf_copy_indirect_symbol
60 PARAMS ((struct elf_backend_data
*, struct elf_link_hash_entry
*,
61 struct elf_link_hash_entry
*));
62 static boolean sh_elf_check_relocs
63 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
64 const Elf_Internal_Rela
*));
65 static struct bfd_hash_entry
*sh_elf_link_hash_newfunc
66 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
67 static struct bfd_link_hash_table
*sh_elf_link_hash_table_create
69 static boolean sh_elf_adjust_dynamic_symbol
70 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
71 static boolean sh_elf_size_dynamic_sections
72 PARAMS ((bfd
*, struct bfd_link_info
*));
73 static boolean sh_elf_finish_dynamic_symbol
74 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
76 static boolean sh_elf_finish_dynamic_sections
77 PARAMS ((bfd
*, struct bfd_link_info
*));
78 static bfd_reloc_status_type sh_elf_reloc_loop
79 PARAMS ((int, bfd
*, asection
*, bfd_byte
*, bfd_vma
, asection
*,
81 static boolean create_got_section
82 PARAMS((bfd
*, struct bfd_link_info
*));
83 static boolean sh_elf_create_dynamic_sections
84 PARAMS ((bfd
*, struct bfd_link_info
*));
85 static asection
* sh_elf_gc_mark_hook
86 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
87 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
88 static boolean sh_elf_gc_sweep_hook
89 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
90 const Elf_Internal_Rela
*));
91 static boolean allocate_dynrelocs
92 PARAMS ((struct elf_link_hash_entry
*, PTR
));
93 static boolean readonly_dynrelocs
94 PARAMS ((struct elf_link_hash_entry
*, PTR
));
95 static enum elf_reloc_type_class sh_elf_reloc_type_class
96 PARAMS ((const Elf_Internal_Rela
*));
97 #ifdef INCLUDE_SHMEDIA
98 inline static void movi_shori_putval
PARAMS ((bfd
*, unsigned long, char *));
101 /* The name of the dynamic interpreter. This is put in the .interp
104 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
106 static reloc_howto_type sh_elf_howto_table
[] =
109 HOWTO (R_SH_NONE
, /* type */
111 0, /* size (0 = byte, 1 = short, 2 = long) */
113 false, /* pc_relative */
115 complain_overflow_dont
, /* complain_on_overflow */
116 sh_elf_ignore_reloc
, /* special_function */
117 "R_SH_NONE", /* name */
118 false, /* partial_inplace */
121 false), /* pcrel_offset */
123 /* 32 bit absolute relocation. Setting partial_inplace to true and
124 src_mask to a non-zero value is similar to the COFF toolchain. */
125 HOWTO (R_SH_DIR32
, /* type */
127 2, /* size (0 = byte, 1 = short, 2 = long) */
129 false, /* pc_relative */
131 complain_overflow_bitfield
, /* complain_on_overflow */
132 sh_elf_reloc
, /* special_function */
133 "R_SH_DIR32", /* name */
134 true, /* partial_inplace */
135 0xffffffff, /* src_mask */
136 0xffffffff, /* dst_mask */
137 false), /* pcrel_offset */
139 /* 32 bit PC relative relocation. */
140 HOWTO (R_SH_REL32
, /* type */
142 2, /* size (0 = byte, 1 = short, 2 = long) */
144 true, /* pc_relative */
146 complain_overflow_signed
, /* complain_on_overflow */
147 sh_elf_ignore_reloc
, /* special_function */
148 "R_SH_REL32", /* name */
149 true, /* partial_inplace */
150 0xffffffff, /* src_mask */
151 0xffffffff, /* dst_mask */
152 true), /* pcrel_offset */
154 /* 8 bit PC relative branch divided by 2. */
155 HOWTO (R_SH_DIR8WPN
, /* type */
157 1, /* size (0 = byte, 1 = short, 2 = long) */
159 true, /* pc_relative */
161 complain_overflow_signed
, /* complain_on_overflow */
162 sh_elf_ignore_reloc
, /* special_function */
163 "R_SH_DIR8WPN", /* name */
164 true, /* partial_inplace */
167 true), /* pcrel_offset */
169 /* 12 bit PC relative branch divided by 2. */
170 HOWTO (R_SH_IND12W
, /* type */
172 1, /* size (0 = byte, 1 = short, 2 = long) */
174 true, /* pc_relative */
176 complain_overflow_signed
, /* complain_on_overflow */
177 sh_elf_reloc
, /* special_function */
178 "R_SH_IND12W", /* name */
179 true, /* partial_inplace */
180 0xfff, /* src_mask */
181 0xfff, /* dst_mask */
182 true), /* pcrel_offset */
184 /* 8 bit unsigned PC relative divided by 4. */
185 HOWTO (R_SH_DIR8WPL
, /* type */
187 1, /* size (0 = byte, 1 = short, 2 = long) */
189 true, /* pc_relative */
191 complain_overflow_unsigned
, /* complain_on_overflow */
192 sh_elf_ignore_reloc
, /* special_function */
193 "R_SH_DIR8WPL", /* name */
194 true, /* partial_inplace */
197 true), /* pcrel_offset */
199 /* 8 bit unsigned PC relative divided by 2. */
200 HOWTO (R_SH_DIR8WPZ
, /* type */
202 1, /* size (0 = byte, 1 = short, 2 = long) */
204 true, /* pc_relative */
206 complain_overflow_unsigned
, /* complain_on_overflow */
207 sh_elf_ignore_reloc
, /* special_function */
208 "R_SH_DIR8WPZ", /* name */
209 true, /* partial_inplace */
212 true), /* pcrel_offset */
214 /* 8 bit GBR relative. FIXME: This only makes sense if we have some
215 special symbol for the GBR relative area, and that is not
217 HOWTO (R_SH_DIR8BP
, /* type */
219 1, /* size (0 = byte, 1 = short, 2 = long) */
221 false, /* pc_relative */
223 complain_overflow_unsigned
, /* complain_on_overflow */
224 sh_elf_ignore_reloc
, /* special_function */
225 "R_SH_DIR8BP", /* name */
226 false, /* partial_inplace */
229 true), /* pcrel_offset */
231 /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if
232 we have some special symbol for the GBR relative area, and that
233 is not implemented. */
234 HOWTO (R_SH_DIR8W
, /* type */
236 1, /* size (0 = byte, 1 = short, 2 = long) */
238 false, /* pc_relative */
240 complain_overflow_unsigned
, /* complain_on_overflow */
241 sh_elf_ignore_reloc
, /* special_function */
242 "R_SH_DIR8W", /* name */
243 false, /* partial_inplace */
246 true), /* pcrel_offset */
248 /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if
249 we have some special symbol for the GBR relative area, and that
250 is not implemented. */
251 HOWTO (R_SH_DIR8L
, /* type */
253 1, /* size (0 = byte, 1 = short, 2 = long) */
255 false, /* pc_relative */
257 complain_overflow_unsigned
, /* complain_on_overflow */
258 sh_elf_ignore_reloc
, /* special_function */
259 "R_SH_DIR8L", /* name */
260 false, /* partial_inplace */
263 true), /* pcrel_offset */
281 /* The remaining relocs are a GNU extension used for relaxing. The
282 final pass of the linker never needs to do anything with any of
283 these relocs. Any required operations are handled by the
286 /* A 16 bit switch table entry. This is generated for an expression
287 such as ``.word L1 - L2''. The offset holds the difference
288 between the reloc address and L2. */
289 HOWTO (R_SH_SWITCH16
, /* type */
291 1, /* size (0 = byte, 1 = short, 2 = long) */
293 false, /* pc_relative */
295 complain_overflow_unsigned
, /* complain_on_overflow */
296 sh_elf_ignore_reloc
, /* special_function */
297 "R_SH_SWITCH16", /* name */
298 false, /* partial_inplace */
301 true), /* pcrel_offset */
303 /* A 32 bit switch table entry. This is generated for an expression
304 such as ``.long L1 - L2''. The offset holds the difference
305 between the reloc address and L2. */
306 HOWTO (R_SH_SWITCH32
, /* type */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
310 false, /* pc_relative */
312 complain_overflow_unsigned
, /* complain_on_overflow */
313 sh_elf_ignore_reloc
, /* special_function */
314 "R_SH_SWITCH32", /* name */
315 false, /* partial_inplace */
318 true), /* pcrel_offset */
320 /* Indicates a .uses pseudo-op. The compiler will generate .uses
321 pseudo-ops when it finds a function call which can be relaxed.
322 The offset field holds the PC relative offset to the instruction
323 which loads the register used in the function call. */
324 HOWTO (R_SH_USES
, /* type */
326 1, /* size (0 = byte, 1 = short, 2 = long) */
328 false, /* pc_relative */
330 complain_overflow_unsigned
, /* complain_on_overflow */
331 sh_elf_ignore_reloc
, /* special_function */
332 "R_SH_USES", /* name */
333 false, /* partial_inplace */
336 true), /* pcrel_offset */
338 /* The assembler will generate this reloc for addresses referred to
339 by the register loads associated with USES relocs. The offset
340 field holds the number of times the address is referenced in the
342 HOWTO (R_SH_COUNT
, /* type */
344 1, /* size (0 = byte, 1 = short, 2 = long) */
346 false, /* pc_relative */
348 complain_overflow_unsigned
, /* complain_on_overflow */
349 sh_elf_ignore_reloc
, /* special_function */
350 "R_SH_COUNT", /* name */
351 false, /* partial_inplace */
354 true), /* pcrel_offset */
356 /* Indicates an alignment statement. The offset field is the power
357 of 2 to which subsequent portions of the object file must be
359 HOWTO (R_SH_ALIGN
, /* type */
361 1, /* size (0 = byte, 1 = short, 2 = long) */
363 false, /* pc_relative */
365 complain_overflow_unsigned
, /* complain_on_overflow */
366 sh_elf_ignore_reloc
, /* special_function */
367 "R_SH_ALIGN", /* name */
368 false, /* partial_inplace */
371 true), /* pcrel_offset */
373 /* The assembler will generate this reloc before a block of
374 instructions. A section should be processed as assumining it
375 contains data, unless this reloc is seen. */
376 HOWTO (R_SH_CODE
, /* type */
378 1, /* size (0 = byte, 1 = short, 2 = long) */
380 false, /* pc_relative */
382 complain_overflow_unsigned
, /* complain_on_overflow */
383 sh_elf_ignore_reloc
, /* special_function */
384 "R_SH_CODE", /* name */
385 false, /* partial_inplace */
388 true), /* pcrel_offset */
390 /* The assembler will generate this reloc after a block of
391 instructions when it sees data that is not instructions. */
392 HOWTO (R_SH_DATA
, /* type */
394 1, /* size (0 = byte, 1 = short, 2 = long) */
396 false, /* pc_relative */
398 complain_overflow_unsigned
, /* complain_on_overflow */
399 sh_elf_ignore_reloc
, /* special_function */
400 "R_SH_DATA", /* name */
401 false, /* partial_inplace */
404 true), /* pcrel_offset */
406 /* The assembler generates this reloc for each label within a block
407 of instructions. This permits the linker to avoid swapping
408 instructions which are the targets of branches. */
409 HOWTO (R_SH_LABEL
, /* type */
411 1, /* size (0 = byte, 1 = short, 2 = long) */
413 false, /* pc_relative */
415 complain_overflow_unsigned
, /* complain_on_overflow */
416 sh_elf_ignore_reloc
, /* special_function */
417 "R_SH_LABEL", /* name */
418 false, /* partial_inplace */
421 true), /* pcrel_offset */
423 /* An 8 bit switch table entry. This is generated for an expression
424 such as ``.word L1 - L2''. The offset holds the difference
425 between the reloc address and L2. */
426 HOWTO (R_SH_SWITCH8
, /* type */
428 0, /* size (0 = byte, 1 = short, 2 = long) */
430 false, /* pc_relative */
432 complain_overflow_unsigned
, /* complain_on_overflow */
433 sh_elf_ignore_reloc
, /* special_function */
434 "R_SH_SWITCH8", /* name */
435 false, /* partial_inplace */
438 true), /* pcrel_offset */
440 /* GNU extension to record C++ vtable hierarchy */
441 HOWTO (R_SH_GNU_VTINHERIT
, /* type */
443 2, /* size (0 = byte, 1 = short, 2 = long) */
445 false, /* pc_relative */
447 complain_overflow_dont
, /* complain_on_overflow */
448 NULL
, /* special_function */
449 "R_SH_GNU_VTINHERIT", /* name */
450 false, /* partial_inplace */
453 false), /* pcrel_offset */
455 /* GNU extension to record C++ vtable member usage */
456 HOWTO (R_SH_GNU_VTENTRY
, /* type */
458 2, /* size (0 = byte, 1 = short, 2 = long) */
460 false, /* pc_relative */
462 complain_overflow_dont
, /* complain_on_overflow */
463 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
464 "R_SH_GNU_VTENTRY", /* name */
465 false, /* partial_inplace */
468 false), /* pcrel_offset */
470 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
471 HOWTO (R_SH_LOOP_START
, /* type */
473 1, /* size (0 = byte, 1 = short, 2 = long) */
475 false, /* pc_relative */
477 complain_overflow_signed
, /* complain_on_overflow */
478 sh_elf_ignore_reloc
, /* special_function */
479 "R_SH_LOOP_START", /* name */
480 true, /* partial_inplace */
483 true), /* pcrel_offset */
485 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
486 HOWTO (R_SH_LOOP_END
, /* type */
488 1, /* size (0 = byte, 1 = short, 2 = long) */
490 false, /* pc_relative */
492 complain_overflow_signed
, /* complain_on_overflow */
493 sh_elf_ignore_reloc
, /* special_function */
494 "R_SH_LOOP_END", /* name */
495 true, /* partial_inplace */
498 true), /* pcrel_offset */
508 #ifdef INCLUDE_SHMEDIA
509 /* Used in SHLLI.L and SHLRI.L. */
510 HOWTO (R_SH_DIR5U
, /* type */
512 2, /* size (0 = byte, 1 = short, 2 = long) */
514 false, /* pc_relative */
516 complain_overflow_unsigned
, /* complain_on_overflow */
517 bfd_elf_generic_reloc
, /* special_function */
518 "R_SH_DIR5U", /* name */
519 false, /* partial_inplace */
521 0xfc00, /* dst_mask */
522 false), /* pcrel_offset */
524 /* Used in SHARI, SHLLI et al. */
525 HOWTO (R_SH_DIR6U
, /* type */
527 2, /* size (0 = byte, 1 = short, 2 = long) */
529 false, /* pc_relative */
531 complain_overflow_unsigned
, /* complain_on_overflow */
532 bfd_elf_generic_reloc
, /* special_function */
533 "R_SH_DIR6U", /* name */
534 false, /* partial_inplace */
536 0xfc00, /* dst_mask */
537 false), /* pcrel_offset */
539 /* Used in BxxI, LDHI.L et al. */
540 HOWTO (R_SH_DIR6S
, /* type */
542 2, /* size (0 = byte, 1 = short, 2 = long) */
544 false, /* pc_relative */
546 complain_overflow_signed
, /* complain_on_overflow */
547 bfd_elf_generic_reloc
, /* special_function */
548 "R_SH_DIR6S", /* name */
549 false, /* partial_inplace */
551 0xfc00, /* dst_mask */
552 false), /* pcrel_offset */
554 /* Used in ADDI, ANDI et al. */
555 HOWTO (R_SH_DIR10S
, /* type */
557 2, /* size (0 = byte, 1 = short, 2 = long) */
559 false, /* pc_relative */
561 complain_overflow_signed
, /* complain_on_overflow */
562 bfd_elf_generic_reloc
, /* special_function */
563 "R_SH_DIR10S", /* name */
564 false, /* partial_inplace */
566 0xffc00, /* dst_mask */
567 false), /* pcrel_offset */
569 /* Used in LD.UW, ST.W et al. */
570 HOWTO (R_SH_DIR10SW
, /* type */
572 2, /* size (0 = byte, 1 = short, 2 = long) */
574 false, /* pc_relative */
576 complain_overflow_signed
, /* complain_on_overflow */
577 bfd_elf_generic_reloc
, /* special_function */
578 "R_SH_DIR10SW", /* name */
579 false, /* partial_inplace */
581 0xffc00, /* dst_mask */
582 false), /* pcrel_offset */
584 /* Used in LD.L, FLD.S et al. */
585 HOWTO (R_SH_DIR10SL
, /* type */
587 2, /* size (0 = byte, 1 = short, 2 = long) */
589 false, /* pc_relative */
591 complain_overflow_signed
, /* complain_on_overflow */
592 bfd_elf_generic_reloc
, /* special_function */
593 "R_SH_DIR10SL", /* name */
594 false, /* partial_inplace */
596 0xffc00, /* dst_mask */
597 false), /* pcrel_offset */
599 /* Used in FLD.D, FST.P et al. */
600 HOWTO (R_SH_DIR10SQ
, /* type */
602 2, /* size (0 = byte, 1 = short, 2 = long) */
604 false, /* pc_relative */
606 complain_overflow_signed
, /* complain_on_overflow */
607 bfd_elf_generic_reloc
, /* special_function */
608 "R_SH_DIR10SQ", /* name */
609 false, /* partial_inplace */
611 0xffc00, /* dst_mask */
612 false), /* pcrel_offset */
733 HOWTO (R_SH_GOT32
, /* type */
735 2, /* size (0 = byte, 1 = short, 2 = long) */
737 false, /* pc_relative */
739 complain_overflow_bitfield
, /* complain_on_overflow */
740 bfd_elf_generic_reloc
, /* */
741 "R_SH_GOT32", /* name */
742 true, /* partial_inplace */
743 0xffffffff, /* src_mask */
744 0xffffffff, /* dst_mask */
745 false), /* pcrel_offset */
747 HOWTO (R_SH_PLT32
, /* type */
749 2, /* size (0 = byte, 1 = short, 2 = long) */
751 true, /* pc_relative */
753 complain_overflow_bitfield
, /* complain_on_overflow */
754 bfd_elf_generic_reloc
, /* */
755 "R_SH_PLT32", /* name */
756 true, /* partial_inplace */
757 0xffffffff, /* src_mask */
758 0xffffffff, /* dst_mask */
759 true), /* pcrel_offset */
761 HOWTO (R_SH_COPY
, /* type */
763 2, /* size (0 = byte, 1 = short, 2 = long) */
765 false, /* pc_relative */
767 complain_overflow_bitfield
, /* complain_on_overflow */
768 bfd_elf_generic_reloc
, /* */
769 "R_SH_COPY", /* name */
770 true, /* partial_inplace */
771 0xffffffff, /* src_mask */
772 0xffffffff, /* dst_mask */
773 false), /* pcrel_offset */
775 HOWTO (R_SH_GLOB_DAT
, /* type */
777 2, /* size (0 = byte, 1 = short, 2 = long) */
779 false, /* pc_relative */
781 complain_overflow_bitfield
, /* complain_on_overflow */
782 bfd_elf_generic_reloc
, /* */
783 "R_SH_GLOB_DAT", /* name */
784 true, /* partial_inplace */
785 0xffffffff, /* src_mask */
786 0xffffffff, /* dst_mask */
787 false), /* pcrel_offset */
789 HOWTO (R_SH_JMP_SLOT
, /* type */
791 2, /* size (0 = byte, 1 = short, 2 = long) */
793 false, /* pc_relative */
795 complain_overflow_bitfield
, /* complain_on_overflow */
796 bfd_elf_generic_reloc
, /* */
797 "R_SH_JMP_SLOT", /* name */
798 true, /* partial_inplace */
799 0xffffffff, /* src_mask */
800 0xffffffff, /* dst_mask */
801 false), /* pcrel_offset */
803 HOWTO (R_SH_RELATIVE
, /* type */
805 2, /* size (0 = byte, 1 = short, 2 = long) */
807 false, /* pc_relative */
809 complain_overflow_bitfield
, /* complain_on_overflow */
810 bfd_elf_generic_reloc
, /* */
811 "R_SH_RELATIVE", /* name */
812 true, /* partial_inplace */
813 0xffffffff, /* src_mask */
814 0xffffffff, /* dst_mask */
815 false), /* pcrel_offset */
817 HOWTO (R_SH_GOTOFF
, /* type */
819 2, /* size (0 = byte, 1 = short, 2 = long) */
821 false, /* pc_relative */
823 complain_overflow_bitfield
, /* complain_on_overflow */
824 bfd_elf_generic_reloc
, /* */
825 "R_SH_GOTOFF", /* name */
826 true, /* partial_inplace */
827 0xffffffff, /* src_mask */
828 0xffffffff, /* dst_mask */
829 false), /* pcrel_offset */
831 HOWTO (R_SH_GOTPC
, /* type */
833 2, /* size (0 = byte, 1 = short, 2 = long) */
835 true, /* pc_relative */
837 complain_overflow_bitfield
, /* complain_on_overflow */
838 bfd_elf_generic_reloc
, /* */
839 "R_SH_GOTPC", /* name */
840 true, /* partial_inplace */
841 0xffffffff, /* src_mask */
842 0xffffffff, /* dst_mask */
843 true), /* pcrel_offset */
845 HOWTO (R_SH_GOTPLT32
, /* type */
847 2, /* size (0 = byte, 1 = short, 2 = long) */
849 false, /* pc_relative */
851 complain_overflow_bitfield
, /* complain_on_overflow */
852 bfd_elf_generic_reloc
, /* */
853 "R_SH_GOTPLT32", /* name */
854 false, /* partial_inplace */
855 0xffffffff, /* src_mask */
856 0xffffffff, /* dst_mask */
857 false), /* pcrel_offset */
859 #ifdef INCLUDE_SHMEDIA
860 /* Used in MOVI and SHORI (x & 65536). */
861 HOWTO (R_SH_GOT_LOW16
, /* type */
863 2, /* size (0 = byte, 1 = short, 2 = long) */
865 false, /* pc_relative */
867 complain_overflow_dont
, /* complain_on_overflow */
868 bfd_elf_generic_reloc
, /* special_function */
869 "R_SH_GOT_LOW16", /* name */
870 false, /* partial_inplace */
872 0x3fffc00, /* dst_mask */
873 false), /* pcrel_offset */
875 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
876 HOWTO (R_SH_GOT_MEDLOW16
, /* type */
878 2, /* size (0 = byte, 1 = short, 2 = long) */
880 false, /* pc_relative */
882 complain_overflow_dont
, /* complain_on_overflow */
883 bfd_elf_generic_reloc
, /* special_function */
884 "R_SH_GOT_MEDLOW16", /* name */
885 false, /* partial_inplace */
887 0x3fffc00, /* dst_mask */
888 false), /* pcrel_offset */
890 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
891 HOWTO (R_SH_GOT_MEDHI16
, /* type */
893 2, /* size (0 = byte, 1 = short, 2 = long) */
895 false, /* pc_relative */
897 complain_overflow_dont
, /* complain_on_overflow */
898 bfd_elf_generic_reloc
, /* special_function */
899 "R_SH_GOT_MEDHI16", /* name */
900 false, /* partial_inplace */
902 0x3fffc00, /* dst_mask */
903 false), /* pcrel_offset */
905 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
906 HOWTO (R_SH_GOT_HI16
, /* type */
908 2, /* size (0 = byte, 1 = short, 2 = long) */
910 false, /* pc_relative */
912 complain_overflow_dont
, /* complain_on_overflow */
913 bfd_elf_generic_reloc
, /* special_function */
914 "R_SH_GOT_HI16", /* name */
915 false, /* partial_inplace */
917 0x3fffc00, /* dst_mask */
918 false), /* pcrel_offset */
920 /* Used in MOVI and SHORI (x & 65536). */
921 HOWTO (R_SH_GOTPLT_LOW16
, /* type */
923 2, /* size (0 = byte, 1 = short, 2 = long) */
925 false, /* pc_relative */
927 complain_overflow_dont
, /* complain_on_overflow */
928 bfd_elf_generic_reloc
, /* special_function */
929 "R_SH_GOTPLT_LOW16", /* name */
930 false, /* partial_inplace */
932 0x3fffc00, /* dst_mask */
933 false), /* pcrel_offset */
935 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
936 HOWTO (R_SH_GOTPLT_MEDLOW16
, /* type */
938 2, /* size (0 = byte, 1 = short, 2 = long) */
940 false, /* pc_relative */
942 complain_overflow_dont
, /* complain_on_overflow */
943 bfd_elf_generic_reloc
, /* special_function */
944 "R_SH_GOTPLT_MEDLOW16", /* name */
945 false, /* partial_inplace */
947 0x3fffc00, /* dst_mask */
948 false), /* pcrel_offset */
950 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
951 HOWTO (R_SH_GOTPLT_MEDHI16
, /* type */
953 2, /* size (0 = byte, 1 = short, 2 = long) */
955 false, /* pc_relative */
957 complain_overflow_dont
, /* complain_on_overflow */
958 bfd_elf_generic_reloc
, /* special_function */
959 "R_SH_GOTPLT_MEDHI16", /* name */
960 false, /* partial_inplace */
962 0x3fffc00, /* dst_mask */
963 false), /* pcrel_offset */
965 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
966 HOWTO (R_SH_GOTPLT_HI16
, /* type */
968 2, /* size (0 = byte, 1 = short, 2 = long) */
970 false, /* pc_relative */
972 complain_overflow_dont
, /* complain_on_overflow */
973 bfd_elf_generic_reloc
, /* special_function */
974 "R_SH_GOTPLT_HI16", /* name */
975 false, /* partial_inplace */
977 0x3fffc00, /* dst_mask */
978 false), /* pcrel_offset */
980 /* Used in MOVI and SHORI (x & 65536). */
981 HOWTO (R_SH_PLT_LOW16
, /* type */
983 2, /* size (0 = byte, 1 = short, 2 = long) */
985 true, /* pc_relative */
987 complain_overflow_dont
, /* complain_on_overflow */
988 bfd_elf_generic_reloc
, /* special_function */
989 "R_SH_PLT_LOW16", /* name */
990 false, /* partial_inplace */
992 0x3fffc00, /* dst_mask */
993 true), /* pcrel_offset */
995 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
996 HOWTO (R_SH_PLT_MEDLOW16
, /* type */
998 2, /* size (0 = byte, 1 = short, 2 = long) */
1000 true, /* pc_relative */
1002 complain_overflow_dont
, /* complain_on_overflow */
1003 bfd_elf_generic_reloc
, /* special_function */
1004 "R_SH_PLT_MEDLOW16", /* name */
1005 false, /* partial_inplace */
1007 0x3fffc00, /* dst_mask */
1008 true), /* pcrel_offset */
1010 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1011 HOWTO (R_SH_PLT_MEDHI16
, /* type */
1012 32, /* rightshift */
1013 2, /* size (0 = byte, 1 = short, 2 = long) */
1015 true, /* pc_relative */
1017 complain_overflow_dont
, /* complain_on_overflow */
1018 bfd_elf_generic_reloc
, /* special_function */
1019 "R_SH_PLT_MEDHI16", /* name */
1020 false, /* partial_inplace */
1022 0x3fffc00, /* dst_mask */
1023 true), /* pcrel_offset */
1025 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1026 HOWTO (R_SH_PLT_HI16
, /* type */
1027 48, /* rightshift */
1028 2, /* size (0 = byte, 1 = short, 2 = long) */
1030 true, /* pc_relative */
1032 complain_overflow_dont
, /* complain_on_overflow */
1033 bfd_elf_generic_reloc
, /* special_function */
1034 "R_SH_PLT_HI16", /* name */
1035 false, /* partial_inplace */
1037 0x3fffc00, /* dst_mask */
1038 true), /* pcrel_offset */
1040 /* Used in MOVI and SHORI (x & 65536). */
1041 HOWTO (R_SH_GOTOFF_LOW16
, /* type */
1043 2, /* size (0 = byte, 1 = short, 2 = long) */
1045 false, /* pc_relative */
1047 complain_overflow_dont
, /* complain_on_overflow */
1048 bfd_elf_generic_reloc
, /* special_function */
1049 "R_SH_GOTOFF_LOW16", /* name */
1050 false, /* partial_inplace */
1052 0x3fffc00, /* dst_mask */
1053 false), /* pcrel_offset */
1055 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1056 HOWTO (R_SH_GOTOFF_MEDLOW16
, /* type */
1057 16, /* rightshift */
1058 2, /* size (0 = byte, 1 = short, 2 = long) */
1060 false, /* pc_relative */
1062 complain_overflow_dont
, /* complain_on_overflow */
1063 bfd_elf_generic_reloc
, /* special_function */
1064 "R_SH_GOTOFF_MEDLOW16", /* name */
1065 false, /* partial_inplace */
1067 0x3fffc00, /* dst_mask */
1068 false), /* pcrel_offset */
1070 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1071 HOWTO (R_SH_GOTOFF_MEDHI16
, /* type */
1072 32, /* rightshift */
1073 2, /* size (0 = byte, 1 = short, 2 = long) */
1075 false, /* pc_relative */
1077 complain_overflow_dont
, /* complain_on_overflow */
1078 bfd_elf_generic_reloc
, /* special_function */
1079 "R_SH_GOTOFF_MEDHI16", /* name */
1080 false, /* partial_inplace */
1082 0x3fffc00, /* dst_mask */
1083 false), /* pcrel_offset */
1085 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1086 HOWTO (R_SH_GOTOFF_HI16
, /* type */
1087 48, /* rightshift */
1088 2, /* size (0 = byte, 1 = short, 2 = long) */
1090 false, /* pc_relative */
1092 complain_overflow_dont
, /* complain_on_overflow */
1093 bfd_elf_generic_reloc
, /* special_function */
1094 "R_SH_GOTOFF_HI16", /* name */
1095 false, /* partial_inplace */
1097 0x3fffc00, /* dst_mask */
1098 false), /* pcrel_offset */
1100 /* Used in MOVI and SHORI (x & 65536). */
1101 HOWTO (R_SH_GOTPC_LOW16
, /* type */
1103 2, /* size (0 = byte, 1 = short, 2 = long) */
1105 true, /* pc_relative */
1107 complain_overflow_dont
, /* complain_on_overflow */
1108 bfd_elf_generic_reloc
, /* special_function */
1109 "R_SH_GOTPC_LOW16", /* name */
1110 false, /* partial_inplace */
1112 0x3fffc00, /* dst_mask */
1113 true), /* pcrel_offset */
1115 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1116 HOWTO (R_SH_GOTPC_MEDLOW16
, /* type */
1117 16, /* rightshift */
1118 2, /* size (0 = byte, 1 = short, 2 = long) */
1120 true, /* pc_relative */
1122 complain_overflow_dont
, /* complain_on_overflow */
1123 bfd_elf_generic_reloc
, /* special_function */
1124 "R_SH_GOTPC_MEDLOW16", /* name */
1125 false, /* partial_inplace */
1127 0x3fffc00, /* dst_mask */
1128 true), /* pcrel_offset */
1130 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1131 HOWTO (R_SH_GOTPC_MEDHI16
, /* type */
1132 32, /* rightshift */
1133 2, /* size (0 = byte, 1 = short, 2 = long) */
1135 true, /* pc_relative */
1137 complain_overflow_dont
, /* complain_on_overflow */
1138 bfd_elf_generic_reloc
, /* special_function */
1139 "R_SH_GOTPC_MEDHI16", /* name */
1140 false, /* partial_inplace */
1142 0x3fffc00, /* dst_mask */
1143 true), /* pcrel_offset */
1145 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1146 HOWTO (R_SH_GOTPC_HI16
, /* type */
1147 48, /* rightshift */
1148 2, /* size (0 = byte, 1 = short, 2 = long) */
1150 true, /* pc_relative */
1152 complain_overflow_dont
, /* complain_on_overflow */
1153 bfd_elf_generic_reloc
, /* special_function */
1154 "R_SH_GOTPC_HI16", /* name */
1155 false, /* partial_inplace */
1157 0x3fffc00, /* dst_mask */
1158 true), /* pcrel_offset */
1160 /* Used in LD.L, FLD.S et al. */
1161 HOWTO (R_SH_GOT10BY4
, /* type */
1163 2, /* size (0 = byte, 1 = short, 2 = long) */
1165 false, /* pc_relative */
1167 complain_overflow_signed
, /* complain_on_overflow */
1168 bfd_elf_generic_reloc
, /* special_function */
1169 "R_SH_GOT10BY4", /* name */
1170 false, /* partial_inplace */
1172 0xffc00, /* dst_mask */
1173 false), /* pcrel_offset */
1175 /* Used in LD.L, FLD.S et al. */
1176 HOWTO (R_SH_GOTPLT10BY4
, /* type */
1178 2, /* size (0 = byte, 1 = short, 2 = long) */
1180 false, /* pc_relative */
1182 complain_overflow_signed
, /* complain_on_overflow */
1183 bfd_elf_generic_reloc
, /* special_function */
1184 "R_SH_GOTPLT10BY4", /* name */
1185 false, /* partial_inplace */
1187 0xffc00, /* dst_mask */
1188 false), /* pcrel_offset */
1190 /* Used in FLD.D, FST.P et al. */
1191 HOWTO (R_SH_GOT10BY8
, /* type */
1193 2, /* size (0 = byte, 1 = short, 2 = long) */
1195 false, /* pc_relative */
1197 complain_overflow_signed
, /* complain_on_overflow */
1198 bfd_elf_generic_reloc
, /* special_function */
1199 "R_SH_GOT10BY8", /* name */
1200 false, /* partial_inplace */
1202 0xffc00, /* dst_mask */
1203 false), /* pcrel_offset */
1205 /* Used in FLD.D, FST.P et al. */
1206 HOWTO (R_SH_GOTPLT10BY8
, /* type */
1208 2, /* size (0 = byte, 1 = short, 2 = long) */
1210 false, /* pc_relative */
1212 complain_overflow_signed
, /* complain_on_overflow */
1213 bfd_elf_generic_reloc
, /* special_function */
1214 "R_SH_GOTPLT10BY8", /* name */
1215 false, /* partial_inplace */
1217 0xffc00, /* dst_mask */
1218 false), /* pcrel_offset */
1220 HOWTO (R_SH_COPY64
, /* type */
1222 4, /* size (0 = byte, 1 = short, 2 = long) */
1224 false, /* pc_relative */
1226 complain_overflow_dont
, /* complain_on_overflow */
1227 bfd_elf_generic_reloc
, /* special_function */
1228 "R_SH_COPY64", /* name */
1229 false, /* partial_inplace */
1231 ((bfd_vma
) 0) - 1, /* dst_mask */
1232 false), /* pcrel_offset */
1234 HOWTO (R_SH_GLOB_DAT64
, /* type */
1236 4, /* size (0 = byte, 1 = short, 2 = long) */
1238 false, /* pc_relative */
1240 complain_overflow_dont
, /* complain_on_overflow */
1241 bfd_elf_generic_reloc
, /* special_function */
1242 "R_SH_GLOB_DAT64", /* name */
1243 false, /* partial_inplace */
1245 ((bfd_vma
) 0) - 1, /* dst_mask */
1246 false), /* pcrel_offset */
1248 HOWTO (R_SH_JMP_SLOT64
, /* type */
1250 4, /* size (0 = byte, 1 = short, 2 = long) */
1252 false, /* pc_relative */
1254 complain_overflow_dont
, /* complain_on_overflow */
1255 bfd_elf_generic_reloc
, /* special_function */
1256 "R_SH_JMP_SLOT64", /* name */
1257 false, /* partial_inplace */
1259 ((bfd_vma
) 0) - 1, /* dst_mask */
1260 false), /* pcrel_offset */
1262 HOWTO (R_SH_RELATIVE64
, /* type */
1264 4, /* size (0 = byte, 1 = short, 2 = long) */
1266 false, /* pc_relative */
1268 complain_overflow_dont
, /* complain_on_overflow */
1269 bfd_elf_generic_reloc
, /* special_function */
1270 "R_SH_RELATIVE64", /* name */
1271 false, /* partial_inplace */
1273 ((bfd_vma
) 0) - 1, /* dst_mask */
1274 false), /* pcrel_offset */
1322 /* Relocations for SHmedia code. None of these are partial_inplace or
1323 use the field being relocated (except R_SH_PT_16). */
1325 /* The assembler will generate this reloc before a block of SHmedia
1326 instructions. A section should be processed as assuming it contains
1327 data, unless this reloc is seen. Note that a block of SHcompact
1328 instructions are instead preceded by R_SH_CODE.
1329 This is currently not implemented, but should be used for SHmedia
1330 linker relaxation. */
1331 HOWTO (R_SH_SHMEDIA_CODE
, /* type */
1333 1, /* size (0 = byte, 1 = short, 2 = long) */
1335 false, /* pc_relative */
1337 complain_overflow_unsigned
, /* complain_on_overflow */
1338 sh_elf_ignore_reloc
, /* special_function */
1339 "R_SH_SHMEDIA_CODE", /* name */
1340 false, /* partial_inplace */
1343 false), /* pcrel_offset */
1345 /* The assembler will generate this reloc at a PTA or PTB instruction,
1346 and the linker checks the right type of target, or changes a PTA to a
1347 PTB, if the original insn was PT. */
1348 HOWTO (R_SH_PT_16
, /* type */
1350 2, /* size (0 = byte, 1 = short, 2 = long) */
1352 true, /* pc_relative */
1354 complain_overflow_signed
, /* complain_on_overflow */
1355 bfd_elf_generic_reloc
, /* special_function */
1356 "R_SH_PT_16", /* name */
1357 false, /* partial_inplace */
1359 0x3fffc00, /* dst_mask */
1360 true), /* pcrel_offset */
1362 /* Used in unexpanded MOVI. */
1363 HOWTO (R_SH_IMMS16
, /* type */
1365 2, /* size (0 = byte, 1 = short, 2 = long) */
1367 false, /* pc_relative */
1369 complain_overflow_signed
, /* complain_on_overflow */
1370 bfd_elf_generic_reloc
, /* special_function */
1371 "R_SH_IMMS16", /* name */
1372 false, /* partial_inplace */
1374 0x3fffc00, /* dst_mask */
1375 false), /* pcrel_offset */
1377 /* Used in SHORI. */
1378 HOWTO (R_SH_IMMU16
, /* type */
1380 2, /* size (0 = byte, 1 = short, 2 = long) */
1382 false, /* pc_relative */
1384 complain_overflow_unsigned
, /* complain_on_overflow */
1385 bfd_elf_generic_reloc
, /* special_function */
1386 "R_SH_IMMU16", /* name */
1387 false, /* partial_inplace */
1389 0x3fffc00, /* dst_mask */
1390 false), /* pcrel_offset */
1392 /* Used in MOVI and SHORI (x & 65536). */
1393 HOWTO (R_SH_IMM_LOW16
, /* type */
1395 2, /* size (0 = byte, 1 = short, 2 = long) */
1397 false, /* pc_relative */
1399 complain_overflow_dont
, /* complain_on_overflow */
1400 bfd_elf_generic_reloc
, /* special_function */
1401 "R_SH_IMM_LOW16", /* name */
1402 false, /* partial_inplace */
1404 0x3fffc00, /* dst_mask */
1405 false), /* pcrel_offset */
1407 /* Used in MOVI and SHORI ((x - $) & 65536). */
1408 HOWTO (R_SH_IMM_LOW16_PCREL
, /* type */
1410 2, /* size (0 = byte, 1 = short, 2 = long) */
1412 true, /* pc_relative */
1414 complain_overflow_dont
, /* complain_on_overflow */
1415 bfd_elf_generic_reloc
, /* special_function */
1416 "R_SH_IMM_LOW16_PCREL", /* name */
1417 false, /* partial_inplace */
1419 0x3fffc00, /* dst_mask */
1420 true), /* pcrel_offset */
1422 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1423 HOWTO (R_SH_IMM_MEDLOW16
, /* type */
1424 16, /* rightshift */
1425 2, /* size (0 = byte, 1 = short, 2 = long) */
1427 false, /* pc_relative */
1429 complain_overflow_dont
, /* complain_on_overflow */
1430 bfd_elf_generic_reloc
, /* special_function */
1431 "R_SH_IMM_MEDLOW16", /* name */
1432 false, /* partial_inplace */
1434 0x3fffc00, /* dst_mask */
1435 false), /* pcrel_offset */
1437 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1438 HOWTO (R_SH_IMM_MEDLOW16_PCREL
, /* type */
1439 16, /* rightshift */
1440 2, /* size (0 = byte, 1 = short, 2 = long) */
1442 true, /* pc_relative */
1444 complain_overflow_dont
, /* complain_on_overflow */
1445 bfd_elf_generic_reloc
, /* special_function */
1446 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1447 false, /* partial_inplace */
1449 0x3fffc00, /* dst_mask */
1450 true), /* pcrel_offset */
1452 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1453 HOWTO (R_SH_IMM_MEDHI16
, /* type */
1454 32, /* rightshift */
1455 2, /* size (0 = byte, 1 = short, 2 = long) */
1457 false, /* pc_relative */
1459 complain_overflow_dont
, /* complain_on_overflow */
1460 bfd_elf_generic_reloc
, /* special_function */
1461 "R_SH_IMM_MEDHI16", /* name */
1462 false, /* partial_inplace */
1464 0x3fffc00, /* dst_mask */
1465 false), /* pcrel_offset */
1467 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1468 HOWTO (R_SH_IMM_MEDHI16_PCREL
, /* type */
1469 32, /* rightshift */
1470 2, /* size (0 = byte, 1 = short, 2 = long) */
1472 true, /* pc_relative */
1474 complain_overflow_dont
, /* complain_on_overflow */
1475 bfd_elf_generic_reloc
, /* special_function */
1476 "R_SH_IMM_MEDHI16_PCREL", /* name */
1477 false, /* partial_inplace */
1479 0x3fffc00, /* dst_mask */
1480 true), /* pcrel_offset */
1482 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1483 HOWTO (R_SH_IMM_HI16
, /* type */
1484 48, /* rightshift */
1485 2, /* size (0 = byte, 1 = short, 2 = long) */
1487 false, /* pc_relative */
1489 complain_overflow_dont
, /* complain_on_overflow */
1490 bfd_elf_generic_reloc
, /* special_function */
1491 "R_SH_IMM_HI16", /* name */
1492 false, /* partial_inplace */
1494 0x3fffc00, /* dst_mask */
1495 false), /* pcrel_offset */
1497 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1498 HOWTO (R_SH_IMM_HI16_PCREL
, /* type */
1499 48, /* rightshift */
1500 2, /* size (0 = byte, 1 = short, 2 = long) */
1502 true, /* pc_relative */
1504 complain_overflow_dont
, /* complain_on_overflow */
1505 bfd_elf_generic_reloc
, /* special_function */
1506 "R_SH_IMM_HI16_PCREL", /* name */
1507 false, /* partial_inplace */
1509 0x3fffc00, /* dst_mask */
1510 true), /* pcrel_offset */
1512 /* For the .uaquad pseudo. */
1513 HOWTO (R_SH_64
, /* type */
1515 4, /* size (0 = byte, 1 = short, 2 = long) */
1517 false, /* pc_relative */
1519 complain_overflow_dont
, /* complain_on_overflow */
1520 bfd_elf_generic_reloc
, /* special_function */
1521 "R_SH_64", /* name */
1522 false, /* partial_inplace */
1524 ((bfd_vma
) 0) - 1, /* dst_mask */
1525 false), /* pcrel_offset */
1527 /* For the .uaquad pseudo, (x - $). */
1528 HOWTO (R_SH_64_PCREL
, /* type */
1529 48, /* rightshift */
1530 2, /* size (0 = byte, 1 = short, 2 = long) */
1532 true, /* pc_relative */
1534 complain_overflow_dont
, /* complain_on_overflow */
1535 bfd_elf_generic_reloc
, /* special_function */
1536 "R_SH_64_PCREL", /* name */
1537 false, /* partial_inplace */
1539 ((bfd_vma
) 0) - 1, /* dst_mask */
1540 true), /* pcrel_offset */
1545 static bfd_reloc_status_type
1546 sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
, addr
,
1547 symbol_section
, start
, end
)
1548 int r_type ATTRIBUTE_UNUSED
;
1550 asection
*input_section
;
1553 asection
*symbol_section
;
1556 static bfd_vma last_addr
;
1557 static asection
*last_symbol_section
;
1558 bfd_byte
*start_ptr
, *ptr
, *last_ptr
;
1563 /* Sanity check the address. */
1564 if (addr
> input_section
->_raw_size
)
1565 return bfd_reloc_outofrange
;
1567 /* We require the start and end relocations to be processed consecutively -
1568 although we allow then to be processed forwards or backwards. */
1572 last_symbol_section
= symbol_section
;
1573 return bfd_reloc_ok
;
1575 if (last_addr
!= addr
)
1579 if (! symbol_section
|| last_symbol_section
!= symbol_section
|| end
< start
)
1580 return bfd_reloc_outofrange
;
1582 /* Get the symbol_section contents. */
1583 if (symbol_section
!= input_section
)
1585 if (elf_section_data (symbol_section
)->this_hdr
.contents
!= NULL
)
1586 contents
= elf_section_data (symbol_section
)->this_hdr
.contents
;
1589 contents
= (bfd_byte
*) bfd_malloc (symbol_section
->_raw_size
);
1590 if (contents
== NULL
)
1591 return bfd_reloc_outofrange
;
1592 if (! bfd_get_section_contents (input_bfd
, symbol_section
, contents
,
1594 symbol_section
->_raw_size
))
1597 return bfd_reloc_outofrange
;
1601 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
1602 start_ptr
= contents
+ start
;
1603 for (cum_diff
= -6, ptr
= contents
+ end
; cum_diff
< 0 && ptr
> start_ptr
;)
1605 for (last_ptr
= ptr
, ptr
-= 4; ptr
>= start_ptr
&& IS_PPI (ptr
);)
1608 diff
= (last_ptr
- ptr
) >> 1;
1609 cum_diff
+= diff
& 1;
1612 /* Calculate the start / end values to load into rs / re minus four -
1613 so that will cancel out the four we would otherwise have to add to
1614 addr to get the value to subtract in order to get relative addressing. */
1618 end
= (ptr
+ cum_diff
* 2) - contents
;
1622 bfd_vma start0
= start
- 4;
1624 while (start0
&& IS_PPI (contents
+ start0
))
1626 start0
= start
- 2 - ((start
- start0
) & 2);
1627 start
= start0
- cum_diff
- 2;
1631 if (contents
!= NULL
1632 && elf_section_data (symbol_section
)->this_hdr
.contents
!= contents
)
1635 insn
= bfd_get_16 (input_bfd
, contents
+ addr
);
1637 x
= (insn
& 0x200 ? end
: start
) - addr
;
1638 if (input_section
!= symbol_section
)
1639 x
+= ((symbol_section
->output_section
->vma
+ symbol_section
->output_offset
)
1640 - (input_section
->output_section
->vma
1641 + input_section
->output_offset
));
1643 if (x
< -128 || x
> 127)
1644 return bfd_reloc_overflow
;
1646 x
= (insn
& ~0xff) | (x
& 0xff);
1647 bfd_put_16 (input_bfd
, (bfd_vma
) x
, contents
+ addr
);
1649 return bfd_reloc_ok
;
1652 /* This function is used for normal relocs. This used to be like the COFF
1653 function, and is almost certainly incorrect for other ELF targets. */
1655 static bfd_reloc_status_type
1656 sh_elf_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
1659 arelent
*reloc_entry
;
1662 asection
*input_section
;
1664 char **error_message ATTRIBUTE_UNUSED
;
1668 enum elf_sh_reloc_type r_type
;
1669 bfd_vma addr
= reloc_entry
->address
;
1670 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
1672 r_type
= (enum elf_sh_reloc_type
) reloc_entry
->howto
->type
;
1674 if (output_bfd
!= NULL
)
1676 /* Partial linking--do nothing. */
1677 reloc_entry
->address
+= input_section
->output_offset
;
1678 return bfd_reloc_ok
;
1681 /* Almost all relocs have to do with relaxing. If any work must be
1682 done for them, it has been done in sh_relax_section. */
1683 if (r_type
== R_SH_IND12W
&& (symbol_in
->flags
& BSF_LOCAL
) != 0)
1684 return bfd_reloc_ok
;
1686 if (symbol_in
!= NULL
1687 && bfd_is_und_section (symbol_in
->section
))
1688 return bfd_reloc_undefined
;
1690 if (bfd_is_com_section (symbol_in
->section
))
1693 sym_value
= (symbol_in
->value
+
1694 symbol_in
->section
->output_section
->vma
+
1695 symbol_in
->section
->output_offset
);
1700 insn
= bfd_get_32 (abfd
, hit_data
);
1701 insn
+= sym_value
+ reloc_entry
->addend
;
1702 bfd_put_32 (abfd
, (bfd_vma
) insn
, hit_data
);
1705 insn
= bfd_get_16 (abfd
, hit_data
);
1706 sym_value
+= reloc_entry
->addend
;
1707 sym_value
-= (input_section
->output_section
->vma
1708 + input_section
->output_offset
1711 sym_value
+= (insn
& 0xfff) << 1;
1713 sym_value
-= 0x1000;
1714 insn
= (insn
& 0xf000) | (sym_value
& 0xfff);
1715 bfd_put_16 (abfd
, (bfd_vma
) insn
, hit_data
);
1716 if (sym_value
< (bfd_vma
) -0x1000 || sym_value
>= 0x1000)
1717 return bfd_reloc_overflow
;
1724 return bfd_reloc_ok
;
1727 /* This function is used for relocs which are only used for relaxing,
1728 which the linker should otherwise ignore. */
1730 static bfd_reloc_status_type
1731 sh_elf_ignore_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1732 output_bfd
, error_message
)
1733 bfd
*abfd ATTRIBUTE_UNUSED
;
1734 arelent
*reloc_entry
;
1735 asymbol
*symbol ATTRIBUTE_UNUSED
;
1736 PTR data ATTRIBUTE_UNUSED
;
1737 asection
*input_section
;
1739 char **error_message ATTRIBUTE_UNUSED
;
1741 if (output_bfd
!= NULL
)
1742 reloc_entry
->address
+= input_section
->output_offset
;
1743 return bfd_reloc_ok
;
1746 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
1748 struct elf_reloc_map
1750 bfd_reloc_code_real_type bfd_reloc_val
;
1751 unsigned char elf_reloc_val
;
1754 /* An array mapping BFD reloc codes to SH ELF relocs. */
1756 static const struct elf_reloc_map sh_reloc_map
[] =
1758 { BFD_RELOC_NONE
, R_SH_NONE
},
1759 { BFD_RELOC_32
, R_SH_DIR32
},
1760 { BFD_RELOC_CTOR
, R_SH_DIR32
},
1761 { BFD_RELOC_32_PCREL
, R_SH_REL32
},
1762 { BFD_RELOC_SH_PCDISP8BY2
, R_SH_DIR8WPN
},
1763 { BFD_RELOC_SH_PCDISP12BY2
, R_SH_IND12W
},
1764 { BFD_RELOC_SH_PCRELIMM8BY2
, R_SH_DIR8WPZ
},
1765 { BFD_RELOC_SH_PCRELIMM8BY4
, R_SH_DIR8WPL
},
1766 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
1767 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
1768 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
1769 { BFD_RELOC_SH_USES
, R_SH_USES
},
1770 { BFD_RELOC_SH_COUNT
, R_SH_COUNT
},
1771 { BFD_RELOC_SH_ALIGN
, R_SH_ALIGN
},
1772 { BFD_RELOC_SH_CODE
, R_SH_CODE
},
1773 { BFD_RELOC_SH_DATA
, R_SH_DATA
},
1774 { BFD_RELOC_SH_LABEL
, R_SH_LABEL
},
1775 { BFD_RELOC_VTABLE_INHERIT
, R_SH_GNU_VTINHERIT
},
1776 { BFD_RELOC_VTABLE_ENTRY
, R_SH_GNU_VTENTRY
},
1777 { BFD_RELOC_SH_LOOP_START
, R_SH_LOOP_START
},
1778 { BFD_RELOC_SH_LOOP_END
, R_SH_LOOP_END
},
1779 { BFD_RELOC_32_GOT_PCREL
, R_SH_GOT32
},
1780 { BFD_RELOC_32_PLT_PCREL
, R_SH_PLT32
},
1781 { BFD_RELOC_SH_COPY
, R_SH_COPY
},
1782 { BFD_RELOC_SH_GLOB_DAT
, R_SH_GLOB_DAT
},
1783 { BFD_RELOC_SH_JMP_SLOT
, R_SH_JMP_SLOT
},
1784 { BFD_RELOC_SH_RELATIVE
, R_SH_RELATIVE
},
1785 { BFD_RELOC_32_GOTOFF
, R_SH_GOTOFF
},
1786 { BFD_RELOC_SH_GOTPC
, R_SH_GOTPC
},
1787 { BFD_RELOC_SH_GOTPLT32
, R_SH_GOTPLT32
},
1788 #ifdef INCLUDE_SHMEDIA
1789 { BFD_RELOC_SH_GOT_LOW16
, R_SH_GOT_LOW16
},
1790 { BFD_RELOC_SH_GOT_MEDLOW16
, R_SH_GOT_MEDLOW16
},
1791 { BFD_RELOC_SH_GOT_MEDHI16
, R_SH_GOT_MEDHI16
},
1792 { BFD_RELOC_SH_GOT_HI16
, R_SH_GOT_HI16
},
1793 { BFD_RELOC_SH_GOTPLT_LOW16
, R_SH_GOTPLT_LOW16
},
1794 { BFD_RELOC_SH_GOTPLT_MEDLOW16
, R_SH_GOTPLT_MEDLOW16
},
1795 { BFD_RELOC_SH_GOTPLT_MEDHI16
, R_SH_GOTPLT_MEDHI16
},
1796 { BFD_RELOC_SH_GOTPLT_HI16
, R_SH_GOTPLT_HI16
},
1797 { BFD_RELOC_SH_PLT_LOW16
, R_SH_PLT_LOW16
},
1798 { BFD_RELOC_SH_PLT_MEDLOW16
, R_SH_PLT_MEDLOW16
},
1799 { BFD_RELOC_SH_PLT_MEDHI16
, R_SH_PLT_MEDHI16
},
1800 { BFD_RELOC_SH_PLT_HI16
, R_SH_PLT_HI16
},
1801 { BFD_RELOC_SH_GOTOFF_LOW16
, R_SH_GOTOFF_LOW16
},
1802 { BFD_RELOC_SH_GOTOFF_MEDLOW16
, R_SH_GOTOFF_MEDLOW16
},
1803 { BFD_RELOC_SH_GOTOFF_MEDHI16
, R_SH_GOTOFF_MEDHI16
},
1804 { BFD_RELOC_SH_GOTOFF_HI16
, R_SH_GOTOFF_HI16
},
1805 { BFD_RELOC_SH_GOTPC_LOW16
, R_SH_GOTPC_LOW16
},
1806 { BFD_RELOC_SH_GOTPC_MEDLOW16
, R_SH_GOTPC_MEDLOW16
},
1807 { BFD_RELOC_SH_GOTPC_MEDHI16
, R_SH_GOTPC_MEDHI16
},
1808 { BFD_RELOC_SH_GOTPC_HI16
, R_SH_GOTPC_HI16
},
1809 { BFD_RELOC_SH_COPY64
, R_SH_COPY64
},
1810 { BFD_RELOC_SH_GLOB_DAT64
, R_SH_GLOB_DAT64
},
1811 { BFD_RELOC_SH_JMP_SLOT64
, R_SH_JMP_SLOT64
},
1812 { BFD_RELOC_SH_RELATIVE64
, R_SH_RELATIVE64
},
1813 { BFD_RELOC_SH_GOT10BY4
, R_SH_GOT10BY4
},
1814 { BFD_RELOC_SH_GOT10BY8
, R_SH_GOT10BY8
},
1815 { BFD_RELOC_SH_GOTPLT10BY4
, R_SH_GOTPLT10BY4
},
1816 { BFD_RELOC_SH_GOTPLT10BY8
, R_SH_GOTPLT10BY8
},
1817 { BFD_RELOC_SH_PT_16
, R_SH_PT_16
},
1818 { BFD_RELOC_SH_SHMEDIA_CODE
, R_SH_SHMEDIA_CODE
},
1819 { BFD_RELOC_SH_IMMU5
, R_SH_DIR5U
},
1820 { BFD_RELOC_SH_IMMS6
, R_SH_DIR6S
},
1821 { BFD_RELOC_SH_IMMU6
, R_SH_DIR6U
},
1822 { BFD_RELOC_SH_IMMS10
, R_SH_DIR10S
},
1823 { BFD_RELOC_SH_IMMS10BY2
, R_SH_DIR10SW
},
1824 { BFD_RELOC_SH_IMMS10BY4
, R_SH_DIR10SL
},
1825 { BFD_RELOC_SH_IMMS10BY8
, R_SH_DIR10SQ
},
1826 { BFD_RELOC_SH_IMMS16
, R_SH_IMMS16
},
1827 { BFD_RELOC_SH_IMMU16
, R_SH_IMMU16
},
1828 { BFD_RELOC_SH_IMM_LOW16
, R_SH_IMM_LOW16
},
1829 { BFD_RELOC_SH_IMM_LOW16_PCREL
, R_SH_IMM_LOW16_PCREL
},
1830 { BFD_RELOC_SH_IMM_MEDLOW16
, R_SH_IMM_MEDLOW16
},
1831 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL
, R_SH_IMM_MEDLOW16_PCREL
},
1832 { BFD_RELOC_SH_IMM_MEDHI16
, R_SH_IMM_MEDHI16
},
1833 { BFD_RELOC_SH_IMM_MEDHI16_PCREL
, R_SH_IMM_MEDHI16_PCREL
},
1834 { BFD_RELOC_SH_IMM_HI16
, R_SH_IMM_HI16
},
1835 { BFD_RELOC_SH_IMM_HI16_PCREL
, R_SH_IMM_HI16_PCREL
},
1836 { BFD_RELOC_64
, R_SH_64
},
1837 { BFD_RELOC_64_PCREL
, R_SH_64_PCREL
},
1838 #endif /* not INCLUDE_SHMEDIA */
1841 /* Given a BFD reloc code, return the howto structure for the
1842 corresponding SH ELf reloc. */
1844 static reloc_howto_type
*
1845 sh_elf_reloc_type_lookup (abfd
, code
)
1846 bfd
*abfd ATTRIBUTE_UNUSED
;
1847 bfd_reloc_code_real_type code
;
1851 for (i
= 0; i
< sizeof (sh_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
1853 if (sh_reloc_map
[i
].bfd_reloc_val
== code
)
1854 return &sh_elf_howto_table
[(int) sh_reloc_map
[i
].elf_reloc_val
];
1860 /* Given an ELF reloc, fill in the howto field of a relent. */
1863 sh_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1864 bfd
*abfd ATTRIBUTE_UNUSED
;
1866 Elf_Internal_Rela
*dst
;
1870 r
= ELF32_R_TYPE (dst
->r_info
);
1872 BFD_ASSERT (r
< (unsigned int) R_SH_max
);
1873 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC
|| r
> R_SH_LAST_INVALID_RELOC
);
1874 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_2
|| r
> R_SH_LAST_INVALID_RELOC_2
);
1875 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_3
|| r
> R_SH_LAST_INVALID_RELOC_3
);
1876 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_4
|| r
> R_SH_LAST_INVALID_RELOC_4
);
1878 cache_ptr
->howto
= &sh_elf_howto_table
[r
];
1881 /* This function handles relaxing for SH ELF. See the corresponding
1882 function in coff-sh.c for a description of what this does. FIXME:
1883 There is a lot of duplication here between this code and the COFF
1884 specific code. The format of relocs and symbols is wound deeply
1885 into this code, but it would still be better if the duplication
1886 could be eliminated somehow. Note in particular that although both
1887 functions use symbols like R_SH_CODE, those symbols have different
1888 values; in coff-sh.c they come from include/coff/sh.h, whereas here
1889 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
1892 sh_elf_relax_section (abfd
, sec
, link_info
, again
)
1895 struct bfd_link_info
*link_info
;
1898 Elf_Internal_Shdr
*symtab_hdr
;
1899 Elf_Internal_Rela
*internal_relocs
;
1901 Elf_Internal_Rela
*irel
, *irelend
;
1902 bfd_byte
*contents
= NULL
;
1903 Elf_Internal_Sym
*isymbuf
= NULL
;
1907 if (link_info
->relocateable
1908 || (sec
->flags
& SEC_RELOC
) == 0
1909 || sec
->reloc_count
== 0)
1912 #ifdef INCLUDE_SHMEDIA
1913 if (elf_section_data (sec
)->this_hdr
.sh_flags
1914 & (SHF_SH5_ISA32
| SHF_SH5_ISA32_MIXED
))
1920 /* If this is the first time we have been called for this section,
1921 initialize the cooked size. */
1922 if (sec
->_cooked_size
== 0)
1923 sec
->_cooked_size
= sec
->_raw_size
;
1925 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1927 internal_relocs
= (_bfd_elf32_link_read_relocs
1928 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
1929 link_info
->keep_memory
));
1930 if (internal_relocs
== NULL
)
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
)
1960 if (! bfd_get_section_contents (abfd
, sec
, contents
,
1961 (file_ptr
) 0, sec
->_raw_size
))
1966 /* The r_addend field of the R_SH_USES reloc will point us to
1967 the register load. The 4 is because the r_addend field is
1968 computed as though it were a jump offset, which are based
1969 from 4 bytes after the jump instruction. */
1970 laddr
= irel
->r_offset
+ 4 + irel
->r_addend
;
1971 if (laddr
>= sec
->_raw_size
)
1973 (*_bfd_error_handler
) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),
1974 bfd_archive_filename (abfd
),
1975 (unsigned long) irel
->r_offset
);
1978 insn
= bfd_get_16 (abfd
, contents
+ laddr
);
1980 /* If the instruction is not mov.l NN,rN, we don't know what to
1982 if ((insn
& 0xf000) != 0xd000)
1984 ((*_bfd_error_handler
)
1985 (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
1986 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
, insn
));
1990 /* Get the address from which the register is being loaded. The
1991 displacement in the mov.l instruction is quadrupled. It is a
1992 displacement from four bytes after the movl instruction, but,
1993 before adding in the PC address, two least significant bits
1994 of the PC are cleared. We assume that the section is aligned
1995 on a four byte boundary. */
1996 paddr
= insn
& 0xff;
1998 paddr
+= (laddr
+ 4) &~ (bfd_vma
) 3;
1999 if (paddr
>= sec
->_raw_size
)
2001 ((*_bfd_error_handler
)
2002 (_("%s: 0x%lx: warning: bad R_SH_USES load offset"),
2003 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
2007 /* Get the reloc for the address from which the register is
2008 being loaded. This reloc will tell us which function is
2009 actually being called. */
2010 for (irelfn
= internal_relocs
; irelfn
< irelend
; irelfn
++)
2011 if (irelfn
->r_offset
== paddr
2012 && ELF32_R_TYPE (irelfn
->r_info
) == (int) R_SH_DIR32
)
2014 if (irelfn
>= irelend
)
2016 ((*_bfd_error_handler
)
2017 (_("%s: 0x%lx: warning: could not find expected reloc"),
2018 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2022 /* Read this BFD's symbols if we haven't done so already. */
2023 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
2025 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2026 if (isymbuf
== NULL
)
2027 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2028 symtab_hdr
->sh_info
, 0,
2030 if (isymbuf
== NULL
)
2034 /* Get the value of the symbol referred to by the reloc. */
2035 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
2037 /* A local symbol. */
2038 Elf_Internal_Sym
*isym
;
2040 isym
= isymbuf
+ ELF32_R_SYM (irelfn
->r_info
);
2042 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd
, sec
))
2044 ((*_bfd_error_handler
)
2045 (_("%s: 0x%lx: warning: symbol in unexpected section"),
2046 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2050 symval
= (isym
->st_value
2051 + sec
->output_section
->vma
2052 + sec
->output_offset
);
2057 struct elf_link_hash_entry
*h
;
2059 indx
= ELF32_R_SYM (irelfn
->r_info
) - symtab_hdr
->sh_info
;
2060 h
= elf_sym_hashes (abfd
)[indx
];
2061 BFD_ASSERT (h
!= NULL
);
2062 if (h
->root
.type
!= bfd_link_hash_defined
2063 && h
->root
.type
!= bfd_link_hash_defweak
)
2065 /* This appears to be a reference to an undefined
2066 symbol. Just ignore it--it will be caught by the
2067 regular reloc processing. */
2071 symval
= (h
->root
.u
.def
.value
2072 + h
->root
.u
.def
.section
->output_section
->vma
2073 + h
->root
.u
.def
.section
->output_offset
);
2076 symval
+= bfd_get_32 (abfd
, contents
+ paddr
);
2078 /* See if this function call can be shortened. */
2081 + sec
->output_section
->vma
2082 + sec
->output_offset
2084 if (foff
< -0x1000 || foff
>= 0x1000)
2086 /* After all that work, we can't shorten this function call. */
2090 /* Shorten the function call. */
2092 /* For simplicity of coding, we are going to modify the section
2093 contents, the section relocs, and the BFD symbol table. We
2094 must tell the rest of the code not to free up this
2095 information. It would be possible to instead create a table
2096 of changes which have to be made, as is done in coff-mips.c;
2097 that would be more work, but would require less memory when
2098 the linker is run. */
2100 elf_section_data (sec
)->relocs
= internal_relocs
;
2101 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2102 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2104 /* Replace the jsr with a bsr. */
2106 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
2107 replace the jsr with a bsr. */
2108 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irelfn
->r_info
), R_SH_IND12W
);
2109 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
2111 /* If this needs to be changed because of future relaxing,
2112 it will be handled here like other internal IND12W
2115 (bfd_vma
) 0xb000 | ((foff
>> 1) & 0xfff),
2116 contents
+ irel
->r_offset
);
2120 /* We can't fully resolve this yet, because the external
2121 symbol value may be changed by future relaxing. We let
2122 the final link phase handle it. */
2123 bfd_put_16 (abfd
, (bfd_vma
) 0xb000, contents
+ irel
->r_offset
);
2126 /* See if there is another R_SH_USES reloc referring to the same
2128 for (irelscan
= internal_relocs
; irelscan
< irelend
; irelscan
++)
2129 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_USES
2130 && laddr
== irelscan
->r_offset
+ 4 + irelscan
->r_addend
)
2132 if (irelscan
< irelend
)
2134 /* Some other function call depends upon this register load,
2135 and we have not yet converted that function call.
2136 Indeed, we may never be able to convert it. There is
2137 nothing else we can do at this point. */
2141 /* Look for a R_SH_COUNT reloc on the location where the
2142 function address is stored. Do this before deleting any
2143 bytes, to avoid confusion about the address. */
2144 for (irelcount
= internal_relocs
; irelcount
< irelend
; irelcount
++)
2145 if (irelcount
->r_offset
== paddr
2146 && ELF32_R_TYPE (irelcount
->r_info
) == (int) R_SH_COUNT
)
2149 /* Delete the register load. */
2150 if (! sh_elf_relax_delete_bytes (abfd
, sec
, laddr
, 2))
2153 /* That will change things, so, just in case it permits some
2154 other function call to come within range, we should relax
2155 again. Note that this is not required, and it may be slow. */
2158 /* Now check whether we got a COUNT reloc. */
2159 if (irelcount
>= irelend
)
2161 ((*_bfd_error_handler
)
2162 (_("%s: 0x%lx: warning: could not find expected COUNT reloc"),
2163 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2167 /* The number of uses is stored in the r_addend field. We've
2168 just deleted one. */
2169 if (irelcount
->r_addend
== 0)
2171 ((*_bfd_error_handler
) (_("%s: 0x%lx: warning: bad count"),
2172 bfd_archive_filename (abfd
),
2173 (unsigned long) paddr
));
2177 --irelcount
->r_addend
;
2179 /* If there are no more uses, we can delete the address. Reload
2180 the address from irelfn, in case it was changed by the
2181 previous call to sh_elf_relax_delete_bytes. */
2182 if (irelcount
->r_addend
== 0)
2184 if (! sh_elf_relax_delete_bytes (abfd
, sec
, irelfn
->r_offset
, 4))
2188 /* We've done all we can with that function call. */
2191 /* Look for load and store instructions that we can align on four
2197 /* Get the section contents. */
2198 if (contents
== NULL
)
2200 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2201 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2204 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
2205 if (contents
== NULL
)
2208 if (! bfd_get_section_contents (abfd
, sec
, contents
,
2209 (file_ptr
) 0, sec
->_raw_size
))
2214 if (! sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
,
2220 elf_section_data (sec
)->relocs
= internal_relocs
;
2221 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2222 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2227 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2229 if (! link_info
->keep_memory
)
2233 /* Cache the symbols for elf_link_input_bfd. */
2234 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2238 if (contents
!= NULL
2239 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2241 if (! link_info
->keep_memory
)
2245 /* Cache the section contents for elf_link_input_bfd. */
2246 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2250 if (internal_relocs
!= NULL
2251 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2252 free (internal_relocs
);
2258 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2260 if (contents
!= NULL
2261 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2263 if (internal_relocs
!= NULL
2264 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2265 free (internal_relocs
);
2270 /* Delete some bytes from a section while relaxing. FIXME: There is a
2271 lot of duplication between this function and sh_relax_delete_bytes
2275 sh_elf_relax_delete_bytes (abfd
, sec
, addr
, count
)
2281 Elf_Internal_Shdr
*symtab_hdr
;
2282 unsigned int sec_shndx
;
2284 Elf_Internal_Rela
*irel
, *irelend
;
2285 Elf_Internal_Rela
*irelalign
;
2287 Elf_Internal_Sym
*isymbuf
, *isym
, *isymend
;
2288 struct elf_link_hash_entry
**sym_hashes
;
2289 struct elf_link_hash_entry
**end_hashes
;
2290 unsigned int symcount
;
2293 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2294 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2296 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
2298 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2300 /* The deletion must stop at the next ALIGN reloc for an aligment
2301 power larger than the number of bytes we are deleting. */
2304 toaddr
= sec
->_cooked_size
;
2306 irel
= elf_section_data (sec
)->relocs
;
2307 irelend
= irel
+ sec
->reloc_count
;
2308 for (; irel
< irelend
; irel
++)
2310 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
2311 && irel
->r_offset
> addr
2312 && count
< (1 << irel
->r_addend
))
2315 toaddr
= irel
->r_offset
;
2320 /* Actually delete the bytes. */
2321 memmove (contents
+ addr
, contents
+ addr
+ count
,
2322 (size_t) (toaddr
- addr
- count
));
2323 if (irelalign
== NULL
)
2324 sec
->_cooked_size
-= count
;
2329 #define NOP_OPCODE (0x0009)
2331 BFD_ASSERT ((count
& 1) == 0);
2332 for (i
= 0; i
< count
; i
+= 2)
2333 bfd_put_16 (abfd
, (bfd_vma
) NOP_OPCODE
, contents
+ toaddr
- count
+ i
);
2336 /* Adjust all the relocs. */
2337 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
2339 bfd_vma nraddr
, stop
;
2342 int off
, adjust
, oinsn
;
2343 bfd_signed_vma voff
= 0;
2346 /* Get the new reloc address. */
2347 nraddr
= irel
->r_offset
;
2348 if ((irel
->r_offset
> addr
2349 && irel
->r_offset
< toaddr
)
2350 || (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
2351 && irel
->r_offset
== toaddr
))
2354 /* See if this reloc was for the bytes we have deleted, in which
2355 case we no longer care about it. Don't delete relocs which
2356 represent addresses, though. */
2357 if (irel
->r_offset
>= addr
2358 && irel
->r_offset
< addr
+ count
2359 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_ALIGN
2360 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
2361 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_DATA
2362 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_LABEL
)
2363 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
2366 /* If this is a PC relative reloc, see if the range it covers
2367 includes the bytes we have deleted. */
2368 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2377 start
= irel
->r_offset
;
2378 insn
= bfd_get_16 (abfd
, contents
+ nraddr
);
2382 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2385 start
= stop
= addr
;
2389 /* If this reloc is against a symbol defined in this
2390 section, and the symbol will not be adjusted below, we
2391 must check the addend to see it will put the value in
2392 range to be adjusted, and hence must be changed. */
2393 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
2395 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
2396 if (isym
->st_shndx
== sec_shndx
2397 && (isym
->st_value
<= addr
2398 || isym
->st_value
>= toaddr
))
2402 val
= bfd_get_32 (abfd
, contents
+ nraddr
);
2403 val
+= isym
->st_value
;
2404 if (val
> addr
&& val
< toaddr
)
2405 bfd_put_32 (abfd
, val
- count
, contents
+ nraddr
);
2408 start
= stop
= addr
;
2415 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
2419 if (ELF32_R_SYM (irel
->r_info
) >= symtab_hdr
->sh_info
)
2420 start
= stop
= addr
;
2426 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
2432 stop
= start
+ 4 + off
* 2;
2437 stop
= (start
& ~(bfd_vma
) 3) + 4 + off
* 4;
2443 /* These relocs types represent
2445 The r_addend field holds the difference between the reloc
2446 address and L1. That is the start of the reloc, and
2447 adding in the contents gives us the top. We must adjust
2448 both the r_offset field and the section contents.
2449 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
2450 and the elf bfd r_offset is called r_vaddr. */
2452 stop
= irel
->r_offset
;
2453 start
= (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irel
->r_addend
);
2457 && (stop
<= addr
|| stop
>= toaddr
))
2458 irel
->r_addend
+= count
;
2459 else if (stop
> addr
2461 && (start
<= addr
|| start
>= toaddr
))
2462 irel
->r_addend
-= count
;
2464 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH16
)
2465 voff
= bfd_get_signed_16 (abfd
, contents
+ nraddr
);
2466 else if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH8
)
2467 voff
= bfd_get_8 (abfd
, contents
+ nraddr
);
2469 voff
= bfd_get_signed_32 (abfd
, contents
+ nraddr
);
2470 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
2475 start
= irel
->r_offset
;
2476 stop
= (bfd_vma
) ((bfd_signed_vma
) start
2477 + (long) irel
->r_addend
2484 && (stop
<= addr
|| stop
>= toaddr
))
2486 else if (stop
> addr
2488 && (start
<= addr
|| start
>= toaddr
))
2497 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2506 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2508 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2513 if ((oinsn
& 0xf000) != (insn
& 0xf000))
2515 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2519 BFD_ASSERT (adjust
== count
|| count
>= 4);
2524 if ((irel
->r_offset
& 3) == 0)
2527 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2529 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2534 if (voff
< 0 || voff
>= 0xff)
2536 bfd_put_8 (abfd
, voff
, contents
+ nraddr
);
2541 if (voff
< - 0x8000 || voff
>= 0x8000)
2543 bfd_put_signed_16 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
2548 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
2552 irel
->r_addend
+= adjust
;
2558 ((*_bfd_error_handler
)
2559 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
2560 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
2561 bfd_set_error (bfd_error_bad_value
);
2566 irel
->r_offset
= nraddr
;
2569 /* Look through all the other sections. If there contain any IMM32
2570 relocs against internal symbols which we are not going to adjust
2571 below, we may need to adjust the addends. */
2572 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2574 Elf_Internal_Rela
*internal_relocs
;
2575 Elf_Internal_Rela
*irelscan
, *irelscanend
;
2576 bfd_byte
*ocontents
;
2579 || (o
->flags
& SEC_RELOC
) == 0
2580 || o
->reloc_count
== 0)
2583 /* We always cache the relocs. Perhaps, if info->keep_memory is
2584 false, we should free them, if we are permitted to, when we
2585 leave sh_coff_relax_section. */
2586 internal_relocs
= (_bfd_elf32_link_read_relocs
2587 (abfd
, o
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
2589 if (internal_relocs
== NULL
)
2593 irelscanend
= internal_relocs
+ o
->reloc_count
;
2594 for (irelscan
= internal_relocs
; irelscan
< irelscanend
; irelscan
++)
2596 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
2597 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_SWITCH32
)
2599 bfd_vma start
, stop
;
2600 bfd_signed_vma voff
;
2602 if (ocontents
== NULL
)
2604 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
2605 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
2608 /* We always cache the section contents.
2609 Perhaps, if info->keep_memory is false, we
2610 should free them, if we are permitted to,
2611 when we leave sh_coff_relax_section. */
2612 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
2613 if (ocontents
== NULL
)
2615 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
2619 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
2623 stop
= irelscan
->r_offset
;
2625 = (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irelscan
->r_addend
);
2627 /* STOP is in a different section, so it won't change. */
2628 if (start
> addr
&& start
< toaddr
)
2629 irelscan
->r_addend
+= count
;
2631 voff
= bfd_get_signed_32 (abfd
, ocontents
+ irelscan
->r_offset
);
2632 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
2636 && (stop
<= addr
|| stop
>= toaddr
))
2637 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
+ count
,
2638 ocontents
+ irelscan
->r_offset
);
2639 else if (stop
> addr
2641 && (start
<= addr
|| start
>= toaddr
))
2642 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
- count
,
2643 ocontents
+ irelscan
->r_offset
);
2646 if (ELF32_R_TYPE (irelscan
->r_info
) != (int) R_SH_DIR32
)
2649 if (ELF32_R_SYM (irelscan
->r_info
) >= symtab_hdr
->sh_info
)
2653 isym
= isymbuf
+ ELF32_R_SYM (irelscan
->r_info
);
2654 if (isym
->st_shndx
== sec_shndx
2655 && (isym
->st_value
<= addr
2656 || isym
->st_value
>= toaddr
))
2660 if (ocontents
== NULL
)
2662 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
2663 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
2666 /* We always cache the section contents.
2667 Perhaps, if info->keep_memory is false, we
2668 should free them, if we are permitted to,
2669 when we leave sh_coff_relax_section. */
2670 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
2671 if (ocontents
== NULL
)
2673 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
2677 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
2681 val
= bfd_get_32 (abfd
, ocontents
+ irelscan
->r_offset
);
2682 val
+= isym
->st_value
;
2683 if (val
> addr
&& val
< toaddr
)
2684 bfd_put_32 (abfd
, val
- count
,
2685 ocontents
+ irelscan
->r_offset
);
2690 /* Adjust the local symbols defined in this section. */
2691 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
2692 for (isym
= isymbuf
; isym
< isymend
; isym
++)
2694 if (isym
->st_shndx
== sec_shndx
2695 && isym
->st_value
> addr
2696 && isym
->st_value
< toaddr
)
2697 isym
->st_value
-= count
;
2700 /* Now adjust the global symbols defined in this section. */
2701 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
2702 - symtab_hdr
->sh_info
);
2703 sym_hashes
= elf_sym_hashes (abfd
);
2704 end_hashes
= sym_hashes
+ symcount
;
2705 for (; sym_hashes
< end_hashes
; sym_hashes
++)
2707 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
2708 if ((sym_hash
->root
.type
== bfd_link_hash_defined
2709 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
2710 && sym_hash
->root
.u
.def
.section
== sec
2711 && sym_hash
->root
.u
.def
.value
> addr
2712 && sym_hash
->root
.u
.def
.value
< toaddr
)
2714 sym_hash
->root
.u
.def
.value
-= count
;
2718 /* See if we can move the ALIGN reloc forward. We have adjusted
2719 r_offset for it already. */
2720 if (irelalign
!= NULL
)
2722 bfd_vma alignto
, alignaddr
;
2724 alignto
= BFD_ALIGN (toaddr
, 1 << irelalign
->r_addend
);
2725 alignaddr
= BFD_ALIGN (irelalign
->r_offset
,
2726 1 << irelalign
->r_addend
);
2727 if (alignto
!= alignaddr
)
2729 /* Tail recursion. */
2730 return sh_elf_relax_delete_bytes (abfd
, sec
, alignaddr
,
2731 (int) (alignto
- alignaddr
));
2738 /* Look for loads and stores which we can align to four byte
2739 boundaries. This is like sh_align_loads in coff-sh.c. */
2742 sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
, pswapped
)
2743 bfd
*abfd ATTRIBUTE_UNUSED
;
2745 Elf_Internal_Rela
*internal_relocs
;
2746 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2749 Elf_Internal_Rela
*irel
, *irelend
;
2750 bfd_vma
*labels
= NULL
;
2751 bfd_vma
*label
, *label_end
;
2756 irelend
= internal_relocs
+ sec
->reloc_count
;
2758 /* Get all the addresses with labels on them. */
2759 amt
= sec
->reloc_count
;
2760 amt
*= sizeof (bfd_vma
);
2761 labels
= (bfd_vma
*) bfd_malloc (amt
);
2765 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2767 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_LABEL
)
2769 *label_end
= irel
->r_offset
;
2774 /* Note that the assembler currently always outputs relocs in
2775 address order. If that ever changes, this code will need to sort
2776 the label values and the relocs. */
2780 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2782 bfd_vma start
, stop
;
2784 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
)
2787 start
= irel
->r_offset
;
2789 for (irel
++; irel
< irelend
; irel
++)
2790 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_DATA
)
2793 stop
= irel
->r_offset
;
2795 stop
= sec
->_cooked_size
;
2797 if (! _bfd_sh_align_load_span (abfd
, sec
, contents
, sh_elf_swap_insns
,
2798 (PTR
) internal_relocs
, &label
,
2799 label_end
, start
, stop
, pswapped
))
2813 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
2816 sh_elf_swap_insns (abfd
, sec
, relocs
, contents
, addr
)
2823 Elf_Internal_Rela
*internal_relocs
= (Elf_Internal_Rela
*) relocs
;
2824 unsigned short i1
, i2
;
2825 Elf_Internal_Rela
*irel
, *irelend
;
2827 /* Swap the instructions themselves. */
2828 i1
= bfd_get_16 (abfd
, contents
+ addr
);
2829 i2
= bfd_get_16 (abfd
, contents
+ addr
+ 2);
2830 bfd_put_16 (abfd
, (bfd_vma
) i2
, contents
+ addr
);
2831 bfd_put_16 (abfd
, (bfd_vma
) i1
, contents
+ addr
+ 2);
2833 /* Adjust all reloc addresses. */
2834 irelend
= internal_relocs
+ sec
->reloc_count
;
2835 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2837 enum elf_sh_reloc_type type
;
2840 /* There are a few special types of relocs that we don't want to
2841 adjust. These relocs do not apply to the instruction itself,
2842 but are only associated with the address. */
2843 type
= (enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
);
2844 if (type
== R_SH_ALIGN
2845 || type
== R_SH_CODE
2846 || type
== R_SH_DATA
2847 || type
== R_SH_LABEL
)
2850 /* If an R_SH_USES reloc points to one of the addresses being
2851 swapped, we must adjust it. It would be incorrect to do this
2852 for a jump, though, since we want to execute both
2853 instructions after the jump. (We have avoided swapping
2854 around a label, so the jump will not wind up executing an
2855 instruction it shouldn't). */
2856 if (type
== R_SH_USES
)
2860 off
= irel
->r_offset
+ 4 + irel
->r_addend
;
2862 irel
->r_offset
+= 2;
2863 else if (off
== addr
+ 2)
2864 irel
->r_offset
-= 2;
2867 if (irel
->r_offset
== addr
)
2869 irel
->r_offset
+= 2;
2872 else if (irel
->r_offset
== addr
+ 2)
2874 irel
->r_offset
-= 2;
2883 unsigned short insn
, oinsn
;
2886 loc
= contents
+ irel
->r_offset
;
2895 insn
= bfd_get_16 (abfd
, loc
);
2898 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2900 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
2904 insn
= bfd_get_16 (abfd
, loc
);
2907 if ((oinsn
& 0xf000) != (insn
& 0xf000))
2909 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
2913 /* This reloc ignores the least significant 3 bits of
2914 the program counter before adding in the offset.
2915 This means that if ADDR is at an even address, the
2916 swap will not affect the offset. If ADDR is an at an
2917 odd address, then the instruction will be crossing a
2918 four byte boundary, and must be adjusted. */
2919 if ((addr
& 3) != 0)
2921 insn
= bfd_get_16 (abfd
, loc
);
2924 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2926 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
2934 ((*_bfd_error_handler
)
2935 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
2936 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
2937 bfd_set_error (bfd_error_bad_value
);
2946 #ifdef INCLUDE_SHMEDIA
2948 /* The size in bytes of an entry in the procedure linkage table. */
2950 #define PLT_ENTRY_SIZE 64
2952 /* First entry in an absolute procedure linkage table look like this. */
2954 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
2956 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
2957 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
2958 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
2959 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
2960 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
2961 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
2962 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2963 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2964 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2965 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2966 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2967 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2968 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2969 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2970 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2971 0x6f, 0xf0, 0xff, 0xf0, /* nop */
2974 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
2976 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
2977 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
2978 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
2979 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
2980 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
2981 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
2982 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2983 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2984 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2985 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2986 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2987 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2988 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2989 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2990 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2991 0xf0, 0xff, 0xf0, 0x6f, /* nop */
2994 /* Sebsequent entries in an absolute procedure linkage table look like
2997 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
2999 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
3000 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
3001 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
3002 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3003 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3004 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3005 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3006 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3007 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
3008 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
3009 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3010 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3011 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3012 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3013 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3014 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3017 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3019 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3020 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3021 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
3022 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3023 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3024 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3025 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3026 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3027 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
3028 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
3029 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3030 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3031 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3032 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3033 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3034 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3037 /* Entries in a PIC procedure linkage table look like this. */
3039 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3041 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3042 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3043 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
3044 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3045 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3046 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3047 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3048 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3049 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3050 0x00, 0xca, 0x45, 0x10, /* sub.l r12, r17, r17 */
3051 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3052 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3053 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3054 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3055 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3056 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3059 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3061 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3062 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3063 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
3064 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3065 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3066 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3067 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3068 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3069 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3070 0x10, 0x45, 0xca, 0x00, /* sub.l r12, r17, r17 */
3071 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3072 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3073 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3074 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3075 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3076 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3079 static const bfd_byte
*elf_sh_plt0_entry
;
3080 static const bfd_byte
*elf_sh_plt_entry
;
3081 static const bfd_byte
*elf_sh_pic_plt_entry
;
3083 /* Return size of a PLT entry. */
3084 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3086 /* Return offset of the PLT0 address in an absolute PLT entry. */
3087 #define elf_sh_plt_plt0_offset(info) 32
3089 /* Return offset of the linker in PLT0 entry. */
3090 #define elf_sh_plt0_gotplt_offset(info) 0
3092 /* Return offset of the trampoline in PLT entry */
3093 #define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
3095 /* Return offset of the symbol in PLT entry. */
3096 #define elf_sh_plt_symbol_offset(info) 0
3098 /* Return offset of the relocation in PLT entry. */
3099 #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
3102 movi_shori_putval (output_bfd
, value
, addr
)
3104 unsigned long value
;
3107 bfd_put_32 (output_bfd
,
3108 bfd_get_32 (output_bfd
, addr
)
3109 | ((value
>> 6) & 0x3fffc00),
3111 bfd_put_32 (output_bfd
,
3112 bfd_get_32 (output_bfd
, addr
+ 4)
3113 | ((value
<< 10) & 0x3fffc00),
3118 /* The size in bytes of an entry in the procedure linkage table. */
3120 #define PLT_ENTRY_SIZE 28
3122 /* First entry in an absolute procedure linkage table look like this. */
3125 /* Note - this code has been "optimised" not to use r2. r2 is used by
3126 GCC to return the address of large strutcures, so it should not be
3127 corrupted here. This does mean however, that this PLT does not conform
3128 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
3129 and r2 contains the GOT id. This version stores the GOT id in r0 and
3130 ignores the type. Loaders can easily detect this difference however,
3131 since the type will always be 0 or 8, and the GOT ids will always be
3132 greater than or equal to 12. */
3133 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3135 0xd0, 0x05, /* mov.l 2f,r0 */
3136 0x60, 0x02, /* mov.l @r0,r0 */
3137 0x2f, 0x06, /* mov.l r0,@-r15 */
3138 0xd0, 0x03, /* mov.l 1f,r0 */
3139 0x60, 0x02, /* mov.l @r0,r0 */
3140 0x40, 0x2b, /* jmp @r0 */
3141 0x60, 0xf6, /* mov.l @r15+,r0 */
3142 0x00, 0x09, /* nop */
3143 0x00, 0x09, /* nop */
3144 0x00, 0x09, /* nop */
3145 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3146 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3149 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3151 0x05, 0xd0, /* mov.l 2f,r0 */
3152 0x02, 0x60, /* mov.l @r0,r0 */
3153 0x06, 0x2f, /* mov.l r0,@-r15 */
3154 0x03, 0xd0, /* mov.l 1f,r0 */
3155 0x02, 0x60, /* mov.l @r0,r0 */
3156 0x2b, 0x40, /* jmp @r0 */
3157 0xf6, 0x60, /* mov.l @r15+,r0 */
3158 0x09, 0x00, /* nop */
3159 0x09, 0x00, /* nop */
3160 0x09, 0x00, /* nop */
3161 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3162 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3165 /* Sebsequent entries in an absolute procedure linkage table look like
3168 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3170 0xd0, 0x04, /* mov.l 1f,r0 */
3171 0x60, 0x02, /* mov.l @r0,r0 */
3172 0xd1, 0x02, /* mov.l 0f,r1 */
3173 0x40, 0x2b, /* jmp @r0 */
3174 0x60, 0x13, /* mov r1,r0 */
3175 0xd1, 0x03, /* mov.l 2f,r1 */
3176 0x40, 0x2b, /* jmp @r0 */
3177 0x00, 0x09, /* nop */
3178 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3179 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3180 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3183 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3185 0x04, 0xd0, /* mov.l 1f,r0 */
3186 0x02, 0x60, /* mov.l @r0,r0 */
3187 0x02, 0xd1, /* mov.l 0f,r1 */
3188 0x2b, 0x40, /* jmp @r0 */
3189 0x13, 0x60, /* mov r1,r0 */
3190 0x03, 0xd1, /* mov.l 2f,r1 */
3191 0x2b, 0x40, /* jmp @r0 */
3192 0x09, 0x00, /* nop */
3193 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3194 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3195 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3198 /* Entries in a PIC procedure linkage table look like this. */
3200 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3202 0xd0, 0x04, /* mov.l 1f,r0 */
3203 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3204 0x40, 0x2b, /* jmp @r0 */
3205 0x00, 0x09, /* nop */
3206 0x50, 0xc2, /* mov.l @(8,r12),r0 */
3207 0xd1, 0x03, /* mov.l 2f,r1 */
3208 0x40, 0x2b, /* jmp @r0 */
3209 0x50, 0xc1, /* mov.l @(4,r12),r0 */
3210 0x00, 0x09, /* nop */
3211 0x00, 0x09, /* nop */
3212 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3213 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3216 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3218 0x04, 0xd0, /* mov.l 1f,r0 */
3219 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3220 0x2b, 0x40, /* jmp @r0 */
3221 0x09, 0x00, /* nop */
3222 0xc2, 0x50, /* mov.l @(8,r12),r0 */
3223 0x03, 0xd1, /* mov.l 2f,r1 */
3224 0x2b, 0x40, /* jmp @r0 */
3225 0xc1, 0x50, /* mov.l @(4,r12),r0 */
3226 0x09, 0x00, /* nop */
3227 0x09, 0x00, /* nop */
3228 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3229 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3232 #else /* These are the old style PLT entries. */
3233 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3235 0xd0, 0x04, /* mov.l 1f,r0 */
3236 0xd2, 0x05, /* mov.l 2f,r2 */
3237 0x60, 0x02, /* mov.l @r0,r0 */
3238 0x62, 0x22, /* mov.l @r2,r2 */
3239 0x40, 0x2b, /* jmp @r0 */
3240 0xe0, 0x00, /* mov #0,r0 */
3241 0x00, 0x09, /* nop */
3242 0x00, 0x09, /* nop */
3243 0x00, 0x09, /* nop */
3244 0x00, 0x09, /* nop */
3245 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3246 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3249 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3251 0x04, 0xd0, /* mov.l 1f,r0 */
3252 0x05, 0xd2, /* mov.l 2f,r2 */
3253 0x02, 0x60, /* mov.l @r0,r0 */
3254 0x22, 0x62, /* mov.l @r2,r2 */
3255 0x2b, 0x40, /* jmp @r0 */
3256 0x00, 0xe0, /* mov #0,r0 */
3257 0x09, 0x00, /* nop */
3258 0x09, 0x00, /* nop */
3259 0x09, 0x00, /* nop */
3260 0x09, 0x00, /* nop */
3261 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3262 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3265 /* Sebsequent entries in an absolute procedure linkage table look like
3268 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3270 0xd0, 0x04, /* mov.l 1f,r0 */
3271 0x60, 0x02, /* mov.l @r0,r0 */
3272 0xd2, 0x02, /* mov.l 0f,r2 */
3273 0x40, 0x2b, /* jmp @r0 */
3274 0x60, 0x23, /* mov r2,r0 */
3275 0xd1, 0x03, /* mov.l 2f,r1 */
3276 0x40, 0x2b, /* jmp @r0 */
3277 0x00, 0x09, /* nop */
3278 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3279 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3280 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3283 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3285 0x04, 0xd0, /* mov.l 1f,r0 */
3286 0x02, 0x60, /* mov.l @r0,r0 */
3287 0x02, 0xd2, /* mov.l 0f,r2 */
3288 0x2b, 0x40, /* jmp @r0 */
3289 0x23, 0x60, /* mov r2,r0 */
3290 0x03, 0xd1, /* mov.l 2f,r1 */
3291 0x2b, 0x40, /* jmp @r0 */
3292 0x09, 0x00, /* nop */
3293 0, 0, 0, 0, /* 0: replaced with address of .PLT. */
3294 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3295 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3298 /* Entries in a PIC procedure linkage table look like this. */
3300 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3302 0xd0, 0x04, /* mov.l 1f,r0 */
3303 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3304 0x40, 0x2b, /* jmp @r0 */
3305 0x00, 0x09, /* nop */
3306 0x50, 0xc2, /* 0: mov.l @(8,r12),r0 */
3307 0x52, 0xc1, /* 1: mov.l @(4,r12),r2 */
3308 0xd1, 0x02, /* mov.l 2f,r1 */
3309 0x40, 0x2b, /* jmp @r0 */
3310 0xe0, 0x00, /* mov #0,r0 ! shows the type of PLT. */
3311 0x00, 0x09, /* nop */
3312 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3313 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3316 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3318 0x04, 0xd0, /* mov.l 1f,r0 */
3319 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3320 0x2b, 0x40, /* jmp @r0 */
3321 0x09, 0x00, /* nop */
3322 0xc2, 0x50, /* 0: mov.l @(8,r12),r0 */
3323 0xc1, 0x52, /* 1: mov.l @(4,r12),r2 */
3324 0x02, 0xd1, /* mov.l 2f,r1 */
3325 0x2b, 0x40, /* jmp @r0 */
3326 0x00, 0xe0, /* mov #0,r0 ! shows the type of PLT. */
3327 0x09, 0x00, /* nop */
3328 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3329 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3331 #endif /* old style PLT entries. */
3333 static const bfd_byte
*elf_sh_plt0_entry
;
3334 static const bfd_byte
*elf_sh_plt_entry
;
3335 static const bfd_byte
*elf_sh_pic_plt_entry
;
3337 /* Return size of a PLT entry. */
3338 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3340 /* Return offset of the PLT0 address in an absolute PLT entry. */
3341 #define elf_sh_plt_plt0_offset(info) 16
3343 /* Return offset of the linker in PLT0 entry. */
3344 #define elf_sh_plt0_linker_offset(info) 20
3346 /* Return offset of the GOT id in PLT0 entry. */
3347 #define elf_sh_plt0_gotid_offset(info) 24
3349 /* Return offset of the tempoline in PLT entry */
3350 #define elf_sh_plt_temp_offset(info) 8
3352 /* Return offset of the symbol in PLT entry. */
3353 #define elf_sh_plt_symbol_offset(info) 20
3355 /* Return offset of the relocation in PLT entry. */
3356 #define elf_sh_plt_reloc_offset(info) 24
3359 /* The sh linker needs to keep track of the number of relocs that it
3360 decides to copy as dynamic relocs in check_relocs for each symbol.
3361 This is so that it can later discard them if they are found to be
3362 unnecessary. We store the information in a field extending the
3363 regular ELF linker hash table. */
3365 struct elf_sh_dyn_relocs
3367 struct elf_sh_dyn_relocs
*next
;
3369 /* The input section of the reloc. */
3372 /* Total number of relocs copied for the input section. */
3373 bfd_size_type count
;
3375 /* Number of pc-relative relocs copied for the input section. */
3376 bfd_size_type pc_count
;
3379 /* sh ELF linker hash entry. */
3381 struct elf_sh_link_hash_entry
3383 struct elf_link_hash_entry root
;
3385 #ifdef INCLUDE_SHMEDIA
3386 bfd_vma datalabel_got_offset
;
3389 /* Track dynamic relocs copied for this symbol. */
3390 struct elf_sh_dyn_relocs
*dyn_relocs
;
3392 bfd_signed_vma gotplt_refcount
;
3395 /* sh ELF linker hash table. */
3397 struct elf_sh_link_hash_table
3399 struct elf_link_hash_table root
;
3401 /* Short-cuts to get to dynamic linker sections. */
3410 /* Small local sym to section mapping cache. */
3411 struct sym_sec_cache sym_sec
;
3414 /* Traverse an sh ELF linker hash table. */
3416 #define sh_elf_link_hash_traverse(table, func, info) \
3417 (elf_link_hash_traverse \
3419 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
3422 /* Get the sh ELF linker hash table from a link_info structure. */
3424 #define sh_elf_hash_table(p) \
3425 ((struct elf_sh_link_hash_table *) ((p)->hash))
3427 /* Create an entry in an sh ELF linker hash table. */
3429 static struct bfd_hash_entry
*
3430 sh_elf_link_hash_newfunc (entry
, table
, string
)
3431 struct bfd_hash_entry
*entry
;
3432 struct bfd_hash_table
*table
;
3435 struct elf_sh_link_hash_entry
*ret
=
3436 (struct elf_sh_link_hash_entry
*) entry
;
3438 /* Allocate the structure if it has not already been allocated by a
3440 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3441 ret
= ((struct elf_sh_link_hash_entry
*)
3442 bfd_hash_allocate (table
,
3443 sizeof (struct elf_sh_link_hash_entry
)));
3444 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3445 return (struct bfd_hash_entry
*) ret
;
3447 /* Call the allocation method of the superclass. */
3448 ret
= ((struct elf_sh_link_hash_entry
*)
3449 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3451 if (ret
!= (struct elf_sh_link_hash_entry
*) NULL
)
3453 struct elf_sh_link_hash_entry
*eh
;
3455 eh
= (struct elf_sh_link_hash_entry
*) ret
;
3456 eh
->dyn_relocs
= NULL
;
3457 eh
->gotplt_refcount
= 0;
3458 #ifdef INCLUDE_SHMEDIA
3459 ret
->datalabel_got_offset
= (bfd_vma
) -1;
3463 return (struct bfd_hash_entry
*) ret
;
3466 /* Create an sh ELF linker hash table. */
3468 static struct bfd_link_hash_table
*
3469 sh_elf_link_hash_table_create (abfd
)
3472 struct elf_sh_link_hash_table
*ret
;
3473 bfd_size_type amt
= sizeof (struct elf_sh_link_hash_table
);
3475 ret
= (struct elf_sh_link_hash_table
*) bfd_malloc (amt
);
3476 if (ret
== (struct elf_sh_link_hash_table
*) NULL
)
3479 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3480 sh_elf_link_hash_newfunc
))
3487 ret
->sgotplt
= NULL
;
3488 ret
->srelgot
= NULL
;
3490 ret
->srelplt
= NULL
;
3491 ret
->sdynbss
= NULL
;
3492 ret
->srelbss
= NULL
;
3493 ret
->sym_sec
.abfd
= NULL
;
3495 return &ret
->root
.root
;
3498 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
3499 shortcuts to them in our hash table. */
3502 create_got_section (dynobj
, info
)
3504 struct bfd_link_info
*info
;
3506 struct elf_sh_link_hash_table
*htab
;
3508 if (! _bfd_elf_create_got_section (dynobj
, info
))
3511 htab
= sh_elf_hash_table (info
);
3512 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
3513 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
3514 if (! htab
->sgot
|| ! htab
->sgotplt
)
3517 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
3518 if (htab
->srelgot
== NULL
3519 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
3524 | SEC_LINKER_CREATED
3526 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
3531 /* Create dynamic sections when linking against a dynamic object. */
3534 sh_elf_create_dynamic_sections (abfd
, info
)
3536 struct bfd_link_info
*info
;
3538 struct elf_sh_link_hash_table
*htab
;
3539 flagword flags
, pltflags
;
3540 register asection
*s
;
3541 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3544 switch (bed
->s
->arch_size
)
3555 bfd_set_error (bfd_error_bad_value
);
3559 htab
= sh_elf_hash_table (info
);
3561 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3562 .rel[a].bss sections. */
3564 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3565 | SEC_LINKER_CREATED
);
3568 pltflags
|= SEC_CODE
;
3569 if (bed
->plt_not_loaded
)
3570 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
3571 if (bed
->plt_readonly
)
3572 pltflags
|= SEC_READONLY
;
3574 s
= bfd_make_section (abfd
, ".plt");
3577 || ! bfd_set_section_flags (abfd
, s
, pltflags
)
3578 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3581 if (bed
->want_plt_sym
)
3583 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3585 struct elf_link_hash_entry
*h
= NULL
;
3586 if (! (_bfd_generic_link_add_one_symbol
3587 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3588 (bfd_vma
) 0, (const char *) NULL
, false,
3589 get_elf_backend_data (abfd
)->collect
,
3590 (struct bfd_link_hash_entry
**) &h
)))
3592 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3593 h
->type
= STT_OBJECT
;
3596 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
3600 s
= bfd_make_section (abfd
,
3601 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt");
3604 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3605 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3608 if (! create_got_section (abfd
, info
))
3612 const char *secname
;
3617 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3619 secflags
= bfd_get_section_flags (abfd
, sec
);
3620 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3621 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3623 secname
= bfd_get_section_name (abfd
, sec
);
3624 relname
= (char *) bfd_malloc ((bfd_size_type
) strlen (secname
) + 6);
3625 strcpy (relname
, ".rela");
3626 strcat (relname
, secname
);
3627 s
= bfd_make_section (abfd
, relname
);
3629 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3630 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3635 if (bed
->want_dynbss
)
3637 /* The .dynbss section is a place to put symbols which are defined
3638 by dynamic objects, are referenced by regular objects, and are
3639 not functions. We must allocate space for them in the process
3640 image and use a R_*_COPY reloc to tell the dynamic linker to
3641 initialize them at run time. The linker script puts the .dynbss
3642 section into the .bss section of the final image. */
3643 s
= bfd_make_section (abfd
, ".dynbss");
3646 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
3649 /* The .rel[a].bss section holds copy relocs. This section is not
3650 normally needed. We need to create it here, though, so that the
3651 linker will map it to an output section. We can't just create it
3652 only if we need it, because we will not know whether we need it
3653 until we have seen all the input files, and the first time the
3654 main linker code calls BFD after examining all the input files
3655 (size_dynamic_sections) the input sections have already been
3656 mapped to the output sections. If the section turns out not to
3657 be needed, we can discard it later. We will never need this
3658 section when generating a shared object, since they do not use
3662 s
= bfd_make_section (abfd
,
3663 (bed
->default_use_rela_p
3664 ? ".rela.bss" : ".rel.bss"));
3667 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3668 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3676 /* Adjust a symbol defined by a dynamic object and referenced by a
3677 regular object. The current definition is in some section of the
3678 dynamic object, but we're not including those sections. We have to
3679 change the definition to something the rest of the link can
3683 sh_elf_adjust_dynamic_symbol (info
, h
)
3684 struct bfd_link_info
*info
;
3685 struct elf_link_hash_entry
*h
;
3687 struct elf_sh_link_hash_table
*htab
;
3688 struct elf_sh_link_hash_entry
*eh
;
3689 struct elf_sh_dyn_relocs
*p
;
3692 unsigned int power_of_two
;
3694 dynobj
= elf_hash_table (info
)->dynobj
;
3696 /* Make sure we know what is going on here. */
3697 BFD_ASSERT (dynobj
!= NULL
3698 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
3699 || h
->weakdef
!= NULL
3700 || ((h
->elf_link_hash_flags
3701 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3702 && (h
->elf_link_hash_flags
3703 & ELF_LINK_HASH_REF_REGULAR
) != 0
3704 && (h
->elf_link_hash_flags
3705 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
3707 /* If this is a function, put it in the procedure linkage table. We
3708 will fill in the contents of the procedure linkage table later,
3709 when we know the address of the .got section. */
3710 if (h
->type
== STT_FUNC
3711 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3713 if (h
->plt
.refcount
<= 0
3715 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3716 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0
3717 && h
->root
.type
!= bfd_link_hash_undefweak
3718 && h
->root
.type
!= bfd_link_hash_undefined
))
3720 /* This case can occur if we saw a PLT reloc in an input
3721 file, but the symbol was never referred to by a dynamic
3722 object. In such a case, we don't actually need to build
3723 a procedure linkage table, and we can just do a REL32
3725 h
->plt
.offset
= (bfd_vma
) -1;
3726 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3732 h
->plt
.offset
= (bfd_vma
) -1;
3734 /* If this is a weak symbol, and there is a real definition, the
3735 processor independent code will have arranged for us to see the
3736 real definition first, and we can just use the same value. */
3737 if (h
->weakdef
!= NULL
)
3739 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3740 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3741 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3742 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3746 /* This is a reference to a symbol defined by a dynamic object which
3747 is not a function. */
3749 /* If we are creating a shared library, we must presume that the
3750 only references to the symbol are via the global offset table.
3751 For such cases we need not do anything here; the relocations will
3752 be handled correctly by relocate_section. */
3756 /* If there are no references to this symbol that do not use the
3757 GOT, we don't need to generate a copy reloc. */
3758 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
3761 /* If -z nocopyreloc was given, we won't generate them either. */
3762 if (info
->nocopyreloc
)
3764 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3768 eh
= (struct elf_sh_link_hash_entry
*) h
;
3769 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3771 s
= p
->sec
->output_section
;
3772 if (s
!= NULL
&& (s
->flags
& (SEC_READONLY
| SEC_HAS_CONTENTS
)) != 0)
3776 /* If we didn't find any dynamic relocs in sections which needs the
3777 copy reloc, then we'll be keeping the dynamic relocs and avoiding
3781 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3785 /* We must allocate the symbol in our .dynbss section, which will
3786 become part of the .bss section of the executable. There will be
3787 an entry for this symbol in the .dynsym section. The dynamic
3788 object will contain position independent code, so all references
3789 from the dynamic object to this symbol will go through the global
3790 offset table. The dynamic linker will use the .dynsym entry to
3791 determine the address it must put in the global offset table, so
3792 both the dynamic object and the regular object will refer to the
3793 same memory location for the variable. */
3795 htab
= sh_elf_hash_table (info
);
3797 BFD_ASSERT (s
!= NULL
);
3799 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
3800 copy the initial value out of the dynamic object and into the
3801 runtime process image. We need to remember the offset into the
3802 .rela.bss section we are going to use. */
3803 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3807 srel
= htab
->srelbss
;
3808 BFD_ASSERT (srel
!= NULL
);
3809 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
3810 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3813 /* We need to figure out the alignment required for this symbol. I
3814 have no idea how ELF linkers handle this. */
3815 power_of_two
= bfd_log2 (h
->size
);
3816 if (power_of_two
> 3)
3819 /* Apply the required alignment. */
3820 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
3821 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
3823 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
3827 /* Define the symbol as being at this point in the section. */
3828 h
->root
.u
.def
.section
= s
;
3829 h
->root
.u
.def
.value
= s
->_raw_size
;
3831 /* Increment the section size to make room for the symbol. */
3832 s
->_raw_size
+= h
->size
;
3837 /* This is the condition under which sh_elf_finish_dynamic_symbol
3838 will be called from elflink.h. If elflink.h doesn't call our
3839 finish_dynamic_symbol routine, we'll need to do something about
3840 initializing any .plt and .got entries in sh_elf_relocate_section. */
3841 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
3843 && ((INFO)->shared \
3844 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3845 && ((H)->dynindx != -1 \
3846 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3848 /* Allocate space in .plt, .got and associated reloc sections for
3852 allocate_dynrelocs (h
, inf
)
3853 struct elf_link_hash_entry
*h
;
3856 struct bfd_link_info
*info
;
3857 struct elf_sh_link_hash_table
*htab
;
3858 struct elf_sh_link_hash_entry
*eh
;
3859 struct elf_sh_dyn_relocs
*p
;
3861 if (h
->root
.type
== bfd_link_hash_indirect
)
3864 if (h
->root
.type
== bfd_link_hash_warning
)
3865 /* When warning symbols are created, they **replace** the "real"
3866 entry in the hash table, thus we never get to see the real
3867 symbol in a hash traversal. So look at it now. */
3868 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3870 info
= (struct bfd_link_info
*) inf
;
3871 htab
= sh_elf_hash_table (info
);
3873 eh
= (struct elf_sh_link_hash_entry
*) h
;
3874 if ((h
->got
.refcount
> 0
3875 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
3876 && eh
->gotplt_refcount
> 0)
3878 /* The symbol has been forced local, or we have some direct got refs,
3879 so treat all the gotplt refs as got refs. */
3880 h
->got
.refcount
+= eh
->gotplt_refcount
;
3881 if (h
->plt
.refcount
>= eh
->gotplt_refcount
)
3882 h
->plt
.refcount
-= eh
->gotplt_refcount
;
3885 if (htab
->root
.dynamic_sections_created
3886 && h
->plt
.refcount
> 0)
3888 /* Make sure this symbol is output as a dynamic symbol.
3889 Undefined weak syms won't yet be marked as dynamic. */
3890 if (h
->dynindx
== -1
3891 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3893 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3897 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
3899 asection
*s
= htab
->splt
;
3901 /* If this is the first .plt entry, make room for the special
3903 if (s
->_raw_size
== 0)
3904 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3906 h
->plt
.offset
= s
->_raw_size
;
3908 /* If this symbol is not defined in a regular file, and we are
3909 not generating a shared library, then set the symbol to this
3910 location in the .plt. This is required to make function
3911 pointers compare as equal between the normal executable and
3912 the shared library. */
3914 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3916 h
->root
.u
.def
.section
= s
;
3917 h
->root
.u
.def
.value
= h
->plt
.offset
;
3920 /* Make room for this entry. */
3921 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3923 /* We also need to make an entry in the .got.plt section, which
3924 will be placed in the .got section by the linker script. */
3925 htab
->sgotplt
->_raw_size
+= 4;
3927 /* We also need to make an entry in the .rel.plt section. */
3928 htab
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
3932 h
->plt
.offset
= (bfd_vma
) -1;
3933 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3938 h
->plt
.offset
= (bfd_vma
) -1;
3939 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3942 if (h
->got
.refcount
> 0)
3947 /* Make sure this symbol is output as a dynamic symbol.
3948 Undefined weak syms won't yet be marked as dynamic. */
3949 if (h
->dynindx
== -1
3950 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3952 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3957 #ifdef INCLUDE_SHMEDIA
3958 if (h
->type
== STT_DATALABEL
)
3960 struct elf_sh_link_hash_entry
*hsh
;
3962 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3963 hsh
= (struct elf_sh_link_hash_entry
*)h
;
3964 hsh
->datalabel_got_offset
= s
->_raw_size
;
3967 h
->got
.offset
= s
->_raw_size
;
3969 h
->got
.offset
= s
->_raw_size
;
3972 dyn
= htab
->root
.dynamic_sections_created
;
3973 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
3974 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
3977 h
->got
.offset
= (bfd_vma
) -1;
3979 if (eh
->dyn_relocs
== NULL
)
3982 /* In the shared -Bsymbolic case, discard space allocated for
3983 dynamic pc-relative relocs against symbols which turn out to be
3984 defined in regular objects. For the normal shared case, discard
3985 space for pc-relative relocs that have become local due to symbol
3986 visibility changes. */
3990 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
3991 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
3994 struct elf_sh_dyn_relocs
**pp
;
3996 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3998 p
->count
-= p
->pc_count
;
4009 /* For the non-shared case, discard space for relocs against
4010 symbols which turn out to need copy relocs or are not
4013 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
4014 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4015 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4016 || (htab
->root
.dynamic_sections_created
4017 && (h
->root
.type
== bfd_link_hash_undefweak
4018 || h
->root
.type
== bfd_link_hash_undefined
))))
4020 /* Make sure this symbol is output as a dynamic symbol.
4021 Undefined weak syms won't yet be marked as dynamic. */
4022 if (h
->dynindx
== -1
4023 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4025 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
4029 /* If that succeeded, we know we'll be keeping all the
4031 if (h
->dynindx
!= -1)
4035 eh
->dyn_relocs
= NULL
;
4040 /* Finally, allocate space. */
4041 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4043 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
4044 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
4050 /* Find any dynamic relocs that apply to read-only sections. */
4053 readonly_dynrelocs (h
, inf
)
4054 struct elf_link_hash_entry
*h
;
4057 struct elf_sh_link_hash_entry
*eh
;
4058 struct elf_sh_dyn_relocs
*p
;
4060 if (h
->root
.type
== bfd_link_hash_warning
)
4061 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4063 eh
= (struct elf_sh_link_hash_entry
*) h
;
4064 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4066 asection
*s
= p
->sec
->output_section
;
4068 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4070 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4072 info
->flags
|= DF_TEXTREL
;
4074 /* Not an error, just cut short the traversal. */
4081 /* Set the sizes of the dynamic sections. */
4084 sh_elf_size_dynamic_sections (output_bfd
, info
)
4085 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4086 struct bfd_link_info
*info
;
4088 struct elf_sh_link_hash_table
*htab
;
4094 htab
= sh_elf_hash_table (info
);
4095 dynobj
= htab
->root
.dynobj
;
4096 BFD_ASSERT (dynobj
!= NULL
);
4098 if (htab
->root
.dynamic_sections_created
)
4100 /* Set the contents of the .interp section to the interpreter. */
4103 s
= bfd_get_section_by_name (dynobj
, ".interp");
4104 BFD_ASSERT (s
!= NULL
);
4105 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4106 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4110 /* Set up .got offsets for local syms, and space for local dynamic
4112 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4114 bfd_signed_vma
*local_got
;
4115 bfd_signed_vma
*end_local_got
;
4116 bfd_size_type locsymcount
;
4117 Elf_Internal_Shdr
*symtab_hdr
;
4120 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
4123 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4125 struct elf_sh_dyn_relocs
*p
;
4127 for (p
= ((struct elf_sh_dyn_relocs
*)
4128 elf_section_data (s
)->local_dynrel
);
4132 if (! bfd_is_abs_section (p
->sec
)
4133 && bfd_is_abs_section (p
->sec
->output_section
))
4135 /* Input section has been discarded, either because
4136 it is a copy of a linkonce section or due to
4137 linker script /DISCARD/, so we'll be discarding
4140 else if (p
->count
!= 0)
4142 srel
= elf_section_data (p
->sec
)->sreloc
;
4143 srel
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
4144 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
4145 info
->flags
|= DF_TEXTREL
;
4150 local_got
= elf_local_got_refcounts (ibfd
);
4154 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4155 locsymcount
= symtab_hdr
->sh_info
;
4156 #ifdef INCLUDE_SHMEDIA
4157 /* Count datalabel local GOT. */
4160 end_local_got
= local_got
+ locsymcount
;
4162 srel
= htab
->srelgot
;
4163 for (; local_got
< end_local_got
; ++local_got
)
4167 *local_got
= s
->_raw_size
;
4170 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
4173 *local_got
= (bfd_vma
) -1;
4177 /* Allocate global sym .plt and .got entries, and space for global
4178 sym dynamic relocs. */
4179 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
4181 /* We now have determined the sizes of the various dynamic sections.
4182 Allocate memory for them. */
4184 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4186 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4191 || s
== htab
->sgotplt
)
4193 /* Strip this section if we don't need it; see the
4196 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4198 if (s
->_raw_size
!= 0 && s
!= htab
->srelplt
)
4201 /* We use the reloc_count field as a counter if we need
4202 to copy relocs into the output file. */
4207 /* It's not one of our sections, so don't allocate space. */
4211 if (s
->_raw_size
== 0)
4213 /* If we don't need this section, strip it from the
4214 output file. This is mostly to handle .rela.bss and
4215 .rela.plt. We must create both sections in
4216 create_dynamic_sections, because they must be created
4217 before the linker maps input sections to output
4218 sections. The linker does that before
4219 adjust_dynamic_symbol is called, and it is that
4220 function which decides whether anything needs to go
4221 into these sections. */
4223 _bfd_strip_section_from_output (info
, s
);
4227 /* Allocate memory for the section contents. We use bfd_zalloc
4228 here in case unused entries are not reclaimed before the
4229 section's contents are written out. This should not happen,
4230 but this way if it does, we get a R_SH_NONE reloc instead
4232 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4233 if (s
->contents
== NULL
)
4237 if (htab
->root
.dynamic_sections_created
)
4239 /* Add some entries to the .dynamic section. We fill in the
4240 values later, in sh_elf_finish_dynamic_sections, but we
4241 must add the entries now so that we get the correct size for
4242 the .dynamic section. The DT_DEBUG entry is filled in by the
4243 dynamic linker and used by the debugger. */
4244 #define add_dynamic_entry(TAG, VAL) \
4245 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4249 if (! add_dynamic_entry (DT_DEBUG
, 0))
4253 if (htab
->splt
->_raw_size
!= 0)
4255 if (! add_dynamic_entry (DT_PLTGOT
, 0)
4256 || ! add_dynamic_entry (DT_PLTRELSZ
, 0)
4257 || ! add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4258 || ! add_dynamic_entry (DT_JMPREL
, 0))
4264 if (! add_dynamic_entry (DT_RELA
, 0)
4265 || ! add_dynamic_entry (DT_RELASZ
, 0)
4266 || ! add_dynamic_entry (DT_RELAENT
,
4267 sizeof (Elf32_External_Rela
)))
4270 /* If any dynamic relocs apply to a read-only section,
4271 then we need a DT_TEXTREL entry. */
4272 if ((info
->flags
& DF_TEXTREL
) == 0)
4273 elf_link_hash_traverse (&htab
->root
, readonly_dynrelocs
,
4276 if ((info
->flags
& DF_TEXTREL
) != 0)
4278 if (! add_dynamic_entry (DT_TEXTREL
, 0))
4283 #undef add_dynamic_entry
4288 /* Relocate an SH ELF section. */
4291 sh_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4292 contents
, relocs
, local_syms
, local_sections
)
4294 struct bfd_link_info
*info
;
4296 asection
*input_section
;
4298 Elf_Internal_Rela
*relocs
;
4299 Elf_Internal_Sym
*local_syms
;
4300 asection
**local_sections
;
4302 struct elf_sh_link_hash_table
*htab
;
4303 Elf_Internal_Shdr
*symtab_hdr
;
4304 struct elf_link_hash_entry
**sym_hashes
;
4305 Elf_Internal_Rela
*rel
, *relend
;
4307 bfd_vma
*local_got_offsets
;
4313 htab
= sh_elf_hash_table (info
);
4314 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4315 sym_hashes
= elf_sym_hashes (input_bfd
);
4316 dynobj
= htab
->root
.dynobj
;
4317 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4320 sgotplt
= htab
->sgotplt
;
4325 relend
= relocs
+ input_section
->reloc_count
;
4326 for (; rel
< relend
; rel
++)
4329 reloc_howto_type
*howto
;
4330 unsigned long r_symndx
;
4331 Elf_Internal_Sym
*sym
;
4333 struct elf_link_hash_entry
*h
;
4335 bfd_vma addend
= (bfd_vma
) 0;
4336 bfd_reloc_status_type r
;
4337 int seen_stt_datalabel
= 0;
4339 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4341 r_type
= ELF32_R_TYPE (rel
->r_info
);
4343 /* Many of the relocs are only used for relaxing, and are
4344 handled entirely by the relaxation code. */
4345 if (r_type
> (int) R_SH_LAST_INVALID_RELOC
4346 && r_type
< (int) R_SH_LOOP_START
)
4348 if (r_type
== (int) R_SH_NONE
)
4352 || r_type
>= R_SH_max
4353 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
4354 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
4355 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_3
4356 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_3
)
4357 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_4
4358 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_4
)
4359 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_2
4360 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_2
))
4362 bfd_set_error (bfd_error_bad_value
);
4366 howto
= sh_elf_howto_table
+ r_type
;
4368 /* For relocs that aren't partial_inplace, we get the addend from
4370 if (! howto
->partial_inplace
)
4371 addend
= rel
->r_addend
;
4376 if (r_symndx
< symtab_hdr
->sh_info
)
4378 sym
= local_syms
+ r_symndx
;
4379 sec
= local_sections
[r_symndx
];
4380 relocation
= (sec
->output_section
->vma
4381 + sec
->output_offset
4383 /* A local symbol never has STO_SH5_ISA32, so we don't need
4384 datalabel processing here. Make sure this does not change
4386 if ((sym
->st_other
& STO_SH5_ISA32
) != 0)
4387 ((*info
->callbacks
->reloc_dangerous
)
4389 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4390 input_bfd
, input_section
, rel
->r_offset
));
4391 if (info
->relocateable
)
4393 /* This is a relocateable link. We don't have to change
4394 anything, unless the reloc is against a section symbol,
4395 in which case we have to adjust according to where the
4396 section symbol winds up in the output section. */
4397 sym
= local_syms
+ r_symndx
;
4398 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4400 if (! howto
->partial_inplace
)
4402 /* For relocations with the addend in the
4403 relocation, we need just to update the addend.
4404 All real relocs are of type partial_inplace; this
4405 code is mostly for completeness. */
4406 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
4411 /* Relocs of type partial_inplace need to pick up the
4412 contents in the contents and add the offset resulting
4413 from the changed location of the section symbol.
4414 Using _bfd_final_link_relocate (e.g. goto
4415 final_link_relocate) here would be wrong, because
4416 relocations marked pc_relative would get the current
4417 location subtracted, and we must only do that at the
4419 r
= _bfd_relocate_contents (howto
, input_bfd
,
4422 contents
+ rel
->r_offset
);
4423 goto relocation_done
;
4428 else if (! howto
->partial_inplace
)
4430 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
4431 addend
= rel
->r_addend
;
4433 else if ((sec
->flags
& SEC_MERGE
)
4434 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4438 if (howto
->rightshift
|| howto
->src_mask
!= 0xffffffff)
4440 (*_bfd_error_handler
)
4441 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
4442 bfd_archive_filename (input_bfd
),
4443 bfd_get_section_name (input_bfd
, input_section
),
4444 (long) rel
->r_offset
, howto
->name
);
4448 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4451 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
4453 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
4454 bfd_put_32 (input_bfd
, addend
, contents
+ rel
->r_offset
);
4460 /* Section symbol are never (?) placed in the hash table, so
4461 we can just ignore hash relocations when creating a
4462 relocateable object file. */
4463 if (info
->relocateable
)
4466 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4467 while (h
->root
.type
== bfd_link_hash_indirect
4468 || h
->root
.type
== bfd_link_hash_warning
)
4470 #ifdef INCLUDE_SHMEDIA
4471 /* If the reference passes a symbol marked with
4472 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4474 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
4476 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4478 if (h
->root
.type
== bfd_link_hash_defined
4479 || h
->root
.type
== bfd_link_hash_defweak
)
4483 dyn
= htab
->root
.dynamic_sections_created
;
4484 sec
= h
->root
.u
.def
.section
;
4485 /* In these cases, we don't need the relocation value.
4486 We check specially because in some obscure cases
4487 sec->output_section will be NULL. */
4488 if (r_type
== R_SH_GOTPC
4489 || r_type
== R_SH_GOTPC_LOW16
4490 || r_type
== R_SH_GOTPC_MEDLOW16
4491 || r_type
== R_SH_GOTPC_MEDHI16
4492 || r_type
== R_SH_GOTPC_HI16
4493 || ((r_type
== R_SH_PLT32
4494 || r_type
== R_SH_PLT_LOW16
4495 || r_type
== R_SH_PLT_MEDLOW16
4496 || r_type
== R_SH_PLT_MEDHI16
4497 || r_type
== R_SH_PLT_HI16
)
4498 && h
->plt
.offset
!= (bfd_vma
) -1)
4499 || ((r_type
== R_SH_GOT32
4500 || r_type
== R_SH_GOT_LOW16
4501 || r_type
== R_SH_GOT_MEDLOW16
4502 || r_type
== R_SH_GOT_MEDHI16
4503 || r_type
== R_SH_GOT_HI16
)
4504 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
4506 || (! info
->symbolic
&& h
->dynindx
!= -1)
4507 || (h
->elf_link_hash_flags
4508 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4509 /* The cases above are those in which relocation is
4510 overwritten in the switch block below. The cases
4511 below are those in which we must defer relocation
4512 to run-time, because we can't resolve absolute
4513 addresses when creating a shared library. */
4515 && ((! info
->symbolic
&& h
->dynindx
!= -1)
4516 || (h
->elf_link_hash_flags
4517 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
4518 && ((r_type
== R_SH_DIR32
4519 && (h
->elf_link_hash_flags
4520 & ELF_LINK_FORCED_LOCAL
) == 0)
4521 || r_type
== R_SH_REL32
)
4522 && ((input_section
->flags
& SEC_ALLOC
) != 0
4523 /* DWARF will emit R_SH_DIR32 relocations in its
4524 sections against symbols defined externally
4525 in shared libraries. We can't do anything
4527 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
4528 && (h
->elf_link_hash_flags
4529 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0))))
4531 else if (sec
->output_section
== NULL
)
4533 (*_bfd_error_handler
)
4534 (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
4535 bfd_archive_filename (input_bfd
), h
->root
.root
.string
,
4536 bfd_get_section_name (input_bfd
, input_section
));
4540 relocation
= ((h
->root
.u
.def
.value
4541 + sec
->output_section
->vma
4542 + sec
->output_offset
)
4543 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4544 symbol value, unless we've seen
4545 STT_DATALABEL on the way to it. */
4546 | ((h
->other
& STO_SH5_ISA32
) != 0
4547 && ! seen_stt_datalabel
));
4549 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4551 else if (info
->shared
4552 && (! info
->symbolic
|| info
->allow_shlib_undefined
)
4553 && ! info
->no_undefined
4554 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4558 if (! ((*info
->callbacks
->undefined_symbol
)
4559 (info
, h
->root
.root
.string
, input_bfd
,
4560 input_section
, rel
->r_offset
,
4561 (!info
->shared
|| info
->no_undefined
4562 || ELF_ST_VISIBILITY (h
->other
)))))
4568 switch ((int) r_type
)
4570 final_link_relocate
:
4571 /* COFF relocs don't use the addend. The addend is used for
4572 R_SH_DIR32 to be compatible with other compilers. */
4573 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4574 contents
, rel
->r_offset
,
4575 relocation
, addend
);
4580 goto final_link_relocate
;
4585 /* If the reloc is against the start of this section, then
4586 the assembler has already taken care of it and the reloc
4587 is here only to assist in relaxing. If the reloc is not
4588 against the start of this section, then it's against an
4589 external symbol and we must deal with it ourselves. */
4590 if (input_section
->output_section
->vma
+ input_section
->output_offset
4593 int disp
= (relocation
4594 - input_section
->output_section
->vma
4595 - input_section
->output_offset
4601 case R_SH_DIR8WPZ
: mask
= 1; break;
4602 case R_SH_DIR8WPL
: mask
= 3; break;
4603 default: mask
= 0; break;
4607 ((*_bfd_error_handler
)
4608 (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4609 bfd_archive_filename (input_section
->owner
),
4610 (unsigned long) rel
->r_offset
));
4611 bfd_set_error (bfd_error_bad_value
);
4615 goto final_link_relocate
;
4621 #ifdef INCLUDE_SHMEDIA
4622 if (shmedia_prepare_reloc (info
, input_bfd
, input_section
,
4623 contents
, rel
, &relocation
))
4624 goto final_link_relocate
;
4626 bfd_set_error (bfd_error_bad_value
);
4633 && (input_section
->flags
& SEC_ALLOC
) != 0
4634 && (r_type
!= R_SH_REL32
4637 && (! info
->symbolic
4638 || (h
->elf_link_hash_flags
4639 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
4641 Elf_Internal_Rela outrel
;
4642 boolean skip
, relocate
;
4644 /* When generating a shared object, these relocations
4645 are copied into the output file to be resolved at run
4652 name
= (bfd_elf_string_from_elf_section
4654 elf_elfheader (input_bfd
)->e_shstrndx
,
4655 elf_section_data (input_section
)->rel_hdr
.sh_name
));
4659 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
4660 && strcmp (bfd_get_section_name (input_bfd
,
4664 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4665 BFD_ASSERT (sreloc
!= NULL
);
4672 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
4674 if (outrel
.r_offset
== (bfd_vma
) -1)
4676 else if (outrel
.r_offset
== (bfd_vma
) -2)
4677 skip
= true, relocate
= true;
4678 outrel
.r_offset
+= (input_section
->output_section
->vma
4679 + input_section
->output_offset
);
4682 memset (&outrel
, 0, sizeof outrel
);
4683 else if (r_type
== R_SH_REL32
)
4685 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
4686 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_REL32
);
4688 = bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4692 /* h->dynindx may be -1 if this symbol was marked to
4695 || ((info
->symbolic
|| h
->dynindx
== -1)
4696 && (h
->elf_link_hash_flags
4697 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
4700 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
4702 = relocation
+ bfd_get_32 (input_bfd
,
4703 contents
+ rel
->r_offset
);
4707 BFD_ASSERT (h
->dynindx
!= -1);
4708 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_DIR32
);
4710 = relocation
+ bfd_get_32 (input_bfd
,
4711 contents
+ rel
->r_offset
);
4715 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
4716 (((Elf32_External_Rela
*)
4718 + sreloc
->reloc_count
));
4719 ++sreloc
->reloc_count
;
4721 /* If this reloc is against an external symbol, we do
4722 not want to fiddle with the addend. Otherwise, we
4723 need to include the symbol value so that it becomes
4724 an addend for the dynamic reloc. */
4728 goto final_link_relocate
;
4731 #ifdef INCLUDE_SHMEDIA
4732 case R_SH_GOTPLT_LOW16
:
4733 case R_SH_GOTPLT_MEDLOW16
:
4734 case R_SH_GOTPLT_MEDHI16
:
4735 case R_SH_GOTPLT_HI16
:
4736 case R_SH_GOTPLT10BY4
:
4737 case R_SH_GOTPLT10BY8
:
4739 /* Relocation is to the entry for this symbol in the
4740 procedure linkage table. */
4743 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
4747 || h
->plt
.offset
== (bfd_vma
) -1
4748 || h
->got
.offset
!= (bfd_vma
) -1)
4751 /* Relocation is to the entry for this symbol in the global
4752 offset table extension for the procedure linkage table. */
4754 BFD_ASSERT (sgotplt
!= NULL
);
4755 relocation
= (sgotplt
->output_offset
4756 + ((h
->plt
.offset
/ elf_sh_sizeof_plt (info
)
4760 relocation
-= GOT_BIAS
;
4763 goto final_link_relocate
;
4767 #ifdef INCLUDE_SHMEDIA
4768 case R_SH_GOT_LOW16
:
4769 case R_SH_GOT_MEDLOW16
:
4770 case R_SH_GOT_MEDHI16
:
4775 /* Relocation is to the entry for this symbol in the global
4778 BFD_ASSERT (sgot
!= NULL
);
4785 off
= h
->got
.offset
;
4786 #ifdef INCLUDE_SHMEDIA
4787 if (seen_stt_datalabel
)
4789 struct elf_sh_link_hash_entry
*hsh
;
4791 hsh
= (struct elf_sh_link_hash_entry
*)h
;
4792 off
= hsh
->datalabel_got_offset
;
4795 BFD_ASSERT (off
!= (bfd_vma
) -1);
4797 dyn
= htab
->root
.dynamic_sections_created
;
4798 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
4800 && (info
->symbolic
|| h
->dynindx
== -1
4801 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
4802 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
4804 /* This is actually a static link, or it is a
4805 -Bsymbolic link and the symbol is defined
4806 locally, or the symbol was forced to be local
4807 because of a version file. We must initialize
4808 this entry in the global offset table. Since the
4809 offset must always be a multiple of 4, we use the
4810 least significant bit to record whether we have
4811 initialized it already.
4813 When doing a dynamic link, we create a .rela.got
4814 relocation entry to initialize the value. This
4815 is done in the finish_dynamic_symbol routine. */
4820 bfd_put_32 (output_bfd
, relocation
,
4821 sgot
->contents
+ off
);
4822 #ifdef INCLUDE_SHMEDIA
4823 if (seen_stt_datalabel
)
4825 struct elf_sh_link_hash_entry
*hsh
;
4827 hsh
= (struct elf_sh_link_hash_entry
*)h
;
4828 hsh
->datalabel_got_offset
|= 1;
4836 relocation
= sgot
->output_offset
+ off
;
4842 #ifdef INCLUDE_SHMEDIA
4845 BFD_ASSERT (local_got_offsets
!= NULL
4846 && (local_got_offsets
[symtab_hdr
->sh_info
4850 off
= local_got_offsets
[symtab_hdr
->sh_info
4856 BFD_ASSERT (local_got_offsets
!= NULL
4857 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
4859 off
= local_got_offsets
[r_symndx
];
4860 #ifdef INCLUDE_SHMEDIA
4864 /* The offset must always be a multiple of 4. We use
4865 the least significant bit to record whether we have
4866 already generated the necessary reloc. */
4871 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
4876 Elf_Internal_Rela outrel
;
4878 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
4879 BFD_ASSERT (srelgot
!= NULL
);
4881 outrel
.r_offset
= (sgot
->output_section
->vma
4882 + sgot
->output_offset
4884 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
4885 outrel
.r_addend
= relocation
;
4886 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
4887 (((Elf32_External_Rela
*)
4889 + srelgot
->reloc_count
));
4890 ++srelgot
->reloc_count
;
4893 #ifdef INCLUDE_SHMEDIA
4895 local_got_offsets
[symtab_hdr
->sh_info
+ r_symndx
] |= 1;
4898 local_got_offsets
[r_symndx
] |= 1;
4901 relocation
= sgot
->output_offset
+ off
;
4905 relocation
-= GOT_BIAS
;
4908 goto final_link_relocate
;
4911 #ifdef INCLUDE_SHMEDIA
4912 case R_SH_GOTOFF_LOW16
:
4913 case R_SH_GOTOFF_MEDLOW16
:
4914 case R_SH_GOTOFF_MEDHI16
:
4915 case R_SH_GOTOFF_HI16
:
4917 /* Relocation is relative to the start of the global offset
4920 BFD_ASSERT (sgot
!= NULL
);
4922 /* Note that sgot->output_offset is not involved in this
4923 calculation. We always want the start of .got. If we
4924 defined _GLOBAL_OFFSET_TABLE in a different way, as is
4925 permitted by the ABI, we might have to change this
4927 relocation
-= sgot
->output_section
->vma
;
4930 relocation
-= GOT_BIAS
;
4933 addend
= rel
->r_addend
;
4935 goto final_link_relocate
;
4938 #ifdef INCLUDE_SHMEDIA
4939 case R_SH_GOTPC_LOW16
:
4940 case R_SH_GOTPC_MEDLOW16
:
4941 case R_SH_GOTPC_MEDHI16
:
4942 case R_SH_GOTPC_HI16
:
4944 /* Use global offset table as symbol value. */
4946 BFD_ASSERT (sgot
!= NULL
);
4947 relocation
= sgot
->output_section
->vma
;
4950 relocation
+= GOT_BIAS
;
4953 addend
= rel
->r_addend
;
4955 goto final_link_relocate
;
4958 #ifdef INCLUDE_SHMEDIA
4959 case R_SH_PLT_LOW16
:
4960 case R_SH_PLT_MEDLOW16
:
4961 case R_SH_PLT_MEDHI16
:
4964 /* Relocation is to the entry for this symbol in the
4965 procedure linkage table. */
4967 /* Resolve a PLT reloc against a local symbol directly,
4968 without using the procedure linkage table. */
4970 goto final_link_relocate
;
4972 if (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
4973 goto final_link_relocate
;
4975 if (h
->plt
.offset
== (bfd_vma
) -1)
4977 /* We didn't make a PLT entry for this symbol. This
4978 happens when statically linking PIC code, or when
4979 using -Bsymbolic. */
4980 goto final_link_relocate
;
4983 BFD_ASSERT (splt
!= NULL
);
4984 relocation
= (splt
->output_section
->vma
4985 + splt
->output_offset
4988 #ifdef INCLUDE_SHMEDIA
4992 addend
= rel
->r_addend
;
4994 goto final_link_relocate
;
4996 case R_SH_LOOP_START
:
4998 static bfd_vma start
, end
;
5000 start
= (relocation
+ rel
->r_addend
5001 - (sec
->output_section
->vma
+ sec
->output_offset
));
5002 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5003 rel
->r_offset
, sec
, start
, end
);
5007 end
= (relocation
+ rel
->r_addend
5008 - (sec
->output_section
->vma
+ sec
->output_offset
));
5009 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5010 rel
->r_offset
, sec
, start
, end
);
5016 if (r
!= bfd_reloc_ok
)
5021 case bfd_reloc_outofrange
:
5023 case bfd_reloc_overflow
:
5028 name
= h
->root
.root
.string
;
5031 name
= (bfd_elf_string_from_elf_section
5032 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5036 name
= bfd_section_name (input_bfd
, sec
);
5038 if (! ((*info
->callbacks
->reloc_overflow
)
5039 (info
, name
, howto
->name
, (bfd_vma
) 0,
5040 input_bfd
, input_section
, rel
->r_offset
)))
5051 /* This is a version of bfd_generic_get_relocated_section_contents
5052 which uses sh_elf_relocate_section. */
5055 sh_elf_get_relocated_section_contents (output_bfd
, link_info
, link_order
,
5056 data
, relocateable
, symbols
)
5058 struct bfd_link_info
*link_info
;
5059 struct bfd_link_order
*link_order
;
5061 boolean relocateable
;
5064 Elf_Internal_Shdr
*symtab_hdr
;
5065 asection
*input_section
= link_order
->u
.indirect
.section
;
5066 bfd
*input_bfd
= input_section
->owner
;
5067 asection
**sections
= NULL
;
5068 Elf_Internal_Rela
*internal_relocs
= NULL
;
5069 Elf_Internal_Sym
*isymbuf
= NULL
;
5071 /* We only need to handle the case of relaxing, or of having a
5072 particular set of section contents, specially. */
5074 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
5075 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
5080 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5082 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
5083 (size_t) input_section
->_raw_size
);
5085 if ((input_section
->flags
& SEC_RELOC
) != 0
5086 && input_section
->reloc_count
> 0)
5089 Elf_Internal_Sym
*isym
, *isymend
;
5092 internal_relocs
= (_bfd_elf32_link_read_relocs
5093 (input_bfd
, input_section
, (PTR
) NULL
,
5094 (Elf_Internal_Rela
*) NULL
, false));
5095 if (internal_relocs
== NULL
)
5098 if (symtab_hdr
->sh_info
!= 0)
5100 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5101 if (isymbuf
== NULL
)
5102 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
5103 symtab_hdr
->sh_info
, 0,
5105 if (isymbuf
== NULL
)
5109 amt
= symtab_hdr
->sh_info
;
5110 amt
*= sizeof (asection
*);
5111 sections
= (asection
**) bfd_malloc (amt
);
5112 if (sections
== NULL
&& amt
!= 0)
5115 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
5116 for (isym
= isymbuf
, secpp
= sections
; isym
< isymend
; ++isym
, ++secpp
)
5120 if (isym
->st_shndx
== SHN_UNDEF
)
5121 isec
= bfd_und_section_ptr
;
5122 else if (isym
->st_shndx
== SHN_ABS
)
5123 isec
= bfd_abs_section_ptr
;
5124 else if (isym
->st_shndx
== SHN_COMMON
)
5125 isec
= bfd_com_section_ptr
;
5127 isec
= bfd_section_from_elf_index (input_bfd
, isym
->st_shndx
);
5132 if (! sh_elf_relocate_section (output_bfd
, link_info
, input_bfd
,
5133 input_section
, data
, internal_relocs
,
5137 if (sections
!= NULL
)
5140 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5142 if (elf_section_data (input_section
)->relocs
!= internal_relocs
)
5143 free (internal_relocs
);
5149 if (sections
!= NULL
)
5152 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5154 if (internal_relocs
!= NULL
5155 && elf_section_data (input_section
)->relocs
!= internal_relocs
)
5156 free (internal_relocs
);
5161 sh_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
5163 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
5164 Elf_Internal_Rela
*rel
;
5165 struct elf_link_hash_entry
*h
;
5166 Elf_Internal_Sym
*sym
;
5170 switch (ELF32_R_TYPE (rel
->r_info
))
5172 case R_SH_GNU_VTINHERIT
:
5173 case R_SH_GNU_VTENTRY
:
5177 #ifdef INCLUDE_SHMEDIA
5178 while (h
->root
.type
== bfd_link_hash_indirect
5179 && h
->root
.u
.i
.link
)
5180 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5182 switch (h
->root
.type
)
5184 case bfd_link_hash_defined
:
5185 case bfd_link_hash_defweak
:
5186 return h
->root
.u
.def
.section
;
5188 case bfd_link_hash_common
:
5189 return h
->root
.u
.c
.p
->section
;
5197 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5202 /* Update the got entry reference counts for the section being removed. */
5205 sh_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
5207 struct bfd_link_info
*info
;
5209 const Elf_Internal_Rela
*relocs
;
5211 Elf_Internal_Shdr
*symtab_hdr
;
5212 struct elf_link_hash_entry
**sym_hashes
;
5213 bfd_signed_vma
*local_got_refcounts
;
5214 const Elf_Internal_Rela
*rel
, *relend
;
5215 unsigned long r_symndx
;
5216 struct elf_link_hash_entry
*h
;
5217 struct elf_sh_link_hash_entry
*eh
;
5219 elf_section_data (sec
)->local_dynrel
= NULL
;
5221 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5222 sym_hashes
= elf_sym_hashes (abfd
);
5223 local_got_refcounts
= elf_local_got_refcounts (abfd
);
5225 relend
= relocs
+ sec
->reloc_count
;
5226 for (rel
= relocs
; rel
< relend
; rel
++)
5227 switch (ELF32_R_TYPE (rel
->r_info
))
5232 #ifdef INCLUDE_SHMEDIA
5233 case R_SH_GOT_LOW16
:
5234 case R_SH_GOT_MEDLOW16
:
5235 case R_SH_GOT_MEDHI16
:
5239 case R_SH_GOTOFF_LOW16
:
5240 case R_SH_GOTOFF_MEDLOW16
:
5241 case R_SH_GOTOFF_MEDHI16
:
5242 case R_SH_GOTOFF_HI16
:
5243 case R_SH_GOTPC_LOW16
:
5244 case R_SH_GOTPC_MEDLOW16
:
5245 case R_SH_GOTPC_MEDHI16
:
5246 case R_SH_GOTPC_HI16
:
5248 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5249 if (r_symndx
>= symtab_hdr
->sh_info
)
5251 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5252 if (h
->got
.refcount
> 0)
5253 h
->got
.refcount
-= 1;
5255 else if (local_got_refcounts
!= NULL
)
5257 if (local_got_refcounts
[r_symndx
] > 0)
5258 local_got_refcounts
[r_symndx
] -= 1;
5264 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5265 if (r_symndx
>= symtab_hdr
->sh_info
)
5267 struct elf_sh_link_hash_entry
*eh
;
5268 struct elf_sh_dyn_relocs
**pp
;
5269 struct elf_sh_dyn_relocs
*p
;
5271 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5273 if (!info
->shared
&& h
->plt
.refcount
> 0)
5274 h
->plt
.refcount
-= 1;
5276 eh
= (struct elf_sh_link_hash_entry
*) h
;
5278 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5281 if (ELF32_R_TYPE (rel
->r_info
) == R_SH_REL32
)
5292 #ifdef INCLUDE_SHMEDIA
5293 case R_SH_PLT_LOW16
:
5294 case R_SH_PLT_MEDLOW16
:
5295 case R_SH_PLT_MEDHI16
:
5298 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5299 if (r_symndx
>= symtab_hdr
->sh_info
)
5301 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5302 if (h
->plt
.refcount
> 0)
5303 h
->plt
.refcount
-= 1;
5308 #ifdef INCLUDE_SHMEDIA
5309 case R_SH_GOTPLT_LOW16
:
5310 case R_SH_GOTPLT_MEDLOW16
:
5311 case R_SH_GOTPLT_MEDHI16
:
5312 case R_SH_GOTPLT_HI16
:
5313 case R_SH_GOTPLT10BY4
:
5314 case R_SH_GOTPLT10BY8
:
5316 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5317 if (r_symndx
>= symtab_hdr
->sh_info
)
5319 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5320 eh
= (struct elf_sh_link_hash_entry
*) h
;
5321 if (eh
->gotplt_refcount
> 0)
5323 eh
->gotplt_refcount
-= 1;
5324 if (h
->plt
.refcount
> 0)
5325 h
->plt
.refcount
-= 1;
5327 else if (h
->got
.refcount
> 0)
5328 h
->got
.refcount
-= 1;
5330 else if (local_got_refcounts
!= NULL
)
5332 if (local_got_refcounts
[r_symndx
] > 0)
5333 local_got_refcounts
[r_symndx
] -= 1;
5344 /* Copy the extra info we tack onto an elf_link_hash_entry. */
5347 sh_elf_copy_indirect_symbol (bed
, dir
, ind
)
5348 struct elf_backend_data
*bed
;
5349 struct elf_link_hash_entry
*dir
, *ind
;
5351 struct elf_sh_link_hash_entry
*edir
, *eind
;
5353 edir
= (struct elf_sh_link_hash_entry
*) dir
;
5354 eind
= (struct elf_sh_link_hash_entry
*) ind
;
5356 if (eind
->dyn_relocs
!= NULL
)
5358 if (edir
->dyn_relocs
!= NULL
)
5360 struct elf_sh_dyn_relocs
**pp
;
5361 struct elf_sh_dyn_relocs
*p
;
5363 BFD_ASSERT (ind
->root
.type
!= bfd_link_hash_indirect
);
5365 /* Add reloc counts against the weak sym to the strong sym
5366 list. Merge any entries against the same section. */
5367 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
5369 struct elf_sh_dyn_relocs
*q
;
5371 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
5372 if (q
->sec
== p
->sec
)
5374 q
->pc_count
+= p
->pc_count
;
5375 q
->count
+= p
->count
;
5382 *pp
= edir
->dyn_relocs
;
5385 edir
->dyn_relocs
= eind
->dyn_relocs
;
5386 eind
->dyn_relocs
= NULL
;
5388 edir
->gotplt_refcount
= eind
->gotplt_refcount
;
5389 eind
->gotplt_refcount
= 0;
5391 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
5394 /* Look through the relocs for a section during the first phase.
5395 Since we don't do .gots or .plts, we just need to consider the
5396 virtual table relocs for gc. */
5399 sh_elf_check_relocs (abfd
, info
, sec
, relocs
)
5401 struct bfd_link_info
*info
;
5403 const Elf_Internal_Rela
*relocs
;
5405 Elf_Internal_Shdr
*symtab_hdr
;
5406 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
5407 struct elf_sh_link_hash_table
*htab
;
5408 const Elf_Internal_Rela
*rel
;
5409 const Elf_Internal_Rela
*rel_end
;
5411 bfd_vma
*local_got_offsets
;
5420 if (info
->relocateable
)
5423 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5424 sym_hashes
= elf_sym_hashes (abfd
);
5425 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof (Elf32_External_Sym
);
5426 if (!elf_bad_symtab (abfd
))
5427 sym_hashes_end
-= symtab_hdr
->sh_info
;
5429 htab
= sh_elf_hash_table (info
);
5430 dynobj
= htab
->root
.dynobj
;
5431 local_got_offsets
= elf_local_got_offsets (abfd
);
5433 rel_end
= relocs
+ sec
->reloc_count
;
5434 for (rel
= relocs
; rel
< rel_end
; rel
++)
5436 struct elf_link_hash_entry
*h
;
5437 unsigned long r_symndx
;
5439 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5440 if (r_symndx
< symtab_hdr
->sh_info
)
5443 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5445 /* Some relocs require a global offset table. */
5446 if (htab
->sgot
== NULL
)
5448 switch (ELF32_R_TYPE (rel
->r_info
))
5454 #ifdef INCLUDE_SHMEDIA
5455 case R_SH_GOTPLT_LOW16
:
5456 case R_SH_GOTPLT_MEDLOW16
:
5457 case R_SH_GOTPLT_MEDHI16
:
5458 case R_SH_GOTPLT_HI16
:
5459 case R_SH_GOTPLT10BY4
:
5460 case R_SH_GOTPLT10BY8
:
5461 case R_SH_GOT_LOW16
:
5462 case R_SH_GOT_MEDLOW16
:
5463 case R_SH_GOT_MEDHI16
:
5467 case R_SH_GOTOFF_LOW16
:
5468 case R_SH_GOTOFF_MEDLOW16
:
5469 case R_SH_GOTOFF_MEDHI16
:
5470 case R_SH_GOTOFF_HI16
:
5471 case R_SH_GOTPC_LOW16
:
5472 case R_SH_GOTPC_MEDLOW16
:
5473 case R_SH_GOTPC_MEDHI16
:
5474 case R_SH_GOTPC_HI16
:
5477 htab
->root
.dynobj
= dynobj
= abfd
;
5478 if (! create_got_section (dynobj
, info
))
5487 switch (ELF32_R_TYPE (rel
->r_info
))
5489 /* This relocation describes the C++ object vtable hierarchy.
5490 Reconstruct it for later use during GC. */
5491 case R_SH_GNU_VTINHERIT
:
5492 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5496 /* This relocation describes which C++ vtable entries are actually
5497 used. Record for later use during GC. */
5498 case R_SH_GNU_VTENTRY
:
5499 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
5505 #ifdef INCLUDE_SHMEDIA
5506 case R_SH_GOT_LOW16
:
5507 case R_SH_GOT_MEDLOW16
:
5508 case R_SH_GOT_MEDHI16
:
5514 h
->got
.refcount
+= 1;
5517 bfd_signed_vma
*local_got_refcounts
;
5519 /* This is a global offset table entry for a local
5521 local_got_refcounts
= elf_local_got_refcounts (abfd
);
5522 if (local_got_refcounts
== NULL
)
5526 size
= symtab_hdr
->sh_info
;
5527 size
*= sizeof (bfd_signed_vma
);
5528 #ifdef INCLUDE_SHMEDIA
5529 /* Reserve space for both the datalabel and
5530 codelabel local GOT offsets. */
5533 local_got_refcounts
= ((bfd_signed_vma
*)
5534 bfd_zalloc (abfd
, size
));
5535 if (local_got_refcounts
== NULL
)
5537 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
5539 local_got_refcounts
[r_symndx
] += 1;
5544 #ifdef INCLUDE_SHMEDIA
5545 case R_SH_GOTPLT_LOW16
:
5546 case R_SH_GOTPLT_MEDLOW16
:
5547 case R_SH_GOTPLT_MEDHI16
:
5548 case R_SH_GOTPLT_HI16
:
5549 case R_SH_GOTPLT10BY4
:
5550 case R_SH_GOTPLT10BY8
:
5552 /* If this is a local symbol, we resolve it directly without
5553 creating a procedure linkage table entry. */
5556 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
5559 || h
->dynindx
== -1)
5562 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
5563 h
->plt
.refcount
+= 1;
5564 ((struct elf_sh_link_hash_entry
*) h
)->gotplt_refcount
+= 1;
5569 #ifdef INCLUDE_SHMEDIA
5570 case R_SH_PLT_LOW16
:
5571 case R_SH_PLT_MEDLOW16
:
5572 case R_SH_PLT_MEDHI16
:
5575 /* This symbol requires a procedure linkage table entry. We
5576 actually build the entry in adjust_dynamic_symbol,
5577 because this might be a case of linking PIC code which is
5578 never referenced by a dynamic object, in which case we
5579 don't need to generate a procedure linkage table entry
5582 /* If this is a local symbol, we resolve it directly without
5583 creating a procedure linkage table entry. */
5587 if (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
5590 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
5591 h
->plt
.refcount
+= 1;
5596 if (h
!= NULL
&& ! info
->shared
)
5598 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
5599 h
->plt
.refcount
+= 1;
5602 /* If we are creating a shared library, and this is a reloc
5603 against a global symbol, or a non PC relative reloc
5604 against a local symbol, then we need to copy the reloc
5605 into the shared library. However, if we are linking with
5606 -Bsymbolic, we do not need to copy a reloc against a
5607 global symbol which is defined in an object we are
5608 including in the link (i.e., DEF_REGULAR is set). At
5609 this point we have not seen all the input files, so it is
5610 possible that DEF_REGULAR is not set now but will be set
5611 later (it is never cleared). We account for that
5612 possibility below by storing information in the
5613 dyn_relocs field of the hash table entry. A similar
5614 situation occurs when creating shared libraries and symbol
5615 visibility changes render the symbol local.
5617 If on the other hand, we are creating an executable, we
5618 may need to keep relocations for symbols satisfied by a
5619 dynamic library if we manage to avoid copy relocs for the
5622 && (sec
->flags
& SEC_ALLOC
) != 0
5623 && (ELF32_R_TYPE (rel
->r_info
) != R_SH_REL32
5625 && (! info
->symbolic
5626 || h
->root
.type
== bfd_link_hash_defweak
5627 || (h
->elf_link_hash_flags
5628 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
5630 && (sec
->flags
& SEC_ALLOC
) != 0
5632 && (h
->root
.type
== bfd_link_hash_defweak
5633 || (h
->elf_link_hash_flags
5634 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
5636 struct elf_sh_dyn_relocs
*p
;
5637 struct elf_sh_dyn_relocs
**head
;
5640 htab
->root
.dynobj
= dynobj
= abfd
;
5642 /* When creating a shared object, we must copy these
5643 reloc types into the output file. We create a reloc
5644 section in dynobj and make room for this reloc. */
5649 name
= (bfd_elf_string_from_elf_section
5651 elf_elfheader (abfd
)->e_shstrndx
,
5652 elf_section_data (sec
)->rel_hdr
.sh_name
));
5656 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5657 && strcmp (bfd_get_section_name (abfd
, sec
),
5660 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5665 sreloc
= bfd_make_section (dynobj
, name
);
5666 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
5667 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
5668 if ((sec
->flags
& SEC_ALLOC
) != 0)
5669 flags
|= SEC_ALLOC
| SEC_LOAD
;
5671 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
5672 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
5675 if (sec
->flags
& SEC_READONLY
)
5676 info
->flags
|= DF_TEXTREL
;
5677 elf_section_data (sec
)->sreloc
= sreloc
;
5680 /* If this is a global symbol, we count the number of
5681 relocations we need for this symbol. */
5683 head
= &((struct elf_sh_link_hash_entry
*) h
)->dyn_relocs
;
5688 /* Track dynamic relocs needed for local syms too. */
5689 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
5694 head
= ((struct elf_sh_dyn_relocs
**)
5695 &elf_section_data (s
)->local_dynrel
);
5699 if (p
== NULL
|| p
->sec
!= sec
)
5701 bfd_size_type amt
= sizeof (*p
);
5702 p
= ((struct elf_sh_dyn_relocs
*) bfd_alloc (dynobj
, amt
));
5713 if (ELF32_R_TYPE (rel
->r_info
) == R_SH_REL32
)
5724 #ifndef sh_elf_set_mach_from_flags
5726 sh_elf_set_mach_from_flags (abfd
)
5729 flagword flags
= elf_elfheader (abfd
)->e_flags
;
5731 switch (flags
& EF_SH_MACH_MASK
)
5734 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh
);
5737 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh2
);
5740 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh_dsp
);
5743 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3
);
5746 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3_dsp
);
5749 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3e
);
5753 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh4
);
5760 #endif /* not sh_elf_set_mach_from_flags */
5762 #ifndef sh_elf_set_private_flags
5763 /* Function to keep SH specific file flags. */
5766 sh_elf_set_private_flags (abfd
, flags
)
5770 BFD_ASSERT (! elf_flags_init (abfd
)
5771 || elf_elfheader (abfd
)->e_flags
== flags
);
5773 elf_elfheader (abfd
)->e_flags
= flags
;
5774 elf_flags_init (abfd
) = true;
5775 return sh_elf_set_mach_from_flags (abfd
);
5777 #endif /* not sh_elf_set_private_flags */
5779 #ifndef sh_elf_copy_private_data
5780 /* Copy backend specific data from one object module to another */
5783 sh_elf_copy_private_data (ibfd
, obfd
)
5787 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
5788 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
5791 return sh_elf_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
5793 #endif /* not sh_elf_copy_private_data */
5795 #ifndef sh_elf_merge_private_data
5796 /* This routine checks for linking big and little endian objects
5797 together, and for linking sh-dsp with sh3e / sh4 objects. */
5800 sh_elf_merge_private_data (ibfd
, obfd
)
5804 flagword old_flags
, new_flags
;
5806 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
5809 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
5810 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
5813 if (! elf_flags_init (obfd
))
5815 /* This happens when ld starts out with a 'blank' output file. */
5816 elf_flags_init (obfd
) = true;
5817 elf_elfheader (obfd
)->e_flags
= EF_SH1
;
5819 old_flags
= elf_elfheader (obfd
)->e_flags
;
5820 new_flags
= elf_elfheader (ibfd
)->e_flags
;
5821 if ((EF_SH_HAS_DSP (old_flags
) && EF_SH_HAS_FP (new_flags
))
5822 || (EF_SH_HAS_DSP (new_flags
) && EF_SH_HAS_FP (old_flags
)))
5824 (*_bfd_error_handler
)
5825 ("%s: uses %s instructions while previous modules use %s instructions",
5826 bfd_archive_filename (ibfd
),
5827 EF_SH_HAS_DSP (new_flags
) ? "dsp" : "floating point",
5828 EF_SH_HAS_DSP (new_flags
) ? "floating point" : "dsp");
5829 bfd_set_error (bfd_error_bad_value
);
5832 elf_elfheader (obfd
)->e_flags
= EF_SH_MERGE_MACH (old_flags
, new_flags
);
5834 return sh_elf_set_mach_from_flags (obfd
);
5836 #endif /* not sh_elf_merge_private_data */
5838 /* Finish up dynamic symbol handling. We set the contents of various
5839 dynamic sections here. */
5842 sh_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5844 struct bfd_link_info
*info
;
5845 struct elf_link_hash_entry
*h
;
5846 Elf_Internal_Sym
*sym
;
5848 struct elf_sh_link_hash_table
*htab
;
5851 htab
= sh_elf_hash_table (info
);
5852 dynobj
= htab
->root
.dynobj
;
5854 if (h
->plt
.offset
!= (bfd_vma
) -1)
5862 Elf_Internal_Rela rel
;
5864 /* This symbol has an entry in the procedure linkage table. Set
5867 BFD_ASSERT (h
->dynindx
!= -1);
5870 sgot
= htab
->sgotplt
;
5871 srel
= htab
->srelplt
;
5872 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
5874 /* Get the index in the procedure linkage table which
5875 corresponds to this symbol. This is the index of this symbol
5876 in all the symbols for which we are making plt entries. The
5877 first entry in the procedure linkage table is reserved. */
5878 plt_index
= h
->plt
.offset
/ elf_sh_sizeof_plt (info
) - 1;
5880 /* Get the offset into the .got table of the entry that
5881 corresponds to this function. Each .got entry is 4 bytes.
5882 The first three are reserved. */
5883 got_offset
= (plt_index
+ 3) * 4;
5887 got_offset
-= GOT_BIAS
;
5890 /* Fill in the entry in the procedure linkage table. */
5893 if (elf_sh_plt_entry
== NULL
)
5895 elf_sh_plt_entry
= (bfd_big_endian (output_bfd
) ?
5896 elf_sh_plt_entry_be
: elf_sh_plt_entry_le
);
5898 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_plt_entry
,
5899 elf_sh_sizeof_plt (info
));
5900 #ifdef INCLUDE_SHMEDIA
5901 movi_shori_putval (output_bfd
,
5902 (sgot
->output_section
->vma
5903 + sgot
->output_offset
5905 (splt
->contents
+ h
->plt
.offset
5906 + elf_sh_plt_symbol_offset (info
)));
5908 /* Set bottom bit because its for a branch to SHmedia */
5909 movi_shori_putval (output_bfd
,
5910 (splt
->output_section
->vma
+ splt
->output_offset
)
5912 (splt
->contents
+ h
->plt
.offset
5913 + elf_sh_plt_plt0_offset (info
)));
5915 bfd_put_32 (output_bfd
,
5916 (sgot
->output_section
->vma
5917 + sgot
->output_offset
5919 (splt
->contents
+ h
->plt
.offset
5920 + elf_sh_plt_symbol_offset (info
)));
5922 bfd_put_32 (output_bfd
,
5923 (splt
->output_section
->vma
+ splt
->output_offset
),
5924 (splt
->contents
+ h
->plt
.offset
5925 + elf_sh_plt_plt0_offset (info
)));
5930 if (elf_sh_pic_plt_entry
== NULL
)
5932 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
5933 elf_sh_pic_plt_entry_be
:
5934 elf_sh_pic_plt_entry_le
);
5936 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_pic_plt_entry
,
5937 elf_sh_sizeof_plt (info
));
5938 #ifdef INCLUDE_SHMEDIA
5939 movi_shori_putval (output_bfd
, got_offset
,
5940 (splt
->contents
+ h
->plt
.offset
5941 + elf_sh_plt_symbol_offset (info
)));
5943 bfd_put_32 (output_bfd
, got_offset
,
5944 (splt
->contents
+ h
->plt
.offset
5945 + elf_sh_plt_symbol_offset (info
)));
5951 got_offset
+= GOT_BIAS
;
5954 #ifdef INCLUDE_SHMEDIA
5955 movi_shori_putval (output_bfd
,
5956 plt_index
* sizeof (Elf32_External_Rela
),
5957 (splt
->contents
+ h
->plt
.offset
5958 + elf_sh_plt_reloc_offset (info
)));
5960 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
5961 (splt
->contents
+ h
->plt
.offset
5962 + elf_sh_plt_reloc_offset (info
)));
5965 /* Fill in the entry in the global offset table. */
5966 bfd_put_32 (output_bfd
,
5967 (splt
->output_section
->vma
5968 + splt
->output_offset
5970 + elf_sh_plt_temp_offset (info
)),
5971 sgot
->contents
+ got_offset
);
5973 /* Fill in the entry in the .rela.plt section. */
5974 rel
.r_offset
= (sgot
->output_section
->vma
5975 + sgot
->output_offset
5977 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_JMP_SLOT
);
5980 rel
.r_addend
= GOT_BIAS
;
5982 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
5983 ((Elf32_External_Rela
*) srel
->contents
5986 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5988 /* Mark the symbol as undefined, rather than as defined in
5989 the .plt section. Leave the value alone. */
5990 sym
->st_shndx
= SHN_UNDEF
;
5994 if (h
->got
.offset
!= (bfd_vma
) -1)
5998 Elf_Internal_Rela rel
;
6000 /* This symbol has an entry in the global offset table. Set it
6004 srel
= htab
->srelgot
;
6005 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
6007 rel
.r_offset
= (sgot
->output_section
->vma
6008 + sgot
->output_offset
6009 + (h
->got
.offset
&~ (bfd_vma
) 1));
6011 /* If this is a static link, or it is a -Bsymbolic link and the
6012 symbol is defined locally or was forced to be local because
6013 of a version file, we just want to emit a RELATIVE reloc.
6014 The entry in the global offset table will already have been
6015 initialized in the relocate_section function. */
6019 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
6020 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
6022 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
6023 rel
.r_addend
= (h
->root
.u
.def
.value
6024 + h
->root
.u
.def
.section
->output_section
->vma
6025 + h
->root
.u
.def
.section
->output_offset
);
6029 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
6030 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
6034 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
6035 ((Elf32_External_Rela
*) srel
->contents
6036 + srel
->reloc_count
));
6037 ++srel
->reloc_count
;
6040 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
6043 Elf_Internal_Rela rel
;
6045 /* This symbol needs a copy reloc. Set it up. */
6047 BFD_ASSERT (h
->dynindx
!= -1
6048 && (h
->root
.type
== bfd_link_hash_defined
6049 || h
->root
.type
== bfd_link_hash_defweak
));
6051 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
6053 BFD_ASSERT (s
!= NULL
);
6055 rel
.r_offset
= (h
->root
.u
.def
.value
6056 + h
->root
.u
.def
.section
->output_section
->vma
6057 + h
->root
.u
.def
.section
->output_offset
);
6058 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_COPY
);
6060 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
6061 ((Elf32_External_Rela
*) s
->contents
6066 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
6067 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
6068 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
6069 sym
->st_shndx
= SHN_ABS
;
6074 /* Finish up the dynamic sections. */
6077 sh_elf_finish_dynamic_sections (output_bfd
, info
)
6079 struct bfd_link_info
*info
;
6081 struct elf_sh_link_hash_table
*htab
;
6086 htab
= sh_elf_hash_table (info
);
6087 dynobj
= htab
->root
.dynobj
;
6089 sgot
= htab
->sgotplt
;
6090 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6092 if (htab
->root
.dynamic_sections_created
)
6095 Elf32_External_Dyn
*dyncon
, *dynconend
;
6097 BFD_ASSERT (sgot
!= NULL
&& sdyn
!= NULL
);
6099 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
6100 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
6101 for (; dyncon
< dynconend
; dyncon
++)
6103 Elf_Internal_Dyn dyn
;
6105 #ifdef INCLUDE_SHMEDIA
6109 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6116 #ifdef INCLUDE_SHMEDIA
6118 name
= info
->init_function
;
6122 name
= info
->fini_function
;
6124 if (dyn
.d_un
.d_val
!= 0)
6126 struct elf_link_hash_entry
*h
;
6128 h
= elf_link_hash_lookup (&htab
->root
, name
,
6129 false, false, true);
6130 if (h
!= NULL
&& (h
->other
& STO_SH5_ISA32
))
6132 dyn
.d_un
.d_val
|= 1;
6133 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6140 s
= htab
->sgot
->output_section
;
6144 s
= htab
->srelplt
->output_section
;
6146 BFD_ASSERT (s
!= NULL
);
6147 dyn
.d_un
.d_ptr
= s
->vma
;
6148 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6152 s
= htab
->srelplt
->output_section
;
6153 BFD_ASSERT (s
!= NULL
);
6154 if (s
->_cooked_size
!= 0)
6155 dyn
.d_un
.d_val
= s
->_cooked_size
;
6157 dyn
.d_un
.d_val
= s
->_raw_size
;
6158 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6162 /* My reading of the SVR4 ABI indicates that the
6163 procedure linkage table relocs (DT_JMPREL) should be
6164 included in the overall relocs (DT_RELA). This is
6165 what Solaris does. However, UnixWare can not handle
6166 that case. Therefore, we override the DT_RELASZ entry
6167 here to make it not include the JMPREL relocs. Since
6168 the linker script arranges for .rela.plt to follow all
6169 other relocation sections, we don't have to worry
6170 about changing the DT_RELA entry. */
6171 if (htab
->srelplt
!= NULL
)
6173 s
= htab
->srelplt
->output_section
;
6174 if (s
->_cooked_size
!= 0)
6175 dyn
.d_un
.d_val
-= s
->_cooked_size
;
6177 dyn
.d_un
.d_val
-= s
->_raw_size
;
6179 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6184 /* Fill in the first entry in the procedure linkage table. */
6186 if (splt
&& splt
->_raw_size
> 0)
6190 if (elf_sh_pic_plt_entry
== NULL
)
6192 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
6193 elf_sh_pic_plt_entry_be
:
6194 elf_sh_pic_plt_entry_le
);
6196 memcpy (splt
->contents
, elf_sh_pic_plt_entry
,
6197 elf_sh_sizeof_plt (info
));
6201 if (elf_sh_plt0_entry
== NULL
)
6203 elf_sh_plt0_entry
= (bfd_big_endian (output_bfd
) ?
6204 elf_sh_plt0_entry_be
:
6205 elf_sh_plt0_entry_le
);
6207 memcpy (splt
->contents
, elf_sh_plt0_entry
, PLT_ENTRY_SIZE
);
6208 #ifdef INCLUDE_SHMEDIA
6209 movi_shori_putval (output_bfd
,
6210 sgot
->output_section
->vma
6211 + sgot
->output_offset
,
6213 + elf_sh_plt0_gotplt_offset (info
));
6215 bfd_put_32 (output_bfd
,
6216 sgot
->output_section
->vma
+ sgot
->output_offset
+ 4,
6217 splt
->contents
+ elf_sh_plt0_gotid_offset (info
));
6218 bfd_put_32 (output_bfd
,
6219 sgot
->output_section
->vma
+ sgot
->output_offset
+ 8,
6220 splt
->contents
+ elf_sh_plt0_linker_offset (info
));
6224 /* UnixWare sets the entsize of .plt to 4, although that doesn't
6225 really seem like the right value. */
6226 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
6230 /* Fill in the first three entries in the global offset table. */
6231 if (sgot
&& sgot
->_raw_size
> 0)
6234 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
6236 bfd_put_32 (output_bfd
,
6237 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
6239 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
6240 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
6242 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
6248 static enum elf_reloc_type_class
6249 sh_elf_reloc_type_class (rela
)
6250 const Elf_Internal_Rela
*rela
;
6252 switch ((int) ELF32_R_TYPE (rela
->r_info
))
6255 return reloc_class_relative
;
6257 return reloc_class_plt
;
6259 return reloc_class_copy
;
6261 return reloc_class_normal
;
6266 #define TARGET_BIG_SYM bfd_elf32_sh_vec
6267 #define TARGET_BIG_NAME "elf32-sh"
6268 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
6269 #define TARGET_LITTLE_NAME "elf32-shl"
6270 #define ELF_ARCH bfd_arch_sh
6271 #define ELF_MACHINE_CODE EM_SH
6272 #define ELF_MAXPAGESIZE 128
6274 #define elf_symbol_leading_char '_'
6275 #endif /* ELF_ARCH */
6277 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
6278 #define elf_info_to_howto sh_elf_info_to_howto
6279 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
6280 #define elf_backend_relocate_section sh_elf_relocate_section
6281 #define bfd_elf32_bfd_get_relocated_section_contents \
6282 sh_elf_get_relocated_section_contents
6283 #define elf_backend_object_p sh_elf_set_mach_from_flags
6284 #define bfd_elf32_bfd_set_private_bfd_flags \
6285 sh_elf_set_private_flags
6286 #define bfd_elf32_bfd_copy_private_bfd_data \
6287 sh_elf_copy_private_data
6288 #define bfd_elf32_bfd_merge_private_bfd_data \
6289 sh_elf_merge_private_data
6291 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
6292 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
6293 #define elf_backend_check_relocs sh_elf_check_relocs
6294 #define elf_backend_copy_indirect_symbol \
6295 sh_elf_copy_indirect_symbol
6296 #define elf_backend_create_dynamic_sections \
6297 sh_elf_create_dynamic_sections
6298 #define bfd_elf32_bfd_link_hash_table_create \
6299 sh_elf_link_hash_table_create
6300 #define elf_backend_adjust_dynamic_symbol \
6301 sh_elf_adjust_dynamic_symbol
6302 #define elf_backend_size_dynamic_sections \
6303 sh_elf_size_dynamic_sections
6304 #define elf_backend_finish_dynamic_symbol \
6305 sh_elf_finish_dynamic_symbol
6306 #define elf_backend_finish_dynamic_sections \
6307 sh_elf_finish_dynamic_sections
6308 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
6310 #define elf_backend_can_gc_sections 1
6311 #define elf_backend_can_refcount 1
6312 #define elf_backend_want_got_plt 1
6313 #define elf_backend_plt_readonly 1
6314 #define elf_backend_want_plt_sym 0
6315 #define elf_backend_got_header_size 12
6316 #define elf_backend_plt_header_size PLT_ENTRY_SIZE
6318 #ifndef ELF32_SH_C_INCLUDED
6319 #include "elf32-target.h"