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. */
29 static bfd_reloc_status_type sh_elf_reloc
30 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
31 static bfd_reloc_status_type sh_elf_ignore_reloc
32 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
33 static reloc_howto_type
*sh_elf_reloc_type_lookup
34 (bfd
*, bfd_reloc_code_real_type
);
35 static void sh_elf_info_to_howto
36 (bfd
*, arelent
*, Elf_Internal_Rela
*);
37 static bfd_boolean sh_elf_set_private_flags
39 static bfd_boolean sh_elf_copy_private_data
41 static bfd_boolean sh_elf_merge_private_data
43 static bfd_boolean sh_elf_set_mach_from_flags
45 static bfd_boolean sh_elf_relax_section
46 (bfd
*, asection
*, struct bfd_link_info
*, bfd_boolean
*);
47 static bfd_boolean sh_elf_relax_delete_bytes
48 (bfd
*, asection
*, bfd_vma
, int);
49 static bfd_boolean sh_elf_align_loads
50 (bfd
*, asection
*, Elf_Internal_Rela
*, bfd_byte
*, bfd_boolean
*);
51 static bfd_boolean sh_elf_swap_insns
52 (bfd
*, asection
*, void *, bfd_byte
*, bfd_vma
);
53 static bfd_boolean sh_elf_relocate_section
54 (bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
55 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**);
56 static bfd_byte
*sh_elf_get_relocated_section_contents
57 (bfd
*, struct bfd_link_info
*, struct bfd_link_order
*, bfd_byte
*,
58 bfd_boolean
, asymbol
**);
59 static void sh_elf_copy_indirect_symbol
60 (const struct elf_backend_data
*, struct elf_link_hash_entry
*,
61 struct elf_link_hash_entry
*);
62 static int sh_elf_optimized_tls_reloc
63 (struct bfd_link_info
*, int, int);
64 static bfd_boolean sh_elf_mkobject
66 static bfd_boolean sh_elf_object_p
68 static bfd_boolean sh_elf_check_relocs
69 (bfd
*, struct bfd_link_info
*, asection
*, const Elf_Internal_Rela
*);
70 static struct bfd_hash_entry
*sh_elf_link_hash_newfunc
71 (struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *);
72 static struct bfd_link_hash_table
*sh_elf_link_hash_table_create
74 static bfd_boolean sh_elf_adjust_dynamic_symbol
75 (struct bfd_link_info
*, struct elf_link_hash_entry
*);
76 static bfd_boolean sh_elf_size_dynamic_sections
77 (bfd
*, struct bfd_link_info
*);
78 static bfd_boolean sh_elf_finish_dynamic_symbol
79 (bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
81 static bfd_boolean sh_elf_finish_dynamic_sections
82 (bfd
*, struct bfd_link_info
*);
83 static bfd_reloc_status_type sh_elf_reloc_loop
84 (int, bfd
*, asection
*, bfd_byte
*, bfd_vma
, asection
*, bfd_vma
,
86 static bfd_boolean create_got_section
87 (bfd
*, struct bfd_link_info
*);
88 static bfd_boolean sh_elf_create_dynamic_sections
89 (bfd
*, struct bfd_link_info
*);
90 static bfd_vma dtpoff_base
91 (struct bfd_link_info
*);
93 (struct bfd_link_info
*, bfd_vma
);
94 static asection
* sh_elf_gc_mark_hook
95 (asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
96 struct elf_link_hash_entry
*, Elf_Internal_Sym
*);
97 static bfd_boolean sh_elf_gc_sweep_hook
98 (bfd
*, struct bfd_link_info
*, asection
*, const Elf_Internal_Rela
*);
99 static bfd_boolean allocate_dynrelocs
100 (struct elf_link_hash_entry
*, void *);
101 static bfd_boolean readonly_dynrelocs
102 (struct elf_link_hash_entry
*, void *);
103 static enum elf_reloc_type_class sh_elf_reloc_type_class
104 (const Elf_Internal_Rela
*);
105 #ifdef INCLUDE_SHMEDIA
106 inline static void movi_shori_putval (bfd
*, unsigned long, char *);
108 static bfd_boolean elf32_shlin_grok_prstatus
109 (bfd
*abfd
, Elf_Internal_Note
*note
);
110 static bfd_boolean elf32_shlin_grok_psinfo
111 (bfd
*abfd
, Elf_Internal_Note
*note
);
113 /* The name of the dynamic interpreter. This is put in the .interp
116 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
118 static reloc_howto_type sh_elf_howto_table
[] =
121 HOWTO (R_SH_NONE
, /* type */
123 0, /* size (0 = byte, 1 = short, 2 = long) */
125 FALSE
, /* pc_relative */
127 complain_overflow_dont
, /* complain_on_overflow */
128 sh_elf_ignore_reloc
, /* special_function */
129 "R_SH_NONE", /* name */
130 FALSE
, /* partial_inplace */
133 FALSE
), /* pcrel_offset */
135 /* 32 bit absolute relocation. Setting partial_inplace to TRUE and
136 src_mask to a non-zero value is similar to the COFF toolchain. */
137 HOWTO (R_SH_DIR32
, /* type */
139 2, /* size (0 = byte, 1 = short, 2 = long) */
141 FALSE
, /* pc_relative */
143 complain_overflow_bitfield
, /* complain_on_overflow */
144 sh_elf_reloc
, /* special_function */
145 "R_SH_DIR32", /* name */
146 TRUE
, /* partial_inplace */
147 0xffffffff, /* src_mask */
148 0xffffffff, /* dst_mask */
149 FALSE
), /* pcrel_offset */
151 /* 32 bit PC relative relocation. */
152 HOWTO (R_SH_REL32
, /* type */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
156 TRUE
, /* pc_relative */
158 complain_overflow_signed
, /* complain_on_overflow */
159 sh_elf_ignore_reloc
, /* special_function */
160 "R_SH_REL32", /* name */
161 TRUE
, /* partial_inplace */
162 0xffffffff, /* src_mask */
163 0xffffffff, /* dst_mask */
164 TRUE
), /* pcrel_offset */
166 /* 8 bit PC relative branch divided by 2. */
167 HOWTO (R_SH_DIR8WPN
, /* type */
169 1, /* size (0 = byte, 1 = short, 2 = long) */
171 TRUE
, /* pc_relative */
173 complain_overflow_signed
, /* complain_on_overflow */
174 sh_elf_ignore_reloc
, /* special_function */
175 "R_SH_DIR8WPN", /* name */
176 TRUE
, /* partial_inplace */
179 TRUE
), /* pcrel_offset */
181 /* 12 bit PC relative branch divided by 2. */
182 /* This cannot be partial_inplace because relaxation can't know the
183 eventual value of a symbol. */
184 HOWTO (R_SH_IND12W
, /* type */
186 1, /* size (0 = byte, 1 = short, 2 = long) */
188 TRUE
, /* pc_relative */
190 complain_overflow_signed
, /* complain_on_overflow */
191 NULL
, /* special_function */
192 "R_SH_IND12W", /* name */
193 FALSE
, /* partial_inplace */
195 0xfff, /* dst_mask */
196 TRUE
), /* pcrel_offset */
198 /* 8 bit unsigned PC relative divided by 4. */
199 HOWTO (R_SH_DIR8WPL
, /* type */
201 1, /* size (0 = byte, 1 = short, 2 = long) */
203 TRUE
, /* pc_relative */
205 complain_overflow_unsigned
, /* complain_on_overflow */
206 sh_elf_ignore_reloc
, /* special_function */
207 "R_SH_DIR8WPL", /* name */
208 TRUE
, /* partial_inplace */
211 TRUE
), /* pcrel_offset */
213 /* 8 bit unsigned PC relative divided by 2. */
214 HOWTO (R_SH_DIR8WPZ
, /* type */
216 1, /* size (0 = byte, 1 = short, 2 = long) */
218 TRUE
, /* pc_relative */
220 complain_overflow_unsigned
, /* complain_on_overflow */
221 sh_elf_ignore_reloc
, /* special_function */
222 "R_SH_DIR8WPZ", /* name */
223 TRUE
, /* partial_inplace */
226 TRUE
), /* pcrel_offset */
228 /* 8 bit GBR relative. FIXME: This only makes sense if we have some
229 special symbol for the GBR relative area, and that is not
231 HOWTO (R_SH_DIR8BP
, /* type */
233 1, /* size (0 = byte, 1 = short, 2 = long) */
235 FALSE
, /* pc_relative */
237 complain_overflow_unsigned
, /* complain_on_overflow */
238 sh_elf_ignore_reloc
, /* special_function */
239 "R_SH_DIR8BP", /* name */
240 FALSE
, /* partial_inplace */
243 TRUE
), /* pcrel_offset */
245 /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if
246 we have some special symbol for the GBR relative area, and that
247 is not implemented. */
248 HOWTO (R_SH_DIR8W
, /* type */
250 1, /* size (0 = byte, 1 = short, 2 = long) */
252 FALSE
, /* pc_relative */
254 complain_overflow_unsigned
, /* complain_on_overflow */
255 sh_elf_ignore_reloc
, /* special_function */
256 "R_SH_DIR8W", /* name */
257 FALSE
, /* partial_inplace */
260 TRUE
), /* pcrel_offset */
262 /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if
263 we have some special symbol for the GBR relative area, and that
264 is not implemented. */
265 HOWTO (R_SH_DIR8L
, /* type */
267 1, /* size (0 = byte, 1 = short, 2 = long) */
269 FALSE
, /* pc_relative */
271 complain_overflow_unsigned
, /* complain_on_overflow */
272 sh_elf_ignore_reloc
, /* special_function */
273 "R_SH_DIR8L", /* name */
274 FALSE
, /* partial_inplace */
277 TRUE
), /* pcrel_offset */
279 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
280 HOWTO (R_SH_LOOP_START
, /* type */
282 1, /* size (0 = byte, 1 = short, 2 = long) */
284 FALSE
, /* pc_relative */
286 complain_overflow_signed
, /* complain_on_overflow */
287 sh_elf_ignore_reloc
, /* special_function */
288 "R_SH_LOOP_START", /* name */
289 TRUE
, /* partial_inplace */
292 TRUE
), /* pcrel_offset */
294 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
295 HOWTO (R_SH_LOOP_END
, /* type */
297 1, /* size (0 = byte, 1 = short, 2 = long) */
299 FALSE
, /* pc_relative */
301 complain_overflow_signed
, /* complain_on_overflow */
302 sh_elf_ignore_reloc
, /* special_function */
303 "R_SH_LOOP_END", /* name */
304 TRUE
, /* partial_inplace */
307 TRUE
), /* pcrel_offset */
320 /* The remaining relocs are a GNU extension used for relaxing. The
321 final pass of the linker never needs to do anything with any of
322 these relocs. Any required operations are handled by the
325 /* GNU extension to record C++ vtable hierarchy */
326 HOWTO (R_SH_GNU_VTINHERIT
, /* type */
328 2, /* size (0 = byte, 1 = short, 2 = long) */
330 FALSE
, /* pc_relative */
332 complain_overflow_dont
, /* complain_on_overflow */
333 NULL
, /* special_function */
334 "R_SH_GNU_VTINHERIT", /* name */
335 FALSE
, /* partial_inplace */
338 FALSE
), /* pcrel_offset */
340 /* GNU extension to record C++ vtable member usage */
341 HOWTO (R_SH_GNU_VTENTRY
, /* type */
343 2, /* size (0 = byte, 1 = short, 2 = long) */
345 FALSE
, /* pc_relative */
347 complain_overflow_dont
, /* complain_on_overflow */
348 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
349 "R_SH_GNU_VTENTRY", /* name */
350 FALSE
, /* partial_inplace */
353 FALSE
), /* pcrel_offset */
355 /* An 8 bit switch table entry. This is generated for an expression
356 such as ``.word L1 - L2''. The offset holds the difference
357 between the reloc address and L2. */
358 HOWTO (R_SH_SWITCH8
, /* type */
360 0, /* size (0 = byte, 1 = short, 2 = long) */
362 FALSE
, /* pc_relative */
364 complain_overflow_unsigned
, /* complain_on_overflow */
365 sh_elf_ignore_reloc
, /* special_function */
366 "R_SH_SWITCH8", /* name */
367 FALSE
, /* partial_inplace */
370 TRUE
), /* pcrel_offset */
372 /* A 16 bit switch table entry. This is generated for an expression
373 such as ``.word L1 - L2''. The offset holds the difference
374 between the reloc address and L2. */
375 HOWTO (R_SH_SWITCH16
, /* type */
377 1, /* size (0 = byte, 1 = short, 2 = long) */
379 FALSE
, /* pc_relative */
381 complain_overflow_unsigned
, /* complain_on_overflow */
382 sh_elf_ignore_reloc
, /* special_function */
383 "R_SH_SWITCH16", /* name */
384 FALSE
, /* partial_inplace */
387 TRUE
), /* pcrel_offset */
389 /* A 32 bit switch table entry. This is generated for an expression
390 such as ``.long L1 - L2''. The offset holds the difference
391 between the reloc address and L2. */
392 HOWTO (R_SH_SWITCH32
, /* type */
394 2, /* size (0 = byte, 1 = short, 2 = long) */
396 FALSE
, /* pc_relative */
398 complain_overflow_unsigned
, /* complain_on_overflow */
399 sh_elf_ignore_reloc
, /* special_function */
400 "R_SH_SWITCH32", /* name */
401 FALSE
, /* partial_inplace */
404 TRUE
), /* pcrel_offset */
406 /* Indicates a .uses pseudo-op. The compiler will generate .uses
407 pseudo-ops when it finds a function call which can be relaxed.
408 The offset field holds the PC relative offset to the instruction
409 which loads the register used in the function call. */
410 HOWTO (R_SH_USES
, /* type */
412 1, /* size (0 = byte, 1 = short, 2 = long) */
414 FALSE
, /* pc_relative */
416 complain_overflow_unsigned
, /* complain_on_overflow */
417 sh_elf_ignore_reloc
, /* special_function */
418 "R_SH_USES", /* name */
419 FALSE
, /* partial_inplace */
422 TRUE
), /* pcrel_offset */
424 /* The assembler will generate this reloc for addresses referred to
425 by the register loads associated with USES relocs. The offset
426 field holds the number of times the address is referenced in the
428 HOWTO (R_SH_COUNT
, /* type */
430 1, /* size (0 = byte, 1 = short, 2 = long) */
432 FALSE
, /* pc_relative */
434 complain_overflow_unsigned
, /* complain_on_overflow */
435 sh_elf_ignore_reloc
, /* special_function */
436 "R_SH_COUNT", /* name */
437 FALSE
, /* partial_inplace */
440 TRUE
), /* pcrel_offset */
442 /* Indicates an alignment statement. The offset field is the power
443 of 2 to which subsequent portions of the object file must be
445 HOWTO (R_SH_ALIGN
, /* type */
447 1, /* size (0 = byte, 1 = short, 2 = long) */
449 FALSE
, /* pc_relative */
451 complain_overflow_unsigned
, /* complain_on_overflow */
452 sh_elf_ignore_reloc
, /* special_function */
453 "R_SH_ALIGN", /* name */
454 FALSE
, /* partial_inplace */
457 TRUE
), /* pcrel_offset */
459 /* The assembler will generate this reloc before a block of
460 instructions. A section should be processed as assuming it
461 contains data, unless this reloc is seen. */
462 HOWTO (R_SH_CODE
, /* type */
464 1, /* size (0 = byte, 1 = short, 2 = long) */
466 FALSE
, /* pc_relative */
468 complain_overflow_unsigned
, /* complain_on_overflow */
469 sh_elf_ignore_reloc
, /* special_function */
470 "R_SH_CODE", /* name */
471 FALSE
, /* partial_inplace */
474 TRUE
), /* pcrel_offset */
476 /* The assembler will generate this reloc after a block of
477 instructions when it sees data that is not instructions. */
478 HOWTO (R_SH_DATA
, /* type */
480 1, /* size (0 = byte, 1 = short, 2 = long) */
482 FALSE
, /* pc_relative */
484 complain_overflow_unsigned
, /* complain_on_overflow */
485 sh_elf_ignore_reloc
, /* special_function */
486 "R_SH_DATA", /* name */
487 FALSE
, /* partial_inplace */
490 TRUE
), /* pcrel_offset */
492 /* The assembler generates this reloc for each label within a block
493 of instructions. This permits the linker to avoid swapping
494 instructions which are the targets of branches. */
495 HOWTO (R_SH_LABEL
, /* type */
497 1, /* size (0 = byte, 1 = short, 2 = long) */
499 FALSE
, /* pc_relative */
501 complain_overflow_unsigned
, /* complain_on_overflow */
502 sh_elf_ignore_reloc
, /* special_function */
503 "R_SH_LABEL", /* name */
504 FALSE
, /* partial_inplace */
507 TRUE
), /* pcrel_offset */
509 /* The next 12 are only supported via linking in SHC-generated objects. */
510 HOWTO (R_SH_DIR16
, /* type */
512 1, /* size (0 = byte, 1 = short, 2 = long) */
514 FALSE
, /* pc_relative */
516 complain_overflow_dont
, /* complain_on_overflow */
517 bfd_elf_generic_reloc
, /* special_function */
518 "R_SH_DIR16", /* name */
519 FALSE
, /* partial_inplace */
521 0xffff, /* dst_mask */
522 FALSE
), /* pcrel_offset */
524 HOWTO (R_SH_DIR8
, /* type */
526 0, /* size (0 = byte, 1 = short, 2 = long) */
528 FALSE
, /* pc_relative */
530 complain_overflow_dont
, /* complain_on_overflow */
531 bfd_elf_generic_reloc
, /* special_function */
532 "R_SH_DIR8", /* name */
533 FALSE
, /* partial_inplace */
536 FALSE
), /* pcrel_offset */
538 HOWTO (R_SH_DIR8UL
, /* type */
540 0, /* size (0 = byte, 1 = short, 2 = long) */
542 FALSE
, /* pc_relative */
544 complain_overflow_unsigned
, /* complain_on_overflow */
545 bfd_elf_generic_reloc
, /* special_function */
546 "R_SH_DIR8UL", /* name */
547 FALSE
, /* partial_inplace */
550 FALSE
), /* pcrel_offset */
552 HOWTO (R_SH_DIR8UW
, /* type */
554 0, /* size (0 = byte, 1 = short, 2 = long) */
556 FALSE
, /* pc_relative */
558 complain_overflow_unsigned
, /* complain_on_overflow */
559 bfd_elf_generic_reloc
, /* special_function */
560 "R_SH_DIR8UW", /* name */
561 FALSE
, /* partial_inplace */
564 FALSE
), /* pcrel_offset */
566 HOWTO (R_SH_DIR8U
, /* type */
568 0, /* size (0 = byte, 1 = short, 2 = long) */
570 FALSE
, /* pc_relative */
572 complain_overflow_unsigned
, /* complain_on_overflow */
573 bfd_elf_generic_reloc
, /* special_function */
574 "R_SH_DIR8U", /* name */
575 FALSE
, /* partial_inplace */
578 FALSE
), /* pcrel_offset */
580 HOWTO (R_SH_DIR8SW
, /* type */
582 0, /* size (0 = byte, 1 = short, 2 = long) */
584 FALSE
, /* pc_relative */
586 complain_overflow_signed
, /* complain_on_overflow */
587 bfd_elf_generic_reloc
, /* special_function */
588 "R_SH_DIR8SW", /* name */
589 FALSE
, /* partial_inplace */
592 FALSE
), /* pcrel_offset */
594 HOWTO (R_SH_DIR8S
, /* type */
596 0, /* size (0 = byte, 1 = short, 2 = long) */
598 FALSE
, /* pc_relative */
600 complain_overflow_signed
, /* complain_on_overflow */
601 bfd_elf_generic_reloc
, /* special_function */
602 "R_SH_DIR8S", /* name */
603 FALSE
, /* partial_inplace */
606 FALSE
), /* pcrel_offset */
608 HOWTO (R_SH_DIR4UL
, /* type */
610 0, /* size (0 = byte, 1 = short, 2 = long) */
612 FALSE
, /* pc_relative */
614 complain_overflow_unsigned
, /* complain_on_overflow */
615 bfd_elf_generic_reloc
, /* special_function */
616 "R_SH_DIR4UL", /* name */
617 FALSE
, /* partial_inplace */
620 FALSE
), /* pcrel_offset */
622 HOWTO (R_SH_DIR4UW
, /* type */
624 0, /* size (0 = byte, 1 = short, 2 = long) */
626 FALSE
, /* pc_relative */
628 complain_overflow_unsigned
, /* complain_on_overflow */
629 bfd_elf_generic_reloc
, /* special_function */
630 "R_SH_DIR4UW", /* name */
631 FALSE
, /* partial_inplace */
634 FALSE
), /* pcrel_offset */
636 HOWTO (R_SH_DIR4U
, /* type */
638 0, /* size (0 = byte, 1 = short, 2 = long) */
640 FALSE
, /* pc_relative */
642 complain_overflow_unsigned
, /* complain_on_overflow */
643 bfd_elf_generic_reloc
, /* special_function */
644 "R_SH_DIR4U", /* name */
645 FALSE
, /* partial_inplace */
648 FALSE
), /* pcrel_offset */
650 HOWTO (R_SH_PSHA
, /* type */
652 1, /* size (0 = byte, 1 = short, 2 = long) */
654 FALSE
, /* pc_relative */
656 complain_overflow_signed
, /* complain_on_overflow */
657 bfd_elf_generic_reloc
, /* special_function */
658 "R_SH_PSHA", /* name */
659 FALSE
, /* partial_inplace */
662 FALSE
), /* pcrel_offset */
664 HOWTO (R_SH_PSHL
, /* type */
666 1, /* size (0 = byte, 1 = short, 2 = long) */
668 FALSE
, /* pc_relative */
670 complain_overflow_signed
, /* complain_on_overflow */
671 bfd_elf_generic_reloc
, /* special_function */
672 "R_SH_PSHL", /* name */
673 FALSE
, /* partial_inplace */
676 FALSE
), /* pcrel_offset */
678 #ifdef INCLUDE_SHMEDIA
679 /* Used in SHLLI.L and SHLRI.L. */
680 HOWTO (R_SH_DIR5U
, /* type */
682 2, /* size (0 = byte, 1 = short, 2 = long) */
684 FALSE
, /* pc_relative */
686 complain_overflow_unsigned
, /* complain_on_overflow */
687 bfd_elf_generic_reloc
, /* special_function */
688 "R_SH_DIR5U", /* name */
689 FALSE
, /* partial_inplace */
691 0xfc00, /* dst_mask */
692 FALSE
), /* pcrel_offset */
694 /* Used in SHARI, SHLLI et al. */
695 HOWTO (R_SH_DIR6U
, /* type */
697 2, /* size (0 = byte, 1 = short, 2 = long) */
699 FALSE
, /* pc_relative */
701 complain_overflow_unsigned
, /* complain_on_overflow */
702 bfd_elf_generic_reloc
, /* special_function */
703 "R_SH_DIR6U", /* name */
704 FALSE
, /* partial_inplace */
706 0xfc00, /* dst_mask */
707 FALSE
), /* pcrel_offset */
709 /* Used in BxxI, LDHI.L et al. */
710 HOWTO (R_SH_DIR6S
, /* type */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
714 FALSE
, /* pc_relative */
716 complain_overflow_signed
, /* complain_on_overflow */
717 bfd_elf_generic_reloc
, /* special_function */
718 "R_SH_DIR6S", /* name */
719 FALSE
, /* partial_inplace */
721 0xfc00, /* dst_mask */
722 FALSE
), /* pcrel_offset */
724 /* Used in ADDI, ANDI et al. */
725 HOWTO (R_SH_DIR10S
, /* type */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
729 FALSE
, /* pc_relative */
731 complain_overflow_signed
, /* complain_on_overflow */
732 bfd_elf_generic_reloc
, /* special_function */
733 "R_SH_DIR10S", /* name */
734 FALSE
, /* partial_inplace */
736 0xffc00, /* dst_mask */
737 FALSE
), /* pcrel_offset */
739 /* Used in LD.UW, ST.W et al. */
740 HOWTO (R_SH_DIR10SW
, /* type */
742 2, /* size (0 = byte, 1 = short, 2 = long) */
744 FALSE
, /* pc_relative */
746 complain_overflow_signed
, /* complain_on_overflow */
747 bfd_elf_generic_reloc
, /* special_function */
748 "R_SH_DIR10SW", /* name */
749 FALSE
, /* partial_inplace */
751 0xffc00, /* dst_mask */
752 FALSE
), /* pcrel_offset */
754 /* Used in LD.L, FLD.S et al. */
755 HOWTO (R_SH_DIR10SL
, /* type */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
759 FALSE
, /* pc_relative */
761 complain_overflow_signed
, /* complain_on_overflow */
762 bfd_elf_generic_reloc
, /* special_function */
763 "R_SH_DIR10SL", /* name */
764 FALSE
, /* partial_inplace */
766 0xffc00, /* dst_mask */
767 FALSE
), /* pcrel_offset */
769 /* Used in FLD.D, FST.P et al. */
770 HOWTO (R_SH_DIR10SQ
, /* type */
772 2, /* size (0 = byte, 1 = short, 2 = long) */
774 FALSE
, /* pc_relative */
776 complain_overflow_signed
, /* complain_on_overflow */
777 bfd_elf_generic_reloc
, /* special_function */
778 "R_SH_DIR10SQ", /* name */
779 FALSE
, /* partial_inplace */
781 0xffc00, /* dst_mask */
782 FALSE
), /* pcrel_offset */
796 HOWTO (R_SH_DIR16S
, /* type */
798 1, /* size (0 = byte, 1 = short, 2 = long) */
800 FALSE
, /* pc_relative */
802 complain_overflow_signed
, /* complain_on_overflow */
803 bfd_elf_generic_reloc
, /* special_function */
804 "R_SH_DIR16S", /* name */
805 FALSE
, /* partial_inplace */
807 0xffff, /* dst_mask */
808 FALSE
), /* pcrel_offset */
901 HOWTO (R_SH_TLS_GD_32
, /* type */
903 2, /* size (0 = byte, 1 = short, 2 = long) */
905 FALSE
, /* pc_relative */
907 complain_overflow_bitfield
, /* complain_on_overflow */
908 bfd_elf_generic_reloc
, /* */
909 "R_SH_TLS_GD_32", /* name */
910 TRUE
, /* partial_inplace */
911 0xffffffff, /* src_mask */
912 0xffffffff, /* dst_mask */
913 FALSE
), /* pcrel_offset */
915 HOWTO (R_SH_TLS_LD_32
, /* type */
917 2, /* size (0 = byte, 1 = short, 2 = long) */
919 FALSE
, /* pc_relative */
921 complain_overflow_bitfield
, /* complain_on_overflow */
922 bfd_elf_generic_reloc
, /* */
923 "R_SH_TLS_LD_32", /* name */
924 TRUE
, /* partial_inplace */
925 0xffffffff, /* src_mask */
926 0xffffffff, /* dst_mask */
927 FALSE
), /* pcrel_offset */
929 HOWTO (R_SH_TLS_LDO_32
, /* type */
931 2, /* size (0 = byte, 1 = short, 2 = long) */
933 FALSE
, /* pc_relative */
935 complain_overflow_bitfield
, /* complain_on_overflow */
936 bfd_elf_generic_reloc
, /* */
937 "R_SH_TLS_LDO_32", /* name */
938 TRUE
, /* partial_inplace */
939 0xffffffff, /* src_mask */
940 0xffffffff, /* dst_mask */
941 FALSE
), /* pcrel_offset */
943 HOWTO (R_SH_TLS_IE_32
, /* type */
945 2, /* size (0 = byte, 1 = short, 2 = long) */
947 FALSE
, /* pc_relative */
949 complain_overflow_bitfield
, /* complain_on_overflow */
950 bfd_elf_generic_reloc
, /* */
951 "R_SH_TLS_IE_32", /* name */
952 TRUE
, /* partial_inplace */
953 0xffffffff, /* src_mask */
954 0xffffffff, /* dst_mask */
955 FALSE
), /* pcrel_offset */
957 HOWTO (R_SH_TLS_LE_32
, /* type */
959 2, /* size (0 = byte, 1 = short, 2 = long) */
961 FALSE
, /* pc_relative */
963 complain_overflow_bitfield
, /* complain_on_overflow */
964 bfd_elf_generic_reloc
, /* */
965 "R_SH_TLS_LE_32", /* name */
966 TRUE
, /* partial_inplace */
967 0xffffffff, /* src_mask */
968 0xffffffff, /* dst_mask */
969 FALSE
), /* pcrel_offset */
971 HOWTO (R_SH_TLS_DTPMOD32
, /* type */
973 2, /* size (0 = byte, 1 = short, 2 = long) */
975 FALSE
, /* pc_relative */
977 complain_overflow_bitfield
, /* complain_on_overflow */
978 bfd_elf_generic_reloc
, /* */
979 "R_SH_TLS_DTPMOD32", /* name */
980 TRUE
, /* partial_inplace */
981 0xffffffff, /* src_mask */
982 0xffffffff, /* dst_mask */
983 FALSE
), /* pcrel_offset */
985 HOWTO (R_SH_TLS_DTPOFF32
, /* type */
987 2, /* size (0 = byte, 1 = short, 2 = long) */
989 FALSE
, /* pc_relative */
991 complain_overflow_bitfield
, /* complain_on_overflow */
992 bfd_elf_generic_reloc
, /* */
993 "R_SH_TLS_DTPOFF32", /* name */
994 TRUE
, /* partial_inplace */
995 0xffffffff, /* src_mask */
996 0xffffffff, /* dst_mask */
997 FALSE
), /* pcrel_offset */
999 HOWTO (R_SH_TLS_TPOFF32
, /* type */
1001 2, /* size (0 = byte, 1 = short, 2 = long) */
1003 FALSE
, /* pc_relative */
1005 complain_overflow_bitfield
, /* complain_on_overflow */
1006 bfd_elf_generic_reloc
, /* */
1007 "R_SH_TLS_TPOFF32", /* name */
1008 TRUE
, /* partial_inplace */
1009 0xffffffff, /* src_mask */
1010 0xffffffff, /* dst_mask */
1011 FALSE
), /* pcrel_offset */
1022 HOWTO (R_SH_GOT32
, /* type */
1024 2, /* size (0 = byte, 1 = short, 2 = long) */
1026 FALSE
, /* pc_relative */
1028 complain_overflow_bitfield
, /* complain_on_overflow */
1029 bfd_elf_generic_reloc
, /* */
1030 "R_SH_GOT32", /* name */
1031 TRUE
, /* partial_inplace */
1032 0xffffffff, /* src_mask */
1033 0xffffffff, /* dst_mask */
1034 FALSE
), /* pcrel_offset */
1036 HOWTO (R_SH_PLT32
, /* type */
1038 2, /* size (0 = byte, 1 = short, 2 = long) */
1040 TRUE
, /* pc_relative */
1042 complain_overflow_bitfield
, /* complain_on_overflow */
1043 bfd_elf_generic_reloc
, /* */
1044 "R_SH_PLT32", /* name */
1045 TRUE
, /* partial_inplace */
1046 0xffffffff, /* src_mask */
1047 0xffffffff, /* dst_mask */
1048 TRUE
), /* pcrel_offset */
1050 HOWTO (R_SH_COPY
, /* type */
1052 2, /* size (0 = byte, 1 = short, 2 = long) */
1054 FALSE
, /* pc_relative */
1056 complain_overflow_bitfield
, /* complain_on_overflow */
1057 bfd_elf_generic_reloc
, /* */
1058 "R_SH_COPY", /* name */
1059 TRUE
, /* partial_inplace */
1060 0xffffffff, /* src_mask */
1061 0xffffffff, /* dst_mask */
1062 FALSE
), /* pcrel_offset */
1064 HOWTO (R_SH_GLOB_DAT
, /* type */
1066 2, /* size (0 = byte, 1 = short, 2 = long) */
1068 FALSE
, /* pc_relative */
1070 complain_overflow_bitfield
, /* complain_on_overflow */
1071 bfd_elf_generic_reloc
, /* */
1072 "R_SH_GLOB_DAT", /* name */
1073 TRUE
, /* partial_inplace */
1074 0xffffffff, /* src_mask */
1075 0xffffffff, /* dst_mask */
1076 FALSE
), /* pcrel_offset */
1078 HOWTO (R_SH_JMP_SLOT
, /* type */
1080 2, /* size (0 = byte, 1 = short, 2 = long) */
1082 FALSE
, /* pc_relative */
1084 complain_overflow_bitfield
, /* complain_on_overflow */
1085 bfd_elf_generic_reloc
, /* */
1086 "R_SH_JMP_SLOT", /* name */
1087 TRUE
, /* partial_inplace */
1088 0xffffffff, /* src_mask */
1089 0xffffffff, /* dst_mask */
1090 FALSE
), /* pcrel_offset */
1092 HOWTO (R_SH_RELATIVE
, /* type */
1094 2, /* size (0 = byte, 1 = short, 2 = long) */
1096 FALSE
, /* pc_relative */
1098 complain_overflow_bitfield
, /* complain_on_overflow */
1099 bfd_elf_generic_reloc
, /* */
1100 "R_SH_RELATIVE", /* name */
1101 TRUE
, /* partial_inplace */
1102 0xffffffff, /* src_mask */
1103 0xffffffff, /* dst_mask */
1104 FALSE
), /* pcrel_offset */
1106 HOWTO (R_SH_GOTOFF
, /* type */
1108 2, /* size (0 = byte, 1 = short, 2 = long) */
1110 FALSE
, /* pc_relative */
1112 complain_overflow_bitfield
, /* complain_on_overflow */
1113 bfd_elf_generic_reloc
, /* */
1114 "R_SH_GOTOFF", /* name */
1115 TRUE
, /* partial_inplace */
1116 0xffffffff, /* src_mask */
1117 0xffffffff, /* dst_mask */
1118 FALSE
), /* pcrel_offset */
1120 HOWTO (R_SH_GOTPC
, /* type */
1122 2, /* size (0 = byte, 1 = short, 2 = long) */
1124 TRUE
, /* pc_relative */
1126 complain_overflow_bitfield
, /* complain_on_overflow */
1127 bfd_elf_generic_reloc
, /* */
1128 "R_SH_GOTPC", /* name */
1129 TRUE
, /* partial_inplace */
1130 0xffffffff, /* src_mask */
1131 0xffffffff, /* dst_mask */
1132 TRUE
), /* pcrel_offset */
1134 HOWTO (R_SH_GOTPLT32
, /* type */
1136 2, /* size (0 = byte, 1 = short, 2 = long) */
1138 FALSE
, /* pc_relative */
1140 complain_overflow_bitfield
, /* complain_on_overflow */
1141 bfd_elf_generic_reloc
, /* */
1142 "R_SH_GOTPLT32", /* name */
1143 FALSE
, /* partial_inplace */
1144 0xffffffff, /* src_mask */
1145 0xffffffff, /* dst_mask */
1146 FALSE
), /* pcrel_offset */
1148 #ifdef INCLUDE_SHMEDIA
1149 /* Used in MOVI and SHORI (x & 65536). */
1150 HOWTO (R_SH_GOT_LOW16
, /* type */
1152 2, /* size (0 = byte, 1 = short, 2 = long) */
1154 FALSE
, /* pc_relative */
1156 complain_overflow_dont
, /* complain_on_overflow */
1157 bfd_elf_generic_reloc
, /* special_function */
1158 "R_SH_GOT_LOW16", /* name */
1159 FALSE
, /* partial_inplace */
1161 0x3fffc00, /* dst_mask */
1162 FALSE
), /* pcrel_offset */
1164 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1165 HOWTO (R_SH_GOT_MEDLOW16
, /* type */
1166 16, /* rightshift */
1167 2, /* size (0 = byte, 1 = short, 2 = long) */
1169 FALSE
, /* pc_relative */
1171 complain_overflow_dont
, /* complain_on_overflow */
1172 bfd_elf_generic_reloc
, /* special_function */
1173 "R_SH_GOT_MEDLOW16", /* name */
1174 FALSE
, /* partial_inplace */
1176 0x3fffc00, /* dst_mask */
1177 FALSE
), /* pcrel_offset */
1179 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1180 HOWTO (R_SH_GOT_MEDHI16
, /* type */
1181 32, /* rightshift */
1182 2, /* size (0 = byte, 1 = short, 2 = long) */
1184 FALSE
, /* pc_relative */
1186 complain_overflow_dont
, /* complain_on_overflow */
1187 bfd_elf_generic_reloc
, /* special_function */
1188 "R_SH_GOT_MEDHI16", /* name */
1189 FALSE
, /* partial_inplace */
1191 0x3fffc00, /* dst_mask */
1192 FALSE
), /* pcrel_offset */
1194 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1195 HOWTO (R_SH_GOT_HI16
, /* type */
1196 48, /* rightshift */
1197 2, /* size (0 = byte, 1 = short, 2 = long) */
1199 FALSE
, /* pc_relative */
1201 complain_overflow_dont
, /* complain_on_overflow */
1202 bfd_elf_generic_reloc
, /* special_function */
1203 "R_SH_GOT_HI16", /* name */
1204 FALSE
, /* partial_inplace */
1206 0x3fffc00, /* dst_mask */
1207 FALSE
), /* pcrel_offset */
1209 /* Used in MOVI and SHORI (x & 65536). */
1210 HOWTO (R_SH_GOTPLT_LOW16
, /* type */
1212 2, /* size (0 = byte, 1 = short, 2 = long) */
1214 FALSE
, /* pc_relative */
1216 complain_overflow_dont
, /* complain_on_overflow */
1217 bfd_elf_generic_reloc
, /* special_function */
1218 "R_SH_GOTPLT_LOW16", /* name */
1219 FALSE
, /* partial_inplace */
1221 0x3fffc00, /* dst_mask */
1222 FALSE
), /* pcrel_offset */
1224 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1225 HOWTO (R_SH_GOTPLT_MEDLOW16
, /* type */
1226 16, /* rightshift */
1227 2, /* size (0 = byte, 1 = short, 2 = long) */
1229 FALSE
, /* pc_relative */
1231 complain_overflow_dont
, /* complain_on_overflow */
1232 bfd_elf_generic_reloc
, /* special_function */
1233 "R_SH_GOTPLT_MEDLOW16", /* name */
1234 FALSE
, /* partial_inplace */
1236 0x3fffc00, /* dst_mask */
1237 FALSE
), /* pcrel_offset */
1239 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1240 HOWTO (R_SH_GOTPLT_MEDHI16
, /* type */
1241 32, /* rightshift */
1242 2, /* size (0 = byte, 1 = short, 2 = long) */
1244 FALSE
, /* pc_relative */
1246 complain_overflow_dont
, /* complain_on_overflow */
1247 bfd_elf_generic_reloc
, /* special_function */
1248 "R_SH_GOTPLT_MEDHI16", /* name */
1249 FALSE
, /* partial_inplace */
1251 0x3fffc00, /* dst_mask */
1252 FALSE
), /* pcrel_offset */
1254 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1255 HOWTO (R_SH_GOTPLT_HI16
, /* type */
1256 48, /* rightshift */
1257 2, /* size (0 = byte, 1 = short, 2 = long) */
1259 FALSE
, /* pc_relative */
1261 complain_overflow_dont
, /* complain_on_overflow */
1262 bfd_elf_generic_reloc
, /* special_function */
1263 "R_SH_GOTPLT_HI16", /* name */
1264 FALSE
, /* partial_inplace */
1266 0x3fffc00, /* dst_mask */
1267 FALSE
), /* pcrel_offset */
1269 /* Used in MOVI and SHORI (x & 65536). */
1270 HOWTO (R_SH_PLT_LOW16
, /* type */
1272 2, /* size (0 = byte, 1 = short, 2 = long) */
1274 TRUE
, /* pc_relative */
1276 complain_overflow_dont
, /* complain_on_overflow */
1277 bfd_elf_generic_reloc
, /* special_function */
1278 "R_SH_PLT_LOW16", /* name */
1279 FALSE
, /* partial_inplace */
1281 0x3fffc00, /* dst_mask */
1282 TRUE
), /* pcrel_offset */
1284 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1285 HOWTO (R_SH_PLT_MEDLOW16
, /* type */
1286 16, /* rightshift */
1287 2, /* size (0 = byte, 1 = short, 2 = long) */
1289 TRUE
, /* pc_relative */
1291 complain_overflow_dont
, /* complain_on_overflow */
1292 bfd_elf_generic_reloc
, /* special_function */
1293 "R_SH_PLT_MEDLOW16", /* name */
1294 FALSE
, /* partial_inplace */
1296 0x3fffc00, /* dst_mask */
1297 TRUE
), /* pcrel_offset */
1299 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1300 HOWTO (R_SH_PLT_MEDHI16
, /* type */
1301 32, /* rightshift */
1302 2, /* size (0 = byte, 1 = short, 2 = long) */
1304 TRUE
, /* pc_relative */
1306 complain_overflow_dont
, /* complain_on_overflow */
1307 bfd_elf_generic_reloc
, /* special_function */
1308 "R_SH_PLT_MEDHI16", /* name */
1309 FALSE
, /* partial_inplace */
1311 0x3fffc00, /* dst_mask */
1312 TRUE
), /* pcrel_offset */
1314 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1315 HOWTO (R_SH_PLT_HI16
, /* type */
1316 48, /* rightshift */
1317 2, /* size (0 = byte, 1 = short, 2 = long) */
1319 TRUE
, /* pc_relative */
1321 complain_overflow_dont
, /* complain_on_overflow */
1322 bfd_elf_generic_reloc
, /* special_function */
1323 "R_SH_PLT_HI16", /* name */
1324 FALSE
, /* partial_inplace */
1326 0x3fffc00, /* dst_mask */
1327 TRUE
), /* pcrel_offset */
1329 /* Used in MOVI and SHORI (x & 65536). */
1330 HOWTO (R_SH_GOTOFF_LOW16
, /* type */
1332 2, /* size (0 = byte, 1 = short, 2 = long) */
1334 FALSE
, /* pc_relative */
1336 complain_overflow_dont
, /* complain_on_overflow */
1337 bfd_elf_generic_reloc
, /* special_function */
1338 "R_SH_GOTOFF_LOW16", /* name */
1339 FALSE
, /* partial_inplace */
1341 0x3fffc00, /* dst_mask */
1342 FALSE
), /* pcrel_offset */
1344 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1345 HOWTO (R_SH_GOTOFF_MEDLOW16
, /* type */
1346 16, /* rightshift */
1347 2, /* size (0 = byte, 1 = short, 2 = long) */
1349 FALSE
, /* pc_relative */
1351 complain_overflow_dont
, /* complain_on_overflow */
1352 bfd_elf_generic_reloc
, /* special_function */
1353 "R_SH_GOTOFF_MEDLOW16", /* name */
1354 FALSE
, /* partial_inplace */
1356 0x3fffc00, /* dst_mask */
1357 FALSE
), /* pcrel_offset */
1359 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1360 HOWTO (R_SH_GOTOFF_MEDHI16
, /* type */
1361 32, /* rightshift */
1362 2, /* size (0 = byte, 1 = short, 2 = long) */
1364 FALSE
, /* pc_relative */
1366 complain_overflow_dont
, /* complain_on_overflow */
1367 bfd_elf_generic_reloc
, /* special_function */
1368 "R_SH_GOTOFF_MEDHI16", /* name */
1369 FALSE
, /* partial_inplace */
1371 0x3fffc00, /* dst_mask */
1372 FALSE
), /* pcrel_offset */
1374 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1375 HOWTO (R_SH_GOTOFF_HI16
, /* type */
1376 48, /* rightshift */
1377 2, /* size (0 = byte, 1 = short, 2 = long) */
1379 FALSE
, /* pc_relative */
1381 complain_overflow_dont
, /* complain_on_overflow */
1382 bfd_elf_generic_reloc
, /* special_function */
1383 "R_SH_GOTOFF_HI16", /* name */
1384 FALSE
, /* partial_inplace */
1386 0x3fffc00, /* dst_mask */
1387 FALSE
), /* pcrel_offset */
1389 /* Used in MOVI and SHORI (x & 65536). */
1390 HOWTO (R_SH_GOTPC_LOW16
, /* type */
1392 2, /* size (0 = byte, 1 = short, 2 = long) */
1394 TRUE
, /* pc_relative */
1396 complain_overflow_dont
, /* complain_on_overflow */
1397 bfd_elf_generic_reloc
, /* special_function */
1398 "R_SH_GOTPC_LOW16", /* name */
1399 FALSE
, /* partial_inplace */
1401 0x3fffc00, /* dst_mask */
1402 TRUE
), /* pcrel_offset */
1404 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1405 HOWTO (R_SH_GOTPC_MEDLOW16
, /* type */
1406 16, /* rightshift */
1407 2, /* size (0 = byte, 1 = short, 2 = long) */
1409 TRUE
, /* pc_relative */
1411 complain_overflow_dont
, /* complain_on_overflow */
1412 bfd_elf_generic_reloc
, /* special_function */
1413 "R_SH_GOTPC_MEDLOW16", /* name */
1414 FALSE
, /* partial_inplace */
1416 0x3fffc00, /* dst_mask */
1417 TRUE
), /* pcrel_offset */
1419 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1420 HOWTO (R_SH_GOTPC_MEDHI16
, /* type */
1421 32, /* rightshift */
1422 2, /* size (0 = byte, 1 = short, 2 = long) */
1424 TRUE
, /* pc_relative */
1426 complain_overflow_dont
, /* complain_on_overflow */
1427 bfd_elf_generic_reloc
, /* special_function */
1428 "R_SH_GOTPC_MEDHI16", /* name */
1429 FALSE
, /* partial_inplace */
1431 0x3fffc00, /* dst_mask */
1432 TRUE
), /* pcrel_offset */
1434 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1435 HOWTO (R_SH_GOTPC_HI16
, /* type */
1436 48, /* rightshift */
1437 2, /* size (0 = byte, 1 = short, 2 = long) */
1439 TRUE
, /* pc_relative */
1441 complain_overflow_dont
, /* complain_on_overflow */
1442 bfd_elf_generic_reloc
, /* special_function */
1443 "R_SH_GOTPC_HI16", /* name */
1444 FALSE
, /* partial_inplace */
1446 0x3fffc00, /* dst_mask */
1447 TRUE
), /* pcrel_offset */
1449 /* Used in LD.L, FLD.S et al. */
1450 HOWTO (R_SH_GOT10BY4
, /* type */
1452 2, /* size (0 = byte, 1 = short, 2 = long) */
1454 FALSE
, /* pc_relative */
1456 complain_overflow_signed
, /* complain_on_overflow */
1457 bfd_elf_generic_reloc
, /* special_function */
1458 "R_SH_GOT10BY4", /* name */
1459 FALSE
, /* partial_inplace */
1461 0xffc00, /* dst_mask */
1462 FALSE
), /* pcrel_offset */
1464 /* Used in LD.L, FLD.S et al. */
1465 HOWTO (R_SH_GOTPLT10BY4
, /* type */
1467 2, /* size (0 = byte, 1 = short, 2 = long) */
1469 FALSE
, /* pc_relative */
1471 complain_overflow_signed
, /* complain_on_overflow */
1472 bfd_elf_generic_reloc
, /* special_function */
1473 "R_SH_GOTPLT10BY4", /* name */
1474 FALSE
, /* partial_inplace */
1476 0xffc00, /* dst_mask */
1477 FALSE
), /* pcrel_offset */
1479 /* Used in FLD.D, FST.P et al. */
1480 HOWTO (R_SH_GOT10BY8
, /* type */
1482 2, /* size (0 = byte, 1 = short, 2 = long) */
1484 FALSE
, /* pc_relative */
1486 complain_overflow_signed
, /* complain_on_overflow */
1487 bfd_elf_generic_reloc
, /* special_function */
1488 "R_SH_GOT10BY8", /* name */
1489 FALSE
, /* partial_inplace */
1491 0xffc00, /* dst_mask */
1492 FALSE
), /* pcrel_offset */
1494 /* Used in FLD.D, FST.P et al. */
1495 HOWTO (R_SH_GOTPLT10BY8
, /* type */
1497 2, /* size (0 = byte, 1 = short, 2 = long) */
1499 FALSE
, /* pc_relative */
1501 complain_overflow_signed
, /* complain_on_overflow */
1502 bfd_elf_generic_reloc
, /* special_function */
1503 "R_SH_GOTPLT10BY8", /* name */
1504 FALSE
, /* partial_inplace */
1506 0xffc00, /* dst_mask */
1507 FALSE
), /* pcrel_offset */
1509 HOWTO (R_SH_COPY64
, /* type */
1511 4, /* size (0 = byte, 1 = short, 2 = long) */
1513 FALSE
, /* pc_relative */
1515 complain_overflow_dont
, /* complain_on_overflow */
1516 bfd_elf_generic_reloc
, /* special_function */
1517 "R_SH_COPY64", /* name */
1518 FALSE
, /* partial_inplace */
1520 ((bfd_vma
) 0) - 1, /* dst_mask */
1521 FALSE
), /* pcrel_offset */
1523 HOWTO (R_SH_GLOB_DAT64
, /* type */
1525 4, /* size (0 = byte, 1 = short, 2 = long) */
1527 FALSE
, /* pc_relative */
1529 complain_overflow_dont
, /* complain_on_overflow */
1530 bfd_elf_generic_reloc
, /* special_function */
1531 "R_SH_GLOB_DAT64", /* name */
1532 FALSE
, /* partial_inplace */
1534 ((bfd_vma
) 0) - 1, /* dst_mask */
1535 FALSE
), /* pcrel_offset */
1537 HOWTO (R_SH_JMP_SLOT64
, /* type */
1539 4, /* size (0 = byte, 1 = short, 2 = long) */
1541 FALSE
, /* pc_relative */
1543 complain_overflow_dont
, /* complain_on_overflow */
1544 bfd_elf_generic_reloc
, /* special_function */
1545 "R_SH_JMP_SLOT64", /* name */
1546 FALSE
, /* partial_inplace */
1548 ((bfd_vma
) 0) - 1, /* dst_mask */
1549 FALSE
), /* pcrel_offset */
1551 HOWTO (R_SH_RELATIVE64
, /* type */
1553 4, /* size (0 = byte, 1 = short, 2 = long) */
1555 FALSE
, /* pc_relative */
1557 complain_overflow_dont
, /* complain_on_overflow */
1558 bfd_elf_generic_reloc
, /* special_function */
1559 "R_SH_RELATIVE64", /* name */
1560 FALSE
, /* partial_inplace */
1562 ((bfd_vma
) 0) - 1, /* dst_mask */
1563 FALSE
), /* pcrel_offset */
1611 /* Relocations for SHmedia code. None of these are partial_inplace or
1612 use the field being relocated (except R_SH_PT_16). */
1614 /* The assembler will generate this reloc before a block of SHmedia
1615 instructions. A section should be processed as assuming it contains
1616 data, unless this reloc is seen. Note that a block of SHcompact
1617 instructions are instead preceded by R_SH_CODE.
1618 This is currently not implemented, but should be used for SHmedia
1619 linker relaxation. */
1620 HOWTO (R_SH_SHMEDIA_CODE
, /* type */
1622 1, /* size (0 = byte, 1 = short, 2 = long) */
1624 FALSE
, /* pc_relative */
1626 complain_overflow_unsigned
, /* complain_on_overflow */
1627 sh_elf_ignore_reloc
, /* special_function */
1628 "R_SH_SHMEDIA_CODE", /* name */
1629 FALSE
, /* partial_inplace */
1632 FALSE
), /* pcrel_offset */
1634 /* The assembler will generate this reloc at a PTA or PTB instruction,
1635 and the linker checks the right type of target, or changes a PTA to a
1636 PTB, if the original insn was PT. */
1637 HOWTO (R_SH_PT_16
, /* type */
1639 2, /* size (0 = byte, 1 = short, 2 = long) */
1641 TRUE
, /* pc_relative */
1643 complain_overflow_signed
, /* complain_on_overflow */
1644 bfd_elf_generic_reloc
, /* special_function */
1645 "R_SH_PT_16", /* name */
1646 FALSE
, /* partial_inplace */
1648 0x3fffc00, /* dst_mask */
1649 TRUE
), /* pcrel_offset */
1651 /* Used in unexpanded MOVI. */
1652 HOWTO (R_SH_IMMS16
, /* type */
1654 2, /* size (0 = byte, 1 = short, 2 = long) */
1656 FALSE
, /* pc_relative */
1658 complain_overflow_signed
, /* complain_on_overflow */
1659 bfd_elf_generic_reloc
, /* special_function */
1660 "R_SH_IMMS16", /* name */
1661 FALSE
, /* partial_inplace */
1663 0x3fffc00, /* dst_mask */
1664 FALSE
), /* pcrel_offset */
1666 /* Used in SHORI. */
1667 HOWTO (R_SH_IMMU16
, /* type */
1669 2, /* size (0 = byte, 1 = short, 2 = long) */
1671 FALSE
, /* pc_relative */
1673 complain_overflow_unsigned
, /* complain_on_overflow */
1674 bfd_elf_generic_reloc
, /* special_function */
1675 "R_SH_IMMU16", /* name */
1676 FALSE
, /* partial_inplace */
1678 0x3fffc00, /* dst_mask */
1679 FALSE
), /* pcrel_offset */
1681 /* Used in MOVI and SHORI (x & 65536). */
1682 HOWTO (R_SH_IMM_LOW16
, /* type */
1684 2, /* size (0 = byte, 1 = short, 2 = long) */
1686 FALSE
, /* pc_relative */
1688 complain_overflow_dont
, /* complain_on_overflow */
1689 bfd_elf_generic_reloc
, /* special_function */
1690 "R_SH_IMM_LOW16", /* name */
1691 FALSE
, /* partial_inplace */
1693 0x3fffc00, /* dst_mask */
1694 FALSE
), /* pcrel_offset */
1696 /* Used in MOVI and SHORI ((x - $) & 65536). */
1697 HOWTO (R_SH_IMM_LOW16_PCREL
, /* type */
1699 2, /* size (0 = byte, 1 = short, 2 = long) */
1701 TRUE
, /* pc_relative */
1703 complain_overflow_dont
, /* complain_on_overflow */
1704 bfd_elf_generic_reloc
, /* special_function */
1705 "R_SH_IMM_LOW16_PCREL", /* name */
1706 FALSE
, /* partial_inplace */
1708 0x3fffc00, /* dst_mask */
1709 TRUE
), /* pcrel_offset */
1711 /* Used in MOVI and SHORI ((x >> 16) & 65536). */
1712 HOWTO (R_SH_IMM_MEDLOW16
, /* type */
1713 16, /* rightshift */
1714 2, /* size (0 = byte, 1 = short, 2 = long) */
1716 FALSE
, /* pc_relative */
1718 complain_overflow_dont
, /* complain_on_overflow */
1719 bfd_elf_generic_reloc
, /* special_function */
1720 "R_SH_IMM_MEDLOW16", /* name */
1721 FALSE
, /* partial_inplace */
1723 0x3fffc00, /* dst_mask */
1724 FALSE
), /* pcrel_offset */
1726 /* Used in MOVI and SHORI (((x - $) >> 16) & 65536). */
1727 HOWTO (R_SH_IMM_MEDLOW16_PCREL
, /* type */
1728 16, /* rightshift */
1729 2, /* size (0 = byte, 1 = short, 2 = long) */
1731 TRUE
, /* pc_relative */
1733 complain_overflow_dont
, /* complain_on_overflow */
1734 bfd_elf_generic_reloc
, /* special_function */
1735 "R_SH_IMM_MEDLOW16_PCREL", /* name */
1736 FALSE
, /* partial_inplace */
1738 0x3fffc00, /* dst_mask */
1739 TRUE
), /* pcrel_offset */
1741 /* Used in MOVI and SHORI ((x >> 32) & 65536). */
1742 HOWTO (R_SH_IMM_MEDHI16
, /* type */
1743 32, /* rightshift */
1744 2, /* size (0 = byte, 1 = short, 2 = long) */
1746 FALSE
, /* pc_relative */
1748 complain_overflow_dont
, /* complain_on_overflow */
1749 bfd_elf_generic_reloc
, /* special_function */
1750 "R_SH_IMM_MEDHI16", /* name */
1751 FALSE
, /* partial_inplace */
1753 0x3fffc00, /* dst_mask */
1754 FALSE
), /* pcrel_offset */
1756 /* Used in MOVI and SHORI (((x - $) >> 32) & 65536). */
1757 HOWTO (R_SH_IMM_MEDHI16_PCREL
, /* type */
1758 32, /* rightshift */
1759 2, /* size (0 = byte, 1 = short, 2 = long) */
1761 TRUE
, /* pc_relative */
1763 complain_overflow_dont
, /* complain_on_overflow */
1764 bfd_elf_generic_reloc
, /* special_function */
1765 "R_SH_IMM_MEDHI16_PCREL", /* name */
1766 FALSE
, /* partial_inplace */
1768 0x3fffc00, /* dst_mask */
1769 TRUE
), /* pcrel_offset */
1771 /* Used in MOVI and SHORI ((x >> 48) & 65536). */
1772 HOWTO (R_SH_IMM_HI16
, /* type */
1773 48, /* rightshift */
1774 2, /* size (0 = byte, 1 = short, 2 = long) */
1776 FALSE
, /* pc_relative */
1778 complain_overflow_dont
, /* complain_on_overflow */
1779 bfd_elf_generic_reloc
, /* special_function */
1780 "R_SH_IMM_HI16", /* name */
1781 FALSE
, /* partial_inplace */
1783 0x3fffc00, /* dst_mask */
1784 FALSE
), /* pcrel_offset */
1786 /* Used in MOVI and SHORI (((x - $) >> 48) & 65536). */
1787 HOWTO (R_SH_IMM_HI16_PCREL
, /* type */
1788 48, /* rightshift */
1789 2, /* size (0 = byte, 1 = short, 2 = long) */
1791 TRUE
, /* pc_relative */
1793 complain_overflow_dont
, /* complain_on_overflow */
1794 bfd_elf_generic_reloc
, /* special_function */
1795 "R_SH_IMM_HI16_PCREL", /* name */
1796 FALSE
, /* partial_inplace */
1798 0x3fffc00, /* dst_mask */
1799 TRUE
), /* pcrel_offset */
1801 /* For the .uaquad pseudo. */
1802 HOWTO (R_SH_64
, /* type */
1804 4, /* size (0 = byte, 1 = short, 2 = long) */
1806 FALSE
, /* pc_relative */
1808 complain_overflow_dont
, /* complain_on_overflow */
1809 bfd_elf_generic_reloc
, /* special_function */
1810 "R_SH_64", /* name */
1811 FALSE
, /* partial_inplace */
1813 ((bfd_vma
) 0) - 1, /* dst_mask */
1814 FALSE
), /* pcrel_offset */
1816 /* For the .uaquad pseudo, (x - $). */
1817 HOWTO (R_SH_64_PCREL
, /* type */
1818 48, /* rightshift */
1819 2, /* size (0 = byte, 1 = short, 2 = long) */
1821 TRUE
, /* pc_relative */
1823 complain_overflow_dont
, /* complain_on_overflow */
1824 bfd_elf_generic_reloc
, /* special_function */
1825 "R_SH_64_PCREL", /* name */
1826 FALSE
, /* partial_inplace */
1828 ((bfd_vma
) 0) - 1, /* dst_mask */
1829 TRUE
), /* pcrel_offset */
1834 static bfd_reloc_status_type
1835 sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED
, bfd
*input_bfd
,
1836 asection
*input_section
, bfd_byte
*contents
,
1837 bfd_vma addr
, asection
*symbol_section
,
1838 bfd_vma start
, bfd_vma end
)
1840 static bfd_vma last_addr
;
1841 static asection
*last_symbol_section
;
1842 bfd_byte
*start_ptr
, *ptr
, *last_ptr
;
1847 /* Sanity check the address. */
1848 if (addr
> input_section
->_raw_size
)
1849 return bfd_reloc_outofrange
;
1851 /* We require the start and end relocations to be processed consecutively -
1852 although we allow then to be processed forwards or backwards. */
1856 last_symbol_section
= symbol_section
;
1857 return bfd_reloc_ok
;
1859 if (last_addr
!= addr
)
1863 if (! symbol_section
|| last_symbol_section
!= symbol_section
|| end
< start
)
1864 return bfd_reloc_outofrange
;
1866 /* Get the symbol_section contents. */
1867 if (symbol_section
!= input_section
)
1869 if (elf_section_data (symbol_section
)->this_hdr
.contents
!= NULL
)
1870 contents
= elf_section_data (symbol_section
)->this_hdr
.contents
;
1873 contents
= (bfd_byte
*) bfd_malloc (symbol_section
->_raw_size
);
1874 if (contents
== NULL
)
1875 return bfd_reloc_outofrange
;
1876 if (! bfd_get_section_contents (input_bfd
, symbol_section
, contents
,
1878 symbol_section
->_raw_size
))
1881 return bfd_reloc_outofrange
;
1885 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
1886 start_ptr
= contents
+ start
;
1887 for (cum_diff
= -6, ptr
= contents
+ end
; cum_diff
< 0 && ptr
> start_ptr
;)
1889 for (last_ptr
= ptr
, ptr
-= 4; ptr
>= start_ptr
&& IS_PPI (ptr
);)
1892 diff
= (last_ptr
- ptr
) >> 1;
1893 cum_diff
+= diff
& 1;
1896 /* Calculate the start / end values to load into rs / re minus four -
1897 so that will cancel out the four we would otherwise have to add to
1898 addr to get the value to subtract in order to get relative addressing. */
1902 end
= (ptr
+ cum_diff
* 2) - contents
;
1906 bfd_vma start0
= start
- 4;
1908 while (start0
&& IS_PPI (contents
+ start0
))
1910 start0
= start
- 2 - ((start
- start0
) & 2);
1911 start
= start0
- cum_diff
- 2;
1915 if (contents
!= NULL
1916 && elf_section_data (symbol_section
)->this_hdr
.contents
!= contents
)
1919 insn
= bfd_get_16 (input_bfd
, contents
+ addr
);
1921 x
= (insn
& 0x200 ? end
: start
) - addr
;
1922 if (input_section
!= symbol_section
)
1923 x
+= ((symbol_section
->output_section
->vma
+ symbol_section
->output_offset
)
1924 - (input_section
->output_section
->vma
1925 + input_section
->output_offset
));
1927 if (x
< -128 || x
> 127)
1928 return bfd_reloc_overflow
;
1930 x
= (insn
& ~0xff) | (x
& 0xff);
1931 bfd_put_16 (input_bfd
, (bfd_vma
) x
, contents
+ addr
);
1933 return bfd_reloc_ok
;
1936 /* This function is used for normal relocs. This used to be like the COFF
1937 function, and is almost certainly incorrect for other ELF targets. */
1939 static bfd_reloc_status_type
1940 sh_elf_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol_in
,
1941 void *data
, asection
*input_section
, bfd
*output_bfd
,
1942 char **error_message ATTRIBUTE_UNUSED
)
1946 enum elf_sh_reloc_type r_type
;
1947 bfd_vma addr
= reloc_entry
->address
;
1948 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
1950 r_type
= (enum elf_sh_reloc_type
) reloc_entry
->howto
->type
;
1952 if (output_bfd
!= NULL
)
1954 /* Partial linking--do nothing. */
1955 reloc_entry
->address
+= input_section
->output_offset
;
1956 return bfd_reloc_ok
;
1959 /* Almost all relocs have to do with relaxing. If any work must be
1960 done for them, it has been done in sh_relax_section. */
1961 if (r_type
== R_SH_IND12W
&& (symbol_in
->flags
& BSF_LOCAL
) != 0)
1962 return bfd_reloc_ok
;
1964 if (symbol_in
!= NULL
1965 && bfd_is_und_section (symbol_in
->section
))
1966 return bfd_reloc_undefined
;
1968 if (bfd_is_com_section (symbol_in
->section
))
1971 sym_value
= (symbol_in
->value
+
1972 symbol_in
->section
->output_section
->vma
+
1973 symbol_in
->section
->output_offset
);
1978 insn
= bfd_get_32 (abfd
, hit_data
);
1979 insn
+= sym_value
+ reloc_entry
->addend
;
1980 bfd_put_32 (abfd
, (bfd_vma
) insn
, hit_data
);
1983 insn
= bfd_get_16 (abfd
, hit_data
);
1984 sym_value
+= reloc_entry
->addend
;
1985 sym_value
-= (input_section
->output_section
->vma
1986 + input_section
->output_offset
1989 sym_value
+= (insn
& 0xfff) << 1;
1991 sym_value
-= 0x1000;
1992 insn
= (insn
& 0xf000) | (sym_value
& 0xfff);
1993 bfd_put_16 (abfd
, (bfd_vma
) insn
, hit_data
);
1994 if (sym_value
< (bfd_vma
) -0x1000 || sym_value
>= 0x1000)
1995 return bfd_reloc_overflow
;
2002 return bfd_reloc_ok
;
2005 /* This function is used for relocs which are only used for relaxing,
2006 which the linker should otherwise ignore. */
2008 static bfd_reloc_status_type
2009 sh_elf_ignore_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2010 asymbol
*symbol ATTRIBUTE_UNUSED
,
2011 void *data ATTRIBUTE_UNUSED
, asection
*input_section
,
2013 char **error_message ATTRIBUTE_UNUSED
)
2015 if (output_bfd
!= NULL
)
2016 reloc_entry
->address
+= input_section
->output_offset
;
2017 return bfd_reloc_ok
;
2020 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
2022 struct elf_reloc_map
2024 bfd_reloc_code_real_type bfd_reloc_val
;
2025 unsigned char elf_reloc_val
;
2028 /* An array mapping BFD reloc codes to SH ELF relocs. */
2030 static const struct elf_reloc_map sh_reloc_map
[] =
2032 { BFD_RELOC_NONE
, R_SH_NONE
},
2033 { BFD_RELOC_32
, R_SH_DIR32
},
2034 { BFD_RELOC_16
, R_SH_DIR16
},
2035 { BFD_RELOC_8
, R_SH_DIR8
},
2036 { BFD_RELOC_CTOR
, R_SH_DIR32
},
2037 { BFD_RELOC_32_PCREL
, R_SH_REL32
},
2038 { BFD_RELOC_SH_PCDISP8BY2
, R_SH_DIR8WPN
},
2039 { BFD_RELOC_SH_PCDISP12BY2
, R_SH_IND12W
},
2040 { BFD_RELOC_SH_PCRELIMM8BY2
, R_SH_DIR8WPZ
},
2041 { BFD_RELOC_SH_PCRELIMM8BY4
, R_SH_DIR8WPL
},
2042 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
2043 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
2044 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
2045 { BFD_RELOC_SH_USES
, R_SH_USES
},
2046 { BFD_RELOC_SH_COUNT
, R_SH_COUNT
},
2047 { BFD_RELOC_SH_ALIGN
, R_SH_ALIGN
},
2048 { BFD_RELOC_SH_CODE
, R_SH_CODE
},
2049 { BFD_RELOC_SH_DATA
, R_SH_DATA
},
2050 { BFD_RELOC_SH_LABEL
, R_SH_LABEL
},
2051 { BFD_RELOC_VTABLE_INHERIT
, R_SH_GNU_VTINHERIT
},
2052 { BFD_RELOC_VTABLE_ENTRY
, R_SH_GNU_VTENTRY
},
2053 { BFD_RELOC_SH_LOOP_START
, R_SH_LOOP_START
},
2054 { BFD_RELOC_SH_LOOP_END
, R_SH_LOOP_END
},
2055 { BFD_RELOC_SH_TLS_GD_32
, R_SH_TLS_GD_32
},
2056 { BFD_RELOC_SH_TLS_LD_32
, R_SH_TLS_LD_32
},
2057 { BFD_RELOC_SH_TLS_LDO_32
, R_SH_TLS_LDO_32
},
2058 { BFD_RELOC_SH_TLS_IE_32
, R_SH_TLS_IE_32
},
2059 { BFD_RELOC_SH_TLS_LE_32
, R_SH_TLS_LE_32
},
2060 { BFD_RELOC_SH_TLS_DTPMOD32
, R_SH_TLS_DTPMOD32
},
2061 { BFD_RELOC_SH_TLS_DTPOFF32
, R_SH_TLS_DTPOFF32
},
2062 { BFD_RELOC_SH_TLS_TPOFF32
, R_SH_TLS_TPOFF32
},
2063 { BFD_RELOC_32_GOT_PCREL
, R_SH_GOT32
},
2064 { BFD_RELOC_32_PLT_PCREL
, R_SH_PLT32
},
2065 { BFD_RELOC_SH_COPY
, R_SH_COPY
},
2066 { BFD_RELOC_SH_GLOB_DAT
, R_SH_GLOB_DAT
},
2067 { BFD_RELOC_SH_JMP_SLOT
, R_SH_JMP_SLOT
},
2068 { BFD_RELOC_SH_RELATIVE
, R_SH_RELATIVE
},
2069 { BFD_RELOC_32_GOTOFF
, R_SH_GOTOFF
},
2070 { BFD_RELOC_SH_GOTPC
, R_SH_GOTPC
},
2071 { BFD_RELOC_SH_GOTPLT32
, R_SH_GOTPLT32
},
2072 #ifdef INCLUDE_SHMEDIA
2073 { BFD_RELOC_SH_GOT_LOW16
, R_SH_GOT_LOW16
},
2074 { BFD_RELOC_SH_GOT_MEDLOW16
, R_SH_GOT_MEDLOW16
},
2075 { BFD_RELOC_SH_GOT_MEDHI16
, R_SH_GOT_MEDHI16
},
2076 { BFD_RELOC_SH_GOT_HI16
, R_SH_GOT_HI16
},
2077 { BFD_RELOC_SH_GOTPLT_LOW16
, R_SH_GOTPLT_LOW16
},
2078 { BFD_RELOC_SH_GOTPLT_MEDLOW16
, R_SH_GOTPLT_MEDLOW16
},
2079 { BFD_RELOC_SH_GOTPLT_MEDHI16
, R_SH_GOTPLT_MEDHI16
},
2080 { BFD_RELOC_SH_GOTPLT_HI16
, R_SH_GOTPLT_HI16
},
2081 { BFD_RELOC_SH_PLT_LOW16
, R_SH_PLT_LOW16
},
2082 { BFD_RELOC_SH_PLT_MEDLOW16
, R_SH_PLT_MEDLOW16
},
2083 { BFD_RELOC_SH_PLT_MEDHI16
, R_SH_PLT_MEDHI16
},
2084 { BFD_RELOC_SH_PLT_HI16
, R_SH_PLT_HI16
},
2085 { BFD_RELOC_SH_GOTOFF_LOW16
, R_SH_GOTOFF_LOW16
},
2086 { BFD_RELOC_SH_GOTOFF_MEDLOW16
, R_SH_GOTOFF_MEDLOW16
},
2087 { BFD_RELOC_SH_GOTOFF_MEDHI16
, R_SH_GOTOFF_MEDHI16
},
2088 { BFD_RELOC_SH_GOTOFF_HI16
, R_SH_GOTOFF_HI16
},
2089 { BFD_RELOC_SH_GOTPC_LOW16
, R_SH_GOTPC_LOW16
},
2090 { BFD_RELOC_SH_GOTPC_MEDLOW16
, R_SH_GOTPC_MEDLOW16
},
2091 { BFD_RELOC_SH_GOTPC_MEDHI16
, R_SH_GOTPC_MEDHI16
},
2092 { BFD_RELOC_SH_GOTPC_HI16
, R_SH_GOTPC_HI16
},
2093 { BFD_RELOC_SH_COPY64
, R_SH_COPY64
},
2094 { BFD_RELOC_SH_GLOB_DAT64
, R_SH_GLOB_DAT64
},
2095 { BFD_RELOC_SH_JMP_SLOT64
, R_SH_JMP_SLOT64
},
2096 { BFD_RELOC_SH_RELATIVE64
, R_SH_RELATIVE64
},
2097 { BFD_RELOC_SH_GOT10BY4
, R_SH_GOT10BY4
},
2098 { BFD_RELOC_SH_GOT10BY8
, R_SH_GOT10BY8
},
2099 { BFD_RELOC_SH_GOTPLT10BY4
, R_SH_GOTPLT10BY4
},
2100 { BFD_RELOC_SH_GOTPLT10BY8
, R_SH_GOTPLT10BY8
},
2101 { BFD_RELOC_SH_PT_16
, R_SH_PT_16
},
2102 { BFD_RELOC_SH_SHMEDIA_CODE
, R_SH_SHMEDIA_CODE
},
2103 { BFD_RELOC_SH_IMMU5
, R_SH_DIR5U
},
2104 { BFD_RELOC_SH_IMMS6
, R_SH_DIR6S
},
2105 { BFD_RELOC_SH_IMMU6
, R_SH_DIR6U
},
2106 { BFD_RELOC_SH_IMMS10
, R_SH_DIR10S
},
2107 { BFD_RELOC_SH_IMMS10BY2
, R_SH_DIR10SW
},
2108 { BFD_RELOC_SH_IMMS10BY4
, R_SH_DIR10SL
},
2109 { BFD_RELOC_SH_IMMS10BY8
, R_SH_DIR10SQ
},
2110 { BFD_RELOC_SH_IMMS16
, R_SH_IMMS16
},
2111 { BFD_RELOC_SH_IMMU16
, R_SH_IMMU16
},
2112 { BFD_RELOC_SH_IMM_LOW16
, R_SH_IMM_LOW16
},
2113 { BFD_RELOC_SH_IMM_LOW16_PCREL
, R_SH_IMM_LOW16_PCREL
},
2114 { BFD_RELOC_SH_IMM_MEDLOW16
, R_SH_IMM_MEDLOW16
},
2115 { BFD_RELOC_SH_IMM_MEDLOW16_PCREL
, R_SH_IMM_MEDLOW16_PCREL
},
2116 { BFD_RELOC_SH_IMM_MEDHI16
, R_SH_IMM_MEDHI16
},
2117 { BFD_RELOC_SH_IMM_MEDHI16_PCREL
, R_SH_IMM_MEDHI16_PCREL
},
2118 { BFD_RELOC_SH_IMM_HI16
, R_SH_IMM_HI16
},
2119 { BFD_RELOC_SH_IMM_HI16_PCREL
, R_SH_IMM_HI16_PCREL
},
2120 { BFD_RELOC_64
, R_SH_64
},
2121 { BFD_RELOC_64_PCREL
, R_SH_64_PCREL
},
2122 #endif /* not INCLUDE_SHMEDIA */
2125 /* Given a BFD reloc code, return the howto structure for the
2126 corresponding SH ELf reloc. */
2128 static reloc_howto_type
*
2129 sh_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2130 bfd_reloc_code_real_type code
)
2134 for (i
= 0; i
< sizeof (sh_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
2136 if (sh_reloc_map
[i
].bfd_reloc_val
== code
)
2137 return &sh_elf_howto_table
[(int) sh_reloc_map
[i
].elf_reloc_val
];
2143 /* Given an ELF reloc, fill in the howto field of a relent. */
2146 sh_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2147 Elf_Internal_Rela
*dst
)
2151 r
= ELF32_R_TYPE (dst
->r_info
);
2153 BFD_ASSERT (r
< (unsigned int) R_SH_max
);
2154 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC
|| r
> R_SH_LAST_INVALID_RELOC
);
2155 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_2
|| r
> R_SH_LAST_INVALID_RELOC_2
);
2156 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_3
|| r
> R_SH_LAST_INVALID_RELOC_3
);
2157 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_4
|| r
> R_SH_LAST_INVALID_RELOC_4
);
2158 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC_5
|| r
> R_SH_LAST_INVALID_RELOC_5
);
2160 cache_ptr
->howto
= &sh_elf_howto_table
[r
];
2163 /* This function handles relaxing for SH ELF. See the corresponding
2164 function in coff-sh.c for a description of what this does. FIXME:
2165 There is a lot of duplication here between this code and the COFF
2166 specific code. The format of relocs and symbols is wound deeply
2167 into this code, but it would still be better if the duplication
2168 could be eliminated somehow. Note in particular that although both
2169 functions use symbols like R_SH_CODE, those symbols have different
2170 values; in coff-sh.c they come from include/coff/sh.h, whereas here
2171 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
2174 sh_elf_relax_section (bfd
*abfd
, asection
*sec
,
2175 struct bfd_link_info
*link_info
, bfd_boolean
*again
)
2177 Elf_Internal_Shdr
*symtab_hdr
;
2178 Elf_Internal_Rela
*internal_relocs
;
2179 bfd_boolean have_code
;
2180 Elf_Internal_Rela
*irel
, *irelend
;
2181 bfd_byte
*contents
= NULL
;
2182 Elf_Internal_Sym
*isymbuf
= NULL
;
2186 if (link_info
->relocatable
2187 || (sec
->flags
& SEC_RELOC
) == 0
2188 || sec
->reloc_count
== 0)
2191 #ifdef INCLUDE_SHMEDIA
2192 if (elf_section_data (sec
)->this_hdr
.sh_flags
2193 & (SHF_SH5_ISA32
| SHF_SH5_ISA32_MIXED
))
2199 /* If this is the first time we have been called for this section,
2200 initialize the cooked size. */
2201 if (sec
->_cooked_size
== 0)
2202 sec
->_cooked_size
= sec
->_raw_size
;
2204 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2206 internal_relocs
= (_bfd_elf_link_read_relocs
2207 (abfd
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
2208 link_info
->keep_memory
));
2209 if (internal_relocs
== NULL
)
2214 irelend
= internal_relocs
+ sec
->reloc_count
;
2215 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2217 bfd_vma laddr
, paddr
, symval
;
2218 unsigned short insn
;
2219 Elf_Internal_Rela
*irelfn
, *irelscan
, *irelcount
;
2220 bfd_signed_vma foff
;
2222 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_CODE
)
2225 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_USES
)
2228 /* Get the section contents. */
2229 if (contents
== NULL
)
2231 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2232 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2235 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
2236 if (contents
== NULL
)
2239 if (! bfd_get_section_contents (abfd
, sec
, contents
,
2240 (file_ptr
) 0, sec
->_raw_size
))
2245 /* The r_addend field of the R_SH_USES reloc will point us to
2246 the register load. The 4 is because the r_addend field is
2247 computed as though it were a jump offset, which are based
2248 from 4 bytes after the jump instruction. */
2249 laddr
= irel
->r_offset
+ 4 + irel
->r_addend
;
2250 if (laddr
>= sec
->_raw_size
)
2252 (*_bfd_error_handler
) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),
2253 bfd_archive_filename (abfd
),
2254 (unsigned long) irel
->r_offset
);
2257 insn
= bfd_get_16 (abfd
, contents
+ laddr
);
2259 /* If the instruction is not mov.l NN,rN, we don't know what to
2261 if ((insn
& 0xf000) != 0xd000)
2263 ((*_bfd_error_handler
)
2264 (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
2265 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
, insn
));
2269 /* Get the address from which the register is being loaded. The
2270 displacement in the mov.l instruction is quadrupled. It is a
2271 displacement from four bytes after the movl instruction, but,
2272 before adding in the PC address, two least significant bits
2273 of the PC are cleared. We assume that the section is aligned
2274 on a four byte boundary. */
2275 paddr
= insn
& 0xff;
2277 paddr
+= (laddr
+ 4) &~ (bfd_vma
) 3;
2278 if (paddr
>= sec
->_raw_size
)
2280 ((*_bfd_error_handler
)
2281 (_("%s: 0x%lx: warning: bad R_SH_USES load offset"),
2282 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
2286 /* Get the reloc for the address from which the register is
2287 being loaded. This reloc will tell us which function is
2288 actually being called. */
2289 for (irelfn
= internal_relocs
; irelfn
< irelend
; irelfn
++)
2290 if (irelfn
->r_offset
== paddr
2291 && ELF32_R_TYPE (irelfn
->r_info
) == (int) R_SH_DIR32
)
2293 if (irelfn
>= irelend
)
2295 ((*_bfd_error_handler
)
2296 (_("%s: 0x%lx: warning: could not find expected reloc"),
2297 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2301 /* Read this BFD's symbols if we haven't done so already. */
2302 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
2304 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2305 if (isymbuf
== NULL
)
2306 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
2307 symtab_hdr
->sh_info
, 0,
2309 if (isymbuf
== NULL
)
2313 /* Get the value of the symbol referred to by the reloc. */
2314 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
2316 /* A local symbol. */
2317 Elf_Internal_Sym
*isym
;
2319 isym
= isymbuf
+ ELF32_R_SYM (irelfn
->r_info
);
2321 != (unsigned int) _bfd_elf_section_from_bfd_section (abfd
, sec
))
2323 ((*_bfd_error_handler
)
2324 (_("%s: 0x%lx: warning: symbol in unexpected section"),
2325 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2329 symval
= (isym
->st_value
2330 + sec
->output_section
->vma
2331 + sec
->output_offset
);
2336 struct elf_link_hash_entry
*h
;
2338 indx
= ELF32_R_SYM (irelfn
->r_info
) - symtab_hdr
->sh_info
;
2339 h
= elf_sym_hashes (abfd
)[indx
];
2340 BFD_ASSERT (h
!= NULL
);
2341 if (h
->root
.type
!= bfd_link_hash_defined
2342 && h
->root
.type
!= bfd_link_hash_defweak
)
2344 /* This appears to be a reference to an undefined
2345 symbol. Just ignore it--it will be caught by the
2346 regular reloc processing. */
2350 symval
= (h
->root
.u
.def
.value
2351 + h
->root
.u
.def
.section
->output_section
->vma
2352 + h
->root
.u
.def
.section
->output_offset
);
2355 symval
+= bfd_get_32 (abfd
, contents
+ paddr
);
2357 /* See if this function call can be shortened. */
2360 + sec
->output_section
->vma
2361 + sec
->output_offset
2363 if (foff
< -0x1000 || foff
>= 0x1000)
2365 /* After all that work, we can't shorten this function call. */
2369 /* Shorten the function call. */
2371 /* For simplicity of coding, we are going to modify the section
2372 contents, the section relocs, and the BFD symbol table. We
2373 must tell the rest of the code not to free up this
2374 information. It would be possible to instead create a table
2375 of changes which have to be made, as is done in coff-mips.c;
2376 that would be more work, but would require less memory when
2377 the linker is run. */
2379 elf_section_data (sec
)->relocs
= internal_relocs
;
2380 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2381 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2383 /* Replace the jsr with a bsr. */
2385 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
2386 replace the jsr with a bsr. */
2387 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irelfn
->r_info
), R_SH_IND12W
);
2388 /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
2389 here, but that only checks if the symbol is an external symbol,
2390 not if the symbol is in a different section. Besides, we need
2391 a consistent meaning for the relocation, so we just assume here that
2392 the value of the symbol is not available. */
2394 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
2396 /* If this needs to be changed because of future relaxing,
2397 it will be handled here like other internal IND12W
2400 (bfd_vma
) 0xb000 | ((foff
>> 1) & 0xfff),
2401 contents
+ irel
->r_offset
);
2406 /* We can't fully resolve this yet, because the external
2407 symbol value may be changed by future relaxing. We let
2408 the final link phase handle it. */
2409 bfd_put_16 (abfd
, (bfd_vma
) 0xb000, contents
+ irel
->r_offset
);
2411 irel
->r_addend
= -4;
2413 /* See if there is another R_SH_USES reloc referring to the same
2415 for (irelscan
= internal_relocs
; irelscan
< irelend
; irelscan
++)
2416 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_USES
2417 && laddr
== irelscan
->r_offset
+ 4 + irelscan
->r_addend
)
2419 if (irelscan
< irelend
)
2421 /* Some other function call depends upon this register load,
2422 and we have not yet converted that function call.
2423 Indeed, we may never be able to convert it. There is
2424 nothing else we can do at this point. */
2428 /* Look for a R_SH_COUNT reloc on the location where the
2429 function address is stored. Do this before deleting any
2430 bytes, to avoid confusion about the address. */
2431 for (irelcount
= internal_relocs
; irelcount
< irelend
; irelcount
++)
2432 if (irelcount
->r_offset
== paddr
2433 && ELF32_R_TYPE (irelcount
->r_info
) == (int) R_SH_COUNT
)
2436 /* Delete the register load. */
2437 if (! sh_elf_relax_delete_bytes (abfd
, sec
, laddr
, 2))
2440 /* That will change things, so, just in case it permits some
2441 other function call to come within range, we should relax
2442 again. Note that this is not required, and it may be slow. */
2445 /* Now check whether we got a COUNT reloc. */
2446 if (irelcount
>= irelend
)
2448 ((*_bfd_error_handler
)
2449 (_("%s: 0x%lx: warning: could not find expected COUNT reloc"),
2450 bfd_archive_filename (abfd
), (unsigned long) paddr
));
2454 /* The number of uses is stored in the r_addend field. We've
2455 just deleted one. */
2456 if (irelcount
->r_addend
== 0)
2458 ((*_bfd_error_handler
) (_("%s: 0x%lx: warning: bad count"),
2459 bfd_archive_filename (abfd
),
2460 (unsigned long) paddr
));
2464 --irelcount
->r_addend
;
2466 /* If there are no more uses, we can delete the address. Reload
2467 the address from irelfn, in case it was changed by the
2468 previous call to sh_elf_relax_delete_bytes. */
2469 if (irelcount
->r_addend
== 0)
2471 if (! sh_elf_relax_delete_bytes (abfd
, sec
, irelfn
->r_offset
, 4))
2475 /* We've done all we can with that function call. */
2478 /* Look for load and store instructions that we can align on four
2480 if ((elf_elfheader (abfd
)->e_flags
& EF_SH_MACH_MASK
) != EF_SH4
2483 bfd_boolean swapped
;
2485 /* Get the section contents. */
2486 if (contents
== NULL
)
2488 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
2489 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2492 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
2493 if (contents
== NULL
)
2496 if (! bfd_get_section_contents (abfd
, sec
, contents
,
2497 (file_ptr
) 0, sec
->_raw_size
))
2502 if (! sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
,
2508 elf_section_data (sec
)->relocs
= internal_relocs
;
2509 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2510 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2515 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2517 if (! link_info
->keep_memory
)
2521 /* Cache the symbols for elf_link_input_bfd. */
2522 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2526 if (contents
!= NULL
2527 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2529 if (! link_info
->keep_memory
)
2533 /* Cache the section contents for elf_link_input_bfd. */
2534 elf_section_data (sec
)->this_hdr
.contents
= contents
;
2538 if (internal_relocs
!= NULL
2539 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2540 free (internal_relocs
);
2546 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2548 if (contents
!= NULL
2549 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
2551 if (internal_relocs
!= NULL
2552 && elf_section_data (sec
)->relocs
!= internal_relocs
)
2553 free (internal_relocs
);
2558 /* Delete some bytes from a section while relaxing. FIXME: There is a
2559 lot of duplication between this function and sh_relax_delete_bytes
2563 sh_elf_relax_delete_bytes (bfd
*abfd
, asection
*sec
, bfd_vma addr
,
2566 Elf_Internal_Shdr
*symtab_hdr
;
2567 unsigned int sec_shndx
;
2569 Elf_Internal_Rela
*irel
, *irelend
;
2570 Elf_Internal_Rela
*irelalign
;
2572 Elf_Internal_Sym
*isymbuf
, *isym
, *isymend
;
2573 struct elf_link_hash_entry
**sym_hashes
;
2574 struct elf_link_hash_entry
**end_hashes
;
2575 unsigned int symcount
;
2578 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2579 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
2581 sec_shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
2583 contents
= elf_section_data (sec
)->this_hdr
.contents
;
2585 /* The deletion must stop at the next ALIGN reloc for an aligment
2586 power larger than the number of bytes we are deleting. */
2589 toaddr
= sec
->_cooked_size
;
2591 irel
= elf_section_data (sec
)->relocs
;
2592 irelend
= irel
+ sec
->reloc_count
;
2593 for (; irel
< irelend
; irel
++)
2595 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
2596 && irel
->r_offset
> addr
2597 && count
< (1 << irel
->r_addend
))
2600 toaddr
= irel
->r_offset
;
2605 /* Actually delete the bytes. */
2606 memmove (contents
+ addr
, contents
+ addr
+ count
,
2607 (size_t) (toaddr
- addr
- count
));
2608 if (irelalign
== NULL
)
2609 sec
->_cooked_size
-= count
;
2614 #define NOP_OPCODE (0x0009)
2616 BFD_ASSERT ((count
& 1) == 0);
2617 for (i
= 0; i
< count
; i
+= 2)
2618 bfd_put_16 (abfd
, (bfd_vma
) NOP_OPCODE
, contents
+ toaddr
- count
+ i
);
2621 /* Adjust all the relocs. */
2622 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
2624 bfd_vma nraddr
, stop
;
2627 int off
, adjust
, oinsn
;
2628 bfd_signed_vma voff
= 0;
2629 bfd_boolean overflow
;
2631 /* Get the new reloc address. */
2632 nraddr
= irel
->r_offset
;
2633 if ((irel
->r_offset
> addr
2634 && irel
->r_offset
< toaddr
)
2635 || (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
2636 && irel
->r_offset
== toaddr
))
2639 /* See if this reloc was for the bytes we have deleted, in which
2640 case we no longer care about it. Don't delete relocs which
2641 represent addresses, though. */
2642 if (irel
->r_offset
>= addr
2643 && irel
->r_offset
< addr
+ count
2644 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_ALIGN
2645 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
2646 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_DATA
2647 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_LABEL
)
2648 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
2651 /* If this is a PC relative reloc, see if the range it covers
2652 includes the bytes we have deleted. */
2653 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2662 start
= irel
->r_offset
;
2663 insn
= bfd_get_16 (abfd
, contents
+ nraddr
);
2667 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2670 start
= stop
= addr
;
2674 /* If this reloc is against a symbol defined in this
2675 section, and the symbol will not be adjusted below, we
2676 must check the addend to see it will put the value in
2677 range to be adjusted, and hence must be changed. */
2678 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
2680 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
2681 if (isym
->st_shndx
== sec_shndx
2682 && (isym
->st_value
<= addr
2683 || isym
->st_value
>= toaddr
))
2687 val
= bfd_get_32 (abfd
, contents
+ nraddr
);
2688 val
+= isym
->st_value
;
2689 if (val
> addr
&& val
< toaddr
)
2690 bfd_put_32 (abfd
, val
- count
, contents
+ nraddr
);
2693 start
= stop
= addr
;
2700 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
2707 /* This has been made by previous relaxation. Since the
2708 relocation will be against an external symbol, the
2709 final relocation will just do the right thing. */
2710 start
= stop
= addr
;
2716 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
2718 /* The addend will be against the section symbol, thus
2719 for adjusting the addend, the relevant start is the
2720 start of the section.
2721 N.B. If we want to abandon in-place changes here and
2722 test directly using symbol + addend, we have to take into
2723 account that the addend has already been adjusted by -4. */
2724 if (stop
> addr
&& stop
< toaddr
)
2725 irel
->r_addend
-= count
;
2731 stop
= start
+ 4 + off
* 2;
2736 stop
= (start
& ~(bfd_vma
) 3) + 4 + off
* 4;
2742 /* These relocs types represent
2744 The r_addend field holds the difference between the reloc
2745 address and L1. That is the start of the reloc, and
2746 adding in the contents gives us the top. We must adjust
2747 both the r_offset field and the section contents.
2748 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
2749 and the elf bfd r_offset is called r_vaddr. */
2751 stop
= irel
->r_offset
;
2752 start
= (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irel
->r_addend
);
2756 && (stop
<= addr
|| stop
>= toaddr
))
2757 irel
->r_addend
+= count
;
2758 else if (stop
> addr
2760 && (start
<= addr
|| start
>= toaddr
))
2761 irel
->r_addend
-= count
;
2763 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH16
)
2764 voff
= bfd_get_signed_16 (abfd
, contents
+ nraddr
);
2765 else if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH8
)
2766 voff
= bfd_get_8 (abfd
, contents
+ nraddr
);
2768 voff
= bfd_get_signed_32 (abfd
, contents
+ nraddr
);
2769 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
2774 start
= irel
->r_offset
;
2775 stop
= (bfd_vma
) ((bfd_signed_vma
) start
2776 + (long) irel
->r_addend
2783 && (stop
<= addr
|| stop
>= toaddr
))
2785 else if (stop
> addr
2787 && (start
<= addr
|| start
>= toaddr
))
2796 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
2805 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2807 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2812 if ((oinsn
& 0xf000) != (insn
& 0xf000))
2814 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2818 BFD_ASSERT (adjust
== count
|| count
>= 4);
2823 if ((irel
->r_offset
& 3) == 0)
2826 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2828 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
2833 if (voff
< 0 || voff
>= 0xff)
2835 bfd_put_8 (abfd
, voff
, contents
+ nraddr
);
2840 if (voff
< - 0x8000 || voff
>= 0x8000)
2842 bfd_put_signed_16 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
2847 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
2851 irel
->r_addend
+= adjust
;
2857 ((*_bfd_error_handler
)
2858 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
2859 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
2860 bfd_set_error (bfd_error_bad_value
);
2865 irel
->r_offset
= nraddr
;
2868 /* Look through all the other sections. If there contain any IMM32
2869 relocs against internal symbols which we are not going to adjust
2870 below, we may need to adjust the addends. */
2871 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2873 Elf_Internal_Rela
*internal_relocs
;
2874 Elf_Internal_Rela
*irelscan
, *irelscanend
;
2875 bfd_byte
*ocontents
;
2878 || (o
->flags
& SEC_RELOC
) == 0
2879 || o
->reloc_count
== 0)
2882 /* We always cache the relocs. Perhaps, if info->keep_memory is
2883 FALSE, we should free them, if we are permitted to, when we
2884 leave sh_coff_relax_section. */
2885 internal_relocs
= (_bfd_elf_link_read_relocs
2886 (abfd
, o
, NULL
, (Elf_Internal_Rela
*) NULL
, TRUE
));
2887 if (internal_relocs
== NULL
)
2891 irelscanend
= internal_relocs
+ o
->reloc_count
;
2892 for (irelscan
= internal_relocs
; irelscan
< irelscanend
; irelscan
++)
2894 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
2895 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_SWITCH32
)
2897 bfd_vma start
, stop
;
2898 bfd_signed_vma voff
;
2900 if (ocontents
== NULL
)
2902 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
2903 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
2906 /* We always cache the section contents.
2907 Perhaps, if info->keep_memory is FALSE, we
2908 should free them, if we are permitted to,
2909 when we leave sh_coff_relax_section. */
2910 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
2911 if (ocontents
== NULL
)
2913 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
2917 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
2921 stop
= irelscan
->r_offset
;
2923 = (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irelscan
->r_addend
);
2925 /* STOP is in a different section, so it won't change. */
2926 if (start
> addr
&& start
< toaddr
)
2927 irelscan
->r_addend
+= count
;
2929 voff
= bfd_get_signed_32 (abfd
, ocontents
+ irelscan
->r_offset
);
2930 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
2934 && (stop
<= addr
|| stop
>= toaddr
))
2935 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
+ count
,
2936 ocontents
+ irelscan
->r_offset
);
2937 else if (stop
> addr
2939 && (start
<= addr
|| start
>= toaddr
))
2940 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
- count
,
2941 ocontents
+ irelscan
->r_offset
);
2944 if (ELF32_R_TYPE (irelscan
->r_info
) != (int) R_SH_DIR32
)
2947 if (ELF32_R_SYM (irelscan
->r_info
) >= symtab_hdr
->sh_info
)
2951 isym
= isymbuf
+ ELF32_R_SYM (irelscan
->r_info
);
2952 if (isym
->st_shndx
== sec_shndx
2953 && (isym
->st_value
<= addr
2954 || isym
->st_value
>= toaddr
))
2958 if (ocontents
== NULL
)
2960 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
2961 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
2964 /* We always cache the section contents.
2965 Perhaps, if info->keep_memory is FALSE, we
2966 should free them, if we are permitted to,
2967 when we leave sh_coff_relax_section. */
2968 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
2969 if (ocontents
== NULL
)
2971 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
2975 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
2979 val
= bfd_get_32 (abfd
, ocontents
+ irelscan
->r_offset
);
2980 val
+= isym
->st_value
;
2981 if (val
> addr
&& val
< toaddr
)
2982 bfd_put_32 (abfd
, val
- count
,
2983 ocontents
+ irelscan
->r_offset
);
2988 /* Adjust the local symbols defined in this section. */
2989 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
2990 for (isym
= isymbuf
; isym
< isymend
; isym
++)
2992 if (isym
->st_shndx
== sec_shndx
2993 && isym
->st_value
> addr
2994 && isym
->st_value
< toaddr
)
2995 isym
->st_value
-= count
;
2998 /* Now adjust the global symbols defined in this section. */
2999 symcount
= (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
)
3000 - symtab_hdr
->sh_info
);
3001 sym_hashes
= elf_sym_hashes (abfd
);
3002 end_hashes
= sym_hashes
+ symcount
;
3003 for (; sym_hashes
< end_hashes
; sym_hashes
++)
3005 struct elf_link_hash_entry
*sym_hash
= *sym_hashes
;
3006 if ((sym_hash
->root
.type
== bfd_link_hash_defined
3007 || sym_hash
->root
.type
== bfd_link_hash_defweak
)
3008 && sym_hash
->root
.u
.def
.section
== sec
3009 && sym_hash
->root
.u
.def
.value
> addr
3010 && sym_hash
->root
.u
.def
.value
< toaddr
)
3012 sym_hash
->root
.u
.def
.value
-= count
;
3016 /* See if we can move the ALIGN reloc forward. We have adjusted
3017 r_offset for it already. */
3018 if (irelalign
!= NULL
)
3020 bfd_vma alignto
, alignaddr
;
3022 alignto
= BFD_ALIGN (toaddr
, 1 << irelalign
->r_addend
);
3023 alignaddr
= BFD_ALIGN (irelalign
->r_offset
,
3024 1 << irelalign
->r_addend
);
3025 if (alignto
!= alignaddr
)
3027 /* Tail recursion. */
3028 return sh_elf_relax_delete_bytes (abfd
, sec
, alignaddr
,
3029 (int) (alignto
- alignaddr
));
3036 /* Look for loads and stores which we can align to four byte
3037 boundaries. This is like sh_align_loads in coff-sh.c. */
3040 sh_elf_align_loads (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
,
3041 Elf_Internal_Rela
*internal_relocs
,
3042 bfd_byte
*contents ATTRIBUTE_UNUSED
,
3043 bfd_boolean
*pswapped
)
3045 Elf_Internal_Rela
*irel
, *irelend
;
3046 bfd_vma
*labels
= NULL
;
3047 bfd_vma
*label
, *label_end
;
3052 irelend
= internal_relocs
+ sec
->reloc_count
;
3054 /* Get all the addresses with labels on them. */
3055 amt
= sec
->reloc_count
;
3056 amt
*= sizeof (bfd_vma
);
3057 labels
= (bfd_vma
*) bfd_malloc (amt
);
3061 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3063 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_LABEL
)
3065 *label_end
= irel
->r_offset
;
3070 /* Note that the assembler currently always outputs relocs in
3071 address order. If that ever changes, this code will need to sort
3072 the label values and the relocs. */
3076 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3078 bfd_vma start
, stop
;
3080 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
)
3083 start
= irel
->r_offset
;
3085 for (irel
++; irel
< irelend
; irel
++)
3086 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_DATA
)
3089 stop
= irel
->r_offset
;
3091 stop
= sec
->_cooked_size
;
3093 if (! _bfd_sh_align_load_span (abfd
, sec
, contents
, sh_elf_swap_insns
,
3094 internal_relocs
, &label
,
3095 label_end
, start
, stop
, pswapped
))
3109 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
3112 sh_elf_swap_insns (bfd
*abfd
, asection
*sec
, void *relocs
,
3113 bfd_byte
*contents
, bfd_vma addr
)
3115 Elf_Internal_Rela
*internal_relocs
= (Elf_Internal_Rela
*) relocs
;
3116 unsigned short i1
, i2
;
3117 Elf_Internal_Rela
*irel
, *irelend
;
3119 /* Swap the instructions themselves. */
3120 i1
= bfd_get_16 (abfd
, contents
+ addr
);
3121 i2
= bfd_get_16 (abfd
, contents
+ addr
+ 2);
3122 bfd_put_16 (abfd
, (bfd_vma
) i2
, contents
+ addr
);
3123 bfd_put_16 (abfd
, (bfd_vma
) i1
, contents
+ addr
+ 2);
3125 /* Adjust all reloc addresses. */
3126 irelend
= internal_relocs
+ sec
->reloc_count
;
3127 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
3129 enum elf_sh_reloc_type type
;
3132 /* There are a few special types of relocs that we don't want to
3133 adjust. These relocs do not apply to the instruction itself,
3134 but are only associated with the address. */
3135 type
= (enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
);
3136 if (type
== R_SH_ALIGN
3137 || type
== R_SH_CODE
3138 || type
== R_SH_DATA
3139 || type
== R_SH_LABEL
)
3142 /* If an R_SH_USES reloc points to one of the addresses being
3143 swapped, we must adjust it. It would be incorrect to do this
3144 for a jump, though, since we want to execute both
3145 instructions after the jump. (We have avoided swapping
3146 around a label, so the jump will not wind up executing an
3147 instruction it shouldn't). */
3148 if (type
== R_SH_USES
)
3152 off
= irel
->r_offset
+ 4 + irel
->r_addend
;
3154 irel
->r_offset
+= 2;
3155 else if (off
== addr
+ 2)
3156 irel
->r_offset
-= 2;
3159 if (irel
->r_offset
== addr
)
3161 irel
->r_offset
+= 2;
3164 else if (irel
->r_offset
== addr
+ 2)
3166 irel
->r_offset
-= 2;
3175 unsigned short insn
, oinsn
;
3176 bfd_boolean overflow
;
3178 loc
= contents
+ irel
->r_offset
;
3187 insn
= bfd_get_16 (abfd
, loc
);
3190 if ((oinsn
& 0xff00) != (insn
& 0xff00))
3192 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3196 insn
= bfd_get_16 (abfd
, loc
);
3199 if ((oinsn
& 0xf000) != (insn
& 0xf000))
3201 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3205 /* This reloc ignores the least significant 3 bits of
3206 the program counter before adding in the offset.
3207 This means that if ADDR is at an even address, the
3208 swap will not affect the offset. If ADDR is an at an
3209 odd address, then the instruction will be crossing a
3210 four byte boundary, and must be adjusted. */
3211 if ((addr
& 3) != 0)
3213 insn
= bfd_get_16 (abfd
, loc
);
3216 if ((oinsn
& 0xff00) != (insn
& 0xff00))
3218 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
3226 ((*_bfd_error_handler
)
3227 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
3228 bfd_archive_filename (abfd
), (unsigned long) irel
->r_offset
));
3229 bfd_set_error (bfd_error_bad_value
);
3238 #ifdef INCLUDE_SHMEDIA
3240 /* The size in bytes of an entry in the procedure linkage table. */
3242 #define PLT_ENTRY_SIZE 64
3244 /* First entry in an absolute procedure linkage table look like this. */
3246 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3248 0xcc, 0x00, 0x01, 0x10, /* movi .got.plt >> 16, r17 */
3249 0xc8, 0x00, 0x01, 0x10, /* shori .got.plt & 65535, r17 */
3250 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3251 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3252 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3253 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3254 0x6f, 0xf0, 0xff, 0xf0, /* nop */
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 */
3266 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3268 0x10, 0x01, 0x00, 0xcc, /* movi .got.plt >> 16, r17 */
3269 0x10, 0x01, 0x00, 0xc8, /* shori .got.plt & 65535, r17 */
3270 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3271 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3272 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3273 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3274 0xf0, 0xff, 0xf0, 0x6f, /* nop */
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 */
3286 /* Sebsequent entries in an absolute procedure linkage table look like
3289 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3291 0xcc, 0x00, 0x01, 0x90, /* movi nameN-in-GOT >> 16, r25 */
3292 0xc8, 0x00, 0x01, 0x90, /* shori nameN-in-GOT & 65535, r25 */
3293 0x89, 0x90, 0x01, 0x90, /* ld.l r25, 0, r25 */
3294 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3295 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3296 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3297 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3298 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3299 0xcc, 0x00, 0x01, 0x90, /* movi .PLT0 >> 16, r25 */
3300 0xc8, 0x00, 0x01, 0x90, /* shori .PLT0 & 65535, r25 */
3301 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3302 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3303 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3304 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3305 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3306 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3309 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3311 0x90, 0x01, 0x00, 0xcc, /* movi nameN-in-GOT >> 16, r25 */
3312 0x90, 0x01, 0x00, 0xc8, /* shori nameN-in-GOT & 65535, r25 */
3313 0x90, 0x01, 0x90, 0x89, /* ld.l r25, 0, r25 */
3314 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3315 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3316 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3317 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3318 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3319 0x90, 0x01, 0x00, 0xcc, /* movi .PLT0 >> 16, r25 */
3320 0x90, 0x01, 0x00, 0xc8, /* shori .PLT0 & 65535, r25 */
3321 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3322 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3323 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3324 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3325 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3326 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3329 /* Entries in a PIC procedure linkage table look like this. */
3331 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3333 0xcc, 0x00, 0x01, 0x90, /* movi nameN@GOT >> 16, r25 */
3334 0xc8, 0x00, 0x01, 0x90, /* shori nameN@GOT & 65535, r25 */
3335 0x40, 0xc2, 0x65, 0x90, /* ldx.l r12, r25, r25 */
3336 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3337 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3338 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3339 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3340 0x6f, 0xf0, 0xff, 0xf0, /* nop */
3341 0xce, 0x00, 0x01, 0x10, /* movi -GOT_BIAS, r17 */
3342 0x00, 0xc8, 0x45, 0x10, /* add.l r12, r17, r17 */
3343 0x89, 0x10, 0x09, 0x90, /* ld.l r17, 8, r25 */
3344 0x6b, 0xf1, 0x66, 0x00, /* ptabs r25, tr0 */
3345 0x89, 0x10, 0x05, 0x10, /* ld.l r17, 4, r17 */
3346 0xcc, 0x00, 0x01, 0x50, /* movi reloc-offset >> 16, r21 */
3347 0xc8, 0x00, 0x01, 0x50, /* shori reloc-offset & 65535, r21 */
3348 0x44, 0x01, 0xff, 0xf0, /* blink tr0, r63 */
3351 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3353 0x90, 0x01, 0x00, 0xcc, /* movi nameN@GOT >> 16, r25 */
3354 0x90, 0x01, 0x00, 0xc8, /* shori nameN@GOT & 65535, r25 */
3355 0x90, 0x65, 0xc2, 0x40, /* ldx.l r12, r25, r25 */
3356 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3357 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3358 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3359 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3360 0xf0, 0xff, 0xf0, 0x6f, /* nop */
3361 0x10, 0x01, 0x00, 0xce, /* movi -GOT_BIAS, r17 */
3362 0x10, 0x45, 0xc8, 0x00, /* add.l r12, r17, r17 */
3363 0x90, 0x09, 0x10, 0x89, /* ld.l r17, 8, r25 */
3364 0x00, 0x66, 0xf1, 0x6b, /* ptabs r25, tr0 */
3365 0x10, 0x05, 0x10, 0x89, /* ld.l r17, 4, r17 */
3366 0x50, 0x01, 0x00, 0xcc, /* movi reloc-offset >> 16, r21 */
3367 0x50, 0x01, 0x00, 0xc8, /* shori reloc-offset & 65535, r21 */
3368 0xf0, 0xff, 0x01, 0x44, /* blink tr0, r63 */
3371 static const bfd_byte
*elf_sh_plt0_entry
;
3372 static const bfd_byte
*elf_sh_plt_entry
;
3373 static const bfd_byte
*elf_sh_pic_plt_entry
;
3375 /* Return size of a PLT entry. */
3376 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3378 /* Return offset of the PLT0 address in an absolute PLT entry. */
3379 #define elf_sh_plt_plt0_offset(info) 32
3381 /* Return offset of the linker in PLT0 entry. */
3382 #define elf_sh_plt0_gotplt_offset(info) 0
3384 /* Return offset of the trampoline in PLT entry */
3385 #define elf_sh_plt_temp_offset(info) 33 /* Add one because it's SHmedia. */
3387 /* Return offset of the symbol in PLT entry. */
3388 #define elf_sh_plt_symbol_offset(info) 0
3390 /* Return offset of the relocation in PLT entry. */
3391 #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
3394 movi_shori_putval (bfd
*output_bfd
, unsigned long value
, char *addr
)
3396 bfd_put_32 (output_bfd
,
3397 bfd_get_32 (output_bfd
, addr
)
3398 | ((value
>> 6) & 0x3fffc00),
3400 bfd_put_32 (output_bfd
,
3401 bfd_get_32 (output_bfd
, addr
+ 4)
3402 | ((value
<< 10) & 0x3fffc00),
3407 /* The size in bytes of an entry in the procedure linkage table. */
3409 #define PLT_ENTRY_SIZE 28
3411 /* First entry in an absolute procedure linkage table look like this. */
3414 /* Note - this code has been "optimised" not to use r2. r2 is used by
3415 GCC to return the address of large structures, so it should not be
3416 corrupted here. This does mean however, that this PLT does not conform
3417 to the SH PIC ABI. That spec says that r0 contains the type of the PLT
3418 and r2 contains the GOT id. This version stores the GOT id in r0 and
3419 ignores the type. Loaders can easily detect this difference however,
3420 since the type will always be 0 or 8, and the GOT ids will always be
3421 greater than or equal to 12. */
3422 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3424 0xd0, 0x05, /* mov.l 2f,r0 */
3425 0x60, 0x02, /* mov.l @r0,r0 */
3426 0x2f, 0x06, /* mov.l r0,@-r15 */
3427 0xd0, 0x03, /* mov.l 1f,r0 */
3428 0x60, 0x02, /* mov.l @r0,r0 */
3429 0x40, 0x2b, /* jmp @r0 */
3430 0x60, 0xf6, /* mov.l @r15+,r0 */
3431 0x00, 0x09, /* nop */
3432 0x00, 0x09, /* nop */
3433 0x00, 0x09, /* nop */
3434 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3435 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3438 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3440 0x05, 0xd0, /* mov.l 2f,r0 */
3441 0x02, 0x60, /* mov.l @r0,r0 */
3442 0x06, 0x2f, /* mov.l r0,@-r15 */
3443 0x03, 0xd0, /* mov.l 1f,r0 */
3444 0x02, 0x60, /* mov.l @r0,r0 */
3445 0x2b, 0x40, /* jmp @r0 */
3446 0xf6, 0x60, /* mov.l @r15+,r0 */
3447 0x09, 0x00, /* nop */
3448 0x09, 0x00, /* nop */
3449 0x09, 0x00, /* nop */
3450 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3451 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3454 /* Sebsequent entries in an absolute procedure linkage table look like
3457 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3459 0xd0, 0x04, /* mov.l 1f,r0 */
3460 0x60, 0x02, /* mov.l @r0,r0 */
3461 0xd1, 0x02, /* mov.l 0f,r1 */
3462 0x40, 0x2b, /* jmp @r0 */
3463 0x60, 0x13, /* mov r1,r0 */
3464 0xd1, 0x03, /* mov.l 2f,r1 */
3465 0x40, 0x2b, /* jmp @r0 */
3466 0x00, 0x09, /* nop */
3467 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3468 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3469 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3472 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3474 0x04, 0xd0, /* mov.l 1f,r0 */
3475 0x02, 0x60, /* mov.l @r0,r0 */
3476 0x02, 0xd1, /* mov.l 0f,r1 */
3477 0x2b, 0x40, /* jmp @r0 */
3478 0x13, 0x60, /* mov r1,r0 */
3479 0x03, 0xd1, /* mov.l 2f,r1 */
3480 0x2b, 0x40, /* jmp @r0 */
3481 0x09, 0x00, /* nop */
3482 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3483 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3484 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3487 /* Entries in a PIC procedure linkage table look like this. */
3489 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3491 0xd0, 0x04, /* mov.l 1f,r0 */
3492 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3493 0x40, 0x2b, /* jmp @r0 */
3494 0x00, 0x09, /* nop */
3495 0x50, 0xc2, /* mov.l @(8,r12),r0 */
3496 0xd1, 0x03, /* mov.l 2f,r1 */
3497 0x40, 0x2b, /* jmp @r0 */
3498 0x50, 0xc1, /* mov.l @(4,r12),r0 */
3499 0x00, 0x09, /* nop */
3500 0x00, 0x09, /* nop */
3501 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3502 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3505 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3507 0x04, 0xd0, /* mov.l 1f,r0 */
3508 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3509 0x2b, 0x40, /* jmp @r0 */
3510 0x09, 0x00, /* nop */
3511 0xc2, 0x50, /* mov.l @(8,r12),r0 */
3512 0x03, 0xd1, /* mov.l 2f,r1 */
3513 0x2b, 0x40, /* jmp @r0 */
3514 0xc1, 0x50, /* mov.l @(4,r12),r0 */
3515 0x09, 0x00, /* nop */
3516 0x09, 0x00, /* nop */
3517 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3518 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3521 #else /* These are the old style PLT entries. */
3522 static const bfd_byte elf_sh_plt0_entry_be
[PLT_ENTRY_SIZE
] =
3524 0xd0, 0x04, /* mov.l 1f,r0 */
3525 0xd2, 0x05, /* mov.l 2f,r2 */
3526 0x60, 0x02, /* mov.l @r0,r0 */
3527 0x62, 0x22, /* mov.l @r2,r2 */
3528 0x40, 0x2b, /* jmp @r0 */
3529 0xe0, 0x00, /* mov #0,r0 */
3530 0x00, 0x09, /* nop */
3531 0x00, 0x09, /* nop */
3532 0x00, 0x09, /* nop */
3533 0x00, 0x09, /* nop */
3534 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3535 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3538 static const bfd_byte elf_sh_plt0_entry_le
[PLT_ENTRY_SIZE
] =
3540 0x04, 0xd0, /* mov.l 1f,r0 */
3541 0x05, 0xd2, /* mov.l 2f,r2 */
3542 0x02, 0x60, /* mov.l @r0,r0 */
3543 0x22, 0x62, /* mov.l @r2,r2 */
3544 0x2b, 0x40, /* jmp @r0 */
3545 0x00, 0xe0, /* mov #0,r0 */
3546 0x09, 0x00, /* nop */
3547 0x09, 0x00, /* nop */
3548 0x09, 0x00, /* nop */
3549 0x09, 0x00, /* nop */
3550 0, 0, 0, 0, /* 1: replaced with address of .got.plt + 8. */
3551 0, 0, 0, 0, /* 2: replaced with address of .got.plt + 4. */
3554 /* Sebsequent entries in an absolute procedure linkage table look like
3557 static const bfd_byte elf_sh_plt_entry_be
[PLT_ENTRY_SIZE
] =
3559 0xd0, 0x04, /* mov.l 1f,r0 */
3560 0x60, 0x02, /* mov.l @r0,r0 */
3561 0xd2, 0x02, /* mov.l 0f,r2 */
3562 0x40, 0x2b, /* jmp @r0 */
3563 0x60, 0x23, /* mov r2,r0 */
3564 0xd1, 0x03, /* mov.l 2f,r1 */
3565 0x40, 0x2b, /* jmp @r0 */
3566 0x00, 0x09, /* nop */
3567 0, 0, 0, 0, /* 0: replaced with address of .PLT0. */
3568 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3569 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3572 static const bfd_byte elf_sh_plt_entry_le
[PLT_ENTRY_SIZE
] =
3574 0x04, 0xd0, /* mov.l 1f,r0 */
3575 0x02, 0x60, /* mov.l @r0,r0 */
3576 0x02, 0xd2, /* mov.l 0f,r2 */
3577 0x2b, 0x40, /* jmp @r0 */
3578 0x23, 0x60, /* mov r2,r0 */
3579 0x03, 0xd1, /* mov.l 2f,r1 */
3580 0x2b, 0x40, /* jmp @r0 */
3581 0x09, 0x00, /* nop */
3582 0, 0, 0, 0, /* 0: replaced with address of .PLT. */
3583 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3584 0, 0, 0, 0, /* 2: replaced with offset into relocation table. */
3587 /* Entries in a PIC procedure linkage table look like this. */
3589 static const bfd_byte elf_sh_pic_plt_entry_be
[PLT_ENTRY_SIZE
] =
3591 0xd0, 0x04, /* mov.l 1f,r0 */
3592 0x00, 0xce, /* mov.l @(r0,r12),r0 */
3593 0x40, 0x2b, /* jmp @r0 */
3594 0x00, 0x09, /* nop */
3595 0x50, 0xc2, /* 0: mov.l @(8,r12),r0 */
3596 0x52, 0xc1, /* 1: mov.l @(4,r12),r2 */
3597 0xd1, 0x02, /* mov.l 2f,r1 */
3598 0x40, 0x2b, /* jmp @r0 */
3599 0xe0, 0x00, /* mov #0,r0 ! shows the type of PLT. */
3600 0x00, 0x09, /* nop */
3601 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3602 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3605 static const bfd_byte elf_sh_pic_plt_entry_le
[PLT_ENTRY_SIZE
] =
3607 0x04, 0xd0, /* mov.l 1f,r0 */
3608 0xce, 0x00, /* mov.l @(r0,r12),r0 */
3609 0x2b, 0x40, /* jmp @r0 */
3610 0x09, 0x00, /* nop */
3611 0xc2, 0x50, /* 0: mov.l @(8,r12),r0 */
3612 0xc1, 0x52, /* 1: mov.l @(4,r12),r2 */
3613 0x02, 0xd1, /* mov.l 2f,r1 */
3614 0x2b, 0x40, /* jmp @r0 */
3615 0x00, 0xe0, /* mov #0,r0 ! shows the type of PLT. */
3616 0x09, 0x00, /* nop */
3617 0, 0, 0, 0, /* 1: replaced with address of this symbol in .got. */
3618 0, 0, 0, 0 /* 2: replaced with offset into relocation table. */
3620 #endif /* old style PLT entries. */
3622 static const bfd_byte
*elf_sh_plt0_entry
;
3623 static const bfd_byte
*elf_sh_plt_entry
;
3624 static const bfd_byte
*elf_sh_pic_plt_entry
;
3626 /* Return size of a PLT entry. */
3627 #define elf_sh_sizeof_plt(info) PLT_ENTRY_SIZE
3629 /* Return offset of the PLT0 address in an absolute PLT entry. */
3630 #define elf_sh_plt_plt0_offset(info) 16
3632 /* Return offset of the linker in PLT0 entry. */
3633 #define elf_sh_plt0_linker_offset(info) 20
3635 /* Return offset of the GOT id in PLT0 entry. */
3636 #define elf_sh_plt0_gotid_offset(info) 24
3638 /* Return offset of the temporary in PLT entry */
3639 #define elf_sh_plt_temp_offset(info) 8
3641 /* Return offset of the symbol in PLT entry. */
3642 #define elf_sh_plt_symbol_offset(info) 20
3644 /* Return offset of the relocation in PLT entry. */
3645 #define elf_sh_plt_reloc_offset(info) 24
3648 /* The sh linker needs to keep track of the number of relocs that it
3649 decides to copy as dynamic relocs in check_relocs for each symbol.
3650 This is so that it can later discard them if they are found to be
3651 unnecessary. We store the information in a field extending the
3652 regular ELF linker hash table. */
3654 struct elf_sh_dyn_relocs
3656 struct elf_sh_dyn_relocs
*next
;
3658 /* The input section of the reloc. */
3661 /* Total number of relocs copied for the input section. */
3662 bfd_size_type count
;
3664 /* Number of pc-relative relocs copied for the input section. */
3665 bfd_size_type pc_count
;
3668 /* sh ELF linker hash entry. */
3670 struct elf_sh_link_hash_entry
3672 struct elf_link_hash_entry root
;
3674 #ifdef INCLUDE_SHMEDIA
3677 bfd_signed_vma refcount
;
3682 /* Track dynamic relocs copied for this symbol. */
3683 struct elf_sh_dyn_relocs
*dyn_relocs
;
3685 bfd_signed_vma gotplt_refcount
;
3688 GOT_UNKNOWN
= 0, GOT_NORMAL
, GOT_TLS_GD
, GOT_TLS_IE
3692 #define sh_elf_hash_entry(ent) ((struct elf_sh_link_hash_entry *)(ent))
3694 struct sh_elf_obj_tdata
3696 struct elf_obj_tdata root
;
3698 /* tls_type for each local got entry. */
3699 char *local_got_tls_type
;
3702 #define sh_elf_tdata(abfd) \
3703 ((struct sh_elf_obj_tdata *) (abfd)->tdata.any)
3705 #define sh_elf_local_got_tls_type(abfd) \
3706 (sh_elf_tdata (abfd)->local_got_tls_type)
3708 /* Override the generic function because we need to store sh_elf_obj_tdata
3709 as the specific tdata. */
3712 sh_elf_mkobject (bfd
*abfd
)
3714 bfd_size_type amt
= sizeof (struct sh_elf_obj_tdata
);
3715 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
3716 if (abfd
->tdata
.any
== NULL
)
3721 /* sh ELF linker hash table. */
3723 struct elf_sh_link_hash_table
3725 struct elf_link_hash_table root
;
3727 /* Short-cuts to get to dynamic linker sections. */
3736 /* Small local sym to section mapping cache. */
3737 struct sym_sec_cache sym_sec
;
3739 /* A counter or offset to track a TLS got entry. */
3742 bfd_signed_vma refcount
;
3747 /* Traverse an sh ELF linker hash table. */
3749 #define sh_elf_link_hash_traverse(table, func, info) \
3750 (elf_link_hash_traverse \
3752 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
3755 /* Get the sh ELF linker hash table from a link_info structure. */
3757 #define sh_elf_hash_table(p) \
3758 ((struct elf_sh_link_hash_table *) ((p)->hash))
3760 /* Create an entry in an sh ELF linker hash table. */
3762 static struct bfd_hash_entry
*
3763 sh_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
3764 struct bfd_hash_table
*table
,
3767 struct elf_sh_link_hash_entry
*ret
=
3768 (struct elf_sh_link_hash_entry
*) entry
;
3770 /* Allocate the structure if it has not already been allocated by a
3772 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3773 ret
= ((struct elf_sh_link_hash_entry
*)
3774 bfd_hash_allocate (table
,
3775 sizeof (struct elf_sh_link_hash_entry
)));
3776 if (ret
== (struct elf_sh_link_hash_entry
*) NULL
)
3777 return (struct bfd_hash_entry
*) ret
;
3779 /* Call the allocation method of the superclass. */
3780 ret
= ((struct elf_sh_link_hash_entry
*)
3781 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
3783 if (ret
!= (struct elf_sh_link_hash_entry
*) NULL
)
3785 ret
->dyn_relocs
= NULL
;
3786 ret
->gotplt_refcount
= 0;
3787 #ifdef INCLUDE_SHMEDIA
3788 ret
->datalabel_got
.refcount
= ret
->root
.got
.refcount
;
3790 ret
->tls_type
= GOT_UNKNOWN
;
3793 return (struct bfd_hash_entry
*) ret
;
3796 /* Create an sh ELF linker hash table. */
3798 static struct bfd_link_hash_table
*
3799 sh_elf_link_hash_table_create (bfd
*abfd
)
3801 struct elf_sh_link_hash_table
*ret
;
3802 bfd_size_type amt
= sizeof (struct elf_sh_link_hash_table
);
3804 ret
= (struct elf_sh_link_hash_table
*) bfd_malloc (amt
);
3805 if (ret
== (struct elf_sh_link_hash_table
*) NULL
)
3808 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
3809 sh_elf_link_hash_newfunc
))
3816 ret
->sgotplt
= NULL
;
3817 ret
->srelgot
= NULL
;
3819 ret
->srelplt
= NULL
;
3820 ret
->sdynbss
= NULL
;
3821 ret
->srelbss
= NULL
;
3822 ret
->sym_sec
.abfd
= NULL
;
3823 ret
->tls_ldm_got
.refcount
= 0;
3825 return &ret
->root
.root
;
3828 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
3829 shortcuts to them in our hash table. */
3832 create_got_section (bfd
*dynobj
, struct bfd_link_info
*info
)
3834 struct elf_sh_link_hash_table
*htab
;
3836 if (! _bfd_elf_create_got_section (dynobj
, info
))
3839 htab
= sh_elf_hash_table (info
);
3840 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
3841 htab
->sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
3842 if (! htab
->sgot
|| ! htab
->sgotplt
)
3845 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
3846 if (htab
->srelgot
== NULL
3847 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
3852 | SEC_LINKER_CREATED
3854 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 2))
3859 /* Create dynamic sections when linking against a dynamic object. */
3862 sh_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
3864 struct elf_sh_link_hash_table
*htab
;
3865 flagword flags
, pltflags
;
3866 register asection
*s
;
3867 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
3870 switch (bed
->s
->arch_size
)
3881 bfd_set_error (bfd_error_bad_value
);
3885 htab
= sh_elf_hash_table (info
);
3886 if (htab
->root
.dynamic_sections_created
)
3889 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
3890 .rel[a].bss sections. */
3892 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3893 | SEC_LINKER_CREATED
);
3896 pltflags
|= SEC_CODE
;
3897 if (bed
->plt_not_loaded
)
3898 pltflags
&= ~ (SEC_LOAD
| SEC_HAS_CONTENTS
);
3899 if (bed
->plt_readonly
)
3900 pltflags
|= SEC_READONLY
;
3902 s
= bfd_make_section (abfd
, ".plt");
3905 || ! bfd_set_section_flags (abfd
, s
, pltflags
)
3906 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
3909 if (bed
->want_plt_sym
)
3911 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
3913 struct elf_link_hash_entry
*h
;
3914 struct bfd_link_hash_entry
*bh
= NULL
;
3916 if (! (_bfd_generic_link_add_one_symbol
3917 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
,
3918 (bfd_vma
) 0, (const char *) NULL
, FALSE
,
3919 get_elf_backend_data (abfd
)->collect
, &bh
)))
3922 h
= (struct elf_link_hash_entry
*) bh
;
3923 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3924 h
->type
= STT_OBJECT
;
3927 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
3931 s
= bfd_make_section (abfd
,
3932 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt");
3935 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3936 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3939 if (htab
->sgot
== NULL
3940 && !create_got_section (abfd
, info
))
3944 const char *secname
;
3949 for (sec
= abfd
->sections
; sec
; sec
= sec
->next
)
3951 secflags
= bfd_get_section_flags (abfd
, sec
);
3952 if ((secflags
& (SEC_DATA
| SEC_LINKER_CREATED
))
3953 || ((secflags
& SEC_HAS_CONTENTS
) != SEC_HAS_CONTENTS
))
3955 secname
= bfd_get_section_name (abfd
, sec
);
3956 relname
= (char *) bfd_malloc ((bfd_size_type
) strlen (secname
) + 6);
3957 strcpy (relname
, ".rela");
3958 strcat (relname
, secname
);
3959 if (bfd_get_section_by_name (abfd
, secname
))
3961 s
= bfd_make_section (abfd
, relname
);
3963 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
3964 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
3969 if (bed
->want_dynbss
)
3971 /* The .dynbss section is a place to put symbols which are defined
3972 by dynamic objects, are referenced by regular objects, and are
3973 not functions. We must allocate space for them in the process
3974 image and use a R_*_COPY reloc to tell the dynamic linker to
3975 initialize them at run time. The linker script puts the .dynbss
3976 section into the .bss section of the final image. */
3977 s
= bfd_make_section (abfd
, ".dynbss");
3980 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
3983 /* The .rel[a].bss section holds copy relocs. This section is not
3984 normally needed. We need to create it here, though, so that the
3985 linker will map it to an output section. We can't just create it
3986 only if we need it, because we will not know whether we need it
3987 until we have seen all the input files, and the first time the
3988 main linker code calls BFD after examining all the input files
3989 (size_dynamic_sections) the input sections have already been
3990 mapped to the output sections. If the section turns out not to
3991 be needed, we can discard it later. We will never need this
3992 section when generating a shared object, since they do not use
3996 s
= bfd_make_section (abfd
,
3997 (bed
->default_use_rela_p
3998 ? ".rela.bss" : ".rel.bss"));
4001 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
4002 || ! bfd_set_section_alignment (abfd
, s
, ptralign
))
4010 /* Adjust a symbol defined by a dynamic object and referenced by a
4011 regular object. The current definition is in some section of the
4012 dynamic object, but we're not including those sections. We have to
4013 change the definition to something the rest of the link can
4017 sh_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
4018 struct elf_link_hash_entry
*h
)
4020 struct elf_sh_link_hash_table
*htab
;
4021 struct elf_sh_link_hash_entry
*eh
;
4022 struct elf_sh_dyn_relocs
*p
;
4024 unsigned int power_of_two
;
4026 htab
= sh_elf_hash_table (info
);
4028 /* Make sure we know what is going on here. */
4029 BFD_ASSERT (htab
->root
.dynobj
!= NULL
4030 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
4031 || h
->weakdef
!= NULL
4032 || ((h
->elf_link_hash_flags
4033 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4034 && (h
->elf_link_hash_flags
4035 & ELF_LINK_HASH_REF_REGULAR
) != 0
4036 && (h
->elf_link_hash_flags
4037 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
4039 /* If this is a function, put it in the procedure linkage table. We
4040 will fill in the contents of the procedure linkage table later,
4041 when we know the address of the .got section. */
4042 if (h
->type
== STT_FUNC
4043 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4045 if (h
->plt
.refcount
<= 0
4046 || SYMBOL_CALLS_LOCAL (info
, h
)
4047 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4048 && h
->root
.type
== bfd_link_hash_undefweak
))
4050 /* This case can occur if we saw a PLT reloc in an input
4051 file, but the symbol was never referred to by a dynamic
4052 object. In such a case, we don't actually need to build
4053 a procedure linkage table, and we can just do a REL32
4055 h
->plt
.offset
= (bfd_vma
) -1;
4056 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4062 h
->plt
.offset
= (bfd_vma
) -1;
4064 /* If this is a weak symbol, and there is a real definition, the
4065 processor independent code will have arranged for us to see the
4066 real definition first, and we can just use the same value. */
4067 if (h
->weakdef
!= NULL
)
4069 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
4070 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
4071 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
4072 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
4073 if (info
->nocopyreloc
)
4074 h
->elf_link_hash_flags
4075 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
4076 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
4080 /* This is a reference to a symbol defined by a dynamic object which
4081 is not a function. */
4083 /* If we are creating a shared library, we must presume that the
4084 only references to the symbol are via the global offset table.
4085 For such cases we need not do anything here; the relocations will
4086 be handled correctly by relocate_section. */
4090 /* If there are no references to this symbol that do not use the
4091 GOT, we don't need to generate a copy reloc. */
4092 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
4095 /* If -z nocopyreloc was given, we won't generate them either. */
4096 if (info
->nocopyreloc
)
4098 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
4102 eh
= (struct elf_sh_link_hash_entry
*) h
;
4103 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4105 s
= p
->sec
->output_section
;
4106 if (s
!= NULL
&& (s
->flags
& (SEC_READONLY
| SEC_HAS_CONTENTS
)) != 0)
4110 /* If we didn't find any dynamic relocs in sections which needs the
4111 copy reloc, then we'll be keeping the dynamic relocs and avoiding
4115 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
4119 /* We must allocate the symbol in our .dynbss section, which will
4120 become part of the .bss section of the executable. There will be
4121 an entry for this symbol in the .dynsym section. The dynamic
4122 object will contain position independent code, so all references
4123 from the dynamic object to this symbol will go through the global
4124 offset table. The dynamic linker will use the .dynsym entry to
4125 determine the address it must put in the global offset table, so
4126 both the dynamic object and the regular object will refer to the
4127 same memory location for the variable. */
4130 BFD_ASSERT (s
!= NULL
);
4132 /* We must generate a R_SH_COPY reloc to tell the dynamic linker to
4133 copy the initial value out of the dynamic object and into the
4134 runtime process image. We need to remember the offset into the
4135 .rela.bss section we are going to use. */
4136 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
4140 srel
= htab
->srelbss
;
4141 BFD_ASSERT (srel
!= NULL
);
4142 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
4143 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
4146 /* We need to figure out the alignment required for this symbol. I
4147 have no idea how ELF linkers handle this. */
4148 power_of_two
= bfd_log2 (h
->size
);
4149 if (power_of_two
> 3)
4152 /* Apply the required alignment. */
4153 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
4154 if (power_of_two
> bfd_get_section_alignment (htab
->root
.dynobj
, s
))
4156 if (! bfd_set_section_alignment (htab
->root
.dynobj
, s
, power_of_two
))
4160 /* Define the symbol as being at this point in the section. */
4161 h
->root
.u
.def
.section
= s
;
4162 h
->root
.u
.def
.value
= s
->_raw_size
;
4164 /* Increment the section size to make room for the symbol. */
4165 s
->_raw_size
+= h
->size
;
4170 /* Allocate space in .plt, .got and associated reloc sections for
4174 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
4176 struct bfd_link_info
*info
;
4177 struct elf_sh_link_hash_table
*htab
;
4178 struct elf_sh_link_hash_entry
*eh
;
4179 struct elf_sh_dyn_relocs
*p
;
4181 if (h
->root
.type
== bfd_link_hash_indirect
)
4184 if (h
->root
.type
== bfd_link_hash_warning
)
4185 /* When warning symbols are created, they **replace** the "real"
4186 entry in the hash table, thus we never get to see the real
4187 symbol in a hash traversal. So look at it now. */
4188 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4190 info
= (struct bfd_link_info
*) inf
;
4191 htab
= sh_elf_hash_table (info
);
4193 eh
= (struct elf_sh_link_hash_entry
*) h
;
4194 if ((h
->got
.refcount
> 0
4195 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
4196 && eh
->gotplt_refcount
> 0)
4198 /* The symbol has been forced local, or we have some direct got refs,
4199 so treat all the gotplt refs as got refs. */
4200 h
->got
.refcount
+= eh
->gotplt_refcount
;
4201 if (h
->plt
.refcount
>= eh
->gotplt_refcount
)
4202 h
->plt
.refcount
-= eh
->gotplt_refcount
;
4205 if (htab
->root
.dynamic_sections_created
4206 && h
->plt
.refcount
> 0
4207 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4208 || h
->root
.type
!= bfd_link_hash_undefweak
))
4210 /* Make sure this symbol is output as a dynamic symbol.
4211 Undefined weak syms won't yet be marked as dynamic. */
4212 if (h
->dynindx
== -1
4213 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4215 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4220 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
4222 asection
*s
= htab
->splt
;
4224 /* If this is the first .plt entry, make room for the special
4226 if (s
->_raw_size
== 0)
4227 s
->_raw_size
+= PLT_ENTRY_SIZE
;
4229 h
->plt
.offset
= s
->_raw_size
;
4231 /* If this symbol is not defined in a regular file, and we are
4232 not generating a shared library, then set the symbol to this
4233 location in the .plt. This is required to make function
4234 pointers compare as equal between the normal executable and
4235 the shared library. */
4237 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4239 h
->root
.u
.def
.section
= s
;
4240 h
->root
.u
.def
.value
= h
->plt
.offset
;
4243 /* Make room for this entry. */
4244 s
->_raw_size
+= PLT_ENTRY_SIZE
;
4246 /* We also need to make an entry in the .got.plt section, which
4247 will be placed in the .got section by the linker script. */
4248 htab
->sgotplt
->_raw_size
+= 4;
4250 /* We also need to make an entry in the .rel.plt section. */
4251 htab
->srelplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
4255 h
->plt
.offset
= (bfd_vma
) -1;
4256 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4261 h
->plt
.offset
= (bfd_vma
) -1;
4262 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4265 if (h
->got
.refcount
> 0)
4269 int tls_type
= sh_elf_hash_entry (h
)->tls_type
;
4271 /* Make sure this symbol is output as a dynamic symbol.
4272 Undefined weak syms won't yet be marked as dynamic. */
4273 if (h
->dynindx
== -1
4274 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4276 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4281 h
->got
.offset
= s
->_raw_size
;
4283 /* R_SH_TLS_GD needs 2 consecutive GOT slots. */
4284 if (tls_type
== GOT_TLS_GD
)
4286 dyn
= htab
->root
.dynamic_sections_created
;
4287 /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
4288 R_SH_TLS_GD needs one if local symbol and two if global. */
4289 if ((tls_type
== GOT_TLS_GD
&& h
->dynindx
== -1)
4290 || (tls_type
== GOT_TLS_IE
&& dyn
))
4291 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4292 else if (tls_type
== GOT_TLS_GD
)
4293 htab
->srelgot
->_raw_size
+= 2 * sizeof (Elf32_External_Rela
);
4294 else if ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4295 || h
->root
.type
!= bfd_link_hash_undefweak
)
4297 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
4298 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4301 h
->got
.offset
= (bfd_vma
) -1;
4303 #ifdef INCLUDE_SHMEDIA
4304 if (eh
->datalabel_got
.refcount
> 0)
4309 /* Make sure this symbol is output as a dynamic symbol.
4310 Undefined weak syms won't yet be marked as dynamic. */
4311 if (h
->dynindx
== -1
4312 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4314 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4319 eh
->datalabel_got
.offset
= s
->_raw_size
;
4321 dyn
= htab
->root
.dynamic_sections_created
;
4322 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
))
4323 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4326 eh
->datalabel_got
.offset
= (bfd_vma
) -1;
4329 if (eh
->dyn_relocs
== NULL
)
4332 /* In the shared -Bsymbolic case, discard space allocated for
4333 dynamic pc-relative relocs against symbols which turn out to be
4334 defined in regular objects. For the normal shared case, discard
4335 space for pc-relative relocs that have become local due to symbol
4336 visibility changes. */
4340 if (SYMBOL_CALLS_LOCAL (info
, h
))
4342 struct elf_sh_dyn_relocs
**pp
;
4344 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
4346 p
->count
-= p
->pc_count
;
4355 /* Also discard relocs on undefined weak syms with non-default
4357 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4358 && h
->root
.type
== bfd_link_hash_undefweak
)
4359 eh
->dyn_relocs
= NULL
;
4363 /* For the non-shared case, discard space for relocs against
4364 symbols which turn out to need copy relocs or are not
4367 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
4368 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4369 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4370 || (htab
->root
.dynamic_sections_created
4371 && (h
->root
.type
== bfd_link_hash_undefweak
4372 || h
->root
.type
== bfd_link_hash_undefined
))))
4374 /* Make sure this symbol is output as a dynamic symbol.
4375 Undefined weak syms won't yet be marked as dynamic. */
4376 if (h
->dynindx
== -1
4377 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4379 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4383 /* If that succeeded, we know we'll be keeping all the
4385 if (h
->dynindx
!= -1)
4389 eh
->dyn_relocs
= NULL
;
4394 /* Finally, allocate space. */
4395 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4397 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
4398 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
4404 /* Find any dynamic relocs that apply to read-only sections. */
4407 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
4409 struct elf_sh_link_hash_entry
*eh
;
4410 struct elf_sh_dyn_relocs
*p
;
4412 if (h
->root
.type
== bfd_link_hash_warning
)
4413 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4415 eh
= (struct elf_sh_link_hash_entry
*) h
;
4416 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4418 asection
*s
= p
->sec
->output_section
;
4420 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4422 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4424 info
->flags
|= DF_TEXTREL
;
4426 /* Not an error, just cut short the traversal. */
4433 /* Set the sizes of the dynamic sections. */
4436 sh_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
4437 struct bfd_link_info
*info
)
4439 struct elf_sh_link_hash_table
*htab
;
4445 htab
= sh_elf_hash_table (info
);
4446 dynobj
= htab
->root
.dynobj
;
4447 BFD_ASSERT (dynobj
!= NULL
);
4449 if (htab
->root
.dynamic_sections_created
)
4451 /* Set the contents of the .interp section to the interpreter. */
4452 if (info
->executable
)
4454 s
= bfd_get_section_by_name (dynobj
, ".interp");
4455 BFD_ASSERT (s
!= NULL
);
4456 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4457 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4461 /* Set up .got offsets for local syms, and space for local dynamic
4463 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4465 bfd_signed_vma
*local_got
;
4466 bfd_signed_vma
*end_local_got
;
4467 char *local_tls_type
;
4468 bfd_size_type locsymcount
;
4469 Elf_Internal_Shdr
*symtab_hdr
;
4472 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
4475 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4477 struct elf_sh_dyn_relocs
*p
;
4479 for (p
= ((struct elf_sh_dyn_relocs
*)
4480 elf_section_data (s
)->local_dynrel
);
4484 if (! bfd_is_abs_section (p
->sec
)
4485 && bfd_is_abs_section (p
->sec
->output_section
))
4487 /* Input section has been discarded, either because
4488 it is a copy of a linkonce section or due to
4489 linker script /DISCARD/, so we'll be discarding
4492 else if (p
->count
!= 0)
4494 srel
= elf_section_data (p
->sec
)->sreloc
;
4495 srel
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
4496 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
4497 info
->flags
|= DF_TEXTREL
;
4502 local_got
= elf_local_got_refcounts (ibfd
);
4506 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4507 locsymcount
= symtab_hdr
->sh_info
;
4508 #ifdef INCLUDE_SHMEDIA
4509 /* Count datalabel local GOT. */
4512 end_local_got
= local_got
+ locsymcount
;
4513 local_tls_type
= sh_elf_local_got_tls_type (ibfd
);
4515 srel
= htab
->srelgot
;
4516 for (; local_got
< end_local_got
; ++local_got
)
4520 *local_got
= s
->_raw_size
;
4522 if (*local_tls_type
== GOT_TLS_GD
)
4525 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
4528 *local_got
= (bfd_vma
) -1;
4533 if (htab
->tls_ldm_got
.refcount
> 0)
4535 /* Allocate 2 got entries and 1 dynamic reloc for R_SH_TLS_LD_32
4537 htab
->tls_ldm_got
.offset
= htab
->sgot
->_raw_size
;
4538 htab
->sgot
->_raw_size
+= 8;
4539 htab
->srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
4542 htab
->tls_ldm_got
.offset
= -1;
4544 /* Allocate global sym .plt and .got entries, and space for global
4545 sym dynamic relocs. */
4546 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, info
);
4548 /* We now have determined the sizes of the various dynamic sections.
4549 Allocate memory for them. */
4551 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4553 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4558 || s
== htab
->sgotplt
)
4560 /* Strip this section if we don't need it; see the
4563 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4565 if (s
->_raw_size
!= 0 && s
!= htab
->srelplt
)
4568 /* We use the reloc_count field as a counter if we need
4569 to copy relocs into the output file. */
4574 /* It's not one of our sections, so don't allocate space. */
4578 if (s
->_raw_size
== 0)
4580 /* If we don't need this section, strip it from the
4581 output file. This is mostly to handle .rela.bss and
4582 .rela.plt. We must create both sections in
4583 create_dynamic_sections, because they must be created
4584 before the linker maps input sections to output
4585 sections. The linker does that before
4586 adjust_dynamic_symbol is called, and it is that
4587 function which decides whether anything needs to go
4588 into these sections. */
4590 _bfd_strip_section_from_output (info
, s
);
4594 /* Allocate memory for the section contents. We use bfd_zalloc
4595 here in case unused entries are not reclaimed before the
4596 section's contents are written out. This should not happen,
4597 but this way if it does, we get a R_SH_NONE reloc instead
4599 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4600 if (s
->contents
== NULL
)
4604 if (htab
->root
.dynamic_sections_created
)
4606 /* Add some entries to the .dynamic section. We fill in the
4607 values later, in sh_elf_finish_dynamic_sections, but we
4608 must add the entries now so that we get the correct size for
4609 the .dynamic section. The DT_DEBUG entry is filled in by the
4610 dynamic linker and used by the debugger. */
4611 #define add_dynamic_entry(TAG, VAL) \
4612 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4614 if (info
->executable
)
4616 if (! add_dynamic_entry (DT_DEBUG
, 0))
4620 if (htab
->splt
->_raw_size
!= 0)
4622 if (! add_dynamic_entry (DT_PLTGOT
, 0)
4623 || ! add_dynamic_entry (DT_PLTRELSZ
, 0)
4624 || ! add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4625 || ! add_dynamic_entry (DT_JMPREL
, 0))
4631 if (! add_dynamic_entry (DT_RELA
, 0)
4632 || ! add_dynamic_entry (DT_RELASZ
, 0)
4633 || ! add_dynamic_entry (DT_RELAENT
,
4634 sizeof (Elf32_External_Rela
)))
4637 /* If any dynamic relocs apply to a read-only section,
4638 then we need a DT_TEXTREL entry. */
4639 if ((info
->flags
& DF_TEXTREL
) == 0)
4640 elf_link_hash_traverse (&htab
->root
, readonly_dynrelocs
, info
);
4642 if ((info
->flags
& DF_TEXTREL
) != 0)
4644 if (! add_dynamic_entry (DT_TEXTREL
, 0))
4649 #undef add_dynamic_entry
4654 /* Relocate an SH ELF section. */
4657 sh_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
4658 bfd
*input_bfd
, asection
*input_section
,
4659 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
4660 Elf_Internal_Sym
*local_syms
,
4661 asection
**local_sections
)
4663 struct elf_sh_link_hash_table
*htab
;
4664 Elf_Internal_Shdr
*symtab_hdr
;
4665 struct elf_link_hash_entry
**sym_hashes
;
4666 Elf_Internal_Rela
*rel
, *relend
;
4668 bfd_vma
*local_got_offsets
;
4675 htab
= sh_elf_hash_table (info
);
4676 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4677 sym_hashes
= elf_sym_hashes (input_bfd
);
4678 dynobj
= htab
->root
.dynobj
;
4679 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4682 sgotplt
= htab
->sgotplt
;
4688 relend
= relocs
+ input_section
->reloc_count
;
4689 for (; rel
< relend
; rel
++)
4692 reloc_howto_type
*howto
;
4693 unsigned long r_symndx
;
4694 Elf_Internal_Sym
*sym
;
4696 struct elf_link_hash_entry
*h
;
4698 bfd_vma addend
= (bfd_vma
) 0;
4699 bfd_reloc_status_type r
;
4700 int seen_stt_datalabel
= 0;
4704 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4706 r_type
= ELF32_R_TYPE (rel
->r_info
);
4708 /* Many of the relocs are only used for relaxing, and are
4709 handled entirely by the relaxation code. */
4710 if (r_type
>= (int) R_SH_GNU_VTINHERIT
4711 && r_type
<= (int) R_SH_LABEL
)
4713 if (r_type
== (int) R_SH_NONE
)
4717 || r_type
>= R_SH_max
4718 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
4719 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
)
4720 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_3
4721 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_3
)
4722 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_4
4723 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_4
)
4724 || ( r_type
>= (int) R_SH_FIRST_INVALID_RELOC_5
4725 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_5
)
4726 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC_2
4727 && r_type
<= (int) R_SH_LAST_INVALID_RELOC_2
))
4729 bfd_set_error (bfd_error_bad_value
);
4733 howto
= sh_elf_howto_table
+ r_type
;
4735 /* For relocs that aren't partial_inplace, we get the addend from
4737 if (! howto
->partial_inplace
)
4738 addend
= rel
->r_addend
;
4743 if (r_symndx
< symtab_hdr
->sh_info
)
4745 sym
= local_syms
+ r_symndx
;
4746 sec
= local_sections
[r_symndx
];
4747 relocation
= (sec
->output_section
->vma
4748 + sec
->output_offset
4750 /* A local symbol never has STO_SH5_ISA32, so we don't need
4751 datalabel processing here. Make sure this does not change
4753 if ((sym
->st_other
& STO_SH5_ISA32
) != 0)
4754 ((*info
->callbacks
->reloc_dangerous
)
4756 _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
4757 input_bfd
, input_section
, rel
->r_offset
));
4758 if (info
->relocatable
)
4760 /* This is a relocatable link. We don't have to change
4761 anything, unless the reloc is against a section symbol,
4762 in which case we have to adjust according to where the
4763 section symbol winds up in the output section. */
4764 sym
= local_syms
+ r_symndx
;
4765 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4767 if (! howto
->partial_inplace
)
4769 /* For relocations with the addend in the
4770 relocation, we need just to update the addend.
4771 All real relocs are of type partial_inplace; this
4772 code is mostly for completeness. */
4773 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
4778 /* Relocs of type partial_inplace need to pick up the
4779 contents in the contents and add the offset resulting
4780 from the changed location of the section symbol.
4781 Using _bfd_final_link_relocate (e.g. goto
4782 final_link_relocate) here would be wrong, because
4783 relocations marked pc_relative would get the current
4784 location subtracted, and we must only do that at the
4786 r
= _bfd_relocate_contents (howto
, input_bfd
,
4789 contents
+ rel
->r_offset
);
4790 goto relocation_done
;
4795 else if (! howto
->partial_inplace
)
4797 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4798 addend
= rel
->r_addend
;
4800 else if ((sec
->flags
& SEC_MERGE
)
4801 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4805 if (howto
->rightshift
|| howto
->src_mask
!= 0xffffffff)
4807 (*_bfd_error_handler
)
4808 (_("%s(%s+0x%lx): %s relocation against SEC_MERGE section"),
4809 bfd_archive_filename (input_bfd
),
4810 bfd_get_section_name (input_bfd
, input_section
),
4811 (long) rel
->r_offset
, howto
->name
);
4815 addend
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
4818 _bfd_elf_rel_local_sym (output_bfd
, sym
, &msec
, addend
)
4820 addend
+= msec
->output_section
->vma
+ msec
->output_offset
;
4821 bfd_put_32 (input_bfd
, addend
, contents
+ rel
->r_offset
);
4827 /* FIXME: Ought to make use of the RELOC_FOR_GLOBAL_SYMBOL macro. */
4829 /* Section symbol are never (?) placed in the hash table, so
4830 we can just ignore hash relocations when creating a
4831 relocatable object file. */
4832 if (info
->relocatable
)
4835 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4836 while (h
->root
.type
== bfd_link_hash_indirect
4837 || h
->root
.type
== bfd_link_hash_warning
)
4839 #ifdef INCLUDE_SHMEDIA
4840 /* If the reference passes a symbol marked with
4841 STT_DATALABEL, then any STO_SH5_ISA32 on the final value
4843 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
4845 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4847 if (h
->root
.type
== bfd_link_hash_defined
4848 || h
->root
.type
== bfd_link_hash_defweak
)
4852 dyn
= htab
->root
.dynamic_sections_created
;
4853 sec
= h
->root
.u
.def
.section
;
4854 /* In these cases, we don't need the relocation value.
4855 We check specially because in some obscure cases
4856 sec->output_section will be NULL. */
4857 if (r_type
== R_SH_GOTPC
4858 || r_type
== R_SH_GOTPC_LOW16
4859 || r_type
== R_SH_GOTPC_MEDLOW16
4860 || r_type
== R_SH_GOTPC_MEDHI16
4861 || r_type
== R_SH_GOTPC_HI16
4862 || ((r_type
== R_SH_PLT32
4863 || r_type
== R_SH_PLT_LOW16
4864 || r_type
== R_SH_PLT_MEDLOW16
4865 || r_type
== R_SH_PLT_MEDHI16
4866 || r_type
== R_SH_PLT_HI16
)
4867 && h
->plt
.offset
!= (bfd_vma
) -1)
4868 || ((r_type
== R_SH_GOT32
4869 || r_type
== R_SH_GOT_LOW16
4870 || r_type
== R_SH_GOT_MEDLOW16
4871 || r_type
== R_SH_GOT_MEDHI16
4872 || r_type
== R_SH_GOT_HI16
)
4873 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
4875 || (! info
->symbolic
&& h
->dynindx
!= -1)
4876 || (h
->elf_link_hash_flags
4877 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
4878 /* The cases above are those in which relocation is
4879 overwritten in the switch block below. The cases
4880 below are those in which we must defer relocation
4881 to run-time, because we can't resolve absolute
4882 addresses when creating a shared library. */
4884 && ((! info
->symbolic
&& h
->dynindx
!= -1)
4885 || (h
->elf_link_hash_flags
4886 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
4887 && ((r_type
== R_SH_DIR32
4888 && (h
->elf_link_hash_flags
4889 & ELF_LINK_FORCED_LOCAL
) == 0)
4890 || r_type
== R_SH_REL32
)
4891 && ((input_section
->flags
& SEC_ALLOC
) != 0
4892 /* DWARF will emit R_SH_DIR32 relocations in its
4893 sections against symbols defined externally
4894 in shared libraries. We can't do anything
4896 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
4897 && (h
->elf_link_hash_flags
4898 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0)))
4899 /* Dynamic relocs are not propagated for SEC_DEBUGGING
4900 sections because such sections are not SEC_ALLOC and
4901 thus ld.so will not process them. */
4902 || (sec
->output_section
== NULL
4903 && ((input_section
->flags
& SEC_DEBUGGING
) != 0
4904 && (h
->elf_link_hash_flags
4905 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
4906 || (sec
->output_section
== NULL
4907 && (sh_elf_hash_entry (h
)->tls_type
== GOT_TLS_IE
4908 || sh_elf_hash_entry (h
)->tls_type
== GOT_TLS_GD
)))
4910 else if (sec
->output_section
== NULL
)
4912 (*_bfd_error_handler
)
4913 (_("%s: unresolvable relocation against symbol `%s' from %s section"),
4914 bfd_archive_filename (input_bfd
), h
->root
.root
.string
,
4915 bfd_get_section_name (input_bfd
, input_section
));
4919 relocation
= ((h
->root
.u
.def
.value
4920 + sec
->output_section
->vma
4921 + sec
->output_offset
)
4922 /* A STO_SH5_ISA32 causes a "bitor 1" to the
4923 symbol value, unless we've seen
4924 STT_DATALABEL on the way to it. */
4925 | ((h
->other
& STO_SH5_ISA32
) != 0
4926 && ! seen_stt_datalabel
));
4928 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4930 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
4931 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4935 if (! info
->callbacks
->undefined_symbol
4936 (info
, h
->root
.root
.string
, input_bfd
,
4937 input_section
, rel
->r_offset
,
4938 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
4939 || ELF_ST_VISIBILITY (h
->other
))))
4945 switch ((int) r_type
)
4947 final_link_relocate
:
4948 /* COFF relocs don't use the addend. The addend is used for
4949 R_SH_DIR32 to be compatible with other compilers. */
4950 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
4951 contents
, rel
->r_offset
,
4952 relocation
, addend
);
4956 goto final_link_relocate
;
4961 /* If the reloc is against the start of this section, then
4962 the assembler has already taken care of it and the reloc
4963 is here only to assist in relaxing. If the reloc is not
4964 against the start of this section, then it's against an
4965 external symbol and we must deal with it ourselves. */
4966 if (input_section
->output_section
->vma
+ input_section
->output_offset
4969 int disp
= (relocation
4970 - input_section
->output_section
->vma
4971 - input_section
->output_offset
4977 case R_SH_DIR8WPZ
: mask
= 1; break;
4978 case R_SH_DIR8WPL
: mask
= 3; break;
4979 default: mask
= 0; break;
4983 ((*_bfd_error_handler
)
4984 (_("%s: 0x%lx: fatal: unaligned branch target for relax-support relocation"),
4985 bfd_archive_filename (input_section
->owner
),
4986 (unsigned long) rel
->r_offset
));
4987 bfd_set_error (bfd_error_bad_value
);
4991 goto final_link_relocate
;
4997 #ifdef INCLUDE_SHMEDIA
4998 if (shmedia_prepare_reloc (info
, input_bfd
, input_section
,
4999 contents
, rel
, &relocation
))
5000 goto final_link_relocate
;
5002 bfd_set_error (bfd_error_bad_value
);
5010 goto final_link_relocate
;
5016 ((*_bfd_error_handler
)
5017 (_("%s: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
5018 bfd_archive_filename (input_section
->owner
),
5019 (unsigned long) rel
->r_offset
, howto
->name
,
5020 (unsigned long)relocation
));
5021 bfd_set_error (bfd_error_bad_value
);
5024 goto final_link_relocate
;
5031 ((*_bfd_error_handler
)
5032 (_("%s: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
5033 bfd_archive_filename (input_section
->owner
),
5034 (unsigned long) rel
->r_offset
, howto
->name
,
5035 (unsigned long)relocation
));
5036 bfd_set_error (bfd_error_bad_value
);
5039 goto final_link_relocate
;
5042 if ((signed int)relocation
< -32
5043 || (signed int)relocation
> 32)
5045 ((*_bfd_error_handler
)
5046 (_("%s: 0x%lx: fatal: R_SH_PSHA relocation %d not in range -32..32"),
5047 bfd_archive_filename (input_section
->owner
),
5048 (unsigned long) rel
->r_offset
,
5049 (unsigned long)relocation
));
5050 bfd_set_error (bfd_error_bad_value
);
5053 goto final_link_relocate
;
5056 if ((signed int)relocation
< -16
5057 || (signed int)relocation
> 16)
5059 ((*_bfd_error_handler
)
5060 (_("%s: 0x%lx: fatal: R_SH_PSHL relocation %d not in range -32..32"),
5061 bfd_archive_filename (input_section
->owner
),
5062 (unsigned long) rel
->r_offset
,
5063 (unsigned long)relocation
));
5064 bfd_set_error (bfd_error_bad_value
);
5067 goto final_link_relocate
;
5071 #ifdef INCLUDE_SHMEDIA
5072 case R_SH_IMM_LOW16_PCREL
:
5073 case R_SH_IMM_MEDLOW16_PCREL
:
5074 case R_SH_IMM_MEDHI16_PCREL
:
5075 case R_SH_IMM_HI16_PCREL
:
5079 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5080 || h
->root
.type
!= bfd_link_hash_undefweak
)
5082 && (input_section
->flags
& SEC_ALLOC
) != 0
5083 && (r_type
== R_SH_DIR32
5084 || !SYMBOL_CALLS_LOCAL (info
, h
)))
5086 Elf_Internal_Rela outrel
;
5088 bfd_boolean skip
, relocate
;
5090 /* When generating a shared object, these relocations
5091 are copied into the output file to be resolved at run
5098 name
= (bfd_elf_string_from_elf_section
5100 elf_elfheader (input_bfd
)->e_shstrndx
,
5101 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5105 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5106 && strcmp (bfd_get_section_name (input_bfd
,
5110 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5111 BFD_ASSERT (sreloc
!= NULL
);
5118 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5120 if (outrel
.r_offset
== (bfd_vma
) -1)
5122 else if (outrel
.r_offset
== (bfd_vma
) -2)
5123 skip
= TRUE
, relocate
= TRUE
;
5124 outrel
.r_offset
+= (input_section
->output_section
->vma
5125 + input_section
->output_offset
);
5128 memset (&outrel
, 0, sizeof outrel
);
5129 else if (r_type
== R_SH_REL32
)
5131 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
5132 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_REL32
);
5134 = bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
5136 #ifdef INCLUDE_SHMEDIA
5137 else if (r_type
== R_SH_IMM_LOW16_PCREL
5138 || r_type
== R_SH_IMM_MEDLOW16_PCREL
5139 || r_type
== R_SH_IMM_MEDHI16_PCREL
5140 || r_type
== R_SH_IMM_HI16_PCREL
)
5142 BFD_ASSERT (h
!= NULL
&& h
->dynindx
!= -1);
5143 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5144 outrel
.r_addend
= addend
;
5149 /* h->dynindx may be -1 if this symbol was marked to
5152 || ((info
->symbolic
|| h
->dynindx
== -1)
5153 && (h
->elf_link_hash_flags
5154 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
5157 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
5159 = relocation
+ bfd_get_32 (input_bfd
,
5160 contents
+ rel
->r_offset
);
5164 BFD_ASSERT (h
->dynindx
!= -1);
5165 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_DIR32
);
5167 = relocation
+ bfd_get_32 (input_bfd
,
5168 contents
+ rel
->r_offset
);
5172 loc
= sreloc
->contents
;
5173 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5174 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5176 /* If this reloc is against an external symbol, we do
5177 not want to fiddle with the addend. Otherwise, we
5178 need to include the symbol value so that it becomes
5179 an addend for the dynamic reloc. */
5183 goto final_link_relocate
;
5186 #ifdef INCLUDE_SHMEDIA
5187 case R_SH_GOTPLT_LOW16
:
5188 case R_SH_GOTPLT_MEDLOW16
:
5189 case R_SH_GOTPLT_MEDHI16
:
5190 case R_SH_GOTPLT_HI16
:
5191 case R_SH_GOTPLT10BY4
:
5192 case R_SH_GOTPLT10BY8
:
5194 /* Relocation is to the entry for this symbol in the
5195 procedure linkage table. */
5198 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
5202 || h
->plt
.offset
== (bfd_vma
) -1
5203 || h
->got
.offset
!= (bfd_vma
) -1)
5206 /* Relocation is to the entry for this symbol in the global
5207 offset table extension for the procedure linkage table. */
5209 BFD_ASSERT (sgotplt
!= NULL
);
5210 relocation
= (sgotplt
->output_offset
5211 + ((h
->plt
.offset
/ elf_sh_sizeof_plt (info
)
5215 relocation
-= GOT_BIAS
;
5218 goto final_link_relocate
;
5222 #ifdef INCLUDE_SHMEDIA
5223 case R_SH_GOT_LOW16
:
5224 case R_SH_GOT_MEDLOW16
:
5225 case R_SH_GOT_MEDHI16
:
5230 /* Relocation is to the entry for this symbol in the global
5233 BFD_ASSERT (sgot
!= NULL
);
5239 off
= h
->got
.offset
;
5240 #ifdef INCLUDE_SHMEDIA
5241 if (seen_stt_datalabel
)
5243 struct elf_sh_link_hash_entry
*hsh
;
5245 hsh
= (struct elf_sh_link_hash_entry
*)h
;
5246 off
= hsh
->datalabel_got
.offset
;
5249 BFD_ASSERT (off
!= (bfd_vma
) -1);
5251 dyn
= htab
->root
.dynamic_sections_created
;
5252 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
5254 && SYMBOL_REFERENCES_LOCAL (info
, h
))
5255 || (ELF_ST_VISIBILITY (h
->other
)
5256 && h
->root
.type
== bfd_link_hash_undefweak
))
5258 /* This is actually a static link, or it is a
5259 -Bsymbolic link and the symbol is defined
5260 locally, or the symbol was forced to be local
5261 because of a version file. We must initialize
5262 this entry in the global offset table. Since the
5263 offset must always be a multiple of 4, we use the
5264 least significant bit to record whether we have
5265 initialized it already.
5267 When doing a dynamic link, we create a .rela.got
5268 relocation entry to initialize the value. This
5269 is done in the finish_dynamic_symbol routine. */
5274 bfd_put_32 (output_bfd
, relocation
,
5275 sgot
->contents
+ off
);
5276 #ifdef INCLUDE_SHMEDIA
5277 if (seen_stt_datalabel
)
5279 struct elf_sh_link_hash_entry
*hsh
;
5281 hsh
= (struct elf_sh_link_hash_entry
*)h
;
5282 hsh
->datalabel_got
.offset
|= 1;
5290 relocation
= sgot
->output_offset
+ off
;
5294 #ifdef INCLUDE_SHMEDIA
5297 BFD_ASSERT (local_got_offsets
!= NULL
5298 && (local_got_offsets
[symtab_hdr
->sh_info
5302 off
= local_got_offsets
[symtab_hdr
->sh_info
5308 BFD_ASSERT (local_got_offsets
!= NULL
5309 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
5311 off
= local_got_offsets
[r_symndx
];
5312 #ifdef INCLUDE_SHMEDIA
5316 /* The offset must always be a multiple of 4. We use
5317 the least significant bit to record whether we have
5318 already generated the necessary reloc. */
5323 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
5327 Elf_Internal_Rela outrel
;
5330 if (srelgot
== NULL
)
5332 srelgot
= bfd_get_section_by_name (dynobj
,
5334 BFD_ASSERT (srelgot
!= NULL
);
5337 outrel
.r_offset
= (sgot
->output_section
->vma
5338 + sgot
->output_offset
5340 outrel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
5341 outrel
.r_addend
= relocation
;
5342 loc
= srelgot
->contents
;
5343 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5344 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5347 #ifdef INCLUDE_SHMEDIA
5349 local_got_offsets
[symtab_hdr
->sh_info
+ r_symndx
] |= 1;
5352 local_got_offsets
[r_symndx
] |= 1;
5355 relocation
= sgot
->output_offset
+ off
;
5359 relocation
-= GOT_BIAS
;
5362 goto final_link_relocate
;
5365 #ifdef INCLUDE_SHMEDIA
5366 case R_SH_GOTOFF_LOW16
:
5367 case R_SH_GOTOFF_MEDLOW16
:
5368 case R_SH_GOTOFF_MEDHI16
:
5369 case R_SH_GOTOFF_HI16
:
5371 /* Relocation is relative to the start of the global offset
5374 BFD_ASSERT (sgot
!= NULL
);
5376 /* Note that sgot->output_offset is not involved in this
5377 calculation. We always want the start of .got. If we
5378 defined _GLOBAL_OFFSET_TABLE in a different way, as is
5379 permitted by the ABI, we might have to change this
5381 relocation
-= sgot
->output_section
->vma
;
5384 relocation
-= GOT_BIAS
;
5387 addend
= rel
->r_addend
;
5389 goto final_link_relocate
;
5392 #ifdef INCLUDE_SHMEDIA
5393 case R_SH_GOTPC_LOW16
:
5394 case R_SH_GOTPC_MEDLOW16
:
5395 case R_SH_GOTPC_MEDHI16
:
5396 case R_SH_GOTPC_HI16
:
5398 /* Use global offset table as symbol value. */
5400 BFD_ASSERT (sgot
!= NULL
);
5401 relocation
= sgot
->output_section
->vma
;
5404 relocation
+= GOT_BIAS
;
5407 addend
= rel
->r_addend
;
5409 goto final_link_relocate
;
5412 #ifdef INCLUDE_SHMEDIA
5413 case R_SH_PLT_LOW16
:
5414 case R_SH_PLT_MEDLOW16
:
5415 case R_SH_PLT_MEDHI16
:
5418 /* Relocation is to the entry for this symbol in the
5419 procedure linkage table. */
5421 /* Resolve a PLT reloc against a local symbol directly,
5422 without using the procedure linkage table. */
5424 goto final_link_relocate
;
5426 if (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
5427 goto final_link_relocate
;
5429 if (h
->plt
.offset
== (bfd_vma
) -1)
5431 /* We didn't make a PLT entry for this symbol. This
5432 happens when statically linking PIC code, or when
5433 using -Bsymbolic. */
5434 goto final_link_relocate
;
5437 BFD_ASSERT (splt
!= NULL
);
5438 relocation
= (splt
->output_section
->vma
5439 + splt
->output_offset
5442 #ifdef INCLUDE_SHMEDIA
5446 addend
= rel
->r_addend
;
5448 goto final_link_relocate
;
5450 case R_SH_LOOP_START
:
5452 static bfd_vma start
, end
;
5454 start
= (relocation
+ rel
->r_addend
5455 - (sec
->output_section
->vma
+ sec
->output_offset
));
5456 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5457 rel
->r_offset
, sec
, start
, end
);
5461 end
= (relocation
+ rel
->r_addend
5462 - (sec
->output_section
->vma
+ sec
->output_offset
));
5463 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
5464 rel
->r_offset
, sec
, start
, end
);
5468 case R_SH_TLS_GD_32
:
5469 case R_SH_TLS_IE_32
:
5470 r_type
= sh_elf_optimized_tls_reloc (info
, r_type
, h
== NULL
);
5471 tls_type
= GOT_UNKNOWN
;
5472 if (h
== NULL
&& local_got_offsets
)
5473 tls_type
= sh_elf_local_got_tls_type (input_bfd
) [r_symndx
];
5476 tls_type
= sh_elf_hash_entry (h
)->tls_type
;
5478 && (h
->dynindx
== -1
5479 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
5480 r_type
= R_SH_TLS_LE_32
;
5483 if (r_type
== R_SH_TLS_GD_32
&& tls_type
== GOT_TLS_IE
)
5484 r_type
= R_SH_TLS_IE_32
;
5486 if (r_type
== R_SH_TLS_LE_32
)
5489 unsigned short insn
;
5491 if (ELF32_R_TYPE (rel
->r_info
) == R_SH_TLS_GD_32
)
5493 /* GD->LE transition:
5494 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5495 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5496 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5498 mov.l 1f,r4; stc gbr,r0; add r4,r0; nop;
5500 1: .long x@TPOFF; 2: .long __tls_get_addr@PLT; 3:. */
5502 offset
= rel
->r_offset
;
5503 BFD_ASSERT (offset
>= 16);
5504 /* Size of GD instructions is 16 or 18. */
5506 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5507 if ((insn
& 0xff00) == 0xc700)
5509 BFD_ASSERT (offset
>= 2);
5511 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5514 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5515 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5516 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5517 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5518 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5519 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5520 BFD_ASSERT (insn
== 0x310c);
5521 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5522 BFD_ASSERT (insn
== 0x410b);
5523 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5524 BFD_ASSERT (insn
== 0x34cc);
5526 bfd_put_16 (output_bfd
, 0x0012, contents
+ offset
+ 2);
5527 bfd_put_16 (output_bfd
, 0x304c, contents
+ offset
+ 4);
5528 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 6);
5529 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5530 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5536 /* IE->LE transition:
5537 mov.l 1f,r0; stc gbr,rN; mov.l @(r0,r12),rM;
5538 bra 2f; add ...; .align 2; 1: x@GOTTPOFF; 2:
5540 mov.l .Ln,rM; stc gbr,rN; nop; ...;
5543 offset
= rel
->r_offset
;
5544 BFD_ASSERT (offset
>= 16);
5545 /* Size of IE instructions is 10 or 12. */
5547 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5548 if ((insn
& 0xf0ff) == 0x0012)
5550 BFD_ASSERT (offset
>= 2);
5552 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5555 BFD_ASSERT ((insn
& 0xff00) == 0xd000);
5556 index
= insn
& 0x00ff;
5557 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5558 BFD_ASSERT ((insn
& 0xf0ff) == 0x0012);
5559 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5560 BFD_ASSERT ((insn
& 0xf0ff) == 0x00ce);
5561 insn
= 0xd000 | (insn
& 0x0f00) | index
;
5562 bfd_put_16 (output_bfd
, insn
, contents
+ offset
+ 0);
5563 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 4);
5566 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
5567 contents
+ rel
->r_offset
);
5576 off
= h
->got
.offset
;
5579 if (local_got_offsets
== NULL
)
5582 off
= local_got_offsets
[r_symndx
];
5585 /* Relocate R_SH_TLS_IE_32 directly when statically linking. */
5586 if (r_type
== R_SH_TLS_IE_32
5587 && ! htab
->root
.dynamic_sections_created
)
5590 bfd_put_32 (output_bfd
, tpoff (info
, relocation
),
5591 sgot
->contents
+ off
);
5592 bfd_put_32 (output_bfd
, sgot
->output_offset
+ off
,
5593 contents
+ rel
->r_offset
);
5601 Elf_Internal_Rela outrel
;
5605 if (srelgot
== NULL
)
5607 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
5608 BFD_ASSERT (srelgot
!= NULL
);
5611 outrel
.r_offset
= (sgot
->output_section
->vma
5612 + sgot
->output_offset
+ off
);
5614 if (h
== NULL
|| h
->dynindx
== -1)
5619 dr_type
= (r_type
== R_SH_TLS_GD_32
? R_SH_TLS_DTPMOD32
:
5621 if (dr_type
== R_SH_TLS_TPOFF32
&& indx
== 0)
5622 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5624 outrel
.r_addend
= 0;
5625 outrel
.r_info
= ELF32_R_INFO (indx
, dr_type
);
5626 loc
= srelgot
->contents
;
5627 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5628 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5630 if (r_type
== R_SH_TLS_GD_32
)
5634 bfd_put_32 (output_bfd
,
5635 relocation
- dtpoff_base (info
),
5636 sgot
->contents
+ off
+ 4);
5640 outrel
.r_info
= ELF32_R_INFO (indx
,
5642 outrel
.r_offset
+= 4;
5643 outrel
.r_addend
= 0;
5644 srelgot
->reloc_count
++;
5645 loc
+= sizeof (Elf32_External_Rela
);
5646 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5653 local_got_offsets
[r_symndx
] |= 1;
5656 if (off
>= (bfd_vma
) -2)
5659 if (r_type
== (int) ELF32_R_TYPE (rel
->r_info
))
5660 relocation
= sgot
->output_offset
+ off
;
5664 unsigned short insn
;
5666 /* GD->IE transition:
5667 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5668 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5669 1: .long x$TLSGD; 2: .long __tls_get_addr@PLT; 3:
5671 mov.l 1f,r0; stc gbr,r4; mov.l @(r0,r12),r0; add r4,r0;
5672 nop; nop; bra 3f; nop; .align 2;
5673 1: .long x@TPOFF; 2:...; 3:. */
5675 offset
= rel
->r_offset
;
5676 BFD_ASSERT (offset
>= 16);
5677 /* Size of GD instructions is 16 or 18. */
5679 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5680 if ((insn
& 0xff00) == 0xc700)
5682 BFD_ASSERT (offset
>= 2);
5684 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5687 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5689 /* Replace mov.l 1f,R4 with mov.l 1f,r0. */
5690 bfd_put_16 (output_bfd
, insn
& 0xf0ff, contents
+ offset
);
5692 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5693 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5694 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5695 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5696 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5697 BFD_ASSERT (insn
== 0x310c);
5698 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5699 BFD_ASSERT (insn
== 0x410b);
5700 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5701 BFD_ASSERT (insn
== 0x34cc);
5703 bfd_put_16 (output_bfd
, 0x0412, contents
+ offset
+ 2);
5704 bfd_put_16 (output_bfd
, 0x00ce, contents
+ offset
+ 4);
5705 bfd_put_16 (output_bfd
, 0x304c, contents
+ offset
+ 6);
5706 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5707 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5709 bfd_put_32 (output_bfd
, sgot
->output_offset
+ off
,
5710 contents
+ rel
->r_offset
);
5715 addend
= rel
->r_addend
;
5717 goto final_link_relocate
;
5719 case R_SH_TLS_LD_32
:
5723 unsigned short insn
;
5725 /* LD->LE transition:
5726 mov.l 1f,r4; mova 2f,r0; mov.l 2f,r1; add r0,r1;
5727 jsr @r1; add r12,r4; bra 3f; nop; .align 2;
5728 1: .long x$TLSLD; 2: .long __tls_get_addr@PLT; 3:
5730 stc gbr,r0; nop; nop; nop;
5731 nop; nop; bra 3f; ...; 3:. */
5733 offset
= rel
->r_offset
;
5734 BFD_ASSERT (offset
>= 16);
5735 /* Size of LD instructions is 16 or 18. */
5737 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5738 if ((insn
& 0xff00) == 0xc700)
5740 BFD_ASSERT (offset
>= 2);
5742 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 0);
5745 BFD_ASSERT ((insn
& 0xff00) == 0xd400);
5746 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 2);
5747 BFD_ASSERT ((insn
& 0xff00) == 0xc700);
5748 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 4);
5749 BFD_ASSERT ((insn
& 0xff00) == 0xd100);
5750 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 6);
5751 BFD_ASSERT (insn
== 0x310c);
5752 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 8);
5753 BFD_ASSERT (insn
== 0x410b);
5754 insn
= bfd_get_16 (input_bfd
, contents
+ offset
+ 10);
5755 BFD_ASSERT (insn
== 0x34cc);
5757 bfd_put_16 (output_bfd
, 0x0012, contents
+ offset
+ 0);
5758 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 2);
5759 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 4);
5760 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 6);
5761 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 8);
5762 bfd_put_16 (output_bfd
, 0x0009, contents
+ offset
+ 10);
5771 off
= htab
->tls_ldm_got
.offset
;
5776 Elf_Internal_Rela outrel
;
5779 srelgot
= htab
->srelgot
;
5780 if (srelgot
== NULL
)
5783 outrel
.r_offset
= (sgot
->output_section
->vma
5784 + sgot
->output_offset
+ off
);
5785 outrel
.r_addend
= 0;
5786 outrel
.r_info
= ELF32_R_INFO (0, R_SH_TLS_DTPMOD32
);
5787 loc
= srelgot
->contents
;
5788 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5789 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5790 htab
->tls_ldm_got
.offset
|= 1;
5793 relocation
= sgot
->output_offset
+ off
;
5794 addend
= rel
->r_addend
;
5796 goto final_link_relocate
;
5798 case R_SH_TLS_LDO_32
:
5800 relocation
= tpoff (info
, relocation
);
5802 relocation
-= dtpoff_base (info
);
5804 addend
= rel
->r_addend
;
5805 goto final_link_relocate
;
5807 case R_SH_TLS_LE_32
:
5810 Elf_Internal_Rela outrel
;
5815 relocation
= tpoff (info
, relocation
);
5816 addend
= rel
->r_addend
;
5817 goto final_link_relocate
;
5824 name
= (bfd_elf_string_from_elf_section
5826 elf_elfheader (input_bfd
)->e_shstrndx
,
5827 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5831 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5832 && strcmp (bfd_get_section_name (input_bfd
,
5836 sreloc
= bfd_get_section_by_name (dynobj
, name
);
5837 BFD_ASSERT (sreloc
!= NULL
);
5840 if (h
== NULL
|| h
->dynindx
== -1)
5845 outrel
.r_offset
= (input_section
->output_section
->vma
5846 + input_section
->output_offset
5848 outrel
.r_info
= ELF32_R_INFO (indx
, R_SH_TLS_TPOFF32
);
5850 outrel
.r_addend
= relocation
- dtpoff_base (info
);
5852 outrel
.r_addend
= 0;
5854 loc
= sreloc
->contents
;
5855 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5856 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5862 if (r
!= bfd_reloc_ok
)
5867 case bfd_reloc_outofrange
:
5869 case bfd_reloc_overflow
:
5874 name
= h
->root
.root
.string
;
5877 name
= (bfd_elf_string_from_elf_section
5878 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
5882 name
= bfd_section_name (input_bfd
, sec
);
5884 if (! ((*info
->callbacks
->reloc_overflow
)
5885 (info
, name
, howto
->name
, (bfd_vma
) 0,
5886 input_bfd
, input_section
, rel
->r_offset
)))
5897 /* This is a version of bfd_generic_get_relocated_section_contents
5898 which uses sh_elf_relocate_section. */
5901 sh_elf_get_relocated_section_contents (bfd
*output_bfd
,
5902 struct bfd_link_info
*link_info
,
5903 struct bfd_link_order
*link_order
,
5905 bfd_boolean relocatable
,
5908 Elf_Internal_Shdr
*symtab_hdr
;
5909 asection
*input_section
= link_order
->u
.indirect
.section
;
5910 bfd
*input_bfd
= input_section
->owner
;
5911 asection
**sections
= NULL
;
5912 Elf_Internal_Rela
*internal_relocs
= NULL
;
5913 Elf_Internal_Sym
*isymbuf
= NULL
;
5915 /* We only need to handle the case of relaxing, or of having a
5916 particular set of section contents, specially. */
5918 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
5919 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
5924 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5926 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
5927 (size_t) input_section
->_raw_size
);
5929 if ((input_section
->flags
& SEC_RELOC
) != 0
5930 && input_section
->reloc_count
> 0)
5933 Elf_Internal_Sym
*isym
, *isymend
;
5936 internal_relocs
= (_bfd_elf_link_read_relocs
5937 (input_bfd
, input_section
, NULL
,
5938 (Elf_Internal_Rela
*) NULL
, FALSE
));
5939 if (internal_relocs
== NULL
)
5942 if (symtab_hdr
->sh_info
!= 0)
5944 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5945 if (isymbuf
== NULL
)
5946 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
5947 symtab_hdr
->sh_info
, 0,
5949 if (isymbuf
== NULL
)
5953 amt
= symtab_hdr
->sh_info
;
5954 amt
*= sizeof (asection
*);
5955 sections
= (asection
**) bfd_malloc (amt
);
5956 if (sections
== NULL
&& amt
!= 0)
5959 isymend
= isymbuf
+ symtab_hdr
->sh_info
;
5960 for (isym
= isymbuf
, secpp
= sections
; isym
< isymend
; ++isym
, ++secpp
)
5964 if (isym
->st_shndx
== SHN_UNDEF
)
5965 isec
= bfd_und_section_ptr
;
5966 else if (isym
->st_shndx
== SHN_ABS
)
5967 isec
= bfd_abs_section_ptr
;
5968 else if (isym
->st_shndx
== SHN_COMMON
)
5969 isec
= bfd_com_section_ptr
;
5971 isec
= bfd_section_from_elf_index (input_bfd
, isym
->st_shndx
);
5976 if (! sh_elf_relocate_section (output_bfd
, link_info
, input_bfd
,
5977 input_section
, data
, internal_relocs
,
5981 if (sections
!= NULL
)
5984 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5986 if (elf_section_data (input_section
)->relocs
!= internal_relocs
)
5987 free (internal_relocs
);
5993 if (sections
!= NULL
)
5996 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
5998 if (internal_relocs
!= NULL
5999 && elf_section_data (input_section
)->relocs
!= internal_relocs
)
6000 free (internal_relocs
);
6004 /* Return the base VMA address which should be subtracted from real addresses
6005 when resolving @dtpoff relocation.
6006 This is PT_TLS segment p_vaddr. */
6009 dtpoff_base (struct bfd_link_info
*info
)
6011 /* If tls_sec is NULL, we should have signalled an error already. */
6012 if (elf_hash_table (info
)->tls_sec
== NULL
)
6014 return elf_hash_table (info
)->tls_sec
->vma
;
6017 /* Return the relocation value for R_SH_TLS_TPOFF32.. */
6020 tpoff (struct bfd_link_info
*info
, bfd_vma address
)
6022 /* If tls_sec is NULL, we should have signalled an error already. */
6023 if (elf_hash_table (info
)->tls_sec
== NULL
)
6025 /* SH TLS ABI is variant I and static TLS block start just after tcbhead
6026 structure which has 2 pointer fields. */
6027 return address
- elf_hash_table (info
)->tls_sec
->vma
+ 8;
6031 sh_elf_gc_mark_hook (asection
*sec
,
6032 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6033 Elf_Internal_Rela
*rel
, struct elf_link_hash_entry
*h
,
6034 Elf_Internal_Sym
*sym
)
6038 switch (ELF32_R_TYPE (rel
->r_info
))
6040 case R_SH_GNU_VTINHERIT
:
6041 case R_SH_GNU_VTENTRY
:
6045 #ifdef INCLUDE_SHMEDIA
6046 while (h
->root
.type
== bfd_link_hash_indirect
6047 && h
->root
.u
.i
.link
)
6048 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6050 switch (h
->root
.type
)
6052 case bfd_link_hash_defined
:
6053 case bfd_link_hash_defweak
:
6054 return h
->root
.u
.def
.section
;
6056 case bfd_link_hash_common
:
6057 return h
->root
.u
.c
.p
->section
;
6065 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6070 /* Update the got entry reference counts for the section being removed. */
6073 sh_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
6074 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6076 Elf_Internal_Shdr
*symtab_hdr
;
6077 struct elf_link_hash_entry
**sym_hashes
;
6078 bfd_signed_vma
*local_got_refcounts
;
6079 const Elf_Internal_Rela
*rel
, *relend
;
6081 elf_section_data (sec
)->local_dynrel
= NULL
;
6083 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6084 sym_hashes
= elf_sym_hashes (abfd
);
6085 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6087 relend
= relocs
+ sec
->reloc_count
;
6088 for (rel
= relocs
; rel
< relend
; rel
++)
6090 unsigned long r_symndx
;
6091 unsigned int r_type
;
6092 struct elf_link_hash_entry
*h
= NULL
;
6093 #ifdef INCLUDE_SHMEDIA
6094 int seen_stt_datalabel
= 0;
6097 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6098 if (r_symndx
>= symtab_hdr
->sh_info
)
6100 struct elf_sh_link_hash_entry
*eh
;
6101 struct elf_sh_dyn_relocs
**pp
;
6102 struct elf_sh_dyn_relocs
*p
;
6104 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6105 #ifdef INCLUDE_SHMEDIA
6106 while (h
->root
.type
== bfd_link_hash_indirect
6107 || h
->root
.type
== bfd_link_hash_warning
)
6109 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
6110 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6113 eh
= (struct elf_sh_link_hash_entry
*) h
;
6114 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
6117 /* Everything must go for SEC. */
6123 r_type
= ELF32_R_TYPE (rel
->r_info
);
6124 switch (sh_elf_optimized_tls_reloc (info
, r_type
, h
!= NULL
))
6126 case R_SH_TLS_LD_32
:
6127 if (sh_elf_hash_table (info
)->tls_ldm_got
.refcount
> 0)
6128 sh_elf_hash_table (info
)->tls_ldm_got
.refcount
-= 1;
6134 #ifdef INCLUDE_SHMEDIA
6135 case R_SH_GOT_LOW16
:
6136 case R_SH_GOT_MEDLOW16
:
6137 case R_SH_GOT_MEDHI16
:
6141 case R_SH_GOTOFF_LOW16
:
6142 case R_SH_GOTOFF_MEDLOW16
:
6143 case R_SH_GOTOFF_MEDHI16
:
6144 case R_SH_GOTOFF_HI16
:
6145 case R_SH_GOTPC_LOW16
:
6146 case R_SH_GOTPC_MEDLOW16
:
6147 case R_SH_GOTPC_MEDHI16
:
6148 case R_SH_GOTPC_HI16
:
6150 case R_SH_TLS_GD_32
:
6151 case R_SH_TLS_IE_32
:
6154 #ifdef INCLUDE_SHMEDIA
6155 if (seen_stt_datalabel
)
6157 struct elf_sh_link_hash_entry
*eh
;
6158 eh
= (struct elf_sh_link_hash_entry
*) h
;
6159 if (eh
->datalabel_got
.refcount
> 0)
6160 eh
->datalabel_got
.refcount
-= 1;
6164 if (h
->got
.refcount
> 0)
6165 h
->got
.refcount
-= 1;
6167 else if (local_got_refcounts
!= NULL
)
6169 #ifdef INCLUDE_SHMEDIA
6170 if (rel
->r_addend
& 1)
6172 if (local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] > 0)
6173 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] -= 1;
6177 if (local_got_refcounts
[r_symndx
] > 0)
6178 local_got_refcounts
[r_symndx
] -= 1;
6189 #ifdef INCLUDE_SHMEDIA
6190 case R_SH_PLT_LOW16
:
6191 case R_SH_PLT_MEDLOW16
:
6192 case R_SH_PLT_MEDHI16
:
6197 if (h
->plt
.refcount
> 0)
6198 h
->plt
.refcount
-= 1;
6203 #ifdef INCLUDE_SHMEDIA
6204 case R_SH_GOTPLT_LOW16
:
6205 case R_SH_GOTPLT_MEDLOW16
:
6206 case R_SH_GOTPLT_MEDHI16
:
6207 case R_SH_GOTPLT_HI16
:
6208 case R_SH_GOTPLT10BY4
:
6209 case R_SH_GOTPLT10BY8
:
6213 struct elf_sh_link_hash_entry
*eh
;
6214 eh
= (struct elf_sh_link_hash_entry
*) h
;
6215 if (eh
->gotplt_refcount
> 0)
6217 eh
->gotplt_refcount
-= 1;
6218 if (h
->plt
.refcount
> 0)
6219 h
->plt
.refcount
-= 1;
6221 #ifdef INCLUDE_SHMEDIA
6222 else if (seen_stt_datalabel
)
6224 if (eh
->datalabel_got
.refcount
> 0)
6225 eh
->datalabel_got
.refcount
-= 1;
6228 else if (h
->got
.refcount
> 0)
6229 h
->got
.refcount
-= 1;
6231 else if (local_got_refcounts
!= NULL
)
6233 #ifdef INCLUDE_SHMEDIA
6234 if (rel
->r_addend
& 1)
6236 if (local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] > 0)
6237 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] -= 1;
6241 if (local_got_refcounts
[r_symndx
] > 0)
6242 local_got_refcounts
[r_symndx
] -= 1;
6254 /* Copy the extra info we tack onto an elf_link_hash_entry. */
6257 sh_elf_copy_indirect_symbol (const struct elf_backend_data
*bed
,
6258 struct elf_link_hash_entry
*dir
,
6259 struct elf_link_hash_entry
*ind
)
6261 struct elf_sh_link_hash_entry
*edir
, *eind
;
6262 #ifdef INCLUDE_SHMEDIA
6266 edir
= (struct elf_sh_link_hash_entry
*) dir
;
6267 eind
= (struct elf_sh_link_hash_entry
*) ind
;
6269 if (eind
->dyn_relocs
!= NULL
)
6271 if (edir
->dyn_relocs
!= NULL
)
6273 struct elf_sh_dyn_relocs
**pp
;
6274 struct elf_sh_dyn_relocs
*p
;
6276 BFD_ASSERT (ind
->root
.type
!= bfd_link_hash_indirect
);
6278 /* Add reloc counts against the weak sym to the strong sym
6279 list. Merge any entries against the same section. */
6280 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
6282 struct elf_sh_dyn_relocs
*q
;
6284 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
6285 if (q
->sec
== p
->sec
)
6287 q
->pc_count
+= p
->pc_count
;
6288 q
->count
+= p
->count
;
6295 *pp
= edir
->dyn_relocs
;
6298 edir
->dyn_relocs
= eind
->dyn_relocs
;
6299 eind
->dyn_relocs
= NULL
;
6301 edir
->gotplt_refcount
= eind
->gotplt_refcount
;
6302 eind
->gotplt_refcount
= 0;
6303 #ifdef INCLUDE_SHMEDIA
6304 tmp
= edir
->datalabel_got
.refcount
;
6307 edir
->datalabel_got
.refcount
= eind
->datalabel_got
.refcount
;
6308 eind
->datalabel_got
.refcount
= tmp
;
6311 BFD_ASSERT (eind
->datalabel_got
.refcount
< 1);
6314 if (ind
->root
.type
== bfd_link_hash_indirect
6315 && dir
->got
.refcount
<= 0)
6317 edir
->tls_type
= eind
->tls_type
;
6318 eind
->tls_type
= GOT_UNKNOWN
;
6321 if (ind
->root
.type
!= bfd_link_hash_indirect
6322 && (dir
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
6323 /* If called to transfer flags for a weakdef during processing
6324 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
6325 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
6326 dir
->elf_link_hash_flags
|=
6327 (ind
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_DYNAMIC
6328 | ELF_LINK_HASH_REF_REGULAR
6329 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
6330 | ELF_LINK_HASH_NEEDS_PLT
));
6332 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
6336 sh_elf_optimized_tls_reloc (struct bfd_link_info
*info
, int r_type
,
6344 case R_SH_TLS_GD_32
:
6345 case R_SH_TLS_IE_32
:
6347 return R_SH_TLS_LE_32
;
6348 return R_SH_TLS_IE_32
;
6349 case R_SH_TLS_LD_32
:
6350 return R_SH_TLS_LE_32
;
6356 /* Look through the relocs for a section during the first phase.
6357 Since we don't do .gots or .plts, we just need to consider the
6358 virtual table relocs for gc. */
6361 sh_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
6362 const Elf_Internal_Rela
*relocs
)
6364 Elf_Internal_Shdr
*symtab_hdr
;
6365 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
6366 struct elf_sh_link_hash_table
*htab
;
6367 const Elf_Internal_Rela
*rel
;
6368 const Elf_Internal_Rela
*rel_end
;
6369 bfd_vma
*local_got_offsets
;
6373 unsigned int r_type
;
6374 int tls_type
, old_tls_type
;
6380 if (info
->relocatable
)
6383 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
6384 sym_hashes
= elf_sym_hashes (abfd
);
6385 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof (Elf32_External_Sym
);
6386 if (!elf_bad_symtab (abfd
))
6387 sym_hashes_end
-= symtab_hdr
->sh_info
;
6389 htab
= sh_elf_hash_table (info
);
6390 local_got_offsets
= elf_local_got_offsets (abfd
);
6392 rel_end
= relocs
+ sec
->reloc_count
;
6393 for (rel
= relocs
; rel
< rel_end
; rel
++)
6395 struct elf_link_hash_entry
*h
;
6396 unsigned long r_symndx
;
6397 #ifdef INCLUDE_SHMEDIA
6398 int seen_stt_datalabel
= 0;
6401 r_symndx
= ELF32_R_SYM (rel
->r_info
);
6402 r_type
= ELF32_R_TYPE (rel
->r_info
);
6404 if (r_symndx
< symtab_hdr
->sh_info
)
6408 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6409 #ifdef INCLUDE_SHMEDIA
6410 while (h
->root
.type
== bfd_link_hash_indirect
6411 || h
->root
.type
== bfd_link_hash_warning
)
6413 seen_stt_datalabel
|= h
->type
== STT_DATALABEL
;
6414 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6419 r_type
= sh_elf_optimized_tls_reloc (info
, r_type
, h
== NULL
);
6421 && r_type
== R_SH_TLS_IE_32
6423 && h
->root
.type
!= bfd_link_hash_undefined
6424 && h
->root
.type
!= bfd_link_hash_undefweak
6425 && (h
->dynindx
== -1
6426 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
6427 r_type
= R_SH_TLS_LE_32
;
6429 /* Some relocs require a global offset table. */
6430 if (htab
->sgot
== NULL
)
6438 #ifdef INCLUDE_SHMEDIA
6439 case R_SH_GOTPLT_LOW16
:
6440 case R_SH_GOTPLT_MEDLOW16
:
6441 case R_SH_GOTPLT_MEDHI16
:
6442 case R_SH_GOTPLT_HI16
:
6443 case R_SH_GOTPLT10BY4
:
6444 case R_SH_GOTPLT10BY8
:
6445 case R_SH_GOT_LOW16
:
6446 case R_SH_GOT_MEDLOW16
:
6447 case R_SH_GOT_MEDHI16
:
6451 case R_SH_GOTOFF_LOW16
:
6452 case R_SH_GOTOFF_MEDLOW16
:
6453 case R_SH_GOTOFF_MEDHI16
:
6454 case R_SH_GOTOFF_HI16
:
6455 case R_SH_GOTPC_LOW16
:
6456 case R_SH_GOTPC_MEDLOW16
:
6457 case R_SH_GOTPC_MEDHI16
:
6458 case R_SH_GOTPC_HI16
:
6460 case R_SH_TLS_GD_32
:
6461 case R_SH_TLS_LD_32
:
6462 case R_SH_TLS_IE_32
:
6463 if (htab
->sgot
== NULL
)
6465 if (htab
->root
.dynobj
== NULL
)
6466 htab
->root
.dynobj
= abfd
;
6467 if (!create_got_section (htab
->root
.dynobj
, info
))
6479 /* This relocation describes the C++ object vtable hierarchy.
6480 Reconstruct it for later use during GC. */
6481 case R_SH_GNU_VTINHERIT
:
6482 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
6486 /* This relocation describes which C++ vtable entries are actually
6487 used. Record for later use during GC. */
6488 case R_SH_GNU_VTENTRY
:
6489 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
6493 case R_SH_TLS_IE_32
:
6495 info
->flags
|= DF_STATIC_TLS
;
6499 case R_SH_TLS_GD_32
:
6501 #ifdef INCLUDE_SHMEDIA
6502 case R_SH_GOT_LOW16
:
6503 case R_SH_GOT_MEDLOW16
:
6504 case R_SH_GOT_MEDHI16
:
6512 tls_type
= GOT_NORMAL
;
6514 case R_SH_TLS_GD_32
:
6515 tls_type
= GOT_TLS_GD
;
6517 case R_SH_TLS_IE_32
:
6518 tls_type
= GOT_TLS_IE
;
6524 #ifdef INCLUDE_SHMEDIA
6525 if (seen_stt_datalabel
)
6527 struct elf_sh_link_hash_entry
*eh
6528 = (struct elf_sh_link_hash_entry
*) h
;
6530 eh
->datalabel_got
.refcount
+= 1;
6534 h
->got
.refcount
+= 1;
6535 old_tls_type
= sh_elf_hash_entry (h
)->tls_type
;
6539 bfd_signed_vma
*local_got_refcounts
;
6541 /* This is a global offset table entry for a local
6543 local_got_refcounts
= elf_local_got_refcounts (abfd
);
6544 if (local_got_refcounts
== NULL
)
6548 size
= symtab_hdr
->sh_info
;
6549 size
*= sizeof (bfd_signed_vma
);
6550 #ifdef INCLUDE_SHMEDIA
6551 /* Reserve space for both the datalabel and
6552 codelabel local GOT offsets. */
6555 size
+= symtab_hdr
->sh_info
;
6556 local_got_refcounts
= ((bfd_signed_vma
*)
6557 bfd_zalloc (abfd
, size
));
6558 if (local_got_refcounts
== NULL
)
6560 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
6561 #ifdef INCLUDE_SHMEDIA
6562 /* Take care of both the datalabel and codelabel local
6564 sh_elf_local_got_tls_type (abfd
)
6565 = (char *) (local_got_refcounts
+ 2 * symtab_hdr
->sh_info
);
6567 sh_elf_local_got_tls_type (abfd
)
6568 = (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
6571 #ifdef INCLUDE_SHMEDIA
6572 if (rel
->r_addend
& 1)
6573 local_got_refcounts
[symtab_hdr
->sh_info
+ r_symndx
] += 1;
6576 local_got_refcounts
[r_symndx
] += 1;
6577 old_tls_type
= sh_elf_local_got_tls_type (abfd
) [r_symndx
];
6580 /* If a TLS symbol is accessed using IE at least once,
6581 there is no point to use dynamic model for it. */
6582 if (old_tls_type
!= tls_type
&& old_tls_type
!= GOT_UNKNOWN
6583 && (old_tls_type
!= GOT_TLS_GD
|| tls_type
!= GOT_TLS_IE
))
6585 if (old_tls_type
== GOT_TLS_IE
&& tls_type
== GOT_TLS_GD
)
6586 tls_type
= GOT_TLS_IE
;
6589 (*_bfd_error_handler
)
6590 (_("%s: `%s' accessed both as normal and thread local symbol"),
6591 bfd_archive_filename (abfd
), h
->root
.root
.string
);
6596 if (old_tls_type
!= tls_type
)
6599 sh_elf_hash_entry (h
)->tls_type
= tls_type
;
6601 sh_elf_local_got_tls_type (abfd
) [r_symndx
] = tls_type
;
6606 case R_SH_TLS_LD_32
:
6607 sh_elf_hash_table(info
)->tls_ldm_got
.refcount
+= 1;
6611 #ifdef INCLUDE_SHMEDIA
6612 case R_SH_GOTPLT_LOW16
:
6613 case R_SH_GOTPLT_MEDLOW16
:
6614 case R_SH_GOTPLT_MEDHI16
:
6615 case R_SH_GOTPLT_HI16
:
6616 case R_SH_GOTPLT10BY4
:
6617 case R_SH_GOTPLT10BY8
:
6619 /* If this is a local symbol, we resolve it directly without
6620 creating a procedure linkage table entry. */
6623 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
6626 || h
->dynindx
== -1)
6629 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6630 h
->plt
.refcount
+= 1;
6631 ((struct elf_sh_link_hash_entry
*) h
)->gotplt_refcount
+= 1;
6636 #ifdef INCLUDE_SHMEDIA
6637 case R_SH_PLT_LOW16
:
6638 case R_SH_PLT_MEDLOW16
:
6639 case R_SH_PLT_MEDHI16
:
6642 /* This symbol requires a procedure linkage table entry. We
6643 actually build the entry in adjust_dynamic_symbol,
6644 because this might be a case of linking PIC code which is
6645 never referenced by a dynamic object, in which case we
6646 don't need to generate a procedure linkage table entry
6649 /* If this is a local symbol, we resolve it directly without
6650 creating a procedure linkage table entry. */
6654 if (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
6657 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
6658 h
->plt
.refcount
+= 1;
6663 #ifdef INCLUDE_SHMEDIA
6664 case R_SH_IMM_LOW16_PCREL
:
6665 case R_SH_IMM_MEDLOW16_PCREL
:
6666 case R_SH_IMM_MEDHI16_PCREL
:
6667 case R_SH_IMM_HI16_PCREL
:
6669 if (h
!= NULL
&& ! info
->shared
)
6671 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
6672 h
->plt
.refcount
+= 1;
6675 /* If we are creating a shared library, and this is a reloc
6676 against a global symbol, or a non PC relative reloc
6677 against a local symbol, then we need to copy the reloc
6678 into the shared library. However, if we are linking with
6679 -Bsymbolic, we do not need to copy a reloc against a
6680 global symbol which is defined in an object we are
6681 including in the link (i.e., DEF_REGULAR is set). At
6682 this point we have not seen all the input files, so it is
6683 possible that DEF_REGULAR is not set now but will be set
6684 later (it is never cleared). We account for that
6685 possibility below by storing information in the
6686 dyn_relocs field of the hash table entry. A similar
6687 situation occurs when creating shared libraries and symbol
6688 visibility changes render the symbol local.
6690 If on the other hand, we are creating an executable, we
6691 may need to keep relocations for symbols satisfied by a
6692 dynamic library if we manage to avoid copy relocs for the
6695 && (sec
->flags
& SEC_ALLOC
) != 0
6696 && (r_type
!= R_SH_REL32
6698 && (! info
->symbolic
6699 || h
->root
.type
== bfd_link_hash_defweak
6700 || (h
->elf_link_hash_flags
6701 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
6703 && (sec
->flags
& SEC_ALLOC
) != 0
6705 && (h
->root
.type
== bfd_link_hash_defweak
6706 || (h
->elf_link_hash_flags
6707 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
6709 struct elf_sh_dyn_relocs
*p
;
6710 struct elf_sh_dyn_relocs
**head
;
6712 if (htab
->root
.dynobj
== NULL
)
6713 htab
->root
.dynobj
= abfd
;
6715 /* When creating a shared object, we must copy these
6716 reloc types into the output file. We create a reloc
6717 section in dynobj and make room for this reloc. */
6722 name
= (bfd_elf_string_from_elf_section
6724 elf_elfheader (abfd
)->e_shstrndx
,
6725 elf_section_data (sec
)->rel_hdr
.sh_name
));
6729 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
6730 && strcmp (bfd_get_section_name (abfd
, sec
),
6733 sreloc
= bfd_get_section_by_name (htab
->root
.dynobj
, name
);
6738 sreloc
= bfd_make_section (htab
->root
.dynobj
, name
);
6739 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
6740 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
6741 if ((sec
->flags
& SEC_ALLOC
) != 0)
6742 flags
|= SEC_ALLOC
| SEC_LOAD
;
6744 || ! bfd_set_section_flags (htab
->root
.dynobj
,
6746 || ! bfd_set_section_alignment (htab
->root
.dynobj
,
6750 elf_section_data (sec
)->sreloc
= sreloc
;
6753 /* If this is a global symbol, we count the number of
6754 relocations we need for this symbol. */
6756 head
= &((struct elf_sh_link_hash_entry
*) h
)->dyn_relocs
;
6761 /* Track dynamic relocs needed for local syms too. */
6762 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
6767 head
= ((struct elf_sh_dyn_relocs
**)
6768 &elf_section_data (s
)->local_dynrel
);
6772 if (p
== NULL
|| p
->sec
!= sec
)
6774 bfd_size_type amt
= sizeof (*p
);
6775 p
= bfd_alloc (htab
->root
.dynobj
, amt
);
6786 if (r_type
== R_SH_REL32
6787 #ifdef INCLUDE_SHMEDIA
6788 || r_type
== R_SH_IMM_LOW16_PCREL
6789 || r_type
== R_SH_IMM_MEDLOW16_PCREL
6790 || r_type
== R_SH_IMM_MEDHI16_PCREL
6791 || r_type
== R_SH_IMM_HI16_PCREL
6799 case R_SH_TLS_LE_32
:
6802 (*_bfd_error_handler
) (_("%s: TLS local exec code cannot be linked into shared objects"),
6803 bfd_archive_filename (abfd
));
6809 case R_SH_TLS_LDO_32
:
6810 /* Nothing to do. */
6821 #ifndef sh_elf_set_mach_from_flags
6823 sh_elf_set_mach_from_flags (bfd
*abfd
)
6825 flagword flags
= elf_elfheader (abfd
)->e_flags
;
6827 switch (flags
& EF_SH_MACH_MASK
)
6830 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh
);
6833 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh2
);
6836 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh2e
);
6839 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh_dsp
);
6842 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3
);
6845 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3_dsp
);
6848 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3e
);
6852 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh4
);
6855 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh4_nofpu
);
6858 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh4a
);
6861 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh4a_nofpu
);
6864 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh4al_dsp
);
6866 case EF_SH4_NOMMU_NOFPU
:
6867 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh4_nommu_nofpu
);
6874 #endif /* not sh_elf_set_mach_from_flags */
6876 #ifndef sh_elf_set_private_flags
6877 /* Function to keep SH specific file flags. */
6880 sh_elf_set_private_flags (bfd
*abfd
, flagword flags
)
6882 BFD_ASSERT (! elf_flags_init (abfd
)
6883 || elf_elfheader (abfd
)->e_flags
== flags
);
6885 elf_elfheader (abfd
)->e_flags
= flags
;
6886 elf_flags_init (abfd
) = TRUE
;
6887 return sh_elf_set_mach_from_flags (abfd
);
6889 #endif /* not sh_elf_set_private_flags */
6891 #ifndef sh_elf_copy_private_data
6892 /* Copy backend specific data from one object module to another */
6895 sh_elf_copy_private_data (bfd
* ibfd
, bfd
* obfd
)
6897 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6898 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6901 return sh_elf_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
6903 #endif /* not sh_elf_copy_private_data */
6905 #ifndef sh_elf_merge_private_data
6906 /* This routine checks for linking big and little endian objects
6907 together, and for linking sh-dsp with sh3e / sh4 objects. */
6910 sh_elf_merge_private_data (bfd
*ibfd
, bfd
*obfd
)
6912 flagword old_flags
, new_flags
;
6914 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
6917 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
6918 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
6921 if (! elf_flags_init (obfd
))
6923 /* This happens when ld starts out with a 'blank' output file. */
6924 elf_flags_init (obfd
) = TRUE
;
6925 elf_elfheader (obfd
)->e_flags
= EF_SH1
;
6927 old_flags
= elf_elfheader (obfd
)->e_flags
;
6928 new_flags
= elf_elfheader (ibfd
)->e_flags
;
6929 if ((EF_SH_HAS_DSP (old_flags
) && EF_SH_HAS_FP (new_flags
))
6930 || (EF_SH_HAS_DSP (new_flags
) && EF_SH_HAS_FP (old_flags
)))
6932 (*_bfd_error_handler
)
6933 ("%s: uses %s instructions while previous modules use %s instructions",
6934 bfd_archive_filename (ibfd
),
6935 EF_SH_HAS_DSP (new_flags
) ? "dsp" : "floating point",
6936 EF_SH_HAS_DSP (new_flags
) ? "floating point" : "dsp");
6937 bfd_set_error (bfd_error_bad_value
);
6940 elf_elfheader (obfd
)->e_flags
= EF_SH_MERGE_MACH (old_flags
, new_flags
);
6942 return sh_elf_set_mach_from_flags (obfd
);
6944 #endif /* not sh_elf_merge_private_data */
6946 /* Override the generic function because we need to store sh_elf_obj_tdata
6947 as the specific tdata. We set also the machine architecture from flags
6951 sh_elf_object_p (bfd
*abfd
)
6953 return sh_elf_set_mach_from_flags (abfd
);
6956 /* Finish up dynamic symbol handling. We set the contents of various
6957 dynamic sections here. */
6960 sh_elf_finish_dynamic_symbol (bfd
*output_bfd
, struct bfd_link_info
*info
,
6961 struct elf_link_hash_entry
*h
,
6962 Elf_Internal_Sym
*sym
)
6964 struct elf_sh_link_hash_table
*htab
;
6966 htab
= sh_elf_hash_table (info
);
6968 if (h
->plt
.offset
!= (bfd_vma
) -1)
6976 Elf_Internal_Rela rel
;
6979 /* This symbol has an entry in the procedure linkage table. Set
6982 BFD_ASSERT (h
->dynindx
!= -1);
6985 sgot
= htab
->sgotplt
;
6986 srel
= htab
->srelplt
;
6987 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srel
!= NULL
);
6989 /* Get the index in the procedure linkage table which
6990 corresponds to this symbol. This is the index of this symbol
6991 in all the symbols for which we are making plt entries. The
6992 first entry in the procedure linkage table is reserved. */
6993 plt_index
= h
->plt
.offset
/ elf_sh_sizeof_plt (info
) - 1;
6995 /* Get the offset into the .got table of the entry that
6996 corresponds to this function. Each .got entry is 4 bytes.
6997 The first three are reserved. */
6998 got_offset
= (plt_index
+ 3) * 4;
7002 got_offset
-= GOT_BIAS
;
7005 /* Fill in the entry in the procedure linkage table. */
7008 if (elf_sh_plt_entry
== NULL
)
7010 elf_sh_plt_entry
= (bfd_big_endian (output_bfd
) ?
7011 elf_sh_plt_entry_be
: elf_sh_plt_entry_le
);
7013 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_plt_entry
,
7014 elf_sh_sizeof_plt (info
));
7015 #ifdef INCLUDE_SHMEDIA
7016 movi_shori_putval (output_bfd
,
7017 (sgot
->output_section
->vma
7018 + sgot
->output_offset
7020 (splt
->contents
+ h
->plt
.offset
7021 + elf_sh_plt_symbol_offset (info
)));
7023 /* Set bottom bit because its for a branch to SHmedia */
7024 movi_shori_putval (output_bfd
,
7025 (splt
->output_section
->vma
+ splt
->output_offset
)
7027 (splt
->contents
+ h
->plt
.offset
7028 + elf_sh_plt_plt0_offset (info
)));
7030 bfd_put_32 (output_bfd
,
7031 (sgot
->output_section
->vma
7032 + sgot
->output_offset
7034 (splt
->contents
+ h
->plt
.offset
7035 + elf_sh_plt_symbol_offset (info
)));
7037 bfd_put_32 (output_bfd
,
7038 (splt
->output_section
->vma
+ splt
->output_offset
),
7039 (splt
->contents
+ h
->plt
.offset
7040 + elf_sh_plt_plt0_offset (info
)));
7045 if (elf_sh_pic_plt_entry
== NULL
)
7047 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
7048 elf_sh_pic_plt_entry_be
:
7049 elf_sh_pic_plt_entry_le
);
7051 memcpy (splt
->contents
+ h
->plt
.offset
, elf_sh_pic_plt_entry
,
7052 elf_sh_sizeof_plt (info
));
7053 #ifdef INCLUDE_SHMEDIA
7054 movi_shori_putval (output_bfd
, got_offset
,
7055 (splt
->contents
+ h
->plt
.offset
7056 + elf_sh_plt_symbol_offset (info
)));
7058 bfd_put_32 (output_bfd
, got_offset
,
7059 (splt
->contents
+ h
->plt
.offset
7060 + elf_sh_plt_symbol_offset (info
)));
7066 got_offset
+= GOT_BIAS
;
7069 #ifdef INCLUDE_SHMEDIA
7070 movi_shori_putval (output_bfd
,
7071 plt_index
* sizeof (Elf32_External_Rela
),
7072 (splt
->contents
+ h
->plt
.offset
7073 + elf_sh_plt_reloc_offset (info
)));
7075 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
7076 (splt
->contents
+ h
->plt
.offset
7077 + elf_sh_plt_reloc_offset (info
)));
7080 /* Fill in the entry in the global offset table. */
7081 bfd_put_32 (output_bfd
,
7082 (splt
->output_section
->vma
7083 + splt
->output_offset
7085 + elf_sh_plt_temp_offset (info
)),
7086 sgot
->contents
+ got_offset
);
7088 /* Fill in the entry in the .rela.plt section. */
7089 rel
.r_offset
= (sgot
->output_section
->vma
7090 + sgot
->output_offset
7092 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_JMP_SLOT
);
7095 rel
.r_addend
= GOT_BIAS
;
7097 loc
= srel
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
7098 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7100 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
7102 /* Mark the symbol as undefined, rather than as defined in
7103 the .plt section. Leave the value alone. */
7104 sym
->st_shndx
= SHN_UNDEF
;
7108 if (h
->got
.offset
!= (bfd_vma
) -1
7109 && sh_elf_hash_entry (h
)->tls_type
!= GOT_TLS_GD
7110 && sh_elf_hash_entry (h
)->tls_type
!= GOT_TLS_IE
)
7114 Elf_Internal_Rela rel
;
7117 /* This symbol has an entry in the global offset table. Set it
7121 srel
= htab
->srelgot
;
7122 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
7124 rel
.r_offset
= (sgot
->output_section
->vma
7125 + sgot
->output_offset
7126 + (h
->got
.offset
&~ (bfd_vma
) 1));
7128 /* If this is a static link, or it is a -Bsymbolic link and the
7129 symbol is defined locally or was forced to be local because
7130 of a version file, we just want to emit a RELATIVE reloc.
7131 The entry in the global offset table will already have been
7132 initialized in the relocate_section function. */
7134 && SYMBOL_REFERENCES_LOCAL (info
, h
))
7136 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
7137 rel
.r_addend
= (h
->root
.u
.def
.value
7138 + h
->root
.u
.def
.section
->output_section
->vma
7139 + h
->root
.u
.def
.section
->output_offset
);
7143 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
7144 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
7148 loc
= srel
->contents
;
7149 loc
+= srel
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7150 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7153 #ifdef INCLUDE_SHMEDIA
7155 struct elf_sh_link_hash_entry
*eh
;
7157 eh
= (struct elf_sh_link_hash_entry
*) h
;
7158 if (eh
->datalabel_got
.offset
!= (bfd_vma
) -1)
7162 Elf_Internal_Rela rel
;
7165 /* This symbol has a datalabel entry in the global offset table.
7169 srel
= htab
->srelgot
;
7170 BFD_ASSERT (sgot
!= NULL
&& srel
!= NULL
);
7172 rel
.r_offset
= (sgot
->output_section
->vma
7173 + sgot
->output_offset
7174 + (eh
->datalabel_got
.offset
&~ (bfd_vma
) 1));
7176 /* If this is a static link, or it is a -Bsymbolic link and the
7177 symbol is defined locally or was forced to be local because
7178 of a version file, we just want to emit a RELATIVE reloc.
7179 The entry in the global offset table will already have been
7180 initialized in the relocate_section function. */
7182 && SYMBOL_REFERENCES_LOCAL (info
, h
))
7184 rel
.r_info
= ELF32_R_INFO (0, R_SH_RELATIVE
);
7185 rel
.r_addend
= (h
->root
.u
.def
.value
7186 + h
->root
.u
.def
.section
->output_section
->vma
7187 + h
->root
.u
.def
.section
->output_offset
);
7191 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
7192 + eh
->datalabel_got
.offset
);
7193 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_GLOB_DAT
);
7197 loc
= srel
->contents
;
7198 loc
+= srel
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7199 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7204 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
7207 Elf_Internal_Rela rel
;
7210 /* This symbol needs a copy reloc. Set it up. */
7212 BFD_ASSERT (h
->dynindx
!= -1
7213 && (h
->root
.type
== bfd_link_hash_defined
7214 || h
->root
.type
== bfd_link_hash_defweak
));
7216 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
7218 BFD_ASSERT (s
!= NULL
);
7220 rel
.r_offset
= (h
->root
.u
.def
.value
7221 + h
->root
.u
.def
.section
->output_section
->vma
7222 + h
->root
.u
.def
.section
->output_offset
);
7223 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SH_COPY
);
7225 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
7226 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
7229 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
7230 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
7231 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
7232 sym
->st_shndx
= SHN_ABS
;
7237 /* Finish up the dynamic sections. */
7240 sh_elf_finish_dynamic_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
7242 struct elf_sh_link_hash_table
*htab
;
7246 htab
= sh_elf_hash_table (info
);
7247 sgot
= htab
->sgotplt
;
7248 sdyn
= bfd_get_section_by_name (htab
->root
.dynobj
, ".dynamic");
7250 if (htab
->root
.dynamic_sections_created
)
7253 Elf32_External_Dyn
*dyncon
, *dynconend
;
7255 BFD_ASSERT (sgot
!= NULL
&& sdyn
!= NULL
);
7257 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
7258 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
7259 for (; dyncon
< dynconend
; dyncon
++)
7261 Elf_Internal_Dyn dyn
;
7263 #ifdef INCLUDE_SHMEDIA
7267 bfd_elf32_swap_dyn_in (htab
->root
.dynobj
, dyncon
, &dyn
);
7274 #ifdef INCLUDE_SHMEDIA
7276 name
= info
->init_function
;
7280 name
= info
->fini_function
;
7282 if (dyn
.d_un
.d_val
!= 0)
7284 struct elf_link_hash_entry
*h
;
7286 h
= elf_link_hash_lookup (&htab
->root
, name
,
7287 FALSE
, FALSE
, TRUE
);
7288 if (h
!= NULL
&& (h
->other
& STO_SH5_ISA32
))
7290 dyn
.d_un
.d_val
|= 1;
7291 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7298 s
= htab
->sgot
->output_section
;
7302 s
= htab
->srelplt
->output_section
;
7304 BFD_ASSERT (s
!= NULL
);
7305 dyn
.d_un
.d_ptr
= s
->vma
;
7306 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7310 s
= htab
->srelplt
->output_section
;
7311 BFD_ASSERT (s
!= NULL
);
7312 if (s
->_cooked_size
!= 0)
7313 dyn
.d_un
.d_val
= s
->_cooked_size
;
7315 dyn
.d_un
.d_val
= s
->_raw_size
;
7316 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7320 /* My reading of the SVR4 ABI indicates that the
7321 procedure linkage table relocs (DT_JMPREL) should be
7322 included in the overall relocs (DT_RELA). This is
7323 what Solaris does. However, UnixWare can not handle
7324 that case. Therefore, we override the DT_RELASZ entry
7325 here to make it not include the JMPREL relocs. Since
7326 the linker script arranges for .rela.plt to follow all
7327 other relocation sections, we don't have to worry
7328 about changing the DT_RELA entry. */
7329 if (htab
->srelplt
!= NULL
)
7331 s
= htab
->srelplt
->output_section
;
7332 if (s
->_cooked_size
!= 0)
7333 dyn
.d_un
.d_val
-= s
->_cooked_size
;
7335 dyn
.d_un
.d_val
-= s
->_raw_size
;
7337 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
7342 /* Fill in the first entry in the procedure linkage table. */
7344 if (splt
&& splt
->_raw_size
> 0)
7348 if (elf_sh_pic_plt_entry
== NULL
)
7350 elf_sh_pic_plt_entry
= (bfd_big_endian (output_bfd
) ?
7351 elf_sh_pic_plt_entry_be
:
7352 elf_sh_pic_plt_entry_le
);
7354 memcpy (splt
->contents
, elf_sh_pic_plt_entry
,
7355 elf_sh_sizeof_plt (info
));
7359 if (elf_sh_plt0_entry
== NULL
)
7361 elf_sh_plt0_entry
= (bfd_big_endian (output_bfd
) ?
7362 elf_sh_plt0_entry_be
:
7363 elf_sh_plt0_entry_le
);
7365 memcpy (splt
->contents
, elf_sh_plt0_entry
, PLT_ENTRY_SIZE
);
7366 #ifdef INCLUDE_SHMEDIA
7367 movi_shori_putval (output_bfd
,
7368 sgot
->output_section
->vma
7369 + sgot
->output_offset
,
7371 + elf_sh_plt0_gotplt_offset (info
));
7373 bfd_put_32 (output_bfd
,
7374 sgot
->output_section
->vma
+ sgot
->output_offset
+ 4,
7375 splt
->contents
+ elf_sh_plt0_gotid_offset (info
));
7376 bfd_put_32 (output_bfd
,
7377 sgot
->output_section
->vma
+ sgot
->output_offset
+ 8,
7378 splt
->contents
+ elf_sh_plt0_linker_offset (info
));
7382 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7383 really seem like the right value. */
7384 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
= 4;
7388 /* Fill in the first three entries in the global offset table. */
7389 if (sgot
&& sgot
->_raw_size
> 0)
7392 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
7394 bfd_put_32 (output_bfd
,
7395 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
7397 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
7398 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
7400 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
7406 static enum elf_reloc_type_class
7407 sh_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
7409 switch ((int) ELF32_R_TYPE (rela
->r_info
))
7412 return reloc_class_relative
;
7414 return reloc_class_plt
;
7416 return reloc_class_copy
;
7418 return reloc_class_normal
;
7422 /* Support for Linux core dump NOTE sections. */
7424 elf32_shlin_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
7427 unsigned int raw_size
;
7429 switch (note
->descsz
)
7434 case 168: /* Linux/SH */
7436 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
7439 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
7448 /* Make a ".reg/999" section. */
7449 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
7450 raw_size
, note
->descpos
+ offset
);
7454 elf32_shlin_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
7456 switch (note
->descsz
)
7461 case 124: /* Linux/SH elf_prpsinfo */
7462 elf_tdata (abfd
)->core_program
7463 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 28, 16);
7464 elf_tdata (abfd
)->core_command
7465 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 44, 80);
7468 /* Note that for some reason, a spurious space is tacked
7469 onto the end of the args in some (at least one anyway)
7470 implementations, so strip it off if it exists. */
7473 char *command
= elf_tdata (abfd
)->core_command
;
7474 int n
= strlen (command
);
7476 if (0 < n
&& command
[n
- 1] == ' ')
7477 command
[n
- 1] = '\0';
7484 /* Return address for Ith PLT stub in section PLT, for relocation REL
7485 or (bfd_vma) -1 if it should not be included. */
7488 sh_elf_plt_sym_val (bfd_vma i
, const asection
*plt
,
7489 const arelent
*rel ATTRIBUTE_UNUSED
)
7491 return plt
->vma
+ (i
+ 1) * PLT_ENTRY_SIZE
;
7494 #define TARGET_BIG_SYM bfd_elf32_sh_vec
7495 #define TARGET_BIG_NAME "elf32-sh"
7496 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
7497 #define TARGET_LITTLE_NAME "elf32-shl"
7498 #define ELF_ARCH bfd_arch_sh
7499 #define ELF_MACHINE_CODE EM_SH
7500 #ifdef __QNXTARGET__
7501 #define ELF_MAXPAGESIZE 0x1000
7503 #define ELF_MAXPAGESIZE 0x80
7506 #define elf_symbol_leading_char '_'
7508 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
7509 #define elf_info_to_howto sh_elf_info_to_howto
7510 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
7511 #define elf_backend_relocate_section sh_elf_relocate_section
7512 #define bfd_elf32_bfd_get_relocated_section_contents \
7513 sh_elf_get_relocated_section_contents
7514 #define bfd_elf32_mkobject sh_elf_mkobject
7515 #define elf_backend_object_p sh_elf_object_p
7516 #define bfd_elf32_bfd_set_private_bfd_flags \
7517 sh_elf_set_private_flags
7518 #define bfd_elf32_bfd_copy_private_bfd_data \
7519 sh_elf_copy_private_data
7520 #define bfd_elf32_bfd_merge_private_bfd_data \
7521 sh_elf_merge_private_data
7523 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
7524 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
7525 #define elf_backend_check_relocs sh_elf_check_relocs
7526 #define elf_backend_copy_indirect_symbol \
7527 sh_elf_copy_indirect_symbol
7528 #define elf_backend_create_dynamic_sections \
7529 sh_elf_create_dynamic_sections
7530 #define bfd_elf32_bfd_link_hash_table_create \
7531 sh_elf_link_hash_table_create
7532 #define elf_backend_adjust_dynamic_symbol \
7533 sh_elf_adjust_dynamic_symbol
7534 #define elf_backend_size_dynamic_sections \
7535 sh_elf_size_dynamic_sections
7536 #define elf_backend_finish_dynamic_symbol \
7537 sh_elf_finish_dynamic_symbol
7538 #define elf_backend_finish_dynamic_sections \
7539 sh_elf_finish_dynamic_sections
7540 #define elf_backend_reloc_type_class sh_elf_reloc_type_class
7541 #define elf_backend_plt_sym_val sh_elf_plt_sym_val
7543 #define elf_backend_can_gc_sections 1
7544 #define elf_backend_can_refcount 1
7545 #define elf_backend_want_got_plt 1
7546 #define elf_backend_plt_readonly 1
7547 #define elf_backend_want_plt_sym 0
7548 #define elf_backend_got_header_size 12
7550 #ifndef INCLUDE_SHMEDIA
7552 #include "elf32-target.h"
7554 /* NetBSD support. */
7555 #undef TARGET_BIG_SYM
7556 #define TARGET_BIG_SYM bfd_elf32_shnbsd_vec
7557 #undef TARGET_BIG_NAME
7558 #define TARGET_BIG_NAME "elf32-sh-nbsd"
7559 #undef TARGET_LITTLE_SYM
7560 #define TARGET_LITTLE_SYM bfd_elf32_shlnbsd_vec
7561 #undef TARGET_LITTLE_NAME
7562 #define TARGET_LITTLE_NAME "elf32-shl-nbsd"
7563 #undef ELF_MAXPAGESIZE
7564 #define ELF_MAXPAGESIZE 0x10000
7565 #undef elf_symbol_leading_char
7566 #define elf_symbol_leading_char 0
7568 #define elf32_bed elf32_sh_nbsd_bed
7570 #include "elf32-target.h"
7573 /* Linux support. */
7574 #undef TARGET_BIG_SYM
7575 #define TARGET_BIG_SYM bfd_elf32_shblin_vec
7576 #undef TARGET_BIG_NAME
7577 #define TARGET_BIG_NAME "elf32-shbig-linux"
7578 #undef TARGET_LITTLE_SYM
7579 #define TARGET_LITTLE_SYM bfd_elf32_shlin_vec
7580 #undef TARGET_LITTLE_NAME
7581 #define TARGET_LITTLE_NAME "elf32-sh-linux"
7583 #undef elf_backend_grok_prstatus
7584 #define elf_backend_grok_prstatus elf32_shlin_grok_prstatus
7585 #undef elf_backend_grok_psinfo
7586 #define elf_backend_grok_psinfo elf32_shlin_grok_psinfo
7588 #define elf32_bed elf32_sh_lin_bed
7590 #include "elf32-target.h"
7592 #endif /* INCLUDE_SHMEDIA */