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
< 0 || voff
>= 0xff)
1401 bfd_put_8 (abfd
, voff
, contents
+ nraddr
);
1406 if (voff
< - 0x8000 || voff
>= 0x8000)
1408 bfd_put_signed_16 (abfd
, voff
, contents
+ nraddr
);
1413 bfd_put_signed_32 (abfd
, voff
, contents
+ nraddr
);
1417 irel
->r_addend
+= adjust
;
1423 ((*_bfd_error_handler
)
1424 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
1425 bfd_get_filename (abfd
), (unsigned long) irel
->r_offset
));
1426 bfd_set_error (bfd_error_bad_value
);
1431 irel
->r_offset
= nraddr
;
1434 /* Look through all the other sections. If there contain any IMM32
1435 relocs against internal symbols which we are not going to adjust
1436 below, we may need to adjust the addends. */
1437 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
1439 Elf_Internal_Rela
*internal_relocs
;
1440 Elf_Internal_Rela
*irelscan
, *irelscanend
;
1441 bfd_byte
*ocontents
;
1444 || (o
->flags
& SEC_RELOC
) == 0
1445 || o
->reloc_count
== 0)
1448 /* We always cache the relocs. Perhaps, if info->keep_memory is
1449 false, we should free them, if we are permitted to, when we
1450 leave sh_coff_relax_section. */
1451 internal_relocs
= (_bfd_elf32_link_read_relocs
1452 (abfd
, o
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
1454 if (internal_relocs
== NULL
)
1458 irelscanend
= internal_relocs
+ o
->reloc_count
;
1459 for (irelscan
= internal_relocs
; irelscan
< irelscanend
; irelscan
++)
1461 Elf_Internal_Sym sym
;
1463 /* Dwarf line numbers use R_SH_SWITCH32 relocs. */
1464 if (ELF32_R_TYPE (irelscan
->r_info
) == (int) R_SH_SWITCH32
)
1466 bfd_vma start
, stop
;
1467 bfd_signed_vma voff
;
1469 if (ocontents
== NULL
)
1471 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
1472 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
1475 /* We always cache the section contents.
1476 Perhaps, if info->keep_memory is false, we
1477 should free them, if we are permitted to,
1478 when we leave sh_coff_relax_section. */
1479 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
1480 if (ocontents
== NULL
)
1482 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
1486 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
1490 stop
= irelscan
->r_offset
;
1492 = (bfd_vma
) ((bfd_signed_vma
) stop
- (long) irelscan
->r_addend
);
1494 /* STOP is in a different section, so it won't change. */
1495 if (start
> addr
&& start
< toaddr
)
1496 irelscan
->r_addend
+= count
;
1498 voff
= bfd_get_signed_32 (abfd
, ocontents
+ irelscan
->r_offset
);
1499 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
1503 && (stop
<= addr
|| stop
>= toaddr
))
1504 bfd_put_signed_32 (abfd
, voff
+ count
,
1505 ocontents
+ irelscan
->r_offset
);
1506 else if (stop
> addr
1508 && (start
<= addr
|| start
>= toaddr
))
1509 bfd_put_signed_32 (abfd
, voff
- count
,
1510 ocontents
+ irelscan
->r_offset
);
1513 if (ELF32_R_TYPE (irelscan
->r_info
) != (int) R_SH_DIR32
)
1516 if (ELF32_R_SYM (irelscan
->r_info
) >= symtab_hdr
->sh_info
)
1519 bfd_elf32_swap_symbol_in (abfd
,
1520 extsyms
+ ELF32_R_SYM (irelscan
->r_info
),
1523 if (sym
.st_shndx
== shndx
1524 && (sym
.st_value
<= addr
1525 || sym
.st_value
>= toaddr
))
1529 if (ocontents
== NULL
)
1531 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
1532 ocontents
= elf_section_data (o
)->this_hdr
.contents
;
1535 /* We always cache the section contents.
1536 Perhaps, if info->keep_memory is false, we
1537 should free them, if we are permitted to,
1538 when we leave sh_coff_relax_section. */
1539 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
1540 if (ocontents
== NULL
)
1542 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
1546 elf_section_data (o
)->this_hdr
.contents
= ocontents
;
1550 val
= bfd_get_32 (abfd
, ocontents
+ irelscan
->r_offset
);
1551 val
+= sym
.st_value
;
1552 if (val
> addr
&& val
< toaddr
)
1553 bfd_put_32 (abfd
, val
- count
,
1554 ocontents
+ irelscan
->r_offset
);
1559 /* Adjust the local symbols defined in this section. */
1561 esymend
= esym
+ symtab_hdr
->sh_info
;
1562 for (; esym
< esymend
; esym
++)
1564 Elf_Internal_Sym isym
;
1566 bfd_elf32_swap_symbol_in (abfd
, esym
, &isym
);
1568 if (isym
.st_shndx
== shndx
1569 && isym
.st_value
> addr
1570 && isym
.st_value
< toaddr
)
1572 isym
.st_value
-= count
;
1573 bfd_elf32_swap_symbol_out (abfd
, &isym
, esym
);
1577 /* Now adjust the global symbols defined in this section. */
1578 esym
= extsyms
+ symtab_hdr
->sh_info
;
1579 esymend
= extsyms
+ (symtab_hdr
->sh_size
/ sizeof (Elf32_External_Sym
));
1580 for (index
= 0; esym
< esymend
; esym
++, index
++)
1582 Elf_Internal_Sym isym
;
1584 bfd_elf32_swap_symbol_in (abfd
, esym
, &isym
);
1585 sym_hash
= elf_sym_hashes (abfd
)[index
];
1586 if (isym
.st_shndx
== shndx
1587 && ((sym_hash
)->root
.type
== bfd_link_hash_defined
1588 || (sym_hash
)->root
.type
== bfd_link_hash_defweak
)
1589 && (sym_hash
)->root
.u
.def
.section
== sec
1590 && (sym_hash
)->root
.u
.def
.value
> addr
1591 && (sym_hash
)->root
.u
.def
.value
< toaddr
)
1593 (sym_hash
)->root
.u
.def
.value
-= count
;
1597 /* See if we can move the ALIGN reloc forward. We have adjusted
1598 r_offset for it already. */
1599 if (irelalign
!= NULL
)
1601 bfd_vma alignto
, alignaddr
;
1603 alignto
= BFD_ALIGN (toaddr
, 1 << irelalign
->r_addend
);
1604 alignaddr
= BFD_ALIGN (irelalign
->r_offset
,
1605 1 << irelalign
->r_addend
);
1606 if (alignto
!= alignaddr
)
1608 /* Tail recursion. */
1609 return sh_elf_relax_delete_bytes (abfd
, sec
, alignaddr
,
1610 alignto
- alignaddr
);
1617 /* Look for loads and stores which we can align to four byte
1618 boundaries. This is like sh_align_loads in coff-sh.c. */
1621 sh_elf_align_loads (abfd
, sec
, internal_relocs
, contents
, pswapped
)
1624 Elf_Internal_Rela
*internal_relocs
;
1628 Elf_Internal_Rela
*irel
, *irelend
;
1629 bfd_vma
*labels
= NULL
;
1630 bfd_vma
*label
, *label_end
;
1634 irelend
= internal_relocs
+ sec
->reloc_count
;
1636 /* Get all the addresses with labels on them. */
1637 labels
= (bfd_vma
*) bfd_malloc (sec
->reloc_count
* sizeof (bfd_vma
));
1641 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1643 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_LABEL
)
1645 *label_end
= irel
->r_offset
;
1650 /* Note that the assembler currently always outputs relocs in
1651 address order. If that ever changes, this code will need to sort
1652 the label values and the relocs. */
1656 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1658 bfd_vma start
, stop
;
1660 if (ELF32_R_TYPE (irel
->r_info
) != (int) R_SH_CODE
)
1663 start
= irel
->r_offset
;
1665 for (irel
++; irel
< irelend
; irel
++)
1666 if (ELF32_R_TYPE (irel
->r_info
) == (int) R_SH_DATA
)
1669 stop
= irel
->r_offset
;
1671 stop
= sec
->_cooked_size
;
1673 if (! _bfd_sh_align_load_span (abfd
, sec
, contents
, sh_elf_swap_insns
,
1674 (PTR
) internal_relocs
, &label
,
1675 label_end
, start
, stop
, pswapped
))
1689 /* Swap two SH instructions. This is like sh_swap_insns in coff-sh.c. */
1692 sh_elf_swap_insns (abfd
, sec
, relocs
, contents
, addr
)
1699 Elf_Internal_Rela
*internal_relocs
= (Elf_Internal_Rela
*) relocs
;
1700 unsigned short i1
, i2
;
1701 Elf_Internal_Rela
*irel
, *irelend
;
1703 /* Swap the instructions themselves. */
1704 i1
= bfd_get_16 (abfd
, contents
+ addr
);
1705 i2
= bfd_get_16 (abfd
, contents
+ addr
+ 2);
1706 bfd_put_16 (abfd
, i2
, contents
+ addr
);
1707 bfd_put_16 (abfd
, i1
, contents
+ addr
+ 2);
1709 /* Adjust all reloc addresses. */
1710 irelend
= internal_relocs
+ sec
->reloc_count
;
1711 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1713 enum elf_sh_reloc_type type
;
1716 /* There are a few special types of relocs that we don't want to
1717 adjust. These relocs do not apply to the instruction itself,
1718 but are only associated with the address. */
1719 type
= (enum elf_sh_reloc_type
) ELF32_R_TYPE (irel
->r_info
);
1720 if (type
== R_SH_ALIGN
1721 || type
== R_SH_CODE
1722 || type
== R_SH_DATA
1723 || type
== R_SH_LABEL
)
1726 /* If an R_SH_USES reloc points to one of the addresses being
1727 swapped, we must adjust it. It would be incorrect to do this
1728 for a jump, though, since we want to execute both
1729 instructions after the jump. (We have avoided swapping
1730 around a label, so the jump will not wind up executing an
1731 instruction it shouldn't). */
1732 if (type
== R_SH_USES
)
1736 off
= irel
->r_offset
+ 4 + irel
->r_addend
;
1738 irel
->r_offset
+= 2;
1739 else if (off
== addr
+ 2)
1740 irel
->r_offset
-= 2;
1743 if (irel
->r_offset
== addr
)
1745 irel
->r_offset
+= 2;
1748 else if (irel
->r_offset
== addr
+ 2)
1750 irel
->r_offset
-= 2;
1759 unsigned short insn
, oinsn
;
1762 loc
= contents
+ irel
->r_offset
;
1771 insn
= bfd_get_16 (abfd
, loc
);
1774 if ((oinsn
& 0xff00) != (insn
& 0xff00))
1776 bfd_put_16 (abfd
, insn
, loc
);
1780 insn
= bfd_get_16 (abfd
, loc
);
1783 if ((oinsn
& 0xf000) != (insn
& 0xf000))
1785 bfd_put_16 (abfd
, insn
, loc
);
1789 /* This reloc ignores the least significant 3 bits of
1790 the program counter before adding in the offset.
1791 This means that if ADDR is at an even address, the
1792 swap will not affect the offset. If ADDR is an at an
1793 odd address, then the instruction will be crossing a
1794 four byte boundary, and must be adjusted. */
1795 if ((addr
& 3) != 0)
1797 insn
= bfd_get_16 (abfd
, loc
);
1800 if ((oinsn
& 0xff00) != (insn
& 0xff00))
1802 bfd_put_16 (abfd
, insn
, loc
);
1810 ((*_bfd_error_handler
)
1811 (_("%s: 0x%lx: fatal: reloc overflow while relaxing"),
1812 bfd_get_filename (abfd
), (unsigned long) irel
->r_offset
));
1813 bfd_set_error (bfd_error_bad_value
);
1822 /* Relocate an SH ELF section. */
1825 sh_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1826 contents
, relocs
, local_syms
, local_sections
)
1827 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1828 struct bfd_link_info
*info
;
1830 asection
*input_section
;
1832 Elf_Internal_Rela
*relocs
;
1833 Elf_Internal_Sym
*local_syms
;
1834 asection
**local_sections
;
1836 Elf_Internal_Shdr
*symtab_hdr
;
1837 struct elf_link_hash_entry
**sym_hashes
;
1838 Elf_Internal_Rela
*rel
, *relend
;
1840 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1841 sym_hashes
= elf_sym_hashes (input_bfd
);
1844 relend
= relocs
+ input_section
->reloc_count
;
1845 for (; rel
< relend
; rel
++)
1848 reloc_howto_type
*howto
;
1849 unsigned long r_symndx
;
1850 Elf_Internal_Sym
*sym
;
1852 struct elf_link_hash_entry
*h
;
1854 bfd_vma addend
= (bfd_vma
)0;
1855 bfd_reloc_status_type r
;
1857 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1859 if (info
->relocateable
)
1861 /* This is a relocateable link. We don't have to change
1862 anything, unless the reloc is against a section symbol,
1863 in which case we have to adjust according to where the
1864 section symbol winds up in the output section. */
1865 if (r_symndx
< symtab_hdr
->sh_info
)
1867 sym
= local_syms
+ r_symndx
;
1868 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1870 sec
= local_sections
[r_symndx
];
1871 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1878 r_type
= ELF32_R_TYPE (rel
->r_info
);
1880 /* Many of the relocs are only used for relaxing, and are
1881 handled entirely by the relaxation code. */
1882 if (r_type
> (int) R_SH_LAST_INVALID_RELOC
1883 && r_type
< (int) R_SH_LOOP_START
)
1887 || (r_type
>= (int) R_SH_FIRST_INVALID_RELOC
1888 && r_type
<= (int) R_SH_LAST_INVALID_RELOC
))
1890 bfd_set_error (bfd_error_bad_value
);
1894 /* FIXME: This is certainly incorrect. However, it is how the
1895 COFF linker works. */
1896 if (r_type
!= (int) R_SH_DIR32
1897 && r_type
!= (int) R_SH_IND12W
1898 && r_type
!= (int) R_SH_LOOP_START
1899 && r_type
!= (int) R_SH_LOOP_END
)
1902 howto
= sh_elf_howto_table
+ r_type
;
1904 /* This is a final link. */
1908 if (r_symndx
< symtab_hdr
->sh_info
)
1910 /* There is nothing to be done for an internal IND12W
1911 relocation. FIXME: This is probably wrong, but it's how
1912 the COFF relocations work. */
1913 if (r_type
== (int) R_SH_IND12W
)
1915 sym
= local_syms
+ r_symndx
;
1916 sec
= local_sections
[r_symndx
];
1917 relocation
= (sec
->output_section
->vma
1918 + sec
->output_offset
1923 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1924 while (h
->root
.type
== bfd_link_hash_indirect
1925 || h
->root
.type
== bfd_link_hash_warning
)
1926 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1927 if (h
->root
.type
== bfd_link_hash_defined
1928 || h
->root
.type
== bfd_link_hash_defweak
)
1930 sec
= h
->root
.u
.def
.section
;
1931 relocation
= (h
->root
.u
.def
.value
1932 + sec
->output_section
->vma
1933 + sec
->output_offset
);
1935 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1939 if (! ((*info
->callbacks
->undefined_symbol
)
1940 (info
, h
->root
.root
.string
, input_bfd
,
1941 input_section
, rel
->r_offset
, true)))
1947 /* FIXME: This is how the COFF relocations work. */
1948 if (r_type
== (int) R_SH_IND12W
)
1951 switch ((int)r_type
)
1953 case (int)R_SH_DIR32
:
1954 addend
= rel
->r_addend
;
1957 /* COFF relocs don't use the addend. The addend is used for
1958 R_SH_DIR32 to be compatible with other compilers. */
1959 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1960 contents
, rel
->r_offset
,
1961 relocation
, addend
);
1963 case R_SH_LOOP_START
:
1965 static bfd_vma start
, end
;
1967 start
= (relocation
+ rel
->r_addend
1968 - (sec
->output_section
->vma
+ sec
->output_offset
));
1969 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
1970 rel
->r_offset
, sec
, start
, end
);
1973 end
= (relocation
+ rel
->r_addend
1974 - (sec
->output_section
->vma
+ sec
->output_offset
));
1975 r
= sh_elf_reloc_loop (r_type
, input_bfd
, input_section
, contents
,
1976 rel
->r_offset
, sec
, start
, end
);
1981 if (r
!= bfd_reloc_ok
)
1986 case bfd_reloc_outofrange
:
1988 case bfd_reloc_overflow
:
1993 name
= h
->root
.root
.string
;
1996 name
= (bfd_elf_string_from_elf_section
1997 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
));
2001 name
= bfd_section_name (input_bfd
, sec
);
2003 if (! ((*info
->callbacks
->reloc_overflow
)
2004 (info
, name
, howto
->name
, (bfd_vma
) 0,
2005 input_bfd
, input_section
, rel
->r_offset
)))
2016 /* This is a version of bfd_generic_get_relocated_section_contents
2017 which uses sh_elf_relocate_section. */
2020 sh_elf_get_relocated_section_contents (output_bfd
, link_info
, link_order
,
2021 data
, relocateable
, symbols
)
2023 struct bfd_link_info
*link_info
;
2024 struct bfd_link_order
*link_order
;
2026 boolean relocateable
;
2029 Elf_Internal_Shdr
*symtab_hdr
;
2030 asection
*input_section
= link_order
->u
.indirect
.section
;
2031 bfd
*input_bfd
= input_section
->owner
;
2032 asection
**sections
= NULL
;
2033 Elf_Internal_Rela
*internal_relocs
= NULL
;
2034 Elf32_External_Sym
*external_syms
= NULL
;
2035 Elf_Internal_Sym
*internal_syms
= NULL
;
2037 /* We only need to handle the case of relaxing, or of having a
2038 particular set of section contents, specially. */
2040 || elf_section_data (input_section
)->this_hdr
.contents
== NULL
)
2041 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
2046 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2048 memcpy (data
, elf_section_data (input_section
)->this_hdr
.contents
,
2049 input_section
->_raw_size
);
2051 if ((input_section
->flags
& SEC_RELOC
) != 0
2052 && input_section
->reloc_count
> 0)
2054 Elf_Internal_Sym
*isymp
;
2056 Elf32_External_Sym
*esym
, *esymend
;
2058 if (symtab_hdr
->contents
!= NULL
)
2059 external_syms
= (Elf32_External_Sym
*) symtab_hdr
->contents
;
2062 external_syms
= ((Elf32_External_Sym
*)
2063 bfd_malloc (symtab_hdr
->sh_info
2064 * sizeof (Elf32_External_Sym
)));
2065 if (external_syms
== NULL
&& symtab_hdr
->sh_info
> 0)
2067 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
2068 || (bfd_read (external_syms
, sizeof (Elf32_External_Sym
),
2069 symtab_hdr
->sh_info
, input_bfd
)
2070 != (symtab_hdr
->sh_info
* sizeof (Elf32_External_Sym
))))
2074 internal_relocs
= (_bfd_elf32_link_read_relocs
2075 (input_bfd
, input_section
, (PTR
) NULL
,
2076 (Elf_Internal_Rela
*) NULL
, false));
2077 if (internal_relocs
== NULL
)
2080 internal_syms
= ((Elf_Internal_Sym
*)
2081 bfd_malloc (symtab_hdr
->sh_info
2082 * sizeof (Elf_Internal_Sym
)));
2083 if (internal_syms
== NULL
&& symtab_hdr
->sh_info
> 0)
2086 sections
= (asection
**) bfd_malloc (symtab_hdr
->sh_info
2087 * sizeof (asection
*));
2088 if (sections
== NULL
&& symtab_hdr
->sh_info
> 0)
2091 isymp
= internal_syms
;
2093 esym
= external_syms
;
2094 esymend
= esym
+ symtab_hdr
->sh_info
;
2095 for (; esym
< esymend
; ++esym
, ++isymp
, ++secpp
)
2099 bfd_elf32_swap_symbol_in (input_bfd
, esym
, isymp
);
2101 if (isymp
->st_shndx
== SHN_UNDEF
)
2102 isec
= bfd_und_section_ptr
;
2103 else if (isymp
->st_shndx
> 0 && isymp
->st_shndx
< SHN_LORESERVE
)
2104 isec
= bfd_section_from_elf_index (input_bfd
, isymp
->st_shndx
);
2105 else if (isymp
->st_shndx
== SHN_ABS
)
2106 isec
= bfd_abs_section_ptr
;
2107 else if (isymp
->st_shndx
== SHN_COMMON
)
2108 isec
= bfd_com_section_ptr
;
2118 if (! sh_elf_relocate_section (output_bfd
, link_info
, input_bfd
,
2119 input_section
, data
, internal_relocs
,
2120 internal_syms
, sections
))
2123 if (sections
!= NULL
)
2126 if (internal_syms
!= NULL
)
2127 free (internal_syms
);
2128 internal_syms
= NULL
;
2129 if (external_syms
!= NULL
&& symtab_hdr
->contents
== NULL
)
2130 free (external_syms
);
2131 external_syms
= NULL
;
2132 if (internal_relocs
!= elf_section_data (input_section
)->relocs
)
2133 free (internal_relocs
);
2134 internal_relocs
= NULL
;
2140 if (internal_relocs
!= NULL
2141 && internal_relocs
!= elf_section_data (input_section
)->relocs
)
2142 free (internal_relocs
);
2143 if (external_syms
!= NULL
&& symtab_hdr
->contents
== NULL
)
2144 free (external_syms
);
2145 if (internal_syms
!= NULL
)
2146 free (internal_syms
);
2147 if (sections
!= NULL
)
2152 sh_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
2154 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2155 Elf_Internal_Rela
*rel
;
2156 struct elf_link_hash_entry
*h
;
2157 Elf_Internal_Sym
*sym
;
2161 switch (ELF32_R_TYPE (rel
->r_info
))
2163 case R_SH_GNU_VTINHERIT
:
2164 case R_SH_GNU_VTENTRY
:
2168 switch (h
->root
.type
)
2170 case bfd_link_hash_defined
:
2171 case bfd_link_hash_defweak
:
2172 return h
->root
.u
.def
.section
;
2174 case bfd_link_hash_common
:
2175 return h
->root
.u
.c
.p
->section
;
2184 if (!(elf_bad_symtab (abfd
)
2185 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
2186 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
2187 && sym
->st_shndx
!= SHN_COMMON
))
2189 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
2196 sh_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2197 bfd
*abfd ATTRIBUTE_UNUSED
;
2198 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2199 asection
*sec ATTRIBUTE_UNUSED
;
2200 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
;
2202 /* we don't use got and plt entries for sh. */
2206 /* Look through the relocs for a section during the first phase.
2207 Since we don't do .gots or .plts, we just need to consider the
2208 virtual table relocs for gc. */
2211 sh_elf_check_relocs (abfd
, info
, sec
, relocs
)
2213 struct bfd_link_info
*info
;
2215 const Elf_Internal_Rela
*relocs
;
2217 Elf_Internal_Shdr
*symtab_hdr
;
2218 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
2219 const Elf_Internal_Rela
*rel
;
2220 const Elf_Internal_Rela
*rel_end
;
2222 if (info
->relocateable
)
2225 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2226 sym_hashes
= elf_sym_hashes (abfd
);
2227 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf32_External_Sym
);
2228 if (!elf_bad_symtab (abfd
))
2229 sym_hashes_end
-= symtab_hdr
->sh_info
;
2231 rel_end
= relocs
+ sec
->reloc_count
;
2232 for (rel
= relocs
; rel
< rel_end
; rel
++)
2234 struct elf_link_hash_entry
*h
;
2235 unsigned long r_symndx
;
2237 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2238 if (r_symndx
< symtab_hdr
->sh_info
)
2241 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2243 switch (ELF32_R_TYPE (rel
->r_info
))
2245 /* This relocation describes the C++ object vtable hierarchy.
2246 Reconstruct it for later use during GC. */
2247 case R_SH_GNU_VTINHERIT
:
2248 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2252 /* This relocation describes which C++ vtable entries are actually
2253 used. Record for later use during GC. */
2254 case R_SH_GNU_VTENTRY
:
2255 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2265 sh_elf_set_mach_from_flags (abfd
)
2268 flagword flags
= elf_elfheader (abfd
)->e_flags
;
2270 switch (flags
& EF_SH_MACH_MASK
)
2273 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh
);
2276 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh2
);
2279 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh_dsp
);
2282 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3
);
2285 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3_dsp
);
2288 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh3e
);
2292 bfd_default_set_arch_mach (abfd
, bfd_arch_sh
, bfd_mach_sh4
);
2300 /* Function to keep SH specific file flags. */
2302 sh_elf_set_private_flags (abfd
, flags
)
2306 BFD_ASSERT (! elf_flags_init (abfd
)
2307 || elf_elfheader (abfd
)->e_flags
== flags
);
2309 elf_elfheader (abfd
)->e_flags
= flags
;
2310 elf_flags_init (abfd
) = true;
2311 return sh_elf_set_mach_from_flags (abfd
);
2314 /* Copy backend specific data from one object module to another */
2316 sh_elf_copy_private_data (ibfd
, obfd
)
2320 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2321 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2324 return sh_elf_set_private_flags (obfd
, elf_elfheader (ibfd
)->e_flags
);
2327 /* This routine checks for linking big and little endian objects
2328 together, and for linking sh-dsp with sh3e / sh4 objects. */
2331 sh_elf_merge_private_data (ibfd
, obfd
)
2335 flagword old_flags
, new_flags
;
2337 if (_bfd_generic_verify_endian_match (ibfd
, obfd
) == false)
2340 if ( bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2341 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2344 if (! elf_flags_init (obfd
))
2346 elf_flags_init (obfd
) = true;
2347 elf_elfheader (obfd
)->e_flags
= 0;
2349 old_flags
= elf_elfheader (obfd
)->e_flags
;
2350 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2351 if ((EF_SH_HAS_DSP (old_flags
) && EF_SH_HAS_FP (new_flags
))
2352 || (EF_SH_HAS_DSP (new_flags
) && EF_SH_HAS_FP (old_flags
)))
2354 (*_bfd_error_handler
)
2355 ("%s: uses %s instructions while previous modules use %s instructions",
2356 bfd_get_filename (ibfd
),
2357 EF_SH_HAS_DSP (new_flags
) ? "dsp" : "floating point",
2358 EF_SH_HAS_DSP (new_flags
) ? "floating point" : "dsp");
2359 bfd_set_error (bfd_error_bad_value
);
2362 elf_elfheader (obfd
)->e_flags
= EF_SH_MERGE_MACH (old_flags
, new_flags
);
2364 return sh_elf_set_mach_from_flags (obfd
);
2367 #define TARGET_BIG_SYM bfd_elf32_sh_vec
2368 #define TARGET_BIG_NAME "elf32-sh"
2369 #define TARGET_LITTLE_SYM bfd_elf32_shl_vec
2370 #define TARGET_LITTLE_NAME "elf32-shl"
2371 #define ELF_ARCH bfd_arch_sh
2372 #define ELF_MACHINE_CODE EM_SH
2373 #define ELF_MAXPAGESIZE 0x1
2375 #define elf_symbol_leading_char '_'
2377 #define bfd_elf32_bfd_reloc_type_lookup sh_elf_reloc_type_lookup
2378 #define elf_info_to_howto sh_elf_info_to_howto
2379 #define bfd_elf32_bfd_relax_section sh_elf_relax_section
2380 #define elf_backend_relocate_section sh_elf_relocate_section
2381 #define bfd_elf32_bfd_get_relocated_section_contents \
2382 sh_elf_get_relocated_section_contents
2383 #define elf_backend_object_p sh_elf_set_mach_from_flags
2384 #define bfd_elf32_bfd_set_private_bfd_flags \
2385 sh_elf_set_private_flags
2386 #define bfd_elf32_bfd_copy_private_bfd_data \
2387 sh_elf_copy_private_data
2388 #define bfd_elf32_bfd_merge_private_bfd_data \
2389 sh_elf_merge_private_data
2391 #define elf_backend_gc_mark_hook sh_elf_gc_mark_hook
2392 #define elf_backend_gc_sweep_hook sh_elf_gc_sweep_hook
2393 #define elf_backend_check_relocs sh_elf_check_relocs
2395 #define elf_backend_can_gc_sections 1
2396 #include "elf32-target.h"