1 /* Hitachi SH specific support for 32-bit ELF
2 Copyright 1996, 97, 98, 1999, 2000 Free Software Foundation, Inc.
3 Contributed by Ian Lance Taylor, Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 static bfd_reloc_status_type sh_elf_reloc
29 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
30 static bfd_reloc_status_type sh_elf_ignore_reloc
31 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
32 static reloc_howto_type
*sh_elf_reloc_type_lookup
33 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
34 static void sh_elf_info_to_howto
35 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
36 static boolean sh_elf_set_private_flags
37 PARAMS ((bfd
*, flagword
));
38 static boolean sh_elf_copy_private_data
39 PARAMS ((bfd
*, bfd
*));
40 static boolean sh_elf_merge_private_data
41 PARAMS ((bfd
*, bfd
*));
42 boolean sh_elf_set_mach_from_flags
44 static boolean sh_elf_relax_section
45 PARAMS ((bfd
*, asection
*, struct bfd_link_info
*, boolean
*));
46 static boolean sh_elf_relax_delete_bytes
47 PARAMS ((bfd
*, asection
*, bfd_vma
, int));
48 static boolean sh_elf_align_loads
49 PARAMS ((bfd
*, asection
*, Elf_Internal_Rela
*, bfd_byte
*, boolean
*));
50 static boolean sh_elf_swap_insns
51 PARAMS ((bfd
*, asection
*, PTR
, bfd_byte
*, bfd_vma
));
52 static boolean sh_elf_relocate_section
53 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
54 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
55 static bfd_byte
*sh_elf_get_relocated_section_contents
56 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
57 bfd_byte
*, boolean
, asymbol
**));
59 static reloc_howto_type sh_elf_howto_table
[] =
62 HOWTO (R_SH_NONE
, /* type */
64 0, /* size (0 = byte, 1 = short, 2 = long) */
66 false, /* pc_relative */
68 complain_overflow_dont
, /* complain_on_overflow */
69 sh_elf_ignore_reloc
, /* special_function */
70 "R_SH_NONE", /* name */
71 false, /* partial_inplace */
74 false), /* pcrel_offset */
76 /* 32 bit absolute relocation. Setting partial_inplace to true and
77 src_mask to a non-zero value is similar to the COFF toolchain. */
78 HOWTO (R_SH_DIR32
, /* type */
80 2, /* size (0 = byte, 1 = short, 2 = long) */
82 false, /* pc_relative */
84 complain_overflow_bitfield
, /* complain_on_overflow */
85 sh_elf_reloc
, /* special_function */
86 "R_SH_DIR32", /* name */
87 true, /* partial_inplace */
88 0xffffffff, /* src_mask */
89 0xffffffff, /* dst_mask */
90 false), /* pcrel_offset */
92 /* 32 bit PC relative relocation. */
93 HOWTO (R_SH_REL32
, /* type */
95 2, /* size (0 = byte, 1 = short, 2 = long) */
97 true, /* pc_relative */
99 complain_overflow_signed
, /* complain_on_overflow */
100 sh_elf_ignore_reloc
, /* special_function */
101 "R_SH_REL32", /* name */
102 false, /* partial_inplace */
104 0xffffffff, /* dst_mask */
105 true), /* pcrel_offset */
107 /* 8 bit PC relative branch divided by 2. */
108 HOWTO (R_SH_DIR8WPN
, /* type */
110 1, /* size (0 = byte, 1 = short, 2 = long) */
112 true, /* pc_relative */
114 complain_overflow_signed
, /* complain_on_overflow */
115 sh_elf_ignore_reloc
, /* special_function */
116 "R_SH_DIR8WPN", /* name */
117 true, /* partial_inplace */
120 true), /* pcrel_offset */
122 /* 12 bit PC relative branch divided by 2. */
123 HOWTO (R_SH_IND12W
, /* type */
125 1, /* size (0 = byte, 1 = short, 2 = long) */
127 true, /* pc_relative */
129 complain_overflow_signed
, /* complain_on_overflow */
130 sh_elf_reloc
, /* special_function */
131 "R_SH_IND12W", /* name */
132 true, /* partial_inplace */
133 0xfff, /* src_mask */
134 0xfff, /* dst_mask */
135 true), /* pcrel_offset */
137 /* 8 bit unsigned PC relative divided by 4. */
138 HOWTO (R_SH_DIR8WPL
, /* type */
140 1, /* size (0 = byte, 1 = short, 2 = long) */
142 true, /* pc_relative */
144 complain_overflow_unsigned
, /* complain_on_overflow */
145 sh_elf_ignore_reloc
, /* special_function */
146 "R_SH_DIR8WPL", /* name */
147 true, /* partial_inplace */
150 true), /* pcrel_offset */
152 /* 8 bit unsigned PC relative divided by 2. */
153 HOWTO (R_SH_DIR8WPZ
, /* type */
155 1, /* size (0 = byte, 1 = short, 2 = long) */
157 true, /* pc_relative */
159 complain_overflow_unsigned
, /* complain_on_overflow */
160 sh_elf_ignore_reloc
, /* special_function */
161 "R_SH_DIR8WPZ", /* name */
162 true, /* partial_inplace */
165 true), /* pcrel_offset */
167 /* 8 bit GBR relative. FIXME: This only makes sense if we have some
168 special symbol for the GBR relative area, and that is not
170 HOWTO (R_SH_DIR8BP
, /* type */
172 1, /* size (0 = byte, 1 = short, 2 = long) */
174 false, /* pc_relative */
176 complain_overflow_unsigned
, /* complain_on_overflow */
177 sh_elf_ignore_reloc
, /* special_function */
178 "R_SH_DIR8BP", /* name */
179 false, /* partial_inplace */
182 true), /* pcrel_offset */
184 /* 8 bit GBR relative divided by 2. FIXME: This only makes sense if
185 we have some special symbol for the GBR relative area, and that
186 is not implemented. */
187 HOWTO (R_SH_DIR8W
, /* type */
189 1, /* size (0 = byte, 1 = short, 2 = long) */
191 false, /* pc_relative */
193 complain_overflow_unsigned
, /* complain_on_overflow */
194 sh_elf_ignore_reloc
, /* special_function */
195 "R_SH_DIR8W", /* name */
196 false, /* partial_inplace */
199 true), /* pcrel_offset */
201 /* 8 bit GBR relative divided by 4. FIXME: This only makes sense if
202 we have some special symbol for the GBR relative area, and that
203 is not implemented. */
204 HOWTO (R_SH_DIR8L
, /* type */
206 1, /* size (0 = byte, 1 = short, 2 = long) */
208 false, /* pc_relative */
210 complain_overflow_unsigned
, /* complain_on_overflow */
211 sh_elf_ignore_reloc
, /* special_function */
212 "R_SH_DIR8L", /* name */
213 false, /* partial_inplace */
216 true), /* pcrel_offset */
234 /* The remaining relocs are a GNU extension used for relaxing. The
235 final pass of the linker never needs to do anything with any of
236 these relocs. Any required operations are handled by the
239 /* A 16 bit switch table entry. This is generated for an expression
240 such as ``.word L1 - L2''. The offset holds the difference
241 between the reloc address and L2. */
242 HOWTO (R_SH_SWITCH16
, /* type */
244 1, /* size (0 = byte, 1 = short, 2 = long) */
246 false, /* pc_relative */
248 complain_overflow_unsigned
, /* complain_on_overflow */
249 sh_elf_ignore_reloc
, /* special_function */
250 "R_SH_SWITCH16", /* name */
251 false, /* partial_inplace */
254 true), /* pcrel_offset */
256 /* A 32 bit switch table entry. This is generated for an expression
257 such as ``.long L1 - L2''. The offset holds the difference
258 between the reloc address and L2. */
259 HOWTO (R_SH_SWITCH32
, /* type */
261 2, /* size (0 = byte, 1 = short, 2 = long) */
263 false, /* pc_relative */
265 complain_overflow_unsigned
, /* complain_on_overflow */
266 sh_elf_ignore_reloc
, /* special_function */
267 "R_SH_SWITCH32", /* name */
268 false, /* partial_inplace */
271 true), /* pcrel_offset */
273 /* Indicates a .uses pseudo-op. The compiler will generate .uses
274 pseudo-ops when it finds a function call which can be relaxed.
275 The offset field holds the PC relative offset to the instruction
276 which loads the register used in the function call. */
277 HOWTO (R_SH_USES
, /* type */
279 1, /* size (0 = byte, 1 = short, 2 = long) */
281 false, /* pc_relative */
283 complain_overflow_unsigned
, /* complain_on_overflow */
284 sh_elf_ignore_reloc
, /* special_function */
285 "R_SH_USES", /* name */
286 false, /* partial_inplace */
289 true), /* pcrel_offset */
291 /* The assembler will generate this reloc for addresses referred to
292 by the register loads associated with USES relocs. The offset
293 field holds the number of times the address is referenced in the
295 HOWTO (R_SH_COUNT
, /* type */
297 1, /* size (0 = byte, 1 = short, 2 = long) */
299 false, /* pc_relative */
301 complain_overflow_unsigned
, /* complain_on_overflow */
302 sh_elf_ignore_reloc
, /* special_function */
303 "R_SH_COUNT", /* name */
304 false, /* partial_inplace */
307 true), /* pcrel_offset */
309 /* Indicates an alignment statement. The offset field is the power
310 of 2 to which subsequent portions of the object file must be
312 HOWTO (R_SH_ALIGN
, /* type */
314 1, /* size (0 = byte, 1 = short, 2 = long) */
316 false, /* pc_relative */
318 complain_overflow_unsigned
, /* complain_on_overflow */
319 sh_elf_ignore_reloc
, /* special_function */
320 "R_SH_ALIGN", /* name */
321 false, /* partial_inplace */
324 true), /* pcrel_offset */
326 /* The assembler will generate this reloc before a block of
327 instructions. A section should be processed as assumining it
328 contains data, unless this reloc is seen. */
329 HOWTO (R_SH_CODE
, /* type */
331 1, /* size (0 = byte, 1 = short, 2 = long) */
333 false, /* pc_relative */
335 complain_overflow_unsigned
, /* complain_on_overflow */
336 sh_elf_ignore_reloc
, /* special_function */
337 "R_SH_CODE", /* name */
338 false, /* partial_inplace */
341 true), /* pcrel_offset */
343 /* The assembler will generate this reloc after a block of
344 instructions when it sees data that is not instructions. */
345 HOWTO (R_SH_DATA
, /* type */
347 1, /* size (0 = byte, 1 = short, 2 = long) */
349 false, /* pc_relative */
351 complain_overflow_unsigned
, /* complain_on_overflow */
352 sh_elf_ignore_reloc
, /* special_function */
353 "R_SH_DATA", /* name */
354 false, /* partial_inplace */
357 true), /* pcrel_offset */
359 /* The assembler generates this reloc for each label within a block
360 of instructions. This permits the linker to avoid swapping
361 instructions which are the targets of branches. */
362 HOWTO (R_SH_LABEL
, /* type */
364 1, /* size (0 = byte, 1 = short, 2 = long) */
366 false, /* pc_relative */
368 complain_overflow_unsigned
, /* complain_on_overflow */
369 sh_elf_ignore_reloc
, /* special_function */
370 "R_SH_LABEL", /* name */
371 false, /* partial_inplace */
374 true), /* pcrel_offset */
376 /* An 8 bit switch table entry. This is generated for an expression
377 such as ``.word L1 - L2''. The offset holds the difference
378 between the reloc address and L2. */
379 HOWTO (R_SH_SWITCH8
, /* type */
381 0, /* size (0 = byte, 1 = short, 2 = long) */
383 false, /* pc_relative */
385 complain_overflow_unsigned
, /* complain_on_overflow */
386 sh_elf_ignore_reloc
, /* special_function */
387 "R_SH_SWITCH8", /* name */
388 false, /* partial_inplace */
391 true), /* pcrel_offset */
393 /* GNU extension to record C++ vtable hierarchy */
394 HOWTO (R_SH_GNU_VTINHERIT
, /* type */
396 2, /* size (0 = byte, 1 = short, 2 = long) */
398 false, /* pc_relative */
400 complain_overflow_dont
, /* complain_on_overflow */
401 NULL
, /* special_function */
402 "R_SH_GNU_VTINHERIT", /* name */
403 false, /* partial_inplace */
406 false), /* pcrel_offset */
408 /* GNU extension to record C++ vtable member usage */
409 HOWTO (R_SH_GNU_VTENTRY
, /* type */
411 2, /* size (0 = byte, 1 = short, 2 = long) */
413 false, /* pc_relative */
415 complain_overflow_dont
, /* complain_on_overflow */
416 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
417 "R_SH_GNU_VTENTRY", /* name */
418 false, /* partial_inplace */
421 false), /* pcrel_offset */
423 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
424 HOWTO (R_SH_LOOP_START
, /* type */
426 1, /* size (0 = byte, 1 = short, 2 = long) */
428 false, /* pc_relative */
430 complain_overflow_signed
, /* complain_on_overflow */
431 sh_elf_ignore_reloc
, /* special_function */
432 "R_SH_LOOP_START", /* name */
433 true, /* partial_inplace */
436 true), /* pcrel_offset */
438 /* 8 bit PC relative divided by 2 - but specified in a very odd way. */
439 HOWTO (R_SH_LOOP_END
, /* type */
441 1, /* size (0 = byte, 1 = short, 2 = long) */
443 false, /* pc_relative */
445 complain_overflow_signed
, /* complain_on_overflow */
446 sh_elf_ignore_reloc
, /* special_function */
447 "R_SH_LOOP_END", /* name */
448 true, /* partial_inplace */
451 true), /* pcrel_offset */
455 static bfd_reloc_status_type
456 sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
, addr
,
457 symbol_section
, start
, end
)
460 asection
*input_section
;
463 asection
*symbol_section
;
466 static bfd_vma last_addr
;
467 asection
*last_symbol_section
;
468 bfd_byte
*free_contents
= NULL
;
469 bfd_byte
*start_ptr
, *ptr
, *last_ptr
;
474 /* Sanity check the address. */
475 if (addr
> input_section
->_raw_size
)
476 return bfd_reloc_outofrange
;
478 /* We require the start and end relocations to be processed consecutively -
479 although we allow then to be processed forwards or backwards. */
483 last_symbol_section
= symbol_section
;
486 if (last_addr
!= addr
)
490 if (! symbol_section
|| last_symbol_section
!= symbol_section
|| end
< start
)
491 return bfd_reloc_outofrange
;
493 /* Get the symbol_section contents. */
494 if (symbol_section
!= input_section
)
496 if (elf_section_data (symbol_section
)->this_hdr
.contents
!= NULL
)
497 contents
= elf_section_data (symbol_section
)->this_hdr
.contents
;
500 free_contents
= contents
501 = (bfd_byte
*) bfd_malloc (symbol_section
->_raw_size
);
502 if (contents
== NULL
)
503 return bfd_reloc_outofrange
;
504 if (! bfd_get_section_contents (input_bfd
, symbol_section
, contents
,
506 symbol_section
->_raw_size
))
509 return bfd_reloc_outofrange
;
513 #define IS_PPI(PTR) ((bfd_get_16 (input_bfd, (PTR)) & 0xfc00) == 0xf800)
514 start_ptr
= contents
+ start
;
515 for (cum_diff
= -6, ptr
= contents
+ end
; cum_diff
< 0 && ptr
> start_ptr
;)
517 for (last_ptr
= ptr
, ptr
-= 4; ptr
>= start_ptr
&& IS_PPI (ptr
);)
520 diff
= last_ptr
- ptr
>> 1;
521 cum_diff
+= diff
& 1;
524 /* Calculate the start / end values to load into rs / re minus four -
525 so that will cancel out the four we would otherwise have to add to
526 addr to get the value to subtract in order to get relative addressing. */
530 end
= (ptr
+ cum_diff
* 2) - contents
;
534 bfd_vma start0
= start
- 4;
536 while (start0
>= 0 && IS_PPI (contents
+ start0
))
538 start0
= start
- 2 - ((start
- start0
) & 2);
539 start
= start0
- cum_diff
- 2;
544 free (free_contents
);
546 insn
= bfd_get_16 (input_bfd
, contents
+ addr
);
548 x
= (insn
& 0x200 ? end
: start
) - addr
;
549 if (input_section
!= symbol_section
)
550 x
+= ((symbol_section
->output_section
->vma
+ symbol_section
->output_offset
)
551 - (input_section
->output_section
->vma
552 + input_section
->output_offset
));
554 if (x
< -128 || x
> 127)
555 return bfd_reloc_overflow
;
557 x
= insn
& ~0xff | x
& 0xff;
558 bfd_put_16 (input_bfd
, x
, contents
+ addr
);
563 /* This function is used for normal relocs. This used to be like the COFF
564 function, and is almost certainly incorrect for other ELF targets. */
566 static bfd_reloc_status_type
567 sh_elf_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
570 arelent
*reloc_entry
;
573 asection
*input_section
;
575 char **error_message ATTRIBUTE_UNUSED
;
579 enum elf_sh_reloc_type r_type
;
580 bfd_vma addr
= reloc_entry
->address
;
581 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
583 r_type
= (enum elf_sh_reloc_type
) reloc_entry
->howto
->type
;
585 if (output_bfd
!= NULL
)
587 /* Partial linking--do nothing. */
588 reloc_entry
->address
+= input_section
->output_offset
;
592 /* Almost all relocs have to do with relaxing. If any work must be
593 done for them, it has been done in sh_relax_section. */
594 if (r_type
== R_SH_IND12W
&& (symbol_in
->flags
& BSF_LOCAL
) != 0)
597 if (symbol_in
!= NULL
598 && bfd_is_und_section (symbol_in
->section
))
599 return bfd_reloc_undefined
;
601 if (bfd_is_com_section (symbol_in
->section
))
604 sym_value
= (symbol_in
->value
+
605 symbol_in
->section
->output_section
->vma
+
606 symbol_in
->section
->output_offset
);
611 insn
= bfd_get_32 (abfd
, hit_data
);
612 insn
+= sym_value
+ reloc_entry
->addend
;
613 bfd_put_32 (abfd
, insn
, hit_data
);
616 insn
= bfd_get_16 (abfd
, hit_data
);
617 sym_value
+= reloc_entry
->addend
;
618 sym_value
-= (input_section
->output_section
->vma
619 + input_section
->output_offset
622 sym_value
+= (insn
& 0xfff) << 1;
625 insn
= (insn
& 0xf000) | (sym_value
& 0xfff);
626 bfd_put_16 (abfd
, insn
, hit_data
);
627 if (sym_value
< (bfd_vma
) -0x1000 || sym_value
>= 0x1000)
628 return bfd_reloc_overflow
;
638 /* This function is used for relocs which are only used for relaxing,
639 which the linker should otherwise ignore. */
641 static bfd_reloc_status_type
642 sh_elf_ignore_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
643 output_bfd
, error_message
)
644 bfd
*abfd ATTRIBUTE_UNUSED
;
645 arelent
*reloc_entry
;
646 asymbol
*symbol ATTRIBUTE_UNUSED
;
647 PTR data ATTRIBUTE_UNUSED
;
648 asection
*input_section
;
650 char **error_message ATTRIBUTE_UNUSED
;
652 if (output_bfd
!= NULL
)
653 reloc_entry
->address
+= input_section
->output_offset
;
657 /* This structure is used to map BFD reloc codes to SH ELF relocs. */
661 bfd_reloc_code_real_type bfd_reloc_val
;
662 unsigned char elf_reloc_val
;
665 /* An array mapping BFD reloc codes to SH ELF relocs. */
667 static const struct elf_reloc_map sh_reloc_map
[] =
669 { BFD_RELOC_NONE
, R_SH_NONE
},
670 { BFD_RELOC_32
, R_SH_DIR32
},
671 { BFD_RELOC_CTOR
, R_SH_DIR32
},
672 { BFD_RELOC_32_PCREL
, R_SH_REL32
},
673 { BFD_RELOC_SH_PCDISP8BY2
, R_SH_DIR8WPN
},
674 { BFD_RELOC_SH_PCDISP12BY2
, R_SH_IND12W
},
675 { BFD_RELOC_SH_PCRELIMM8BY2
, R_SH_DIR8WPZ
},
676 { BFD_RELOC_SH_PCRELIMM8BY4
, R_SH_DIR8WPL
},
677 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
678 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
679 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
680 { BFD_RELOC_SH_USES
, R_SH_USES
},
681 { BFD_RELOC_SH_COUNT
, R_SH_COUNT
},
682 { BFD_RELOC_SH_ALIGN
, R_SH_ALIGN
},
683 { BFD_RELOC_SH_CODE
, R_SH_CODE
},
684 { BFD_RELOC_SH_DATA
, R_SH_DATA
},
685 { BFD_RELOC_SH_LABEL
, R_SH_LABEL
},
686 { BFD_RELOC_VTABLE_INHERIT
, R_SH_GNU_VTINHERIT
},
687 { BFD_RELOC_VTABLE_ENTRY
, R_SH_GNU_VTENTRY
},
688 { BFD_RELOC_SH_LOOP_START
, R_SH_LOOP_START
},
689 { BFD_RELOC_SH_LOOP_END
, R_SH_LOOP_END
},
692 /* Given a BFD reloc code, return the howto structure for the
693 corresponding SH ELf reloc. */
695 static reloc_howto_type
*
696 sh_elf_reloc_type_lookup (abfd
, code
)
697 bfd
*abfd ATTRIBUTE_UNUSED
;
698 bfd_reloc_code_real_type code
;
702 for (i
= 0; i
< sizeof (sh_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
704 if (sh_reloc_map
[i
].bfd_reloc_val
== code
)
705 return &sh_elf_howto_table
[(int) sh_reloc_map
[i
].elf_reloc_val
];
711 /* Given an ELF reloc, fill in the howto field of a relent. */
714 sh_elf_info_to_howto (abfd
, cache_ptr
, dst
)
715 bfd
*abfd ATTRIBUTE_UNUSED
;
717 Elf_Internal_Rela
*dst
;
721 r
= ELF32_R_TYPE (dst
->r_info
);
723 BFD_ASSERT (r
< (unsigned int) R_SH_max
);
724 BFD_ASSERT (r
< R_SH_FIRST_INVALID_RELOC
|| r
> R_SH_LAST_INVALID_RELOC
);
726 cache_ptr
->howto
= &sh_elf_howto_table
[r
];
729 /* This function handles relaxing for SH ELF. See the corresponding
730 function in coff-sh.c for a description of what this does. FIXME:
731 There is a lot of duplication here between this code and the COFF
732 specific code. The format of relocs and symbols is wound deeply
733 into this code, but it would still be better if the duplication
734 could be eliminated somehow. Note in particular that although both
735 functions use symbols like R_SH_CODE, those symbols have different
736 values; in coff-sh.c they come from include/coff/sh.h, whereas here
737 they come from enum elf_sh_reloc_type in include/elf/sh.h. */
740 sh_elf_relax_section (abfd
, sec
, link_info
, again
)
743 struct bfd_link_info
*link_info
;
746 Elf_Internal_Shdr
*symtab_hdr
;
747 Elf_Internal_Rela
*internal_relocs
;
748 Elf_Internal_Rela
*free_relocs
= NULL
;
750 Elf_Internal_Rela
*irel
, *irelend
;
751 bfd_byte
*contents
= NULL
;
752 bfd_byte
*free_contents
= NULL
;
753 Elf32_External_Sym
*extsyms
= NULL
;
754 Elf32_External_Sym
*free_extsyms
= NULL
;
758 if (link_info
->relocateable
759 || (sec
->flags
& SEC_RELOC
) == 0
760 || sec
->reloc_count
== 0)
763 /* If this is the first time we have been called for this section,
764 initialize the cooked size. */
765 if (sec
->_cooked_size
== 0)
766 sec
->_cooked_size
= sec
->_raw_size
;
768 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
770 internal_relocs
= (_bfd_elf32_link_read_relocs
771 (abfd
, sec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
772 link_info
->keep_memory
));
773 if (internal_relocs
== NULL
)
775 if (! link_info
->keep_memory
)
776 free_relocs
= internal_relocs
;
780 irelend
= internal_relocs
+ sec
->reloc_count
;
781 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
783 bfd_vma laddr
, paddr
, symval
;
785 Elf_Internal_Rela
*irelfn
, *irelscan
, *irelcount
;
788 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_CODE
)
791 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_USES
)
794 /* Get the section contents. */
795 if (contents
== NULL
)
797 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
798 contents
= elf_section_data (sec
)->this_hdr
.contents
;
801 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
802 if (contents
== NULL
)
804 free_contents
= contents
;
806 if (! bfd_get_section_contents (abfd
, sec
, contents
,
807 (file_ptr
) 0, sec
->_raw_size
))
812 /* The r_addend field of the R_SH_USES reloc will point us to
813 the register load. The 4 is because the r_addend field is
814 computed as though it were a jump offset, which are based
815 from 4 bytes after the jump instruction. */
816 laddr
= irel
->r_offset
+ 4 + irel
->r_addend
;
817 if (laddr
>= sec
->_raw_size
)
819 (*_bfd_error_handler
) (_("%s: 0x%lx: warning: bad R_SH_USES offset"),
820 bfd_get_filename (abfd
),
821 (unsigned long) irel
->r_offset
);
824 insn
= bfd_get_16 (abfd
, contents
+ laddr
);
826 /* If the instruction is not mov.l NN,rN, we don't know what to
828 if ((insn
& 0xf000) != 0xd000)
830 ((*_bfd_error_handler
)
831 (_("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x"),
832 bfd_get_filename (abfd
), (unsigned long) irel
->r_offset
, insn
));
836 /* Get the address from which the register is being loaded. The
837 displacement in the mov.l instruction is quadrupled. It is a
838 displacement from four bytes after the movl instruction, but,
839 before adding in the PC address, two least significant bits
840 of the PC are cleared. We assume that the section is aligned
841 on a four byte boundary. */
844 paddr
+= (laddr
+ 4) &~ 3;
845 if (paddr
>= sec
->_raw_size
)
847 ((*_bfd_error_handler
)
848 (_("%s: 0x%lx: warning: bad R_SH_USES load offset"),
849 bfd_get_filename (abfd
), (unsigned long) irel
->r_offset
));
853 /* Get the reloc for the address from which the register is
854 being loaded. This reloc will tell us which function is
855 actually being called. */
856 for (irelfn
= internal_relocs
; irelfn
< irelend
; irelfn
++)
857 if (irelfn
->r_offset
== paddr
858 && ELF32_R_TYPE (irelfn
->r_info
) == (int) R_SH_DIR32
)
860 if (irelfn
>= irelend
)
862 ((*_bfd_error_handler
)
863 (_("%s: 0x%lx: warning: could not find expected reloc"),
864 bfd_get_filename (abfd
), (unsigned long) paddr
));
868 /* Read this BFD's symbols if we haven't done so already. */
871 if (symtab_hdr
->contents
!= NULL
)
872 extsyms
= (Elf32_External_Sym
*) symtab_hdr
->contents
;
875 extsyms
= ((Elf32_External_Sym
*)
876 bfd_malloc (symtab_hdr
->sh_size
));
879 free_extsyms
= extsyms
;
880 if (bfd_seek (abfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
881 || (bfd_read (extsyms
, 1, symtab_hdr
->sh_size
, abfd
)
882 != symtab_hdr
->sh_size
))
887 /* Get the value of the symbol referred to by the reloc. */
888 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
890 Elf_Internal_Sym isym
;
892 /* A local symbol. */
893 bfd_elf32_swap_symbol_in (abfd
,
894 extsyms
+ ELF32_R_SYM (irelfn
->r_info
),
897 if (isym
.st_shndx
!= _bfd_elf_section_from_bfd_section (abfd
, sec
))
899 ((*_bfd_error_handler
)
900 (_("%s: 0x%lx: warning: symbol in unexpected section"),
901 bfd_get_filename (abfd
), (unsigned long) paddr
));
905 symval
= (isym
.st_value
906 + sec
->output_section
->vma
907 + sec
->output_offset
);
912 struct elf_link_hash_entry
*h
;
914 indx
= ELF32_R_SYM (irelfn
->r_info
) - symtab_hdr
->sh_info
;
915 h
= elf_sym_hashes (abfd
)[indx
];
916 BFD_ASSERT (h
!= NULL
);
917 if (h
->root
.type
!= bfd_link_hash_defined
918 && h
->root
.type
!= bfd_link_hash_defweak
)
920 /* This appears to be a reference to an undefined
921 symbol. Just ignore it--it will be caught by the
922 regular reloc processing. */
926 symval
= (h
->root
.u
.def
.value
927 + h
->root
.u
.def
.section
->output_section
->vma
928 + h
->root
.u
.def
.section
->output_offset
);
931 symval
+= bfd_get_32 (abfd
, contents
+ paddr
);
933 /* See if this function call can be shortened. */
936 + sec
->output_section
->vma
939 if (foff
< -0x1000 || foff
>= 0x1000)
941 /* After all that work, we can't shorten this function call. */
945 /* Shorten the function call. */
947 /* For simplicity of coding, we are going to modify the section
948 contents, the section relocs, and the BFD symbol table. We
949 must tell the rest of the code not to free up this
950 information. It would be possible to instead create a table
951 of changes which have to be made, as is done in coff-mips.c;
952 that would be more work, but would require less memory when
953 the linker is run. */
955 elf_section_data (sec
)->relocs
= internal_relocs
;
958 elf_section_data (sec
)->this_hdr
.contents
= contents
;
959 free_contents
= NULL
;
961 symtab_hdr
->contents
= (bfd_byte
*) extsyms
;
964 /* Replace the jsr with a bsr. */
966 /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
967 replace the jsr with a bsr. */
968 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irelfn
->r_info
), R_SH_IND12W
);
969 if (ELF32_R_SYM (irelfn
->r_info
) < symtab_hdr
->sh_info
)
971 /* If this needs to be changed because of future relaxing,
972 it will be handled here like other internal IND12W
975 0xb000 | ((foff
>> 1) & 0xfff),
976 contents
+ irel
->r_offset
);
980 /* We can't fully resolve this yet, because the external
981 symbol value may be changed by future relaxing. We let
982 the final link phase handle it. */
983 bfd_put_16 (abfd
, 0xb000, contents
+ irel
->r_offset
);
986 /* See if there is another R_SH_USES reloc referring to the same
988 for (irelscan
= internal_relocs
; irelscan
< irelend
; irelscan
++)
989 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_USES
990 && laddr
== irelscan
->r_offset
+ 4 + irelscan
->r_addend
)
992 if (irelscan
< irelend
)
994 /* Some other function call depends upon this register load,
995 and we have not yet converted that function call.
996 Indeed, we may never be able to convert it. There is
997 nothing else we can do at this point. */
1001 /* Look for a R_SH_COUNT reloc on the location where the
1002 function address is stored. Do this before deleting any
1003 bytes, to avoid confusion about the address. */
1004 for (irelcount
= internal_relocs
; irelcount
< irelend
; irelcount
++)
1005 if (irelcount
->r_offset
== paddr
1006 && ELF32_R_TYPE (irelcount
->r_info
) == (int) R_SH_COUNT
)
1009 /* Delete the register load. */
1010 if (! sh_elf_relax_delete_bytes (abfd
, sec
, laddr
, 2))
1013 /* That will change things, so, just in case it permits some
1014 other function call to come within range, we should relax
1015 again. Note that this is not required, and it may be slow. */
1018 /* Now check whether we got a COUNT reloc. */
1019 if (irelcount
>= irelend
)
1021 ((*_bfd_error_handler
)
1022 (_("%s: 0x%lx: warning: could not find expected COUNT reloc"),
1023 bfd_get_filename (abfd
), (unsigned long) paddr
));
1027 /* The number of uses is stored in the r_addend field. We've
1028 just deleted one. */
1029 if (irelcount
->r_addend
== 0)
1031 ((*_bfd_error_handler
) (_("%s: 0x%lx: warning: bad count"),
1032 bfd_get_filename (abfd
),
1033 (unsigned long) paddr
));
1037 --irelcount
->r_addend
;
1039 /* If there are no more uses, we can delete the address. Reload
1040 the address from irelfn, in case it was changed by the
1041 previous call to sh_elf_relax_delete_bytes. */
1042 if (irelcount
->r_addend
== 0)
1044 if (! sh_elf_relax_delete_bytes (abfd
, sec
, irelfn
->r_offset
, 4))
1048 /* We've done all we can with that function call. */
1051 /* Look for load and store instructions that we can align on four
1057 /* Get the section contents. */
1058 if (contents
== NULL
)
1060 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
1061 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1064 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
1065 if (contents
== NULL
)
1067 free_contents
= contents
;
1069 if (! bfd_get_section_contents (abfd
, sec
, contents
,
1070 (file_ptr
) 0, sec
->_raw_size
))
1075 if (! sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
,
1081 elf_section_data (sec
)->relocs
= internal_relocs
;
1084 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1085 free_contents
= NULL
;
1087 symtab_hdr
->contents
= (bfd_byte
*) extsyms
;
1088 free_extsyms
= NULL
;
1092 if (free_relocs
!= NULL
)
1098 if (free_contents
!= NULL
)
1100 if (! link_info
->keep_memory
)
1101 free (free_contents
);
1104 /* Cache the section contents for elf_link_input_bfd. */
1105 elf_section_data (sec
)->this_hdr
.contents
= contents
;
1107 free_contents
= NULL
;
1110 if (free_extsyms
!= NULL
)
1112 if (! link_info
->keep_memory
)
1113 free (free_extsyms
);
1116 /* Cache the symbols for elf_link_input_bfd. */
1117 symtab_hdr
->contents
= extsyms
;
1119 free_extsyms
= NULL
;
1125 if (free_relocs
!= NULL
)
1127 if (free_contents
!= NULL
)
1128 free (free_contents
);
1129 if (free_extsyms
!= NULL
)
1130 free (free_extsyms
);
1134 /* Delete some bytes from a section while relaxing. FIXME: There is a
1135 lot of duplication between this function and sh_relax_delete_bytes
1139 sh_elf_relax_delete_bytes (abfd
, sec
, addr
, count
)
1145 Elf_Internal_Shdr
*symtab_hdr
;
1146 Elf32_External_Sym
*extsyms
;
1149 Elf_Internal_Rela
*irel
, *irelend
;
1150 Elf_Internal_Rela
*irelalign
;
1152 Elf32_External_Sym
*esym
, *esymend
;
1153 struct elf_link_hash_entry
*sym_hash
;
1156 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1157 extsyms
= (Elf32_External_Sym
*) symtab_hdr
->contents
;
1159 shndx
= _bfd_elf_section_from_bfd_section (abfd
, sec
);
1161 contents
= elf_section_data (sec
)->this_hdr
.contents
;
1163 /* The deletion must stop at the next ALIGN reloc for an aligment
1164 power larger than the number of bytes we are deleting. */
1167 toaddr
= sec
->_cooked_size
;
1169 irel
= elf_section_data (sec
)->relocs
;
1170 irelend
= irel
+ sec
->reloc_count
;
1171 for (; irel
< irelend
; irel
++)
1173 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
1174 && irel
->r_offset
> addr
1175 && count
< (1 << irel
->r_addend
))
1178 toaddr
= irel
->r_offset
;
1183 /* Actually delete the bytes. */
1184 memmove (contents
+ addr
, contents
+ addr
+ count
, toaddr
- addr
- count
);
1185 if (irelalign
== NULL
)
1186 sec
->_cooked_size
-= count
;
1191 #define NOP_OPCODE (0x0009)
1193 BFD_ASSERT ((count
& 1) == 0);
1194 for (i
= 0; i
< count
; i
+= 2)
1195 bfd_put_16 (abfd
, NOP_OPCODE
, contents
+ toaddr
- count
+ i
);
1198 /* Adjust all the relocs. */
1199 for (irel
= elf_section_data (sec
)->relocs
; irel
< irelend
; irel
++)
1201 bfd_vma nraddr
, stop
;
1204 Elf_Internal_Sym sym
;
1205 int off
, adjust
, oinsn
;
1206 bfd_signed_vma voff
= 0;
1209 /* Get the new reloc address. */
1210 nraddr
= irel
->r_offset
;
1211 if ((irel
->r_offset
> addr
1212 && irel
->r_offset
< toaddr
)
1213 || (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_ALIGN
1214 && irel
->r_offset
== toaddr
))
1217 /* See if this reloc was for the bytes we have deleted, in which
1218 case we no longer care about it. Don't delete relocs which
1219 represent addresses, though. */
1220 if (irel
->r_offset
>= addr
1221 && irel
->r_offset
< addr
+ count
1222 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_ALIGN
1223 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
1224 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_DATA
1225 && ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_LABEL
)
1226 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
1229 /* If this is a PC relative reloc, see if the range it covers
1230 includes the bytes we have deleted. */
1231 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
1240 start
= irel
->r_offset
;
1241 insn
= bfd_get_16 (abfd
, contents
+ nraddr
);
1245 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
1248 start
= stop
= addr
;
1252 /* If this reloc is against a symbol defined in this
1253 section, and the symbol will not be adjusted below, we
1254 must check the addend to see it will put the value in
1255 range to be adjusted, and hence must be changed. */
1256 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
1258 bfd_elf32_swap_symbol_in (abfd
,
1259 extsyms
+ ELF32_R_SYM (irel
->r_info
),
1261 if (sym
.st_shndx
== shndx
1262 && (sym
.st_value
<= addr
1263 || sym
.st_value
>= toaddr
))
1267 val
= bfd_get_32 (abfd
, contents
+ nraddr
);
1268 val
+= sym
.st_value
;
1269 if (val
> addr
&& val
< toaddr
)
1270 bfd_put_32 (abfd
, val
- count
, contents
+ nraddr
);
1273 start
= stop
= addr
;
1280 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
1284 if (ELF32_R_SYM (irel
->r_info
) >= symtab_hdr
->sh_info
)
1285 start
= stop
= addr
;
1291 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
1297 stop
= start
+ 4 + off
* 2;
1302 stop
= (start
&~ (bfd_vma
) 3) + 4 + off
* 4;
1308 /* These relocs types represent
1310 The r_addend field holds the difference between the reloc
1311 address and L1. That is the start of the reloc, and
1312 adding in the contents gives us the top. We must adjust
1313 both the r_offset field and the section contents.
1314 N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
1315 and the elf bfd r_offset is called r_vaddr. */
1317 stop
= irel
->r_offset
;
1318 start
= (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irel
->r_addend
);
1322 && (stop
<= addr
|| stop
>= toaddr
))
1323 irel
->r_addend
+= count
;
1324 else if (stop
> addr
1326 && (start
<= addr
|| start
>= toaddr
))
1327 irel
->r_addend
-= count
;
1329 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH16
)
1330 voff
= bfd_get_signed_16 (abfd
, contents
+ nraddr
);
1331 else if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_SWITCH8
)
1332 voff
= bfd_get_8 (abfd
, contents
+ nraddr
);
1334 voff
= bfd_get_signed_32 (abfd
, contents
+ nraddr
);
1335 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
1340 start
= irel
->r_offset
;
1341 stop
= (bfd_vma
) ((bfd_signed_vma
) start
1342 + (long) irel
->r_addend
1349 && (stop
<= addr
|| stop
>= toaddr
))
1351 else if (stop
> addr
1353 && (start
<= addr
|| start
>= toaddr
))
1362 switch ((enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
))
1371 if ((oinsn
& 0xff00) != (insn
& 0xff00))
1373 bfd_put_16 (abfd
, insn
, contents
+ nraddr
);
1378 if ((oinsn
& 0xf000) != (insn
& 0xf000))
1380 bfd_put_16 (abfd
, insn
, contents
+ nraddr
);
1384 BFD_ASSERT (adjust
== count
|| count
>= 4);
1389 if ((irel
->r_offset
& 3) == 0)
1392 if ((oinsn
& 0xff00) != (insn
& 0xff00))
1394 bfd_put_16 (abfd
, insn
, contents
+ nraddr
);
1399 if (voff
< - 0x8000 || voff
>= 0x8000)
1401 bfd_put_signed_16 (abfd
, voff
, contents
+ nraddr
);
1406 bfd_put_signed_32 (abfd
, voff
, contents
+ nraddr
);
1410 irel
->r_addend
+= adjust
;
1416 ((*_bfd_error_handler
)
1417 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
1418 bfd_get_filename (abfd
), (unsigned long) irel
->r_offset
));
1419 bfd_set_error (bfd_error_bad_value
);
1424 irel
->r_offset
= nraddr
;
1427 /* Look through all the other sections. If there contain any IMM32
1428 relocs against internal symbols which we are not going to adjust
1429 below, we may need to adjust the addends. */
1430 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
1432 Elf_Internal_Rela
*internal_relocs
;
1433 Elf_Internal_Rela
*irelscan
, *irelscanend
;
1434 bfd_byte
*ocontents
;
1437 || (o
->flags
& SEC_RELOC
) == 0
1438 || o
->reloc_count
== 0)
1441 /* We always cache the relocs. Perhaps, if info->keep_memory is
1442 false, we should free them, if we are permitted to, when we
1443 leave sh_coff_relax_section. */
1444 internal_relocs
= (_bfd_elf32_link_read_relocs
1445 (abfd
, o
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
1447 if (internal_relocs
== NULL
)
1451 irelscanend
= internal_relocs
+ o
->reloc_count
;
1452 for (irelscan
= internal_relocs
; irelscan
< irelscanend
; irelscan
++)
1454 Elf_Internal_Sym sym
;
1456 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
1457 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_SWITCH32
)
1459 bfd_vma start
, stop
;
1460 bfd_signed_vma voff
;
1462 if (ocontents
== NULL
)
1464 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
1465 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
1468 /* We always cache the section contents.
1469 Perhaps, if info->keep_memory is false, we
1470 should free them, if we are permitted to,
1471 when we leave sh_coff_relax_section. */
1472 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
1473 if (ocontents
== NULL
)
1475 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
1479 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
1483 stop
= irelscan
->r_offset
;
1485 = (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irelscan
->r_addend
);
1487 /* STOP is in a different section, so it won't change. */
1488 if (start
> addr
&& start
< toaddr
)
1489 irelscan
->r_addend
+= count
;
1491 voff
= bfd_get_signed_32 (abfd
, ocontents
+ irelscan
->r_offset
);
1492 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
1496 && (stop
<= addr
|| stop
>= toaddr
))
1497 bfd_put_signed_32 (abfd
, voff
+ count
,
1498 ocontents
+ irelscan
->r_offset
);
1499 else if (stop
> addr
1501 && (start
<= addr
|| start
>= toaddr
))
1502 bfd_put_signed_32 (abfd
, voff
- count
,
1503 ocontents
+ irelscan
->r_offset
);
1506 if (ELF32_R_TYPE (irelscan
->r_info
) != (int) R_SH_DIR32
)
1509 if (ELF32_R_SYM (irelscan
->r_info
) >= symtab_hdr
->sh_info
)
1512 bfd_elf32_swap_symbol_in (abfd
,
1513 extsyms
+ ELF32_R_SYM (irelscan
->r_info
),
1516 if (sym
.st_shndx
== shndx
1517 && (sym
.st_value
<= addr
1518 || sym
.st_value
>= toaddr
))
1522 if (ocontents
== NULL
)
1524 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
1525 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
1528 /* We always cache the section contents.
1529 Perhaps, if info->keep_memory is false, we
1530 should free them, if we are permitted to,
1531 when we leave sh_coff_relax_section. */
1532 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
1533 if (ocontents
== NULL
)
1535 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
1539 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
1543 val
= bfd_get_32 (abfd
, ocontents
+ irelscan
->r_offset
);
1544 val
+= sym
.st_value
;
1545 if (val
> addr
&& val
< toaddr
)
1546 bfd_put_32 (abfd
, val
- count
,
1547 ocontents
+ irelscan
->r_offset
);
1552 /* Adjust the local symbols defined in this section. */
1554 esymend
= esym
+ symtab_hdr
->sh_info
;
1555 for (; esym
< esymend
; esym
++)
1557 Elf_Internal_Sym isym
;
1559 bfd_elf32_swap_symbol_in (abfd
, esym
, &isym
);
1561 if (isym
.st_shndx
== shndx
1562 && isym
.st_value
> addr
1563 && isym
.st_value
< toaddr
)
1565 isym
.st_value
-= count
;
1566 bfd_elf32_swap_symbol_out (abfd
, &isym
, esym
);
1570 /* Now adjust the global symbols defined in this section. */
1571 esym
= extsyms
+ symtab_hdr
->sh_info
;
1572 esymend
= extsyms
+ (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
));
1573 for (index
= 0; esym
< esymend
; esym
++, index
++)
1575 Elf_Internal_Sym isym
;
1577 bfd_elf32_swap_symbol_in (abfd
, esym
, &isym
);
1578 sym_hash
= elf_sym_hashes (abfd
)[index
];
1579 if (isym
.st_shndx
== shndx
1580 && ((sym_hash
)->root
.type
== bfd_link_hash_defined
1581 || (sym_hash
)->root
.type
== bfd_link_hash_defweak
)
1582 && (sym_hash
)->root
.u
.def
.section
== sec
1583 && (sym_hash
)->root
.u
.def
.value
> addr
1584 && (sym_hash
)->root
.u
.def
.value
< toaddr
)
1586 (sym_hash
)->root
.u
.def
.value
-= count
;
1590 /* See if we can move the ALIGN reloc forward. We have adjusted
1591 r_offset for it already. */
1592 if (irelalign
!= NULL
)
1594 bfd_vma alignto
, alignaddr
;
1596 alignto
= BFD_ALIGN (toaddr
, 1 << irelalign
->r_addend
);
1597 alignaddr
= BFD_ALIGN (irelalign
->r_offset
,
1598 1 << irelalign
->r_addend
);
1599 if (alignto
!= alignaddr
)
1601 /* Tail recursion. */
1602 return sh_elf_relax_delete_bytes (abfd
, sec
, alignaddr
,
1603 alignto
- alignaddr
);
1610 /* Look for loads and stores which we can align to four byte
1611 boundaries. This is like sh_align_loads in coff-sh.c. */
1614 sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
, pswapped
)
1617 Elf_Internal_Rela
*internal_relocs
;
1621 Elf_Internal_Rela
*irel
, *irelend
;
1622 bfd_vma
*labels
= NULL
;
1623 bfd_vma
*label
, *label_end
;
1627 irelend
= internal_relocs
+ sec
->reloc_count
;
1629 /* Get all the addresses with labels on them. */
1630 labels
= (bfd_vma
*) bfd_malloc (sec
->reloc_count
* sizeof (bfd_vma
));
1634 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1636 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_LABEL
)
1638 *label_end
= irel
->r_offset
;
1643 /* Note that the assembler currently always outputs relocs in
1644 address order. If that ever changes, this code will need to sort
1645 the label values and the relocs. */
1649 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1651 bfd_vma start
, stop
;
1653 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
)
1656 start
= irel
->r_offset
;
1658 for (irel
++; irel
< irelend
; irel
++)
1659 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_DATA
)
1662 stop
= irel
->r_offset
;
1664 stop
= sec
->_cooked_size
;
1666 if (! _bfd_sh_align_load_span (abfd
, sec
, contents
, sh_elf_swap_insns
,
1667 (PTR
) internal_relocs
, &label
,
1668 label_end
, start
, stop
, pswapped
))
1682 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
1685 sh_elf_swap_insns (abfd
, sec
, relocs
, contents
, addr
)
1692 Elf_Internal_Rela
*internal_relocs
= (Elf_Internal_Rela
*) relocs
;
1693 unsigned short i1
, i2
;
1694 Elf_Internal_Rela
*irel
, *irelend
;
1696 /* Swap the instructions themselves. */
1697 i1
= bfd_get_16 (abfd
, contents
+ addr
);
1698 i2
= bfd_get_16 (abfd
, contents
+ addr
+ 2);
1699 bfd_put_16 (abfd
, i2
, contents
+ addr
);
1700 bfd_put_16 (abfd
, i1
, contents
+ addr
+ 2);
1702 /* Adjust all reloc addresses. */
1703 irelend
= internal_relocs
+ sec
->reloc_count
;
1704 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1706 enum elf_sh_reloc_type type
;
1709 /* There are a few special types of relocs that we don't want to
1710 adjust. These relocs do not apply to the instruction itself,
1711 but are only associated with the address. */
1712 type
= (enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
);
1713 if (type
== R_SH_ALIGN
1714 || type
== R_SH_CODE
1715 || type
== R_SH_DATA
1716 || type
== R_SH_LABEL
)
1719 /* If an R_SH_USES reloc points to one of the addresses being
1720 swapped, we must adjust it. It would be incorrect to do this
1721 for a jump, though, since we want to execute both
1722 instructions after the jump. (We have avoided swapping
1723 around a label, so the jump will not wind up executing an
1724 instruction it shouldn't). */
1725 if (type
== R_SH_USES
)
1729 off
= irel
->r_offset
+ 4 + irel
->r_addend
;
1731 irel
->r_offset
+= 2;
1732 else if (off
== addr
+ 2)
1733 irel
->r_offset
-= 2;
1736 if (irel
->r_offset
== addr
)
1738 irel
->r_offset
+= 2;
1741 else if (irel
->r_offset
== addr
+ 2)
1743 irel
->r_offset
-= 2;
1752 unsigned short insn
, oinsn
;
1755 loc
= contents
+ irel
->r_offset
;
1764 insn
= bfd_get_16 (abfd
, loc
);
1767 if ((oinsn
& 0xff00) != (insn
& 0xff00))
1769 bfd_put_16 (abfd
, insn
, loc
);
1773 insn
= bfd_get_16 (abfd
, loc
);
1776 if ((oinsn
& 0xf000) != (insn
& 0xf000))
1778 bfd_put_16 (abfd
, insn
, loc
);
1782 /* This reloc ignores the least significant 3 bits of
1783 the program counter before adding in the offset.
1784 This means that if ADDR is at an even address, the
1785 swap will not affect the offset. If ADDR is an at an
1786 odd address, then the instruction will be crossing a
1787 four byte boundary, and must be adjusted. */
1788 if ((addr
& 3) != 0)
1790 insn
= bfd_get_16 (abfd
, loc
);
1793 if ((oinsn
& 0xff00) != (insn
& 0xff00))
1795 bfd_put_16 (abfd
, insn
, loc
);
1803 ((*_bfd_error_handler
)
1804 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
1805 bfd_get_filename (abfd
), (unsigned long) irel
->r_offset
));
1806 bfd_set_error (bfd_error_bad_value
);
1815 /* Relocate an SH ELF section. */
1818 sh_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1819 contents
, relocs
, local_syms
, local_sections
)
1820 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1821 struct bfd_link_info
*info
;
1823 asection
*input_section
;
1825 Elf_Internal_Rela
*relocs
;
1826 Elf_Internal_Sym
*local_syms
;
1827 asection
**local_sections
;
1829 Elf_Internal_Shdr
*symtab_hdr
;
1830 struct elf_link_hash_entry
**sym_hashes
;
1831 Elf_Internal_Rela
*rel
, *relend
;
1833 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1834 sym_hashes
= elf_sym_hashes (input_bfd
);
1837 relend
= relocs
+ input_section
->reloc_count
;
1838 for (; rel
< relend
; rel
++)
1841 reloc_howto_type
*howto
;
1842 unsigned long r_symndx
;
1843 Elf_Internal_Sym
*sym
;
1845 struct elf_link_hash_entry
*h
;
1847 bfd_vma addend
= (bfd_vma
)0;
1848 bfd_reloc_status_type r
;
1850 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1852 if (info
->relocateable
)
1854 /* This is a relocateable link. We don't have to change
1855 anything, unless the reloc is against a section symbol,
1856 in which case we have to adjust according to where the
1857 section symbol winds up in the output section. */
1858 if (r_symndx
< symtab_hdr
->sh_info
)
1860 sym
= local_syms
+ r_symndx
;
1861 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1863 sec
= local_sections
[r_symndx
];
1864 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1871 r_type
= ELF32_R_TYPE (rel
->r_info
);
1873 /* Many of the relocs are only used for relaxing, and are
1874 handled entirely by the relaxation code. */
1875 if (r_type
> (int) R_SH_LAST_INVALID_RELOC
1876 && r_type
< (int) R_SH_LOOP_START
)
1880 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
1881 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
))
1883 bfd_set_error (bfd_error_bad_value
);
1887 /* FIXME: This is certainly incorrect. However, it is how the
1888 COFF linker works. */
1889 if (r_type
!= (int) R_SH_DIR32
1890 && r_type
!= (int) R_SH_IND12W
1891 && r_type
!= (int) R_SH_LOOP_START
1892 && r_type
!= (int) R_SH_LOOP_END
)
1895 howto
= sh_elf_howto_table
+ r_type
;
1897 /* This is a final link. */
1901 if (r_symndx
< symtab_hdr
->sh_info
)
1903 /* There is nothing to be done for an internal IND12W
1904 relocation. FIXME: This is probably wrong, but it's how
1905 the COFF relocations work. */
1906 if (r_type
== (int) R_SH_IND12W
)
1908 sym
= local_syms
+ r_symndx
;
1909 sec
= local_sections
[r_symndx
];
1910 relocation
= (sec
->output_section
->vma
1911 + sec
->output_offset
1916 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1917 while (h
->root
.type
== bfd_link_hash_indirect
1918 || h
->root
.type
== bfd_link_hash_warning
)
1919 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1920 if (h
->root
.type
== bfd_link_hash_defined
1921 || h
->root
.type
== bfd_link_hash_defweak
)
1923 sec
= h
->root
.u
.def
.section
;
1924 relocation
= (h
->root
.u
.def
.value
1925 + sec
->output_section
->vma
1926 + sec
->output_offset
);
1928 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1932 if (! ((*info
->callbacks
->undefined_symbol
)
1933 (info
, h
->root
.root
.string
, input_bfd
,
1934 input_section
, rel
->r_offset
, true)))
1940 /* FIXME: This is how the COFF relocations work. */
1941 if (r_type
== (int) R_SH_IND12W
)
1944 switch ((int)r_type
)
1946 case (int)R_SH_DIR32
:
1947 addend
= rel
->r_addend
;
1950 /* COFF relocs don't use the addend. The addend is used for
1951 R_SH_DIR32 to be compatible with other compilers. */
1952 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1953 contents
, rel
->r_offset
,
1954 relocation
, addend
);
1956 case R_SH_LOOP_START
:
1958 static bfd_vma start
, end
;
1960 start
= (relocation
+ rel
->r_addend
1961 - (sec
->output_section
->vma
+ sec
->output_offset
));
1962 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
1963 rel
->r_offset
, sec
, start
, end
);
1966 end
= (relocation
+ rel
->r_addend
1967 - (sec
->output_section
->vma
+ sec
->output_offset
));
1968 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
1969 rel
->r_offset
, sec
, start
, end
);
1974 if (r
!= bfd_reloc_ok
)
1979 case bfd_reloc_outofrange
:
1981 case bfd_reloc_overflow
:
1986 name
= h
->root
.root
.string
;
1989 name
= (bfd_elf_string_from_elf_section
1990 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
1994 name
= bfd_section_name (input_bfd
, sec
);
1996 if (! ((*info
->callbacks
->reloc_overflow
)
1997 (info
, name
, howto
->name
, (bfd_vma
) 0,
1998 input_bfd
, input_section
, rel
->r_offset
)))
2009 /* This is a version of bfd_generic_get_relocated_section_contents
2010 which uses sh_elf_relocate_section. */
2013 sh_elf_get_relocated_section_contents (output_bfd
, link_info
, link_order
,
2014 data
, relocateable
, symbols
)
2016 struct bfd_link_info
*link_info
;
2017 struct bfd_link_order
*link_order
;
2019 boolean relocateable
;
2022 Elf_Internal_Shdr
*symtab_hdr
;
2023 asection
*input_section
= link_order
->u
.indirect
.section
;
2024 bfd
*input_bfd
= input_section
->owner
;
2025 asection
**sections
= NULL
;
2026 Elf_Internal_Rela
*internal_relocs
= NULL
;
2027 Elf32_External_Sym
*external_syms
= NULL
;
2028 Elf_Internal_Sym
*internal_syms
= NULL
;
2030 /* We only need to handle the case of relaxing, or of having a
2031 particular set of section contents, specially. */
2033 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
2034 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
2039 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2041 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
2042 input_section
->_raw_size
);
2044 if ((input_section
->flags
& SEC_RELOC
) != 0
2045 && input_section
->reloc_count
> 0)
2047 Elf_Internal_Sym
*isymp
;
2049 Elf32_External_Sym
*esym
, *esymend
;
2051 if (symtab_hdr
->contents
!= NULL
)
2052 external_syms
= (Elf32_External_Sym
*) symtab_hdr
->contents
;
2055 external_syms
= ((Elf32_External_Sym
*)
2056 bfd_malloc (symtab_hdr
->sh_info
2057 * sizeof (Elf32_External_Sym
)));
2058 if (external_syms
== NULL
&& symtab_hdr
->sh_info
> 0)
2060 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2061 || (bfd_read (external_syms
, sizeof (Elf32_External_Sym
),
2062 symtab_hdr
->sh_info
, input_bfd
)
2063 != (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
))))
2067 internal_relocs
= (_bfd_elf32_link_read_relocs
2068 (input_bfd
, input_section
, (PTR
) NULL
,
2069 (Elf_Internal_Rela
*) NULL
, false));
2070 if (internal_relocs
== NULL
)
2073 internal_syms
= ((Elf_Internal_Sym
*)
2074 bfd_malloc (symtab_hdr
->sh_info
2075 * sizeof (Elf_Internal_Sym
)));
2076 if (internal_syms
== NULL
&& symtab_hdr
->sh_info
> 0)
2079 sections
= (asection
**) bfd_malloc (symtab_hdr
->sh_info
2080 * sizeof (asection
*));
2081 if (sections
== NULL
&& symtab_hdr
->sh_info
> 0)
2084 isymp
= internal_syms
;
2086 esym
= external_syms
;
2087 esymend
= esym
+ symtab_hdr
->sh_info
;
2088 for (; esym
< esymend
; ++esym
, ++isymp
, ++secpp
)
2092 bfd_elf32_swap_symbol_in (input_bfd
, esym
, isymp
);
2094 if (isymp
->st_shndx
== SHN_UNDEF
)
2095 isec
= bfd_und_section_ptr
;
2096 else if (isymp
->st_shndx
> 0 && isymp
->st_shndx
< SHN_LORESERVE
)
2097 isec
= bfd_section_from_elf_index (input_bfd
, isymp
->st_shndx
);
2098 else if (isymp
->st_shndx
== SHN_ABS
)
2099 isec
= bfd_abs_section_ptr
;
2100 else if (isymp
->st_shndx
== SHN_COMMON
)
2101 isec
= bfd_com_section_ptr
;
2111 if (! sh_elf_relocate_section (output_bfd
, link_info
, input_bfd
,
2112 input_section
, data
, internal_relocs
,
2113 internal_syms
, sections
))
2116 if (sections
!= NULL
)
2119 if (internal_syms
!= NULL
)
2120 free (internal_syms
);
2121 internal_syms
= NULL
;
2122 if (external_syms
!= NULL
&& symtab_hdr
->contents
== NULL
)
2123 free (external_syms
);
2124 external_syms
= NULL
;
2125 if (internal_relocs
!= elf_section_data (input_section
)->relocs
)
2126 free (internal_relocs
);
2127 internal_relocs
= NULL
;
2133 if (internal_relocs
!= NULL
2134 && internal_relocs
!= elf_section_data (input_section
)->relocs
)
2135 free (internal_relocs
);
2136 if (external_syms
!= NULL
&& symtab_hdr
->contents
== NULL
)
2137 free (external_syms
);
2138 if (internal_syms
!= NULL
)
2139 free (internal_syms
);
2140 if (sections
!= NULL
)
2145 sh_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
2147 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2148 Elf_Internal_Rela
*rel
;
2149 struct elf_link_hash_entry
*h
;
2150 Elf_Internal_Sym
*sym
;
2154 switch (ELF32_R_TYPE (rel
->r_info
))
2156 case R_SH_GNU_VTINHERIT
:
2157 case R_SH_GNU_VTENTRY
:
2161 switch (h
->root
.type
)
2163 case bfd_link_hash_defined
:
2164 case bfd_link_hash_defweak
:
2165 return h
->root
.u
.def
.section
;
2167 case bfd_link_hash_common
:
2168 return h
->root
.u
.c
.p
->section
;
2177 if (!(elf_bad_symtab (abfd
)
2178 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
2179 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
2180 && sym
->st_shndx
!= SHN_COMMON
))
2182 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
2189 sh_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2190 bfd
*abfd ATTRIBUTE_UNUSED
;
2191 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2192 asection
*sec ATTRIBUTE_UNUSED
;
2193 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
2195 /* we don't use got and plt entries for sh. */
2199 /* Look through the relocs for a section during the first phase.
2200 Since we don't do .gots or .plts, we just need to consider the
2201 virtual table relocs for gc. */
2204 sh_elf_check_relocs (abfd
, info
, sec
, relocs
)
2206 struct bfd_link_info
*info
;
2208 const Elf_Internal_Rela
*relocs
;
2210 Elf_Internal_Shdr
*symtab_hdr
;
2211 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
2212 const Elf_Internal_Rela
*rel
;
2213 const Elf_Internal_Rela
*rel_end
;
2215 if (info
->relocateable
)
2218 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2219 sym_hashes
= elf_sym_hashes (abfd
);
2220 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf32_External_Sym
);
2221 if (!elf_bad_symtab (abfd
))
2222 sym_hashes_end
-= symtab_hdr
->sh_info
;
2224 rel_end
= relocs
+ sec
->reloc_count
;
2225 for (rel
= relocs
; rel
< rel_end
; rel
++)
2227 struct elf_link_hash_entry
*h
;
2228 unsigned long r_symndx
;
2230 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2231 if (r_symndx
< symtab_hdr
->sh_info
)
2234 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2236 switch (ELF32_R_TYPE (rel
->r_info
))
2238 /* This relocation describes the C++ object vtable hierarchy.
2239 Reconstruct it for later use during GC. */
2240 case R_SH_GNU_VTINHERIT
:
2241 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2245 /* This relocation describes which C++ vtable entries are actually
2246 used. Record for later use during GC. */
2247 case R_SH_GNU_VTENTRY
:
2248 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2258 sh_elf_set_mach_from_flags (abfd
)
2261 flagword flags
= elf_elfheader (abfd
)->e_flags
;
2263 switch (flags
& EF_SH_MACH_MASK
)
2266 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh
);
2269 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh2
);
2272 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh_dsp
);
2275 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3
);
2278 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3_dsp
);
2281 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3e
);
2285 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh4
);
2293 /* Function to keep SH specific file flags. */
2295 sh_elf_set_private_flags (abfd
, flags
)
2299 BFD_ASSERT (! elf_flags_init (abfd
)
2300 || elf_elfheader (abfd
)->e_flags
== flags
);
2302 elf_elfheader (abfd
)->e_flags
= flags
;
2303 elf_flags_init (abfd
) = true;
2304 return sh_elf_set_mach_from_flags (abfd
);
2307 /* Copy backend specific data from one object module to another */
2309 sh_elf_copy_private_data (ibfd
, obfd
)
2313 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2314 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2317 return sh_elf_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
2320 /* This routine checks for linking big and little endian objects
2321 together, and for linking sh-dsp with sh3e / sh4 objects. */
2324 sh_elf_merge_private_data (ibfd
, obfd
)
2328 flagword old_flags
, new_flags
;
2330 if (_bfd_generic_verify_endian_match (ibfd
, obfd
) == false)
2333 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2334 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2337 if (! elf_flags_init (obfd
))
2339 elf_flags_init (obfd
) = true;
2340 elf_elfheader (obfd
)->e_flags
= 0;
2342 old_flags
= elf_elfheader (obfd
)->e_flags
;
2343 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2344 if ((EF_SH_HAS_DSP (old_flags
) && EF_SH_HAS_FP (new_flags
))
2345 || (EF_SH_HAS_DSP (new_flags
) && EF_SH_HAS_FP (old_flags
)))
2347 (*_bfd_error_handler
)
2348 ("%s: uses %s instructions while previous modules use %s instructions",
2349 bfd_get_filename (ibfd
),
2350 EF_SH_HAS_DSP (new_flags
) ? "dsp" : "floating point",
2351 EF_SH_HAS_DSP (new_flags
) ? "floating point" : "dsp");
2352 bfd_set_error (bfd_error_bad_value
);
2355 elf_elfheader (obfd
)->e_flags
= EF_SH_MERGE_MACH (old_flags
, new_flags
);
2357 return sh_elf_set_mach_from_flags (obfd
);
2360 #define TARGET_BIG_SYM bfd_elf32_sh_vec
2361 #define TARGET_BIG_NAME "elf32-sh"
2362 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
2363 #define TARGET_LITTLE_NAME "elf32-shl"
2364 #define ELF_ARCH bfd_arch_sh
2365 #define ELF_MACHINE_CODE EM_SH
2366 #define ELF_MAXPAGESIZE 0x1
2368 #define elf_symbol_leading_char '_'
2370 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
2371 #define elf_info_to_howto sh_elf_info_to_howto
2372 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
2373 #define elf_backend_relocate_section sh_elf_relocate_section
2374 #define bfd_elf32_bfd_get_relocated_section_contents \
2375 sh_elf_get_relocated_section_contents
2376 #define elf_backend_object_p sh_elf_set_mach_from_flags
2377 #define bfd_elf32_bfd_set_private_bfd_flags \
2378 sh_elf_set_private_flags
2379 #define bfd_elf32_bfd_copy_private_bfd_data \
2380 sh_elf_copy_private_data
2381 #define bfd_elf32_bfd_merge_private_bfd_data \
2382 sh_elf_merge_private_data
2384 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
2385 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
2386 #define elf_backend_check_relocs sh_elf_check_relocs
2388 #define elf_backend_can_gc_sections 1
2389 #include "elf32-target.h"