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"
30 static bfd_reloc_status_type sh_elf_reloc
31 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
32 static bfd_reloc_status_type sh_elf_ignore_reloc
33 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
34 static reloc_howto_type
*sh_elf_reloc_type_lookup
35 (bfd
*, bfd_reloc_code_real_type
);
36 static void sh_elf_info_to_howto
37 (bfd
*, arelent
*, Elf_Internal_Rela
*);
38 static bfd_boolean sh_elf_set_private_flags
40 static bfd_boolean sh_elf_copy_private_data
42 static bfd_boolean sh_elf_merge_private_data
44 static bfd_boolean sh_elf_set_mach_from_flags
46 static bfd_boolean sh_elf_relax_section
47 (bfd
*, asection
*, struct bfd_link_info
*, bfd_boolean
*);
48 static bfd_boolean sh_elf_relax_delete_bytes
49 (bfd
*, asection
*, bfd_vma
, int);
50 static bfd_boolean sh_elf_align_loads
51 (bfd
*, asection
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_boolean
*);
52 static bfd_boolean sh_elf_swap_insns
53 (bfd
*, asection
*, void *, bfd_byte
*, bfd_vma
);
54 static bfd_boolean sh_elf_relocate_section
55 (bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
56 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**);
57 static bfd_byte
*sh_elf_get_relocated_section_contents
58 (bfd
*, struct bfd_link_info
*, struct bfd_link_order
*, bfd_byte
*,
59 bfd_boolean
, asymbol
**);
60 static void sh_elf_copy_indirect_symbol
61 (const struct elf_backend_data
*, struct elf_link_hash_entry
*,
62 struct elf_link_hash_entry
*);
63 static int sh_elf_optimized_tls_reloc
64 (struct bfd_link_info
*, int, int);
65 static bfd_boolean sh_elf_mkobject
67 static bfd_boolean sh_elf_object_p
69 static bfd_boolean sh_elf_check_relocs
70 (bfd
*, struct bfd_link_info
*, asection
*, const Elf_Internal_Rela
*);
71 static struct bfd_hash_entry
*sh_elf_link_hash_newfunc
72 (struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *);
73 static struct bfd_link_hash_table
*sh_elf_link_hash_table_create
75 static bfd_boolean sh_elf_adjust_dynamic_symbol
76 (struct bfd_link_info
*, struct elf_link_hash_entry
*);
77 static bfd_boolean sh_elf_size_dynamic_sections
78 (bfd
*, struct bfd_link_info
*);
79 static bfd_boolean sh_elf_finish_dynamic_symbol
80 (bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
82 static bfd_boolean sh_elf_finish_dynamic_sections
83 (bfd
*, struct bfd_link_info
*);
84 static bfd_reloc_status_type sh_elf_reloc_loop
85 (int, bfd
*, asection
*, bfd_byte
*, bfd_vma
, asection
*, bfd_vma
,
87 static bfd_boolean create_got_section
88 (bfd
*, struct bfd_link_info
*);
89 static bfd_boolean sh_elf_create_dynamic_sections
90 (bfd
*, struct bfd_link_info
*);
91 static bfd_vma dtpoff_base
92 (struct bfd_link_info
*);
94 (struct bfd_link_info
*, bfd_vma
);
95 static asection
* sh_elf_gc_mark_hook
96 (asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
97 struct elf_link_hash_entry
*, Elf_Internal_Sym
*);
98 static bfd_boolean sh_elf_gc_sweep_hook
99 (bfd
*, struct bfd_link_info
*, asection
*, const Elf_Internal_Rela
*);
100 static bfd_boolean allocate_dynrelocs
101 (struct elf_link_hash_entry
*, void *);
102 static bfd_boolean readonly_dynrelocs
103 (struct elf_link_hash_entry
*, void *);
104 static enum elf_reloc_type_class sh_elf_reloc_type_class
105 (const Elf_Internal_Rela
*);
106 #ifdef INCLUDE_SHMEDIA
107 inline static void movi_shori_putval (bfd
*, unsigned long, char *);
109 static bfd_boolean elf32_shlin_grok_prstatus
110 (bfd
*abfd
, Elf_Internal_Note
*note
);
111 static bfd_boolean elf32_shlin_grok_psinfo
112 (bfd
*abfd
, Elf_Internal_Note
*note
);
114 /* The name of the dynamic interpreter. This is put in the .interp
117 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
119 static reloc_howto_type sh_elf_howto_table
[] =
122 HOWTO (R_SH_NONE
, /* type */
124 0, /* size (0 = byte, 1 = short, 2 = long) */
126 FALSE
, /* pc_relative */
128 complain_overflow_dont
, /* complain_on_overflow */
129 sh_elf_ignore_reloc
, /* special_function */
130 "R_SH_NONE", /* name */
131 FALSE
, /* partial_inplace */
134 FALSE
), /* pcrel_offset */
136 /* 32 bit absolute relocation. Setting partial_inplace to TRUE and
137 src_mask to a non-zero value is similar to the COFF toolchain. */
138 HOWTO (R_SH_DIR32
, /* type */
140 2, /* size (0 = byte, 1 = short, 2 = long) */
142 FALSE
, /* pc_relative */
144 complain_overflow_bitfield
, /* complain_on_overflow */
145 sh_elf_reloc
, /* special_function */
146 "R_SH_DIR32", /* name */
147 TRUE
, /* partial_inplace */
148 0xffffffff, /* src_mask */
149 0xffffffff, /* dst_mask */
150 FALSE
), /* pcrel_offset */
152 /* 32 bit PC relative relocation. */
153 HOWTO (R_SH_REL32
, /* type */
155 2, /* size (0 = byte, 1 = short, 2 = long) */
157 TRUE
, /* pc_relative */
159 complain_overflow_signed
, /* complain_on_overflow */
160 sh_elf_ignore_reloc
, /* special_function */
161 "R_SH_REL32", /* name */
162 TRUE
, /* partial_inplace */
163 0xffffffff, /* src_mask */
164 0xffffffff, /* dst_mask */
165 TRUE
), /* pcrel_offset */
167 /* 8 bit PC relative branch divided by 2. */
168 HOWTO (R_SH_DIR8WPN
, /* type */
170 1, /* size (0 = byte, 1 = short, 2 = long) */
172 TRUE
, /* pc_relative */
174 complain_overflow_signed
, /* complain_on_overflow */
175 sh_elf_ignore_reloc
, /* special_function */
176 "R_SH_DIR8WPN", /* name */
177 TRUE
, /* partial_inplace */
180 TRUE
), /* pcrel_offset */
182 /* 12 bit PC relative branch divided by 2. */
183 /* This cannot be partial_inplace because relaxation can't know the
184 eventual value of a symbol. */
185 HOWTO (R_SH_IND12W
, /* type */
187 1, /* size (0 = byte, 1 = short, 2 = long) */
189 TRUE
, /* pc_relative */
191 complain_overflow_signed
, /* complain_on_overflow */
192 NULL
, /* special_function */
193 "R_SH_IND12W", /* name */
194 FALSE
, /* partial_inplace */
196 0xfff, /* dst_mask */
197 TRUE
), /* pcrel_offset */
199 /* 8 bit unsigned PC relative divided by 4. */
200 HOWTO (R_SH_DIR8WPL
, /* type */
202 1, /* size (0 = byte, 1 = short, 2 = long) */
204 TRUE
, /* pc_relative */
206 complain_overflow_unsigned
, /* complain_on_overflow */
207 sh_elf_ignore_reloc
, /* special_function */
208 "R_SH_DIR8WPL", /* name */
209 TRUE
, /* partial_inplace */
212 TRUE
), /* pcrel_offset */
214 /* 8 bit unsigned PC relative divided by 2. */
215 HOWTO (R_SH_DIR8WPZ
, /* type */
217 1, /* size (0 = byte, 1 = short, 2 = long) */
219 TRUE
, /* pc_relative */
221 complain_overflow_unsigned
, /* complain_on_overflow */
222 sh_elf_ignore_reloc
, /* special_function */
223 "R_SH_DIR8WPZ", /* name */
224 TRUE
, /* partial_inplace */
227 TRUE
), /* pcrel_offset */
229 /* 8 bit GBR relative. FIXME: This only makes sense if we have some
230 special symbol for the GBR relative area, and that is not
232 HOWTO (R_SH_DIR8BP
, /* type */
234 1, /* size (0 = byte, 1 = short, 2 = long) */
236 FALSE
, /* pc_relative */
238 complain_overflow_unsigned
, /* complain_on_overflow */
239 sh_elf_ignore_reloc
, /* special_function */
240 "R_SH_DIR8BP", /* name */
241 FALSE
, /* partial_inplace */
244 TRUE
), /* pcrel_offset */
246 /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if
247 we have some special symbol for the GBR relative area, and that
248 is not implemented. */
249 HOWTO (R_SH_DIR8W
, /* type */
251 1, /* size (0 = byte, 1 = short, 2 = long) */
253 FALSE
, /* pc_relative */
255 complain_overflow_unsigned
, /* complain_on_overflow */
256 sh_elf_ignore_reloc
, /* special_function */
257 "R_SH_DIR8W", /* name */
258 FALSE
, /* partial_inplace */
261 TRUE
), /* pcrel_offset */
263 /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if
264 we have some special symbol for the GBR relative area, and that
265 is not implemented. */
266 HOWTO (R_SH_DIR8L
, /* type */
268 1, /* size (0 = byte, 1 = short, 2 = long) */
270 FALSE
, /* pc_relative */
272 complain_overflow_unsigned
, /* complain_on_overflow */
273 sh_elf_ignore_reloc
, /* special_function */
274 "R_SH_DIR8L", /* name */
275 FALSE
, /* partial_inplace */
278 TRUE
), /* pcrel_offset */
280 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
281 HOWTO (R_SH_LOOP_START
, /* type */
283 1, /* size (0 = byte, 1 = short, 2 = long) */
285 FALSE
, /* pc_relative */
287 complain_overflow_signed
, /* complain_on_overflow */
288 sh_elf_ignore_reloc
, /* special_function */
289 "R_SH_LOOP_START", /* name */
290 TRUE
, /* partial_inplace */
293 TRUE
), /* pcrel_offset */
295 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
296 HOWTO (R_SH_LOOP_END
, /* type */
298 1, /* size (0 = byte, 1 = short, 2 = long) */
300 FALSE
, /* pc_relative */
302 complain_overflow_signed
, /* complain_on_overflow */
303 sh_elf_ignore_reloc
, /* special_function */
304 "R_SH_LOOP_END", /* name */
305 TRUE
, /* partial_inplace */
308 TRUE
), /* pcrel_offset */
321 /* The remaining relocs are a GNU extension used for relaxing. The
322 final pass of the linker never needs to do anything with any of
323 these relocs. Any required operations are handled by the
326 /* GNU extension to record C++ vtable hierarchy */
327 HOWTO (R_SH_GNU_VTINHERIT
, /* type */
329 2, /* size (0 = byte, 1 = short, 2 = long) */
331 FALSE
, /* pc_relative */
333 complain_overflow_dont
, /* complain_on_overflow */
334 NULL
, /* special_function */
335 "R_SH_GNU_VTINHERIT", /* name */
336 FALSE
, /* partial_inplace */
339 FALSE
), /* pcrel_offset */
341 /* GNU extension to record C++ vtable member usage */
342 HOWTO (R_SH_GNU_VTENTRY
, /* type */
344 2, /* size (0 = byte, 1 = short, 2 = long) */
346 FALSE
, /* pc_relative */
348 complain_overflow_dont
, /* complain_on_overflow */
349 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
350 "R_SH_GNU_VTENTRY", /* name */
351 FALSE
, /* partial_inplace */
354 FALSE
), /* pcrel_offset */
356 /* An 8 bit switch table entry. This is generated for an expression
357 such as ``.word L1 - L2''. The offset holds the difference
358 between the reloc address and L2. */
359 HOWTO (R_SH_SWITCH8
, /* type */
361 0, /* size (0 = byte, 1 = short, 2 = long) */
363 FALSE
, /* pc_relative */
365 complain_overflow_unsigned
, /* complain_on_overflow */
366 sh_elf_ignore_reloc
, /* special_function */
367 "R_SH_SWITCH8", /* name */
368 FALSE
, /* partial_inplace */
371 TRUE
), /* pcrel_offset */
373 /* A 16 bit switch table entry. This is generated for an expression
374 such as ``.word L1 - L2''. The offset holds the difference
375 between the reloc address and L2. */
376 HOWTO (R_SH_SWITCH16
, /* type */
378 1, /* size (0 = byte, 1 = short, 2 = long) */
380 FALSE
, /* pc_relative */
382 complain_overflow_unsigned
, /* complain_on_overflow */
383 sh_elf_ignore_reloc
, /* special_function */
384 "R_SH_SWITCH16", /* name */
385 FALSE
, /* partial_inplace */
388 TRUE
), /* pcrel_offset */
390 /* A 32 bit switch table entry. This is generated for an expression
391 such as ``.long L1 - L2''. The offset holds the difference
392 between the reloc address and L2. */
393 HOWTO (R_SH_SWITCH32
, /* type */
395 2, /* size (0 = byte, 1 = short, 2 = long) */
397 FALSE
, /* pc_relative */
399 complain_overflow_unsigned
, /* complain_on_overflow */
400 sh_elf_ignore_reloc
, /* special_function */
401 "R_SH_SWITCH32", /* name */
402 FALSE
, /* partial_inplace */
405 TRUE
), /* pcrel_offset */
407 /* Indicates a .uses pseudo-op. The compiler will generate .uses
408 pseudo-ops when it finds a function call which can be relaxed.
409 The offset field holds the PC relative offset to the instruction
410 which loads the register used in the function call. */
411 HOWTO (R_SH_USES
, /* type */
413 1, /* size (0 = byte, 1 = short, 2 = long) */
415 FALSE
, /* pc_relative */
417 complain_overflow_unsigned
, /* complain_on_overflow */
418 sh_elf_ignore_reloc
, /* special_function */
419 "R_SH_USES", /* name */
420 FALSE
, /* partial_inplace */
423 TRUE
), /* pcrel_offset */
425 /* The assembler will generate this reloc for addresses referred to
426 by the register loads associated with USES relocs. The offset
427 field holds the number of times the address is referenced in the
429 HOWTO (R_SH_COUNT
, /* type */
431 1, /* size (0 = byte, 1 = short, 2 = long) */
433 FALSE
, /* pc_relative */
435 complain_overflow_unsigned
, /* complain_on_overflow */
436 sh_elf_ignore_reloc
, /* special_function */
437 "R_SH_COUNT", /* name */
438 FALSE
, /* partial_inplace */
441 TRUE
), /* pcrel_offset */
443 /* Indicates an alignment statement. The offset field is the power
444 of 2 to which subsequent portions of the object file must be
446 HOWTO (R_SH_ALIGN
, /* type */
448 1, /* size (0 = byte, 1 = short, 2 = long) */
450 FALSE
, /* pc_relative */
452 complain_overflow_unsigned
, /* complain_on_overflow */
453 sh_elf_ignore_reloc
, /* special_function */
454 "R_SH_ALIGN", /* name */
455 FALSE
, /* partial_inplace */
458 TRUE
), /* pcrel_offset */
460 /* The assembler will generate this reloc before a block of
461 instructions. A section should be processed as assuming it
462 contains data, unless this reloc is seen. */
463 HOWTO (R_SH_CODE
, /* type */
465 1, /* size (0 = byte, 1 = short, 2 = long) */
467 FALSE
, /* pc_relative */
469 complain_overflow_unsigned
, /* complain_on_overflow */
470 sh_elf_ignore_reloc
, /* special_function */
471 "R_SH_CODE", /* name */
472 FALSE
, /* partial_inplace */
475 TRUE
), /* pcrel_offset */
477 /* The assembler will generate this reloc after a block of
478 instructions when it sees data that is not instructions. */
479 HOWTO (R_SH_DATA
, /* type */
481 1, /* size (0 = byte, 1 = short, 2 = long) */
483 FALSE
, /* pc_relative */
485 complain_overflow_unsigned
, /* complain_on_overflow */
486 sh_elf_ignore_reloc
, /* special_function */
487 "R_SH_DATA", /* name */
488 FALSE
, /* partial_inplace */
491 TRUE
), /* pcrel_offset */
493 /* The assembler generates this reloc for each label within a block
494 of instructions. This permits the linker to avoid swapping
495 instructions which are the targets of branches. */
496 HOWTO (R_SH_LABEL
, /* type */
498 1, /* size (0 = byte, 1 = short, 2 = long) */
500 FALSE
, /* pc_relative */
502 complain_overflow_unsigned
, /* complain_on_overflow */
503 sh_elf_ignore_reloc
, /* special_function */
504 "R_SH_LABEL", /* name */
505 FALSE
, /* partial_inplace */
508 TRUE
), /* pcrel_offset */
510 /* The next 12 are only supported via linking in SHC-generated objects. */
511 HOWTO (R_SH_DIR16
, /* type */
513 1, /* size (0 = byte, 1 = short, 2 = long) */
515 FALSE
, /* pc_relative */
517 complain_overflow_dont
, /* complain_on_overflow */
518 bfd_elf_generic_reloc
, /* special_function */
519 "R_SH_DIR16", /* name */
520 FALSE
, /* partial_inplace */
522 0xffff, /* dst_mask */
523 FALSE
), /* pcrel_offset */
525 HOWTO (R_SH_DIR8
, /* type */
527 0, /* size (0 = byte, 1 = short, 2 = long) */
529 FALSE
, /* pc_relative */
531 complain_overflow_dont
, /* complain_on_overflow */
532 bfd_elf_generic_reloc
, /* special_function */
533 "R_SH_DIR8", /* name */
534 FALSE
, /* partial_inplace */
537 FALSE
), /* pcrel_offset */
539 HOWTO (R_SH_DIR8UL
, /* type */
541 0, /* size (0 = byte, 1 = short, 2 = long) */
543 FALSE
, /* pc_relative */
545 complain_overflow_unsigned
, /* complain_on_overflow */
546 bfd_elf_generic_reloc
, /* special_function */
547 "R_SH_DIR8UL", /* name */
548 FALSE
, /* partial_inplace */
551 FALSE
), /* pcrel_offset */
553 HOWTO (R_SH_DIR8UW
, /* type */
555 0, /* size (0 = byte, 1 = short, 2 = long) */
557 FALSE
, /* pc_relative */
559 complain_overflow_unsigned
, /* complain_on_overflow */
560 bfd_elf_generic_reloc
, /* special_function */
561 "R_SH_DIR8UW", /* name */
562 FALSE
, /* partial_inplace */
565 FALSE
), /* pcrel_offset */
567 HOWTO (R_SH_DIR8U
, /* type */
569 0, /* size (0 = byte, 1 = short, 2 = long) */
571 FALSE
, /* pc_relative */
573 complain_overflow_unsigned
, /* complain_on_overflow */
574 bfd_elf_generic_reloc
, /* special_function */
575 "R_SH_DIR8U", /* name */
576 FALSE
, /* partial_inplace */
579 FALSE
), /* pcrel_offset */
581 HOWTO (R_SH_DIR8SW
, /* type */
583 0, /* size (0 = byte, 1 = short, 2 = long) */
585 FALSE
, /* pc_relative */
587 complain_overflow_signed
, /* complain_on_overflow */
588 bfd_elf_generic_reloc
, /* special_function */
589 "R_SH_DIR8SW", /* name */
590 FALSE
, /* partial_inplace */
593 FALSE
), /* pcrel_offset */
595 HOWTO (R_SH_DIR8S
, /* type */
597 0, /* size (0 = byte, 1 = short, 2 = long) */
599 FALSE
, /* pc_relative */
601 complain_overflow_signed
, /* complain_on_overflow */
602 bfd_elf_generic_reloc
, /* special_function */
603 "R_SH_DIR8S", /* name */
604 FALSE
, /* partial_inplace */
607 FALSE
), /* pcrel_offset */
609 HOWTO (R_SH_DIR4UL
, /* type */
611 0, /* size (0 = byte, 1 = short, 2 = long) */
613 FALSE
, /* pc_relative */
615 complain_overflow_unsigned
, /* complain_on_overflow */
616 bfd_elf_generic_reloc
, /* special_function */
617 "R_SH_DIR4UL", /* name */
618 FALSE
, /* partial_inplace */
621 FALSE
), /* pcrel_offset */
623 HOWTO (R_SH_DIR4UW
, /* type */
625 0, /* size (0 = byte, 1 = short, 2 = long) */
627 FALSE
, /* pc_relative */
629 complain_overflow_unsigned
, /* complain_on_overflow */
630 bfd_elf_generic_reloc
, /* special_function */
631 "R_SH_DIR4UW", /* name */
632 FALSE
, /* partial_inplace */
635 FALSE
), /* pcrel_offset */
637 HOWTO (R_SH_DIR4U
, /* type */
639 0, /* size (0 = byte, 1 = short, 2 = long) */
641 FALSE
, /* pc_relative */
643 complain_overflow_unsigned
, /* complain_on_overflow */
644 bfd_elf_generic_reloc
, /* special_function */
645 "R_SH_DIR4U", /* name */
646 FALSE
, /* partial_inplace */
649 FALSE
), /* pcrel_offset */
651 HOWTO (R_SH_PSHA
, /* type */
653 1, /* size (0 = byte, 1 = short, 2 = long) */
655 FALSE
, /* pc_relative */
657 complain_overflow_signed
, /* complain_on_overflow */
658 bfd_elf_generic_reloc
, /* special_function */
659 "R_SH_PSHA", /* name */
660 FALSE
, /* partial_inplace */
663 FALSE
), /* pcrel_offset */
665 HOWTO (R_SH_PSHL
, /* type */
667 1, /* size (0 = byte, 1 = short, 2 = long) */
669 FALSE
, /* pc_relative */
671 complain_overflow_signed
, /* complain_on_overflow */
672 bfd_elf_generic_reloc
, /* special_function */
673 "R_SH_PSHL", /* name */
674 FALSE
, /* partial_inplace */
677 FALSE
), /* pcrel_offset */
679 #ifdef INCLUDE_SHMEDIA
680 /* Used in SHLLI.L and SHLRI.L. */
681 HOWTO (R_SH_DIR5U
, /* type */
683 2, /* size (0 = byte, 1 = short, 2 = long) */
685 FALSE
, /* pc_relative */
687 complain_overflow_unsigned
, /* complain_on_overflow */
688 bfd_elf_generic_reloc
, /* special_function */
689 "R_SH_DIR5U", /* name */
690 FALSE
, /* partial_inplace */
692 0xfc00, /* dst_mask */
693 FALSE
), /* pcrel_offset */
695 /* Used in SHARI, SHLLI et al. */
696 HOWTO (R_SH_DIR6U
, /* type */
698 2, /* size (0 = byte, 1 = short, 2 = long) */
700 FALSE
, /* pc_relative */
702 complain_overflow_unsigned
, /* complain_on_overflow */
703 bfd_elf_generic_reloc
, /* special_function */
704 "R_SH_DIR6U", /* name */
705 FALSE
, /* partial_inplace */
707 0xfc00, /* dst_mask */
708 FALSE
), /* pcrel_offset */
710 /* Used in BxxI, LDHI.L et al. */
711 HOWTO (R_SH_DIR6S
, /* type */
713 2, /* size (0 = byte, 1 = short, 2 = long) */
715 FALSE
, /* pc_relative */
717 complain_overflow_signed
, /* complain_on_overflow */
718 bfd_elf_generic_reloc
, /* special_function */
719 "R_SH_DIR6S", /* name */
720 FALSE
, /* partial_inplace */
722 0xfc00, /* dst_mask */
723 FALSE
), /* pcrel_offset */
725 /* Used in ADDI, ANDI et al. */
726 HOWTO (R_SH_DIR10S
, /* type */
728 2, /* size (0 = byte, 1 = short, 2 = long) */
730 FALSE
, /* pc_relative */
732 complain_overflow_signed
, /* complain_on_overflow */
733 bfd_elf_generic_reloc
, /* special_function */
734 "R_SH_DIR10S", /* name */
735 FALSE
, /* partial_inplace */
737 0xffc00, /* dst_mask */
738 FALSE
), /* pcrel_offset */
740 /* Used in LD.UW, ST.W et al. */
741 HOWTO (R_SH_DIR10SW
, /* type */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
745 FALSE
, /* pc_relative */
747 complain_overflow_signed
, /* complain_on_overflow */
748 bfd_elf_generic_reloc
, /* special_function */
749 "R_SH_DIR10SW", /* name */
750 FALSE
, /* partial_inplace */
752 0xffc00, /* dst_mask */
753 FALSE
), /* pcrel_offset */
755 /* Used in LD.L, FLD.S et al. */
756 HOWTO (R_SH_DIR10SL
, /* type */
758 2, /* size (0 = byte, 1 = short, 2 = long) */
760 FALSE
, /* pc_relative */
762 complain_overflow_signed
, /* complain_on_overflow */
763 bfd_elf_generic_reloc
, /* special_function */
764 "R_SH_DIR10SL", /* name */
765 FALSE
, /* partial_inplace */
767 0xffc00, /* dst_mask */
768 FALSE
), /* pcrel_offset */
770 /* Used in FLD.D, FST.P et al. */
771 HOWTO (R_SH_DIR10SQ
, /* type */
773 2, /* size (0 = byte, 1 = short, 2 = long) */
775 FALSE
, /* pc_relative */
777 complain_overflow_signed
, /* complain_on_overflow */
778 bfd_elf_generic_reloc
, /* special_function */
779 "R_SH_DIR10SQ", /* name */
780 FALSE
, /* partial_inplace */
782 0xffc00, /* dst_mask */
783 FALSE
), /* pcrel_offset */
797 HOWTO (R_SH_DIR16S
, /* type */
799 1, /* size (0 = byte, 1 = short, 2 = long) */
801 FALSE
, /* pc_relative */
803 complain_overflow_signed
, /* complain_on_overflow */
804 bfd_elf_generic_reloc
, /* special_function */
805 "R_SH_DIR16S", /* name */
806 FALSE
, /* partial_inplace */
808 0xffff, /* dst_mask */
809 FALSE
), /* pcrel_offset */
902 HOWTO (R_SH_TLS_GD_32
, /* type */
904 2, /* size (0 = byte, 1 = short, 2 = long) */
906 FALSE
, /* pc_relative */
908 complain_overflow_bitfield
, /* complain_on_overflow */
909 bfd_elf_generic_reloc
, /* */
910 "R_SH_TLS_GD_32", /* name */
911 TRUE
, /* partial_inplace */
912 0xffffffff, /* src_mask */
913 0xffffffff, /* dst_mask */
914 FALSE
), /* pcrel_offset */
916 HOWTO (R_SH_TLS_LD_32
, /* type */
918 2, /* size (0 = byte, 1 = short, 2 = long) */
920 FALSE
, /* pc_relative */
922 complain_overflow_bitfield
, /* complain_on_overflow */
923 bfd_elf_generic_reloc
, /* */
924 "R_SH_TLS_LD_32", /* name */
925 TRUE
, /* partial_inplace */
926 0xffffffff, /* src_mask */
927 0xffffffff, /* dst_mask */
928 FALSE
), /* pcrel_offset */
930 HOWTO (R_SH_TLS_LDO_32
, /* type */
932 2, /* size (0 = byte, 1 = short, 2 = long) */
934 FALSE
, /* pc_relative */
936 complain_overflow_bitfield
, /* complain_on_overflow */
937 bfd_elf_generic_reloc
, /* */
938 "R_SH_TLS_LDO_32", /* name */
939 TRUE
, /* partial_inplace */
940 0xffffffff, /* src_mask */
941 0xffffffff, /* dst_mask */
942 FALSE
), /* pcrel_offset */
944 HOWTO (R_SH_TLS_IE_32
, /* type */
946 2, /* size (0 = byte, 1 = short, 2 = long) */
948 FALSE
, /* pc_relative */
950 complain_overflow_bitfield
, /* complain_on_overflow */
951 bfd_elf_generic_reloc
, /* */
952 "R_SH_TLS_IE_32", /* name */
953 TRUE
, /* partial_inplace */
954 0xffffffff, /* src_mask */
955 0xffffffff, /* dst_mask */
956 FALSE
), /* pcrel_offset */
958 HOWTO (R_SH_TLS_LE_32
, /* type */
960 2, /* size (0 = byte, 1 = short, 2 = long) */
962 FALSE
, /* pc_relative */
964 complain_overflow_bitfield
, /* complain_on_overflow */
965 bfd_elf_generic_reloc
, /* */
966 "R_SH_TLS_LE_32", /* name */
967 TRUE
, /* partial_inplace */
968 0xffffffff, /* src_mask */
969 0xffffffff, /* dst_mask */
970 FALSE
), /* pcrel_offset */
972 HOWTO (R_SH_TLS_DTPMOD32
, /* type */
974 2, /* size (0 = byte, 1 = short, 2 = long) */
976 FALSE
, /* pc_relative */
978 complain_overflow_bitfield
, /* complain_on_overflow */
979 bfd_elf_generic_reloc
, /* */
980 "R_SH_TLS_DTPMOD32", /* name */
981 TRUE
, /* partial_inplace */
982 0xffffffff, /* src_mask */
983 0xffffffff, /* dst_mask */
984 FALSE
), /* pcrel_offset */
986 HOWTO (R_SH_TLS_DTPOFF32
, /* type */
988 2, /* size (0 = byte, 1 = short, 2 = long) */
990 FALSE
, /* pc_relative */
992 complain_overflow_bitfield
, /* complain_on_overflow */
993 bfd_elf_generic_reloc
, /* */
994 "R_SH_TLS_DTPOFF32", /* name */
995 TRUE
, /* partial_inplace */
996 0xffffffff, /* src_mask */
997 0xffffffff, /* dst_mask */
998 FALSE
), /* pcrel_offset */
1000 HOWTO (R_SH_TLS_TPOFF32
, /* type */
1002 2, /* size (0 = byte, 1 = short, 2 = long) */
1004 FALSE
, /* pc_relative */
1006 complain_overflow_bitfield
, /* complain_on_overflow */
1007 bfd_elf_generic_reloc
, /* */
1008 "R_SH_TLS_TPOFF32", /* name */
1009 TRUE
, /* partial_inplace */
1010 0xffffffff, /* src_mask */
1011 0xffffffff, /* dst_mask */
1012 FALSE
), /* pcrel_offset */
1023 HOWTO (R_SH_GOT32
, /* type */
1025 2, /* size (0 = byte, 1 = short, 2 = long) */
1027 FALSE
, /* pc_relative */
1029 complain_overflow_bitfield
, /* complain_on_overflow */
1030 bfd_elf_generic_reloc
, /* */
1031 "R_SH_GOT32", /* name */
1032 TRUE
, /* partial_inplace */
1033 0xffffffff, /* src_mask */
1034 0xffffffff, /* dst_mask */
1035 FALSE
), /* pcrel_offset */
1037 HOWTO (R_SH_PLT32
, /* type */
1039 2, /* size (0 = byte, 1 = short, 2 = long) */
1041 TRUE
, /* pc_relative */
1043 complain_overflow_bitfield
, /* complain_on_overflow */
1044 bfd_elf_generic_reloc
, /* */
1045 "R_SH_PLT32", /* name */
1046 TRUE
, /* partial_inplace */
1047 0xffffffff, /* src_mask */
1048 0xffffffff, /* dst_mask */
1049 TRUE
), /* pcrel_offset */
1051 HOWTO (R_SH_COPY
, /* type */
1053 2, /* size (0 = byte, 1 = short, 2 = long) */
1055 FALSE
, /* pc_relative */
1057 complain_overflow_bitfield
, /* complain_on_overflow */
1058 bfd_elf_generic_reloc
, /* */
1059 "R_SH_COPY", /* name */
1060 TRUE
, /* partial_inplace */
1061 0xffffffff, /* src_mask */
1062 0xffffffff, /* dst_mask */
1063 FALSE
), /* pcrel_offset */
1065 HOWTO (R_SH_GLOB_DAT
, /* type */
1067 2, /* size (0 = byte, 1 = short, 2 = long) */
1069 FALSE
, /* pc_relative */
1071 complain_overflow_bitfield
, /* complain_on_overflow */
1072 bfd_elf_generic_reloc
, /* */
1073 "R_SH_GLOB_DAT", /* name */
1074 TRUE
, /* partial_inplace */
1075 0xffffffff, /* src_mask */
1076 0xffffffff, /* dst_mask */
1077 FALSE
), /* pcrel_offset */
1079 HOWTO (R_SH_JMP_SLOT
, /* type */
1081 2, /* size (0 = byte, 1 = short, 2 = long) */
1083 FALSE
, /* pc_relative */
1085 complain_overflow_bitfield
, /* complain_on_overflow */
1086 bfd_elf_generic_reloc
, /* */
1087 "R_SH_JMP_SLOT", /* name */
1088 TRUE
, /* partial_inplace */
1089 0xffffffff, /* src_mask */
1090 0xffffffff, /* dst_mask */
1091 FALSE
), /* pcrel_offset */
1093 HOWTO (R_SH_RELATIVE
, /* type */
1095 2, /* size (0 = byte, 1 = short, 2 = long) */
1097 FALSE
, /* pc_relative */
1099 complain_overflow_bitfield
, /* complain_on_overflow */
1100 bfd_elf_generic_reloc
, /* */
1101 "R_SH_RELATIVE", /* name */
1102 TRUE
, /* partial_inplace */
1103 0xffffffff, /* src_mask */
1104 0xffffffff, /* dst_mask */
1105 FALSE
), /* pcrel_offset */
1107 HOWTO (R_SH_GOTOFF
, /* type */
1109 2, /* size (0 = byte, 1 = short, 2 = long) */
1111 FALSE
, /* pc_relative */
1113 complain_overflow_bitfield
, /* complain_on_overflow */
1114 bfd_elf_generic_reloc
, /* */
1115 "R_SH_GOTOFF", /* name */
1116 TRUE
, /* partial_inplace */
1117 0xffffffff, /* src_mask */
1118 0xffffffff, /* dst_mask */
1119 FALSE
), /* pcrel_offset */
1121 HOWTO (R_SH_GOTPC
, /* type */
1123 2, /* size (0 = byte, 1 = short, 2 = long) */
1125 TRUE
, /* pc_relative */
1127 complain_overflow_bitfield
, /* complain_on_overflow */
1128 bfd_elf_generic_reloc
, /* */
1129 "R_SH_GOTPC", /* name */
1130 TRUE
, /* partial_inplace */
1131 0xffffffff, /* src_mask */
1132 0xffffffff, /* dst_mask */
1133 TRUE
), /* pcrel_offset */
1135 HOWTO (R_SH_GOTPLT32
, /* type */
1137 2, /* size (0 = byte, 1 = short, 2 = long) */
1139 FALSE
, /* pc_relative */
1141 complain_overflow_bitfield
, /* complain_on_overflow */
1142 bfd_elf_generic_reloc
, /* */
1143 "R_SH_GOTPLT32", /* name */
1144 FALSE
, /* partial_inplace */
1145 0xffffffff, /* src_mask */
1146 0xffffffff, /* dst_mask */
1147 FALSE
), /* pcrel_offset */
1149 #ifdef INCLUDE_SHMEDIA
1150 /* Used in MOVI and SHORI (x & 65536). */
1151 HOWTO (R_SH_GOT_LOW16
, /* type */
1153 2, /* size (0 = byte, 1 = short, 2 = long) */
1155 FALSE
, /* pc_relative */
1157 complain_overflow_dont
, /* complain_on_overflow */
1158 bfd_elf_generic_reloc
, /* special_function */
1159 "R_SH_GOT_LOW16", /* name */
1160 FALSE
, /* partial_inplace */
1162 0x3fffc00, /* dst_mask */
1163 FALSE
), /* pcrel_offset */
1165 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1166 HOWTO (R_SH_GOT_MEDLOW16
, /* type */
1167 16, /* rightshift */
1168 2, /* size (0 = byte, 1 = short, 2 = long) */
1170 FALSE
, /* pc_relative */
1172 complain_overflow_dont
, /* complain_on_overflow */
1173 bfd_elf_generic_reloc
, /* special_function */
1174 "R_SH_GOT_MEDLOW16", /* name */
1175 FALSE
, /* partial_inplace */
1177 0x3fffc00, /* dst_mask */
1178 FALSE
), /* pcrel_offset */
1180 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1181 HOWTO (R_SH_GOT_MEDHI16
, /* type */
1182 32, /* rightshift */
1183 2, /* size (0 = byte, 1 = short, 2 = long) */
1185 FALSE
, /* pc_relative */
1187 complain_overflow_dont
, /* complain_on_overflow */
1188 bfd_elf_generic_reloc
, /* special_function */
1189 "R_SH_GOT_MEDHI16", /* name */
1190 FALSE
, /* partial_inplace */
1192 0x3fffc00, /* dst_mask */
1193 FALSE
), /* pcrel_offset */
1195 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1196 HOWTO (R_SH_GOT_HI16
, /* type */
1197 48, /* rightshift */
1198 2, /* size (0 = byte, 1 = short, 2 = long) */
1200 FALSE
, /* pc_relative */
1202 complain_overflow_dont
, /* complain_on_overflow */
1203 bfd_elf_generic_reloc
, /* special_function */
1204 "R_SH_GOT_HI16", /* name */
1205 FALSE
, /* partial_inplace */
1207 0x3fffc00, /* dst_mask */
1208 FALSE
), /* pcrel_offset */
1210 /* Used in MOVI and SHORI (x & 65536). */
1211 HOWTO (R_SH_GOTPLT_LOW16
, /* type */
1213 2, /* size (0 = byte, 1 = short, 2 = long) */
1215 FALSE
, /* pc_relative */
1217 complain_overflow_dont
, /* complain_on_overflow */
1218 bfd_elf_generic_reloc
, /* special_function */
1219 "R_SH_GOTPLT_LOW16", /* name */
1220 FALSE
, /* partial_inplace */
1222 0x3fffc00, /* dst_mask */
1223 FALSE
), /* pcrel_offset */
1225 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1226 HOWTO (R_SH_GOTPLT_MEDLOW16
, /* type */
1227 16, /* rightshift */
1228 2, /* size (0 = byte, 1 = short, 2 = long) */
1230 FALSE
, /* pc_relative */
1232 complain_overflow_dont
, /* complain_on_overflow */
1233 bfd_elf_generic_reloc
, /* special_function */
1234 "R_SH_GOTPLT_MEDLOW16", /* name */
1235 FALSE
, /* partial_inplace */
1237 0x3fffc00, /* dst_mask */
1238 FALSE
), /* pcrel_offset */
1240 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1241 HOWTO (R_SH_GOTPLT_MEDHI16
, /* type */
1242 32, /* rightshift */
1243 2, /* size (0 = byte, 1 = short, 2 = long) */
1245 FALSE
, /* pc_relative */
1247 complain_overflow_dont
, /* complain_on_overflow */
1248 bfd_elf_generic_reloc
, /* special_function */
1249 "R_SH_GOTPLT_MEDHI16", /* name */
1250 FALSE
, /* partial_inplace */
1252 0x3fffc00, /* dst_mask */
1253 FALSE
), /* pcrel_offset */
1255 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1256 HOWTO (R_SH_GOTPLT_HI16
, /* type */
1257 48, /* rightshift */
1258 2, /* size (0 = byte, 1 = short, 2 = long) */
1260 FALSE
, /* pc_relative */
1262 complain_overflow_dont
, /* complain_on_overflow */
1263 bfd_elf_generic_reloc
, /* special_function */
1264 "R_SH_GOTPLT_HI16", /* name */
1265 FALSE
, /* partial_inplace */
1267 0x3fffc00, /* dst_mask */
1268 FALSE
), /* pcrel_offset */
1270 /* Used in MOVI and SHORI (x & 65536). */
1271 HOWTO (R_SH_PLT_LOW16
, /* type */
1273 2, /* size (0 = byte, 1 = short, 2 = long) */
1275 TRUE
, /* pc_relative */
1277 complain_overflow_dont
, /* complain_on_overflow */
1278 bfd_elf_generic_reloc
, /* special_function */
1279 "R_SH_PLT_LOW16", /* name */
1280 FALSE
, /* partial_inplace */
1282 0x3fffc00, /* dst_mask */
1283 TRUE
), /* pcrel_offset */
1285 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1286 HOWTO (R_SH_PLT_MEDLOW16
, /* type */
1287 16, /* rightshift */
1288 2, /* size (0 = byte, 1 = short, 2 = long) */
1290 TRUE
, /* pc_relative */
1292 complain_overflow_dont
, /* complain_on_overflow */
1293 bfd_elf_generic_reloc
, /* special_function */
1294 "R_SH_PLT_MEDLOW16", /* name */
1295 FALSE
, /* partial_inplace */
1297 0x3fffc00, /* dst_mask */
1298 TRUE
), /* pcrel_offset */
1300 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1301 HOWTO (R_SH_PLT_MEDHI16
, /* type */
1302 32, /* rightshift */
1303 2, /* size (0 = byte, 1 = short, 2 = long) */
1305 TRUE
, /* pc_relative */
1307 complain_overflow_dont
, /* complain_on_overflow */
1308 bfd_elf_generic_reloc
, /* special_function */
1309 "R_SH_PLT_MEDHI16", /* name */
1310 FALSE
, /* partial_inplace */
1312 0x3fffc00, /* dst_mask */
1313 TRUE
), /* pcrel_offset */
1315 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1316 HOWTO (R_SH_PLT_HI16
, /* type */
1317 48, /* rightshift */
1318 2, /* size (0 = byte, 1 = short, 2 = long) */
1320 TRUE
, /* pc_relative */
1322 complain_overflow_dont
, /* complain_on_overflow */
1323 bfd_elf_generic_reloc
, /* special_function */
1324 "R_SH_PLT_HI16", /* name */
1325 FALSE
, /* partial_inplace */
1327 0x3fffc00, /* dst_mask */
1328 TRUE
), /* pcrel_offset */
1330 /* Used in MOVI and SHORI (x & 65536). */
1331 HOWTO (R_SH_GOTOFF_LOW16
, /* type */
1333 2, /* size (0 = byte, 1 = short, 2 = long) */
1335 FALSE
, /* pc_relative */
1337 complain_overflow_dont
, /* complain_on_overflow */
1338 bfd_elf_generic_reloc
, /* special_function */
1339 "R_SH_GOTOFF_LOW16", /* name */
1340 FALSE
, /* partial_inplace */
1342 0x3fffc00, /* dst_mask */
1343 FALSE
), /* pcrel_offset */
1345 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1346 HOWTO (R_SH_GOTOFF_MEDLOW16
, /* type */
1347 16, /* rightshift */
1348 2, /* size (0 = byte, 1 = short, 2 = long) */
1350 FALSE
, /* pc_relative */
1352 complain_overflow_dont
, /* complain_on_overflow */
1353 bfd_elf_generic_reloc
, /* special_function */
1354 "R_SH_GOTOFF_MEDLOW16", /* name */
1355 FALSE
, /* partial_inplace */
1357 0x3fffc00, /* dst_mask */
1358 FALSE
), /* pcrel_offset */
1360 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1361 HOWTO (R_SH_GOTOFF_MEDHI16
, /* type */
1362 32, /* rightshift */
1363 2, /* size (0 = byte, 1 = short, 2 = long) */
1365 FALSE
, /* pc_relative */
1367 complain_overflow_dont
, /* complain_on_overflow */
1368 bfd_elf_generic_reloc
, /* special_function */
1369 "R_SH_GOTOFF_MEDHI16", /* name */
1370 FALSE
, /* partial_inplace */
1372 0x3fffc00, /* dst_mask */
1373 FALSE
), /* pcrel_offset */
1375 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1376 HOWTO (R_SH_GOTOFF_HI16
, /* type */
1377 48, /* rightshift */
1378 2, /* size (0 = byte, 1 = short, 2 = long) */
1380 FALSE
, /* pc_relative */
1382 complain_overflow_dont
, /* complain_on_overflow */
1383 bfd_elf_generic_reloc
, /* special_function */
1384 "R_SH_GOTOFF_HI16", /* name */
1385 FALSE
, /* partial_inplace */
1387 0x3fffc00, /* dst_mask */
1388 FALSE
), /* pcrel_offset */
1390 /* Used in MOVI and SHORI (x & 65536). */
1391 HOWTO (R_SH_GOTPC_LOW16
, /* type */
1393 2, /* size (0 = byte, 1 = short, 2 = long) */
1395 TRUE
, /* pc_relative */
1397 complain_overflow_dont
, /* complain_on_overflow */
1398 bfd_elf_generic_reloc
, /* special_function */
1399 "R_SH_GOTPC_LOW16", /* name */
1400 FALSE
, /* partial_inplace */
1402 0x3fffc00, /* dst_mask */
1403 TRUE
), /* pcrel_offset */
1405 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1406 HOWTO (R_SH_GOTPC_MEDLOW16
, /* type */
1407 16, /* rightshift */
1408 2, /* size (0 = byte, 1 = short, 2 = long) */
1410 TRUE
, /* pc_relative */
1412 complain_overflow_dont
, /* complain_on_overflow */
1413 bfd_elf_generic_reloc
, /* special_function */
1414 "R_SH_GOTPC_MEDLOW16", /* name */
1415 FALSE
, /* partial_inplace */
1417 0x3fffc00, /* dst_mask */
1418 TRUE
), /* pcrel_offset */
1420 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1421 HOWTO (R_SH_GOTPC_MEDHI16
, /* type */
1422 32, /* rightshift */
1423 2, /* size (0 = byte, 1 = short, 2 = long) */
1425 TRUE
, /* pc_relative */
1427 complain_overflow_dont
, /* complain_on_overflow */
1428 bfd_elf_generic_reloc
, /* special_function */
1429 "R_SH_GOTPC_MEDHI16", /* name */
1430 FALSE
, /* partial_inplace */
1432 0x3fffc00, /* dst_mask */
1433 TRUE
), /* pcrel_offset */
1435 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1436 HOWTO (R_SH_GOTPC_HI16
, /* type */
1437 48, /* rightshift */
1438 2, /* size (0 = byte, 1 = short, 2 = long) */
1440 TRUE
, /* pc_relative */
1442 complain_overflow_dont
, /* complain_on_overflow */
1443 bfd_elf_generic_reloc
, /* special_function */
1444 "R_SH_GOTPC_HI16", /* name */
1445 FALSE
, /* partial_inplace */
1447 0x3fffc00, /* dst_mask */
1448 TRUE
), /* pcrel_offset */
1450 /* Used in LD.L, FLD.S et al. */
1451 HOWTO (R_SH_GOT10BY4
, /* type */
1453 2, /* size (0 = byte, 1 = short, 2 = long) */
1455 FALSE
, /* pc_relative */
1457 complain_overflow_signed
, /* complain_on_overflow */
1458 bfd_elf_generic_reloc
, /* special_function */
1459 "R_SH_GOT10BY4", /* name */
1460 FALSE
, /* partial_inplace */
1462 0xffc00, /* dst_mask */
1463 FALSE
), /* pcrel_offset */
1465 /* Used in LD.L, FLD.S et al. */
1466 HOWTO (R_SH_GOTPLT10BY4
, /* type */
1468 2, /* size (0 = byte, 1 = short, 2 = long) */
1470 FALSE
, /* pc_relative */
1472 complain_overflow_signed
, /* complain_on_overflow */
1473 bfd_elf_generic_reloc
, /* special_function */
1474 "R_SH_GOTPLT10BY4", /* name */
1475 FALSE
, /* partial_inplace */
1477 0xffc00, /* dst_mask */
1478 FALSE
), /* pcrel_offset */
1480 /* Used in FLD.D, FST.P et al. */
1481 HOWTO (R_SH_GOT10BY8
, /* type */
1483 2, /* size (0 = byte, 1 = short, 2 = long) */
1485 FALSE
, /* pc_relative */
1487 complain_overflow_signed
, /* complain_on_overflow */
1488 bfd_elf_generic_reloc
, /* special_function */
1489 "R_SH_GOT10BY8", /* name */
1490 FALSE
, /* partial_inplace */
1492 0xffc00, /* dst_mask */
1493 FALSE
), /* pcrel_offset */
1495 /* Used in FLD.D, FST.P et al. */
1496 HOWTO (R_SH_GOTPLT10BY8
, /* type */
1498 2, /* size (0 = byte, 1 = short, 2 = long) */
1500 FALSE
, /* pc_relative */
1502 complain_overflow_signed
, /* complain_on_overflow */
1503 bfd_elf_generic_reloc
, /* special_function */
1504 "R_SH_GOTPLT10BY8", /* name */
1505 FALSE
, /* partial_inplace */
1507 0xffc00, /* dst_mask */
1508 FALSE
), /* pcrel_offset */
1510 HOWTO (R_SH_COPY64
, /* type */
1512 4, /* size (0 = byte, 1 = short, 2 = long) */
1514 FALSE
, /* pc_relative */
1516 complain_overflow_dont
, /* complain_on_overflow */
1517 bfd_elf_generic_reloc
, /* special_function */
1518 "R_SH_COPY64", /* name */
1519 FALSE
, /* partial_inplace */
1521 ((bfd_vma
) 0) - 1, /* dst_mask */
1522 FALSE
), /* pcrel_offset */
1524 HOWTO (R_SH_GLOB_DAT64
, /* type */
1526 4, /* size (0 = byte, 1 = short, 2 = long) */
1528 FALSE
, /* pc_relative */
1530 complain_overflow_dont
, /* complain_on_overflow */
1531 bfd_elf_generic_reloc
, /* special_function */
1532 "R_SH_GLOB_DAT64", /* name */
1533 FALSE
, /* partial_inplace */
1535 ((bfd_vma
) 0) - 1, /* dst_mask */
1536 FALSE
), /* pcrel_offset */
1538 HOWTO (R_SH_JMP_SLOT64
, /* type */
1540 4, /* size (0 = byte, 1 = short, 2 = long) */
1542 FALSE
, /* pc_relative */
1544 complain_overflow_dont
, /* complain_on_overflow */
1545 bfd_elf_generic_reloc
, /* special_function */
1546 "R_SH_JMP_SLOT64", /* name */
1547 FALSE
, /* partial_inplace */
1549 ((bfd_vma
) 0) - 1, /* dst_mask */
1550 FALSE
), /* pcrel_offset */
1552 HOWTO (R_SH_RELATIVE64
, /* type */
1554 4, /* size (0 = byte, 1 = short, 2 = long) */
1556 FALSE
, /* pc_relative */
1558 complain_overflow_dont
, /* complain_on_overflow */
1559 bfd_elf_generic_reloc
, /* special_function */
1560 "R_SH_RELATIVE64", /* name */
1561 FALSE
, /* partial_inplace */
1563 ((bfd_vma
) 0) - 1, /* dst_mask */
1564 FALSE
), /* pcrel_offset */
1612 /* Relocations for SHmedia code. None of these are partial_inplace or
1613 use the field being relocated (except R_SH_PT_16). */
1615 /* The assembler will generate this reloc before a block of SHmedia
1616 instructions. A section should be processed as assuming it contains
1617 data, unless this reloc is seen. Note that a block of SHcompact
1618 instructions are instead preceded by R_SH_CODE.
1619 This is currently not implemented, but should be used for SHmedia
1620 linker relaxation. */
1621 HOWTO (R_SH_SHMEDIA_CODE
, /* type */
1623 1, /* size (0 = byte, 1 = short, 2 = long) */
1625 FALSE
, /* pc_relative */
1627 complain_overflow_unsigned
, /* complain_on_overflow */
1628 sh_elf_ignore_reloc
, /* special_function */
1629 "R_SH_SHMEDIA_CODE", /* name */
1630 FALSE
, /* partial_inplace */
1633 FALSE
), /* pcrel_offset */
1635 /* The assembler will generate this reloc at a PTA or PTB instruction,
1636 and the linker checks the right type of target, or changes a PTA to a
1637 PTB, if the original insn was PT. */
1638 HOWTO (R_SH_PT_16
, /* type */
1640 2, /* size (0 = byte, 1 = short, 2 = long) */
1642 TRUE
, /* pc_relative */
1644 complain_overflow_signed
, /* complain_on_overflow */
1645 bfd_elf_generic_reloc
, /* special_function */
1646 "R_SH_PT_16", /* name */
1647 FALSE
, /* partial_inplace */
1649 0x3fffc00, /* dst_mask */
1650 TRUE
), /* pcrel_offset */
1652 /* Used in unexpanded MOVI. */
1653 HOWTO (R_SH_IMMS16
, /* type */
1655 2, /* size (0 = byte, 1 = short, 2 = long) */
1657 FALSE
, /* pc_relative */
1659 complain_overflow_signed
, /* complain_on_overflow */
1660 bfd_elf_generic_reloc
, /* special_function */
1661 "R_SH_IMMS16", /* name */
1662 FALSE
, /* partial_inplace */
1664 0x3fffc00, /* dst_mask */
1665 FALSE
), /* pcrel_offset */
1667 /* Used in SHORI. */
1668 HOWTO (R_SH_IMMU16
, /* type */
1670 2, /* size (0 = byte, 1 = short, 2 = long) */
1672 FALSE
, /* pc_relative */
1674 complain_overflow_unsigned
, /* complain_on_overflow */
1675 bfd_elf_generic_reloc
, /* special_function */
1676 "R_SH_IMMU16", /* name */
1677 FALSE
, /* partial_inplace */
1679 0x3fffc00, /* dst_mask */
1680 FALSE
), /* pcrel_offset */
1682 /* Used in MOVI and SHORI (x & 65536). */
1683 HOWTO (R_SH_IMM_LOW16
, /* type */
1685 2, /* size (0 = byte, 1 = short, 2 = long) */
1687 FALSE
, /* pc_relative */
1689 complain_overflow_dont
, /* complain_on_overflow */
1690 bfd_elf_generic_reloc
, /* special_function */
1691 "R_SH_IMM_LOW16", /* name */
1692 FALSE
, /* partial_inplace */
1694 0x3fffc00, /* dst_mask */
1695 FALSE
), /* pcrel_offset */
1697 /* Used in MOVI and SHORI ((x - $) & 65536). */
1698 HOWTO (R_SH_IMM_LOW16_PCREL
, /* type */
1700 2, /* size (0 = byte, 1 = short, 2 = long) */
1702 TRUE
, /* pc_relative */
1704 complain_overflow_dont
, /* complain_on_overflow */
1705 bfd_elf_generic_reloc
, /* special_function */
1706 "R_SH_IMM_LOW16_PCREL", /* name */
1707 FALSE
, /* partial_inplace */
1709 0x3fffc00, /* dst_mask */
1710 TRUE
), /* pcrel_offset */
1712 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1713 HOWTO (R_SH_IMM_MEDLOW16
, /* type */
1714 16, /* rightshift */
1715 2, /* size (0 = byte, 1 = short, 2 = long) */
1717 FALSE
, /* pc_relative */
1719 complain_overflow_dont
, /* complain_on_overflow */
1720 bfd_elf_generic_reloc
, /* special_function */
1721 "R_SH_IMM_MEDLOW16", /* name */
1722 FALSE
, /* partial_inplace */
1724 0x3fffc00, /* dst_mask */
1725 FALSE
), /* pcrel_offset */
1727 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1728 HOWTO (R_SH_IMM_MEDLOW16_PCREL
, /* type */
1729 16, /* rightshift */
1730 2, /* size (0 = byte, 1 = short, 2 = long) */
1732 TRUE
, /* pc_relative */
1734 complain_overflow_dont
, /* complain_on_overflow */
1735 bfd_elf_generic_reloc
, /* special_function */
1736 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1737 FALSE
, /* partial_inplace */
1739 0x3fffc00, /* dst_mask */
1740 TRUE
), /* pcrel_offset */
1742 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1743 HOWTO (R_SH_IMM_MEDHI16
, /* type */
1744 32, /* rightshift */
1745 2, /* size (0 = byte, 1 = short, 2 = long) */
1747 FALSE
, /* pc_relative */
1749 complain_overflow_dont
, /* complain_on_overflow */
1750 bfd_elf_generic_reloc
, /* special_function */
1751 "R_SH_IMM_MEDHI16", /* name */
1752 FALSE
, /* partial_inplace */
1754 0x3fffc00, /* dst_mask */
1755 FALSE
), /* pcrel_offset */
1757 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1758 HOWTO (R_SH_IMM_MEDHI16_PCREL
, /* type */
1759 32, /* rightshift */
1760 2, /* size (0 = byte, 1 = short, 2 = long) */
1762 TRUE
, /* pc_relative */
1764 complain_overflow_dont
, /* complain_on_overflow */
1765 bfd_elf_generic_reloc
, /* special_function */
1766 "R_SH_IMM_MEDHI16_PCREL", /* name */
1767 FALSE
, /* partial_inplace */
1769 0x3fffc00, /* dst_mask */
1770 TRUE
), /* pcrel_offset */
1772 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1773 HOWTO (R_SH_IMM_HI16
, /* type */
1774 48, /* rightshift */
1775 2, /* size (0 = byte, 1 = short, 2 = long) */
1777 FALSE
, /* pc_relative */
1779 complain_overflow_dont
, /* complain_on_overflow */
1780 bfd_elf_generic_reloc
, /* special_function */
1781 "R_SH_IMM_HI16", /* name */
1782 FALSE
, /* partial_inplace */
1784 0x3fffc00, /* dst_mask */
1785 FALSE
), /* pcrel_offset */
1787 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1788 HOWTO (R_SH_IMM_HI16_PCREL
, /* type */
1789 48, /* rightshift */
1790 2, /* size (0 = byte, 1 = short, 2 = long) */
1792 TRUE
, /* pc_relative */
1794 complain_overflow_dont
, /* complain_on_overflow */
1795 bfd_elf_generic_reloc
, /* special_function */
1796 "R_SH_IMM_HI16_PCREL", /* name */
1797 FALSE
, /* partial_inplace */
1799 0x3fffc00, /* dst_mask */
1800 TRUE
), /* pcrel_offset */
1802 /* For the .uaquad pseudo. */
1803 HOWTO (R_SH_64
, /* type */
1805 4, /* size (0 = byte, 1 = short, 2 = long) */
1807 FALSE
, /* pc_relative */
1809 complain_overflow_dont
, /* complain_on_overflow */
1810 bfd_elf_generic_reloc
, /* special_function */
1811 "R_SH_64", /* name */
1812 FALSE
, /* partial_inplace */
1814 ((bfd_vma
) 0) - 1, /* dst_mask */
1815 FALSE
), /* pcrel_offset */
1817 /* For the .uaquad pseudo, (x - $). */
1818 HOWTO (R_SH_64_PCREL
, /* type */
1819 48, /* rightshift */
1820 2, /* size (0 = byte, 1 = short, 2 = long) */
1822 TRUE
, /* pc_relative */
1824 complain_overflow_dont
, /* complain_on_overflow */
1825 bfd_elf_generic_reloc
, /* special_function */
1826 "R_SH_64_PCREL", /* name */
1827 FALSE
, /* partial_inplace */
1829 ((bfd_vma
) 0) - 1, /* dst_mask */
1830 TRUE
), /* pcrel_offset */
1835 static bfd_reloc_status_type
1836 sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED
, bfd
*input_bfd
,
1837 asection
*input_section
, bfd_byte
*contents
,
1838 bfd_vma addr
, asection
*symbol_section
,
1839 bfd_vma start
, bfd_vma end
)
1841 static bfd_vma last_addr
;
1842 static asection
*last_symbol_section
;
1843 bfd_byte
*start_ptr
, *ptr
, *last_ptr
;
1848 /* Sanity check the address. */
1849 if (addr
> input_section
->_raw_size
)
1850 return bfd_reloc_outofrange
;
1852 /* We require the start and end relocations to be processed consecutively -
1853 although we allow then to be processed forwards or backwards. */
1857 last_symbol_section
= symbol_section
;
1858 return bfd_reloc_ok
;
1860 if (last_addr
!= addr
)
1864 if (! symbol_section
|| last_symbol_section
!= symbol_section
|| end
< start
)
1865 return bfd_reloc_outofrange
;
1867 /* Get the symbol_section contents. */
1868 if (symbol_section
!= input_section
)
1870 if (elf_section_data (symbol_section
)->this_hdr
.contents
!= NULL
)
1871 contents
= elf_section_data (symbol_section
)->this_hdr
.contents
;
1874 contents
= (bfd_byte
*) bfd_malloc (symbol_section
->_raw_size
);
1875 if (contents
== NULL
)
1876 return bfd_reloc_outofrange
;
1877 if (! bfd_get_section_contents (input_bfd
, symbol_section
, contents
,
1879 symbol_section
->_raw_size
))
1882 return bfd_reloc_outofrange
;
1886 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
1887 start_ptr
= contents
+ start
;
1888 for (cum_diff
= -6, ptr
= contents
+ end
; cum_diff
< 0 && ptr
> start_ptr
;)
1890 for (last_ptr
= ptr
, ptr
-= 4; ptr
>= start_ptr
&& IS_PPI (ptr
);)
1893 diff
= (last_ptr
- ptr
) >> 1;
1894 cum_diff
+= diff
& 1;
1897 /* Calculate the start / end values to load into rs / re minus four -
1898 so that will cancel out the four we would otherwise have to add to
1899 addr to get the value to subtract in order to get relative addressing. */
1903 end
= (ptr
+ cum_diff
* 2) - contents
;
1907 bfd_vma start0
= start
- 4;
1909 while (start0
&& IS_PPI (contents
+ start0
))
1911 start0
= start
- 2 - ((start
- start0
) & 2);
1912 start
= start0
- cum_diff
- 2;
1916 if (contents
!= NULL
1917 && elf_section_data (symbol_section
)->this_hdr
.contents
!= contents
)
1920 insn
= bfd_get_16 (input_bfd
, contents
+ addr
);
1922 x
= (insn
& 0x200 ? end
: start
) - addr
;
1923 if (input_section
!= symbol_section
)
1924 x
+= ((symbol_section
->output_section
->vma
+ symbol_section
->output_offset
)
1925 - (input_section
->output_section
->vma
1926 + input_section
->output_offset
));
1928 if (x
< -128 || x
> 127)
1929 return bfd_reloc_overflow
;
1931 x
= (insn
& ~0xff) | (x
& 0xff);
1932 bfd_put_16 (input_bfd
, (bfd_vma
) x
, contents
+ addr
);
1934 return bfd_reloc_ok
;
1937 /* This function is used for normal relocs. This used to be like the COFF
1938 function, and is almost certainly incorrect for other ELF targets. */
1940 static bfd_reloc_status_type
1941 sh_elf_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol_in
,
1942 void *data
, asection
*input_section
, bfd
*output_bfd
,
1943 char **error_message ATTRIBUTE_UNUSED
)
1947 enum elf_sh_reloc_type r_type
;
1948 bfd_vma addr
= reloc_entry
->address
;
1949 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
1951 r_type
= (enum elf_sh_reloc_type
) reloc_entry
->howto
->type
;
1953 if (output_bfd
!= NULL
)
1955 /* Partial linking--do nothing. */
1956 reloc_entry
->address
+= input_section
->output_offset
;
1957 return bfd_reloc_ok
;
1960 /* Almost all relocs have to do with relaxing. If any work must be
1961 done for them, it has been done in sh_relax_section. */
1962 if (r_type
== R_SH_IND12W
&& (symbol_in
->flags
& BSF_LOCAL
) != 0)
1963 return bfd_reloc_ok
;
1965 if (symbol_in
!= NULL
1966 && bfd_is_und_section (symbol_in
->section
))
1967 return bfd_reloc_undefined
;
1969 if (bfd_is_com_section (symbol_in
->section
))
1972 sym_value
= (symbol_in
->value
+
1973 symbol_in
->section
->output_section
->vma
+
1974 symbol_in
->section
->output_offset
);
1979 insn
= bfd_get_32 (abfd
, hit_data
);
1980 insn
+= sym_value
+ reloc_entry
->addend
;
1981 bfd_put_32 (abfd
, (bfd_vma
) insn
, hit_data
);
1984 insn
= bfd_get_16 (abfd
, hit_data
);
1985 sym_value
+= reloc_entry
->addend
;
1986 sym_value
-= (input_section
->output_section
->vma
1987 + input_section
->output_offset
1990 sym_value
+= (insn
& 0xfff) << 1;
1992 sym_value
-= 0x1000;
1993 insn
= (insn
& 0xf000) | (sym_value
& 0xfff);
1994 bfd_put_16 (abfd
, (bfd_vma
) insn
, hit_data
);
1995 if (sym_value
< (bfd_vma
) -0x1000 || sym_value
>= 0x1000)
1996 return bfd_reloc_overflow
;
2003 return bfd_reloc_ok
;
2006 /* This function is used for relocs which are only used for relaxing,
2007 which the linker should otherwise ignore. */
2009 static bfd_reloc_status_type
2010 sh_elf_ignore_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2011 asymbol
*symbol ATTRIBUTE_UNUSED
,
2012 void *data ATTRIBUTE_UNUSED
, asection
*input_section
,
2014 char **error_message ATTRIBUTE_UNUSED
)
2016 if (output_bfd
!= NULL
)
2017 reloc_entry
->address
+= input_section
->output_offset
;
2018 return bfd_reloc_ok
;
2021 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
2023 struct elf_reloc_map
2025 bfd_reloc_code_real_type bfd_reloc_val
;
2026 unsigned char elf_reloc_val
;
2029 /* An array mapping BFD reloc codes to SH ELF relocs. */
2031 static const struct elf_reloc_map sh_reloc_map
[] =
2033 { BFD_RELOC_NONE
, R_SH_NONE
},
2034 { BFD_RELOC_32
, R_SH_DIR32
},
2035 { BFD_RELOC_16
, R_SH_DIR16
},
2036 { BFD_RELOC_8
, R_SH_DIR8
},
2037 { BFD_RELOC_CTOR
, R_SH_DIR32
},
2038 { BFD_RELOC_32_PCREL
, R_SH_REL32
},
2039 { BFD_RELOC_SH_PCDISP8BY2
, R_SH_DIR8WPN
},
2040 { BFD_RELOC_SH_PCDISP12BY2
, R_SH_IND12W
},
2041 { BFD_RELOC_SH_PCRELIMM8BY2
, R_SH_DIR8WPZ
},
2042 { BFD_RELOC_SH_PCRELIMM8BY4
, R_SH_DIR8WPL
},
2043 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
2044 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
2045 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
2046 { BFD_RELOC_SH_USES
, R_SH_USES
},
2047 { BFD_RELOC_SH_COUNT
, R_SH_COUNT
},
2048 { BFD_RELOC_SH_ALIGN
, R_SH_ALIGN
},
2049 { BFD_RELOC_SH_CODE
, R_SH_CODE
},
2050 { BFD_RELOC_SH_DATA
, R_SH_DATA
},
2051 { BFD_RELOC_SH_LABEL
, R_SH_LABEL
},
2052 { BFD_RELOC_VTABLE_INHERIT
, R_SH_GNU_VTINHERIT
},
2053 { BFD_RELOC_VTABLE_ENTRY
, R_SH_GNU_VTENTRY
},
2054 { BFD_RELOC_SH_LOOP_START
, R_SH_LOOP_START
},
2055 { BFD_RELOC_SH_LOOP_END
, R_SH_LOOP_END
},
2056 { BFD_RELOC_SH_TLS_GD_32
, R_SH_TLS_GD_32
},
2057 { BFD_RELOC_SH_TLS_LD_32
, R_SH_TLS_LD_32
},
2058 { BFD_RELOC_SH_TLS_LDO_32
, R_SH_TLS_LDO_32
},
2059 { BFD_RELOC_SH_TLS_IE_32
, R_SH_TLS_IE_32
},
2060 { BFD_RELOC_SH_TLS_LE_32
, R_SH_TLS_LE_32
},
2061 { BFD_RELOC_SH_TLS_DTPMOD32
, R_SH_TLS_DTPMOD32
},
2062 { BFD_RELOC_SH_TLS_DTPOFF32
, R_SH_TLS_DTPOFF32
},
2063 { BFD_RELOC_SH_TLS_TPOFF32
, R_SH_TLS_TPOFF32
},
2064 { BFD_RELOC_32_GOT_PCREL
, R_SH_GOT32
},
2065 { BFD_RELOC_32_PLT_PCREL
, R_SH_PLT32
},
2066 { BFD_RELOC_SH_COPY
, R_SH_COPY
},
2067 { BFD_RELOC_SH_GLOB_DAT
, R_SH_GLOB_DAT
},
2068 { BFD_RELOC_SH_JMP_SLOT
, R_SH_JMP_SLOT
},
2069 { BFD_RELOC_SH_RELATIVE
, R_SH_RELATIVE
},
2070 { BFD_RELOC_32_GOTOFF
, R_SH_GOTOFF
},
2071 { BFD_RELOC_SH_GOTPC
, R_SH_GOTPC
},
2072 { BFD_RELOC_SH_GOTPLT32
, R_SH_GOTPLT32
},
2073 #ifdef INCLUDE_SHMEDIA
2074 { BFD_RELOC_SH_GOT_LOW16
, R_SH_GOT_LOW16
},
2075 { BFD_RELOC_SH_GOT_MEDLOW16
, R_SH_GOT_MEDLOW16
},
2076 { BFD_RELOC_SH_GOT_MEDHI16
, R_SH_GOT_MEDHI16
},
2077 { BFD_RELOC_SH_GOT_HI16
, R_SH_GOT_HI16
},
2078 { BFD_RELOC_SH_GOTPLT_LOW16
, R_SH_GOTPLT_LOW16
},
2079 { BFD_RELOC_SH_GOTPLT_MEDLOW16
, R_SH_GOTPLT_MEDLOW16
},
2080 { BFD_RELOC_SH_GOTPLT_MEDHI16
, R_SH_GOTPLT_MEDHI16
},
2081 { BFD_RELOC_SH_GOTPLT_HI16
, R_SH_GOTPLT_HI16
},
2082 { BFD_RELOC_SH_PLT_LOW16
, R_SH_PLT_LOW16
},
2083 { BFD_RELOC_SH_PLT_MEDLOW16
, R_SH_PLT_MEDLOW16
},
2084 { BFD_RELOC_SH_PLT_MEDHI16
, R_SH_PLT_MEDHI16
},
2085 { BFD_RELOC_SH_PLT_HI16
, R_SH_PLT_HI16
},
2086 { BFD_RELOC_SH_GOTOFF_LOW16
, R_SH_GOTOFF_LOW16
},
2087 { BFD_RELOC_SH_GOTOFF_MEDLOW16
, R_SH_GOTOFF_MEDLOW16
},
2088 { BFD_RELOC_SH_GOTOFF_MEDHI16
, R_SH_GOTOFF_MEDHI16
},
2089 { BFD_RELOC_SH_GOTOFF_HI16
, R_SH_GOTOFF_HI16
},
2090 { BFD_RELOC_SH_GOTPC_LOW16
, R_SH_GOTPC_LOW16
},
2091 { BFD_RELOC_SH_GOTPC_MEDLOW16
, R_SH_GOTPC_MEDLOW16
},
2092 { BFD_RELOC_SH_GOTPC_MEDHI16
, R_SH_GOTPC_MEDHI16
},
2093 { BFD_RELOC_SH_GOTPC_HI16
, R_SH_GOTPC_HI16
},
2094 { BFD_RELOC_SH_COPY64
, R_SH_COPY64
},
2095 { BFD_RELOC_SH_GLOB_DAT64
, R_SH_GLOB_DAT64
},
2096 { BFD_RELOC_SH_JMP_SLOT64
, R_SH_JMP_SLOT64
},
2097 { BFD_RELOC_SH_RELATIVE64
, R_SH_RELATIVE64
},
2098 { BFD_RELOC_SH_GOT10BY4
, R_SH_GOT10BY4
},
2099 { BFD_RELOC_SH_GOT10BY8
, R_SH_GOT10BY8
},
2100 { BFD_RELOC_SH_GOTPLT10BY4
, R_SH_GOTPLT10BY4
},
2101 { BFD_RELOC_SH_GOTPLT10BY8
, R_SH_GOTPLT10BY8
},
2102 { BFD_RELOC_SH_PT_16
, R_SH_PT_16
},
2103 { BFD_RELOC_SH_SHMEDIA_CODE
, R_SH_SHMEDIA_CODE
},
2104 { BFD_RELOC_SH_IMMU5
, R_SH_DIR5U
},
2105 { BFD_RELOC_SH_IMMS6
, R_SH_DIR6S
},
2106 { BFD_RELOC_SH_IMMU6
, R_SH_DIR6U
},
2107 { BFD_RELOC_SH_IMMS10
, R_SH_DIR10S
},
2108 { BFD_RELOC_SH_IMMS10BY2
, R_SH_DIR10SW
},
2109 { BFD_RELOC_SH_IMMS10BY4
, R_SH_DIR10SL
},
2110 { BFD_RELOC_SH_IMMS10BY8
, R_SH_DIR10SQ
},
2111 { BFD_RELOC_SH_IMMS16
, R_SH_IMMS16
},
2112 { BFD_RELOC_SH_IMMU16
, R_SH_IMMU16
},
2113 { BFD_RELOC_SH_IMM_LOW16
, R_SH_IMM_LOW16
},
2114 { BFD_RELOC_SH_IMM_LOW16_PCREL
, R_SH_IMM_LOW16_PCREL
},
2115 { BFD_RELOC_SH_IMM_MEDLOW16
, R_SH_IMM_MEDLOW16
},
2116 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL
, R_SH_IMM_MEDLOW16_PCREL
},
2117 { BFD_RELOC_SH_IMM_MEDHI16
, R_SH_IMM_MEDHI16
},
2118 { BFD_RELOC_SH_IMM_MEDHI16_PCREL
, R_SH_IMM_MEDHI16_PCREL
},
2119 { BFD_RELOC_SH_IMM_HI16
, R_SH_IMM_HI16
},
2120 { BFD_RELOC_SH_IMM_HI16_PCREL
, R_SH_IMM_HI16_PCREL
},
2121 { BFD_RELOC_64
, R_SH_64
},
2122 { BFD_RELOC_64_PCREL
, R_SH_64_PCREL
},
2123 #endif /* not INCLUDE_SHMEDIA */
2126 /* Given a BFD reloc code, return the howto structure for the
2127 corresponding SH ELf reloc. */
2129 static reloc_howto_type
*
2130 sh_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2131 bfd_reloc_code_real_type code
)
2135 for (i
= 0; i
< sizeof (sh_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
2137 if (sh_reloc_map
[i
].bfd_reloc_val
== code
)
2138 return &sh_elf_howto_table
[(int) sh_reloc_map
[i
].elf_reloc_val
];
2144 /* Given an ELF reloc, fill in the howto field of a relent. */
2147 sh_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2148 Elf_Internal_Rela
*dst
)
2152 r
= ELF32_R_TYPE (dst
->r_info
);
2154 BFD_ASSERT (r
< (unsigned int) R_SH_max
);
2155 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC
|| r
> R_SH_LAST_INVALID_RELOC
);
2156 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_2
|| r
> R_SH_LAST_INVALID_RELOC_2
);
2157 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_3
|| r
> R_SH_LAST_INVALID_RELOC_3
);
2158 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_4
|| r
> R_SH_LAST_INVALID_RELOC_4
);
2159 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_5
|| r
> R_SH_LAST_INVALID_RELOC_5
);
2161 cache_ptr
->howto
= &sh_elf_howto_table
[r
];
2164 /* This function handles relaxing for SH ELF. See the corresponding
2165 function in coff-sh.c for a description of what this does. FIXME:
2166 There is a lot of duplication here between this code and the COFF
2167 specific code. The format of relocs and symbols is wound deeply
2168 into this code, but it would still be better if the duplication
2169 could be eliminated somehow. Note in particular that although both
2170 functions use symbols like R_SH_CODE, those symbols have different
2171 values; in coff-sh.c they come from include/coff/sh.h, whereas here
2172 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
2175 sh_elf_relax_section (bfd
*abfd
, asection
*sec
,
2176 struct bfd_link_info
*link_info
, bfd_boolean
*again
)
2178 Elf_Internal_Shdr
*symtab_hdr
;
2179 Elf_Internal_Rela
*internal_relocs
;
2180 bfd_boolean have_code
;
2181 Elf_Internal_Rela
*irel
, *irelend
;
2182 bfd_byte
*contents
= NULL
;
2183 Elf_Internal_Sym
*isymbuf
= NULL
;
2187 if (link_info
->relocatable
2188 || (sec
->flags
& SEC_RELOC
) == 0
2189 || sec
->reloc_count
== 0)
2192 #ifdef INCLUDE_SHMEDIA
2193 if (elf_section_data (sec
)->this_hdr
.sh_flags
2194 & (SHF_SH5_ISA32
| SHF_SH5_ISA32_MIXED
))
2200 /* If this is the first time we have been called for this section,
2201 initialize the cooked size. */
2202 if (sec
->_cooked_size
== 0)
2203 sec
->_cooked_size
= sec
->_raw_size
;
2205 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2207 internal_relocs
= (_bfd_elf_link_read_relocs
2208 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
2209 link_info
->keep_memory
));
2210 if (internal_relocs
== NULL
)
2215 irelend
= internal_relocs
+ sec
->reloc_count
;
2216 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2218 bfd_vma laddr
, paddr
, symval
;
2219 unsigned short insn
;
2220 Elf_Internal_Rela
*irelfn
, *irelscan
, *irelcount
;
2221 bfd_signed_vma foff
;
2223 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_CODE
)
2226 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_USES
)
2229 /* Get the section contents. */
2230 if (contents
== NULL
)
2232 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2233 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2236 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
2237 if (contents
== NULL
)
2240 if (! bfd_get_section_contents (abfd
, sec
, contents
,
2241 (file_ptr
) 0, sec
->_raw_size
))
2246 /* The r_addend field of the R_SH_USES reloc will point us to
2247 the register load. The 4 is because the r_addend field is
2248 computed as though it were a jump offset, which are based
2249 from 4 bytes after the jump instruction. */
2250 laddr
= irel
->r_offset
+ 4 + irel
->r_addend
;
2251 if (laddr
>= sec
->_raw_size
)
2253 (*_bfd_error_handler
) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),
2254 bfd_archive_filename (abfd
),
2255 (unsigned long) irel
->r_offset
);
2258 insn
= bfd_get_16 (abfd
, contents
+ laddr
);
2260 /* If the instruction is not mov.l NN,rN, we don't know what to
2262 if ((insn
& 0xf000) != 0xd000)
2264 ((*_bfd_error_handler
)
2265 (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
2266 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
, insn
));
2270 /* Get the address from which the register is being loaded. The
2271 displacement in the mov.l instruction is quadrupled. It is a
2272 displacement from four bytes after the movl instruction, but,
2273 before adding in the PC address, two least significant bits
2274 of the PC are cleared. We assume that the section is aligned
2275 on a four byte boundary. */
2276 paddr
= insn
& 0xff;
2278 paddr
+= (laddr
+ 4) &~ (bfd_vma
) 3;
2279 if (paddr
>= sec
->_raw_size
)
2281 ((*_bfd_error_handler
)
2282 (_("%s: 0x%lx: warning: bad R_SH_USES load offset"),
2283 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
2287 /* Get the reloc for the address from which the register is
2288 being loaded. This reloc will tell us which function is
2289 actually being called. */
2290 for (irelfn
= internal_relocs
; irelfn
< irelend
; irelfn
++)
2291 if (irelfn
->r_offset
== paddr
2292 && ELF32_R_TYPE (irelfn
->r_info
) == (int) R_SH_DIR32
)
2294 if (irelfn
>= irelend
)
2296 ((*_bfd_error_handler
)
2297 (_("%s: 0x%lx: warning: could not find expected reloc"),
2298 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2302 /* Read this BFD's symbols if we haven't done so already. */
2303 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
2305 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2306 if (isymbuf
== NULL
)
2307 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2308 symtab_hdr
->sh_info
, 0,
2310 if (isymbuf
== NULL
)
2314 /* Get the value of the symbol referred to by the reloc. */
2315 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
2317 /* A local symbol. */
2318 Elf_Internal_Sym
*isym
;
2320 isym
= isymbuf
+ ELF32_R_SYM (irelfn
->r_info
);
2322 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd
, sec
))
2324 ((*_bfd_error_handler
)
2325 (_("%s: 0x%lx: warning: symbol in unexpected section"),
2326 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2330 symval
= (isym
->st_value
2331 + sec
->output_section
->vma
2332 + sec
->output_offset
);
2337 struct elf_link_hash_entry
*h
;
2339 indx
= ELF32_R_SYM (irelfn
->r_info
) - symtab_hdr
->sh_info
;
2340 h
= elf_sym_hashes (abfd
)[indx
];
2341 BFD_ASSERT (h
!= NULL
);
2342 if (h
->root
.type
!= bfd_link_hash_defined
2343 && h
->root
.type
!= bfd_link_hash_defweak
)
2345 /* This appears to be a reference to an undefined
2346 symbol. Just ignore it--it will be caught by the
2347 regular reloc processing. */
2351 symval
= (h
->root
.u
.def
.value
2352 + h
->root
.u
.def
.section
->output_section
->vma
2353 + h
->root
.u
.def
.section
->output_offset
);
2356 symval
+= bfd_get_32 (abfd
, contents
+ paddr
);
2358 /* See if this function call can be shortened. */
2361 + sec
->output_section
->vma
2362 + sec
->output_offset
2364 if (foff
< -0x1000 || foff
>= 0x1000)
2366 /* After all that work, we can't shorten this function call. */
2370 /* Shorten the function call. */
2372 /* For simplicity of coding, we are going to modify the section
2373 contents, the section relocs, and the BFD symbol table. We
2374 must tell the rest of the code not to free up this
2375 information. It would be possible to instead create a table
2376 of changes which have to be made, as is done in coff-mips.c;
2377 that would be more work, but would require less memory when
2378 the linker is run. */
2380 elf_section_data (sec
)->relocs
= internal_relocs
;
2381 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2382 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2384 /* Replace the jsr with a bsr. */
2386 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
2387 replace the jsr with a bsr. */
2388 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irelfn
->r_info
), R_SH_IND12W
);
2389 /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2390 here, but that only checks if the symbol is an external symbol,
2391 not if the symbol is in a different section. Besides, we need
2392 a consistent meaning for the relocation, so we just assume here that
2393 the value of the symbol is not available. */
2395 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
2397 /* If this needs to be changed because of future relaxing,
2398 it will be handled here like other internal IND12W
2401 (bfd_vma
) 0xb000 | ((foff
>> 1) & 0xfff),
2402 contents
+ irel
->r_offset
);
2407 /* We can't fully resolve this yet, because the external
2408 symbol value may be changed by future relaxing. We let
2409 the final link phase handle it. */
2410 bfd_put_16 (abfd
, (bfd_vma
) 0xb000, contents
+ irel
->r_offset
);
2412 irel
->r_addend
= -4;
2414 /* See if there is another R_SH_USES reloc referring to the same
2416 for (irelscan
= internal_relocs
; irelscan
< irelend
; irelscan
++)
2417 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_USES
2418 && laddr
== irelscan
->r_offset
+ 4 + irelscan
->r_addend
)
2420 if (irelscan
< irelend
)
2422 /* Some other function call depends upon this register load,
2423 and we have not yet converted that function call.
2424 Indeed, we may never be able to convert it. There is
2425 nothing else we can do at this point. */
2429 /* Look for a R_SH_COUNT reloc on the location where the
2430 function address is stored. Do this before deleting any
2431 bytes, to avoid confusion about the address. */
2432 for (irelcount
= internal_relocs
; irelcount
< irelend
; irelcount
++)
2433 if (irelcount
->r_offset
== paddr
2434 && ELF32_R_TYPE (irelcount
->r_info
) == (int) R_SH_COUNT
)
2437 /* Delete the register load. */
2438 if (! sh_elf_relax_delete_bytes (abfd
, sec
, laddr
, 2))
2441 /* That will change things, so, just in case it permits some
2442 other function call to come within range, we should relax
2443 again. Note that this is not required, and it may be slow. */
2446 /* Now check whether we got a COUNT reloc. */
2447 if (irelcount
>= irelend
)
2449 ((*_bfd_error_handler
)
2450 (_("%s: 0x%lx: warning: could not find expected COUNT reloc"),
2451 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2455 /* The number of uses is stored in the r_addend field. We've
2456 just deleted one. */
2457 if (irelcount
->r_addend
== 0)
2459 ((*_bfd_error_handler
) (_("%s: 0x%lx: warning: bad count"),
2460 bfd_archive_filename (abfd
),
2461 (unsigned long) paddr
));
2465 --irelcount
->r_addend
;
2467 /* If there are no more uses, we can delete the address. Reload
2468 the address from irelfn, in case it was changed by the
2469 previous call to sh_elf_relax_delete_bytes. */
2470 if (irelcount
->r_addend
== 0)
2472 if (! sh_elf_relax_delete_bytes (abfd
, sec
, irelfn
->r_offset
, 4))
2476 /* We've done all we can with that function call. */
2479 /* Look for load and store instructions that we can align on four
2481 if ((elf_elfheader (abfd
)->e_flags
& EF_SH_MACH_MASK
) != EF_SH4
2484 bfd_boolean swapped
;
2486 /* Get the section contents. */
2487 if (contents
== NULL
)
2489 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2490 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2493 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
2494 if (contents
== NULL
)
2497 if (! bfd_get_section_contents (abfd
, sec
, contents
,
2498 (file_ptr
) 0, sec
->_raw_size
))
2503 if (! sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
,
2509 elf_section_data (sec
)->relocs
= internal_relocs
;
2510 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2511 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2516 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2518 if (! link_info
->keep_memory
)
2522 /* Cache the symbols for elf_link_input_bfd. */
2523 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2527 if (contents
!= NULL
2528 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2530 if (! link_info
->keep_memory
)
2534 /* Cache the section contents for elf_link_input_bfd. */
2535 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2539 if (internal_relocs
!= NULL
2540 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2541 free (internal_relocs
);
2547 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2549 if (contents
!= NULL
2550 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2552 if (internal_relocs
!= NULL
2553 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2554 free (internal_relocs
);
2559 /* Delete some bytes from a section while relaxing. FIXME: There is a
2560 lot of duplication between this function and sh_relax_delete_bytes
2564 sh_elf_relax_delete_bytes (bfd
*abfd
, asection
*sec
, bfd_vma addr
,
2567 Elf_Internal_Shdr
*symtab_hdr
;
2568 unsigned int sec_shndx
;
2570 Elf_Internal_Rela
*irel
, *irelend
;
2571 Elf_Internal_Rela
*irelalign
;
2573 Elf_Internal_Sym
*isymbuf
, *isym
, *isymend
;
2574 struct elf_link_hash_entry
**sym_hashes
;
2575 struct elf_link_hash_entry
**end_hashes
;
2576 unsigned int symcount
;
2579 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2580 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2582 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
2584 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2586 /* The deletion must stop at the next ALIGN reloc for an aligment
2587 power larger than the number of bytes we are deleting. */
2590 toaddr
= sec
->_cooked_size
;
2592 irel
= elf_section_data (sec
)->relocs
;
2593 irelend
= irel
+ sec
->reloc_count
;
2594 for (; irel
< irelend
; irel
++)
2596 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
2597 && irel
->r_offset
> addr
2598 && count
< (1 << irel
->r_addend
))
2601 toaddr
= irel
->r_offset
;
2606 /* Actually delete the bytes. */
2607 memmove (contents
+ addr
, contents
+ addr
+ count
,
2608 (size_t) (toaddr
- addr
- count
));
2609 if (irelalign
== NULL
)
2610 sec
->_cooked_size
-= count
;
2615 #define NOP_OPCODE (0x0009)
2617 BFD_ASSERT ((count
& 1) == 0);
2618 for (i
= 0; i
< count
; i
+= 2)
2619 bfd_put_16 (abfd
, (bfd_vma
) NOP_OPCODE
, contents
+ toaddr
- count
+ i
);
2622 /* Adjust all the relocs. */
2623 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
2625 bfd_vma nraddr
, stop
;
2628 int off
, adjust
, oinsn
;
2629 bfd_signed_vma voff
= 0;
2630 bfd_boolean overflow
;
2632 /* Get the new reloc address. */
2633 nraddr
= irel
->r_offset
;
2634 if ((irel
->r_offset
> addr
2635 && irel
->r_offset
< toaddr
)
2636 || (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
2637 && irel
->r_offset
== toaddr
))
2640 /* See if this reloc was for the bytes we have deleted, in which
2641 case we no longer care about it. Don't delete relocs which
2642 represent addresses, though. */
2643 if (irel
->r_offset
>= addr
2644 && irel
->r_offset
< addr
+ count
2645 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_ALIGN
2646 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
2647 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_DATA
2648 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_LABEL
)
2649 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
2652 /* If this is a PC relative reloc, see if the range it covers
2653 includes the bytes we have deleted. */
2654 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2663 start
= irel
->r_offset
;
2664 insn
= bfd_get_16 (abfd
, contents
+ nraddr
);
2668 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2671 start
= stop
= addr
;
2675 /* If this reloc is against a symbol defined in this
2676 section, and the symbol will not be adjusted below, we
2677 must check the addend to see it will put the value in
2678 range to be adjusted, and hence must be changed. */
2679 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
2681 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
2682 if (isym
->st_shndx
== sec_shndx
2683 && (isym
->st_value
<= addr
2684 || isym
->st_value
>= toaddr
))
2688 val
= bfd_get_32 (abfd
, contents
+ nraddr
);
2689 val
+= isym
->st_value
;
2690 if (val
> addr
&& val
< toaddr
)
2691 bfd_put_32 (abfd
, val
- count
, contents
+ nraddr
);
2694 start
= stop
= addr
;
2701 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
2708 /* This has been made by previous relaxation. Since the
2709 relocation will be against an external symbol, the
2710 final relocation will just do the right thing. */
2711 start
= stop
= addr
;
2717 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
2719 /* The addend will be against the section symbol, thus
2720 for adjusting the addend, the relevant start is the
2721 start of the section.
2722 N.B. If we want to abandon in-place changes here and
2723 test directly using symbol + addend, we have to take into
2724 account that the addend has already been adjusted by -4. */
2725 if (stop
> addr
&& stop
< toaddr
)
2726 irel
->r_addend
-= count
;
2732 stop
= start
+ 4 + off
* 2;
2737 stop
= (start
& ~(bfd_vma
) 3) + 4 + off
* 4;
2743 /* These relocs types represent
2745 The r_addend field holds the difference between the reloc
2746 address and L1. That is the start of the reloc, and
2747 adding in the contents gives us the top. We must adjust
2748 both the r_offset field and the section contents.
2749 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
2750 and the elf bfd r_offset is called r_vaddr. */
2752 stop
= irel
->r_offset
;
2753 start
= (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irel
->r_addend
);
2757 && (stop
<= addr
|| stop
>= toaddr
))
2758 irel
->r_addend
+= count
;
2759 else if (stop
> addr
2761 && (start
<= addr
|| start
>= toaddr
))
2762 irel
->r_addend
-= count
;
2764 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH16
)
2765 voff
= bfd_get_signed_16 (abfd
, contents
+ nraddr
);
2766 else if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH8
)
2767 voff
= bfd_get_8 (abfd
, contents
+ nraddr
);
2769 voff
= bfd_get_signed_32 (abfd
, contents
+ nraddr
);
2770 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
2775 start
= irel
->r_offset
;
2776 stop
= (bfd_vma
) ((bfd_signed_vma
) start
2777 + (long) irel
->r_addend
2784 && (stop
<= addr
|| stop
>= toaddr
))
2786 else if (stop
> addr
2788 && (start
<= addr
|| start
>= toaddr
))
2797 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2806 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2808 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2813 if ((oinsn
& 0xf000) != (insn
& 0xf000))
2815 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2819 BFD_ASSERT (adjust
== count
|| count
>= 4);
2824 if ((irel
->r_offset
& 3) == 0)
2827 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2829 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2834 if (voff
< 0 || voff
>= 0xff)
2836 bfd_put_8 (abfd
, voff
, contents
+ nraddr
);
2841 if (voff
< - 0x8000 || voff
>= 0x8000)
2843 bfd_put_signed_16 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
2848 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
2852 irel
->r_addend
+= adjust
;
2858 ((*_bfd_error_handler
)
2859 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
2860 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
2861 bfd_set_error (bfd_error_bad_value
);
2866 irel
->r_offset
= nraddr
;
2869 /* Look through all the other sections. If there contain any IMM32
2870 relocs against internal symbols which we are not going to adjust
2871 below, we may need to adjust the addends. */
2872 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2874 Elf_Internal_Rela
*internal_relocs
;
2875 Elf_Internal_Rela
*irelscan
, *irelscanend
;
2876 bfd_byte
*ocontents
;
2879 || (o
->flags
& SEC_RELOC
) == 0
2880 || o
->reloc_count
== 0)
2883 /* We always cache the relocs. Perhaps, if info->keep_memory is
2884 FALSE, we should free them, if we are permitted to, when we
2885 leave sh_coff_relax_section. */
2886 internal_relocs
= (_bfd_elf_link_read_relocs
2887 (abfd
, o
, NULL
, (Elf_Internal_Rela
*) NULL
, TRUE
));
2888 if (internal_relocs
== NULL
)
2892 irelscanend
= internal_relocs
+ o
->reloc_count
;
2893 for (irelscan
= internal_relocs
; irelscan
< irelscanend
; irelscan
++)
2895 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
2896 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_SWITCH32
)
2898 bfd_vma start
, stop
;
2899 bfd_signed_vma voff
;
2901 if (ocontents
== NULL
)
2903 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
2904 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
2907 /* We always cache the section contents.
2908 Perhaps, if info->keep_memory is FALSE, we
2909 should free them, if we are permitted to,
2910 when we leave sh_coff_relax_section. */
2911 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
2912 if (ocontents
== NULL
)
2914 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
2918 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
2922 stop
= irelscan
->r_offset
;
2924 = (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irelscan
->r_addend
);
2926 /* STOP is in a different section, so it won't change. */
2927 if (start
> addr
&& start
< toaddr
)
2928 irelscan
->r_addend
+= count
;
2930 voff
= bfd_get_signed_32 (abfd
, ocontents
+ irelscan
->r_offset
);
2931 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
2935 && (stop
<= addr
|| stop
>= toaddr
))
2936 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
+ count
,
2937 ocontents
+ irelscan
->r_offset
);
2938 else if (stop
> addr
2940 && (start
<= addr
|| start
>= toaddr
))
2941 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
- count
,
2942 ocontents
+ irelscan
->r_offset
);
2945 if (ELF32_R_TYPE (irelscan
->r_info
) != (int) R_SH_DIR32
)
2948 if (ELF32_R_SYM (irelscan
->r_info
) >= symtab_hdr
->sh_info
)
2952 isym
= isymbuf
+ ELF32_R_SYM (irelscan
->r_info
);
2953 if (isym
->st_shndx
== sec_shndx
2954 && (isym
->st_value
<= addr
2955 || isym
->st_value
>= toaddr
))
2959 if (ocontents
== NULL
)
2961 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
2962 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
2965 /* We always cache the section contents.
2966 Perhaps, if info->keep_memory is FALSE, we
2967 should free them, if we are permitted to,
2968 when we leave sh_coff_relax_section. */
2969 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
2970 if (ocontents
== NULL
)
2972 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
2976 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
2980 val
= bfd_get_32 (abfd
, ocontents
+ irelscan
->r_offset
);
2981 val
+= isym
->st_value
;
2982 if (val
> addr
&& val
< toaddr
)
2983 bfd_put_32 (abfd
, val
- count
,
2984 ocontents
+ irelscan
->r_offset
);
2989 /* Adjust the local symbols defined in this section. */
2990 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
2991 for (isym
= isymbuf
; isym
< isymend
; isym
++)
2993 if (isym
->st_shndx
== sec_shndx
2994 && isym
->st_value
> addr
2995 && isym
->st_value
< toaddr
)
2996 isym
->st_value
-= count
;
2999 /* Now adjust the global symbols defined in this section. */
3000 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
3001 - symtab_hdr
->sh_info
);
3002 sym_hashes
= elf_sym_hashes (abfd
);
3003 end_hashes
= sym_hashes
+ symcount
;
3004 for (; sym_hashes
< end_hashes
; sym_hashes
++)
3006 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
3007 if ((sym_hash
->root
.type
== bfd_link_hash_defined
3008 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
3009 && sym_hash
->root
.u
.def
.section
== sec
3010 && sym_hash
->root
.u
.def
.value
> addr
3011 && sym_hash
->root
.u
.def
.value
< toaddr
)
3013 sym_hash
->root
.u
.def
.value
-= count
;
3017 /* See if we can move the ALIGN reloc forward. We have adjusted
3018 r_offset for it already. */
3019 if (irelalign
!= NULL
)
3021 bfd_vma alignto
, alignaddr
;
3023 alignto
= BFD_ALIGN (toaddr
, 1 << irelalign
->r_addend
);
3024 alignaddr
= BFD_ALIGN (irelalign
->r_offset
,
3025 1 << irelalign
->r_addend
);
3026 if (alignto
!= alignaddr
)
3028 /* Tail recursion. */
3029 return sh_elf_relax_delete_bytes (abfd
, sec
, alignaddr
,
3030 (int) (alignto
- alignaddr
));
3037 /* Look for loads and stores which we can align to four byte
3038 boundaries. This is like sh_align_loads in coff-sh.c. */
3041 sh_elf_align_loads (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
,
3042 Elf_Internal_Rela
*internal_relocs
,
3043 bfd_byte
*contents ATTRIBUTE_UNUSED
,
3044 bfd_boolean
*pswapped
)
3046 Elf_Internal_Rela
*irel
, *irelend
;
3047 bfd_vma
*labels
= NULL
;
3048 bfd_vma
*label
, *label_end
;
3053 irelend
= internal_relocs
+ sec
->reloc_count
;
3055 /* Get all the addresses with labels on them. */
3056 amt
= sec
->reloc_count
;
3057 amt
*= sizeof (bfd_vma
);
3058 labels
= (bfd_vma
*) bfd_malloc (amt
);
3062 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3064 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_LABEL
)
3066 *label_end
= irel
->r_offset
;
3071 /* Note that the assembler currently always outputs relocs in
3072 address order. If that ever changes, this code will need to sort
3073 the label values and the relocs. */
3077 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3079 bfd_vma start
, stop
;
3081 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
)
3084 start
= irel
->r_offset
;
3086 for (irel
++; irel
< irelend
; irel
++)
3087 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_DATA
)
3090 stop
= irel
->r_offset
;
3092 stop
= sec
->_cooked_size
;
3094 if (! _bfd_sh_align_load_span (abfd
, sec
, contents
, sh_elf_swap_insns
,
3095 internal_relocs
, &label
,
3096 label_end
, start
, stop
, pswapped
))
3110 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
3113 sh_elf_swap_insns (bfd
*abfd
, asection
*sec
, void *relocs
,
3114 bfd_byte
*contents
, bfd_vma addr
)
3116 Elf_Internal_Rela
*internal_relocs
= (Elf_Internal_Rela
*) relocs
;
3117 unsigned short i1
, i2
;
3118 Elf_Internal_Rela
*irel
, *irelend
;
3120 /* Swap the instructions themselves. */
3121 i1
= bfd_get_16 (abfd
, contents
+ addr
);
3122 i2
= bfd_get_16 (abfd
, contents
+ addr
+ 2);
3123 bfd_put_16 (abfd
, (bfd_vma
) i2
, contents
+ addr
);
3124 bfd_put_16 (abfd
, (bfd_vma
) i1
, contents
+ addr
+ 2);
3126 /* Adjust all reloc addresses. */
3127 irelend
= internal_relocs
+ sec
->reloc_count
;
3128 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3130 enum elf_sh_reloc_type type
;
3133 /* There are a few special types of relocs that we don't want to
3134 adjust. These relocs do not apply to the instruction itself,
3135 but are only associated with the address. */
3136 type
= (enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
);
3137 if (type
== R_SH_ALIGN
3138 || type
== R_SH_CODE
3139 || type
== R_SH_DATA
3140 || type
== R_SH_LABEL
)
3143 /* If an R_SH_USES reloc points to one of the addresses being
3144 swapped, we must adjust it. It would be incorrect to do this
3145 for a jump, though, since we want to execute both
3146 instructions after the jump. (We have avoided swapping
3147 around a label, so the jump will not wind up executing an
3148 instruction it shouldn't). */
3149 if (type
== R_SH_USES
)
3153 off
= irel
->r_offset
+ 4 + irel
->r_addend
;
3155 irel
->r_offset
+= 2;
3156 else if (off
== addr
+ 2)
3157 irel
->r_offset
-= 2;
3160 if (irel
->r_offset
== addr
)
3162 irel
->r_offset
+= 2;
3165 else if (irel
->r_offset
== addr
+ 2)
3167 irel
->r_offset
-= 2;
3176 unsigned short insn
, oinsn
;
3177 bfd_boolean overflow
;
3179 loc
= contents
+ irel
->r_offset
;
3188 insn
= bfd_get_16 (abfd
, loc
);
3191 if ((oinsn
& 0xff00) != (insn
& 0xff00))
3193 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3197 insn
= bfd_get_16 (abfd
, loc
);
3200 if ((oinsn
& 0xf000) != (insn
& 0xf000))
3202 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3206 /* This reloc ignores the least significant 3 bits of
3207 the program counter before adding in the offset.
3208 This means that if ADDR is at an even address, the
3209 swap will not affect the offset. If ADDR is an at an
3210 odd address, then the instruction will be crossing a
3211 four byte boundary, and must be adjusted. */
3212 if ((addr
& 3) != 0)
3214 insn
= bfd_get_16 (abfd
, loc
);
3217 if ((oinsn
& 0xff00) != (insn
& 0xff00))
3219 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3227 ((*_bfd_error_handler
)
3228 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
3229 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
3230 bfd_set_error (bfd_error_bad_value
);
3239 #ifdef INCLUDE_SHMEDIA
3241 /* The size in bytes of an entry in the procedure linkage table. */
3243 #define PLT_ENTRY_SIZE 64
3245 /* First entry in an absolute procedure linkage table look like this. */
3247 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3249 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
3250 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
3251 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3252 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3253 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3254 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3255 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3256 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3257 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3258 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3259 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3260 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3261 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3262 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3263 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3264 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3267 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3269 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
3270 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
3271 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3272 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3273 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3274 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3275 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3276 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3277 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3278 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3279 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3280 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3281 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3282 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3283 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3284 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3287 /* Sebsequent entries in an absolute procedure linkage table look like
3290 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3292 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
3293 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
3294 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
3295 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3296 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3297 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3298 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3299 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3300 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
3301 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
3302 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3303 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3304 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3305 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3306 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3307 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3310 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3312 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3313 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3314 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
3315 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3316 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3317 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3318 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3319 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3320 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
3321 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
3322 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3323 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3324 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3325 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3326 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3327 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3330 /* Entries in a PIC procedure linkage table look like this. */
3332 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3334 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3335 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3336 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
3337 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3338 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3339 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3340 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3341 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3342 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3343 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
3344 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3345 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3346 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3347 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3348 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3349 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3352 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3354 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3355 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3356 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
3357 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3358 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3359 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3360 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3361 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3362 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3363 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
3364 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3365 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3366 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3367 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3368 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3369 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3372 static const bfd_byte
*elf_sh_plt0_entry
;
3373 static const bfd_byte
*elf_sh_plt_entry
;
3374 static const bfd_byte
*elf_sh_pic_plt_entry
;
3376 /* Return size of a PLT entry. */
3377 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3379 /* Return offset of the PLT0 address in an absolute PLT entry. */
3380 #define elf_sh_plt_plt0_offset(info) 32
3382 /* Return offset of the linker in PLT0 entry. */
3383 #define elf_sh_plt0_gotplt_offset(info) 0
3385 /* Return offset of the trampoline in PLT entry */
3386 #define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
3388 /* Return offset of the symbol in PLT entry. */
3389 #define elf_sh_plt_symbol_offset(info) 0
3391 /* Return offset of the relocation in PLT entry. */
3392 #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
3395 movi_shori_putval (bfd
*output_bfd
, unsigned long value
, char *addr
)
3397 bfd_put_32 (output_bfd
,
3398 bfd_get_32 (output_bfd
, addr
)
3399 | ((value
>> 6) & 0x3fffc00),
3401 bfd_put_32 (output_bfd
,
3402 bfd_get_32 (output_bfd
, addr
+ 4)
3403 | ((value
<< 10) & 0x3fffc00),
3408 /* The size in bytes of an entry in the procedure linkage table. */
3410 #define PLT_ENTRY_SIZE 28
3412 /* First entry in an absolute procedure linkage table look like this. */
3415 /* Note - this code has been "optimised" not to use r2. r2 is used by
3416 GCC to return the address of large structures, so it should not be
3417 corrupted here. This does mean however, that this PLT does not conform
3418 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
3419 and r2 contains the GOT id. This version stores the GOT id in r0 and
3420 ignores the type. Loaders can easily detect this difference however,
3421 since the type will always be 0 or 8, and the GOT ids will always be
3422 greater than or equal to 12. */
3423 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3425 0xd0, 0x05, /* mov.l 2f,r0 */
3426 0x60, 0x02, /* mov.l @r0,r0 */
3427 0x2f, 0x06, /* mov.l r0,@-r15 */
3428 0xd0, 0x03, /* mov.l 1f,r0 */
3429 0x60, 0x02, /* mov.l @r0,r0 */
3430 0x40, 0x2b, /* jmp @r0 */
3431 0x60, 0xf6, /* mov.l @r15+,r0 */
3432 0x00, 0x09, /* nop */
3433 0x00, 0x09, /* nop */
3434 0x00, 0x09, /* nop */
3435 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3436 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3439 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3441 0x05, 0xd0, /* mov.l 2f,r0 */
3442 0x02, 0x60, /* mov.l @r0,r0 */
3443 0x06, 0x2f, /* mov.l r0,@-r15 */
3444 0x03, 0xd0, /* mov.l 1f,r0 */
3445 0x02, 0x60, /* mov.l @r0,r0 */
3446 0x2b, 0x40, /* jmp @r0 */
3447 0xf6, 0x60, /* mov.l @r15+,r0 */
3448 0x09, 0x00, /* nop */
3449 0x09, 0x00, /* nop */
3450 0x09, 0x00, /* nop */
3451 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3452 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3455 /* Sebsequent entries in an absolute procedure linkage table look like
3458 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3460 0xd0, 0x04, /* mov.l 1f,r0 */
3461 0x60, 0x02, /* mov.l @r0,r0 */
3462 0xd1, 0x02, /* mov.l 0f,r1 */
3463 0x40, 0x2b, /* jmp @r0 */
3464 0x60, 0x13, /* mov r1,r0 */
3465 0xd1, 0x03, /* mov.l 2f,r1 */
3466 0x40, 0x2b, /* jmp @r0 */
3467 0x00, 0x09, /* nop */
3468 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3469 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3470 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3473 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3475 0x04, 0xd0, /* mov.l 1f,r0 */
3476 0x02, 0x60, /* mov.l @r0,r0 */
3477 0x02, 0xd1, /* mov.l 0f,r1 */
3478 0x2b, 0x40, /* jmp @r0 */
3479 0x13, 0x60, /* mov r1,r0 */
3480 0x03, 0xd1, /* mov.l 2f,r1 */
3481 0x2b, 0x40, /* jmp @r0 */
3482 0x09, 0x00, /* nop */
3483 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3484 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3485 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3488 /* Entries in a PIC procedure linkage table look like this. */
3490 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3492 0xd0, 0x04, /* mov.l 1f,r0 */
3493 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3494 0x40, 0x2b, /* jmp @r0 */
3495 0x00, 0x09, /* nop */
3496 0x50, 0xc2, /* mov.l @(8,r12),r0 */
3497 0xd1, 0x03, /* mov.l 2f,r1 */
3498 0x40, 0x2b, /* jmp @r0 */
3499 0x50, 0xc1, /* mov.l @(4,r12),r0 */
3500 0x00, 0x09, /* nop */
3501 0x00, 0x09, /* nop */
3502 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3503 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3506 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3508 0x04, 0xd0, /* mov.l 1f,r0 */
3509 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3510 0x2b, 0x40, /* jmp @r0 */
3511 0x09, 0x00, /* nop */
3512 0xc2, 0x50, /* mov.l @(8,r12),r0 */
3513 0x03, 0xd1, /* mov.l 2f,r1 */
3514 0x2b, 0x40, /* jmp @r0 */
3515 0xc1, 0x50, /* mov.l @(4,r12),r0 */
3516 0x09, 0x00, /* nop */
3517 0x09, 0x00, /* nop */
3518 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3519 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3522 #else /* These are the old style PLT entries. */
3523 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3525 0xd0, 0x04, /* mov.l 1f,r0 */
3526 0xd2, 0x05, /* mov.l 2f,r2 */
3527 0x60, 0x02, /* mov.l @r0,r0 */
3528 0x62, 0x22, /* mov.l @r2,r2 */
3529 0x40, 0x2b, /* jmp @r0 */
3530 0xe0, 0x00, /* mov #0,r0 */
3531 0x00, 0x09, /* nop */
3532 0x00, 0x09, /* nop */
3533 0x00, 0x09, /* nop */
3534 0x00, 0x09, /* nop */
3535 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3536 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3539 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3541 0x04, 0xd0, /* mov.l 1f,r0 */
3542 0x05, 0xd2, /* mov.l 2f,r2 */
3543 0x02, 0x60, /* mov.l @r0,r0 */
3544 0x22, 0x62, /* mov.l @r2,r2 */
3545 0x2b, 0x40, /* jmp @r0 */
3546 0x00, 0xe0, /* mov #0,r0 */
3547 0x09, 0x00, /* nop */
3548 0x09, 0x00, /* nop */
3549 0x09, 0x00, /* nop */
3550 0x09, 0x00, /* nop */
3551 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3552 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3555 /* Sebsequent entries in an absolute procedure linkage table look like
3558 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3560 0xd0, 0x04, /* mov.l 1f,r0 */
3561 0x60, 0x02, /* mov.l @r0,r0 */
3562 0xd2, 0x02, /* mov.l 0f,r2 */
3563 0x40, 0x2b, /* jmp @r0 */
3564 0x60, 0x23, /* mov r2,r0 */
3565 0xd1, 0x03, /* mov.l 2f,r1 */
3566 0x40, 0x2b, /* jmp @r0 */
3567 0x00, 0x09, /* nop */
3568 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3569 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3570 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3573 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3575 0x04, 0xd0, /* mov.l 1f,r0 */
3576 0x02, 0x60, /* mov.l @r0,r0 */
3577 0x02, 0xd2, /* mov.l 0f,r2 */
3578 0x2b, 0x40, /* jmp @r0 */
3579 0x23, 0x60, /* mov r2,r0 */
3580 0x03, 0xd1, /* mov.l 2f,r1 */
3581 0x2b, 0x40, /* jmp @r0 */
3582 0x09, 0x00, /* nop */
3583 0, 0, 0, 0, /* 0: replaced with address of .PLT. */
3584 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3585 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3588 /* Entries in a PIC procedure linkage table look like this. */
3590 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3592 0xd0, 0x04, /* mov.l 1f,r0 */
3593 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3594 0x40, 0x2b, /* jmp @r0 */
3595 0x00, 0x09, /* nop */
3596 0x50, 0xc2, /* 0: mov.l @(8,r12),r0 */
3597 0x52, 0xc1, /* 1: mov.l @(4,r12),r2 */
3598 0xd1, 0x02, /* mov.l 2f,r1 */
3599 0x40, 0x2b, /* jmp @r0 */
3600 0xe0, 0x00, /* mov #0,r0 ! shows the type of PLT. */
3601 0x00, 0x09, /* nop */
3602 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3603 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3606 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3608 0x04, 0xd0, /* mov.l 1f,r0 */
3609 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3610 0x2b, 0x40, /* jmp @r0 */
3611 0x09, 0x00, /* nop */
3612 0xc2, 0x50, /* 0: mov.l @(8,r12),r0 */
3613 0xc1, 0x52, /* 1: mov.l @(4,r12),r2 */
3614 0x02, 0xd1, /* mov.l 2f,r1 */
3615 0x2b, 0x40, /* jmp @r0 */
3616 0x00, 0xe0, /* mov #0,r0 ! shows the type of PLT. */
3617 0x09, 0x00, /* nop */
3618 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3619 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3621 #endif /* old style PLT entries. */
3623 static const bfd_byte
*elf_sh_plt0_entry
;
3624 static const bfd_byte
*elf_sh_plt_entry
;
3625 static const bfd_byte
*elf_sh_pic_plt_entry
;
3627 /* Return size of a PLT entry. */
3628 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3630 /* Return offset of the PLT0 address in an absolute PLT entry. */
3631 #define elf_sh_plt_plt0_offset(info) 16
3633 /* Return offset of the linker in PLT0 entry. */
3634 #define elf_sh_plt0_linker_offset(info) 20
3636 /* Return offset of the GOT id in PLT0 entry. */
3637 #define elf_sh_plt0_gotid_offset(info) 24
3639 /* Return offset of the temporary in PLT entry */
3640 #define elf_sh_plt_temp_offset(info) 8
3642 /* Return offset of the symbol in PLT entry. */
3643 #define elf_sh_plt_symbol_offset(info) 20
3645 /* Return offset of the relocation in PLT entry. */
3646 #define elf_sh_plt_reloc_offset(info) 24
3649 /* The sh linker needs to keep track of the number of relocs that it
3650 decides to copy as dynamic relocs in check_relocs for each symbol.
3651 This is so that it can later discard them if they are found to be
3652 unnecessary. We store the information in a field extending the
3653 regular ELF linker hash table. */
3655 struct elf_sh_dyn_relocs
3657 struct elf_sh_dyn_relocs
*next
;
3659 /* The input section of the reloc. */
3662 /* Total number of relocs copied for the input section. */
3663 bfd_size_type count
;
3665 /* Number of pc-relative relocs copied for the input section. */
3666 bfd_size_type pc_count
;
3669 /* sh ELF linker hash entry. */
3671 struct elf_sh_link_hash_entry
3673 struct elf_link_hash_entry root
;
3675 #ifdef INCLUDE_SHMEDIA
3678 bfd_signed_vma refcount
;
3683 /* Track dynamic relocs copied for this symbol. */
3684 struct elf_sh_dyn_relocs
*dyn_relocs
;
3686 bfd_signed_vma gotplt_refcount
;
3689 GOT_UNKNOWN
= 0, GOT_NORMAL
, GOT_TLS_GD
, GOT_TLS_IE
3693 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
3695 struct sh_elf_obj_tdata
3697 struct elf_obj_tdata root
;
3699 /* tls_type for each local got entry. */
3700 char *local_got_tls_type
;
3703 #define sh_elf_tdata(abfd) \
3704 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
3706 #define sh_elf_local_got_tls_type(abfd) \
3707 (sh_elf_tdata (abfd)->local_got_tls_type)
3709 /* Override the generic function because we need to store sh_elf_obj_tdata
3710 as the specific tdata. */
3713 sh_elf_mkobject (bfd
*abfd
)
3715 bfd_size_type amt
= sizeof (struct sh_elf_obj_tdata
);
3716 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
3717 if (abfd
->tdata
.any
== NULL
)
3722 /* sh ELF linker hash table. */
3724 struct elf_sh_link_hash_table
3726 struct elf_link_hash_table root
;
3728 /* Short-cuts to get to dynamic linker sections. */
3737 /* Small local sym to section mapping cache. */
3738 struct sym_sec_cache sym_sec
;
3740 /* A counter or offset to track a TLS got entry. */
3743 bfd_signed_vma refcount
;
3748 /* Traverse an sh ELF linker hash table. */
3750 #define sh_elf_link_hash_traverse(table, func, info) \
3751 (elf_link_hash_traverse \
3753 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
3756 /* Get the sh ELF linker hash table from a link_info structure. */
3758 #define sh_elf_hash_table(p) \
3759 ((struct elf_sh_link_hash_table *) ((p)->hash))
3761 /* Create an entry in an sh ELF linker hash table. */
3763 static struct bfd_hash_entry
*
3764 sh_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
3765 struct bfd_hash_table
*table
,
3768 struct elf_sh_link_hash_entry
*ret
=
3769 (struct elf_sh_link_hash_entry
*) entry
;
3771 /* Allocate the structure if it has not already been allocated by a
3773 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3774 ret
= ((struct elf_sh_link_hash_entry
*)
3775 bfd_hash_allocate (table
,
3776 sizeof (struct elf_sh_link_hash_entry
)));
3777 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3778 return (struct bfd_hash_entry
*) ret
;
3780 /* Call the allocation method of the superclass. */
3781 ret
= ((struct elf_sh_link_hash_entry
*)
3782 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3784 if (ret
!= (struct elf_sh_link_hash_entry
*) NULL
)
3786 ret
->dyn_relocs
= NULL
;
3787 ret
->gotplt_refcount
= 0;
3788 #ifdef INCLUDE_SHMEDIA
3789 ret
->datalabel_got
.refcount
= ret
->root
.got
.refcount
;
3791 ret
->tls_type
= GOT_UNKNOWN
;
3794 return (struct bfd_hash_entry
*) ret
;
3797 /* Create an sh ELF linker hash table. */
3799 static struct bfd_link_hash_table
*
3800 sh_elf_link_hash_table_create (bfd
*abfd
)
3802 struct elf_sh_link_hash_table
*ret
;
3803 bfd_size_type amt
= sizeof (struct elf_sh_link_hash_table
);
3805 ret
= (struct elf_sh_link_hash_table
*) bfd_malloc (amt
);
3806 if (ret
== (struct elf_sh_link_hash_table
*) NULL
)
3809 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3810 sh_elf_link_hash_newfunc
))
3817 ret
->sgotplt
= NULL
;
3818 ret
->srelgot
= NULL
;
3820 ret
->srelplt
= NULL
;
3821 ret
->sdynbss
= NULL
;
3822 ret
->srelbss
= NULL
;
3823 ret
->sym_sec
.abfd
= NULL
;
3824 ret
->tls_ldm_got
.refcount
= 0;
3826 return &ret
->root
.root
;
3829 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
3830 shortcuts to them in our hash table. */
3833 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
3835 struct elf_sh_link_hash_table
*htab
;
3837 if (! _bfd_elf_create_got_section (dynobj
, info
))
3840 htab
= sh_elf_hash_table (info
);
3841 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
3842 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
3843 if (! htab
->sgot
|| ! htab
->sgotplt
)
3846 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
3847 if (htab
->srelgot
== NULL
3848 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
3853 | SEC_LINKER_CREATED
3855 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
3860 /* Create dynamic sections when linking against a dynamic object. */
3863 sh_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
3865 struct elf_sh_link_hash_table
*htab
;
3866 flagword flags
, pltflags
;
3867 register asection
*s
;
3868 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3871 switch (bed
->s
->arch_size
)
3882 bfd_set_error (bfd_error_bad_value
);
3886 htab
= sh_elf_hash_table (info
);
3887 if (htab
->root
.dynamic_sections_created
)
3890 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3891 .rel[a].bss sections. */
3893 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3894 | SEC_LINKER_CREATED
);
3897 pltflags
|= SEC_CODE
;
3898 if (bed
->plt_not_loaded
)
3899 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
3900 if (bed
->plt_readonly
)
3901 pltflags
|= SEC_READONLY
;
3903 s
= bfd_make_section (abfd
, ".plt");
3906 || ! bfd_set_section_flags (abfd
, s
, pltflags
)
3907 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3910 if (bed
->want_plt_sym
)
3912 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3914 struct elf_link_hash_entry
*h
;
3915 struct bfd_link_hash_entry
*bh
= NULL
;
3917 if (! (_bfd_generic_link_add_one_symbol
3918 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3919 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
3920 get_elf_backend_data (abfd
)->collect
, &bh
)))
3923 h
= (struct elf_link_hash_entry
*) bh
;
3924 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3925 h
->type
= STT_OBJECT
;
3928 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3932 s
= bfd_make_section (abfd
,
3933 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt");
3936 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3937 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3940 if (htab
->sgot
== NULL
3941 && !create_got_section (abfd
, info
))
3945 const char *secname
;
3950 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3952 secflags
= bfd_get_section_flags (abfd
, sec
);
3953 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3954 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3956 secname
= bfd_get_section_name (abfd
, sec
);
3957 relname
= (char *) bfd_malloc ((bfd_size_type
) strlen (secname
) + 6);
3958 strcpy (relname
, ".rela");
3959 strcat (relname
, secname
);
3960 if (bfd_get_section_by_name (abfd
, secname
))
3962 s
= bfd_make_section (abfd
, relname
);
3964 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3965 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3970 if (bed
->want_dynbss
)
3972 /* The .dynbss section is a place to put symbols which are defined
3973 by dynamic objects, are referenced by regular objects, and are
3974 not functions. We must allocate space for them in the process
3975 image and use a R_*_COPY reloc to tell the dynamic linker to
3976 initialize them at run time. The linker script puts the .dynbss
3977 section into the .bss section of the final image. */
3978 s
= bfd_make_section (abfd
, ".dynbss");
3981 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
3984 /* The .rel[a].bss section holds copy relocs. This section is not
3985 normally needed. We need to create it here, though, so that the
3986 linker will map it to an output section. We can't just create it
3987 only if we need it, because we will not know whether we need it
3988 until we have seen all the input files, and the first time the
3989 main linker code calls BFD after examining all the input files
3990 (size_dynamic_sections) the input sections have already been
3991 mapped to the output sections. If the section turns out not to
3992 be needed, we can discard it later. We will never need this
3993 section when generating a shared object, since they do not use
3997 s
= bfd_make_section (abfd
,
3998 (bed
->default_use_rela_p
3999 ? ".rela.bss" : ".rel.bss"));
4002 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
4003 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
4011 /* Adjust a symbol defined by a dynamic object and referenced by a
4012 regular object. The current definition is in some section of the
4013 dynamic object, but we're not including those sections. We have to
4014 change the definition to something the rest of the link can
4018 sh_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
4019 struct elf_link_hash_entry
*h
)
4021 struct elf_sh_link_hash_table
*htab
;
4022 struct elf_sh_link_hash_entry
*eh
;
4023 struct elf_sh_dyn_relocs
*p
;
4025 unsigned int power_of_two
;
4027 htab
= sh_elf_hash_table (info
);
4029 /* Make sure we know what is going on here. */
4030 BFD_ASSERT (htab
->root
.dynobj
!= NULL
4031 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
4032 || h
->weakdef
!= NULL
4033 || ((h
->elf_link_hash_flags
4034 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4035 && (h
->elf_link_hash_flags
4036 & ELF_LINK_HASH_REF_REGULAR
) != 0
4037 && (h
->elf_link_hash_flags
4038 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
4040 /* If this is a function, put it in the procedure linkage table. We
4041 will fill in the contents of the procedure linkage table later,
4042 when we know the address of the .got section. */
4043 if (h
->type
== STT_FUNC
4044 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4046 if (h
->plt
.refcount
<= 0
4047 || SYMBOL_CALLS_LOCAL (info
, h
)
4048 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4049 && h
->root
.type
== bfd_link_hash_undefweak
))
4051 /* This case can occur if we saw a PLT reloc in an input
4052 file, but the symbol was never referred to by a dynamic
4053 object. In such a case, we don't actually need to build
4054 a procedure linkage table, and we can just do a REL32
4056 h
->plt
.offset
= (bfd_vma
) -1;
4057 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4063 h
->plt
.offset
= (bfd_vma
) -1;
4065 /* If this is a weak symbol, and there is a real definition, the
4066 processor independent code will have arranged for us to see the
4067 real definition first, and we can just use the same value. */
4068 if (h
->weakdef
!= NULL
)
4070 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
4071 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
4072 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
4073 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
4074 if (info
->nocopyreloc
)
4075 h
->elf_link_hash_flags
4076 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
4077 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
4081 /* This is a reference to a symbol defined by a dynamic object which
4082 is not a function. */
4084 /* If we are creating a shared library, we must presume that the
4085 only references to the symbol are via the global offset table.
4086 For such cases we need not do anything here; the relocations will
4087 be handled correctly by relocate_section. */
4091 /* If there are no references to this symbol that do not use the
4092 GOT, we don't need to generate a copy reloc. */
4093 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
4096 /* If -z nocopyreloc was given, we won't generate them either. */
4097 if (info
->nocopyreloc
)
4099 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
4103 eh
= (struct elf_sh_link_hash_entry
*) h
;
4104 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4106 s
= p
->sec
->output_section
;
4107 if (s
!= NULL
&& (s
->flags
& (SEC_READONLY
| SEC_HAS_CONTENTS
)) != 0)
4111 /* If we didn't find any dynamic relocs in sections which needs the
4112 copy reloc, then we'll be keeping the dynamic relocs and avoiding
4116 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
4120 /* We must allocate the symbol in our .dynbss section, which will
4121 become part of the .bss section of the executable. There will be
4122 an entry for this symbol in the .dynsym section. The dynamic
4123 object will contain position independent code, so all references
4124 from the dynamic object to this symbol will go through the global
4125 offset table. The dynamic linker will use the .dynsym entry to
4126 determine the address it must put in the global offset table, so
4127 both the dynamic object and the regular object will refer to the
4128 same memory location for the variable. */
4131 BFD_ASSERT (s
!= NULL
);
4133 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
4134 copy the initial value out of the dynamic object and into the
4135 runtime process image. We need to remember the offset into the
4136 .rela.bss section we are going to use. */
4137 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
4141 srel
= htab
->srelbss
;
4142 BFD_ASSERT (srel
!= NULL
);
4143 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
4144 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
4147 /* We need to figure out the alignment required for this symbol. I
4148 have no idea how ELF linkers handle this. */
4149 power_of_two
= bfd_log2 (h
->size
);
4150 if (power_of_two
> 3)
4153 /* Apply the required alignment. */
4154 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
4155 if (power_of_two
> bfd_get_section_alignment (htab
->root
.dynobj
, s
))
4157 if (! bfd_set_section_alignment (htab
->root
.dynobj
, s
, power_of_two
))
4161 /* Define the symbol as being at this point in the section. */
4162 h
->root
.u
.def
.section
= s
;
4163 h
->root
.u
.def
.value
= s
->_raw_size
;
4165 /* Increment the section size to make room for the symbol. */
4166 s
->_raw_size
+= h
->size
;
4171 /* Allocate space in .plt, .got and associated reloc sections for
4175 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
4177 struct bfd_link_info
*info
;
4178 struct elf_sh_link_hash_table
*htab
;
4179 struct elf_sh_link_hash_entry
*eh
;
4180 struct elf_sh_dyn_relocs
*p
;
4182 if (h
->root
.type
== bfd_link_hash_indirect
)
4185 if (h
->root
.type
== bfd_link_hash_warning
)
4186 /* When warning symbols are created, they **replace** the "real"
4187 entry in the hash table, thus we never get to see the real
4188 symbol in a hash traversal. So look at it now. */
4189 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4191 info
= (struct bfd_link_info
*) inf
;
4192 htab
= sh_elf_hash_table (info
);
4194 eh
= (struct elf_sh_link_hash_entry
*) h
;
4195 if ((h
->got
.refcount
> 0
4196 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
4197 && eh
->gotplt_refcount
> 0)
4199 /* The symbol has been forced local, or we have some direct got refs,
4200 so treat all the gotplt refs as got refs. */
4201 h
->got
.refcount
+= eh
->gotplt_refcount
;
4202 if (h
->plt
.refcount
>= eh
->gotplt_refcount
)
4203 h
->plt
.refcount
-= eh
->gotplt_refcount
;
4206 if (htab
->root
.dynamic_sections_created
4207 && h
->plt
.refcount
> 0
4208 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4209 || h
->root
.type
!= bfd_link_hash_undefweak
))
4211 /* Make sure this symbol is output as a dynamic symbol.
4212 Undefined weak syms won't yet be marked as dynamic. */
4213 if (h
->dynindx
== -1
4214 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4216 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4221 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
4223 asection
*s
= htab
->splt
;
4225 /* If this is the first .plt entry, make room for the special
4227 if (s
->_raw_size
== 0)
4228 s
->_raw_size
+= PLT_ENTRY_SIZE
;
4230 h
->plt
.offset
= s
->_raw_size
;
4232 /* If this symbol is not defined in a regular file, and we are
4233 not generating a shared library, then set the symbol to this
4234 location in the .plt. This is required to make function
4235 pointers compare as equal between the normal executable and
4236 the shared library. */
4238 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4240 h
->root
.u
.def
.section
= s
;
4241 h
->root
.u
.def
.value
= h
->plt
.offset
;
4244 /* Make room for this entry. */
4245 s
->_raw_size
+= PLT_ENTRY_SIZE
;
4247 /* We also need to make an entry in the .got.plt section, which
4248 will be placed in the .got section by the linker script. */
4249 htab
->sgotplt
->_raw_size
+= 4;
4251 /* We also need to make an entry in the .rel.plt section. */
4252 htab
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
4256 h
->plt
.offset
= (bfd_vma
) -1;
4257 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4262 h
->plt
.offset
= (bfd_vma
) -1;
4263 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4266 if (h
->got
.refcount
> 0)
4270 int tls_type
= sh_elf_hash_entry (h
)->tls_type
;
4272 /* Make sure this symbol is output as a dynamic symbol.
4273 Undefined weak syms won't yet be marked as dynamic. */
4274 if (h
->dynindx
== -1
4275 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4277 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4282 h
->got
.offset
= s
->_raw_size
;
4284 /* R_SH_TLS_GD needs 2 consecutive GOT slots. */
4285 if (tls_type
== GOT_TLS_GD
)
4287 dyn
= htab
->root
.dynamic_sections_created
;
4288 /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
4289 R_SH_TLS_GD needs one if local symbol and two if global. */
4290 if ((tls_type
== GOT_TLS_GD
&& h
->dynindx
== -1)
4291 || (tls_type
== GOT_TLS_IE
&& dyn
))
4292 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4293 else if (tls_type
== GOT_TLS_GD
)
4294 htab
->srelgot
->_raw_size
+= 2 * sizeof (Elf32_External_Rela
);
4295 else if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4296 || h
->root
.type
!= bfd_link_hash_undefweak
)
4298 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
4299 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4302 h
->got
.offset
= (bfd_vma
) -1;
4304 #ifdef INCLUDE_SHMEDIA
4305 if (eh
->datalabel_got
.refcount
> 0)
4310 /* Make sure this symbol is output as a dynamic symbol.
4311 Undefined weak syms won't yet be marked as dynamic. */
4312 if (h
->dynindx
== -1
4313 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4315 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4320 eh
->datalabel_got
.offset
= s
->_raw_size
;
4322 dyn
= htab
->root
.dynamic_sections_created
;
4323 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
))
4324 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4327 eh
->datalabel_got
.offset
= (bfd_vma
) -1;
4330 if (eh
->dyn_relocs
== NULL
)
4333 /* In the shared -Bsymbolic case, discard space allocated for
4334 dynamic pc-relative relocs against symbols which turn out to be
4335 defined in regular objects. For the normal shared case, discard
4336 space for pc-relative relocs that have become local due to symbol
4337 visibility changes. */
4341 if (SYMBOL_CALLS_LOCAL (info
, h
))
4343 struct elf_sh_dyn_relocs
**pp
;
4345 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
4347 p
->count
-= p
->pc_count
;
4356 /* Also discard relocs on undefined weak syms with non-default
4358 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4359 && h
->root
.type
== bfd_link_hash_undefweak
)
4360 eh
->dyn_relocs
= NULL
;
4364 /* For the non-shared case, discard space for relocs against
4365 symbols which turn out to need copy relocs or are not
4368 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
4369 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4370 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4371 || (htab
->root
.dynamic_sections_created
4372 && (h
->root
.type
== bfd_link_hash_undefweak
4373 || h
->root
.type
== bfd_link_hash_undefined
))))
4375 /* Make sure this symbol is output as a dynamic symbol.
4376 Undefined weak syms won't yet be marked as dynamic. */
4377 if (h
->dynindx
== -1
4378 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4380 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4384 /* If that succeeded, we know we'll be keeping all the
4386 if (h
->dynindx
!= -1)
4390 eh
->dyn_relocs
= NULL
;
4395 /* Finally, allocate space. */
4396 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4398 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
4399 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
4405 /* Find any dynamic relocs that apply to read-only sections. */
4408 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
4410 struct elf_sh_link_hash_entry
*eh
;
4411 struct elf_sh_dyn_relocs
*p
;
4413 if (h
->root
.type
== bfd_link_hash_warning
)
4414 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4416 eh
= (struct elf_sh_link_hash_entry
*) h
;
4417 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4419 asection
*s
= p
->sec
->output_section
;
4421 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4423 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4425 info
->flags
|= DF_TEXTREL
;
4427 /* Not an error, just cut short the traversal. */
4434 /* Set the sizes of the dynamic sections. */
4437 sh_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4438 struct bfd_link_info
*info
)
4440 struct elf_sh_link_hash_table
*htab
;
4446 htab
= sh_elf_hash_table (info
);
4447 dynobj
= htab
->root
.dynobj
;
4448 BFD_ASSERT (dynobj
!= NULL
);
4450 if (htab
->root
.dynamic_sections_created
)
4452 /* Set the contents of the .interp section to the interpreter. */
4453 if (info
->executable
)
4455 s
= bfd_get_section_by_name (dynobj
, ".interp");
4456 BFD_ASSERT (s
!= NULL
);
4457 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4458 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4462 /* Set up .got offsets for local syms, and space for local dynamic
4464 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4466 bfd_signed_vma
*local_got
;
4467 bfd_signed_vma
*end_local_got
;
4468 char *local_tls_type
;
4469 bfd_size_type locsymcount
;
4470 Elf_Internal_Shdr
*symtab_hdr
;
4473 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
4476 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4478 struct elf_sh_dyn_relocs
*p
;
4480 for (p
= ((struct elf_sh_dyn_relocs
*)
4481 elf_section_data (s
)->local_dynrel
);
4485 if (! bfd_is_abs_section (p
->sec
)
4486 && bfd_is_abs_section (p
->sec
->output_section
))
4488 /* Input section has been discarded, either because
4489 it is a copy of a linkonce section or due to
4490 linker script /DISCARD/, so we'll be discarding
4493 else if (p
->count
!= 0)
4495 srel
= elf_section_data (p
->sec
)->sreloc
;
4496 srel
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
4497 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
4498 info
->flags
|= DF_TEXTREL
;
4503 local_got
= elf_local_got_refcounts (ibfd
);
4507 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4508 locsymcount
= symtab_hdr
->sh_info
;
4509 #ifdef INCLUDE_SHMEDIA
4510 /* Count datalabel local GOT. */
4513 end_local_got
= local_got
+ locsymcount
;
4514 local_tls_type
= sh_elf_local_got_tls_type (ibfd
);
4516 srel
= htab
->srelgot
;
4517 for (; local_got
< end_local_got
; ++local_got
)
4521 *local_got
= s
->_raw_size
;
4523 if (*local_tls_type
== GOT_TLS_GD
)
4526 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
4529 *local_got
= (bfd_vma
) -1;
4534 if (htab
->tls_ldm_got
.refcount
> 0)
4536 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
4538 htab
->tls_ldm_got
.offset
= htab
->sgot
->_raw_size
;
4539 htab
->sgot
->_raw_size
+= 8;
4540 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4543 htab
->tls_ldm_got
.offset
= -1;
4545 /* Allocate global sym .plt and .got entries, and space for global
4546 sym dynamic relocs. */
4547 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, info
);
4549 /* We now have determined the sizes of the various dynamic sections.
4550 Allocate memory for them. */
4552 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4554 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4559 || s
== htab
->sgotplt
)
4561 /* Strip this section if we don't need it; see the
4564 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4566 if (s
->_raw_size
!= 0 && s
!= htab
->srelplt
)
4569 /* We use the reloc_count field as a counter if we need
4570 to copy relocs into the output file. */
4575 /* It's not one of our sections, so don't allocate space. */
4579 if (s
->_raw_size
== 0)
4581 /* If we don't need this section, strip it from the
4582 output file. This is mostly to handle .rela.bss and
4583 .rela.plt. We must create both sections in
4584 create_dynamic_sections, because they must be created
4585 before the linker maps input sections to output
4586 sections. The linker does that before
4587 adjust_dynamic_symbol is called, and it is that
4588 function which decides whether anything needs to go
4589 into these sections. */
4591 _bfd_strip_section_from_output (info
, s
);
4595 /* Allocate memory for the section contents. We use bfd_zalloc
4596 here in case unused entries are not reclaimed before the
4597 section's contents are written out. This should not happen,
4598 but this way if it does, we get a R_SH_NONE reloc instead
4600 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4601 if (s
->contents
== NULL
)
4605 if (htab
->root
.dynamic_sections_created
)
4607 /* Add some entries to the .dynamic section. We fill in the
4608 values later, in sh_elf_finish_dynamic_sections, but we
4609 must add the entries now so that we get the correct size for
4610 the .dynamic section. The DT_DEBUG entry is filled in by the
4611 dynamic linker and used by the debugger. */
4612 #define add_dynamic_entry(TAG, VAL) \
4613 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4615 if (info
->executable
)
4617 if (! add_dynamic_entry (DT_DEBUG
, 0))
4621 if (htab
->splt
->_raw_size
!= 0)
4623 if (! add_dynamic_entry (DT_PLTGOT
, 0)
4624 || ! add_dynamic_entry (DT_PLTRELSZ
, 0)
4625 || ! add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4626 || ! add_dynamic_entry (DT_JMPREL
, 0))
4632 if (! add_dynamic_entry (DT_RELA
, 0)
4633 || ! add_dynamic_entry (DT_RELASZ
, 0)
4634 || ! add_dynamic_entry (DT_RELAENT
,
4635 sizeof (Elf32_External_Rela
)))
4638 /* If any dynamic relocs apply to a read-only section,
4639 then we need a DT_TEXTREL entry. */
4640 if ((info
->flags
& DF_TEXTREL
) == 0)
4641 elf_link_hash_traverse (&htab
->root
, readonly_dynrelocs
, info
);
4643 if ((info
->flags
& DF_TEXTREL
) != 0)
4645 if (! add_dynamic_entry (DT_TEXTREL
, 0))
4650 #undef add_dynamic_entry
4655 /* Relocate an SH ELF section. */
4658 sh_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
4659 bfd
*input_bfd
, asection
*input_section
,
4660 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
4661 Elf_Internal_Sym
*local_syms
,
4662 asection
**local_sections
)
4664 struct elf_sh_link_hash_table
*htab
;
4665 Elf_Internal_Shdr
*symtab_hdr
;
4666 struct elf_link_hash_entry
**sym_hashes
;
4667 Elf_Internal_Rela
*rel
, *relend
;
4669 bfd_vma
*local_got_offsets
;
4676 htab
= sh_elf_hash_table (info
);
4677 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4678 sym_hashes
= elf_sym_hashes (input_bfd
);
4679 dynobj
= htab
->root
.dynobj
;
4680 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4683 sgotplt
= htab
->sgotplt
;
4689 relend
= relocs
+ input_section
->reloc_count
;
4690 for (; rel
< relend
; rel
++)
4693 reloc_howto_type
*howto
;
4694 unsigned long r_symndx
;
4695 Elf_Internal_Sym
*sym
;
4697 struct elf_link_hash_entry
*h
;
4699 bfd_vma addend
= (bfd_vma
) 0;
4700 bfd_reloc_status_type r
;
4701 int seen_stt_datalabel
= 0;
4705 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4707 r_type
= ELF32_R_TYPE (rel
->r_info
);
4709 /* Many of the relocs are only used for relaxing, and are
4710 handled entirely by the relaxation code. */
4711 if (r_type
>= (int) R_SH_GNU_VTINHERIT
4712 && r_type
<= (int) R_SH_LABEL
)
4714 if (r_type
== (int) R_SH_NONE
)
4718 || r_type
>= R_SH_max
4719 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
4720 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
4721 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_3
4722 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_3
)
4723 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_4
4724 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_4
)
4725 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_5
4726 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_5
)
4727 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_2
4728 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_2
))
4730 bfd_set_error (bfd_error_bad_value
);
4734 howto
= sh_elf_howto_table
+ r_type
;
4736 /* For relocs that aren't partial_inplace, we get the addend from
4738 if (! howto
->partial_inplace
)
4739 addend
= rel
->r_addend
;
4744 if (r_symndx
< symtab_hdr
->sh_info
)
4746 sym
= local_syms
+ r_symndx
;
4747 sec
= local_sections
[r_symndx
];
4748 relocation
= (sec
->output_section
->vma
4749 + sec
->output_offset
4751 /* A local symbol never has STO_SH5_ISA32, so we don't need
4752 datalabel processing here. Make sure this does not change
4754 if ((sym
->st_other
& STO_SH5_ISA32
) != 0)
4755 ((*info
->callbacks
->reloc_dangerous
)
4757 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4758 input_bfd
, input_section
, rel
->r_offset
));
4759 if (info
->relocatable
)
4761 /* This is a relocatable link. We don't have to change
4762 anything, unless the reloc is against a section symbol,
4763 in which case we have to adjust according to where the
4764 section symbol winds up in the output section. */
4765 sym
= local_syms
+ r_symndx
;
4766 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4768 if (! howto
->partial_inplace
)
4770 /* For relocations with the addend in the
4771 relocation, we need just to update the addend.
4772 All real relocs are of type partial_inplace; this
4773 code is mostly for completeness. */
4774 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
4779 /* Relocs of type partial_inplace need to pick up the
4780 contents in the contents and add the offset resulting
4781 from the changed location of the section symbol.
4782 Using _bfd_final_link_relocate (e.g. goto
4783 final_link_relocate) here would be wrong, because
4784 relocations marked pc_relative would get the current
4785 location subtracted, and we must only do that at the
4787 r
= _bfd_relocate_contents (howto
, input_bfd
,
4790 contents
+ rel
->r_offset
);
4791 goto relocation_done
;
4796 else if (! howto
->partial_inplace
)
4798 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4799 addend
= rel
->r_addend
;
4801 else if ((sec
->flags
& SEC_MERGE
)
4802 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4806 if (howto
->rightshift
|| howto
->src_mask
!= 0xffffffff)
4808 (*_bfd_error_handler
)
4809 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
4810 bfd_archive_filename (input_bfd
),
4811 bfd_get_section_name (input_bfd
, input_section
),
4812 (long) rel
->r_offset
, howto
->name
);
4816 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4819 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
4821 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
4822 bfd_put_32 (input_bfd
, addend
, contents
+ rel
->r_offset
);
4828 /* FIXME: Ought to make use of the RELOC_FOR_GLOBAL_SYMBOL macro. */
4830 /* Section symbol are never (?) placed in the hash table, so
4831 we can just ignore hash relocations when creating a
4832 relocatable object file. */
4833 if (info
->relocatable
)
4836 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4837 while (h
->root
.type
== bfd_link_hash_indirect
4838 || h
->root
.type
== bfd_link_hash_warning
)
4840 #ifdef INCLUDE_SHMEDIA
4841 /* If the reference passes a symbol marked with
4842 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4844 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
4846 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4848 if (h
->root
.type
== bfd_link_hash_defined
4849 || h
->root
.type
== bfd_link_hash_defweak
)
4853 dyn
= htab
->root
.dynamic_sections_created
;
4854 sec
= h
->root
.u
.def
.section
;
4855 /* In these cases, we don't need the relocation value.
4856 We check specially because in some obscure cases
4857 sec->output_section will be NULL. */
4858 if (r_type
== R_SH_GOTPC
4859 || r_type
== R_SH_GOTPC_LOW16
4860 || r_type
== R_SH_GOTPC_MEDLOW16
4861 || r_type
== R_SH_GOTPC_MEDHI16
4862 || r_type
== R_SH_GOTPC_HI16
4863 || ((r_type
== R_SH_PLT32
4864 || r_type
== R_SH_PLT_LOW16
4865 || r_type
== R_SH_PLT_MEDLOW16
4866 || r_type
== R_SH_PLT_MEDHI16
4867 || r_type
== R_SH_PLT_HI16
)
4868 && h
->plt
.offset
!= (bfd_vma
) -1)
4869 || ((r_type
== R_SH_GOT32
4870 || r_type
== R_SH_GOT_LOW16
4871 || r_type
== R_SH_GOT_MEDLOW16
4872 || r_type
== R_SH_GOT_MEDHI16
4873 || r_type
== R_SH_GOT_HI16
)
4874 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
4876 || (! info
->symbolic
&& h
->dynindx
!= -1)
4877 || (h
->elf_link_hash_flags
4878 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4879 /* The cases above are those in which relocation is
4880 overwritten in the switch block below. The cases
4881 below are those in which we must defer relocation
4882 to run-time, because we can't resolve absolute
4883 addresses when creating a shared library. */
4885 && ((! info
->symbolic
&& h
->dynindx
!= -1)
4886 || (h
->elf_link_hash_flags
4887 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
4888 && ((r_type
== R_SH_DIR32
4889 && (h
->elf_link_hash_flags
4890 & ELF_LINK_FORCED_LOCAL
) == 0)
4891 || r_type
== R_SH_REL32
)
4892 && ((input_section
->flags
& SEC_ALLOC
) != 0
4893 /* DWARF will emit R_SH_DIR32 relocations in its
4894 sections against symbols defined externally
4895 in shared libraries. We can't do anything
4897 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
4898 && (h
->elf_link_hash_flags
4899 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)))
4900 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4901 sections because such sections are not SEC_ALLOC and
4902 thus ld.so will not process them. */
4903 || (sec
->output_section
== NULL
4904 && ((input_section
->flags
& SEC_DEBUGGING
) != 0
4905 && (h
->elf_link_hash_flags
4906 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
4907 || (sec
->output_section
== NULL
4908 && (sh_elf_hash_entry (h
)->tls_type
== GOT_TLS_IE
4909 || sh_elf_hash_entry (h
)->tls_type
== GOT_TLS_GD
)))
4911 else if (sec
->output_section
== NULL
)
4913 (*_bfd_error_handler
)
4914 (_("%s: unresolvable relocation against symbol `%s' from %s section"),
4915 bfd_archive_filename (input_bfd
), h
->root
.root
.string
,
4916 bfd_get_section_name (input_bfd
, input_section
));
4920 relocation
= ((h
->root
.u
.def
.value
4921 + sec
->output_section
->vma
4922 + sec
->output_offset
)
4923 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4924 symbol value, unless we've seen
4925 STT_DATALABEL on the way to it. */
4926 | ((h
->other
& STO_SH5_ISA32
) != 0
4927 && ! seen_stt_datalabel
));
4929 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4931 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
4932 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4936 if (! info
->callbacks
->undefined_symbol
4937 (info
, h
->root
.root
.string
, input_bfd
,
4938 input_section
, rel
->r_offset
,
4939 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
4940 || ELF_ST_VISIBILITY (h
->other
))))
4946 switch ((int) r_type
)
4948 final_link_relocate
:
4949 /* COFF relocs don't use the addend. The addend is used for
4950 R_SH_DIR32 to be compatible with other compilers. */
4951 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4952 contents
, rel
->r_offset
,
4953 relocation
, addend
);
4957 goto final_link_relocate
;
4962 /* If the reloc is against the start of this section, then
4963 the assembler has already taken care of it and the reloc
4964 is here only to assist in relaxing. If the reloc is not
4965 against the start of this section, then it's against an
4966 external symbol and we must deal with it ourselves. */
4967 if (input_section
->output_section
->vma
+ input_section
->output_offset
4970 int disp
= (relocation
4971 - input_section
->output_section
->vma
4972 - input_section
->output_offset
4978 case R_SH_DIR8WPZ
: mask
= 1; break;
4979 case R_SH_DIR8WPL
: mask
= 3; break;
4980 default: mask
= 0; break;
4984 ((*_bfd_error_handler
)
4985 (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4986 bfd_archive_filename (input_section
->owner
),
4987 (unsigned long) rel
->r_offset
));
4988 bfd_set_error (bfd_error_bad_value
);
4992 goto final_link_relocate
;
4998 #ifdef INCLUDE_SHMEDIA
4999 if (shmedia_prepare_reloc (info
, input_bfd
, input_section
,
5000 contents
, rel
, &relocation
))
5001 goto final_link_relocate
;
5003 bfd_set_error (bfd_error_bad_value
);
5011 goto final_link_relocate
;
5017 ((*_bfd_error_handler
)
5018 (_("%s: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
5019 bfd_archive_filename (input_section
->owner
),
5020 (unsigned long) rel
->r_offset
, howto
->name
,
5021 (unsigned long)relocation
));
5022 bfd_set_error (bfd_error_bad_value
);
5025 goto final_link_relocate
;
5032 ((*_bfd_error_handler
)
5033 (_("%s: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
5034 bfd_archive_filename (input_section
->owner
),
5035 (unsigned long) rel
->r_offset
, howto
->name
,
5036 (unsigned long)relocation
));
5037 bfd_set_error (bfd_error_bad_value
);
5040 goto final_link_relocate
;
5043 if ((signed int)relocation
< -32
5044 || (signed int)relocation
> 32)
5046 ((*_bfd_error_handler
)
5047 (_("%s: 0x%lx: fatal: R_SH_PSHA relocation %d not in range -32..32"),
5048 bfd_archive_filename (input_section
->owner
),
5049 (unsigned long) rel
->r_offset
,
5050 (unsigned long)relocation
));
5051 bfd_set_error (bfd_error_bad_value
);
5054 goto final_link_relocate
;
5057 if ((signed int)relocation
< -16
5058 || (signed int)relocation
> 16)
5060 ((*_bfd_error_handler
)
5061 (_("%s: 0x%lx: fatal: R_SH_PSHL relocation %d not in range -32..32"),
5062 bfd_archive_filename (input_section
->owner
),
5063 (unsigned long) rel
->r_offset
,
5064 (unsigned long)relocation
));
5065 bfd_set_error (bfd_error_bad_value
);
5068 goto final_link_relocate
;
5072 #ifdef INCLUDE_SHMEDIA
5073 case R_SH_IMM_LOW16_PCREL
:
5074 case R_SH_IMM_MEDLOW16_PCREL
:
5075 case R_SH_IMM_MEDHI16_PCREL
:
5076 case R_SH_IMM_HI16_PCREL
:
5080 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5081 || h
->root
.type
!= bfd_link_hash_undefweak
)
5083 && (input_section
->flags
& SEC_ALLOC
) != 0
5084 && (r_type
== R_SH_DIR32
5085 || !SYMBOL_CALLS_LOCAL (info
, h
)))
5087 Elf_Internal_Rela outrel
;
5089 bfd_boolean skip
, relocate
;
5091 /* When generating a shared object, these relocations
5092 are copied into the output file to be resolved at run
5099 name
= (bfd_elf_string_from_elf_section
5101 elf_elfheader (input_bfd
)->e_shstrndx
,
5102 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5106 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5107 && strcmp (bfd_get_section_name (input_bfd
,
5111 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5112 BFD_ASSERT (sreloc
!= NULL
);
5119 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5121 if (outrel
.r_offset
== (bfd_vma
) -1)
5123 else if (outrel
.r_offset
== (bfd_vma
) -2)
5124 skip
= TRUE
, relocate
= TRUE
;
5125 outrel
.r_offset
+= (input_section
->output_section
->vma
5126 + input_section
->output_offset
);
5129 memset (&outrel
, 0, sizeof outrel
);
5130 else if (r_type
== R_SH_REL32
)
5132 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
5133 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_REL32
);
5135 = bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5137 #ifdef INCLUDE_SHMEDIA
5138 else if (r_type
== R_SH_IMM_LOW16_PCREL
5139 || r_type
== R_SH_IMM_MEDLOW16_PCREL
5140 || r_type
== R_SH_IMM_MEDHI16_PCREL
5141 || r_type
== R_SH_IMM_HI16_PCREL
)
5143 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
5144 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5145 outrel
.r_addend
= addend
;
5150 /* h->dynindx may be -1 if this symbol was marked to
5153 || ((info
->symbolic
|| h
->dynindx
== -1)
5154 && (h
->elf_link_hash_flags
5155 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
5158 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
5160 = relocation
+ bfd_get_32 (input_bfd
,
5161 contents
+ rel
->r_offset
);
5165 BFD_ASSERT (h
->dynindx
!= -1);
5166 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_DIR32
);
5168 = relocation
+ bfd_get_32 (input_bfd
,
5169 contents
+ rel
->r_offset
);
5173 loc
= sreloc
->contents
;
5174 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5175 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5177 /* If this reloc is against an external symbol, we do
5178 not want to fiddle with the addend. Otherwise, we
5179 need to include the symbol value so that it becomes
5180 an addend for the dynamic reloc. */
5184 goto final_link_relocate
;
5187 #ifdef INCLUDE_SHMEDIA
5188 case R_SH_GOTPLT_LOW16
:
5189 case R_SH_GOTPLT_MEDLOW16
:
5190 case R_SH_GOTPLT_MEDHI16
:
5191 case R_SH_GOTPLT_HI16
:
5192 case R_SH_GOTPLT10BY4
:
5193 case R_SH_GOTPLT10BY8
:
5195 /* Relocation is to the entry for this symbol in the
5196 procedure linkage table. */
5199 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
5203 || h
->plt
.offset
== (bfd_vma
) -1
5204 || h
->got
.offset
!= (bfd_vma
) -1)
5207 /* Relocation is to the entry for this symbol in the global
5208 offset table extension for the procedure linkage table. */
5210 BFD_ASSERT (sgotplt
!= NULL
);
5211 relocation
= (sgotplt
->output_offset
5212 + ((h
->plt
.offset
/ elf_sh_sizeof_plt (info
)
5216 relocation
-= GOT_BIAS
;
5219 goto final_link_relocate
;
5223 #ifdef INCLUDE_SHMEDIA
5224 case R_SH_GOT_LOW16
:
5225 case R_SH_GOT_MEDLOW16
:
5226 case R_SH_GOT_MEDHI16
:
5231 /* Relocation is to the entry for this symbol in the global
5234 BFD_ASSERT (sgot
!= NULL
);
5240 off
= h
->got
.offset
;
5241 #ifdef INCLUDE_SHMEDIA
5242 if (seen_stt_datalabel
)
5244 struct elf_sh_link_hash_entry
*hsh
;
5246 hsh
= (struct elf_sh_link_hash_entry
*)h
;
5247 off
= hsh
->datalabel_got
.offset
;
5250 BFD_ASSERT (off
!= (bfd_vma
) -1);
5252 dyn
= htab
->root
.dynamic_sections_created
;
5253 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
5255 && SYMBOL_REFERENCES_LOCAL (info
, h
))
5256 || (ELF_ST_VISIBILITY (h
->other
)
5257 && h
->root
.type
== bfd_link_hash_undefweak
))
5259 /* This is actually a static link, or it is a
5260 -Bsymbolic link and the symbol is defined
5261 locally, or the symbol was forced to be local
5262 because of a version file. We must initialize
5263 this entry in the global offset table. Since the
5264 offset must always be a multiple of 4, we use the
5265 least significant bit to record whether we have
5266 initialized it already.
5268 When doing a dynamic link, we create a .rela.got
5269 relocation entry to initialize the value. This
5270 is done in the finish_dynamic_symbol routine. */
5275 bfd_put_32 (output_bfd
, relocation
,
5276 sgot
->contents
+ off
);
5277 #ifdef INCLUDE_SHMEDIA
5278 if (seen_stt_datalabel
)
5280 struct elf_sh_link_hash_entry
*hsh
;
5282 hsh
= (struct elf_sh_link_hash_entry
*)h
;
5283 hsh
->datalabel_got
.offset
|= 1;
5291 relocation
= sgot
->output_offset
+ off
;
5295 #ifdef INCLUDE_SHMEDIA
5298 BFD_ASSERT (local_got_offsets
!= NULL
5299 && (local_got_offsets
[symtab_hdr
->sh_info
5303 off
= local_got_offsets
[symtab_hdr
->sh_info
5309 BFD_ASSERT (local_got_offsets
!= NULL
5310 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
5312 off
= local_got_offsets
[r_symndx
];
5313 #ifdef INCLUDE_SHMEDIA
5317 /* The offset must always be a multiple of 4. We use
5318 the least significant bit to record whether we have
5319 already generated the necessary reloc. */
5324 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
5328 Elf_Internal_Rela outrel
;
5331 if (srelgot
== NULL
)
5333 srelgot
= bfd_get_section_by_name (dynobj
,
5335 BFD_ASSERT (srelgot
!= NULL
);
5338 outrel
.r_offset
= (sgot
->output_section
->vma
5339 + sgot
->output_offset
5341 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
5342 outrel
.r_addend
= relocation
;
5343 loc
= srelgot
->contents
;
5344 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5345 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5348 #ifdef INCLUDE_SHMEDIA
5350 local_got_offsets
[symtab_hdr
->sh_info
+ r_symndx
] |= 1;
5353 local_got_offsets
[r_symndx
] |= 1;
5356 relocation
= sgot
->output_offset
+ off
;
5360 relocation
-= GOT_BIAS
;
5363 goto final_link_relocate
;
5366 #ifdef INCLUDE_SHMEDIA
5367 case R_SH_GOTOFF_LOW16
:
5368 case R_SH_GOTOFF_MEDLOW16
:
5369 case R_SH_GOTOFF_MEDHI16
:
5370 case R_SH_GOTOFF_HI16
:
5372 /* Relocation is relative to the start of the global offset
5375 BFD_ASSERT (sgot
!= NULL
);
5377 /* Note that sgot->output_offset is not involved in this
5378 calculation. We always want the start of .got. If we
5379 defined _GLOBAL_OFFSET_TABLE in a different way, as is
5380 permitted by the ABI, we might have to change this
5382 relocation
-= sgot
->output_section
->vma
;
5385 relocation
-= GOT_BIAS
;
5388 addend
= rel
->r_addend
;
5390 goto final_link_relocate
;
5393 #ifdef INCLUDE_SHMEDIA
5394 case R_SH_GOTPC_LOW16
:
5395 case R_SH_GOTPC_MEDLOW16
:
5396 case R_SH_GOTPC_MEDHI16
:
5397 case R_SH_GOTPC_HI16
:
5399 /* Use global offset table as symbol value. */
5401 BFD_ASSERT (sgot
!= NULL
);
5402 relocation
= sgot
->output_section
->vma
;
5405 relocation
+= GOT_BIAS
;
5408 addend
= rel
->r_addend
;
5410 goto final_link_relocate
;
5413 #ifdef INCLUDE_SHMEDIA
5414 case R_SH_PLT_LOW16
:
5415 case R_SH_PLT_MEDLOW16
:
5416 case R_SH_PLT_MEDHI16
:
5419 /* Relocation is to the entry for this symbol in the
5420 procedure linkage table. */
5422 /* Resolve a PLT reloc against a local symbol directly,
5423 without using the procedure linkage table. */
5425 goto final_link_relocate
;
5427 if (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
5428 goto final_link_relocate
;
5430 if (h
->plt
.offset
== (bfd_vma
) -1)
5432 /* We didn't make a PLT entry for this symbol. This
5433 happens when statically linking PIC code, or when
5434 using -Bsymbolic. */
5435 goto final_link_relocate
;
5438 BFD_ASSERT (splt
!= NULL
);
5439 relocation
= (splt
->output_section
->vma
5440 + splt
->output_offset
5443 #ifdef INCLUDE_SHMEDIA
5447 addend
= rel
->r_addend
;
5449 goto final_link_relocate
;
5451 case R_SH_LOOP_START
:
5453 static bfd_vma start
, end
;
5455 start
= (relocation
+ rel
->r_addend
5456 - (sec
->output_section
->vma
+ sec
->output_offset
));
5457 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5458 rel
->r_offset
, sec
, start
, end
);
5462 end
= (relocation
+ rel
->r_addend
5463 - (sec
->output_section
->vma
+ sec
->output_offset
));
5464 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5465 rel
->r_offset
, sec
, start
, end
);
5469 case R_SH_TLS_GD_32
:
5470 case R_SH_TLS_IE_32
:
5471 r_type
= sh_elf_optimized_tls_reloc (info
, r_type
, h
== NULL
);
5472 tls_type
= GOT_UNKNOWN
;
5473 if (h
== NULL
&& local_got_offsets
)
5474 tls_type
= sh_elf_local_got_tls_type (input_bfd
) [r_symndx
];
5477 tls_type
= sh_elf_hash_entry (h
)->tls_type
;
5479 && (h
->dynindx
== -1
5480 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
5481 r_type
= R_SH_TLS_LE_32
;
5484 if (r_type
== R_SH_TLS_GD_32
&& tls_type
== GOT_TLS_IE
)
5485 r_type
= R_SH_TLS_IE_32
;
5487 if (r_type
== R_SH_TLS_LE_32
)
5490 unsigned short insn
;
5492 if (ELF32_R_TYPE (rel
->r_info
) == R_SH_TLS_GD_32
)
5494 /* GD->LE transition:
5495 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5496 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5497 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5499 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5501 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
5503 offset
= rel
->r_offset
;
5504 BFD_ASSERT (offset
>= 16);
5505 /* Size of GD instructions is 16 or 18. */
5507 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5508 if ((insn
& 0xff00) == 0xc700)
5510 BFD_ASSERT (offset
>= 2);
5512 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5515 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5516 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5517 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5518 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5519 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5520 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5521 BFD_ASSERT (insn
== 0x310c);
5522 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5523 BFD_ASSERT (insn
== 0x410b);
5524 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5525 BFD_ASSERT (insn
== 0x34cc);
5527 bfd_put_16 (output_bfd
, 0x0012, contents
+ offset
+ 2);
5528 bfd_put_16 (output_bfd
, 0x304c, contents
+ offset
+ 4);
5529 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 6);
5530 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5531 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5537 /* IE->LE transition:
5538 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5539 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5541 mov.l .Ln,rM; stc gbr,rN; nop; ...;
5544 offset
= rel
->r_offset
;
5545 BFD_ASSERT (offset
>= 16);
5546 /* Size of IE instructions is 10 or 12. */
5548 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5549 if ((insn
& 0xf0ff) == 0x0012)
5551 BFD_ASSERT (offset
>= 2);
5553 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5556 BFD_ASSERT ((insn
& 0xff00) == 0xd000);
5557 index
= insn
& 0x00ff;
5558 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5559 BFD_ASSERT ((insn
& 0xf0ff) == 0x0012);
5560 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5561 BFD_ASSERT ((insn
& 0xf0ff) == 0x00ce);
5562 insn
= 0xd000 | (insn
& 0x0f00) | index
;
5563 bfd_put_16 (output_bfd
, insn
, contents
+ offset
+ 0);
5564 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 4);
5567 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
5568 contents
+ rel
->r_offset
);
5577 off
= h
->got
.offset
;
5580 if (local_got_offsets
== NULL
)
5583 off
= local_got_offsets
[r_symndx
];
5586 /* Relocate R_SH_TLS_IE_32 directly when statically linking. */
5587 if (r_type
== R_SH_TLS_IE_32
5588 && ! htab
->root
.dynamic_sections_created
)
5591 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
5592 sgot
->contents
+ off
);
5593 bfd_put_32 (output_bfd
, sgot
->output_offset
+ off
,
5594 contents
+ rel
->r_offset
);
5602 Elf_Internal_Rela outrel
;
5606 if (srelgot
== NULL
)
5608 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
5609 BFD_ASSERT (srelgot
!= NULL
);
5612 outrel
.r_offset
= (sgot
->output_section
->vma
5613 + sgot
->output_offset
+ off
);
5615 if (h
== NULL
|| h
->dynindx
== -1)
5620 dr_type
= (r_type
== R_SH_TLS_GD_32
? R_SH_TLS_DTPMOD32
:
5622 if (dr_type
== R_SH_TLS_TPOFF32
&& indx
== 0)
5623 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5625 outrel
.r_addend
= 0;
5626 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
5627 loc
= srelgot
->contents
;
5628 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5629 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5631 if (r_type
== R_SH_TLS_GD_32
)
5635 bfd_put_32 (output_bfd
,
5636 relocation
- dtpoff_base (info
),
5637 sgot
->contents
+ off
+ 4);
5641 outrel
.r_info
= ELF32_R_INFO (indx
,
5643 outrel
.r_offset
+= 4;
5644 outrel
.r_addend
= 0;
5645 srelgot
->reloc_count
++;
5646 loc
+= sizeof (Elf32_External_Rela
);
5647 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5654 local_got_offsets
[r_symndx
] |= 1;
5657 if (off
>= (bfd_vma
) -2)
5660 if (r_type
== (int) ELF32_R_TYPE (rel
->r_info
))
5661 relocation
= sgot
->output_offset
+ off
;
5665 unsigned short insn
;
5667 /* GD->IE transition:
5668 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5669 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5670 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5672 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5673 nop; nop; bra 3f; nop; .align 2;
5674 1: .long x@TPOFF; 2:...; 3:. */
5676 offset
= rel
->r_offset
;
5677 BFD_ASSERT (offset
>= 16);
5678 /* Size of GD instructions is 16 or 18. */
5680 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5681 if ((insn
& 0xff00) == 0xc700)
5683 BFD_ASSERT (offset
>= 2);
5685 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5688 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5690 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
5691 bfd_put_16 (output_bfd
, insn
& 0xf0ff, contents
+ offset
);
5693 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5694 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5695 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5696 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5697 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5698 BFD_ASSERT (insn
== 0x310c);
5699 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5700 BFD_ASSERT (insn
== 0x410b);
5701 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5702 BFD_ASSERT (insn
== 0x34cc);
5704 bfd_put_16 (output_bfd
, 0x0412, contents
+ offset
+ 2);
5705 bfd_put_16 (output_bfd
, 0x00ce, contents
+ offset
+ 4);
5706 bfd_put_16 (output_bfd
, 0x304c, contents
+ offset
+ 6);
5707 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5708 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5710 bfd_put_32 (output_bfd
, sgot
->output_offset
+ off
,
5711 contents
+ rel
->r_offset
);
5716 addend
= rel
->r_addend
;
5718 goto final_link_relocate
;
5720 case R_SH_TLS_LD_32
:
5724 unsigned short insn
;
5726 /* LD->LE transition:
5727 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5728 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5729 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5731 stc gbr,r0; nop; nop; nop;
5732 nop; nop; bra 3f; ...; 3:. */
5734 offset
= rel
->r_offset
;
5735 BFD_ASSERT (offset
>= 16);
5736 /* Size of LD instructions is 16 or 18. */
5738 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5739 if ((insn
& 0xff00) == 0xc700)
5741 BFD_ASSERT (offset
>= 2);
5743 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5746 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5747 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5748 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5749 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5750 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5751 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5752 BFD_ASSERT (insn
== 0x310c);
5753 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5754 BFD_ASSERT (insn
== 0x410b);
5755 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5756 BFD_ASSERT (insn
== 0x34cc);
5758 bfd_put_16 (output_bfd
, 0x0012, contents
+ offset
+ 0);
5759 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 2);
5760 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 4);
5761 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 6);
5762 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5763 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5772 off
= htab
->tls_ldm_got
.offset
;
5777 Elf_Internal_Rela outrel
;
5780 srelgot
= htab
->srelgot
;
5781 if (srelgot
== NULL
)
5784 outrel
.r_offset
= (sgot
->output_section
->vma
5785 + sgot
->output_offset
+ off
);
5786 outrel
.r_addend
= 0;
5787 outrel
.r_info
= ELF32_R_INFO (0, R_SH_TLS_DTPMOD32
);
5788 loc
= srelgot
->contents
;
5789 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5790 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5791 htab
->tls_ldm_got
.offset
|= 1;
5794 relocation
= sgot
->output_offset
+ off
;
5795 addend
= rel
->r_addend
;
5797 goto final_link_relocate
;
5799 case R_SH_TLS_LDO_32
:
5801 relocation
= tpoff (info
, relocation
);
5803 relocation
-= dtpoff_base (info
);
5805 addend
= rel
->r_addend
;
5806 goto final_link_relocate
;
5808 case R_SH_TLS_LE_32
:
5811 Elf_Internal_Rela outrel
;
5816 relocation
= tpoff (info
, relocation
);
5817 addend
= rel
->r_addend
;
5818 goto final_link_relocate
;
5825 name
= (bfd_elf_string_from_elf_section
5827 elf_elfheader (input_bfd
)->e_shstrndx
,
5828 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5832 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5833 && strcmp (bfd_get_section_name (input_bfd
,
5837 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5838 BFD_ASSERT (sreloc
!= NULL
);
5841 if (h
== NULL
|| h
->dynindx
== -1)
5846 outrel
.r_offset
= (input_section
->output_section
->vma
5847 + input_section
->output_offset
5849 outrel
.r_info
= ELF32_R_INFO (indx
, R_SH_TLS_TPOFF32
);
5851 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5853 outrel
.r_addend
= 0;
5855 loc
= sreloc
->contents
;
5856 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5857 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5863 if (r
!= bfd_reloc_ok
)
5868 case bfd_reloc_outofrange
:
5870 case bfd_reloc_overflow
:
5875 name
= h
->root
.root
.string
;
5878 name
= (bfd_elf_string_from_elf_section
5879 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5883 name
= bfd_section_name (input_bfd
, sec
);
5885 if (! ((*info
->callbacks
->reloc_overflow
)
5886 (info
, name
, howto
->name
, (bfd_vma
) 0,
5887 input_bfd
, input_section
, rel
->r_offset
)))
5898 /* This is a version of bfd_generic_get_relocated_section_contents
5899 which uses sh_elf_relocate_section. */
5902 sh_elf_get_relocated_section_contents (bfd
*output_bfd
,
5903 struct bfd_link_info
*link_info
,
5904 struct bfd_link_order
*link_order
,
5906 bfd_boolean relocatable
,
5909 Elf_Internal_Shdr
*symtab_hdr
;
5910 asection
*input_section
= link_order
->u
.indirect
.section
;
5911 bfd
*input_bfd
= input_section
->owner
;
5912 asection
**sections
= NULL
;
5913 Elf_Internal_Rela
*internal_relocs
= NULL
;
5914 Elf_Internal_Sym
*isymbuf
= NULL
;
5916 /* We only need to handle the case of relaxing, or of having a
5917 particular set of section contents, specially. */
5919 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
5920 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
5925 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5927 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
5928 (size_t) input_section
->_raw_size
);
5930 if ((input_section
->flags
& SEC_RELOC
) != 0
5931 && input_section
->reloc_count
> 0)
5934 Elf_Internal_Sym
*isym
, *isymend
;
5937 internal_relocs
= (_bfd_elf_link_read_relocs
5938 (input_bfd
, input_section
, NULL
,
5939 (Elf_Internal_Rela
*) NULL
, FALSE
));
5940 if (internal_relocs
== NULL
)
5943 if (symtab_hdr
->sh_info
!= 0)
5945 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5946 if (isymbuf
== NULL
)
5947 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
5948 symtab_hdr
->sh_info
, 0,
5950 if (isymbuf
== NULL
)
5954 amt
= symtab_hdr
->sh_info
;
5955 amt
*= sizeof (asection
*);
5956 sections
= (asection
**) bfd_malloc (amt
);
5957 if (sections
== NULL
&& amt
!= 0)
5960 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
5961 for (isym
= isymbuf
, secpp
= sections
; isym
< isymend
; ++isym
, ++secpp
)
5965 if (isym
->st_shndx
== SHN_UNDEF
)
5966 isec
= bfd_und_section_ptr
;
5967 else if (isym
->st_shndx
== SHN_ABS
)
5968 isec
= bfd_abs_section_ptr
;
5969 else if (isym
->st_shndx
== SHN_COMMON
)
5970 isec
= bfd_com_section_ptr
;
5972 isec
= bfd_section_from_elf_index (input_bfd
, isym
->st_shndx
);
5977 if (! sh_elf_relocate_section (output_bfd
, link_info
, input_bfd
,
5978 input_section
, data
, internal_relocs
,
5982 if (sections
!= NULL
)
5985 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5987 if (elf_section_data (input_section
)->relocs
!= internal_relocs
)
5988 free (internal_relocs
);
5994 if (sections
!= NULL
)
5997 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5999 if (internal_relocs
!= NULL
6000 && elf_section_data (input_section
)->relocs
!= internal_relocs
)
6001 free (internal_relocs
);
6005 /* Return the base VMA address which should be subtracted from real addresses
6006 when resolving @dtpoff relocation.
6007 This is PT_TLS segment p_vaddr. */
6010 dtpoff_base (struct bfd_link_info
*info
)
6012 /* If tls_sec is NULL, we should have signalled an error already. */
6013 if (elf_hash_table (info
)->tls_sec
== NULL
)
6015 return elf_hash_table (info
)->tls_sec
->vma
;
6018 /* Return the relocation value for R_SH_TLS_TPOFF32.. */
6021 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
6023 /* If tls_sec is NULL, we should have signalled an error already. */
6024 if (elf_hash_table (info
)->tls_sec
== NULL
)
6026 /* SH TLS ABI is variant I and static TLS block start just after tcbhead
6027 structure which has 2 pointer fields. */
6028 return address
- elf_hash_table (info
)->tls_sec
->vma
+ 8;
6032 sh_elf_gc_mark_hook (asection
*sec
,
6033 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6034 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
,
6035 Elf_Internal_Sym
*sym
)
6039 switch (ELF32_R_TYPE (rel
->r_info
))
6041 case R_SH_GNU_VTINHERIT
:
6042 case R_SH_GNU_VTENTRY
:
6046 #ifdef INCLUDE_SHMEDIA
6047 while (h
->root
.type
== bfd_link_hash_indirect
6048 && h
->root
.u
.i
.link
)
6049 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6051 switch (h
->root
.type
)
6053 case bfd_link_hash_defined
:
6054 case bfd_link_hash_defweak
:
6055 return h
->root
.u
.def
.section
;
6057 case bfd_link_hash_common
:
6058 return h
->root
.u
.c
.p
->section
;
6066 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6071 /* Update the got entry reference counts for the section being removed. */
6074 sh_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
6075 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6077 Elf_Internal_Shdr
*symtab_hdr
;
6078 struct elf_link_hash_entry
**sym_hashes
;
6079 bfd_signed_vma
*local_got_refcounts
;
6080 const Elf_Internal_Rela
*rel
, *relend
;
6082 elf_section_data (sec
)->local_dynrel
= NULL
;
6084 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6085 sym_hashes
= elf_sym_hashes (abfd
);
6086 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6088 relend
= relocs
+ sec
->reloc_count
;
6089 for (rel
= relocs
; rel
< relend
; rel
++)
6091 unsigned long r_symndx
;
6092 unsigned int r_type
;
6093 struct elf_link_hash_entry
*h
= NULL
;
6094 #ifdef INCLUDE_SHMEDIA
6095 int seen_stt_datalabel
= 0;
6098 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6099 if (r_symndx
>= symtab_hdr
->sh_info
)
6101 struct elf_sh_link_hash_entry
*eh
;
6102 struct elf_sh_dyn_relocs
**pp
;
6103 struct elf_sh_dyn_relocs
*p
;
6105 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6106 #ifdef INCLUDE_SHMEDIA
6107 while (h
->root
.type
== bfd_link_hash_indirect
6108 || h
->root
.type
== bfd_link_hash_warning
)
6110 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
6111 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6114 eh
= (struct elf_sh_link_hash_entry
*) h
;
6115 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
6118 /* Everything must go for SEC. */
6124 r_type
= ELF32_R_TYPE (rel
->r_info
);
6125 switch (sh_elf_optimized_tls_reloc (info
, r_type
, h
!= NULL
))
6127 case R_SH_TLS_LD_32
:
6128 if (sh_elf_hash_table (info
)->tls_ldm_got
.refcount
> 0)
6129 sh_elf_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
6135 #ifdef INCLUDE_SHMEDIA
6136 case R_SH_GOT_LOW16
:
6137 case R_SH_GOT_MEDLOW16
:
6138 case R_SH_GOT_MEDHI16
:
6142 case R_SH_GOTOFF_LOW16
:
6143 case R_SH_GOTOFF_MEDLOW16
:
6144 case R_SH_GOTOFF_MEDHI16
:
6145 case R_SH_GOTOFF_HI16
:
6146 case R_SH_GOTPC_LOW16
:
6147 case R_SH_GOTPC_MEDLOW16
:
6148 case R_SH_GOTPC_MEDHI16
:
6149 case R_SH_GOTPC_HI16
:
6151 case R_SH_TLS_GD_32
:
6152 case R_SH_TLS_IE_32
:
6155 #ifdef INCLUDE_SHMEDIA
6156 if (seen_stt_datalabel
)
6158 struct elf_sh_link_hash_entry
*eh
;
6159 eh
= (struct elf_sh_link_hash_entry
*) h
;
6160 if (eh
->datalabel_got
.refcount
> 0)
6161 eh
->datalabel_got
.refcount
-= 1;
6165 if (h
->got
.refcount
> 0)
6166 h
->got
.refcount
-= 1;
6168 else if (local_got_refcounts
!= NULL
)
6170 #ifdef INCLUDE_SHMEDIA
6171 if (rel
->r_addend
& 1)
6173 if (local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] > 0)
6174 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] -= 1;
6178 if (local_got_refcounts
[r_symndx
] > 0)
6179 local_got_refcounts
[r_symndx
] -= 1;
6190 #ifdef INCLUDE_SHMEDIA
6191 case R_SH_PLT_LOW16
:
6192 case R_SH_PLT_MEDLOW16
:
6193 case R_SH_PLT_MEDHI16
:
6198 if (h
->plt
.refcount
> 0)
6199 h
->plt
.refcount
-= 1;
6204 #ifdef INCLUDE_SHMEDIA
6205 case R_SH_GOTPLT_LOW16
:
6206 case R_SH_GOTPLT_MEDLOW16
:
6207 case R_SH_GOTPLT_MEDHI16
:
6208 case R_SH_GOTPLT_HI16
:
6209 case R_SH_GOTPLT10BY4
:
6210 case R_SH_GOTPLT10BY8
:
6214 struct elf_sh_link_hash_entry
*eh
;
6215 eh
= (struct elf_sh_link_hash_entry
*) h
;
6216 if (eh
->gotplt_refcount
> 0)
6218 eh
->gotplt_refcount
-= 1;
6219 if (h
->plt
.refcount
> 0)
6220 h
->plt
.refcount
-= 1;
6222 #ifdef INCLUDE_SHMEDIA
6223 else if (seen_stt_datalabel
)
6225 if (eh
->datalabel_got
.refcount
> 0)
6226 eh
->datalabel_got
.refcount
-= 1;
6229 else if (h
->got
.refcount
> 0)
6230 h
->got
.refcount
-= 1;
6232 else if (local_got_refcounts
!= NULL
)
6234 #ifdef INCLUDE_SHMEDIA
6235 if (rel
->r_addend
& 1)
6237 if (local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] > 0)
6238 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] -= 1;
6242 if (local_got_refcounts
[r_symndx
] > 0)
6243 local_got_refcounts
[r_symndx
] -= 1;
6255 /* Copy the extra info we tack onto an elf_link_hash_entry. */
6258 sh_elf_copy_indirect_symbol (const struct elf_backend_data
*bed
,
6259 struct elf_link_hash_entry
*dir
,
6260 struct elf_link_hash_entry
*ind
)
6262 struct elf_sh_link_hash_entry
*edir
, *eind
;
6263 #ifdef INCLUDE_SHMEDIA
6267 edir
= (struct elf_sh_link_hash_entry
*) dir
;
6268 eind
= (struct elf_sh_link_hash_entry
*) ind
;
6270 if (eind
->dyn_relocs
!= NULL
)
6272 if (edir
->dyn_relocs
!= NULL
)
6274 struct elf_sh_dyn_relocs
**pp
;
6275 struct elf_sh_dyn_relocs
*p
;
6277 BFD_ASSERT (ind
->root
.type
!= bfd_link_hash_indirect
);
6279 /* Add reloc counts against the weak sym to the strong sym
6280 list. Merge any entries against the same section. */
6281 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
6283 struct elf_sh_dyn_relocs
*q
;
6285 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
6286 if (q
->sec
== p
->sec
)
6288 q
->pc_count
+= p
->pc_count
;
6289 q
->count
+= p
->count
;
6296 *pp
= edir
->dyn_relocs
;
6299 edir
->dyn_relocs
= eind
->dyn_relocs
;
6300 eind
->dyn_relocs
= NULL
;
6302 edir
->gotplt_refcount
= eind
->gotplt_refcount
;
6303 eind
->gotplt_refcount
= 0;
6304 #ifdef INCLUDE_SHMEDIA
6305 tmp
= edir
->datalabel_got
.refcount
;
6308 edir
->datalabel_got
.refcount
= eind
->datalabel_got
.refcount
;
6309 eind
->datalabel_got
.refcount
= tmp
;
6312 BFD_ASSERT (eind
->datalabel_got
.refcount
< 1);
6315 if (ind
->root
.type
== bfd_link_hash_indirect
6316 && dir
->got
.refcount
<= 0)
6318 edir
->tls_type
= eind
->tls_type
;
6319 eind
->tls_type
= GOT_UNKNOWN
;
6322 if (ind
->root
.type
!= bfd_link_hash_indirect
6323 && (dir
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
6324 /* If called to transfer flags for a weakdef during processing
6325 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
6326 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
6327 dir
->elf_link_hash_flags
|=
6328 (ind
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_DYNAMIC
6329 | ELF_LINK_HASH_REF_REGULAR
6330 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
6331 | ELF_LINK_HASH_NEEDS_PLT
));
6333 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
6337 sh_elf_optimized_tls_reloc (struct bfd_link_info
*info
, int r_type
,
6345 case R_SH_TLS_GD_32
:
6346 case R_SH_TLS_IE_32
:
6348 return R_SH_TLS_LE_32
;
6349 return R_SH_TLS_IE_32
;
6350 case R_SH_TLS_LD_32
:
6351 return R_SH_TLS_LE_32
;
6357 /* Look through the relocs for a section during the first phase.
6358 Since we don't do .gots or .plts, we just need to consider the
6359 virtual table relocs for gc. */
6362 sh_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
6363 const Elf_Internal_Rela
*relocs
)
6365 Elf_Internal_Shdr
*symtab_hdr
;
6366 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
6367 struct elf_sh_link_hash_table
*htab
;
6368 const Elf_Internal_Rela
*rel
;
6369 const Elf_Internal_Rela
*rel_end
;
6370 bfd_vma
*local_got_offsets
;
6374 unsigned int r_type
;
6375 int tls_type
, old_tls_type
;
6381 if (info
->relocatable
)
6384 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6385 sym_hashes
= elf_sym_hashes (abfd
);
6386 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof (Elf32_External_Sym
);
6387 if (!elf_bad_symtab (abfd
))
6388 sym_hashes_end
-= symtab_hdr
->sh_info
;
6390 htab
= sh_elf_hash_table (info
);
6391 local_got_offsets
= elf_local_got_offsets (abfd
);
6393 rel_end
= relocs
+ sec
->reloc_count
;
6394 for (rel
= relocs
; rel
< rel_end
; rel
++)
6396 struct elf_link_hash_entry
*h
;
6397 unsigned long r_symndx
;
6398 #ifdef INCLUDE_SHMEDIA
6399 int seen_stt_datalabel
= 0;
6402 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6403 r_type
= ELF32_R_TYPE (rel
->r_info
);
6405 if (r_symndx
< symtab_hdr
->sh_info
)
6409 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6410 #ifdef INCLUDE_SHMEDIA
6411 while (h
->root
.type
== bfd_link_hash_indirect
6412 || h
->root
.type
== bfd_link_hash_warning
)
6414 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
6415 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6420 r_type
= sh_elf_optimized_tls_reloc (info
, r_type
, h
== NULL
);
6422 && r_type
== R_SH_TLS_IE_32
6424 && h
->root
.type
!= bfd_link_hash_undefined
6425 && h
->root
.type
!= bfd_link_hash_undefweak
6426 && (h
->dynindx
== -1
6427 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
6428 r_type
= R_SH_TLS_LE_32
;
6430 /* Some relocs require a global offset table. */
6431 if (htab
->sgot
== NULL
)
6439 #ifdef INCLUDE_SHMEDIA
6440 case R_SH_GOTPLT_LOW16
:
6441 case R_SH_GOTPLT_MEDLOW16
:
6442 case R_SH_GOTPLT_MEDHI16
:
6443 case R_SH_GOTPLT_HI16
:
6444 case R_SH_GOTPLT10BY4
:
6445 case R_SH_GOTPLT10BY8
:
6446 case R_SH_GOT_LOW16
:
6447 case R_SH_GOT_MEDLOW16
:
6448 case R_SH_GOT_MEDHI16
:
6452 case R_SH_GOTOFF_LOW16
:
6453 case R_SH_GOTOFF_MEDLOW16
:
6454 case R_SH_GOTOFF_MEDHI16
:
6455 case R_SH_GOTOFF_HI16
:
6456 case R_SH_GOTPC_LOW16
:
6457 case R_SH_GOTPC_MEDLOW16
:
6458 case R_SH_GOTPC_MEDHI16
:
6459 case R_SH_GOTPC_HI16
:
6461 case R_SH_TLS_GD_32
:
6462 case R_SH_TLS_LD_32
:
6463 case R_SH_TLS_IE_32
:
6464 if (htab
->sgot
== NULL
)
6466 if (htab
->root
.dynobj
== NULL
)
6467 htab
->root
.dynobj
= abfd
;
6468 if (!create_got_section (htab
->root
.dynobj
, info
))
6480 /* This relocation describes the C++ object vtable hierarchy.
6481 Reconstruct it for later use during GC. */
6482 case R_SH_GNU_VTINHERIT
:
6483 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6487 /* This relocation describes which C++ vtable entries are actually
6488 used. Record for later use during GC. */
6489 case R_SH_GNU_VTENTRY
:
6490 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6494 case R_SH_TLS_IE_32
:
6496 info
->flags
|= DF_STATIC_TLS
;
6500 case R_SH_TLS_GD_32
:
6502 #ifdef INCLUDE_SHMEDIA
6503 case R_SH_GOT_LOW16
:
6504 case R_SH_GOT_MEDLOW16
:
6505 case R_SH_GOT_MEDHI16
:
6513 tls_type
= GOT_NORMAL
;
6515 case R_SH_TLS_GD_32
:
6516 tls_type
= GOT_TLS_GD
;
6518 case R_SH_TLS_IE_32
:
6519 tls_type
= GOT_TLS_IE
;
6525 #ifdef INCLUDE_SHMEDIA
6526 if (seen_stt_datalabel
)
6528 struct elf_sh_link_hash_entry
*eh
6529 = (struct elf_sh_link_hash_entry
*) h
;
6531 eh
->datalabel_got
.refcount
+= 1;
6535 h
->got
.refcount
+= 1;
6536 old_tls_type
= sh_elf_hash_entry (h
)->tls_type
;
6540 bfd_signed_vma
*local_got_refcounts
;
6542 /* This is a global offset table entry for a local
6544 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6545 if (local_got_refcounts
== NULL
)
6549 size
= symtab_hdr
->sh_info
;
6550 size
*= sizeof (bfd_signed_vma
);
6551 #ifdef INCLUDE_SHMEDIA
6552 /* Reserve space for both the datalabel and
6553 codelabel local GOT offsets. */
6556 size
+= symtab_hdr
->sh_info
;
6557 local_got_refcounts
= ((bfd_signed_vma
*)
6558 bfd_zalloc (abfd
, size
));
6559 if (local_got_refcounts
== NULL
)
6561 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
6562 #ifdef INCLUDE_SHMEDIA
6563 /* Take care of both the datalabel and codelabel local
6565 sh_elf_local_got_tls_type (abfd
)
6566 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
6568 sh_elf_local_got_tls_type (abfd
)
6569 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
6572 #ifdef INCLUDE_SHMEDIA
6573 if (rel
->r_addend
& 1)
6574 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] += 1;
6577 local_got_refcounts
[r_symndx
] += 1;
6578 old_tls_type
= sh_elf_local_got_tls_type (abfd
) [r_symndx
];
6581 /* If a TLS symbol is accessed using IE at least once,
6582 there is no point to use dynamic model for it. */
6583 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
6584 && (old_tls_type
!= GOT_TLS_GD
|| tls_type
!= GOT_TLS_IE
))
6586 if (old_tls_type
== GOT_TLS_IE
&& tls_type
== GOT_TLS_GD
)
6587 tls_type
= GOT_TLS_IE
;
6590 (*_bfd_error_handler
)
6591 (_("%s: `%s' accessed both as normal and thread local symbol"),
6592 bfd_archive_filename (abfd
), h
->root
.root
.string
);
6597 if (old_tls_type
!= tls_type
)
6600 sh_elf_hash_entry (h
)->tls_type
= tls_type
;
6602 sh_elf_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
6607 case R_SH_TLS_LD_32
:
6608 sh_elf_hash_table(info
)->tls_ldm_got
.refcount
+= 1;
6612 #ifdef INCLUDE_SHMEDIA
6613 case R_SH_GOTPLT_LOW16
:
6614 case R_SH_GOTPLT_MEDLOW16
:
6615 case R_SH_GOTPLT_MEDHI16
:
6616 case R_SH_GOTPLT_HI16
:
6617 case R_SH_GOTPLT10BY4
:
6618 case R_SH_GOTPLT10BY8
:
6620 /* If this is a local symbol, we resolve it directly without
6621 creating a procedure linkage table entry. */
6624 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
6627 || h
->dynindx
== -1)
6630 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6631 h
->plt
.refcount
+= 1;
6632 ((struct elf_sh_link_hash_entry
*) h
)->gotplt_refcount
+= 1;
6637 #ifdef INCLUDE_SHMEDIA
6638 case R_SH_PLT_LOW16
:
6639 case R_SH_PLT_MEDLOW16
:
6640 case R_SH_PLT_MEDHI16
:
6643 /* This symbol requires a procedure linkage table entry. We
6644 actually build the entry in adjust_dynamic_symbol,
6645 because this might be a case of linking PIC code which is
6646 never referenced by a dynamic object, in which case we
6647 don't need to generate a procedure linkage table entry
6650 /* If this is a local symbol, we resolve it directly without
6651 creating a procedure linkage table entry. */
6655 if (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
6658 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6659 h
->plt
.refcount
+= 1;
6664 #ifdef INCLUDE_SHMEDIA
6665 case R_SH_IMM_LOW16_PCREL
:
6666 case R_SH_IMM_MEDLOW16_PCREL
:
6667 case R_SH_IMM_MEDHI16_PCREL
:
6668 case R_SH_IMM_HI16_PCREL
:
6670 if (h
!= NULL
&& ! info
->shared
)
6672 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
6673 h
->plt
.refcount
+= 1;
6676 /* If we are creating a shared library, and this is a reloc
6677 against a global symbol, or a non PC relative reloc
6678 against a local symbol, then we need to copy the reloc
6679 into the shared library. However, if we are linking with
6680 -Bsymbolic, we do not need to copy a reloc against a
6681 global symbol which is defined in an object we are
6682 including in the link (i.e., DEF_REGULAR is set). At
6683 this point we have not seen all the input files, so it is
6684 possible that DEF_REGULAR is not set now but will be set
6685 later (it is never cleared). We account for that
6686 possibility below by storing information in the
6687 dyn_relocs field of the hash table entry. A similar
6688 situation occurs when creating shared libraries and symbol
6689 visibility changes render the symbol local.
6691 If on the other hand, we are creating an executable, we
6692 may need to keep relocations for symbols satisfied by a
6693 dynamic library if we manage to avoid copy relocs for the
6696 && (sec
->flags
& SEC_ALLOC
) != 0
6697 && (r_type
!= R_SH_REL32
6699 && (! info
->symbolic
6700 || h
->root
.type
== bfd_link_hash_defweak
6701 || (h
->elf_link_hash_flags
6702 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
6704 && (sec
->flags
& SEC_ALLOC
) != 0
6706 && (h
->root
.type
== bfd_link_hash_defweak
6707 || (h
->elf_link_hash_flags
6708 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
6710 struct elf_sh_dyn_relocs
*p
;
6711 struct elf_sh_dyn_relocs
**head
;
6713 if (htab
->root
.dynobj
== NULL
)
6714 htab
->root
.dynobj
= abfd
;
6716 /* When creating a shared object, we must copy these
6717 reloc types into the output file. We create a reloc
6718 section in dynobj and make room for this reloc. */
6723 name
= (bfd_elf_string_from_elf_section
6725 elf_elfheader (abfd
)->e_shstrndx
,
6726 elf_section_data (sec
)->rel_hdr
.sh_name
));
6730 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
6731 && strcmp (bfd_get_section_name (abfd
, sec
),
6734 sreloc
= bfd_get_section_by_name (htab
->root
.dynobj
, name
);
6739 sreloc
= bfd_make_section (htab
->root
.dynobj
, name
);
6740 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
6741 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
6742 if ((sec
->flags
& SEC_ALLOC
) != 0)
6743 flags
|= SEC_ALLOC
| SEC_LOAD
;
6745 || ! bfd_set_section_flags (htab
->root
.dynobj
,
6747 || ! bfd_set_section_alignment (htab
->root
.dynobj
,
6751 elf_section_data (sec
)->sreloc
= sreloc
;
6754 /* If this is a global symbol, we count the number of
6755 relocations we need for this symbol. */
6757 head
= &((struct elf_sh_link_hash_entry
*) h
)->dyn_relocs
;
6762 /* Track dynamic relocs needed for local syms too. */
6763 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
6768 head
= ((struct elf_sh_dyn_relocs
**)
6769 &elf_section_data (s
)->local_dynrel
);
6773 if (p
== NULL
|| p
->sec
!= sec
)
6775 bfd_size_type amt
= sizeof (*p
);
6776 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
6787 if (r_type
== R_SH_REL32
6788 #ifdef INCLUDE_SHMEDIA
6789 || r_type
== R_SH_IMM_LOW16_PCREL
6790 || r_type
== R_SH_IMM_MEDLOW16_PCREL
6791 || r_type
== R_SH_IMM_MEDHI16_PCREL
6792 || r_type
== R_SH_IMM_HI16_PCREL
6800 case R_SH_TLS_LE_32
:
6803 (*_bfd_error_handler
) (_("%s: TLS local exec code cannot be linked into shared objects"),
6804 bfd_archive_filename (abfd
));
6810 case R_SH_TLS_LDO_32
:
6811 /* Nothing to do. */
6822 #ifndef sh_elf_set_mach_from_flags
6823 static unsigned int sh_ef_bfd_table
[] = { EF_SH_BFD_TABLE
};
6826 sh_elf_set_mach_from_flags (bfd
*abfd
)
6828 flagword flags
= elf_elfheader (abfd
)->e_flags
& EF_SH_MACH_MASK
;
6830 if (flags
>= sizeof(sh_ef_bfd_table
))
6833 if (sh_ef_bfd_table
[flags
] == 0)
6836 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, sh_ef_bfd_table
[flags
]);
6842 /* Reverse table lookup for sh_ef_bfd_table[].
6843 Given a bfd MACH value from archures.c
6844 return the equivalent ELF flags from the table.
6845 Return -1 if no match is found. */
6848 sh_elf_get_flags_from_mach (unsigned long mach
)
6850 int i
= ARRAY_SIZE (sh_ef_bfd_table
);
6853 if (sh_ef_bfd_table
[i
] == mach
)
6856 /* shouldn't get here */
6861 #endif /* not sh_elf_set_mach_from_flags */
6863 #ifndef sh_elf_set_private_flags
6864 /* Function to keep SH specific file flags. */
6867 sh_elf_set_private_flags (bfd
*abfd
, flagword flags
)
6869 BFD_ASSERT (! elf_flags_init (abfd
)
6870 || elf_elfheader (abfd
)->e_flags
== flags
);
6872 elf_elfheader (abfd
)->e_flags
= flags
;
6873 elf_flags_init (abfd
) = TRUE
;
6874 return sh_elf_set_mach_from_flags (abfd
);
6876 #endif /* not sh_elf_set_private_flags */
6878 #ifndef sh_elf_copy_private_data
6879 /* Copy backend specific data from one object module to another */
6882 sh_elf_copy_private_data (bfd
* ibfd
, bfd
* obfd
)
6884 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6885 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6888 return sh_elf_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
6890 #endif /* not sh_elf_copy_private_data */
6892 #ifndef sh_elf_merge_private_data
6894 /* This function returns the ELF architecture number that
6895 corresponds to the given arch_sh* flags. */
6897 sh_find_elf_flags (unsigned int arch_set
)
6899 unsigned long bfd_mach
= sh_get_bfd_mach_from_arch_set (arch_set
);
6901 return sh_elf_get_flags_from_mach (bfd_mach
);
6905 /* This routine initialises the elf flags when required and
6906 calls sh_merge_bfd_arch() to check dsp/fpu compatibility. */
6909 sh_elf_merge_private_data (bfd
*ibfd
, bfd
*obfd
)
6911 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6912 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6915 if (! elf_flags_init (obfd
))
6917 /* This happens when ld starts out with a 'blank' output file. */
6918 elf_flags_init (obfd
) = TRUE
;
6919 elf_elfheader (obfd
)->e_flags
= EF_SH1
;
6920 sh_elf_set_mach_from_flags (obfd
);
6923 if ( ! sh_merge_bfd_arch (ibfd
, obfd
) )
6926 elf_elfheader (obfd
)->e_flags
=
6927 sh_elf_get_flags_from_mach (bfd_get_mach (obfd
));
6931 #endif /* not sh_elf_merge_private_data */
6933 /* Override the generic function because we need to store sh_elf_obj_tdata
6934 as the specific tdata. We set also the machine architecture from flags
6938 sh_elf_object_p (bfd
*abfd
)
6940 return sh_elf_set_mach_from_flags (abfd
);
6943 /* Finish up dynamic symbol handling. We set the contents of various
6944 dynamic sections here. */
6947 sh_elf_finish_dynamic_symbol (bfd
*output_bfd
, struct bfd_link_info
*info
,
6948 struct elf_link_hash_entry
*h
,
6949 Elf_Internal_Sym
*sym
)
6951 struct elf_sh_link_hash_table
*htab
;
6953 htab
= sh_elf_hash_table (info
);
6955 if (h
->plt
.offset
!= (bfd_vma
) -1)
6963 Elf_Internal_Rela rel
;
6966 /* This symbol has an entry in the procedure linkage table. Set
6969 BFD_ASSERT (h
->dynindx
!= -1);
6972 sgot
= htab
->sgotplt
;
6973 srel
= htab
->srelplt
;
6974 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
6976 /* Get the index in the procedure linkage table which
6977 corresponds to this symbol. This is the index of this symbol
6978 in all the symbols for which we are making plt entries. The
6979 first entry in the procedure linkage table is reserved. */
6980 plt_index
= h
->plt
.offset
/ elf_sh_sizeof_plt (info
) - 1;
6982 /* Get the offset into the .got table of the entry that
6983 corresponds to this function. Each .got entry is 4 bytes.
6984 The first three are reserved. */
6985 got_offset
= (plt_index
+ 3) * 4;
6989 got_offset
-= GOT_BIAS
;
6992 /* Fill in the entry in the procedure linkage table. */
6995 if (elf_sh_plt_entry
== NULL
)
6997 elf_sh_plt_entry
= (bfd_big_endian (output_bfd
) ?
6998 elf_sh_plt_entry_be
: elf_sh_plt_entry_le
);
7000 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_plt_entry
,
7001 elf_sh_sizeof_plt (info
));
7002 #ifdef INCLUDE_SHMEDIA
7003 movi_shori_putval (output_bfd
,
7004 (sgot
->output_section
->vma
7005 + sgot
->output_offset
7007 (splt
->contents
+ h
->plt
.offset
7008 + elf_sh_plt_symbol_offset (info
)));
7010 /* Set bottom bit because its for a branch to SHmedia */
7011 movi_shori_putval (output_bfd
,
7012 (splt
->output_section
->vma
+ splt
->output_offset
)
7014 (splt
->contents
+ h
->plt
.offset
7015 + elf_sh_plt_plt0_offset (info
)));
7017 bfd_put_32 (output_bfd
,
7018 (sgot
->output_section
->vma
7019 + sgot
->output_offset
7021 (splt
->contents
+ h
->plt
.offset
7022 + elf_sh_plt_symbol_offset (info
)));
7024 bfd_put_32 (output_bfd
,
7025 (splt
->output_section
->vma
+ splt
->output_offset
),
7026 (splt
->contents
+ h
->plt
.offset
7027 + elf_sh_plt_plt0_offset (info
)));
7032 if (elf_sh_pic_plt_entry
== NULL
)
7034 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
7035 elf_sh_pic_plt_entry_be
:
7036 elf_sh_pic_plt_entry_le
);
7038 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_pic_plt_entry
,
7039 elf_sh_sizeof_plt (info
));
7040 #ifdef INCLUDE_SHMEDIA
7041 movi_shori_putval (output_bfd
, got_offset
,
7042 (splt
->contents
+ h
->plt
.offset
7043 + elf_sh_plt_symbol_offset (info
)));
7045 bfd_put_32 (output_bfd
, got_offset
,
7046 (splt
->contents
+ h
->plt
.offset
7047 + elf_sh_plt_symbol_offset (info
)));
7053 got_offset
+= GOT_BIAS
;
7056 #ifdef INCLUDE_SHMEDIA
7057 movi_shori_putval (output_bfd
,
7058 plt_index
* sizeof (Elf32_External_Rela
),
7059 (splt
->contents
+ h
->plt
.offset
7060 + elf_sh_plt_reloc_offset (info
)));
7062 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
7063 (splt
->contents
+ h
->plt
.offset
7064 + elf_sh_plt_reloc_offset (info
)));
7067 /* Fill in the entry in the global offset table. */
7068 bfd_put_32 (output_bfd
,
7069 (splt
->output_section
->vma
7070 + splt
->output_offset
7072 + elf_sh_plt_temp_offset (info
)),
7073 sgot
->contents
+ got_offset
);
7075 /* Fill in the entry in the .rela.plt section. */
7076 rel
.r_offset
= (sgot
->output_section
->vma
7077 + sgot
->output_offset
7079 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_JMP_SLOT
);
7082 rel
.r_addend
= GOT_BIAS
;
7084 loc
= srel
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
7085 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7087 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
7089 /* Mark the symbol as undefined, rather than as defined in
7090 the .plt section. Leave the value alone. */
7091 sym
->st_shndx
= SHN_UNDEF
;
7095 if (h
->got
.offset
!= (bfd_vma
) -1
7096 && sh_elf_hash_entry (h
)->tls_type
!= GOT_TLS_GD
7097 && sh_elf_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
7101 Elf_Internal_Rela rel
;
7104 /* This symbol has an entry in the global offset table. Set it
7108 srel
= htab
->srelgot
;
7109 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
7111 rel
.r_offset
= (sgot
->output_section
->vma
7112 + sgot
->output_offset
7113 + (h
->got
.offset
&~ (bfd_vma
) 1));
7115 /* If this is a static link, or it is a -Bsymbolic link and the
7116 symbol is defined locally or was forced to be local because
7117 of a version file, we just want to emit a RELATIVE reloc.
7118 The entry in the global offset table will already have been
7119 initialized in the relocate_section function. */
7121 && SYMBOL_REFERENCES_LOCAL (info
, h
))
7123 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
7124 rel
.r_addend
= (h
->root
.u
.def
.value
7125 + h
->root
.u
.def
.section
->output_section
->vma
7126 + h
->root
.u
.def
.section
->output_offset
);
7130 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
7131 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
7135 loc
= srel
->contents
;
7136 loc
+= srel
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7137 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7140 #ifdef INCLUDE_SHMEDIA
7142 struct elf_sh_link_hash_entry
*eh
;
7144 eh
= (struct elf_sh_link_hash_entry
*) h
;
7145 if (eh
->datalabel_got
.offset
!= (bfd_vma
) -1)
7149 Elf_Internal_Rela rel
;
7152 /* This symbol has a datalabel entry in the global offset table.
7156 srel
= htab
->srelgot
;
7157 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
7159 rel
.r_offset
= (sgot
->output_section
->vma
7160 + sgot
->output_offset
7161 + (eh
->datalabel_got
.offset
&~ (bfd_vma
) 1));
7163 /* If this is a static link, or it is a -Bsymbolic link and the
7164 symbol is defined locally or was forced to be local because
7165 of a version file, we just want to emit a RELATIVE reloc.
7166 The entry in the global offset table will already have been
7167 initialized in the relocate_section function. */
7169 && SYMBOL_REFERENCES_LOCAL (info
, h
))
7171 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
7172 rel
.r_addend
= (h
->root
.u
.def
.value
7173 + h
->root
.u
.def
.section
->output_section
->vma
7174 + h
->root
.u
.def
.section
->output_offset
);
7178 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
7179 + eh
->datalabel_got
.offset
);
7180 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
7184 loc
= srel
->contents
;
7185 loc
+= srel
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7186 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7191 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
7194 Elf_Internal_Rela rel
;
7197 /* This symbol needs a copy reloc. Set it up. */
7199 BFD_ASSERT (h
->dynindx
!= -1
7200 && (h
->root
.type
== bfd_link_hash_defined
7201 || h
->root
.type
== bfd_link_hash_defweak
));
7203 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
7205 BFD_ASSERT (s
!= NULL
);
7207 rel
.r_offset
= (h
->root
.u
.def
.value
7208 + h
->root
.u
.def
.section
->output_section
->vma
7209 + h
->root
.u
.def
.section
->output_offset
);
7210 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_COPY
);
7212 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7213 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7216 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7217 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
7218 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
7219 sym
->st_shndx
= SHN_ABS
;
7224 /* Finish up the dynamic sections. */
7227 sh_elf_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
7229 struct elf_sh_link_hash_table
*htab
;
7233 htab
= sh_elf_hash_table (info
);
7234 sgot
= htab
->sgotplt
;
7235 sdyn
= bfd_get_section_by_name (htab
->root
.dynobj
, ".dynamic");
7237 if (htab
->root
.dynamic_sections_created
)
7240 Elf32_External_Dyn
*dyncon
, *dynconend
;
7242 BFD_ASSERT (sgot
!= NULL
&& sdyn
!= NULL
);
7244 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7245 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7246 for (; dyncon
< dynconend
; dyncon
++)
7248 Elf_Internal_Dyn dyn
;
7250 #ifdef INCLUDE_SHMEDIA
7254 bfd_elf32_swap_dyn_in (htab
->root
.dynobj
, dyncon
, &dyn
);
7261 #ifdef INCLUDE_SHMEDIA
7263 name
= info
->init_function
;
7267 name
= info
->fini_function
;
7269 if (dyn
.d_un
.d_val
!= 0)
7271 struct elf_link_hash_entry
*h
;
7273 h
= elf_link_hash_lookup (&htab
->root
, name
,
7274 FALSE
, FALSE
, TRUE
);
7275 if (h
!= NULL
&& (h
->other
& STO_SH5_ISA32
))
7277 dyn
.d_un
.d_val
|= 1;
7278 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7285 s
= htab
->sgot
->output_section
;
7289 s
= htab
->srelplt
->output_section
;
7291 BFD_ASSERT (s
!= NULL
);
7292 dyn
.d_un
.d_ptr
= s
->vma
;
7293 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7297 s
= htab
->srelplt
->output_section
;
7298 BFD_ASSERT (s
!= NULL
);
7299 if (s
->_cooked_size
!= 0)
7300 dyn
.d_un
.d_val
= s
->_cooked_size
;
7302 dyn
.d_un
.d_val
= s
->_raw_size
;
7303 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7307 /* My reading of the SVR4 ABI indicates that the
7308 procedure linkage table relocs (DT_JMPREL) should be
7309 included in the overall relocs (DT_RELA). This is
7310 what Solaris does. However, UnixWare can not handle
7311 that case. Therefore, we override the DT_RELASZ entry
7312 here to make it not include the JMPREL relocs. Since
7313 the linker script arranges for .rela.plt to follow all
7314 other relocation sections, we don't have to worry
7315 about changing the DT_RELA entry. */
7316 if (htab
->srelplt
!= NULL
)
7318 s
= htab
->srelplt
->output_section
;
7319 if (s
->_cooked_size
!= 0)
7320 dyn
.d_un
.d_val
-= s
->_cooked_size
;
7322 dyn
.d_un
.d_val
-= s
->_raw_size
;
7324 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7329 /* Fill in the first entry in the procedure linkage table. */
7331 if (splt
&& splt
->_raw_size
> 0)
7335 if (elf_sh_pic_plt_entry
== NULL
)
7337 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
7338 elf_sh_pic_plt_entry_be
:
7339 elf_sh_pic_plt_entry_le
);
7341 memcpy (splt
->contents
, elf_sh_pic_plt_entry
,
7342 elf_sh_sizeof_plt (info
));
7346 if (elf_sh_plt0_entry
== NULL
)
7348 elf_sh_plt0_entry
= (bfd_big_endian (output_bfd
) ?
7349 elf_sh_plt0_entry_be
:
7350 elf_sh_plt0_entry_le
);
7352 memcpy (splt
->contents
, elf_sh_plt0_entry
, PLT_ENTRY_SIZE
);
7353 #ifdef INCLUDE_SHMEDIA
7354 movi_shori_putval (output_bfd
,
7355 sgot
->output_section
->vma
7356 + sgot
->output_offset
,
7358 + elf_sh_plt0_gotplt_offset (info
));
7360 bfd_put_32 (output_bfd
,
7361 sgot
->output_section
->vma
+ sgot
->output_offset
+ 4,
7362 splt
->contents
+ elf_sh_plt0_gotid_offset (info
));
7363 bfd_put_32 (output_bfd
,
7364 sgot
->output_section
->vma
+ sgot
->output_offset
+ 8,
7365 splt
->contents
+ elf_sh_plt0_linker_offset (info
));
7369 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7370 really seem like the right value. */
7371 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
7375 /* Fill in the first three entries in the global offset table. */
7376 if (sgot
&& sgot
->_raw_size
> 0)
7379 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7381 bfd_put_32 (output_bfd
,
7382 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
7384 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
7385 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
7387 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7393 static enum elf_reloc_type_class
7394 sh_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
7396 switch ((int) ELF32_R_TYPE (rela
->r_info
))
7399 return reloc_class_relative
;
7401 return reloc_class_plt
;
7403 return reloc_class_copy
;
7405 return reloc_class_normal
;
7409 /* Support for Linux core dump NOTE sections. */
7411 elf32_shlin_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
7414 unsigned int raw_size
;
7416 switch (note
->descsz
)
7421 case 168: /* Linux/SH */
7423 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
7426 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
7435 /* Make a ".reg/999" section. */
7436 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
7437 raw_size
, note
->descpos
+ offset
);
7441 elf32_shlin_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
7443 switch (note
->descsz
)
7448 case 124: /* Linux/SH elf_prpsinfo */
7449 elf_tdata (abfd
)->core_program
7450 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
7451 elf_tdata (abfd
)->core_command
7452 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
7455 /* Note that for some reason, a spurious space is tacked
7456 onto the end of the args in some (at least one anyway)
7457 implementations, so strip it off if it exists. */
7460 char *command
= elf_tdata (abfd
)->core_command
;
7461 int n
= strlen (command
);
7463 if (0 < n
&& command
[n
- 1] == ' ')
7464 command
[n
- 1] = '\0';
7471 /* Return address for Ith PLT stub in section PLT, for relocation REL
7472 or (bfd_vma) -1 if it should not be included. */
7475 sh_elf_plt_sym_val (bfd_vma i
, const asection
*plt
,
7476 const arelent
*rel ATTRIBUTE_UNUSED
)
7478 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
7481 #define TARGET_BIG_SYM bfd_elf32_sh_vec
7482 #define TARGET_BIG_NAME "elf32-sh"
7483 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
7484 #define TARGET_LITTLE_NAME "elf32-shl"
7485 #define ELF_ARCH bfd_arch_sh
7486 #define ELF_MACHINE_CODE EM_SH
7487 #ifdef __QNXTARGET__
7488 #define ELF_MAXPAGESIZE 0x1000
7490 #define ELF_MAXPAGESIZE 0x80
7493 #define elf_symbol_leading_char '_'
7495 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7496 #define elf_info_to_howto sh_elf_info_to_howto
7497 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
7498 #define elf_backend_relocate_section sh_elf_relocate_section
7499 #define bfd_elf32_bfd_get_relocated_section_contents \
7500 sh_elf_get_relocated_section_contents
7501 #define bfd_elf32_mkobject sh_elf_mkobject
7502 #define elf_backend_object_p sh_elf_object_p
7503 #define bfd_elf32_bfd_set_private_bfd_flags \
7504 sh_elf_set_private_flags
7505 #define bfd_elf32_bfd_copy_private_bfd_data \
7506 sh_elf_copy_private_data
7507 #define bfd_elf32_bfd_merge_private_bfd_data \
7508 sh_elf_merge_private_data
7510 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
7511 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
7512 #define elf_backend_check_relocs sh_elf_check_relocs
7513 #define elf_backend_copy_indirect_symbol \
7514 sh_elf_copy_indirect_symbol
7515 #define elf_backend_create_dynamic_sections \
7516 sh_elf_create_dynamic_sections
7517 #define bfd_elf32_bfd_link_hash_table_create \
7518 sh_elf_link_hash_table_create
7519 #define elf_backend_adjust_dynamic_symbol \
7520 sh_elf_adjust_dynamic_symbol
7521 #define elf_backend_size_dynamic_sections \
7522 sh_elf_size_dynamic_sections
7523 #define elf_backend_finish_dynamic_symbol \
7524 sh_elf_finish_dynamic_symbol
7525 #define elf_backend_finish_dynamic_sections \
7526 sh_elf_finish_dynamic_sections
7527 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
7528 #define elf_backend_plt_sym_val sh_elf_plt_sym_val
7530 #define elf_backend_can_gc_sections 1
7531 #define elf_backend_can_refcount 1
7532 #define elf_backend_want_got_plt 1
7533 #define elf_backend_plt_readonly 1
7534 #define elf_backend_want_plt_sym 0
7535 #define elf_backend_got_header_size 12
7537 #ifndef INCLUDE_SHMEDIA
7539 #include "elf32-target.h"
7541 /* NetBSD support. */
7542 #undef TARGET_BIG_SYM
7543 #define TARGET_BIG_SYM bfd_elf32_shnbsd_vec
7544 #undef TARGET_BIG_NAME
7545 #define TARGET_BIG_NAME "elf32-sh-nbsd"
7546 #undef TARGET_LITTLE_SYM
7547 #define TARGET_LITTLE_SYM bfd_elf32_shlnbsd_vec
7548 #undef TARGET_LITTLE_NAME
7549 #define TARGET_LITTLE_NAME "elf32-shl-nbsd"
7550 #undef ELF_MAXPAGESIZE
7551 #define ELF_MAXPAGESIZE 0x10000
7552 #undef elf_symbol_leading_char
7553 #define elf_symbol_leading_char 0
7555 #define elf32_bed elf32_sh_nbsd_bed
7557 #include "elf32-target.h"
7560 /* Linux support. */
7561 #undef TARGET_BIG_SYM
7562 #define TARGET_BIG_SYM bfd_elf32_shblin_vec
7563 #undef TARGET_BIG_NAME
7564 #define TARGET_BIG_NAME "elf32-shbig-linux"
7565 #undef TARGET_LITTLE_SYM
7566 #define TARGET_LITTLE_SYM bfd_elf32_shlin_vec
7567 #undef TARGET_LITTLE_NAME
7568 #define TARGET_LITTLE_NAME "elf32-sh-linux"
7570 #undef elf_backend_grok_prstatus
7571 #define elf_backend_grok_prstatus elf32_shlin_grok_prstatus
7572 #undef elf_backend_grok_psinfo
7573 #define elf_backend_grok_psinfo elf32_shlin_grok_psinfo
7575 #define elf32_bed elf32_sh_lin_bed
7577 #include "elf32-target.h"
7579 #endif /* INCLUDE_SHMEDIA */