1 /* Renesas / SuperH SH specific support for 32-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
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. */
28 #include "libiberty.h"
29 #include "../opcodes/sh-opc.h"
31 static bfd_reloc_status_type sh_elf_reloc
32 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
33 static bfd_reloc_status_type sh_elf_ignore_reloc
34 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
35 static reloc_howto_type *sh_elf_reloc_type_lookup
36 (bfd *, bfd_reloc_code_real_type);
37 static void sh_elf_info_to_howto
38 (bfd *, arelent *, Elf_Internal_Rela *);
39 static bfd_boolean sh_elf_set_private_flags
41 static bfd_boolean sh_elf_copy_private_data
43 static bfd_boolean sh_elf_merge_private_data
45 static bfd_boolean sh_elf_set_mach_from_flags
47 static bfd_boolean sh_elf_relax_section
48 (bfd *, asection *, struct bfd_link_info *, bfd_boolean *);
49 static bfd_boolean sh_elf_relax_delete_bytes
50 (bfd *, asection *, bfd_vma, int);
51 static bfd_boolean sh_elf_align_loads
52 (bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_boolean *);
53 static bfd_boolean sh_elf_swap_insns
54 (bfd *, asection *, void *, bfd_byte *, bfd_vma);
55 static bfd_boolean sh_elf_relocate_section
56 (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
57 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **);
58 static bfd_byte *sh_elf_get_relocated_section_contents
59 (bfd *, struct bfd_link_info *, struct bfd_link_order *, bfd_byte *,
60 bfd_boolean, asymbol **);
61 static void sh_elf_copy_indirect_symbol
62 (const struct elf_backend_data *, struct elf_link_hash_entry *,
63 struct elf_link_hash_entry *);
64 static int sh_elf_optimized_tls_reloc
65 (struct bfd_link_info *, int, int);
66 static bfd_boolean sh_elf_mkobject
68 static bfd_boolean sh_elf_object_p
70 static bfd_boolean sh_elf_check_relocs
71 (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);
72 static struct bfd_hash_entry *sh_elf_link_hash_newfunc
73 (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
74 static struct bfd_link_hash_table *sh_elf_link_hash_table_create
76 static bfd_boolean sh_elf_adjust_dynamic_symbol
77 (struct bfd_link_info *, struct elf_link_hash_entry *);
78 static bfd_boolean sh_elf_size_dynamic_sections
79 (bfd *, struct bfd_link_info *);
80 static bfd_boolean sh_elf_finish_dynamic_symbol
81 (bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
83 static bfd_boolean sh_elf_finish_dynamic_sections
84 (bfd *, struct bfd_link_info *);
85 static bfd_reloc_status_type sh_elf_reloc_loop
86 (int, bfd *, asection *, bfd_byte *, bfd_vma, asection *, bfd_vma,
88 static bfd_boolean create_got_section
89 (bfd *, struct bfd_link_info *);
90 static bfd_boolean sh_elf_create_dynamic_sections
91 (bfd *, struct bfd_link_info *);
92 static bfd_vma dtpoff_base
93 (struct bfd_link_info *);
95 (struct bfd_link_info *, bfd_vma);
96 static asection * sh_elf_gc_mark_hook
97 (asection *, struct bfd_link_info *, Elf_Internal_Rela *,
98 struct elf_link_hash_entry *, Elf_Internal_Sym *);
99 static bfd_boolean sh_elf_gc_sweep_hook
100 (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);
101 static bfd_boolean allocate_dynrelocs
102 (struct elf_link_hash_entry *, void *);
103 static bfd_boolean readonly_dynrelocs
104 (struct elf_link_hash_entry *, void *);
105 static enum elf_reloc_type_class sh_elf_reloc_type_class
106 (const Elf_Internal_Rela *);
107 #ifdef INCLUDE_SHMEDIA
108 inline static void movi_shori_putval (bfd *, unsigned long, char *);
110 static bfd_boolean elf32_shlin_grok_prstatus
111 (bfd *abfd, Elf_Internal_Note *note);
112 static bfd_boolean elf32_shlin_grok_psinfo
113 (bfd *abfd, Elf_Internal_Note *note);
115 /* The name of the dynamic interpreter. This is put in the .interp
118 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
120 static reloc_howto_type sh_elf_howto_table[] =
123 HOWTO (R_SH_NONE, /* type */
125 0, /* size (0 = byte, 1 = short, 2 = long) */
127 FALSE, /* pc_relative */
129 complain_overflow_dont, /* complain_on_overflow */
130 sh_elf_ignore_reloc, /* special_function */
131 "R_SH_NONE", /* name */
132 FALSE, /* partial_inplace */
135 FALSE), /* pcrel_offset */
137 /* 32 bit absolute relocation. Setting partial_inplace to TRUE and
138 src_mask to a non-zero value is similar to the COFF toolchain. */
139 HOWTO (R_SH_DIR32, /* type */
141 2, /* size (0 = byte, 1 = short, 2 = long) */
143 FALSE, /* pc_relative */
145 complain_overflow_bitfield, /* complain_on_overflow */
146 sh_elf_reloc, /* special_function */
147 "R_SH_DIR32", /* name */
148 TRUE, /* partial_inplace */
149 0xffffffff, /* src_mask */
150 0xffffffff, /* dst_mask */
151 FALSE), /* pcrel_offset */
153 /* 32 bit PC relative relocation. */
154 HOWTO (R_SH_REL32, /* type */
156 2, /* size (0 = byte, 1 = short, 2 = long) */
158 TRUE, /* pc_relative */
160 complain_overflow_signed, /* complain_on_overflow */
161 sh_elf_ignore_reloc, /* special_function */
162 "R_SH_REL32", /* name */
163 TRUE, /* partial_inplace */
164 0xffffffff, /* src_mask */
165 0xffffffff, /* dst_mask */
166 TRUE), /* pcrel_offset */
168 /* 8 bit PC relative branch divided by 2. */
169 HOWTO (R_SH_DIR8WPN, /* type */
171 1, /* size (0 = byte, 1 = short, 2 = long) */
173 TRUE, /* pc_relative */
175 complain_overflow_signed, /* complain_on_overflow */
176 sh_elf_ignore_reloc, /* special_function */
177 "R_SH_DIR8WPN", /* name */
178 TRUE, /* partial_inplace */
181 TRUE), /* pcrel_offset */
183 /* 12 bit PC relative branch divided by 2. */
184 /* This cannot be partial_inplace because relaxation can't know the
185 eventual value of a symbol. */
186 HOWTO (R_SH_IND12W, /* type */
188 1, /* size (0 = byte, 1 = short, 2 = long) */
190 TRUE, /* pc_relative */
192 complain_overflow_signed, /* complain_on_overflow */
193 NULL, /* special_function */
194 "R_SH_IND12W", /* name */
195 FALSE, /* partial_inplace */
197 0xfff, /* dst_mask */
198 TRUE), /* pcrel_offset */
200 /* 8 bit unsigned PC relative divided by 4. */
201 HOWTO (R_SH_DIR8WPL, /* type */
203 1, /* size (0 = byte, 1 = short, 2 = long) */
205 TRUE, /* pc_relative */
207 complain_overflow_unsigned, /* complain_on_overflow */
208 sh_elf_ignore_reloc, /* special_function */
209 "R_SH_DIR8WPL", /* name */
210 TRUE, /* partial_inplace */
213 TRUE), /* pcrel_offset */
215 /* 8 bit unsigned PC relative divided by 2. */
216 HOWTO (R_SH_DIR8WPZ, /* type */
218 1, /* size (0 = byte, 1 = short, 2 = long) */
220 TRUE, /* pc_relative */
222 complain_overflow_unsigned, /* complain_on_overflow */
223 sh_elf_ignore_reloc, /* special_function */
224 "R_SH_DIR8WPZ", /* name */
225 TRUE, /* partial_inplace */
228 TRUE), /* pcrel_offset */
230 /* 8 bit GBR relative. FIXME: This only makes sense if we have some
231 special symbol for the GBR relative area, and that is not
233 HOWTO (R_SH_DIR8BP, /* type */
235 1, /* size (0 = byte, 1 = short, 2 = long) */
237 FALSE, /* pc_relative */
239 complain_overflow_unsigned, /* complain_on_overflow */
240 sh_elf_ignore_reloc, /* special_function */
241 "R_SH_DIR8BP", /* name */
242 FALSE, /* partial_inplace */
245 TRUE), /* pcrel_offset */
247 /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if
248 we have some special symbol for the GBR relative area, and that
249 is not implemented. */
250 HOWTO (R_SH_DIR8W, /* type */
252 1, /* size (0 = byte, 1 = short, 2 = long) */
254 FALSE, /* pc_relative */
256 complain_overflow_unsigned, /* complain_on_overflow */
257 sh_elf_ignore_reloc, /* special_function */
258 "R_SH_DIR8W", /* name */
259 FALSE, /* partial_inplace */
262 TRUE), /* pcrel_offset */
264 /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if
265 we have some special symbol for the GBR relative area, and that
266 is not implemented. */
267 HOWTO (R_SH_DIR8L, /* type */
269 1, /* size (0 = byte, 1 = short, 2 = long) */
271 FALSE, /* pc_relative */
273 complain_overflow_unsigned, /* complain_on_overflow */
274 sh_elf_ignore_reloc, /* special_function */
275 "R_SH_DIR8L", /* name */
276 FALSE, /* partial_inplace */
279 TRUE), /* pcrel_offset */
281 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
282 HOWTO (R_SH_LOOP_START, /* type */
284 1, /* size (0 = byte, 1 = short, 2 = long) */
286 FALSE, /* pc_relative */
288 complain_overflow_signed, /* complain_on_overflow */
289 sh_elf_ignore_reloc, /* special_function */
290 "R_SH_LOOP_START", /* name */
291 TRUE, /* partial_inplace */
294 TRUE), /* pcrel_offset */
296 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
297 HOWTO (R_SH_LOOP_END, /* type */
299 1, /* size (0 = byte, 1 = short, 2 = long) */
301 FALSE, /* pc_relative */
303 complain_overflow_signed, /* complain_on_overflow */
304 sh_elf_ignore_reloc, /* special_function */
305 "R_SH_LOOP_END", /* name */
306 TRUE, /* partial_inplace */
309 TRUE), /* pcrel_offset */
322 /* The remaining relocs are a GNU extension used for relaxing. The
323 final pass of the linker never needs to do anything with any of
324 these relocs. Any required operations are handled by the
327 /* GNU extension to record C++ vtable hierarchy */
328 HOWTO (R_SH_GNU_VTINHERIT, /* type */
330 2, /* size (0 = byte, 1 = short, 2 = long) */
332 FALSE, /* pc_relative */
334 complain_overflow_dont, /* complain_on_overflow */
335 NULL, /* special_function */
336 "R_SH_GNU_VTINHERIT", /* name */
337 FALSE, /* partial_inplace */
340 FALSE), /* pcrel_offset */
342 /* GNU extension to record C++ vtable member usage */
343 HOWTO (R_SH_GNU_VTENTRY, /* type */
345 2, /* size (0 = byte, 1 = short, 2 = long) */
347 FALSE, /* pc_relative */
349 complain_overflow_dont, /* complain_on_overflow */
350 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
351 "R_SH_GNU_VTENTRY", /* name */
352 FALSE, /* partial_inplace */
355 FALSE), /* pcrel_offset */
357 /* An 8 bit switch table entry. This is generated for an expression
358 such as ``.word L1 - L2''. The offset holds the difference
359 between the reloc address and L2. */
360 HOWTO (R_SH_SWITCH8, /* type */
362 0, /* size (0 = byte, 1 = short, 2 = long) */
364 FALSE, /* pc_relative */
366 complain_overflow_unsigned, /* complain_on_overflow */
367 sh_elf_ignore_reloc, /* special_function */
368 "R_SH_SWITCH8", /* name */
369 FALSE, /* partial_inplace */
372 TRUE), /* pcrel_offset */
374 /* A 16 bit switch table entry. This is generated for an expression
375 such as ``.word L1 - L2''. The offset holds the difference
376 between the reloc address and L2. */
377 HOWTO (R_SH_SWITCH16, /* type */
379 1, /* size (0 = byte, 1 = short, 2 = long) */
381 FALSE, /* pc_relative */
383 complain_overflow_unsigned, /* complain_on_overflow */
384 sh_elf_ignore_reloc, /* special_function */
385 "R_SH_SWITCH16", /* name */
386 FALSE, /* partial_inplace */
389 TRUE), /* pcrel_offset */
391 /* A 32 bit switch table entry. This is generated for an expression
392 such as ``.long L1 - L2''. The offset holds the difference
393 between the reloc address and L2. */
394 HOWTO (R_SH_SWITCH32, /* type */
396 2, /* size (0 = byte, 1 = short, 2 = long) */
398 FALSE, /* pc_relative */
400 complain_overflow_unsigned, /* complain_on_overflow */
401 sh_elf_ignore_reloc, /* special_function */
402 "R_SH_SWITCH32", /* name */
403 FALSE, /* partial_inplace */
406 TRUE), /* pcrel_offset */
408 /* Indicates a .uses pseudo-op. The compiler will generate .uses
409 pseudo-ops when it finds a function call which can be relaxed.
410 The offset field holds the PC relative offset to the instruction
411 which loads the register used in the function call. */
412 HOWTO (R_SH_USES, /* type */
414 1, /* size (0 = byte, 1 = short, 2 = long) */
416 FALSE, /* pc_relative */
418 complain_overflow_unsigned, /* complain_on_overflow */
419 sh_elf_ignore_reloc, /* special_function */
420 "R_SH_USES", /* name */
421 FALSE, /* partial_inplace */
424 TRUE), /* pcrel_offset */
426 /* The assembler will generate this reloc for addresses referred to
427 by the register loads associated with USES relocs. The offset
428 field holds the number of times the address is referenced in the
430 HOWTO (R_SH_COUNT, /* type */
432 1, /* size (0 = byte, 1 = short, 2 = long) */
434 FALSE, /* pc_relative */
436 complain_overflow_unsigned, /* complain_on_overflow */
437 sh_elf_ignore_reloc, /* special_function */
438 "R_SH_COUNT", /* name */
439 FALSE, /* partial_inplace */
442 TRUE), /* pcrel_offset */
444 /* Indicates an alignment statement. The offset field is the power
445 of 2 to which subsequent portions of the object file must be
447 HOWTO (R_SH_ALIGN, /* type */
449 1, /* size (0 = byte, 1 = short, 2 = long) */
451 FALSE, /* pc_relative */
453 complain_overflow_unsigned, /* complain_on_overflow */
454 sh_elf_ignore_reloc, /* special_function */
455 "R_SH_ALIGN", /* name */
456 FALSE, /* partial_inplace */
459 TRUE), /* pcrel_offset */
461 /* The assembler will generate this reloc before a block of
462 instructions. A section should be processed as assuming it
463 contains data, unless this reloc is seen. */
464 HOWTO (R_SH_CODE, /* type */
466 1, /* size (0 = byte, 1 = short, 2 = long) */
468 FALSE, /* pc_relative */
470 complain_overflow_unsigned, /* complain_on_overflow */
471 sh_elf_ignore_reloc, /* special_function */
472 "R_SH_CODE", /* name */
473 FALSE, /* partial_inplace */
476 TRUE), /* pcrel_offset */
478 /* The assembler will generate this reloc after a block of
479 instructions when it sees data that is not instructions. */
480 HOWTO (R_SH_DATA, /* type */
482 1, /* size (0 = byte, 1 = short, 2 = long) */
484 FALSE, /* pc_relative */
486 complain_overflow_unsigned, /* complain_on_overflow */
487 sh_elf_ignore_reloc, /* special_function */
488 "R_SH_DATA", /* name */
489 FALSE, /* partial_inplace */
492 TRUE), /* pcrel_offset */
494 /* The assembler generates this reloc for each label within a block
495 of instructions. This permits the linker to avoid swapping
496 instructions which are the targets of branches. */
497 HOWTO (R_SH_LABEL, /* type */
499 1, /* size (0 = byte, 1 = short, 2 = long) */
501 FALSE, /* pc_relative */
503 complain_overflow_unsigned, /* complain_on_overflow */
504 sh_elf_ignore_reloc, /* special_function */
505 "R_SH_LABEL", /* name */
506 FALSE, /* partial_inplace */
509 TRUE), /* pcrel_offset */
511 /* The next 12 are only supported via linking in SHC-generated objects. */
512 HOWTO (R_SH_DIR16, /* type */
514 1, /* size (0 = byte, 1 = short, 2 = long) */
516 FALSE, /* pc_relative */
518 complain_overflow_dont, /* complain_on_overflow */
519 bfd_elf_generic_reloc, /* special_function */
520 "R_SH_DIR16", /* name */
521 FALSE, /* partial_inplace */
523 0xffff, /* dst_mask */
524 FALSE), /* pcrel_offset */
526 HOWTO (R_SH_DIR8, /* type */
528 0, /* size (0 = byte, 1 = short, 2 = long) */
530 FALSE, /* pc_relative */
532 complain_overflow_dont, /* complain_on_overflow */
533 bfd_elf_generic_reloc, /* special_function */
534 "R_SH_DIR8", /* name */
535 FALSE, /* partial_inplace */
538 FALSE), /* pcrel_offset */
540 HOWTO (R_SH_DIR8UL, /* type */
542 0, /* size (0 = byte, 1 = short, 2 = long) */
544 FALSE, /* pc_relative */
546 complain_overflow_unsigned, /* complain_on_overflow */
547 bfd_elf_generic_reloc, /* special_function */
548 "R_SH_DIR8UL", /* name */
549 FALSE, /* partial_inplace */
552 FALSE), /* pcrel_offset */
554 HOWTO (R_SH_DIR8UW, /* type */
556 0, /* size (0 = byte, 1 = short, 2 = long) */
558 FALSE, /* pc_relative */
560 complain_overflow_unsigned, /* complain_on_overflow */
561 bfd_elf_generic_reloc, /* special_function */
562 "R_SH_DIR8UW", /* name */
563 FALSE, /* partial_inplace */
566 FALSE), /* pcrel_offset */
568 HOWTO (R_SH_DIR8U, /* type */
570 0, /* size (0 = byte, 1 = short, 2 = long) */
572 FALSE, /* pc_relative */
574 complain_overflow_unsigned, /* complain_on_overflow */
575 bfd_elf_generic_reloc, /* special_function */
576 "R_SH_DIR8U", /* name */
577 FALSE, /* partial_inplace */
580 FALSE), /* pcrel_offset */
582 HOWTO (R_SH_DIR8SW, /* type */
584 0, /* size (0 = byte, 1 = short, 2 = long) */
586 FALSE, /* pc_relative */
588 complain_overflow_signed, /* complain_on_overflow */
589 bfd_elf_generic_reloc, /* special_function */
590 "R_SH_DIR8SW", /* name */
591 FALSE, /* partial_inplace */
594 FALSE), /* pcrel_offset */
596 HOWTO (R_SH_DIR8S, /* type */
598 0, /* size (0 = byte, 1 = short, 2 = long) */
600 FALSE, /* pc_relative */
602 complain_overflow_signed, /* complain_on_overflow */
603 bfd_elf_generic_reloc, /* special_function */
604 "R_SH_DIR8S", /* name */
605 FALSE, /* partial_inplace */
608 FALSE), /* pcrel_offset */
610 HOWTO (R_SH_DIR4UL, /* type */
612 0, /* size (0 = byte, 1 = short, 2 = long) */
614 FALSE, /* pc_relative */
616 complain_overflow_unsigned, /* complain_on_overflow */
617 bfd_elf_generic_reloc, /* special_function */
618 "R_SH_DIR4UL", /* name */
619 FALSE, /* partial_inplace */
622 FALSE), /* pcrel_offset */
624 HOWTO (R_SH_DIR4UW, /* type */
626 0, /* size (0 = byte, 1 = short, 2 = long) */
628 FALSE, /* pc_relative */
630 complain_overflow_unsigned, /* complain_on_overflow */
631 bfd_elf_generic_reloc, /* special_function */
632 "R_SH_DIR4UW", /* name */
633 FALSE, /* partial_inplace */
636 FALSE), /* pcrel_offset */
638 HOWTO (R_SH_DIR4U, /* type */
640 0, /* size (0 = byte, 1 = short, 2 = long) */
642 FALSE, /* pc_relative */
644 complain_overflow_unsigned, /* complain_on_overflow */
645 bfd_elf_generic_reloc, /* special_function */
646 "R_SH_DIR4U", /* name */
647 FALSE, /* partial_inplace */
650 FALSE), /* pcrel_offset */
652 HOWTO (R_SH_PSHA, /* type */
654 1, /* size (0 = byte, 1 = short, 2 = long) */
656 FALSE, /* pc_relative */
658 complain_overflow_signed, /* complain_on_overflow */
659 bfd_elf_generic_reloc, /* special_function */
660 "R_SH_PSHA", /* name */
661 FALSE, /* partial_inplace */
664 FALSE), /* pcrel_offset */
666 HOWTO (R_SH_PSHL, /* type */
668 1, /* size (0 = byte, 1 = short, 2 = long) */
670 FALSE, /* pc_relative */
672 complain_overflow_signed, /* complain_on_overflow */
673 bfd_elf_generic_reloc, /* special_function */
674 "R_SH_PSHL", /* name */
675 FALSE, /* partial_inplace */
678 FALSE), /* pcrel_offset */
680 #ifdef INCLUDE_SHMEDIA
681 /* Used in SHLLI.L and SHLRI.L. */
682 HOWTO (R_SH_DIR5U, /* type */
684 2, /* size (0 = byte, 1 = short, 2 = long) */
686 FALSE, /* pc_relative */
688 complain_overflow_unsigned, /* complain_on_overflow */
689 bfd_elf_generic_reloc, /* special_function */
690 "R_SH_DIR5U", /* name */
691 FALSE, /* partial_inplace */
693 0xfc00, /* dst_mask */
694 FALSE), /* pcrel_offset */
696 /* Used in SHARI, SHLLI et al. */
697 HOWTO (R_SH_DIR6U, /* type */
699 2, /* size (0 = byte, 1 = short, 2 = long) */
701 FALSE, /* pc_relative */
703 complain_overflow_unsigned, /* complain_on_overflow */
704 bfd_elf_generic_reloc, /* special_function */
705 "R_SH_DIR6U", /* name */
706 FALSE, /* partial_inplace */
708 0xfc00, /* dst_mask */
709 FALSE), /* pcrel_offset */
711 /* Used in BxxI, LDHI.L et al. */
712 HOWTO (R_SH_DIR6S, /* type */
714 2, /* size (0 = byte, 1 = short, 2 = long) */
716 FALSE, /* pc_relative */
718 complain_overflow_signed, /* complain_on_overflow */
719 bfd_elf_generic_reloc, /* special_function */
720 "R_SH_DIR6S", /* name */
721 FALSE, /* partial_inplace */
723 0xfc00, /* dst_mask */
724 FALSE), /* pcrel_offset */
726 /* Used in ADDI, ANDI et al. */
727 HOWTO (R_SH_DIR10S, /* type */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
731 FALSE, /* pc_relative */
733 complain_overflow_signed, /* complain_on_overflow */
734 bfd_elf_generic_reloc, /* special_function */
735 "R_SH_DIR10S", /* name */
736 FALSE, /* partial_inplace */
738 0xffc00, /* dst_mask */
739 FALSE), /* pcrel_offset */
741 /* Used in LD.UW, ST.W et al. */
742 HOWTO (R_SH_DIR10SW, /* type */
744 2, /* size (0 = byte, 1 = short, 2 = long) */
746 FALSE, /* pc_relative */
748 complain_overflow_signed, /* complain_on_overflow */
749 bfd_elf_generic_reloc, /* special_function */
750 "R_SH_DIR10SW", /* name */
751 FALSE, /* partial_inplace */
753 0xffc00, /* dst_mask */
754 FALSE), /* pcrel_offset */
756 /* Used in LD.L, FLD.S et al. */
757 HOWTO (R_SH_DIR10SL, /* type */
759 2, /* size (0 = byte, 1 = short, 2 = long) */
761 FALSE, /* pc_relative */
763 complain_overflow_signed, /* complain_on_overflow */
764 bfd_elf_generic_reloc, /* special_function */
765 "R_SH_DIR10SL", /* name */
766 FALSE, /* partial_inplace */
768 0xffc00, /* dst_mask */
769 FALSE), /* pcrel_offset */
771 /* Used in FLD.D, FST.P et al. */
772 HOWTO (R_SH_DIR10SQ, /* type */
774 2, /* size (0 = byte, 1 = short, 2 = long) */
776 FALSE, /* pc_relative */
778 complain_overflow_signed, /* complain_on_overflow */
779 bfd_elf_generic_reloc, /* special_function */
780 "R_SH_DIR10SQ", /* name */
781 FALSE, /* partial_inplace */
783 0xffc00, /* dst_mask */
784 FALSE), /* pcrel_offset */
798 HOWTO (R_SH_DIR16S, /* type */
800 1, /* size (0 = byte, 1 = short, 2 = long) */
802 FALSE, /* pc_relative */
804 complain_overflow_signed, /* complain_on_overflow */
805 bfd_elf_generic_reloc, /* special_function */
806 "R_SH_DIR16S", /* name */
807 FALSE, /* partial_inplace */
809 0xffff, /* dst_mask */
810 FALSE), /* pcrel_offset */
903 HOWTO (R_SH_TLS_GD_32, /* type */
905 2, /* size (0 = byte, 1 = short, 2 = long) */
907 FALSE, /* pc_relative */
909 complain_overflow_bitfield, /* complain_on_overflow */
910 bfd_elf_generic_reloc, /* */
911 "R_SH_TLS_GD_32", /* name */
912 TRUE, /* partial_inplace */
913 0xffffffff, /* src_mask */
914 0xffffffff, /* dst_mask */
915 FALSE), /* pcrel_offset */
917 HOWTO (R_SH_TLS_LD_32, /* type */
919 2, /* size (0 = byte, 1 = short, 2 = long) */
921 FALSE, /* pc_relative */
923 complain_overflow_bitfield, /* complain_on_overflow */
924 bfd_elf_generic_reloc, /* */
925 "R_SH_TLS_LD_32", /* name */
926 TRUE, /* partial_inplace */
927 0xffffffff, /* src_mask */
928 0xffffffff, /* dst_mask */
929 FALSE), /* pcrel_offset */
931 HOWTO (R_SH_TLS_LDO_32, /* type */
933 2, /* size (0 = byte, 1 = short, 2 = long) */
935 FALSE, /* pc_relative */
937 complain_overflow_bitfield, /* complain_on_overflow */
938 bfd_elf_generic_reloc, /* */
939 "R_SH_TLS_LDO_32", /* name */
940 TRUE, /* partial_inplace */
941 0xffffffff, /* src_mask */
942 0xffffffff, /* dst_mask */
943 FALSE), /* pcrel_offset */
945 HOWTO (R_SH_TLS_IE_32, /* type */
947 2, /* size (0 = byte, 1 = short, 2 = long) */
949 FALSE, /* pc_relative */
951 complain_overflow_bitfield, /* complain_on_overflow */
952 bfd_elf_generic_reloc, /* */
953 "R_SH_TLS_IE_32", /* name */
954 TRUE, /* partial_inplace */
955 0xffffffff, /* src_mask */
956 0xffffffff, /* dst_mask */
957 FALSE), /* pcrel_offset */
959 HOWTO (R_SH_TLS_LE_32, /* type */
961 2, /* size (0 = byte, 1 = short, 2 = long) */
963 FALSE, /* pc_relative */
965 complain_overflow_bitfield, /* complain_on_overflow */
966 bfd_elf_generic_reloc, /* */
967 "R_SH_TLS_LE_32", /* name */
968 TRUE, /* partial_inplace */
969 0xffffffff, /* src_mask */
970 0xffffffff, /* dst_mask */
971 FALSE), /* pcrel_offset */
973 HOWTO (R_SH_TLS_DTPMOD32, /* type */
975 2, /* size (0 = byte, 1 = short, 2 = long) */
977 FALSE, /* pc_relative */
979 complain_overflow_bitfield, /* complain_on_overflow */
980 bfd_elf_generic_reloc, /* */
981 "R_SH_TLS_DTPMOD32", /* name */
982 TRUE, /* partial_inplace */
983 0xffffffff, /* src_mask */
984 0xffffffff, /* dst_mask */
985 FALSE), /* pcrel_offset */
987 HOWTO (R_SH_TLS_DTPOFF32, /* type */
989 2, /* size (0 = byte, 1 = short, 2 = long) */
991 FALSE, /* pc_relative */
993 complain_overflow_bitfield, /* complain_on_overflow */
994 bfd_elf_generic_reloc, /* */
995 "R_SH_TLS_DTPOFF32", /* name */
996 TRUE, /* partial_inplace */
997 0xffffffff, /* src_mask */
998 0xffffffff, /* dst_mask */
999 FALSE), /* pcrel_offset */
1001 HOWTO (R_SH_TLS_TPOFF32, /* type */
1003 2, /* size (0 = byte, 1 = short, 2 = long) */
1005 FALSE, /* pc_relative */
1007 complain_overflow_bitfield, /* complain_on_overflow */
1008 bfd_elf_generic_reloc, /* */
1009 "R_SH_TLS_TPOFF32", /* name */
1010 TRUE, /* partial_inplace */
1011 0xffffffff, /* src_mask */
1012 0xffffffff, /* dst_mask */
1013 FALSE), /* pcrel_offset */
1024 HOWTO (R_SH_GOT32, /* type */
1026 2, /* size (0 = byte, 1 = short, 2 = long) */
1028 FALSE, /* pc_relative */
1030 complain_overflow_bitfield, /* complain_on_overflow */
1031 bfd_elf_generic_reloc, /* */
1032 "R_SH_GOT32", /* name */
1033 TRUE, /* partial_inplace */
1034 0xffffffff, /* src_mask */
1035 0xffffffff, /* dst_mask */
1036 FALSE), /* pcrel_offset */
1038 HOWTO (R_SH_PLT32, /* type */
1040 2, /* size (0 = byte, 1 = short, 2 = long) */
1042 TRUE, /* pc_relative */
1044 complain_overflow_bitfield, /* complain_on_overflow */
1045 bfd_elf_generic_reloc, /* */
1046 "R_SH_PLT32", /* name */
1047 TRUE, /* partial_inplace */
1048 0xffffffff, /* src_mask */
1049 0xffffffff, /* dst_mask */
1050 TRUE), /* pcrel_offset */
1052 HOWTO (R_SH_COPY, /* type */
1054 2, /* size (0 = byte, 1 = short, 2 = long) */
1056 FALSE, /* pc_relative */
1058 complain_overflow_bitfield, /* complain_on_overflow */
1059 bfd_elf_generic_reloc, /* */
1060 "R_SH_COPY", /* name */
1061 TRUE, /* partial_inplace */
1062 0xffffffff, /* src_mask */
1063 0xffffffff, /* dst_mask */
1064 FALSE), /* pcrel_offset */
1066 HOWTO (R_SH_GLOB_DAT, /* type */
1068 2, /* size (0 = byte, 1 = short, 2 = long) */
1070 FALSE, /* pc_relative */
1072 complain_overflow_bitfield, /* complain_on_overflow */
1073 bfd_elf_generic_reloc, /* */
1074 "R_SH_GLOB_DAT", /* name */
1075 TRUE, /* partial_inplace */
1076 0xffffffff, /* src_mask */
1077 0xffffffff, /* dst_mask */
1078 FALSE), /* pcrel_offset */
1080 HOWTO (R_SH_JMP_SLOT, /* type */
1082 2, /* size (0 = byte, 1 = short, 2 = long) */
1084 FALSE, /* pc_relative */
1086 complain_overflow_bitfield, /* complain_on_overflow */
1087 bfd_elf_generic_reloc, /* */
1088 "R_SH_JMP_SLOT", /* name */
1089 TRUE, /* partial_inplace */
1090 0xffffffff, /* src_mask */
1091 0xffffffff, /* dst_mask */
1092 FALSE), /* pcrel_offset */
1094 HOWTO (R_SH_RELATIVE, /* type */
1096 2, /* size (0 = byte, 1 = short, 2 = long) */
1098 FALSE, /* pc_relative */
1100 complain_overflow_bitfield, /* complain_on_overflow */
1101 bfd_elf_generic_reloc, /* */
1102 "R_SH_RELATIVE", /* name */
1103 TRUE, /* partial_inplace */
1104 0xffffffff, /* src_mask */
1105 0xffffffff, /* dst_mask */
1106 FALSE), /* pcrel_offset */
1108 HOWTO (R_SH_GOTOFF, /* type */
1110 2, /* size (0 = byte, 1 = short, 2 = long) */
1112 FALSE, /* pc_relative */
1114 complain_overflow_bitfield, /* complain_on_overflow */
1115 bfd_elf_generic_reloc, /* */
1116 "R_SH_GOTOFF", /* name */
1117 TRUE, /* partial_inplace */
1118 0xffffffff, /* src_mask */
1119 0xffffffff, /* dst_mask */
1120 FALSE), /* pcrel_offset */
1122 HOWTO (R_SH_GOTPC, /* type */
1124 2, /* size (0 = byte, 1 = short, 2 = long) */
1126 TRUE, /* pc_relative */
1128 complain_overflow_bitfield, /* complain_on_overflow */
1129 bfd_elf_generic_reloc, /* */
1130 "R_SH_GOTPC", /* name */
1131 TRUE, /* partial_inplace */
1132 0xffffffff, /* src_mask */
1133 0xffffffff, /* dst_mask */
1134 TRUE), /* pcrel_offset */
1136 HOWTO (R_SH_GOTPLT32, /* type */
1138 2, /* size (0 = byte, 1 = short, 2 = long) */
1140 FALSE, /* pc_relative */
1142 complain_overflow_bitfield, /* complain_on_overflow */
1143 bfd_elf_generic_reloc, /* */
1144 "R_SH_GOTPLT32", /* name */
1145 FALSE, /* partial_inplace */
1146 0xffffffff, /* src_mask */
1147 0xffffffff, /* dst_mask */
1148 FALSE), /* pcrel_offset */
1150 #ifdef INCLUDE_SHMEDIA
1151 /* Used in MOVI and SHORI (x & 65536). */
1152 HOWTO (R_SH_GOT_LOW16, /* type */
1154 2, /* size (0 = byte, 1 = short, 2 = long) */
1156 FALSE, /* pc_relative */
1158 complain_overflow_dont, /* complain_on_overflow */
1159 bfd_elf_generic_reloc, /* special_function */
1160 "R_SH_GOT_LOW16", /* name */
1161 FALSE, /* partial_inplace */
1163 0x3fffc00, /* dst_mask */
1164 FALSE), /* pcrel_offset */
1166 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1167 HOWTO (R_SH_GOT_MEDLOW16, /* type */
1168 16, /* rightshift */
1169 2, /* size (0 = byte, 1 = short, 2 = long) */
1171 FALSE, /* pc_relative */
1173 complain_overflow_dont, /* complain_on_overflow */
1174 bfd_elf_generic_reloc, /* special_function */
1175 "R_SH_GOT_MEDLOW16", /* name */
1176 FALSE, /* partial_inplace */
1178 0x3fffc00, /* dst_mask */
1179 FALSE), /* pcrel_offset */
1181 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1182 HOWTO (R_SH_GOT_MEDHI16, /* type */
1183 32, /* rightshift */
1184 2, /* size (0 = byte, 1 = short, 2 = long) */
1186 FALSE, /* pc_relative */
1188 complain_overflow_dont, /* complain_on_overflow */
1189 bfd_elf_generic_reloc, /* special_function */
1190 "R_SH_GOT_MEDHI16", /* name */
1191 FALSE, /* partial_inplace */
1193 0x3fffc00, /* dst_mask */
1194 FALSE), /* pcrel_offset */
1196 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1197 HOWTO (R_SH_GOT_HI16, /* type */
1198 48, /* rightshift */
1199 2, /* size (0 = byte, 1 = short, 2 = long) */
1201 FALSE, /* pc_relative */
1203 complain_overflow_dont, /* complain_on_overflow */
1204 bfd_elf_generic_reloc, /* special_function */
1205 "R_SH_GOT_HI16", /* name */
1206 FALSE, /* partial_inplace */
1208 0x3fffc00, /* dst_mask */
1209 FALSE), /* pcrel_offset */
1211 /* Used in MOVI and SHORI (x & 65536). */
1212 HOWTO (R_SH_GOTPLT_LOW16, /* type */
1214 2, /* size (0 = byte, 1 = short, 2 = long) */
1216 FALSE, /* pc_relative */
1218 complain_overflow_dont, /* complain_on_overflow */
1219 bfd_elf_generic_reloc, /* special_function */
1220 "R_SH_GOTPLT_LOW16", /* name */
1221 FALSE, /* partial_inplace */
1223 0x3fffc00, /* dst_mask */
1224 FALSE), /* pcrel_offset */
1226 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1227 HOWTO (R_SH_GOTPLT_MEDLOW16, /* type */
1228 16, /* rightshift */
1229 2, /* size (0 = byte, 1 = short, 2 = long) */
1231 FALSE, /* pc_relative */
1233 complain_overflow_dont, /* complain_on_overflow */
1234 bfd_elf_generic_reloc, /* special_function */
1235 "R_SH_GOTPLT_MEDLOW16", /* name */
1236 FALSE, /* partial_inplace */
1238 0x3fffc00, /* dst_mask */
1239 FALSE), /* pcrel_offset */
1241 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1242 HOWTO (R_SH_GOTPLT_MEDHI16, /* type */
1243 32, /* rightshift */
1244 2, /* size (0 = byte, 1 = short, 2 = long) */
1246 FALSE, /* pc_relative */
1248 complain_overflow_dont, /* complain_on_overflow */
1249 bfd_elf_generic_reloc, /* special_function */
1250 "R_SH_GOTPLT_MEDHI16", /* name */
1251 FALSE, /* partial_inplace */
1253 0x3fffc00, /* dst_mask */
1254 FALSE), /* pcrel_offset */
1256 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1257 HOWTO (R_SH_GOTPLT_HI16, /* type */
1258 48, /* rightshift */
1259 2, /* size (0 = byte, 1 = short, 2 = long) */
1261 FALSE, /* pc_relative */
1263 complain_overflow_dont, /* complain_on_overflow */
1264 bfd_elf_generic_reloc, /* special_function */
1265 "R_SH_GOTPLT_HI16", /* name */
1266 FALSE, /* partial_inplace */
1268 0x3fffc00, /* dst_mask */
1269 FALSE), /* pcrel_offset */
1271 /* Used in MOVI and SHORI (x & 65536). */
1272 HOWTO (R_SH_PLT_LOW16, /* type */
1274 2, /* size (0 = byte, 1 = short, 2 = long) */
1276 TRUE, /* pc_relative */
1278 complain_overflow_dont, /* complain_on_overflow */
1279 bfd_elf_generic_reloc, /* special_function */
1280 "R_SH_PLT_LOW16", /* name */
1281 FALSE, /* partial_inplace */
1283 0x3fffc00, /* dst_mask */
1284 TRUE), /* pcrel_offset */
1286 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1287 HOWTO (R_SH_PLT_MEDLOW16, /* type */
1288 16, /* rightshift */
1289 2, /* size (0 = byte, 1 = short, 2 = long) */
1291 TRUE, /* pc_relative */
1293 complain_overflow_dont, /* complain_on_overflow */
1294 bfd_elf_generic_reloc, /* special_function */
1295 "R_SH_PLT_MEDLOW16", /* name */
1296 FALSE, /* partial_inplace */
1298 0x3fffc00, /* dst_mask */
1299 TRUE), /* pcrel_offset */
1301 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1302 HOWTO (R_SH_PLT_MEDHI16, /* type */
1303 32, /* rightshift */
1304 2, /* size (0 = byte, 1 = short, 2 = long) */
1306 TRUE, /* pc_relative */
1308 complain_overflow_dont, /* complain_on_overflow */
1309 bfd_elf_generic_reloc, /* special_function */
1310 "R_SH_PLT_MEDHI16", /* name */
1311 FALSE, /* partial_inplace */
1313 0x3fffc00, /* dst_mask */
1314 TRUE), /* pcrel_offset */
1316 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1317 HOWTO (R_SH_PLT_HI16, /* type */
1318 48, /* rightshift */
1319 2, /* size (0 = byte, 1 = short, 2 = long) */
1321 TRUE, /* pc_relative */
1323 complain_overflow_dont, /* complain_on_overflow */
1324 bfd_elf_generic_reloc, /* special_function */
1325 "R_SH_PLT_HI16", /* name */
1326 FALSE, /* partial_inplace */
1328 0x3fffc00, /* dst_mask */
1329 TRUE), /* pcrel_offset */
1331 /* Used in MOVI and SHORI (x & 65536). */
1332 HOWTO (R_SH_GOTOFF_LOW16, /* type */
1334 2, /* size (0 = byte, 1 = short, 2 = long) */
1336 FALSE, /* pc_relative */
1338 complain_overflow_dont, /* complain_on_overflow */
1339 bfd_elf_generic_reloc, /* special_function */
1340 "R_SH_GOTOFF_LOW16", /* name */
1341 FALSE, /* partial_inplace */
1343 0x3fffc00, /* dst_mask */
1344 FALSE), /* pcrel_offset */
1346 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1347 HOWTO (R_SH_GOTOFF_MEDLOW16, /* type */
1348 16, /* rightshift */
1349 2, /* size (0 = byte, 1 = short, 2 = long) */
1351 FALSE, /* pc_relative */
1353 complain_overflow_dont, /* complain_on_overflow */
1354 bfd_elf_generic_reloc, /* special_function */
1355 "R_SH_GOTOFF_MEDLOW16", /* name */
1356 FALSE, /* partial_inplace */
1358 0x3fffc00, /* dst_mask */
1359 FALSE), /* pcrel_offset */
1361 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1362 HOWTO (R_SH_GOTOFF_MEDHI16, /* type */
1363 32, /* rightshift */
1364 2, /* size (0 = byte, 1 = short, 2 = long) */
1366 FALSE, /* pc_relative */
1368 complain_overflow_dont, /* complain_on_overflow */
1369 bfd_elf_generic_reloc, /* special_function */
1370 "R_SH_GOTOFF_MEDHI16", /* name */
1371 FALSE, /* partial_inplace */
1373 0x3fffc00, /* dst_mask */
1374 FALSE), /* pcrel_offset */
1376 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1377 HOWTO (R_SH_GOTOFF_HI16, /* type */
1378 48, /* rightshift */
1379 2, /* size (0 = byte, 1 = short, 2 = long) */
1381 FALSE, /* pc_relative */
1383 complain_overflow_dont, /* complain_on_overflow */
1384 bfd_elf_generic_reloc, /* special_function */
1385 "R_SH_GOTOFF_HI16", /* name */
1386 FALSE, /* partial_inplace */
1388 0x3fffc00, /* dst_mask */
1389 FALSE), /* pcrel_offset */
1391 /* Used in MOVI and SHORI (x & 65536). */
1392 HOWTO (R_SH_GOTPC_LOW16, /* type */
1394 2, /* size (0 = byte, 1 = short, 2 = long) */
1396 TRUE, /* pc_relative */
1398 complain_overflow_dont, /* complain_on_overflow */
1399 bfd_elf_generic_reloc, /* special_function */
1400 "R_SH_GOTPC_LOW16", /* name */
1401 FALSE, /* partial_inplace */
1403 0x3fffc00, /* dst_mask */
1404 TRUE), /* pcrel_offset */
1406 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1407 HOWTO (R_SH_GOTPC_MEDLOW16, /* type */
1408 16, /* rightshift */
1409 2, /* size (0 = byte, 1 = short, 2 = long) */
1411 TRUE, /* pc_relative */
1413 complain_overflow_dont, /* complain_on_overflow */
1414 bfd_elf_generic_reloc, /* special_function */
1415 "R_SH_GOTPC_MEDLOW16", /* name */
1416 FALSE, /* partial_inplace */
1418 0x3fffc00, /* dst_mask */
1419 TRUE), /* pcrel_offset */
1421 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1422 HOWTO (R_SH_GOTPC_MEDHI16, /* type */
1423 32, /* rightshift */
1424 2, /* size (0 = byte, 1 = short, 2 = long) */
1426 TRUE, /* pc_relative */
1428 complain_overflow_dont, /* complain_on_overflow */
1429 bfd_elf_generic_reloc, /* special_function */
1430 "R_SH_GOTPC_MEDHI16", /* name */
1431 FALSE, /* partial_inplace */
1433 0x3fffc00, /* dst_mask */
1434 TRUE), /* pcrel_offset */
1436 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1437 HOWTO (R_SH_GOTPC_HI16, /* type */
1438 48, /* rightshift */
1439 2, /* size (0 = byte, 1 = short, 2 = long) */
1441 TRUE, /* pc_relative */
1443 complain_overflow_dont, /* complain_on_overflow */
1444 bfd_elf_generic_reloc, /* special_function */
1445 "R_SH_GOTPC_HI16", /* name */
1446 FALSE, /* partial_inplace */
1448 0x3fffc00, /* dst_mask */
1449 TRUE), /* pcrel_offset */
1451 /* Used in LD.L, FLD.S et al. */
1452 HOWTO (R_SH_GOT10BY4, /* type */
1454 2, /* size (0 = byte, 1 = short, 2 = long) */
1456 FALSE, /* pc_relative */
1458 complain_overflow_signed, /* complain_on_overflow */
1459 bfd_elf_generic_reloc, /* special_function */
1460 "R_SH_GOT10BY4", /* name */
1461 FALSE, /* partial_inplace */
1463 0xffc00, /* dst_mask */
1464 FALSE), /* pcrel_offset */
1466 /* Used in LD.L, FLD.S et al. */
1467 HOWTO (R_SH_GOTPLT10BY4, /* type */
1469 2, /* size (0 = byte, 1 = short, 2 = long) */
1471 FALSE, /* pc_relative */
1473 complain_overflow_signed, /* complain_on_overflow */
1474 bfd_elf_generic_reloc, /* special_function */
1475 "R_SH_GOTPLT10BY4", /* name */
1476 FALSE, /* partial_inplace */
1478 0xffc00, /* dst_mask */
1479 FALSE), /* pcrel_offset */
1481 /* Used in FLD.D, FST.P et al. */
1482 HOWTO (R_SH_GOT10BY8, /* type */
1484 2, /* size (0 = byte, 1 = short, 2 = long) */
1486 FALSE, /* pc_relative */
1488 complain_overflow_signed, /* complain_on_overflow */
1489 bfd_elf_generic_reloc, /* special_function */
1490 "R_SH_GOT10BY8", /* name */
1491 FALSE, /* partial_inplace */
1493 0xffc00, /* dst_mask */
1494 FALSE), /* pcrel_offset */
1496 /* Used in FLD.D, FST.P et al. */
1497 HOWTO (R_SH_GOTPLT10BY8, /* type */
1499 2, /* size (0 = byte, 1 = short, 2 = long) */
1501 FALSE, /* pc_relative */
1503 complain_overflow_signed, /* complain_on_overflow */
1504 bfd_elf_generic_reloc, /* special_function */
1505 "R_SH_GOTPLT10BY8", /* name */
1506 FALSE, /* partial_inplace */
1508 0xffc00, /* dst_mask */
1509 FALSE), /* pcrel_offset */
1511 HOWTO (R_SH_COPY64, /* type */
1513 4, /* size (0 = byte, 1 = short, 2 = long) */
1515 FALSE, /* pc_relative */
1517 complain_overflow_dont, /* complain_on_overflow */
1518 bfd_elf_generic_reloc, /* special_function */
1519 "R_SH_COPY64", /* name */
1520 FALSE, /* partial_inplace */
1522 ((bfd_vma) 0) - 1, /* dst_mask */
1523 FALSE), /* pcrel_offset */
1525 HOWTO (R_SH_GLOB_DAT64, /* type */
1527 4, /* size (0 = byte, 1 = short, 2 = long) */
1529 FALSE, /* pc_relative */
1531 complain_overflow_dont, /* complain_on_overflow */
1532 bfd_elf_generic_reloc, /* special_function */
1533 "R_SH_GLOB_DAT64", /* name */
1534 FALSE, /* partial_inplace */
1536 ((bfd_vma) 0) - 1, /* dst_mask */
1537 FALSE), /* pcrel_offset */
1539 HOWTO (R_SH_JMP_SLOT64, /* type */
1541 4, /* size (0 = byte, 1 = short, 2 = long) */
1543 FALSE, /* pc_relative */
1545 complain_overflow_dont, /* complain_on_overflow */
1546 bfd_elf_generic_reloc, /* special_function */
1547 "R_SH_JMP_SLOT64", /* name */
1548 FALSE, /* partial_inplace */
1550 ((bfd_vma) 0) - 1, /* dst_mask */
1551 FALSE), /* pcrel_offset */
1553 HOWTO (R_SH_RELATIVE64, /* type */
1555 4, /* size (0 = byte, 1 = short, 2 = long) */
1557 FALSE, /* pc_relative */
1559 complain_overflow_dont, /* complain_on_overflow */
1560 bfd_elf_generic_reloc, /* special_function */
1561 "R_SH_RELATIVE64", /* name */
1562 FALSE, /* partial_inplace */
1564 ((bfd_vma) 0) - 1, /* dst_mask */
1565 FALSE), /* pcrel_offset */
1613 /* Relocations for SHmedia code. None of these are partial_inplace or
1614 use the field being relocated (except R_SH_PT_16). */
1616 /* The assembler will generate this reloc before a block of SHmedia
1617 instructions. A section should be processed as assuming it contains
1618 data, unless this reloc is seen. Note that a block of SHcompact
1619 instructions are instead preceded by R_SH_CODE.
1620 This is currently not implemented, but should be used for SHmedia
1621 linker relaxation. */
1622 HOWTO (R_SH_SHMEDIA_CODE, /* type */
1624 1, /* size (0 = byte, 1 = short, 2 = long) */
1626 FALSE, /* pc_relative */
1628 complain_overflow_unsigned, /* complain_on_overflow */
1629 sh_elf_ignore_reloc, /* special_function */
1630 "R_SH_SHMEDIA_CODE", /* name */
1631 FALSE, /* partial_inplace */
1634 FALSE), /* pcrel_offset */
1636 /* The assembler will generate this reloc at a PTA or PTB instruction,
1637 and the linker checks the right type of target, or changes a PTA to a
1638 PTB, if the original insn was PT. */
1639 HOWTO (R_SH_PT_16, /* type */
1641 2, /* size (0 = byte, 1 = short, 2 = long) */
1643 TRUE, /* pc_relative */
1645 complain_overflow_signed, /* complain_on_overflow */
1646 bfd_elf_generic_reloc, /* special_function */
1647 "R_SH_PT_16", /* name */
1648 FALSE, /* partial_inplace */
1650 0x3fffc00, /* dst_mask */
1651 TRUE), /* pcrel_offset */
1653 /* Used in unexpanded MOVI. */
1654 HOWTO (R_SH_IMMS16, /* type */
1656 2, /* size (0 = byte, 1 = short, 2 = long) */
1658 FALSE, /* pc_relative */
1660 complain_overflow_signed, /* complain_on_overflow */
1661 bfd_elf_generic_reloc, /* special_function */
1662 "R_SH_IMMS16", /* name */
1663 FALSE, /* partial_inplace */
1665 0x3fffc00, /* dst_mask */
1666 FALSE), /* pcrel_offset */
1668 /* Used in SHORI. */
1669 HOWTO (R_SH_IMMU16, /* type */
1671 2, /* size (0 = byte, 1 = short, 2 = long) */
1673 FALSE, /* pc_relative */
1675 complain_overflow_unsigned, /* complain_on_overflow */
1676 bfd_elf_generic_reloc, /* special_function */
1677 "R_SH_IMMU16", /* name */
1678 FALSE, /* partial_inplace */
1680 0x3fffc00, /* dst_mask */
1681 FALSE), /* pcrel_offset */
1683 /* Used in MOVI and SHORI (x & 65536). */
1684 HOWTO (R_SH_IMM_LOW16, /* type */
1686 2, /* size (0 = byte, 1 = short, 2 = long) */
1688 FALSE, /* pc_relative */
1690 complain_overflow_dont, /* complain_on_overflow */
1691 bfd_elf_generic_reloc, /* special_function */
1692 "R_SH_IMM_LOW16", /* name */
1693 FALSE, /* partial_inplace */
1695 0x3fffc00, /* dst_mask */
1696 FALSE), /* pcrel_offset */
1698 /* Used in MOVI and SHORI ((x - $) & 65536). */
1699 HOWTO (R_SH_IMM_LOW16_PCREL, /* type */
1701 2, /* size (0 = byte, 1 = short, 2 = long) */
1703 TRUE, /* pc_relative */
1705 complain_overflow_dont, /* complain_on_overflow */
1706 bfd_elf_generic_reloc, /* special_function */
1707 "R_SH_IMM_LOW16_PCREL", /* name */
1708 FALSE, /* partial_inplace */
1710 0x3fffc00, /* dst_mask */
1711 TRUE), /* pcrel_offset */
1713 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1714 HOWTO (R_SH_IMM_MEDLOW16, /* type */
1715 16, /* rightshift */
1716 2, /* size (0 = byte, 1 = short, 2 = long) */
1718 FALSE, /* pc_relative */
1720 complain_overflow_dont, /* complain_on_overflow */
1721 bfd_elf_generic_reloc, /* special_function */
1722 "R_SH_IMM_MEDLOW16", /* name */
1723 FALSE, /* partial_inplace */
1725 0x3fffc00, /* dst_mask */
1726 FALSE), /* pcrel_offset */
1728 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1729 HOWTO (R_SH_IMM_MEDLOW16_PCREL, /* type */
1730 16, /* rightshift */
1731 2, /* size (0 = byte, 1 = short, 2 = long) */
1733 TRUE, /* pc_relative */
1735 complain_overflow_dont, /* complain_on_overflow */
1736 bfd_elf_generic_reloc, /* special_function */
1737 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1738 FALSE, /* partial_inplace */
1740 0x3fffc00, /* dst_mask */
1741 TRUE), /* pcrel_offset */
1743 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1744 HOWTO (R_SH_IMM_MEDHI16, /* type */
1745 32, /* rightshift */
1746 2, /* size (0 = byte, 1 = short, 2 = long) */
1748 FALSE, /* pc_relative */
1750 complain_overflow_dont, /* complain_on_overflow */
1751 bfd_elf_generic_reloc, /* special_function */
1752 "R_SH_IMM_MEDHI16", /* name */
1753 FALSE, /* partial_inplace */
1755 0x3fffc00, /* dst_mask */
1756 FALSE), /* pcrel_offset */
1758 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1759 HOWTO (R_SH_IMM_MEDHI16_PCREL, /* type */
1760 32, /* rightshift */
1761 2, /* size (0 = byte, 1 = short, 2 = long) */
1763 TRUE, /* pc_relative */
1765 complain_overflow_dont, /* complain_on_overflow */
1766 bfd_elf_generic_reloc, /* special_function */
1767 "R_SH_IMM_MEDHI16_PCREL", /* name */
1768 FALSE, /* partial_inplace */
1770 0x3fffc00, /* dst_mask */
1771 TRUE), /* pcrel_offset */
1773 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1774 HOWTO (R_SH_IMM_HI16, /* type */
1775 48, /* rightshift */
1776 2, /* size (0 = byte, 1 = short, 2 = long) */
1778 FALSE, /* pc_relative */
1780 complain_overflow_dont, /* complain_on_overflow */
1781 bfd_elf_generic_reloc, /* special_function */
1782 "R_SH_IMM_HI16", /* name */
1783 FALSE, /* partial_inplace */
1785 0x3fffc00, /* dst_mask */
1786 FALSE), /* pcrel_offset */
1788 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1789 HOWTO (R_SH_IMM_HI16_PCREL, /* type */
1790 48, /* rightshift */
1791 2, /* size (0 = byte, 1 = short, 2 = long) */
1793 TRUE, /* pc_relative */
1795 complain_overflow_dont, /* complain_on_overflow */
1796 bfd_elf_generic_reloc, /* special_function */
1797 "R_SH_IMM_HI16_PCREL", /* name */
1798 FALSE, /* partial_inplace */
1800 0x3fffc00, /* dst_mask */
1801 TRUE), /* pcrel_offset */
1803 /* For the .uaquad pseudo. */
1804 HOWTO (R_SH_64, /* type */
1806 4, /* size (0 = byte, 1 = short, 2 = long) */
1808 FALSE, /* pc_relative */
1810 complain_overflow_dont, /* complain_on_overflow */
1811 bfd_elf_generic_reloc, /* special_function */
1812 "R_SH_64", /* name */
1813 FALSE, /* partial_inplace */
1815 ((bfd_vma) 0) - 1, /* dst_mask */
1816 FALSE), /* pcrel_offset */
1818 /* For the .uaquad pseudo, (x - $). */
1819 HOWTO (R_SH_64_PCREL, /* type */
1820 48, /* rightshift */
1821 2, /* size (0 = byte, 1 = short, 2 = long) */
1823 TRUE, /* pc_relative */
1825 complain_overflow_dont, /* complain_on_overflow */
1826 bfd_elf_generic_reloc, /* special_function */
1827 "R_SH_64_PCREL", /* name */
1828 FALSE, /* partial_inplace */
1830 ((bfd_vma) 0) - 1, /* dst_mask */
1831 TRUE), /* pcrel_offset */
1836 static bfd_reloc_status_type
1837 sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED, bfd *input_bfd,
1838 asection *input_section, bfd_byte *contents,
1839 bfd_vma addr, asection *symbol_section,
1840 bfd_vma start, bfd_vma end)
1842 static bfd_vma last_addr;
1843 static asection *last_symbol_section;
1844 bfd_byte *start_ptr, *ptr, *last_ptr;
1849 /* Sanity check the address. */
1850 if (addr > bfd_get_section_limit (input_bfd, input_section))
1851 return bfd_reloc_outofrange;
1853 /* We require the start and end relocations to be processed consecutively -
1854 although we allow then to be processed forwards or backwards. */
1858 last_symbol_section = symbol_section;
1859 return bfd_reloc_ok;
1861 if (last_addr != addr)
1865 if (! symbol_section || last_symbol_section != symbol_section || end < start)
1866 return bfd_reloc_outofrange;
1868 /* Get the symbol_section contents. */
1869 if (symbol_section != input_section)
1871 if (elf_section_data (symbol_section)->this_hdr.contents != NULL)
1872 contents = elf_section_data (symbol_section)->this_hdr.contents;
1875 if (!bfd_malloc_and_get_section (input_bfd, symbol_section,
1878 if (contents != NULL)
1880 return bfd_reloc_outofrange;
1884 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
1885 start_ptr = contents + start;
1886 for (cum_diff = -6, ptr = contents + end; cum_diff < 0 && ptr > start_ptr;)
1888 for (last_ptr = ptr, ptr -= 4; ptr >= start_ptr && IS_PPI (ptr);)
1891 diff = (last_ptr - ptr) >> 1;
1892 cum_diff += diff & 1;
1895 /* Calculate the start / end values to load into rs / re minus four -
1896 so that will cancel out the four we would otherwise have to add to
1897 addr to get the value to subtract in order to get relative addressing. */
1901 end = (ptr + cum_diff * 2) - contents;
1905 bfd_vma start0 = start - 4;
1907 while (start0 && IS_PPI (contents + start0))
1909 start0 = start - 2 - ((start - start0) & 2);
1910 start = start0 - cum_diff - 2;
1914 if (contents != NULL
1915 && elf_section_data (symbol_section)->this_hdr.contents != contents)
1918 insn = bfd_get_16 (input_bfd, contents + addr);
1920 x = (insn & 0x200 ? end : start) - addr;
1921 if (input_section != symbol_section)
1922 x += ((symbol_section->output_section->vma + symbol_section->output_offset)
1923 - (input_section->output_section->vma
1924 + input_section->output_offset));
1926 if (x < -128 || x > 127)
1927 return bfd_reloc_overflow;
1929 x = (insn & ~0xff) | (x & 0xff);
1930 bfd_put_16 (input_bfd, (bfd_vma) x, contents + addr);
1932 return bfd_reloc_ok;
1935 /* This function is used for normal relocs. This used to be like the COFF
1936 function, and is almost certainly incorrect for other ELF targets. */
1938 static bfd_reloc_status_type
1939 sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
1940 void *data, asection *input_section, bfd *output_bfd,
1941 char **error_message ATTRIBUTE_UNUSED)
1945 enum elf_sh_reloc_type r_type;
1946 bfd_vma addr = reloc_entry->address;
1947 bfd_byte *hit_data = addr + (bfd_byte *) data;
1949 r_type = (enum elf_sh_reloc_type) reloc_entry->howto->type;
1951 if (output_bfd != NULL)
1953 /* Partial linking--do nothing. */
1954 reloc_entry->address += input_section->output_offset;
1955 return bfd_reloc_ok;
1958 /* Almost all relocs have to do with relaxing. If any work must be
1959 done for them, it has been done in sh_relax_section. */
1960 if (r_type == R_SH_IND12W && (symbol_in->flags & BSF_LOCAL) != 0)
1961 return bfd_reloc_ok;
1963 if (symbol_in != NULL
1964 && bfd_is_und_section (symbol_in->section))
1965 return bfd_reloc_undefined;
1967 if (bfd_is_com_section (symbol_in->section))
1970 sym_value = (symbol_in->value +
1971 symbol_in->section->output_section->vma +
1972 symbol_in->section->output_offset);
1977 insn = bfd_get_32 (abfd, hit_data);
1978 insn += sym_value + reloc_entry->addend;
1979 bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
1982 insn = bfd_get_16 (abfd, hit_data);
1983 sym_value += reloc_entry->addend;
1984 sym_value -= (input_section->output_section->vma
1985 + input_section->output_offset
1988 sym_value += (insn & 0xfff) << 1;
1990 sym_value -= 0x1000;
1991 insn = (insn & 0xf000) | (sym_value & 0xfff);
1992 bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
1993 if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
1994 return bfd_reloc_overflow;
2001 return bfd_reloc_ok;
2004 /* This function is used for relocs which are only used for relaxing,
2005 which the linker should otherwise ignore. */
2007 static bfd_reloc_status_type
2008 sh_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
2009 asymbol *symbol ATTRIBUTE_UNUSED,
2010 void *data ATTRIBUTE_UNUSED, asection *input_section,
2012 char **error_message ATTRIBUTE_UNUSED)
2014 if (output_bfd != NULL)
2015 reloc_entry->address += input_section->output_offset;
2016 return bfd_reloc_ok;
2019 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
2021 struct elf_reloc_map
2023 bfd_reloc_code_real_type bfd_reloc_val;
2024 unsigned char elf_reloc_val;
2027 /* An array mapping BFD reloc codes to SH ELF relocs. */
2029 static const struct elf_reloc_map sh_reloc_map[] =
2031 { BFD_RELOC_NONE, R_SH_NONE },
2032 { BFD_RELOC_32, R_SH_DIR32 },
2033 { BFD_RELOC_16, R_SH_DIR16 },
2034 { BFD_RELOC_8, R_SH_DIR8 },
2035 { BFD_RELOC_CTOR, R_SH_DIR32 },
2036 { BFD_RELOC_32_PCREL, R_SH_REL32 },
2037 { BFD_RELOC_SH_PCDISP8BY2, R_SH_DIR8WPN },
2038 { BFD_RELOC_SH_PCDISP12BY2, R_SH_IND12W },
2039 { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_DIR8WPZ },
2040 { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_DIR8WPL },
2041 { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
2042 { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
2043 { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
2044 { BFD_RELOC_SH_USES, R_SH_USES },
2045 { BFD_RELOC_SH_COUNT, R_SH_COUNT },
2046 { BFD_RELOC_SH_ALIGN, R_SH_ALIGN },
2047 { BFD_RELOC_SH_CODE, R_SH_CODE },
2048 { BFD_RELOC_SH_DATA, R_SH_DATA },
2049 { BFD_RELOC_SH_LABEL, R_SH_LABEL },
2050 { BFD_RELOC_VTABLE_INHERIT, R_SH_GNU_VTINHERIT },
2051 { BFD_RELOC_VTABLE_ENTRY, R_SH_GNU_VTENTRY },
2052 { BFD_RELOC_SH_LOOP_START, R_SH_LOOP_START },
2053 { BFD_RELOC_SH_LOOP_END, R_SH_LOOP_END },
2054 { BFD_RELOC_SH_TLS_GD_32, R_SH_TLS_GD_32 },
2055 { BFD_RELOC_SH_TLS_LD_32, R_SH_TLS_LD_32 },
2056 { BFD_RELOC_SH_TLS_LDO_32, R_SH_TLS_LDO_32 },
2057 { BFD_RELOC_SH_TLS_IE_32, R_SH_TLS_IE_32 },
2058 { BFD_RELOC_SH_TLS_LE_32, R_SH_TLS_LE_32 },
2059 { BFD_RELOC_SH_TLS_DTPMOD32, R_SH_TLS_DTPMOD32 },
2060 { BFD_RELOC_SH_TLS_DTPOFF32, R_SH_TLS_DTPOFF32 },
2061 { BFD_RELOC_SH_TLS_TPOFF32, R_SH_TLS_TPOFF32 },
2062 { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 },
2063 { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 },
2064 { BFD_RELOC_SH_COPY, R_SH_COPY },
2065 { BFD_RELOC_SH_GLOB_DAT, R_SH_GLOB_DAT },
2066 { BFD_RELOC_SH_JMP_SLOT, R_SH_JMP_SLOT },
2067 { BFD_RELOC_SH_RELATIVE, R_SH_RELATIVE },
2068 { BFD_RELOC_32_GOTOFF, R_SH_GOTOFF },
2069 { BFD_RELOC_SH_GOTPC, R_SH_GOTPC },
2070 { BFD_RELOC_SH_GOTPLT32, R_SH_GOTPLT32 },
2071 #ifdef INCLUDE_SHMEDIA
2072 { BFD_RELOC_SH_GOT_LOW16, R_SH_GOT_LOW16 },
2073 { BFD_RELOC_SH_GOT_MEDLOW16, R_SH_GOT_MEDLOW16 },
2074 { BFD_RELOC_SH_GOT_MEDHI16, R_SH_GOT_MEDHI16 },
2075 { BFD_RELOC_SH_GOT_HI16, R_SH_GOT_HI16 },
2076 { BFD_RELOC_SH_GOTPLT_LOW16, R_SH_GOTPLT_LOW16 },
2077 { BFD_RELOC_SH_GOTPLT_MEDLOW16, R_SH_GOTPLT_MEDLOW16 },
2078 { BFD_RELOC_SH_GOTPLT_MEDHI16, R_SH_GOTPLT_MEDHI16 },
2079 { BFD_RELOC_SH_GOTPLT_HI16, R_SH_GOTPLT_HI16 },
2080 { BFD_RELOC_SH_PLT_LOW16, R_SH_PLT_LOW16 },
2081 { BFD_RELOC_SH_PLT_MEDLOW16, R_SH_PLT_MEDLOW16 },
2082 { BFD_RELOC_SH_PLT_MEDHI16, R_SH_PLT_MEDHI16 },
2083 { BFD_RELOC_SH_PLT_HI16, R_SH_PLT_HI16 },
2084 { BFD_RELOC_SH_GOTOFF_LOW16, R_SH_GOTOFF_LOW16 },
2085 { BFD_RELOC_SH_GOTOFF_MEDLOW16, R_SH_GOTOFF_MEDLOW16 },
2086 { BFD_RELOC_SH_GOTOFF_MEDHI16, R_SH_GOTOFF_MEDHI16 },
2087 { BFD_RELOC_SH_GOTOFF_HI16, R_SH_GOTOFF_HI16 },
2088 { BFD_RELOC_SH_GOTPC_LOW16, R_SH_GOTPC_LOW16 },
2089 { BFD_RELOC_SH_GOTPC_MEDLOW16, R_SH_GOTPC_MEDLOW16 },
2090 { BFD_RELOC_SH_GOTPC_MEDHI16, R_SH_GOTPC_MEDHI16 },
2091 { BFD_RELOC_SH_GOTPC_HI16, R_SH_GOTPC_HI16 },
2092 { BFD_RELOC_SH_COPY64, R_SH_COPY64 },
2093 { BFD_RELOC_SH_GLOB_DAT64, R_SH_GLOB_DAT64 },
2094 { BFD_RELOC_SH_JMP_SLOT64, R_SH_JMP_SLOT64 },
2095 { BFD_RELOC_SH_RELATIVE64, R_SH_RELATIVE64 },
2096 { BFD_RELOC_SH_GOT10BY4, R_SH_GOT10BY4 },
2097 { BFD_RELOC_SH_GOT10BY8, R_SH_GOT10BY8 },
2098 { BFD_RELOC_SH_GOTPLT10BY4, R_SH_GOTPLT10BY4 },
2099 { BFD_RELOC_SH_GOTPLT10BY8, R_SH_GOTPLT10BY8 },
2100 { BFD_RELOC_SH_PT_16, R_SH_PT_16 },
2101 { BFD_RELOC_SH_SHMEDIA_CODE, R_SH_SHMEDIA_CODE },
2102 { BFD_RELOC_SH_IMMU5, R_SH_DIR5U },
2103 { BFD_RELOC_SH_IMMS6, R_SH_DIR6S },
2104 { BFD_RELOC_SH_IMMU6, R_SH_DIR6U },
2105 { BFD_RELOC_SH_IMMS10, R_SH_DIR10S },
2106 { BFD_RELOC_SH_IMMS10BY2, R_SH_DIR10SW },
2107 { BFD_RELOC_SH_IMMS10BY4, R_SH_DIR10SL },
2108 { BFD_RELOC_SH_IMMS10BY8, R_SH_DIR10SQ },
2109 { BFD_RELOC_SH_IMMS16, R_SH_IMMS16 },
2110 { BFD_RELOC_SH_IMMU16, R_SH_IMMU16 },
2111 { BFD_RELOC_SH_IMM_LOW16, R_SH_IMM_LOW16 },
2112 { BFD_RELOC_SH_IMM_LOW16_PCREL, R_SH_IMM_LOW16_PCREL },
2113 { BFD_RELOC_SH_IMM_MEDLOW16, R_SH_IMM_MEDLOW16 },
2114 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL, R_SH_IMM_MEDLOW16_PCREL },
2115 { BFD_RELOC_SH_IMM_MEDHI16, R_SH_IMM_MEDHI16 },
2116 { BFD_RELOC_SH_IMM_MEDHI16_PCREL, R_SH_IMM_MEDHI16_PCREL },
2117 { BFD_RELOC_SH_IMM_HI16, R_SH_IMM_HI16 },
2118 { BFD_RELOC_SH_IMM_HI16_PCREL, R_SH_IMM_HI16_PCREL },
2119 { BFD_RELOC_64, R_SH_64 },
2120 { BFD_RELOC_64_PCREL, R_SH_64_PCREL },
2121 #endif /* not INCLUDE_SHMEDIA */
2124 /* Given a BFD reloc code, return the howto structure for the
2125 corresponding SH ELf reloc. */
2127 static reloc_howto_type *
2128 sh_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2129 bfd_reloc_code_real_type code)
2133 for (i = 0; i < sizeof (sh_reloc_map) / sizeof (struct elf_reloc_map); i++)
2135 if (sh_reloc_map[i].bfd_reloc_val == code)
2136 return &sh_elf_howto_table[(int) sh_reloc_map[i].elf_reloc_val];
2142 /* Given an ELF reloc, fill in the howto field of a relent. */
2145 sh_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
2146 Elf_Internal_Rela *dst)
2150 r = ELF32_R_TYPE (dst->r_info);
2152 BFD_ASSERT (r < (unsigned int) R_SH_max);
2153 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC);
2154 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_2 || r > R_SH_LAST_INVALID_RELOC_2);
2155 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_LAST_INVALID_RELOC_3);
2156 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);
2157 BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_5 || r > R_SH_LAST_INVALID_RELOC_5);
2159 cache_ptr->howto = &sh_elf_howto_table[r];
2162 /* This function handles relaxing for SH ELF. See the corresponding
2163 function in coff-sh.c for a description of what this does. FIXME:
2164 There is a lot of duplication here between this code and the COFF
2165 specific code. The format of relocs and symbols is wound deeply
2166 into this code, but it would still be better if the duplication
2167 could be eliminated somehow. Note in particular that although both
2168 functions use symbols like R_SH_CODE, those symbols have different
2169 values; in coff-sh.c they come from include/coff/sh.h, whereas here
2170 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
2173 sh_elf_relax_section (bfd *abfd, asection *sec,
2174 struct bfd_link_info *link_info, bfd_boolean *again)
2176 Elf_Internal_Shdr *symtab_hdr;
2177 Elf_Internal_Rela *internal_relocs;
2178 bfd_boolean have_code;
2179 Elf_Internal_Rela *irel, *irelend;
2180 bfd_byte *contents = NULL;
2181 Elf_Internal_Sym *isymbuf = NULL;
2185 if (link_info->relocatable
2186 || (sec->flags & SEC_RELOC) == 0
2187 || sec->reloc_count == 0)
2190 #ifdef INCLUDE_SHMEDIA
2191 if (elf_section_data (sec)->this_hdr.sh_flags
2192 & (SHF_SH5_ISA32 | SHF_SH5_ISA32_MIXED))
2198 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2200 internal_relocs = (_bfd_elf_link_read_relocs
2201 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
2202 link_info->keep_memory));
2203 if (internal_relocs == NULL)
2208 irelend = internal_relocs + sec->reloc_count;
2209 for (irel = internal_relocs; irel < irelend; irel++)
2211 bfd_vma laddr, paddr, symval;
2212 unsigned short insn;
2213 Elf_Internal_Rela *irelfn, *irelscan, *irelcount;
2214 bfd_signed_vma foff;
2216 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_CODE)
2219 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_USES)
2222 /* Get the section contents. */
2223 if (contents == NULL)
2225 if (elf_section_data (sec)->this_hdr.contents != NULL)
2226 contents = elf_section_data (sec)->this_hdr.contents;
2229 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
2234 /* The r_addend field of the R_SH_USES reloc will point us to
2235 the register load. The 4 is because the r_addend field is
2236 computed as though it were a jump offset, which are based
2237 from 4 bytes after the jump instruction. */
2238 laddr = irel->r_offset + 4 + irel->r_addend;
2239 if (laddr >= sec->size)
2241 (*_bfd_error_handler) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),
2242 bfd_archive_filename (abfd),
2243 (unsigned long) irel->r_offset);
2246 insn = bfd_get_16 (abfd, contents + laddr);
2248 /* If the instruction is not mov.l NN,rN, we don't know what to
2250 if ((insn & 0xf000) != 0xd000)
2252 ((*_bfd_error_handler)
2253 (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
2254 bfd_archive_filename (abfd), (unsigned long) irel->r_offset, insn));
2258 /* Get the address from which the register is being loaded. The
2259 displacement in the mov.l instruction is quadrupled. It is a
2260 displacement from four bytes after the movl instruction, but,
2261 before adding in the PC address, two least significant bits
2262 of the PC are cleared. We assume that the section is aligned
2263 on a four byte boundary. */
2264 paddr = insn & 0xff;
2266 paddr += (laddr + 4) &~ (bfd_vma) 3;
2267 if (paddr >= sec->size)
2269 ((*_bfd_error_handler)
2270 (_("%s: 0x%lx: warning: bad R_SH_USES load offset"),
2271 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
2275 /* Get the reloc for the address from which the register is
2276 being loaded. This reloc will tell us which function is
2277 actually being called. */
2278 for (irelfn = internal_relocs; irelfn < irelend; irelfn++)
2279 if (irelfn->r_offset == paddr
2280 && ELF32_R_TYPE (irelfn->r_info) == (int) R_SH_DIR32)
2282 if (irelfn >= irelend)
2284 ((*_bfd_error_handler)
2285 (_("%s: 0x%lx: warning: could not find expected reloc"),
2286 bfd_archive_filename (abfd), (unsigned long) paddr));
2290 /* Read this BFD's symbols if we haven't done so already. */
2291 if (isymbuf == NULL && symtab_hdr->sh_info != 0)
2293 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2294 if (isymbuf == NULL)
2295 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
2296 symtab_hdr->sh_info, 0,
2298 if (isymbuf == NULL)
2302 /* Get the value of the symbol referred to by the reloc. */
2303 if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2305 /* A local symbol. */
2306 Elf_Internal_Sym *isym;
2308 isym = isymbuf + ELF32_R_SYM (irelfn->r_info);
2310 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd, sec))
2312 ((*_bfd_error_handler)
2313 (_("%s: 0x%lx: warning: symbol in unexpected section"),
2314 bfd_archive_filename (abfd), (unsigned long) paddr));
2318 symval = (isym->st_value
2319 + sec->output_section->vma
2320 + sec->output_offset);
2325 struct elf_link_hash_entry *h;
2327 indx = ELF32_R_SYM (irelfn->r_info) - symtab_hdr->sh_info;
2328 h = elf_sym_hashes (abfd)[indx];
2329 BFD_ASSERT (h != NULL);
2330 if (h->root.type != bfd_link_hash_defined
2331 && h->root.type != bfd_link_hash_defweak)
2333 /* This appears to be a reference to an undefined
2334 symbol. Just ignore it--it will be caught by the
2335 regular reloc processing. */
2339 symval = (h->root.u.def.value
2340 + h->root.u.def.section->output_section->vma
2341 + h->root.u.def.section->output_offset);
2344 symval += bfd_get_32 (abfd, contents + paddr);
2346 /* See if this function call can be shortened. */
2349 + sec->output_section->vma
2350 + sec->output_offset
2352 if (foff < -0x1000 || foff >= 0x1000)
2354 /* After all that work, we can't shorten this function call. */
2358 /* Shorten the function call. */
2360 /* For simplicity of coding, we are going to modify the section
2361 contents, the section relocs, and the BFD symbol table. We
2362 must tell the rest of the code not to free up this
2363 information. It would be possible to instead create a table
2364 of changes which have to be made, as is done in coff-mips.c;
2365 that would be more work, but would require less memory when
2366 the linker is run. */
2368 elf_section_data (sec)->relocs = internal_relocs;
2369 elf_section_data (sec)->this_hdr.contents = contents;
2370 symtab_hdr->contents = (unsigned char *) isymbuf;
2372 /* Replace the jsr with a bsr. */
2374 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
2375 replace the jsr with a bsr. */
2376 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);
2377 /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2378 here, but that only checks if the symbol is an external symbol,
2379 not if the symbol is in a different section. Besides, we need
2380 a consistent meaning for the relocation, so we just assume here that
2381 the value of the symbol is not available. */
2383 if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2385 /* If this needs to be changed because of future relaxing,
2386 it will be handled here like other internal IND12W
2389 (bfd_vma) 0xb000 | ((foff >> 1) & 0xfff),
2390 contents + irel->r_offset);
2395 /* We can't fully resolve this yet, because the external
2396 symbol value may be changed by future relaxing. We let
2397 the final link phase handle it. */
2398 bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);
2400 irel->r_addend = -4;
2402 /* See if there is another R_SH_USES reloc referring to the same
2404 for (irelscan = internal_relocs; irelscan < irelend; irelscan++)
2405 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_USES
2406 && laddr == irelscan->r_offset + 4 + irelscan->r_addend)
2408 if (irelscan < irelend)
2410 /* Some other function call depends upon this register load,
2411 and we have not yet converted that function call.
2412 Indeed, we may never be able to convert it. There is
2413 nothing else we can do at this point. */
2417 /* Look for a R_SH_COUNT reloc on the location where the
2418 function address is stored. Do this before deleting any
2419 bytes, to avoid confusion about the address. */
2420 for (irelcount = internal_relocs; irelcount < irelend; irelcount++)
2421 if (irelcount->r_offset == paddr
2422 && ELF32_R_TYPE (irelcount->r_info) == (int) R_SH_COUNT)
2425 /* Delete the register load. */
2426 if (! sh_elf_relax_delete_bytes (abfd, sec, laddr, 2))
2429 /* That will change things, so, just in case it permits some
2430 other function call to come within range, we should relax
2431 again. Note that this is not required, and it may be slow. */
2434 /* Now check whether we got a COUNT reloc. */
2435 if (irelcount >= irelend)
2437 ((*_bfd_error_handler)
2438 (_("%s: 0x%lx: warning: could not find expected COUNT reloc"),
2439 bfd_archive_filename (abfd), (unsigned long) paddr));
2443 /* The number of uses is stored in the r_addend field. We've
2444 just deleted one. */
2445 if (irelcount->r_addend == 0)
2447 ((*_bfd_error_handler) (_("%s: 0x%lx: warning: bad count"),
2448 bfd_archive_filename (abfd),
2449 (unsigned long) paddr));
2453 --irelcount->r_addend;
2455 /* If there are no more uses, we can delete the address. Reload
2456 the address from irelfn, in case it was changed by the
2457 previous call to sh_elf_relax_delete_bytes. */
2458 if (irelcount->r_addend == 0)
2460 if (! sh_elf_relax_delete_bytes (abfd, sec, irelfn->r_offset, 4))
2464 /* We've done all we can with that function call. */
2467 /* Look for load and store instructions that we can align on four
2469 if ((elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK) != EF_SH4
2472 bfd_boolean swapped;
2474 /* Get the section contents. */
2475 if (contents == NULL)
2477 if (elf_section_data (sec)->this_hdr.contents != NULL)
2478 contents = elf_section_data (sec)->this_hdr.contents;
2481 if (!bfd_malloc_and_get_section (abfd, sec, &contents))
2486 if (! sh_elf_align_loads (abfd, sec, internal_relocs, contents,
2492 elf_section_data (sec)->relocs = internal_relocs;
2493 elf_section_data (sec)->this_hdr.contents = contents;
2494 symtab_hdr->contents = (unsigned char *) isymbuf;
2499 && symtab_hdr->contents != (unsigned char *) isymbuf)
2501 if (! link_info->keep_memory)
2505 /* Cache the symbols for elf_link_input_bfd. */
2506 symtab_hdr->contents = (unsigned char *) isymbuf;
2510 if (contents != NULL
2511 && elf_section_data (sec)->this_hdr.contents != contents)
2513 if (! link_info->keep_memory)
2517 /* Cache the section contents for elf_link_input_bfd. */
2518 elf_section_data (sec)->this_hdr.contents = contents;
2522 if (internal_relocs != NULL
2523 && elf_section_data (sec)->relocs != internal_relocs)
2524 free (internal_relocs);
2530 && symtab_hdr->contents != (unsigned char *) isymbuf)
2532 if (contents != NULL
2533 && elf_section_data (sec)->this_hdr.contents != contents)
2535 if (internal_relocs != NULL
2536 && elf_section_data (sec)->relocs != internal_relocs)
2537 free (internal_relocs);
2542 /* Delete some bytes from a section while relaxing. FIXME: There is a
2543 lot of duplication between this function and sh_relax_delete_bytes
2547 sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr,
2550 Elf_Internal_Shdr *symtab_hdr;
2551 unsigned int sec_shndx;
2553 Elf_Internal_Rela *irel, *irelend;
2554 Elf_Internal_Rela *irelalign;
2556 Elf_Internal_Sym *isymbuf, *isym, *isymend;
2557 struct elf_link_hash_entry **sym_hashes;
2558 struct elf_link_hash_entry **end_hashes;
2559 unsigned int symcount;
2562 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2563 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
2565 sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
2567 contents = elf_section_data (sec)->this_hdr.contents;
2569 /* The deletion must stop at the next ALIGN reloc for an aligment
2570 power larger than the number of bytes we are deleting. */
2575 irel = elf_section_data (sec)->relocs;
2576 irelend = irel + sec->reloc_count;
2577 for (; irel < irelend; irel++)
2579 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
2580 && irel->r_offset > addr
2581 && count < (1 << irel->r_addend))
2584 toaddr = irel->r_offset;
2589 /* Actually delete the bytes. */
2590 memmove (contents + addr, contents + addr + count,
2591 (size_t) (toaddr - addr - count));
2592 if (irelalign == NULL)
2598 #define NOP_OPCODE (0x0009)
2600 BFD_ASSERT ((count & 1) == 0);
2601 for (i = 0; i < count; i += 2)
2602 bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
2605 /* Adjust all the relocs. */
2606 for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
2608 bfd_vma nraddr, stop;
2611 int off, adjust, oinsn;
2612 bfd_signed_vma voff = 0;
2613 bfd_boolean overflow;
2615 /* Get the new reloc address. */
2616 nraddr = irel->r_offset;
2617 if ((irel->r_offset > addr
2618 && irel->r_offset < toaddr)
2619 || (ELF32_R_TYPE (irel->r_info) == (int) R_SH_ALIGN
2620 && irel->r_offset == toaddr))
2623 /* See if this reloc was for the bytes we have deleted, in which
2624 case we no longer care about it. Don't delete relocs which
2625 represent addresses, though. */
2626 if (irel->r_offset >= addr
2627 && irel->r_offset < addr + count
2628 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_ALIGN
2629 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE
2630 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_DATA
2631 && ELF32_R_TYPE (irel->r_info) != (int) R_SH_LABEL)
2632 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
2635 /* If this is a PC relative reloc, see if the range it covers
2636 includes the bytes we have deleted. */
2637 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2646 start = irel->r_offset;
2647 insn = bfd_get_16 (abfd, contents + nraddr);
2651 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2654 start = stop = addr;
2658 /* If this reloc is against a symbol defined in this
2659 section, and the symbol will not be adjusted below, we
2660 must check the addend to see it will put the value in
2661 range to be adjusted, and hence must be changed. */
2662 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2664 isym = isymbuf + ELF32_R_SYM (irel->r_info);
2665 if (isym->st_shndx == sec_shndx
2666 && (isym->st_value <= addr
2667 || isym->st_value >= toaddr))
2671 val = bfd_get_32 (abfd, contents + nraddr);
2672 val += isym->st_value;
2673 if (val > addr && val < toaddr)
2674 bfd_put_32 (abfd, val - count, contents + nraddr);
2677 start = stop = addr;
2684 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
2691 /* This has been made by previous relaxation. Since the
2692 relocation will be against an external symbol, the
2693 final relocation will just do the right thing. */
2694 start = stop = addr;
2700 stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
2702 /* The addend will be against the section symbol, thus
2703 for adjusting the addend, the relevant start is the
2704 start of the section.
2705 N.B. If we want to abandon in-place changes here and
2706 test directly using symbol + addend, we have to take into
2707 account that the addend has already been adjusted by -4. */
2708 if (stop > addr && stop < toaddr)
2709 irel->r_addend -= count;
2715 stop = start + 4 + off * 2;
2720 stop = (start & ~(bfd_vma) 3) + 4 + off * 4;
2726 /* These relocs types represent
2728 The r_addend field holds the difference between the reloc
2729 address and L1. That is the start of the reloc, and
2730 adding in the contents gives us the top. We must adjust
2731 both the r_offset field and the section contents.
2732 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
2733 and the elf bfd r_offset is called r_vaddr. */
2735 stop = irel->r_offset;
2736 start = (bfd_vma) ((bfd_signed_vma) stop - (long) irel->r_addend);
2740 && (stop <= addr || stop >= toaddr))
2741 irel->r_addend += count;
2742 else if (stop > addr
2744 && (start <= addr || start >= toaddr))
2745 irel->r_addend -= count;
2747 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH16)
2748 voff = bfd_get_signed_16 (abfd, contents + nraddr);
2749 else if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH8)
2750 voff = bfd_get_8 (abfd, contents + nraddr);
2752 voff = bfd_get_signed_32 (abfd, contents + nraddr);
2753 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
2758 start = irel->r_offset;
2759 stop = (bfd_vma) ((bfd_signed_vma) start
2760 + (long) irel->r_addend
2767 && (stop <= addr || stop >= toaddr))
2769 else if (stop > addr
2771 && (start <= addr || start >= toaddr))
2780 switch ((enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info))
2789 if ((oinsn & 0xff00) != (insn & 0xff00))
2791 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2796 if ((oinsn & 0xf000) != (insn & 0xf000))
2798 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2802 BFD_ASSERT (adjust == count || count >= 4);
2807 if ((irel->r_offset & 3) == 0)
2810 if ((oinsn & 0xff00) != (insn & 0xff00))
2812 bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
2817 if (voff < 0 || voff >= 0xff)
2819 bfd_put_8 (abfd, voff, contents + nraddr);
2824 if (voff < - 0x8000 || voff >= 0x8000)
2826 bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);
2831 bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr);
2835 irel->r_addend += adjust;
2841 ((*_bfd_error_handler)
2842 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
2843 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
2844 bfd_set_error (bfd_error_bad_value);
2849 irel->r_offset = nraddr;
2852 /* Look through all the other sections. If there contain any IMM32
2853 relocs against internal symbols which we are not going to adjust
2854 below, we may need to adjust the addends. */
2855 for (o = abfd->sections; o != NULL; o = o->next)
2857 Elf_Internal_Rela *internal_relocs;
2858 Elf_Internal_Rela *irelscan, *irelscanend;
2859 bfd_byte *ocontents;
2862 || (o->flags & SEC_RELOC) == 0
2863 || o->reloc_count == 0)
2866 /* We always cache the relocs. Perhaps, if info->keep_memory is
2867 FALSE, we should free them, if we are permitted to, when we
2868 leave sh_coff_relax_section. */
2869 internal_relocs = (_bfd_elf_link_read_relocs
2870 (abfd, o, NULL, (Elf_Internal_Rela *) NULL, TRUE));
2871 if (internal_relocs == NULL)
2875 irelscanend = internal_relocs + o->reloc_count;
2876 for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++)
2878 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
2879 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_SWITCH32)
2881 bfd_vma start, stop;
2882 bfd_signed_vma voff;
2884 if (ocontents == NULL)
2886 if (elf_section_data (o)->this_hdr.contents != NULL)
2887 ocontents = elf_section_data (o)->this_hdr.contents;
2890 /* We always cache the section contents.
2891 Perhaps, if info->keep_memory is FALSE, we
2892 should free them, if we are permitted to,
2893 when we leave sh_coff_relax_section. */
2894 if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
2896 if (ocontents != NULL)
2901 elf_section_data (o)->this_hdr.contents = ocontents;
2905 stop = irelscan->r_offset;
2907 = (bfd_vma) ((bfd_signed_vma) stop - (long) irelscan->r_addend);
2909 /* STOP is in a different section, so it won't change. */
2910 if (start > addr && start < toaddr)
2911 irelscan->r_addend += count;
2913 voff = bfd_get_signed_32 (abfd, ocontents + irelscan->r_offset);
2914 stop = (bfd_vma) ((bfd_signed_vma) start + voff);
2918 && (stop <= addr || stop >= toaddr))
2919 bfd_put_signed_32 (abfd, (bfd_vma) voff + count,
2920 ocontents + irelscan->r_offset);
2921 else if (stop > addr
2923 && (start <= addr || start >= toaddr))
2924 bfd_put_signed_32 (abfd, (bfd_vma) voff - count,
2925 ocontents + irelscan->r_offset);
2928 if (ELF32_R_TYPE (irelscan->r_info) != (int) R_SH_DIR32)
2931 if (ELF32_R_SYM (irelscan->r_info) >= symtab_hdr->sh_info)
2935 isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
2936 if (isym->st_shndx == sec_shndx
2937 && (isym->st_value <= addr
2938 || isym->st_value >= toaddr))
2942 if (ocontents == NULL)
2944 if (elf_section_data (o)->this_hdr.contents != NULL)
2945 ocontents = elf_section_data (o)->this_hdr.contents;
2948 /* We always cache the section contents.
2949 Perhaps, if info->keep_memory is FALSE, we
2950 should free them, if we are permitted to,
2951 when we leave sh_coff_relax_section. */
2952 if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
2954 if (ocontents != NULL)
2959 elf_section_data (o)->this_hdr.contents = ocontents;
2963 val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
2964 val += isym->st_value;
2965 if (val > addr && val < toaddr)
2966 bfd_put_32 (abfd, val - count,
2967 ocontents + irelscan->r_offset);
2972 /* Adjust the local symbols defined in this section. */
2973 isymend = isymbuf + symtab_hdr->sh_info;
2974 for (isym = isymbuf; isym < isymend; isym++)
2976 if (isym->st_shndx == sec_shndx
2977 && isym->st_value > addr
2978 && isym->st_value < toaddr)
2979 isym->st_value -= count;
2982 /* Now adjust the global symbols defined in this section. */
2983 symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
2984 - symtab_hdr->sh_info);
2985 sym_hashes = elf_sym_hashes (abfd);
2986 end_hashes = sym_hashes + symcount;
2987 for (; sym_hashes < end_hashes; sym_hashes++)
2989 struct elf_link_hash_entry *sym_hash = *sym_hashes;
2990 if ((sym_hash->root.type == bfd_link_hash_defined
2991 || sym_hash->root.type == bfd_link_hash_defweak)
2992 && sym_hash->root.u.def.section == sec
2993 && sym_hash->root.u.def.value > addr
2994 && sym_hash->root.u.def.value < toaddr)
2996 sym_hash->root.u.def.value -= count;
3000 /* See if we can move the ALIGN reloc forward. We have adjusted
3001 r_offset for it already. */
3002 if (irelalign != NULL)
3004 bfd_vma alignto, alignaddr;
3006 alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_addend);
3007 alignaddr = BFD_ALIGN (irelalign->r_offset,
3008 1 << irelalign->r_addend);
3009 if (alignto != alignaddr)
3011 /* Tail recursion. */
3012 return sh_elf_relax_delete_bytes (abfd, sec, alignaddr,
3013 (int) (alignto - alignaddr));
3020 /* Look for loads and stores which we can align to four byte
3021 boundaries. This is like sh_align_loads in coff-sh.c. */
3024 sh_elf_align_loads (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
3025 Elf_Internal_Rela *internal_relocs,
3026 bfd_byte *contents ATTRIBUTE_UNUSED,
3027 bfd_boolean *pswapped)
3029 Elf_Internal_Rela *irel, *irelend;
3030 bfd_vma *labels = NULL;
3031 bfd_vma *label, *label_end;
3036 irelend = internal_relocs + sec->reloc_count;
3038 /* Get all the addresses with labels on them. */
3039 amt = sec->reloc_count;
3040 amt *= sizeof (bfd_vma);
3041 labels = (bfd_vma *) bfd_malloc (amt);
3045 for (irel = internal_relocs; irel < irelend; irel++)
3047 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_LABEL)
3049 *label_end = irel->r_offset;
3054 /* Note that the assembler currently always outputs relocs in
3055 address order. If that ever changes, this code will need to sort
3056 the label values and the relocs. */
3060 for (irel = internal_relocs; irel < irelend; irel++)
3062 bfd_vma start, stop;
3064 if (ELF32_R_TYPE (irel->r_info) != (int) R_SH_CODE)
3067 start = irel->r_offset;
3069 for (irel++; irel < irelend; irel++)
3070 if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_DATA)
3073 stop = irel->r_offset;
3077 if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns,
3078 internal_relocs, &label,
3079 label_end, start, stop, pswapped))
3093 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
3096 sh_elf_swap_insns (bfd *abfd, asection *sec, void *relocs,
3097 bfd_byte *contents, bfd_vma addr)
3099 Elf_Internal_Rela *internal_relocs = (Elf_Internal_Rela *) relocs;
3100 unsigned short i1, i2;
3101 Elf_Internal_Rela *irel, *irelend;
3103 /* Swap the instructions themselves. */
3104 i1 = bfd_get_16 (abfd, contents + addr);
3105 i2 = bfd_get_16 (abfd, contents + addr + 2);
3106 bfd_put_16 (abfd, (bfd_vma) i2, contents + addr);
3107 bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2);
3109 /* Adjust all reloc addresses. */
3110 irelend = internal_relocs + sec->reloc_count;
3111 for (irel = internal_relocs; irel < irelend; irel++)
3113 enum elf_sh_reloc_type type;
3116 /* There are a few special types of relocs that we don't want to
3117 adjust. These relocs do not apply to the instruction itself,
3118 but are only associated with the address. */
3119 type = (enum elf_sh_reloc_type) ELF32_R_TYPE (irel->r_info);
3120 if (type == R_SH_ALIGN
3121 || type == R_SH_CODE
3122 || type == R_SH_DATA
3123 || type == R_SH_LABEL)
3126 /* If an R_SH_USES reloc points to one of the addresses being
3127 swapped, we must adjust it. It would be incorrect to do this
3128 for a jump, though, since we want to execute both
3129 instructions after the jump. (We have avoided swapping
3130 around a label, so the jump will not wind up executing an
3131 instruction it shouldn't). */
3132 if (type == R_SH_USES)
3136 off = irel->r_offset + 4 + irel->r_addend;
3138 irel->r_offset += 2;
3139 else if (off == addr + 2)
3140 irel->r_offset -= 2;
3143 if (irel->r_offset == addr)
3145 irel->r_offset += 2;
3148 else if (irel->r_offset == addr + 2)
3150 irel->r_offset -= 2;
3159 unsigned short insn, oinsn;
3160 bfd_boolean overflow;
3162 loc = contents + irel->r_offset;
3171 insn = bfd_get_16 (abfd, loc);
3174 if ((oinsn & 0xff00) != (insn & 0xff00))
3176 bfd_put_16 (abfd, (bfd_vma) insn, loc);
3180 insn = bfd_get_16 (abfd, loc);
3183 if ((oinsn & 0xf000) != (insn & 0xf000))
3185 bfd_put_16 (abfd, (bfd_vma) insn, loc);
3189 /* This reloc ignores the least significant 3 bits of
3190 the program counter before adding in the offset.
3191 This means that if ADDR is at an even address, the
3192 swap will not affect the offset. If ADDR is an at an
3193 odd address, then the instruction will be crossing a
3194 four byte boundary, and must be adjusted. */
3195 if ((addr & 3) != 0)
3197 insn = bfd_get_16 (abfd, loc);
3200 if ((oinsn & 0xff00) != (insn & 0xff00))
3202 bfd_put_16 (abfd, (bfd_vma) insn, loc);
3210 ((*_bfd_error_handler)
3211 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
3212 bfd_archive_filename (abfd), (unsigned long) irel->r_offset));
3213 bfd_set_error (bfd_error_bad_value);
3222 #ifdef INCLUDE_SHMEDIA
3224 /* The size in bytes of an entry in the procedure linkage table. */
3226 #define PLT_ENTRY_SIZE 64
3228 /* First entry in an absolute procedure linkage table look like this. */
3230 static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3232 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
3233 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
3234 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3235 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3236 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3237 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3238 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3239 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3240 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3241 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3242 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3243 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3244 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3245 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3246 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3247 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3250 static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3252 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
3253 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
3254 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3255 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3256 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3257 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3258 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3259 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3260 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3261 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3262 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3263 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3264 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3265 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3266 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3267 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3270 /* Sebsequent entries in an absolute procedure linkage table look like
3273 static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3275 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
3276 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
3277 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
3278 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3279 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3280 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3281 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3282 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3283 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
3284 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
3285 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3286 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3287 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3288 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3289 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3290 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3293 static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3295 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3296 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3297 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
3298 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3299 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3300 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3301 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3302 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3303 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
3304 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
3305 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3306 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3307 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3308 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3309 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3310 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3313 /* Entries in a PIC procedure linkage table look like this. */
3315 static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3317 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3318 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3319 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
3320 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3321 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3322 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3323 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3324 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3325 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3326 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
3327 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3328 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3329 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3330 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3331 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3332 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3335 static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3337 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3338 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3339 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
3340 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3341 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3342 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3343 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3344 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3345 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3346 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
3347 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3348 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3349 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3350 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3351 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3352 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3355 static const bfd_byte *elf_sh_plt0_entry;
3356 static const bfd_byte *elf_sh_plt_entry;
3357 static const bfd_byte *elf_sh_pic_plt_entry;
3359 /* Return size of a PLT entry. */
3360 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3362 /* Return offset of the PLT0 address in an absolute PLT entry. */
3363 #define elf_sh_plt_plt0_offset(info) 32
3365 /* Return offset of the linker in PLT0 entry. */
3366 #define elf_sh_plt0_gotplt_offset(info) 0
3368 /* Return offset of the trampoline in PLT entry */
3369 #define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
3371 /* Return offset of the symbol in PLT entry. */
3372 #define elf_sh_plt_symbol_offset(info) 0
3374 /* Return offset of the relocation in PLT entry. */
3375 #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
3378 movi_shori_putval (bfd *output_bfd, unsigned long value, char *addr)
3380 bfd_put_32 (output_bfd,
3381 bfd_get_32 (output_bfd, addr)
3382 | ((value >> 6) & 0x3fffc00),
3384 bfd_put_32 (output_bfd,
3385 bfd_get_32 (output_bfd, addr + 4)
3386 | ((value << 10) & 0x3fffc00),
3391 /* The size in bytes of an entry in the procedure linkage table. */
3393 #define PLT_ENTRY_SIZE 28
3395 /* First entry in an absolute procedure linkage table look like this. */
3398 /* Note - this code has been "optimised" not to use r2. r2 is used by
3399 GCC to return the address of large structures, so it should not be
3400 corrupted here. This does mean however, that this PLT does not conform
3401 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
3402 and r2 contains the GOT id. This version stores the GOT id in r0 and
3403 ignores the type. Loaders can easily detect this difference however,
3404 since the type will always be 0 or 8, and the GOT ids will always be
3405 greater than or equal to 12. */
3406 static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3408 0xd0, 0x05, /* mov.l 2f,r0 */
3409 0x60, 0x02, /* mov.l @r0,r0 */
3410 0x2f, 0x06, /* mov.l r0,@-r15 */
3411 0xd0, 0x03, /* mov.l 1f,r0 */
3412 0x60, 0x02, /* mov.l @r0,r0 */
3413 0x40, 0x2b, /* jmp @r0 */
3414 0x60, 0xf6, /* mov.l @r15+,r0 */
3415 0x00, 0x09, /* nop */
3416 0x00, 0x09, /* nop */
3417 0x00, 0x09, /* nop */
3418 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3419 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3422 static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3424 0x05, 0xd0, /* mov.l 2f,r0 */
3425 0x02, 0x60, /* mov.l @r0,r0 */
3426 0x06, 0x2f, /* mov.l r0,@-r15 */
3427 0x03, 0xd0, /* mov.l 1f,r0 */
3428 0x02, 0x60, /* mov.l @r0,r0 */
3429 0x2b, 0x40, /* jmp @r0 */
3430 0xf6, 0x60, /* mov.l @r15+,r0 */
3431 0x09, 0x00, /* nop */
3432 0x09, 0x00, /* nop */
3433 0x09, 0x00, /* nop */
3434 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3435 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3438 /* Sebsequent entries in an absolute procedure linkage table look like
3441 static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3443 0xd0, 0x04, /* mov.l 1f,r0 */
3444 0x60, 0x02, /* mov.l @r0,r0 */
3445 0xd1, 0x02, /* mov.l 0f,r1 */
3446 0x40, 0x2b, /* jmp @r0 */
3447 0x60, 0x13, /* mov r1,r0 */
3448 0xd1, 0x03, /* mov.l 2f,r1 */
3449 0x40, 0x2b, /* jmp @r0 */
3450 0x00, 0x09, /* nop */
3451 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3452 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3453 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3456 static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3458 0x04, 0xd0, /* mov.l 1f,r0 */
3459 0x02, 0x60, /* mov.l @r0,r0 */
3460 0x02, 0xd1, /* mov.l 0f,r1 */
3461 0x2b, 0x40, /* jmp @r0 */
3462 0x13, 0x60, /* mov r1,r0 */
3463 0x03, 0xd1, /* mov.l 2f,r1 */
3464 0x2b, 0x40, /* jmp @r0 */
3465 0x09, 0x00, /* nop */
3466 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3467 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3468 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3471 /* Entries in a PIC procedure linkage table look like this. */
3473 static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3475 0xd0, 0x04, /* mov.l 1f,r0 */
3476 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3477 0x40, 0x2b, /* jmp @r0 */
3478 0x00, 0x09, /* nop */
3479 0x50, 0xc2, /* mov.l @(8,r12),r0 */
3480 0xd1, 0x03, /* mov.l 2f,r1 */
3481 0x40, 0x2b, /* jmp @r0 */
3482 0x50, 0xc1, /* mov.l @(4,r12),r0 */
3483 0x00, 0x09, /* nop */
3484 0x00, 0x09, /* nop */
3485 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3486 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3489 static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3491 0x04, 0xd0, /* mov.l 1f,r0 */
3492 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3493 0x2b, 0x40, /* jmp @r0 */
3494 0x09, 0x00, /* nop */
3495 0xc2, 0x50, /* mov.l @(8,r12),r0 */
3496 0x03, 0xd1, /* mov.l 2f,r1 */
3497 0x2b, 0x40, /* jmp @r0 */
3498 0xc1, 0x50, /* mov.l @(4,r12),r0 */
3499 0x09, 0x00, /* nop */
3500 0x09, 0x00, /* nop */
3501 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3502 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3505 #else /* These are the old style PLT entries. */
3506 static const bfd_byte elf_sh_plt0_entry_be[PLT_ENTRY_SIZE] =
3508 0xd0, 0x04, /* mov.l 1f,r0 */
3509 0xd2, 0x05, /* mov.l 2f,r2 */
3510 0x60, 0x02, /* mov.l @r0,r0 */
3511 0x62, 0x22, /* mov.l @r2,r2 */
3512 0x40, 0x2b, /* jmp @r0 */
3513 0xe0, 0x00, /* mov #0,r0 */
3514 0x00, 0x09, /* nop */
3515 0x00, 0x09, /* nop */
3516 0x00, 0x09, /* nop */
3517 0x00, 0x09, /* nop */
3518 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3519 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3522 static const bfd_byte elf_sh_plt0_entry_le[PLT_ENTRY_SIZE] =
3524 0x04, 0xd0, /* mov.l 1f,r0 */
3525 0x05, 0xd2, /* mov.l 2f,r2 */
3526 0x02, 0x60, /* mov.l @r0,r0 */
3527 0x22, 0x62, /* mov.l @r2,r2 */
3528 0x2b, 0x40, /* jmp @r0 */
3529 0x00, 0xe0, /* mov #0,r0 */
3530 0x09, 0x00, /* nop */
3531 0x09, 0x00, /* nop */
3532 0x09, 0x00, /* nop */
3533 0x09, 0x00, /* nop */
3534 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3535 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3538 /* Sebsequent entries in an absolute procedure linkage table look like
3541 static const bfd_byte elf_sh_plt_entry_be[PLT_ENTRY_SIZE] =
3543 0xd0, 0x04, /* mov.l 1f,r0 */
3544 0x60, 0x02, /* mov.l @r0,r0 */
3545 0xd2, 0x02, /* mov.l 0f,r2 */
3546 0x40, 0x2b, /* jmp @r0 */
3547 0x60, 0x23, /* mov r2,r0 */
3548 0xd1, 0x03, /* mov.l 2f,r1 */
3549 0x40, 0x2b, /* jmp @r0 */
3550 0x00, 0x09, /* nop */
3551 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3552 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3553 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3556 static const bfd_byte elf_sh_plt_entry_le[PLT_ENTRY_SIZE] =
3558 0x04, 0xd0, /* mov.l 1f,r0 */
3559 0x02, 0x60, /* mov.l @r0,r0 */
3560 0x02, 0xd2, /* mov.l 0f,r2 */
3561 0x2b, 0x40, /* jmp @r0 */
3562 0x23, 0x60, /* mov r2,r0 */
3563 0x03, 0xd1, /* mov.l 2f,r1 */
3564 0x2b, 0x40, /* jmp @r0 */
3565 0x09, 0x00, /* nop */
3566 0, 0, 0, 0, /* 0: replaced with address of .PLT. */
3567 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3568 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3571 /* Entries in a PIC procedure linkage table look like this. */
3573 static const bfd_byte elf_sh_pic_plt_entry_be[PLT_ENTRY_SIZE] =
3575 0xd0, 0x04, /* mov.l 1f,r0 */
3576 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3577 0x40, 0x2b, /* jmp @r0 */
3578 0x00, 0x09, /* nop */
3579 0x50, 0xc2, /* 0: mov.l @(8,r12),r0 */
3580 0x52, 0xc1, /* 1: mov.l @(4,r12),r2 */
3581 0xd1, 0x02, /* mov.l 2f,r1 */
3582 0x40, 0x2b, /* jmp @r0 */
3583 0xe0, 0x00, /* mov #0,r0 ! shows the type of PLT. */
3584 0x00, 0x09, /* nop */
3585 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3586 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3589 static const bfd_byte elf_sh_pic_plt_entry_le[PLT_ENTRY_SIZE] =
3591 0x04, 0xd0, /* mov.l 1f,r0 */
3592 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3593 0x2b, 0x40, /* jmp @r0 */
3594 0x09, 0x00, /* nop */
3595 0xc2, 0x50, /* 0: mov.l @(8,r12),r0 */
3596 0xc1, 0x52, /* 1: mov.l @(4,r12),r2 */
3597 0x02, 0xd1, /* mov.l 2f,r1 */
3598 0x2b, 0x40, /* jmp @r0 */
3599 0x00, 0xe0, /* mov #0,r0 ! shows the type of PLT. */
3600 0x09, 0x00, /* nop */
3601 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3602 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3604 #endif /* old style PLT entries. */
3606 static const bfd_byte *elf_sh_plt0_entry;
3607 static const bfd_byte *elf_sh_plt_entry;
3608 static const bfd_byte *elf_sh_pic_plt_entry;
3610 /* Return size of a PLT entry. */
3611 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3613 /* Return offset of the PLT0 address in an absolute PLT entry. */
3614 #define elf_sh_plt_plt0_offset(info) 16
3616 /* Return offset of the linker in PLT0 entry. */
3617 #define elf_sh_plt0_linker_offset(info) 20
3619 /* Return offset of the GOT id in PLT0 entry. */
3620 #define elf_sh_plt0_gotid_offset(info) 24
3622 /* Return offset of the temporary in PLT entry */
3623 #define elf_sh_plt_temp_offset(info) 8
3625 /* Return offset of the symbol in PLT entry. */
3626 #define elf_sh_plt_symbol_offset(info) 20
3628 /* Return offset of the relocation in PLT entry. */
3629 #define elf_sh_plt_reloc_offset(info) 24
3632 /* The sh linker needs to keep track of the number of relocs that it
3633 decides to copy as dynamic relocs in check_relocs for each symbol.
3634 This is so that it can later discard them if they are found to be
3635 unnecessary. We store the information in a field extending the
3636 regular ELF linker hash table. */
3638 struct elf_sh_dyn_relocs
3640 struct elf_sh_dyn_relocs *next;
3642 /* The input section of the reloc. */
3645 /* Total number of relocs copied for the input section. */
3646 bfd_size_type count;
3648 /* Number of pc-relative relocs copied for the input section. */
3649 bfd_size_type pc_count;
3652 /* sh ELF linker hash entry. */
3654 struct elf_sh_link_hash_entry
3656 struct elf_link_hash_entry root;
3658 #ifdef INCLUDE_SHMEDIA
3661 bfd_signed_vma refcount;
3666 /* Track dynamic relocs copied for this symbol. */
3667 struct elf_sh_dyn_relocs *dyn_relocs;
3669 bfd_signed_vma gotplt_refcount;
3672 GOT_UNKNOWN = 0, GOT_NORMAL, GOT_TLS_GD, GOT_TLS_IE
3676 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
3678 struct sh_elf_obj_tdata
3680 struct elf_obj_tdata root;
3682 /* tls_type for each local got entry. */
3683 char *local_got_tls_type;
3686 #define sh_elf_tdata(abfd) \
3687 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
3689 #define sh_elf_local_got_tls_type(abfd) \
3690 (sh_elf_tdata (abfd)->local_got_tls_type)
3692 /* Override the generic function because we need to store sh_elf_obj_tdata
3693 as the specific tdata. */
3696 sh_elf_mkobject (bfd *abfd)
3698 bfd_size_type amt = sizeof (struct sh_elf_obj_tdata);
3699 abfd->tdata.any = bfd_zalloc (abfd, amt);
3700 if (abfd->tdata.any == NULL)
3705 /* sh ELF linker hash table. */
3707 struct elf_sh_link_hash_table
3709 struct elf_link_hash_table root;
3711 /* Short-cuts to get to dynamic linker sections. */
3720 /* Small local sym to section mapping cache. */
3721 struct sym_sec_cache sym_sec;
3723 /* A counter or offset to track a TLS got entry. */
3726 bfd_signed_vma refcount;
3731 /* Traverse an sh ELF linker hash table. */
3733 #define sh_elf_link_hash_traverse(table, func, info) \
3734 (elf_link_hash_traverse \
3736 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
3739 /* Get the sh ELF linker hash table from a link_info structure. */
3741 #define sh_elf_hash_table(p) \
3742 ((struct elf_sh_link_hash_table *) ((p)->hash))
3744 /* Create an entry in an sh ELF linker hash table. */
3746 static struct bfd_hash_entry *
3747 sh_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
3748 struct bfd_hash_table *table,
3751 struct elf_sh_link_hash_entry *ret =
3752 (struct elf_sh_link_hash_entry *) entry;
3754 /* Allocate the structure if it has not already been allocated by a
3756 if (ret == (struct elf_sh_link_hash_entry *) NULL)
3757 ret = ((struct elf_sh_link_hash_entry *)
3758 bfd_hash_allocate (table,
3759 sizeof (struct elf_sh_link_hash_entry)));
3760 if (ret == (struct elf_sh_link_hash_entry *) NULL)
3761 return (struct bfd_hash_entry *) ret;
3763 /* Call the allocation method of the superclass. */
3764 ret = ((struct elf_sh_link_hash_entry *)
3765 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
3767 if (ret != (struct elf_sh_link_hash_entry *) NULL)
3769 ret->dyn_relocs = NULL;
3770 ret->gotplt_refcount = 0;
3771 #ifdef INCLUDE_SHMEDIA
3772 ret->datalabel_got.refcount = ret->root.got.refcount;
3774 ret->tls_type = GOT_UNKNOWN;
3777 return (struct bfd_hash_entry *) ret;
3780 /* Create an sh ELF linker hash table. */
3782 static struct bfd_link_hash_table *
3783 sh_elf_link_hash_table_create (bfd *abfd)
3785 struct elf_sh_link_hash_table *ret;
3786 bfd_size_type amt = sizeof (struct elf_sh_link_hash_table);
3788 ret = (struct elf_sh_link_hash_table *) bfd_malloc (amt);
3789 if (ret == (struct elf_sh_link_hash_table *) NULL)
3792 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
3793 sh_elf_link_hash_newfunc))
3800 ret->sgotplt = NULL;
3801 ret->srelgot = NULL;
3803 ret->srelplt = NULL;
3804 ret->sdynbss = NULL;
3805 ret->srelbss = NULL;
3806 ret->sym_sec.abfd = NULL;
3807 ret->tls_ldm_got.refcount = 0;
3809 return &ret->root.root;
3812 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
3813 shortcuts to them in our hash table. */
3816 create_got_section (bfd *dynobj, struct bfd_link_info *info)
3818 struct elf_sh_link_hash_table *htab;
3820 if (! _bfd_elf_create_got_section (dynobj, info))
3823 htab = sh_elf_hash_table (info);
3824 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
3825 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
3826 if (! htab->sgot || ! htab->sgotplt)
3829 htab->srelgot = bfd_make_section (dynobj, ".rela.got");
3830 if (htab->srelgot == NULL
3831 || ! bfd_set_section_flags (dynobj, htab->srelgot,
3836 | SEC_LINKER_CREATED
3838 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
3843 /* Create dynamic sections when linking against a dynamic object. */
3846 sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
3848 struct elf_sh_link_hash_table *htab;
3849 flagword flags, pltflags;
3850 register asection *s;
3851 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
3854 switch (bed->s->arch_size)
3865 bfd_set_error (bfd_error_bad_value);
3869 htab = sh_elf_hash_table (info);
3870 if (htab->root.dynamic_sections_created)
3873 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3874 .rel[a].bss sections. */
3876 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3877 | SEC_LINKER_CREATED);
3880 pltflags |= SEC_CODE;
3881 if (bed->plt_not_loaded)
3882 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
3883 if (bed->plt_readonly)
3884 pltflags |= SEC_READONLY;
3886 s = bfd_make_section (abfd, ".plt");
3889 || ! bfd_set_section_flags (abfd, s, pltflags)
3890 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
3893 if (bed->want_plt_sym)
3895 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3897 struct elf_link_hash_entry *h;
3898 struct bfd_link_hash_entry *bh = NULL;
3900 if (! (_bfd_generic_link_add_one_symbol
3901 (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
3902 (bfd_vma) 0, (const char *) NULL, FALSE,
3903 get_elf_backend_data (abfd)->collect, &bh)))
3906 h = (struct elf_link_hash_entry *) bh;
3907 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3908 h->type = STT_OBJECT;
3911 && ! bfd_elf_link_record_dynamic_symbol (info, h))
3915 s = bfd_make_section (abfd,
3916 bed->default_use_rela_p ? ".rela.plt" : ".rel.plt");
3919 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3920 || ! bfd_set_section_alignment (abfd, s, ptralign))
3923 if (htab->sgot == NULL
3924 && !create_got_section (abfd, info))
3928 const char *secname;
3933 for (sec = abfd->sections; sec; sec = sec->next)
3935 secflags = bfd_get_section_flags (abfd, sec);
3936 if ((secflags & (SEC_DATA | SEC_LINKER_CREATED))
3937 || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS))
3939 secname = bfd_get_section_name (abfd, sec);
3940 relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
3941 strcpy (relname, ".rela");
3942 strcat (relname, secname);
3943 if (bfd_get_section_by_name (abfd, secname))
3945 s = bfd_make_section (abfd, relname);
3947 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3948 || ! bfd_set_section_alignment (abfd, s, ptralign))
3953 if (bed->want_dynbss)
3955 /* The .dynbss section is a place to put symbols which are defined
3956 by dynamic objects, are referenced by regular objects, and are
3957 not functions. We must allocate space for them in the process
3958 image and use a R_*_COPY reloc to tell the dynamic linker to
3959 initialize them at run time. The linker script puts the .dynbss
3960 section into the .bss section of the final image. */
3961 s = bfd_make_section (abfd, ".dynbss");
3964 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
3967 /* The .rel[a].bss section holds copy relocs. This section is not
3968 normally needed. We need to create it here, though, so that the
3969 linker will map it to an output section. We can't just create it
3970 only if we need it, because we will not know whether we need it
3971 until we have seen all the input files, and the first time the
3972 main linker code calls BFD after examining all the input files
3973 (size_dynamic_sections) the input sections have already been
3974 mapped to the output sections. If the section turns out not to
3975 be needed, we can discard it later. We will never need this
3976 section when generating a shared object, since they do not use
3980 s = bfd_make_section (abfd,
3981 (bed->default_use_rela_p
3982 ? ".rela.bss" : ".rel.bss"));
3985 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
3986 || ! bfd_set_section_alignment (abfd, s, ptralign))
3994 /* Adjust a symbol defined by a dynamic object and referenced by a
3995 regular object. The current definition is in some section of the
3996 dynamic object, but we're not including those sections. We have to
3997 change the definition to something the rest of the link can
4001 sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
4002 struct elf_link_hash_entry *h)
4004 struct elf_sh_link_hash_table *htab;
4005 struct elf_sh_link_hash_entry *eh;
4006 struct elf_sh_dyn_relocs *p;
4008 unsigned int power_of_two;
4010 htab = sh_elf_hash_table (info);
4012 /* Make sure we know what is going on here. */
4013 BFD_ASSERT (htab->root.dynobj != NULL
4014 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
4015 || h->weakdef != NULL
4016 || ((h->elf_link_hash_flags
4017 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
4018 && (h->elf_link_hash_flags
4019 & ELF_LINK_HASH_REF_REGULAR) != 0
4020 && (h->elf_link_hash_flags
4021 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
4023 /* If this is a function, put it in the procedure linkage table. We
4024 will fill in the contents of the procedure linkage table later,
4025 when we know the address of the .got section. */
4026 if (h->type == STT_FUNC
4027 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
4029 if (h->plt.refcount <= 0
4030 || SYMBOL_CALLS_LOCAL (info, h)
4031 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
4032 && h->root.type == bfd_link_hash_undefweak))
4034 /* This case can occur if we saw a PLT reloc in an input
4035 file, but the symbol was never referred to by a dynamic
4036 object. In such a case, we don't actually need to build
4037 a procedure linkage table, and we can just do a REL32
4039 h->plt.offset = (bfd_vma) -1;
4040 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
4046 h->plt.offset = (bfd_vma) -1;
4048 /* If this is a weak symbol, and there is a real definition, the
4049 processor independent code will have arranged for us to see the
4050 real definition first, and we can just use the same value. */
4051 if (h->weakdef != NULL)
4053 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
4054 || h->weakdef->root.type == bfd_link_hash_defweak);
4055 h->root.u.def.section = h->weakdef->root.u.def.section;
4056 h->root.u.def.value = h->weakdef->root.u.def.value;
4057 if (info->nocopyreloc)
4058 h->elf_link_hash_flags
4059 = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF)
4060 | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF));
4064 /* This is a reference to a symbol defined by a dynamic object which
4065 is not a function. */
4067 /* If we are creating a shared library, we must presume that the
4068 only references to the symbol are via the global offset table.
4069 For such cases we need not do anything here; the relocations will
4070 be handled correctly by relocate_section. */
4074 /* If there are no references to this symbol that do not use the
4075 GOT, we don't need to generate a copy reloc. */
4076 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
4079 /* If -z nocopyreloc was given, we won't generate them either. */
4080 if (info->nocopyreloc)
4082 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
4086 eh = (struct elf_sh_link_hash_entry *) h;
4087 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4089 s = p->sec->output_section;
4090 if (s != NULL && (s->flags & (SEC_READONLY | SEC_HAS_CONTENTS)) != 0)
4094 /* If we didn't find any dynamic relocs in sections which needs the
4095 copy reloc, then we'll be keeping the dynamic relocs and avoiding
4099 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
4103 /* We must allocate the symbol in our .dynbss section, which will
4104 become part of the .bss section of the executable. There will be
4105 an entry for this symbol in the .dynsym section. The dynamic
4106 object will contain position independent code, so all references
4107 from the dynamic object to this symbol will go through the global
4108 offset table. The dynamic linker will use the .dynsym entry to
4109 determine the address it must put in the global offset table, so
4110 both the dynamic object and the regular object will refer to the
4111 same memory location for the variable. */
4114 BFD_ASSERT (s != NULL);
4116 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
4117 copy the initial value out of the dynamic object and into the
4118 runtime process image. We need to remember the offset into the
4119 .rela.bss section we are going to use. */
4120 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
4124 srel = htab->srelbss;
4125 BFD_ASSERT (srel != NULL);
4126 srel->size += sizeof (Elf32_External_Rela);
4127 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
4130 /* We need to figure out the alignment required for this symbol. I
4131 have no idea how ELF linkers handle this. */
4132 power_of_two = bfd_log2 (h->size);
4133 if (power_of_two > 3)
4136 /* Apply the required alignment. */
4137 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
4138 if (power_of_two > bfd_get_section_alignment (htab->root.dynobj, s))
4140 if (! bfd_set_section_alignment (htab->root.dynobj, s, power_of_two))
4144 /* Define the symbol as being at this point in the section. */
4145 h->root.u.def.section = s;
4146 h->root.u.def.value = s->size;
4148 /* Increment the section size to make room for the symbol. */
4154 /* Allocate space in .plt, .got and associated reloc sections for
4158 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
4160 struct bfd_link_info *info;
4161 struct elf_sh_link_hash_table *htab;
4162 struct elf_sh_link_hash_entry *eh;
4163 struct elf_sh_dyn_relocs *p;
4165 if (h->root.type == bfd_link_hash_indirect)
4168 if (h->root.type == bfd_link_hash_warning)
4169 /* When warning symbols are created, they **replace** the "real"
4170 entry in the hash table, thus we never get to see the real
4171 symbol in a hash traversal. So look at it now. */
4172 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4174 info = (struct bfd_link_info *) inf;
4175 htab = sh_elf_hash_table (info);
4177 eh = (struct elf_sh_link_hash_entry *) h;
4178 if ((h->got.refcount > 0
4179 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
4180 && eh->gotplt_refcount > 0)
4182 /* The symbol has been forced local, or we have some direct got refs,
4183 so treat all the gotplt refs as got refs. */
4184 h->got.refcount += eh->gotplt_refcount;
4185 if (h->plt.refcount >= eh->gotplt_refcount)
4186 h->plt.refcount -= eh->gotplt_refcount;
4189 if (htab->root.dynamic_sections_created
4190 && h->plt.refcount > 0
4191 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4192 || h->root.type != bfd_link_hash_undefweak))
4194 /* Make sure this symbol is output as a dynamic symbol.
4195 Undefined weak syms won't yet be marked as dynamic. */
4196 if (h->dynindx == -1
4197 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4199 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4204 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
4206 asection *s = htab->splt;
4208 /* If this is the first .plt entry, make room for the special
4211 s->size += PLT_ENTRY_SIZE;
4213 h->plt.offset = s->size;
4215 /* If this symbol is not defined in a regular file, and we are
4216 not generating a shared library, then set the symbol to this
4217 location in the .plt. This is required to make function
4218 pointers compare as equal between the normal executable and
4219 the shared library. */
4221 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4223 h->root.u.def.section = s;
4224 h->root.u.def.value = h->plt.offset;
4227 /* Make room for this entry. */
4228 s->size += PLT_ENTRY_SIZE;
4230 /* We also need to make an entry in the .got.plt section, which
4231 will be placed in the .got section by the linker script. */
4232 htab->sgotplt->size += 4;
4234 /* We also need to make an entry in the .rel.plt section. */
4235 htab->srelplt->size += sizeof (Elf32_External_Rela);
4239 h->plt.offset = (bfd_vma) -1;
4240 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
4245 h->plt.offset = (bfd_vma) -1;
4246 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
4249 if (h->got.refcount > 0)
4253 int tls_type = sh_elf_hash_entry (h)->tls_type;
4255 /* Make sure this symbol is output as a dynamic symbol.
4256 Undefined weak syms won't yet be marked as dynamic. */
4257 if (h->dynindx == -1
4258 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4260 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4265 h->got.offset = s->size;
4267 /* R_SH_TLS_GD needs 2 consecutive GOT slots. */
4268 if (tls_type == GOT_TLS_GD)
4270 dyn = htab->root.dynamic_sections_created;
4271 /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
4272 R_SH_TLS_GD needs one if local symbol and two if global. */
4273 if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
4274 || (tls_type == GOT_TLS_IE && dyn))
4275 htab->srelgot->size += sizeof (Elf32_External_Rela);
4276 else if (tls_type == GOT_TLS_GD)
4277 htab->srelgot->size += 2 * sizeof (Elf32_External_Rela);
4278 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4279 || h->root.type != bfd_link_hash_undefweak)
4281 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
4282 htab->srelgot->size += sizeof (Elf32_External_Rela);
4285 h->got.offset = (bfd_vma) -1;
4287 #ifdef INCLUDE_SHMEDIA
4288 if (eh->datalabel_got.refcount > 0)
4293 /* Make sure this symbol is output as a dynamic symbol.
4294 Undefined weak syms won't yet be marked as dynamic. */
4295 if (h->dynindx == -1
4296 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4298 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4303 eh->datalabel_got.offset = s->size;
4305 dyn = htab->root.dynamic_sections_created;
4306 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
4307 htab->srelgot->size += sizeof (Elf32_External_Rela);
4310 eh->datalabel_got.offset = (bfd_vma) -1;
4313 if (eh->dyn_relocs == NULL)
4316 /* In the shared -Bsymbolic case, discard space allocated for
4317 dynamic pc-relative relocs against symbols which turn out to be
4318 defined in regular objects. For the normal shared case, discard
4319 space for pc-relative relocs that have become local due to symbol
4320 visibility changes. */
4324 if (SYMBOL_CALLS_LOCAL (info, h))
4326 struct elf_sh_dyn_relocs **pp;
4328 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
4330 p->count -= p->pc_count;
4339 /* Also discard relocs on undefined weak syms with non-default
4341 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
4342 && h->root.type == bfd_link_hash_undefweak)
4343 eh->dyn_relocs = NULL;
4347 /* For the non-shared case, discard space for relocs against
4348 symbols which turn out to need copy relocs or are not
4351 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
4352 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
4353 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4354 || (htab->root.dynamic_sections_created
4355 && (h->root.type == bfd_link_hash_undefweak
4356 || h->root.type == bfd_link_hash_undefined))))
4358 /* Make sure this symbol is output as a dynamic symbol.
4359 Undefined weak syms won't yet be marked as dynamic. */
4360 if (h->dynindx == -1
4361 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4363 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4367 /* If that succeeded, we know we'll be keeping all the
4369 if (h->dynindx != -1)
4373 eh->dyn_relocs = NULL;
4378 /* Finally, allocate space. */
4379 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4381 asection *sreloc = elf_section_data (p->sec)->sreloc;
4382 sreloc->size += p->count * sizeof (Elf32_External_Rela);
4388 /* Find any dynamic relocs that apply to read-only sections. */
4391 readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
4393 struct elf_sh_link_hash_entry *eh;
4394 struct elf_sh_dyn_relocs *p;
4396 if (h->root.type == bfd_link_hash_warning)
4397 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4399 eh = (struct elf_sh_link_hash_entry *) h;
4400 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4402 asection *s = p->sec->output_section;
4404 if (s != NULL && (s->flags & SEC_READONLY) != 0)
4406 struct bfd_link_info *info = (struct bfd_link_info *) inf;
4408 info->flags |= DF_TEXTREL;
4410 /* Not an error, just cut short the traversal. */
4417 /* Set the sizes of the dynamic sections. */
4420 sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
4421 struct bfd_link_info *info)
4423 struct elf_sh_link_hash_table *htab;
4429 htab = sh_elf_hash_table (info);
4430 dynobj = htab->root.dynobj;
4431 BFD_ASSERT (dynobj != NULL);
4433 if (htab->root.dynamic_sections_created)
4435 /* Set the contents of the .interp section to the interpreter. */
4436 if (info->executable)
4438 s = bfd_get_section_by_name (dynobj, ".interp");
4439 BFD_ASSERT (s != NULL);
4440 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
4441 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4445 /* Set up .got offsets for local syms, and space for local dynamic
4447 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4449 bfd_signed_vma *local_got;
4450 bfd_signed_vma *end_local_got;
4451 char *local_tls_type;
4452 bfd_size_type locsymcount;
4453 Elf_Internal_Shdr *symtab_hdr;
4456 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
4459 for (s = ibfd->sections; s != NULL; s = s->next)
4461 struct elf_sh_dyn_relocs *p;
4463 for (p = ((struct elf_sh_dyn_relocs *)
4464 elf_section_data (s)->local_dynrel);
4468 if (! bfd_is_abs_section (p->sec)
4469 && bfd_is_abs_section (p->sec->output_section))
4471 /* Input section has been discarded, either because
4472 it is a copy of a linkonce section or due to
4473 linker script /DISCARD/, so we'll be discarding
4476 else if (p->count != 0)
4478 srel = elf_section_data (p->sec)->sreloc;
4479 srel->size += p->count * sizeof (Elf32_External_Rela);
4480 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
4481 info->flags |= DF_TEXTREL;
4486 local_got = elf_local_got_refcounts (ibfd);
4490 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4491 locsymcount = symtab_hdr->sh_info;
4492 #ifdef INCLUDE_SHMEDIA
4493 /* Count datalabel local GOT. */
4496 end_local_got = local_got + locsymcount;
4497 local_tls_type = sh_elf_local_got_tls_type (ibfd);
4499 srel = htab->srelgot;
4500 for (; local_got < end_local_got; ++local_got)
4504 *local_got = s->size;
4506 if (*local_tls_type == GOT_TLS_GD)
4509 srel->size += sizeof (Elf32_External_Rela);
4512 *local_got = (bfd_vma) -1;
4517 if (htab->tls_ldm_got.refcount > 0)
4519 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
4521 htab->tls_ldm_got.offset = htab->sgot->size;
4522 htab->sgot->size += 8;
4523 htab->srelgot->size += sizeof (Elf32_External_Rela);
4526 htab->tls_ldm_got.offset = -1;
4528 /* Allocate global sym .plt and .got entries, and space for global
4529 sym dynamic relocs. */
4530 elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
4532 /* We now have determined the sizes of the various dynamic sections.
4533 Allocate memory for them. */
4535 for (s = dynobj->sections; s != NULL; s = s->next)
4537 if ((s->flags & SEC_LINKER_CREATED) == 0)
4542 || s == htab->sgotplt)
4544 /* Strip this section if we don't need it; see the
4547 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
4549 if (s->size != 0 && s != htab->srelplt)
4552 /* We use the reloc_count field as a counter if we need
4553 to copy relocs into the output file. */
4558 /* It's not one of our sections, so don't allocate space. */
4564 /* If we don't need this section, strip it from the
4565 output file. This is mostly to handle .rela.bss and
4566 .rela.plt. We must create both sections in
4567 create_dynamic_sections, because they must be created
4568 before the linker maps input sections to output
4569 sections. The linker does that before
4570 adjust_dynamic_symbol is called, and it is that
4571 function which decides whether anything needs to go
4572 into these sections. */
4574 _bfd_strip_section_from_output (info, s);
4578 /* Allocate memory for the section contents. We use bfd_zalloc
4579 here in case unused entries are not reclaimed before the
4580 section's contents are written out. This should not happen,
4581 but this way if it does, we get a R_SH_NONE reloc instead
4583 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
4584 if (s->contents == NULL)
4588 if (htab->root.dynamic_sections_created)
4590 /* Add some entries to the .dynamic section. We fill in the
4591 values later, in sh_elf_finish_dynamic_sections, but we
4592 must add the entries now so that we get the correct size for
4593 the .dynamic section. The DT_DEBUG entry is filled in by the
4594 dynamic linker and used by the debugger. */
4595 #define add_dynamic_entry(TAG, VAL) \
4596 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4598 if (info->executable)
4600 if (! add_dynamic_entry (DT_DEBUG, 0))
4604 if (htab->splt->size != 0)
4606 if (! add_dynamic_entry (DT_PLTGOT, 0)
4607 || ! add_dynamic_entry (DT_PLTRELSZ, 0)
4608 || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
4609 || ! add_dynamic_entry (DT_JMPREL, 0))
4615 if (! add_dynamic_entry (DT_RELA, 0)
4616 || ! add_dynamic_entry (DT_RELASZ, 0)
4617 || ! add_dynamic_entry (DT_RELAENT,
4618 sizeof (Elf32_External_Rela)))
4621 /* If any dynamic relocs apply to a read-only section,
4622 then we need a DT_TEXTREL entry. */
4623 if ((info->flags & DF_TEXTREL) == 0)
4624 elf_link_hash_traverse (&htab->root, readonly_dynrelocs, info);
4626 if ((info->flags & DF_TEXTREL) != 0)
4628 if (! add_dynamic_entry (DT_TEXTREL, 0))
4633 #undef add_dynamic_entry
4638 /* Relocate an SH ELF section. */
4641 sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
4642 bfd *input_bfd, asection *input_section,
4643 bfd_byte *contents, Elf_Internal_Rela *relocs,
4644 Elf_Internal_Sym *local_syms,
4645 asection **local_sections)
4647 struct elf_sh_link_hash_table *htab;
4648 Elf_Internal_Shdr *symtab_hdr;
4649 struct elf_link_hash_entry **sym_hashes;
4650 Elf_Internal_Rela *rel, *relend;
4652 bfd_vma *local_got_offsets;
4659 htab = sh_elf_hash_table (info);
4660 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4661 sym_hashes = elf_sym_hashes (input_bfd);
4662 dynobj = htab->root.dynobj;
4663 local_got_offsets = elf_local_got_offsets (input_bfd);
4666 sgotplt = htab->sgotplt;
4672 relend = relocs + input_section->reloc_count;
4673 for (; rel < relend; rel++)
4676 reloc_howto_type *howto;
4677 unsigned long r_symndx;
4678 Elf_Internal_Sym *sym;
4680 struct elf_link_hash_entry *h;
4682 bfd_vma addend = (bfd_vma) 0;
4683 bfd_reloc_status_type r;
4684 int seen_stt_datalabel = 0;
4688 r_symndx = ELF32_R_SYM (rel->r_info);
4690 r_type = ELF32_R_TYPE (rel->r_info);
4692 /* Many of the relocs are only used for relaxing, and are
4693 handled entirely by the relaxation code. */
4694 if (r_type >= (int) R_SH_GNU_VTINHERIT
4695 && r_type <= (int) R_SH_LABEL)
4697 if (r_type == (int) R_SH_NONE)
4701 || r_type >= R_SH_max
4702 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC
4703 && r_type <= (int) R_SH_LAST_INVALID_RELOC)
4704 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_3
4705 && r_type <= (int) R_SH_LAST_INVALID_RELOC_3)
4706 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_4
4707 && r_type <= (int) R_SH_LAST_INVALID_RELOC_4)
4708 || ( r_type >= (int) R_SH_FIRST_INVALID_RELOC_5
4709 && r_type <= (int) R_SH_LAST_INVALID_RELOC_5)
4710 || (r_type >= (int) R_SH_FIRST_INVALID_RELOC_2
4711 && r_type <= (int) R_SH_LAST_INVALID_RELOC_2))
4713 bfd_set_error (bfd_error_bad_value);
4717 howto = sh_elf_howto_table + r_type;
4719 /* For relocs that aren't partial_inplace, we get the addend from
4721 if (! howto->partial_inplace)
4722 addend = rel->r_addend;
4727 if (r_symndx < symtab_hdr->sh_info)
4729 sym = local_syms + r_symndx;
4730 sec = local_sections[r_symndx];
4731 relocation = (sec->output_section->vma
4732 + sec->output_offset
4734 /* A local symbol never has STO_SH5_ISA32, so we don't need
4735 datalabel processing here. Make sure this does not change
4737 if ((sym->st_other & STO_SH5_ISA32) != 0)
4738 ((*info->callbacks->reloc_dangerous)
4740 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4741 input_bfd, input_section, rel->r_offset));
4742 if (info->relocatable)
4744 /* This is a relocatable link. We don't have to change
4745 anything, unless the reloc is against a section symbol,
4746 in which case we have to adjust according to where the
4747 section symbol winds up in the output section. */
4748 sym = local_syms + r_symndx;
4749 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4751 if (! howto->partial_inplace)
4753 /* For relocations with the addend in the
4754 relocation, we need just to update the addend.
4755 All real relocs are of type partial_inplace; this
4756 code is mostly for completeness. */
4757 rel->r_addend += sec->output_offset + sym->st_value;
4762 /* Relocs of type partial_inplace need to pick up the
4763 contents in the contents and add the offset resulting
4764 from the changed location of the section symbol.
4765 Using _bfd_final_link_relocate (e.g. goto
4766 final_link_relocate) here would be wrong, because
4767 relocations marked pc_relative would get the current
4768 location subtracted, and we must only do that at the
4770 r = _bfd_relocate_contents (howto, input_bfd,
4773 contents + rel->r_offset);
4774 goto relocation_done;
4779 else if (! howto->partial_inplace)
4781 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
4782 addend = rel->r_addend;
4784 else if ((sec->flags & SEC_MERGE)
4785 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4789 if (howto->rightshift || howto->src_mask != 0xffffffff)
4791 (*_bfd_error_handler)
4792 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
4793 bfd_archive_filename (input_bfd),
4794 bfd_get_section_name (input_bfd, input_section),
4795 (long) rel->r_offset, howto->name);
4799 addend = bfd_get_32 (input_bfd, contents + rel->r_offset);
4802 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
4804 addend += msec->output_section->vma + msec->output_offset;
4805 bfd_put_32 (input_bfd, addend, contents + rel->r_offset);
4811 /* FIXME: Ought to make use of the RELOC_FOR_GLOBAL_SYMBOL macro. */
4813 /* Section symbol are never (?) placed in the hash table, so
4814 we can just ignore hash relocations when creating a
4815 relocatable object file. */
4816 if (info->relocatable)
4819 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4820 while (h->root.type == bfd_link_hash_indirect
4821 || h->root.type == bfd_link_hash_warning)
4823 #ifdef INCLUDE_SHMEDIA
4824 /* If the reference passes a symbol marked with
4825 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4827 seen_stt_datalabel |= h->type == STT_DATALABEL;
4829 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4831 if (h->root.type == bfd_link_hash_defined
4832 || h->root.type == bfd_link_hash_defweak)
4836 dyn = htab->root.dynamic_sections_created;
4837 sec = h->root.u.def.section;
4838 /* In these cases, we don't need the relocation value.
4839 We check specially because in some obscure cases
4840 sec->output_section will be NULL. */
4841 if (r_type == R_SH_GOTPC
4842 || r_type == R_SH_GOTPC_LOW16
4843 || r_type == R_SH_GOTPC_MEDLOW16
4844 || r_type == R_SH_GOTPC_MEDHI16
4845 || r_type == R_SH_GOTPC_HI16
4846 || ((r_type == R_SH_PLT32
4847 || r_type == R_SH_PLT_LOW16
4848 || r_type == R_SH_PLT_MEDLOW16
4849 || r_type == R_SH_PLT_MEDHI16
4850 || r_type == R_SH_PLT_HI16)
4851 && h->plt.offset != (bfd_vma) -1)
4852 || ((r_type == R_SH_GOT32
4853 || r_type == R_SH_GOT_LOW16
4854 || r_type == R_SH_GOT_MEDLOW16
4855 || r_type == R_SH_GOT_MEDHI16
4856 || r_type == R_SH_GOT_HI16)
4857 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
4859 || (! info->symbolic && h->dynindx != -1)
4860 || (h->elf_link_hash_flags
4861 & ELF_LINK_HASH_DEF_REGULAR) == 0))
4862 /* The cases above are those in which relocation is
4863 overwritten in the switch block below. The cases
4864 below are those in which we must defer relocation
4865 to run-time, because we can't resolve absolute
4866 addresses when creating a shared library. */
4868 && ((! info->symbolic && h->dynindx != -1)
4869 || (h->elf_link_hash_flags
4870 & ELF_LINK_HASH_DEF_REGULAR) == 0)
4871 && ((r_type == R_SH_DIR32
4872 && (h->elf_link_hash_flags
4873 & ELF_LINK_FORCED_LOCAL) == 0)
4874 || r_type == R_SH_REL32)
4875 && ((input_section->flags & SEC_ALLOC) != 0
4876 /* DWARF will emit R_SH_DIR32 relocations in its
4877 sections against symbols defined externally
4878 in shared libraries. We can't do anything
4880 || ((input_section->flags & SEC_DEBUGGING) != 0
4881 && (h->elf_link_hash_flags
4882 & ELF_LINK_HASH_DEF_DYNAMIC) != 0)))
4883 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4884 sections because such sections are not SEC_ALLOC and
4885 thus ld.so will not process them. */
4886 || (sec->output_section == NULL
4887 && ((input_section->flags & SEC_DEBUGGING) != 0
4888 && (h->elf_link_hash_flags
4889 & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
4890 || (sec->output_section == NULL
4891 && (sh_elf_hash_entry (h)->tls_type == GOT_TLS_IE
4892 || sh_elf_hash_entry (h)->tls_type == GOT_TLS_GD)))
4894 else if (sec->output_section == NULL)
4896 (*_bfd_error_handler)
4897 (_("%s: unresolvable relocation against symbol `%s' from %s section"),
4898 bfd_archive_filename (input_bfd), h->root.root.string,
4899 bfd_get_section_name (input_bfd, input_section));
4903 relocation = ((h->root.u.def.value
4904 + sec->output_section->vma
4905 + sec->output_offset)
4906 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4907 symbol value, unless we've seen
4908 STT_DATALABEL on the way to it. */
4909 | ((h->other & STO_SH5_ISA32) != 0
4910 && ! seen_stt_datalabel));
4912 else if (h->root.type == bfd_link_hash_undefweak)
4914 else if (info->unresolved_syms_in_objects == RM_IGNORE
4915 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
4919 if (! info->callbacks->undefined_symbol
4920 (info, h->root.root.string, input_bfd,
4921 input_section, rel->r_offset,
4922 (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
4923 || ELF_ST_VISIBILITY (h->other))))
4929 switch ((int) r_type)
4931 final_link_relocate:
4932 /* COFF relocs don't use the addend. The addend is used for
4933 R_SH_DIR32 to be compatible with other compilers. */
4934 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4935 contents, rel->r_offset,
4936 relocation, addend);
4940 goto final_link_relocate;
4945 /* If the reloc is against the start of this section, then
4946 the assembler has already taken care of it and the reloc
4947 is here only to assist in relaxing. If the reloc is not
4948 against the start of this section, then it's against an
4949 external symbol and we must deal with it ourselves. */
4950 if (input_section->output_section->vma + input_section->output_offset
4953 int disp = (relocation
4954 - input_section->output_section->vma
4955 - input_section->output_offset
4961 case R_SH_DIR8WPZ: mask = 1; break;
4962 case R_SH_DIR8WPL: mask = 3; break;
4963 default: mask = 0; break;
4967 ((*_bfd_error_handler)
4968 (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4969 bfd_archive_filename (input_section->owner),
4970 (unsigned long) rel->r_offset));
4971 bfd_set_error (bfd_error_bad_value);
4975 goto final_link_relocate;
4981 #ifdef INCLUDE_SHMEDIA
4982 if (shmedia_prepare_reloc (info, input_bfd, input_section,
4983 contents, rel, &relocation))
4984 goto final_link_relocate;
4986 bfd_set_error (bfd_error_bad_value);
4994 goto final_link_relocate;
5000 ((*_bfd_error_handler)
5001 (_("%s: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
5002 bfd_archive_filename (input_section->owner),
5003 (unsigned long) rel->r_offset, howto->name,
5004 (unsigned long)relocation));
5005 bfd_set_error (bfd_error_bad_value);
5008 goto final_link_relocate;
5015 ((*_bfd_error_handler)
5016 (_("%s: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
5017 bfd_archive_filename (input_section->owner),
5018 (unsigned long) rel->r_offset, howto->name,
5019 (unsigned long)relocation));
5020 bfd_set_error (bfd_error_bad_value);
5023 goto final_link_relocate;
5026 if ((signed int)relocation < -32
5027 || (signed int)relocation > 32)
5029 ((*_bfd_error_handler)
5030 (_("%s: 0x%lx: fatal: R_SH_PSHA relocation %d not in range -32..32"),
5031 bfd_archive_filename (input_section->owner),
5032 (unsigned long) rel->r_offset,
5033 (unsigned long)relocation));
5034 bfd_set_error (bfd_error_bad_value);
5037 goto final_link_relocate;
5040 if ((signed int)relocation < -16
5041 || (signed int)relocation > 16)
5043 ((*_bfd_error_handler)
5044 (_("%s: 0x%lx: fatal: R_SH_PSHL relocation %d not in range -32..32"),
5045 bfd_archive_filename (input_section->owner),
5046 (unsigned long) rel->r_offset,
5047 (unsigned long)relocation));
5048 bfd_set_error (bfd_error_bad_value);
5051 goto final_link_relocate;
5055 #ifdef INCLUDE_SHMEDIA
5056 case R_SH_IMM_LOW16_PCREL:
5057 case R_SH_IMM_MEDLOW16_PCREL:
5058 case R_SH_IMM_MEDHI16_PCREL:
5059 case R_SH_IMM_HI16_PCREL:
5063 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5064 || h->root.type != bfd_link_hash_undefweak)
5066 && (input_section->flags & SEC_ALLOC) != 0
5067 && (r_type == R_SH_DIR32
5068 || !SYMBOL_CALLS_LOCAL (info, h)))
5070 Elf_Internal_Rela outrel;
5072 bfd_boolean skip, relocate;
5074 /* When generating a shared object, these relocations
5075 are copied into the output file to be resolved at run
5082 name = (bfd_elf_string_from_elf_section
5084 elf_elfheader (input_bfd)->e_shstrndx,
5085 elf_section_data (input_section)->rel_hdr.sh_name));
5089 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5090 && strcmp (bfd_get_section_name (input_bfd,
5094 sreloc = bfd_get_section_by_name (dynobj, name);
5095 BFD_ASSERT (sreloc != NULL);
5102 _bfd_elf_section_offset (output_bfd, info, input_section,
5104 if (outrel.r_offset == (bfd_vma) -1)
5106 else if (outrel.r_offset == (bfd_vma) -2)
5107 skip = TRUE, relocate = TRUE;
5108 outrel.r_offset += (input_section->output_section->vma
5109 + input_section->output_offset);
5112 memset (&outrel, 0, sizeof outrel);
5113 else if (r_type == R_SH_REL32)
5115 BFD_ASSERT (h != NULL && h->dynindx != -1);
5116 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_REL32);
5118 = bfd_get_32 (input_bfd, contents + rel->r_offset);
5120 #ifdef INCLUDE_SHMEDIA
5121 else if (r_type == R_SH_IMM_LOW16_PCREL
5122 || r_type == R_SH_IMM_MEDLOW16_PCREL
5123 || r_type == R_SH_IMM_MEDHI16_PCREL
5124 || r_type == R_SH_IMM_HI16_PCREL)
5126 BFD_ASSERT (h != NULL && h->dynindx != -1);
5127 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
5128 outrel.r_addend = addend;
5133 /* h->dynindx may be -1 if this symbol was marked to
5136 || ((info->symbolic || h->dynindx == -1)
5137 && (h->elf_link_hash_flags
5138 & ELF_LINK_HASH_DEF_REGULAR) != 0))
5141 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
5143 = relocation + bfd_get_32 (input_bfd,
5144 contents + rel->r_offset);
5148 BFD_ASSERT (h->dynindx != -1);
5149 outrel.r_info = ELF32_R_INFO (h->dynindx, R_SH_DIR32);
5151 = relocation + bfd_get_32 (input_bfd,
5152 contents + rel->r_offset);
5156 loc = sreloc->contents;
5157 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5158 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5160 /* If this reloc is against an external symbol, we do
5161 not want to fiddle with the addend. Otherwise, we
5162 need to include the symbol value so that it becomes
5163 an addend for the dynamic reloc. */
5167 goto final_link_relocate;
5170 #ifdef INCLUDE_SHMEDIA
5171 case R_SH_GOTPLT_LOW16:
5172 case R_SH_GOTPLT_MEDLOW16:
5173 case R_SH_GOTPLT_MEDHI16:
5174 case R_SH_GOTPLT_HI16:
5175 case R_SH_GOTPLT10BY4:
5176 case R_SH_GOTPLT10BY8:
5178 /* Relocation is to the entry for this symbol in the
5179 procedure linkage table. */
5182 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
5186 || h->plt.offset == (bfd_vma) -1
5187 || h->got.offset != (bfd_vma) -1)
5190 /* Relocation is to the entry for this symbol in the global
5191 offset table extension for the procedure linkage table. */
5193 BFD_ASSERT (sgotplt != NULL);
5194 relocation = (sgotplt->output_offset
5195 + ((h->plt.offset / elf_sh_sizeof_plt (info)
5199 relocation -= GOT_BIAS;
5202 goto final_link_relocate;
5206 #ifdef INCLUDE_SHMEDIA
5207 case R_SH_GOT_LOW16:
5208 case R_SH_GOT_MEDLOW16:
5209 case R_SH_GOT_MEDHI16:
5214 /* Relocation is to the entry for this symbol in the global
5217 BFD_ASSERT (sgot != NULL);
5223 off = h->got.offset;
5224 #ifdef INCLUDE_SHMEDIA
5225 if (seen_stt_datalabel)
5227 struct elf_sh_link_hash_entry *hsh;
5229 hsh = (struct elf_sh_link_hash_entry *)h;
5230 off = hsh->datalabel_got.offset;
5233 BFD_ASSERT (off != (bfd_vma) -1);
5235 dyn = htab->root.dynamic_sections_created;
5236 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5238 && SYMBOL_REFERENCES_LOCAL (info, h))
5239 || (ELF_ST_VISIBILITY (h->other)
5240 && h->root.type == bfd_link_hash_undefweak))
5242 /* This is actually a static link, or it is a
5243 -Bsymbolic link and the symbol is defined
5244 locally, or the symbol was forced to be local
5245 because of a version file. We must initialize
5246 this entry in the global offset table. Since the
5247 offset must always be a multiple of 4, we use the
5248 least significant bit to record whether we have
5249 initialized it already.
5251 When doing a dynamic link, we create a .rela.got
5252 relocation entry to initialize the value. This
5253 is done in the finish_dynamic_symbol routine. */
5258 bfd_put_32 (output_bfd, relocation,
5259 sgot->contents + off);
5260 #ifdef INCLUDE_SHMEDIA
5261 if (seen_stt_datalabel)
5263 struct elf_sh_link_hash_entry *hsh;
5265 hsh = (struct elf_sh_link_hash_entry *)h;
5266 hsh->datalabel_got.offset |= 1;
5274 relocation = sgot->output_offset + off;
5278 #ifdef INCLUDE_SHMEDIA
5281 BFD_ASSERT (local_got_offsets != NULL
5282 && (local_got_offsets[symtab_hdr->sh_info
5286 off = local_got_offsets[symtab_hdr->sh_info
5292 BFD_ASSERT (local_got_offsets != NULL
5293 && local_got_offsets[r_symndx] != (bfd_vma) -1);
5295 off = local_got_offsets[r_symndx];
5296 #ifdef INCLUDE_SHMEDIA
5300 /* The offset must always be a multiple of 4. We use
5301 the least significant bit to record whether we have
5302 already generated the necessary reloc. */
5307 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
5311 Elf_Internal_Rela outrel;
5314 if (srelgot == NULL)
5316 srelgot = bfd_get_section_by_name (dynobj,
5318 BFD_ASSERT (srelgot != NULL);
5321 outrel.r_offset = (sgot->output_section->vma
5322 + sgot->output_offset
5324 outrel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
5325 outrel.r_addend = relocation;
5326 loc = srelgot->contents;
5327 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5328 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5331 #ifdef INCLUDE_SHMEDIA
5333 local_got_offsets[symtab_hdr->sh_info + r_symndx] |= 1;
5336 local_got_offsets[r_symndx] |= 1;
5339 relocation = sgot->output_offset + off;
5343 relocation -= GOT_BIAS;
5346 goto final_link_relocate;
5349 #ifdef INCLUDE_SHMEDIA
5350 case R_SH_GOTOFF_LOW16:
5351 case R_SH_GOTOFF_MEDLOW16:
5352 case R_SH_GOTOFF_MEDHI16:
5353 case R_SH_GOTOFF_HI16:
5355 /* Relocation is relative to the start of the global offset
5358 BFD_ASSERT (sgot != NULL);
5360 /* Note that sgot->output_offset is not involved in this
5361 calculation. We always want the start of .got. If we
5362 defined _GLOBAL_OFFSET_TABLE in a different way, as is
5363 permitted by the ABI, we might have to change this
5365 relocation -= sgot->output_section->vma;
5368 relocation -= GOT_BIAS;
5371 addend = rel->r_addend;
5373 goto final_link_relocate;
5376 #ifdef INCLUDE_SHMEDIA
5377 case R_SH_GOTPC_LOW16:
5378 case R_SH_GOTPC_MEDLOW16:
5379 case R_SH_GOTPC_MEDHI16:
5380 case R_SH_GOTPC_HI16:
5382 /* Use global offset table as symbol value. */
5384 BFD_ASSERT (sgot != NULL);
5385 relocation = sgot->output_section->vma;
5388 relocation += GOT_BIAS;
5391 addend = rel->r_addend;
5393 goto final_link_relocate;
5396 #ifdef INCLUDE_SHMEDIA
5397 case R_SH_PLT_LOW16:
5398 case R_SH_PLT_MEDLOW16:
5399 case R_SH_PLT_MEDHI16:
5402 /* Relocation is to the entry for this symbol in the
5403 procedure linkage table. */
5405 /* Resolve a PLT reloc against a local symbol directly,
5406 without using the procedure linkage table. */
5408 goto final_link_relocate;
5410 if (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
5411 goto final_link_relocate;
5413 if (h->plt.offset == (bfd_vma) -1)
5415 /* We didn't make a PLT entry for this symbol. This
5416 happens when statically linking PIC code, or when
5417 using -Bsymbolic. */
5418 goto final_link_relocate;
5421 BFD_ASSERT (splt != NULL);
5422 relocation = (splt->output_section->vma
5423 + splt->output_offset
5426 #ifdef INCLUDE_SHMEDIA
5430 addend = rel->r_addend;
5432 goto final_link_relocate;
5434 case R_SH_LOOP_START:
5436 static bfd_vma start, end;
5438 start = (relocation + rel->r_addend
5439 - (sec->output_section->vma + sec->output_offset));
5440 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
5441 rel->r_offset, sec, start, end);
5445 end = (relocation + rel->r_addend
5446 - (sec->output_section->vma + sec->output_offset));
5447 r = sh_elf_reloc_loop (r_type, input_bfd, input_section, contents,
5448 rel->r_offset, sec, start, end);
5452 case R_SH_TLS_GD_32:
5453 case R_SH_TLS_IE_32:
5454 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
5455 tls_type = GOT_UNKNOWN;
5456 if (h == NULL && local_got_offsets)
5457 tls_type = sh_elf_local_got_tls_type (input_bfd) [r_symndx];
5460 tls_type = sh_elf_hash_entry (h)->tls_type;
5462 && (h->dynindx == -1
5463 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
5464 r_type = R_SH_TLS_LE_32;
5467 if (r_type == R_SH_TLS_GD_32 && tls_type == GOT_TLS_IE)
5468 r_type = R_SH_TLS_IE_32;
5470 if (r_type == R_SH_TLS_LE_32)
5473 unsigned short insn;
5475 if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_GD_32)
5477 /* GD->LE transition:
5478 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5479 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5480 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5482 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5484 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
5486 offset = rel->r_offset;
5487 BFD_ASSERT (offset >= 16);
5488 /* Size of GD instructions is 16 or 18. */
5490 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5491 if ((insn & 0xff00) == 0xc700)
5493 BFD_ASSERT (offset >= 2);
5495 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5498 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5499 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5500 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5501 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5502 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5503 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5504 BFD_ASSERT (insn == 0x310c);
5505 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5506 BFD_ASSERT (insn == 0x410b);
5507 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5508 BFD_ASSERT (insn == 0x34cc);
5510 bfd_put_16 (output_bfd, 0x0012, contents + offset + 2);
5511 bfd_put_16 (output_bfd, 0x304c, contents + offset + 4);
5512 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5513 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5514 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5520 /* IE->LE transition:
5521 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5522 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5524 mov.l .Ln,rM; stc gbr,rN; nop; ...;
5527 offset = rel->r_offset;
5528 BFD_ASSERT (offset >= 16);
5529 /* Size of IE instructions is 10 or 12. */
5531 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5532 if ((insn & 0xf0ff) == 0x0012)
5534 BFD_ASSERT (offset >= 2);
5536 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5539 BFD_ASSERT ((insn & 0xff00) == 0xd000);
5540 index = insn & 0x00ff;
5541 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5542 BFD_ASSERT ((insn & 0xf0ff) == 0x0012);
5543 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5544 BFD_ASSERT ((insn & 0xf0ff) == 0x00ce);
5545 insn = 0xd000 | (insn & 0x0f00) | index;
5546 bfd_put_16 (output_bfd, insn, contents + offset + 0);
5547 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5550 bfd_put_32 (output_bfd, tpoff (info, relocation),
5551 contents + rel->r_offset);
5560 off = h->got.offset;
5563 if (local_got_offsets == NULL)
5566 off = local_got_offsets[r_symndx];
5569 /* Relocate R_SH_TLS_IE_32 directly when statically linking. */
5570 if (r_type == R_SH_TLS_IE_32
5571 && ! htab->root.dynamic_sections_created)
5574 bfd_put_32 (output_bfd, tpoff (info, relocation),
5575 sgot->contents + off);
5576 bfd_put_32 (output_bfd, sgot->output_offset + off,
5577 contents + rel->r_offset);
5585 Elf_Internal_Rela outrel;
5589 if (srelgot == NULL)
5591 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
5592 BFD_ASSERT (srelgot != NULL);
5595 outrel.r_offset = (sgot->output_section->vma
5596 + sgot->output_offset + off);
5598 if (h == NULL || h->dynindx == -1)
5603 dr_type = (r_type == R_SH_TLS_GD_32 ? R_SH_TLS_DTPMOD32 :
5605 if (dr_type == R_SH_TLS_TPOFF32 && indx == 0)
5606 outrel.r_addend = relocation - dtpoff_base (info);
5608 outrel.r_addend = 0;
5609 outrel.r_info = ELF32_R_INFO (indx, dr_type);
5610 loc = srelgot->contents;
5611 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5612 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5614 if (r_type == R_SH_TLS_GD_32)
5618 bfd_put_32 (output_bfd,
5619 relocation - dtpoff_base (info),
5620 sgot->contents + off + 4);
5624 outrel.r_info = ELF32_R_INFO (indx,
5626 outrel.r_offset += 4;
5627 outrel.r_addend = 0;
5628 srelgot->reloc_count++;
5629 loc += sizeof (Elf32_External_Rela);
5630 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5637 local_got_offsets[r_symndx] |= 1;
5640 if (off >= (bfd_vma) -2)
5643 if (r_type == (int) ELF32_R_TYPE (rel->r_info))
5644 relocation = sgot->output_offset + off;
5648 unsigned short insn;
5650 /* GD->IE transition:
5651 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5652 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5653 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5655 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5656 nop; nop; bra 3f; nop; .align 2;
5657 1: .long x@TPOFF; 2:...; 3:. */
5659 offset = rel->r_offset;
5660 BFD_ASSERT (offset >= 16);
5661 /* Size of GD instructions is 16 or 18. */
5663 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5664 if ((insn & 0xff00) == 0xc700)
5666 BFD_ASSERT (offset >= 2);
5668 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5671 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5673 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
5674 bfd_put_16 (output_bfd, insn & 0xf0ff, contents + offset);
5676 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5677 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5678 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5679 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5680 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5681 BFD_ASSERT (insn == 0x310c);
5682 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5683 BFD_ASSERT (insn == 0x410b);
5684 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5685 BFD_ASSERT (insn == 0x34cc);
5687 bfd_put_16 (output_bfd, 0x0412, contents + offset + 2);
5688 bfd_put_16 (output_bfd, 0x00ce, contents + offset + 4);
5689 bfd_put_16 (output_bfd, 0x304c, contents + offset + 6);
5690 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5691 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5693 bfd_put_32 (output_bfd, sgot->output_offset + off,
5694 contents + rel->r_offset);
5699 addend = rel->r_addend;
5701 goto final_link_relocate;
5703 case R_SH_TLS_LD_32:
5707 unsigned short insn;
5709 /* LD->LE transition:
5710 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5711 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5712 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5714 stc gbr,r0; nop; nop; nop;
5715 nop; nop; bra 3f; ...; 3:. */
5717 offset = rel->r_offset;
5718 BFD_ASSERT (offset >= 16);
5719 /* Size of LD instructions is 16 or 18. */
5721 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5722 if ((insn & 0xff00) == 0xc700)
5724 BFD_ASSERT (offset >= 2);
5726 insn = bfd_get_16 (input_bfd, contents + offset + 0);
5729 BFD_ASSERT ((insn & 0xff00) == 0xd400);
5730 insn = bfd_get_16 (input_bfd, contents + offset + 2);
5731 BFD_ASSERT ((insn & 0xff00) == 0xc700);
5732 insn = bfd_get_16 (input_bfd, contents + offset + 4);
5733 BFD_ASSERT ((insn & 0xff00) == 0xd100);
5734 insn = bfd_get_16 (input_bfd, contents + offset + 6);
5735 BFD_ASSERT (insn == 0x310c);
5736 insn = bfd_get_16 (input_bfd, contents + offset + 8);
5737 BFD_ASSERT (insn == 0x410b);
5738 insn = bfd_get_16 (input_bfd, contents + offset + 10);
5739 BFD_ASSERT (insn == 0x34cc);
5741 bfd_put_16 (output_bfd, 0x0012, contents + offset + 0);
5742 bfd_put_16 (output_bfd, 0x0009, contents + offset + 2);
5743 bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
5744 bfd_put_16 (output_bfd, 0x0009, contents + offset + 6);
5745 bfd_put_16 (output_bfd, 0x0009, contents + offset + 8);
5746 bfd_put_16 (output_bfd, 0x0009, contents + offset + 10);
5755 off = htab->tls_ldm_got.offset;
5760 Elf_Internal_Rela outrel;
5763 srelgot = htab->srelgot;
5764 if (srelgot == NULL)
5767 outrel.r_offset = (sgot->output_section->vma
5768 + sgot->output_offset + off);
5769 outrel.r_addend = 0;
5770 outrel.r_info = ELF32_R_INFO (0, R_SH_TLS_DTPMOD32);
5771 loc = srelgot->contents;
5772 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
5773 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5774 htab->tls_ldm_got.offset |= 1;
5777 relocation = sgot->output_offset + off;
5778 addend = rel->r_addend;
5780 goto final_link_relocate;
5782 case R_SH_TLS_LDO_32:
5784 relocation = tpoff (info, relocation);
5786 relocation -= dtpoff_base (info);
5788 addend = rel->r_addend;
5789 goto final_link_relocate;
5791 case R_SH_TLS_LE_32:
5794 Elf_Internal_Rela outrel;
5799 relocation = tpoff (info, relocation);
5800 addend = rel->r_addend;
5801 goto final_link_relocate;
5808 name = (bfd_elf_string_from_elf_section
5810 elf_elfheader (input_bfd)->e_shstrndx,
5811 elf_section_data (input_section)->rel_hdr.sh_name));
5815 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
5816 && strcmp (bfd_get_section_name (input_bfd,
5820 sreloc = bfd_get_section_by_name (dynobj, name);
5821 BFD_ASSERT (sreloc != NULL);
5824 if (h == NULL || h->dynindx == -1)
5829 outrel.r_offset = (input_section->output_section->vma
5830 + input_section->output_offset
5832 outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
5834 outrel.r_addend = relocation - dtpoff_base (info);
5836 outrel.r_addend = 0;
5838 loc = sreloc->contents;
5839 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5840 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5846 if (r != bfd_reloc_ok)
5851 case bfd_reloc_outofrange:
5853 case bfd_reloc_overflow:
5858 name = h->root.root.string;
5861 name = (bfd_elf_string_from_elf_section
5862 (input_bfd, symtab_hdr->sh_link, sym->st_name));
5866 name = bfd_section_name (input_bfd, sec);
5868 if (! ((*info->callbacks->reloc_overflow)
5869 (info, name, howto->name, (bfd_vma) 0,
5870 input_bfd, input_section, rel->r_offset)))
5881 /* This is a version of bfd_generic_get_relocated_section_contents
5882 which uses sh_elf_relocate_section. */
5885 sh_elf_get_relocated_section_contents (bfd *output_bfd,
5886 struct bfd_link_info *link_info,
5887 struct bfd_link_order *link_order,
5889 bfd_boolean relocatable,
5892 Elf_Internal_Shdr *symtab_hdr;
5893 asection *input_section = link_order->u.indirect.section;
5894 bfd *input_bfd = input_section->owner;
5895 asection **sections = NULL;
5896 Elf_Internal_Rela *internal_relocs = NULL;
5897 Elf_Internal_Sym *isymbuf = NULL;
5899 /* We only need to handle the case of relaxing, or of having a
5900 particular set of section contents, specially. */
5902 || elf_section_data (input_section)->this_hdr.contents == NULL)
5903 return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
5908 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5910 memcpy (data, elf_section_data (input_section)->this_hdr.contents,
5911 (size_t) input_section->size);
5913 if ((input_section->flags & SEC_RELOC) != 0
5914 && input_section->reloc_count > 0)
5917 Elf_Internal_Sym *isym, *isymend;
5920 internal_relocs = (_bfd_elf_link_read_relocs
5921 (input_bfd, input_section, NULL,
5922 (Elf_Internal_Rela *) NULL, FALSE));
5923 if (internal_relocs == NULL)
5926 if (symtab_hdr->sh_info != 0)
5928 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
5929 if (isymbuf == NULL)
5930 isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
5931 symtab_hdr->sh_info, 0,
5933 if (isymbuf == NULL)
5937 amt = symtab_hdr->sh_info;
5938 amt *= sizeof (asection *);
5939 sections = (asection **) bfd_malloc (amt);
5940 if (sections == NULL && amt != 0)
5943 isymend = isymbuf + symtab_hdr->sh_info;
5944 for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp)
5948 if (isym->st_shndx == SHN_UNDEF)
5949 isec = bfd_und_section_ptr;
5950 else if (isym->st_shndx == SHN_ABS)
5951 isec = bfd_abs_section_ptr;
5952 else if (isym->st_shndx == SHN_COMMON)
5953 isec = bfd_com_section_ptr;
5955 isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx);
5960 if (! sh_elf_relocate_section (output_bfd, link_info, input_bfd,
5961 input_section, data, internal_relocs,
5965 if (sections != NULL)
5968 && symtab_hdr->contents != (unsigned char *) isymbuf)
5970 if (elf_section_data (input_section)->relocs != internal_relocs)
5971 free (internal_relocs);
5977 if (sections != NULL)
5980 && symtab_hdr->contents != (unsigned char *) isymbuf)
5982 if (internal_relocs != NULL
5983 && elf_section_data (input_section)->relocs != internal_relocs)
5984 free (internal_relocs);
5988 /* Return the base VMA address which should be subtracted from real addresses
5989 when resolving @dtpoff relocation.
5990 This is PT_TLS segment p_vaddr. */
5993 dtpoff_base (struct bfd_link_info *info)
5995 /* If tls_sec is NULL, we should have signalled an error already. */
5996 if (elf_hash_table (info)->tls_sec == NULL)
5998 return elf_hash_table (info)->tls_sec->vma;
6001 /* Return the relocation value for R_SH_TLS_TPOFF32.. */
6004 tpoff (struct bfd_link_info *info, bfd_vma address)
6006 /* If tls_sec is NULL, we should have signalled an error already. */
6007 if (elf_hash_table (info)->tls_sec == NULL)
6009 /* SH TLS ABI is variant I and static TLS block start just after tcbhead
6010 structure which has 2 pointer fields. */
6011 return address - elf_hash_table (info)->tls_sec->vma + 8;
6015 sh_elf_gc_mark_hook (asection *sec,
6016 struct bfd_link_info *info ATTRIBUTE_UNUSED,
6017 Elf_Internal_Rela *rel, struct elf_link_hash_entry *h,
6018 Elf_Internal_Sym *sym)
6022 switch (ELF32_R_TYPE (rel->r_info))
6024 case R_SH_GNU_VTINHERIT:
6025 case R_SH_GNU_VTENTRY:
6029 #ifdef INCLUDE_SHMEDIA
6030 while (h->root.type == bfd_link_hash_indirect
6031 && h->root.u.i.link)
6032 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6034 switch (h->root.type)
6036 case bfd_link_hash_defined:
6037 case bfd_link_hash_defweak:
6038 return h->root.u.def.section;
6040 case bfd_link_hash_common:
6041 return h->root.u.c.p->section;
6049 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
6054 /* Update the got entry reference counts for the section being removed. */
6057 sh_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
6058 asection *sec, const Elf_Internal_Rela *relocs)
6060 Elf_Internal_Shdr *symtab_hdr;
6061 struct elf_link_hash_entry **sym_hashes;
6062 bfd_signed_vma *local_got_refcounts;
6063 const Elf_Internal_Rela *rel, *relend;
6065 elf_section_data (sec)->local_dynrel = NULL;
6067 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6068 sym_hashes = elf_sym_hashes (abfd);
6069 local_got_refcounts = elf_local_got_refcounts (abfd);
6071 relend = relocs + sec->reloc_count;
6072 for (rel = relocs; rel < relend; rel++)
6074 unsigned long r_symndx;
6075 unsigned int r_type;
6076 struct elf_link_hash_entry *h = NULL;
6077 #ifdef INCLUDE_SHMEDIA
6078 int seen_stt_datalabel = 0;
6081 r_symndx = ELF32_R_SYM (rel->r_info);
6082 if (r_symndx >= symtab_hdr->sh_info)
6084 struct elf_sh_link_hash_entry *eh;
6085 struct elf_sh_dyn_relocs **pp;
6086 struct elf_sh_dyn_relocs *p;
6088 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6089 #ifdef INCLUDE_SHMEDIA
6090 while (h->root.type == bfd_link_hash_indirect
6091 || h->root.type == bfd_link_hash_warning)
6093 seen_stt_datalabel |= h->type == STT_DATALABEL;
6094 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6097 eh = (struct elf_sh_link_hash_entry *) h;
6098 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
6101 /* Everything must go for SEC. */
6107 r_type = ELF32_R_TYPE (rel->r_info);
6108 switch (sh_elf_optimized_tls_reloc (info, r_type, h != NULL))
6110 case R_SH_TLS_LD_32:
6111 if (sh_elf_hash_table (info)->tls_ldm_got.refcount > 0)
6112 sh_elf_hash_table (info)->tls_ldm_got.refcount -= 1;
6118 #ifdef INCLUDE_SHMEDIA
6119 case R_SH_GOT_LOW16:
6120 case R_SH_GOT_MEDLOW16:
6121 case R_SH_GOT_MEDHI16:
6125 case R_SH_GOTOFF_LOW16:
6126 case R_SH_GOTOFF_MEDLOW16:
6127 case R_SH_GOTOFF_MEDHI16:
6128 case R_SH_GOTOFF_HI16:
6129 case R_SH_GOTPC_LOW16:
6130 case R_SH_GOTPC_MEDLOW16:
6131 case R_SH_GOTPC_MEDHI16:
6132 case R_SH_GOTPC_HI16:
6134 case R_SH_TLS_GD_32:
6135 case R_SH_TLS_IE_32:
6138 #ifdef INCLUDE_SHMEDIA
6139 if (seen_stt_datalabel)
6141 struct elf_sh_link_hash_entry *eh;
6142 eh = (struct elf_sh_link_hash_entry *) h;
6143 if (eh->datalabel_got.refcount > 0)
6144 eh->datalabel_got.refcount -= 1;
6148 if (h->got.refcount > 0)
6149 h->got.refcount -= 1;
6151 else if (local_got_refcounts != NULL)
6153 #ifdef INCLUDE_SHMEDIA
6154 if (rel->r_addend & 1)
6156 if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
6157 local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
6161 if (local_got_refcounts[r_symndx] > 0)
6162 local_got_refcounts[r_symndx] -= 1;
6173 #ifdef INCLUDE_SHMEDIA
6174 case R_SH_PLT_LOW16:
6175 case R_SH_PLT_MEDLOW16:
6176 case R_SH_PLT_MEDHI16:
6181 if (h->plt.refcount > 0)
6182 h->plt.refcount -= 1;
6187 #ifdef INCLUDE_SHMEDIA
6188 case R_SH_GOTPLT_LOW16:
6189 case R_SH_GOTPLT_MEDLOW16:
6190 case R_SH_GOTPLT_MEDHI16:
6191 case R_SH_GOTPLT_HI16:
6192 case R_SH_GOTPLT10BY4:
6193 case R_SH_GOTPLT10BY8:
6197 struct elf_sh_link_hash_entry *eh;
6198 eh = (struct elf_sh_link_hash_entry *) h;
6199 if (eh->gotplt_refcount > 0)
6201 eh->gotplt_refcount -= 1;
6202 if (h->plt.refcount > 0)
6203 h->plt.refcount -= 1;
6205 #ifdef INCLUDE_SHMEDIA
6206 else if (seen_stt_datalabel)
6208 if (eh->datalabel_got.refcount > 0)
6209 eh->datalabel_got.refcount -= 1;
6212 else if (h->got.refcount > 0)
6213 h->got.refcount -= 1;
6215 else if (local_got_refcounts != NULL)
6217 #ifdef INCLUDE_SHMEDIA
6218 if (rel->r_addend & 1)
6220 if (local_got_refcounts[symtab_hdr->sh_info + r_symndx] > 0)
6221 local_got_refcounts[symtab_hdr->sh_info + r_symndx] -= 1;
6225 if (local_got_refcounts[r_symndx] > 0)
6226 local_got_refcounts[r_symndx] -= 1;
6238 /* Copy the extra info we tack onto an elf_link_hash_entry. */
6241 sh_elf_copy_indirect_symbol (const struct elf_backend_data *bed,
6242 struct elf_link_hash_entry *dir,
6243 struct elf_link_hash_entry *ind)
6245 struct elf_sh_link_hash_entry *edir, *eind;
6246 #ifdef INCLUDE_SHMEDIA
6250 edir = (struct elf_sh_link_hash_entry *) dir;
6251 eind = (struct elf_sh_link_hash_entry *) ind;
6253 if (eind->dyn_relocs != NULL)
6255 if (edir->dyn_relocs != NULL)
6257 struct elf_sh_dyn_relocs **pp;
6258 struct elf_sh_dyn_relocs *p;
6260 BFD_ASSERT (ind->root.type != bfd_link_hash_indirect);
6262 /* Add reloc counts against the weak sym to the strong sym
6263 list. Merge any entries against the same section. */
6264 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
6266 struct elf_sh_dyn_relocs *q;
6268 for (q = edir->dyn_relocs; q != NULL; q = q->next)
6269 if (q->sec == p->sec)
6271 q->pc_count += p->pc_count;
6272 q->count += p->count;
6279 *pp = edir->dyn_relocs;
6282 edir->dyn_relocs = eind->dyn_relocs;
6283 eind->dyn_relocs = NULL;
6285 edir->gotplt_refcount = eind->gotplt_refcount;
6286 eind->gotplt_refcount = 0;
6287 #ifdef INCLUDE_SHMEDIA
6288 tmp = edir->datalabel_got.refcount;
6291 edir->datalabel_got.refcount = eind->datalabel_got.refcount;
6292 eind->datalabel_got.refcount = tmp;
6295 BFD_ASSERT (eind->datalabel_got.refcount < 1);
6298 if (ind->root.type == bfd_link_hash_indirect
6299 && dir->got.refcount <= 0)
6301 edir->tls_type = eind->tls_type;
6302 eind->tls_type = GOT_UNKNOWN;
6305 if (ind->root.type != bfd_link_hash_indirect
6306 && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
6307 /* If called to transfer flags for a weakdef during processing
6308 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
6309 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
6310 dir->elf_link_hash_flags |=
6311 (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC
6312 | ELF_LINK_HASH_REF_REGULAR
6313 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
6314 | ELF_LINK_HASH_NEEDS_PLT));
6316 _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
6320 sh_elf_optimized_tls_reloc (struct bfd_link_info *info, int r_type,
6328 case R_SH_TLS_GD_32:
6329 case R_SH_TLS_IE_32:
6331 return R_SH_TLS_LE_32;
6332 return R_SH_TLS_IE_32;
6333 case R_SH_TLS_LD_32:
6334 return R_SH_TLS_LE_32;
6340 /* Look through the relocs for a section during the first phase.
6341 Since we don't do .gots or .plts, we just need to consider the
6342 virtual table relocs for gc. */
6345 sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
6346 const Elf_Internal_Rela *relocs)
6348 Elf_Internal_Shdr *symtab_hdr;
6349 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
6350 struct elf_sh_link_hash_table *htab;
6351 const Elf_Internal_Rela *rel;
6352 const Elf_Internal_Rela *rel_end;
6353 bfd_vma *local_got_offsets;
6357 unsigned int r_type;
6358 int tls_type, old_tls_type;
6364 if (info->relocatable)
6367 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6368 sym_hashes = elf_sym_hashes (abfd);
6369 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);
6370 if (!elf_bad_symtab (abfd))
6371 sym_hashes_end -= symtab_hdr->sh_info;
6373 htab = sh_elf_hash_table (info);
6374 local_got_offsets = elf_local_got_offsets (abfd);
6376 rel_end = relocs + sec->reloc_count;
6377 for (rel = relocs; rel < rel_end; rel++)
6379 struct elf_link_hash_entry *h;
6380 unsigned long r_symndx;
6381 #ifdef INCLUDE_SHMEDIA
6382 int seen_stt_datalabel = 0;
6385 r_symndx = ELF32_R_SYM (rel->r_info);
6386 r_type = ELF32_R_TYPE (rel->r_info);
6388 if (r_symndx < symtab_hdr->sh_info)
6392 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6393 #ifdef INCLUDE_SHMEDIA
6394 while (h->root.type == bfd_link_hash_indirect
6395 || h->root.type == bfd_link_hash_warning)
6397 seen_stt_datalabel |= h->type == STT_DATALABEL;
6398 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6403 r_type = sh_elf_optimized_tls_reloc (info, r_type, h == NULL);
6405 && r_type == R_SH_TLS_IE_32
6407 && h->root.type != bfd_link_hash_undefined
6408 && h->root.type != bfd_link_hash_undefweak
6409 && (h->dynindx == -1
6410 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
6411 r_type = R_SH_TLS_LE_32;
6413 /* Some relocs require a global offset table. */
6414 if (htab->sgot == NULL)
6422 #ifdef INCLUDE_SHMEDIA
6423 case R_SH_GOTPLT_LOW16:
6424 case R_SH_GOTPLT_MEDLOW16:
6425 case R_SH_GOTPLT_MEDHI16:
6426 case R_SH_GOTPLT_HI16:
6427 case R_SH_GOTPLT10BY4:
6428 case R_SH_GOTPLT10BY8:
6429 case R_SH_GOT_LOW16:
6430 case R_SH_GOT_MEDLOW16:
6431 case R_SH_GOT_MEDHI16:
6435 case R_SH_GOTOFF_LOW16:
6436 case R_SH_GOTOFF_MEDLOW16:
6437 case R_SH_GOTOFF_MEDHI16:
6438 case R_SH_GOTOFF_HI16:
6439 case R_SH_GOTPC_LOW16:
6440 case R_SH_GOTPC_MEDLOW16:
6441 case R_SH_GOTPC_MEDHI16:
6442 case R_SH_GOTPC_HI16:
6444 case R_SH_TLS_GD_32:
6445 case R_SH_TLS_LD_32:
6446 case R_SH_TLS_IE_32:
6447 if (htab->sgot == NULL)
6449 if (htab->root.dynobj == NULL)
6450 htab->root.dynobj = abfd;
6451 if (!create_got_section (htab->root.dynobj, info))
6463 /* This relocation describes the C++ object vtable hierarchy.
6464 Reconstruct it for later use during GC. */
6465 case R_SH_GNU_VTINHERIT:
6466 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
6470 /* This relocation describes which C++ vtable entries are actually
6471 used. Record for later use during GC. */
6472 case R_SH_GNU_VTENTRY:
6473 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
6477 case R_SH_TLS_IE_32:
6479 info->flags |= DF_STATIC_TLS;
6483 case R_SH_TLS_GD_32:
6485 #ifdef INCLUDE_SHMEDIA
6486 case R_SH_GOT_LOW16:
6487 case R_SH_GOT_MEDLOW16:
6488 case R_SH_GOT_MEDHI16:
6496 tls_type = GOT_NORMAL;
6498 case R_SH_TLS_GD_32:
6499 tls_type = GOT_TLS_GD;
6501 case R_SH_TLS_IE_32:
6502 tls_type = GOT_TLS_IE;
6508 #ifdef INCLUDE_SHMEDIA
6509 if (seen_stt_datalabel)
6511 struct elf_sh_link_hash_entry *eh
6512 = (struct elf_sh_link_hash_entry *) h;
6514 eh->datalabel_got.refcount += 1;
6518 h->got.refcount += 1;
6519 old_tls_type = sh_elf_hash_entry (h)->tls_type;
6523 bfd_signed_vma *local_got_refcounts;
6525 /* This is a global offset table entry for a local
6527 local_got_refcounts = elf_local_got_refcounts (abfd);
6528 if (local_got_refcounts == NULL)
6532 size = symtab_hdr->sh_info;
6533 size *= sizeof (bfd_signed_vma);
6534 #ifdef INCLUDE_SHMEDIA
6535 /* Reserve space for both the datalabel and
6536 codelabel local GOT offsets. */
6539 size += symtab_hdr->sh_info;
6540 local_got_refcounts = ((bfd_signed_vma *)
6541 bfd_zalloc (abfd, size));
6542 if (local_got_refcounts == NULL)
6544 elf_local_got_refcounts (abfd) = local_got_refcounts;
6545 #ifdef INCLUDE_SHMEDIA
6546 /* Take care of both the datalabel and codelabel local
6548 sh_elf_local_got_tls_type (abfd)
6549 = (char *) (local_got_refcounts + 2 * symtab_hdr->sh_info);
6551 sh_elf_local_got_tls_type (abfd)
6552 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
6555 #ifdef INCLUDE_SHMEDIA
6556 if (rel->r_addend & 1)
6557 local_got_refcounts[symtab_hdr->sh_info + r_symndx] += 1;
6560 local_got_refcounts[r_symndx] += 1;
6561 old_tls_type = sh_elf_local_got_tls_type (abfd) [r_symndx];
6564 /* If a TLS symbol is accessed using IE at least once,
6565 there is no point to use dynamic model for it. */
6566 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
6567 && (old_tls_type != GOT_TLS_GD || tls_type != GOT_TLS_IE))
6569 if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
6570 tls_type = GOT_TLS_IE;
6573 (*_bfd_error_handler)
6574 (_("%s: `%s' accessed both as normal and thread local symbol"),
6575 bfd_archive_filename (abfd), h->root.root.string);
6580 if (old_tls_type != tls_type)
6583 sh_elf_hash_entry (h)->tls_type = tls_type;
6585 sh_elf_local_got_tls_type (abfd) [r_symndx] = tls_type;
6590 case R_SH_TLS_LD_32:
6591 sh_elf_hash_table(info)->tls_ldm_got.refcount += 1;
6595 #ifdef INCLUDE_SHMEDIA
6596 case R_SH_GOTPLT_LOW16:
6597 case R_SH_GOTPLT_MEDLOW16:
6598 case R_SH_GOTPLT_MEDHI16:
6599 case R_SH_GOTPLT_HI16:
6600 case R_SH_GOTPLT10BY4:
6601 case R_SH_GOTPLT10BY8:
6603 /* If this is a local symbol, we resolve it directly without
6604 creating a procedure linkage table entry. */
6607 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
6610 || h->dynindx == -1)
6613 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
6614 h->plt.refcount += 1;
6615 ((struct elf_sh_link_hash_entry *) h)->gotplt_refcount += 1;
6620 #ifdef INCLUDE_SHMEDIA
6621 case R_SH_PLT_LOW16:
6622 case R_SH_PLT_MEDLOW16:
6623 case R_SH_PLT_MEDHI16:
6626 /* This symbol requires a procedure linkage table entry. We
6627 actually build the entry in adjust_dynamic_symbol,
6628 because this might be a case of linking PIC code which is
6629 never referenced by a dynamic object, in which case we
6630 don't need to generate a procedure linkage table entry
6633 /* If this is a local symbol, we resolve it directly without
6634 creating a procedure linkage table entry. */
6638 if (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
6641 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
6642 h->plt.refcount += 1;
6647 #ifdef INCLUDE_SHMEDIA
6648 case R_SH_IMM_LOW16_PCREL:
6649 case R_SH_IMM_MEDLOW16_PCREL:
6650 case R_SH_IMM_MEDHI16_PCREL:
6651 case R_SH_IMM_HI16_PCREL:
6653 if (h != NULL && ! info->shared)
6655 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
6656 h->plt.refcount += 1;
6659 /* If we are creating a shared library, and this is a reloc
6660 against a global symbol, or a non PC relative reloc
6661 against a local symbol, then we need to copy the reloc
6662 into the shared library. However, if we are linking with
6663 -Bsymbolic, we do not need to copy a reloc against a
6664 global symbol which is defined in an object we are
6665 including in the link (i.e., DEF_REGULAR is set). At
6666 this point we have not seen all the input files, so it is
6667 possible that DEF_REGULAR is not set now but will be set
6668 later (it is never cleared). We account for that
6669 possibility below by storing information in the
6670 dyn_relocs field of the hash table entry. A similar
6671 situation occurs when creating shared libraries and symbol
6672 visibility changes render the symbol local.
6674 If on the other hand, we are creating an executable, we
6675 may need to keep relocations for symbols satisfied by a
6676 dynamic library if we manage to avoid copy relocs for the
6679 && (sec->flags & SEC_ALLOC) != 0
6680 && (r_type != R_SH_REL32
6682 && (! info->symbolic
6683 || h->root.type == bfd_link_hash_defweak
6684 || (h->elf_link_hash_flags
6685 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
6687 && (sec->flags & SEC_ALLOC) != 0
6689 && (h->root.type == bfd_link_hash_defweak
6690 || (h->elf_link_hash_flags
6691 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
6693 struct elf_sh_dyn_relocs *p;
6694 struct elf_sh_dyn_relocs **head;
6696 if (htab->root.dynobj == NULL)
6697 htab->root.dynobj = abfd;
6699 /* When creating a shared object, we must copy these
6700 reloc types into the output file. We create a reloc
6701 section in dynobj and make room for this reloc. */
6706 name = (bfd_elf_string_from_elf_section
6708 elf_elfheader (abfd)->e_shstrndx,
6709 elf_section_data (sec)->rel_hdr.sh_name));
6713 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
6714 && strcmp (bfd_get_section_name (abfd, sec),
6717 sreloc = bfd_get_section_by_name (htab->root.dynobj, name);
6722 sreloc = bfd_make_section (htab->root.dynobj, name);
6723 flags = (SEC_HAS_CONTENTS | SEC_READONLY
6724 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
6725 if ((sec->flags & SEC_ALLOC) != 0)
6726 flags |= SEC_ALLOC | SEC_LOAD;
6728 || ! bfd_set_section_flags (htab->root.dynobj,
6730 || ! bfd_set_section_alignment (htab->root.dynobj,
6734 elf_section_data (sec)->sreloc = sreloc;
6737 /* If this is a global symbol, we count the number of
6738 relocations we need for this symbol. */
6740 head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
6745 /* Track dynamic relocs needed for local syms too. */
6746 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
6751 head = ((struct elf_sh_dyn_relocs **)
6752 &elf_section_data (s)->local_dynrel);
6756 if (p == NULL || p->sec != sec)
6758 bfd_size_type amt = sizeof (*p);
6759 p = bfd_alloc (htab->root.dynobj, amt);
6770 if (r_type == R_SH_REL32
6771 #ifdef INCLUDE_SHMEDIA
6772 || r_type == R_SH_IMM_LOW16_PCREL
6773 || r_type == R_SH_IMM_MEDLOW16_PCREL
6774 || r_type == R_SH_IMM_MEDHI16_PCREL
6775 || r_type == R_SH_IMM_HI16_PCREL
6783 case R_SH_TLS_LE_32:
6786 (*_bfd_error_handler) (_("%s: TLS local exec code cannot be linked into shared objects"),
6787 bfd_archive_filename (abfd));
6793 case R_SH_TLS_LDO_32:
6794 /* Nothing to do. */
6805 #ifndef sh_elf_set_mach_from_flags
6806 static unsigned int sh_ef_bfd_table[] = { EF_SH_BFD_TABLE };
6809 sh_elf_set_mach_from_flags (bfd *abfd)
6811 flagword flags = elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK;
6813 if (flags >= sizeof(sh_ef_bfd_table))
6816 if (sh_ef_bfd_table[flags] == 0)
6819 bfd_default_set_arch_mach (abfd, bfd_arch_sh, sh_ef_bfd_table[flags]);
6825 /* Reverse table lookup for sh_ef_bfd_table[].
6826 Given a bfd MACH value from archures.c
6827 return the equivalent ELF flags from the table.
6828 Return -1 if no match is found. */
6831 sh_elf_get_flags_from_mach (unsigned long mach)
6833 int i = ARRAY_SIZE (sh_ef_bfd_table);
6836 if (sh_ef_bfd_table[i] == mach)
6839 /* shouldn't get here */
6844 #endif /* not sh_elf_set_mach_from_flags */
6846 #ifndef sh_elf_set_private_flags
6847 /* Function to keep SH specific file flags. */
6850 sh_elf_set_private_flags (bfd *abfd, flagword flags)
6852 BFD_ASSERT (! elf_flags_init (abfd)
6853 || elf_elfheader (abfd)->e_flags == flags);
6855 elf_elfheader (abfd)->e_flags = flags;
6856 elf_flags_init (abfd) = TRUE;
6857 return sh_elf_set_mach_from_flags (abfd);
6859 #endif /* not sh_elf_set_private_flags */
6861 #ifndef sh_elf_copy_private_data
6862 /* Copy backend specific data from one object module to another */
6865 sh_elf_copy_private_data (bfd * ibfd, bfd * obfd)
6867 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6868 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6871 return sh_elf_set_private_flags (obfd, elf_elfheader (ibfd)->e_flags);
6873 #endif /* not sh_elf_copy_private_data */
6875 #ifndef sh_elf_merge_private_data
6877 /* This function returns the ELF architecture number that
6878 corresponds to the given arch_sh* flags. */
6880 sh_find_elf_flags (unsigned int arch_set)
6882 unsigned long bfd_mach = sh_get_bfd_mach_from_arch_set (arch_set);
6884 return sh_elf_get_flags_from_mach (bfd_mach);
6888 /* This routine initialises the elf flags when required and
6889 calls sh_merge_bfd_arch() to check dsp/fpu compatibility. */
6892 sh_elf_merge_private_data (bfd *ibfd, bfd *obfd)
6894 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6895 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6898 if (! elf_flags_init (obfd))
6900 /* This happens when ld starts out with a 'blank' output file. */
6901 elf_flags_init (obfd) = TRUE;
6902 elf_elfheader (obfd)->e_flags = EF_SH1;
6903 sh_elf_set_mach_from_flags (obfd);
6906 if ( ! sh_merge_bfd_arch (ibfd, obfd) )
6909 elf_elfheader (obfd)->e_flags =
6910 sh_elf_get_flags_from_mach (bfd_get_mach (obfd));
6914 #endif /* not sh_elf_merge_private_data */
6916 /* Override the generic function because we need to store sh_elf_obj_tdata
6917 as the specific tdata. We set also the machine architecture from flags
6921 sh_elf_object_p (bfd *abfd)
6923 return sh_elf_set_mach_from_flags (abfd);
6926 /* Finish up dynamic symbol handling. We set the contents of various
6927 dynamic sections here. */
6930 sh_elf_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
6931 struct elf_link_hash_entry *h,
6932 Elf_Internal_Sym *sym)
6934 struct elf_sh_link_hash_table *htab;
6936 htab = sh_elf_hash_table (info);
6938 if (h->plt.offset != (bfd_vma) -1)
6946 Elf_Internal_Rela rel;
6949 /* This symbol has an entry in the procedure linkage table. Set
6952 BFD_ASSERT (h->dynindx != -1);
6955 sgot = htab->sgotplt;
6956 srel = htab->srelplt;
6957 BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
6959 /* Get the index in the procedure linkage table which
6960 corresponds to this symbol. This is the index of this symbol
6961 in all the symbols for which we are making plt entries. The
6962 first entry in the procedure linkage table is reserved. */
6963 plt_index = h->plt.offset / elf_sh_sizeof_plt (info) - 1;
6965 /* Get the offset into the .got table of the entry that
6966 corresponds to this function. Each .got entry is 4 bytes.
6967 The first three are reserved. */
6968 got_offset = (plt_index + 3) * 4;
6972 got_offset -= GOT_BIAS;
6975 /* Fill in the entry in the procedure linkage table. */
6978 if (elf_sh_plt_entry == NULL)
6980 elf_sh_plt_entry = (bfd_big_endian (output_bfd) ?
6981 elf_sh_plt_entry_be : elf_sh_plt_entry_le);
6983 memcpy (splt->contents + h->plt.offset, elf_sh_plt_entry,
6984 elf_sh_sizeof_plt (info));
6985 #ifdef INCLUDE_SHMEDIA
6986 movi_shori_putval (output_bfd,
6987 (sgot->output_section->vma
6988 + sgot->output_offset
6990 (splt->contents + h->plt.offset
6991 + elf_sh_plt_symbol_offset (info)));
6993 /* Set bottom bit because its for a branch to SHmedia */
6994 movi_shori_putval (output_bfd,
6995 (splt->output_section->vma + splt->output_offset)
6997 (splt->contents + h->plt.offset
6998 + elf_sh_plt_plt0_offset (info)));
7000 bfd_put_32 (output_bfd,
7001 (sgot->output_section->vma
7002 + sgot->output_offset
7004 (splt->contents + h->plt.offset
7005 + elf_sh_plt_symbol_offset (info)));
7007 bfd_put_32 (output_bfd,
7008 (splt->output_section->vma + splt->output_offset),
7009 (splt->contents + h->plt.offset
7010 + elf_sh_plt_plt0_offset (info)));
7015 if (elf_sh_pic_plt_entry == NULL)
7017 elf_sh_pic_plt_entry = (bfd_big_endian (output_bfd) ?
7018 elf_sh_pic_plt_entry_be :
7019 elf_sh_pic_plt_entry_le);
7021 memcpy (splt->contents + h->plt.offset, elf_sh_pic_plt_entry,
7022 elf_sh_sizeof_plt (info));
7023 #ifdef INCLUDE_SHMEDIA
7024 movi_shori_putval (output_bfd, got_offset,
7025 (splt->contents + h->plt.offset
7026 + elf_sh_plt_symbol_offset (info)));
7028 bfd_put_32 (output_bfd, got_offset,
7029 (splt->contents + h->plt.offset
7030 + elf_sh_plt_symbol_offset (info)));
7036 got_offset += GOT_BIAS;
7039 #ifdef INCLUDE_SHMEDIA
7040 movi_shori_putval (output_bfd,
7041 plt_index * sizeof (Elf32_External_Rela),
7042 (splt->contents + h->plt.offset
7043 + elf_sh_plt_reloc_offset (info)));
7045 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
7046 (splt->contents + h->plt.offset
7047 + elf_sh_plt_reloc_offset (info)));
7050 /* Fill in the entry in the global offset table. */
7051 bfd_put_32 (output_bfd,
7052 (splt->output_section->vma
7053 + splt->output_offset
7055 + elf_sh_plt_temp_offset (info)),
7056 sgot->contents + got_offset);
7058 /* Fill in the entry in the .rela.plt section. */
7059 rel.r_offset = (sgot->output_section->vma
7060 + sgot->output_offset
7062 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_JMP_SLOT);
7065 rel.r_addend = GOT_BIAS;
7067 loc = srel->contents + plt_index * sizeof (Elf32_External_Rela);
7068 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
7070 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
7072 /* Mark the symbol as undefined, rather than as defined in
7073 the .plt section. Leave the value alone. */
7074 sym->st_shndx = SHN_UNDEF;
7078 if (h->got.offset != (bfd_vma) -1
7079 && sh_elf_hash_entry (h)->tls_type != GOT_TLS_GD
7080 && sh_elf_hash_entry (h)->tls_type != GOT_TLS_IE)
7084 Elf_Internal_Rela rel;
7087 /* This symbol has an entry in the global offset table. Set it
7091 srel = htab->srelgot;
7092 BFD_ASSERT (sgot != NULL && srel != NULL);
7094 rel.r_offset = (sgot->output_section->vma
7095 + sgot->output_offset
7096 + (h->got.offset &~ (bfd_vma) 1));
7098 /* If this is a static link, or it is a -Bsymbolic link and the
7099 symbol is defined locally or was forced to be local because
7100 of a version file, we just want to emit a RELATIVE reloc.
7101 The entry in the global offset table will already have been
7102 initialized in the relocate_section function. */
7104 && SYMBOL_REFERENCES_LOCAL (info, h))
7106 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
7107 rel.r_addend = (h->root.u.def.value
7108 + h->root.u.def.section->output_section->vma
7109 + h->root.u.def.section->output_offset);
7113 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
7114 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
7118 loc = srel->contents;
7119 loc += srel->reloc_count++ * sizeof (Elf32_External_Rela);
7120 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
7123 #ifdef INCLUDE_SHMEDIA
7125 struct elf_sh_link_hash_entry *eh;
7127 eh = (struct elf_sh_link_hash_entry *) h;
7128 if (eh->datalabel_got.offset != (bfd_vma) -1)
7132 Elf_Internal_Rela rel;
7135 /* This symbol has a datalabel entry in the global offset table.
7139 srel = htab->srelgot;
7140 BFD_ASSERT (sgot != NULL && srel != NULL);
7142 rel.r_offset = (sgot->output_section->vma
7143 + sgot->output_offset
7144 + (eh->datalabel_got.offset &~ (bfd_vma) 1));
7146 /* If this is a static link, or it is a -Bsymbolic link and the
7147 symbol is defined locally or was forced to be local because
7148 of a version file, we just want to emit a RELATIVE reloc.
7149 The entry in the global offset table will already have been
7150 initialized in the relocate_section function. */
7152 && SYMBOL_REFERENCES_LOCAL (info, h))
7154 rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
7155 rel.r_addend = (h->root.u.def.value
7156 + h->root.u.def.section->output_section->vma
7157 + h->root.u.def.section->output_offset);
7161 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents
7162 + eh->datalabel_got.offset);
7163 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_GLOB_DAT);
7167 loc = srel->contents;
7168 loc += srel->reloc_count++ * sizeof (Elf32_External_Rela);
7169 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
7174 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
7177 Elf_Internal_Rela rel;
7180 /* This symbol needs a copy reloc. Set it up. */
7182 BFD_ASSERT (h->dynindx != -1
7183 && (h->root.type == bfd_link_hash_defined
7184 || h->root.type == bfd_link_hash_defweak));
7186 s = bfd_get_section_by_name (h->root.u.def.section->owner,
7188 BFD_ASSERT (s != NULL);
7190 rel.r_offset = (h->root.u.def.value
7191 + h->root.u.def.section->output_section->vma
7192 + h->root.u.def.section->output_offset);
7193 rel.r_info = ELF32_R_INFO (h->dynindx, R_SH_COPY);
7195 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
7196 bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
7199 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7200 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
7201 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
7202 sym->st_shndx = SHN_ABS;
7207 /* Finish up the dynamic sections. */
7210 sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
7212 struct elf_sh_link_hash_table *htab;
7216 htab = sh_elf_hash_table (info);
7217 sgot = htab->sgotplt;
7218 sdyn = bfd_get_section_by_name (htab->root.dynobj, ".dynamic");
7220 if (htab->root.dynamic_sections_created)
7223 Elf32_External_Dyn *dyncon, *dynconend;
7225 BFD_ASSERT (sgot != NULL && sdyn != NULL);
7227 dyncon = (Elf32_External_Dyn *) sdyn->contents;
7228 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
7229 for (; dyncon < dynconend; dyncon++)
7231 Elf_Internal_Dyn dyn;
7233 #ifdef INCLUDE_SHMEDIA
7237 bfd_elf32_swap_dyn_in (htab->root.dynobj, dyncon, &dyn);
7244 #ifdef INCLUDE_SHMEDIA
7246 name = info->init_function;
7250 name = info->fini_function;
7252 if (dyn.d_un.d_val != 0)
7254 struct elf_link_hash_entry *h;
7256 h = elf_link_hash_lookup (&htab->root, name,
7257 FALSE, FALSE, TRUE);
7258 if (h != NULL && (h->other & STO_SH5_ISA32))
7260 dyn.d_un.d_val |= 1;
7261 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7268 s = htab->sgot->output_section;
7272 s = htab->srelplt->output_section;
7274 BFD_ASSERT (s != NULL);
7275 dyn.d_un.d_ptr = s->vma;
7276 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7280 s = htab->srelplt->output_section;
7281 BFD_ASSERT (s != NULL);
7282 dyn.d_un.d_val = s->size;
7283 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7287 /* My reading of the SVR4 ABI indicates that the
7288 procedure linkage table relocs (DT_JMPREL) should be
7289 included in the overall relocs (DT_RELA). This is
7290 what Solaris does. However, UnixWare can not handle
7291 that case. Therefore, we override the DT_RELASZ entry
7292 here to make it not include the JMPREL relocs. Since
7293 the linker script arranges for .rela.plt to follow all
7294 other relocation sections, we don't have to worry
7295 about changing the DT_RELA entry. */
7296 if (htab->srelplt != NULL)
7298 s = htab->srelplt->output_section;
7299 dyn.d_un.d_val -= s->size;
7301 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7306 /* Fill in the first entry in the procedure linkage table. */
7308 if (splt && splt->size > 0)
7312 if (elf_sh_pic_plt_entry == NULL)
7314 elf_sh_pic_plt_entry = (bfd_big_endian (output_bfd) ?
7315 elf_sh_pic_plt_entry_be :
7316 elf_sh_pic_plt_entry_le);
7318 memcpy (splt->contents, elf_sh_pic_plt_entry,
7319 elf_sh_sizeof_plt (info));
7323 if (elf_sh_plt0_entry == NULL)
7325 elf_sh_plt0_entry = (bfd_big_endian (output_bfd) ?
7326 elf_sh_plt0_entry_be :
7327 elf_sh_plt0_entry_le);
7329 memcpy (splt->contents, elf_sh_plt0_entry, PLT_ENTRY_SIZE);
7330 #ifdef INCLUDE_SHMEDIA
7331 movi_shori_putval (output_bfd,
7332 sgot->output_section->vma
7333 + sgot->output_offset,
7335 + elf_sh_plt0_gotplt_offset (info));
7337 bfd_put_32 (output_bfd,
7338 sgot->output_section->vma + sgot->output_offset + 4,
7339 splt->contents + elf_sh_plt0_gotid_offset (info));
7340 bfd_put_32 (output_bfd,
7341 sgot->output_section->vma + sgot->output_offset + 8,
7342 splt->contents + elf_sh_plt0_linker_offset (info));
7346 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7347 really seem like the right value. */
7348 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
7352 /* Fill in the first three entries in the global offset table. */
7353 if (sgot && sgot->size > 0)
7356 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
7358 bfd_put_32 (output_bfd,
7359 sdyn->output_section->vma + sdyn->output_offset,
7361 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
7362 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
7364 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
7370 static enum elf_reloc_type_class
7371 sh_elf_reloc_type_class (const Elf_Internal_Rela *rela)
7373 switch ((int) ELF32_R_TYPE (rela->r_info))
7376 return reloc_class_relative;
7378 return reloc_class_plt;
7380 return reloc_class_copy;
7382 return reloc_class_normal;
7386 /* Support for Linux core dump NOTE sections. */
7388 elf32_shlin_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
7393 switch (note->descsz)
7398 case 168: /* Linux/SH */
7400 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
7403 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
7412 /* Make a ".reg/999" section. */
7413 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
7414 size, note->descpos + offset);
7418 elf32_shlin_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
7420 switch (note->descsz)
7425 case 124: /* Linux/SH elf_prpsinfo */
7426 elf_tdata (abfd)->core_program
7427 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
7428 elf_tdata (abfd)->core_command
7429 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
7432 /* Note that for some reason, a spurious space is tacked
7433 onto the end of the args in some (at least one anyway)
7434 implementations, so strip it off if it exists. */
7437 char *command = elf_tdata (abfd)->core_command;
7438 int n = strlen (command);
7440 if (0 < n && command[n - 1] == ' ')
7441 command[n - 1] = '\0';
7448 /* Return address for Ith PLT stub in section PLT, for relocation REL
7449 or (bfd_vma) -1 if it should not be included. */
7452 sh_elf_plt_sym_val (bfd_vma i, const asection *plt,
7453 const arelent *rel ATTRIBUTE_UNUSED)
7455 return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
7458 #define TARGET_BIG_SYM bfd_elf32_sh_vec
7459 #define TARGET_BIG_NAME "elf32-sh"
7460 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
7461 #define TARGET_LITTLE_NAME "elf32-shl"
7462 #define ELF_ARCH bfd_arch_sh
7463 #define ELF_MACHINE_CODE EM_SH
7464 #ifdef __QNXTARGET__
7465 #define ELF_MAXPAGESIZE 0x1000
7467 #define ELF_MAXPAGESIZE 0x80
7470 #define elf_symbol_leading_char '_'
7472 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7473 #define elf_info_to_howto sh_elf_info_to_howto
7474 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
7475 #define elf_backend_relocate_section sh_elf_relocate_section
7476 #define bfd_elf32_bfd_get_relocated_section_contents \
7477 sh_elf_get_relocated_section_contents
7478 #define bfd_elf32_mkobject sh_elf_mkobject
7479 #define elf_backend_object_p sh_elf_object_p
7480 #define bfd_elf32_bfd_set_private_bfd_flags \
7481 sh_elf_set_private_flags
7482 #define bfd_elf32_bfd_copy_private_bfd_data \
7483 sh_elf_copy_private_data
7484 #define bfd_elf32_bfd_merge_private_bfd_data \
7485 sh_elf_merge_private_data
7487 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
7488 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
7489 #define elf_backend_check_relocs sh_elf_check_relocs
7490 #define elf_backend_copy_indirect_symbol \
7491 sh_elf_copy_indirect_symbol
7492 #define elf_backend_create_dynamic_sections \
7493 sh_elf_create_dynamic_sections
7494 #define bfd_elf32_bfd_link_hash_table_create \
7495 sh_elf_link_hash_table_create
7496 #define elf_backend_adjust_dynamic_symbol \
7497 sh_elf_adjust_dynamic_symbol
7498 #define elf_backend_size_dynamic_sections \
7499 sh_elf_size_dynamic_sections
7500 #define elf_backend_finish_dynamic_symbol \
7501 sh_elf_finish_dynamic_symbol
7502 #define elf_backend_finish_dynamic_sections \
7503 sh_elf_finish_dynamic_sections
7504 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
7505 #define elf_backend_plt_sym_val sh_elf_plt_sym_val
7507 #define elf_backend_can_gc_sections 1
7508 #define elf_backend_can_refcount 1
7509 #define elf_backend_want_got_plt 1
7510 #define elf_backend_plt_readonly 1
7511 #define elf_backend_want_plt_sym 0
7512 #define elf_backend_got_header_size 12
7514 #ifndef INCLUDE_SHMEDIA
7516 #include "elf32-target.h"
7518 /* NetBSD support. */
7519 #undef TARGET_BIG_SYM
7520 #define TARGET_BIG_SYM bfd_elf32_shnbsd_vec
7521 #undef TARGET_BIG_NAME
7522 #define TARGET_BIG_NAME "elf32-sh-nbsd"
7523 #undef TARGET_LITTLE_SYM
7524 #define TARGET_LITTLE_SYM bfd_elf32_shlnbsd_vec
7525 #undef TARGET_LITTLE_NAME
7526 #define TARGET_LITTLE_NAME "elf32-shl-nbsd"
7527 #undef ELF_MAXPAGESIZE
7528 #define ELF_MAXPAGESIZE 0x10000
7529 #undef elf_symbol_leading_char
7530 #define elf_symbol_leading_char 0
7532 #define elf32_bed elf32_sh_nbsd_bed
7534 #include "elf32-target.h"
7537 /* Linux support. */
7538 #undef TARGET_BIG_SYM
7539 #define TARGET_BIG_SYM bfd_elf32_shblin_vec
7540 #undef TARGET_BIG_NAME
7541 #define TARGET_BIG_NAME "elf32-shbig-linux"
7542 #undef TARGET_LITTLE_SYM
7543 #define TARGET_LITTLE_SYM bfd_elf32_shlin_vec
7544 #undef TARGET_LITTLE_NAME
7545 #define TARGET_LITTLE_NAME "elf32-sh-linux"
7547 #undef elf_backend_grok_prstatus
7548 #define elf_backend_grok_prstatus elf32_shlin_grok_prstatus
7549 #undef elf_backend_grok_psinfo
7550 #define elf_backend_grok_psinfo elf32_shlin_grok_psinfo
7552 #define elf32_bed elf32_sh_lin_bed
7554 #include "elf32-target.h"
7556 #endif /* INCLUDE_SHMEDIA */