1 /* BFD back-end for Renesas Super-H COFF binaries.
2 Copyright (C) 1993-2023 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
4 Written by Steve Chamberlain, <sac@cygnus.com>.
5 Relaxing code written by Ian Lance Taylor, <ian@cygnus.com>.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
26 #include "libiberty.h"
30 #include "coff/internal.h"
32 #undef bfd_pe_print_pdata
37 #ifndef COFF_IMAGE_WITH_PE
38 static bool sh_align_load_span
39 (bfd
*, asection
*, bfd_byte
*,
40 bool (*) (bfd
*, asection
*, void *, bfd_byte
*, bfd_vma
),
41 void *, bfd_vma
**, bfd_vma
*, bfd_vma
, bfd_vma
, bool *);
43 #define _bfd_sh_align_load_span sh_align_load_span
46 #define bfd_pe_print_pdata _bfd_pe_print_ce_compressed_pdata
50 #define bfd_pe_print_pdata NULL
52 #endif /* COFF_WITH_PE. */
56 /* Internal functions. */
59 /* Can't build import tables with 2**4 alignment. */
60 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2
62 /* Default section alignment to 2**4. */
63 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 4
66 #ifdef COFF_IMAGE_WITH_PE
67 /* Align PE executables. */
68 #define COFF_PAGE_SIZE 0x1000
71 /* Generate long file names. */
72 #define COFF_LONG_FILENAMES
75 /* Return TRUE if this relocation should
76 appear in the output .reloc section. */
79 in_reloc_p (bfd
* abfd ATTRIBUTE_UNUSED
,
80 reloc_howto_type
* howto
)
82 return ! howto
->pc_relative
&& howto
->type
!= R_SH_IMAGEBASE
;
86 static bfd_reloc_status_type
87 sh_reloc (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
89 sh_relocate_section (bfd
*, struct bfd_link_info
*, bfd
*, asection
*,
90 bfd_byte
*, struct internal_reloc
*,
91 struct internal_syment
*, asection
**);
93 sh_align_loads (bfd
*, asection
*, struct internal_reloc
*,
96 /* The supported relocations. There are a lot of relocations defined
97 in coff/internal.h which we do not expect to ever see. */
98 static reloc_howto_type sh_coff_howtos
[] =
104 HOWTO (R_SH_IMM32CE
, /* type */
108 false, /* pc_relative */
110 complain_overflow_bitfield
, /* complain_on_overflow */
111 sh_reloc
, /* special_function */
112 "r_imm32ce", /* name */
113 true, /* partial_inplace */
114 0xffffffff, /* src_mask */
115 0xffffffff, /* dst_mask */
116 false), /* pcrel_offset */
120 EMPTY_HOWTO (3), /* R_SH_PCREL8 */
121 EMPTY_HOWTO (4), /* R_SH_PCREL16 */
122 EMPTY_HOWTO (5), /* R_SH_HIGH8 */
123 EMPTY_HOWTO (6), /* R_SH_IMM24 */
124 EMPTY_HOWTO (7), /* R_SH_LOW16 */
126 EMPTY_HOWTO (9), /* R_SH_PCDISP8BY4 */
128 HOWTO (R_SH_PCDISP8BY2
, /* type */
132 true, /* pc_relative */
134 complain_overflow_signed
, /* complain_on_overflow */
135 sh_reloc
, /* special_function */
136 "r_pcdisp8by2", /* name */
137 true, /* partial_inplace */
140 true), /* pcrel_offset */
142 EMPTY_HOWTO (11), /* R_SH_PCDISP8 */
144 HOWTO (R_SH_PCDISP
, /* type */
148 true, /* pc_relative */
150 complain_overflow_signed
, /* complain_on_overflow */
151 sh_reloc
, /* special_function */
152 "r_pcdisp12by2", /* name */
153 true, /* partial_inplace */
154 0xfff, /* src_mask */
155 0xfff, /* dst_mask */
156 true), /* pcrel_offset */
160 HOWTO (R_SH_IMM32
, /* type */
164 false, /* pc_relative */
166 complain_overflow_bitfield
, /* complain_on_overflow */
167 sh_reloc
, /* special_function */
168 "r_imm32", /* name */
169 true, /* partial_inplace */
170 0xffffffff, /* src_mask */
171 0xffffffff, /* dst_mask */
172 false), /* pcrel_offset */
176 HOWTO (R_SH_IMAGEBASE
, /* type */
180 false, /* pc_relative */
182 complain_overflow_bitfield
, /* complain_on_overflow */
183 sh_reloc
, /* special_function */
185 true, /* partial_inplace */
186 0xffffffff, /* src_mask */
187 0xffffffff, /* dst_mask */
188 false), /* pcrel_offset */
190 EMPTY_HOWTO (16), /* R_SH_IMM8 */
192 EMPTY_HOWTO (17), /* R_SH_IMM8BY2 */
193 EMPTY_HOWTO (18), /* R_SH_IMM8BY4 */
194 EMPTY_HOWTO (19), /* R_SH_IMM4 */
195 EMPTY_HOWTO (20), /* R_SH_IMM4BY2 */
196 EMPTY_HOWTO (21), /* R_SH_IMM4BY4 */
198 HOWTO (R_SH_PCRELIMM8BY2
, /* type */
202 true, /* pc_relative */
204 complain_overflow_unsigned
, /* complain_on_overflow */
205 sh_reloc
, /* special_function */
206 "r_pcrelimm8by2", /* name */
207 true, /* partial_inplace */
210 true), /* pcrel_offset */
212 HOWTO (R_SH_PCRELIMM8BY4
, /* type */
216 true, /* pc_relative */
218 complain_overflow_unsigned
, /* complain_on_overflow */
219 sh_reloc
, /* special_function */
220 "r_pcrelimm8by4", /* name */
221 true, /* partial_inplace */
224 true), /* pcrel_offset */
226 HOWTO (R_SH_IMM16
, /* type */
230 false, /* pc_relative */
232 complain_overflow_bitfield
, /* complain_on_overflow */
233 sh_reloc
, /* special_function */
234 "r_imm16", /* name */
235 true, /* partial_inplace */
236 0xffff, /* src_mask */
237 0xffff, /* dst_mask */
238 false), /* pcrel_offset */
240 HOWTO (R_SH_SWITCH16
, /* type */
244 false, /* pc_relative */
246 complain_overflow_bitfield
, /* complain_on_overflow */
247 sh_reloc
, /* special_function */
248 "r_switch16", /* name */
249 true, /* partial_inplace */
250 0xffff, /* src_mask */
251 0xffff, /* dst_mask */
252 false), /* pcrel_offset */
254 HOWTO (R_SH_SWITCH32
, /* type */
258 false, /* pc_relative */
260 complain_overflow_bitfield
, /* complain_on_overflow */
261 sh_reloc
, /* special_function */
262 "r_switch32", /* name */
263 true, /* partial_inplace */
264 0xffffffff, /* src_mask */
265 0xffffffff, /* dst_mask */
266 false), /* pcrel_offset */
268 HOWTO (R_SH_USES
, /* type */
272 false, /* pc_relative */
274 complain_overflow_bitfield
, /* complain_on_overflow */
275 sh_reloc
, /* special_function */
277 true, /* partial_inplace */
278 0xffff, /* src_mask */
279 0xffff, /* dst_mask */
280 false), /* pcrel_offset */
282 HOWTO (R_SH_COUNT
, /* type */
286 false, /* pc_relative */
288 complain_overflow_bitfield
, /* complain_on_overflow */
289 sh_reloc
, /* special_function */
290 "r_count", /* name */
291 true, /* partial_inplace */
292 0xffffffff, /* src_mask */
293 0xffffffff, /* dst_mask */
294 false), /* pcrel_offset */
296 HOWTO (R_SH_ALIGN
, /* type */
300 false, /* pc_relative */
302 complain_overflow_bitfield
, /* complain_on_overflow */
303 sh_reloc
, /* special_function */
304 "r_align", /* name */
305 true, /* partial_inplace */
306 0xffffffff, /* src_mask */
307 0xffffffff, /* dst_mask */
308 false), /* pcrel_offset */
310 HOWTO (R_SH_CODE
, /* type */
314 false, /* pc_relative */
316 complain_overflow_bitfield
, /* complain_on_overflow */
317 sh_reloc
, /* special_function */
319 true, /* partial_inplace */
320 0xffffffff, /* src_mask */
321 0xffffffff, /* dst_mask */
322 false), /* pcrel_offset */
324 HOWTO (R_SH_DATA
, /* type */
328 false, /* pc_relative */
330 complain_overflow_bitfield
, /* complain_on_overflow */
331 sh_reloc
, /* special_function */
333 true, /* partial_inplace */
334 0xffffffff, /* src_mask */
335 0xffffffff, /* dst_mask */
336 false), /* pcrel_offset */
338 HOWTO (R_SH_LABEL
, /* type */
342 false, /* pc_relative */
344 complain_overflow_bitfield
, /* complain_on_overflow */
345 sh_reloc
, /* special_function */
346 "r_label", /* name */
347 true, /* partial_inplace */
348 0xffffffff, /* src_mask */
349 0xffffffff, /* dst_mask */
350 false), /* pcrel_offset */
352 HOWTO (R_SH_SWITCH8
, /* type */
356 false, /* pc_relative */
358 complain_overflow_bitfield
, /* complain_on_overflow */
359 sh_reloc
, /* special_function */
360 "r_switch8", /* name */
361 true, /* partial_inplace */
364 false) /* pcrel_offset */
367 #define SH_COFF_HOWTO_COUNT (sizeof sh_coff_howtos / sizeof sh_coff_howtos[0])
369 /* Check for a bad magic number. */
370 #define BADMAG(x) SHBADMAG(x)
372 /* Customize coffcode.h (this is not currently used). */
375 /* FIXME: This should not be set here. */
376 #define __A_MAGIC_SET__
379 /* Swap the r_offset field in and out. */
380 #define SWAP_IN_RELOC_OFFSET H_GET_32
381 #define SWAP_OUT_RELOC_OFFSET H_PUT_32
383 /* Swap out extra information in the reloc structure. */
384 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
387 dst->r_stuff[0] = 'S'; \
388 dst->r_stuff[1] = 'C'; \
393 /* Get the value of a symbol, when performing a relocation. */
396 get_symbol_value (asymbol
*symbol
)
400 if (bfd_is_com_section (symbol
->section
))
403 relocation
= (symbol
->value
+
404 symbol
->section
->output_section
->vma
+
405 symbol
->section
->output_offset
);
411 /* Convert an rtype to howto for the COFF backend linker.
412 Copied from coff-i386. */
413 #define coff_rtype_to_howto coff_sh_rtype_to_howto
416 static reloc_howto_type
*
417 coff_sh_rtype_to_howto (bfd
* abfd ATTRIBUTE_UNUSED
,
419 struct internal_reloc
* rel
,
420 struct coff_link_hash_entry
* h
,
421 struct internal_syment
* sym
,
424 reloc_howto_type
* howto
;
426 howto
= sh_coff_howtos
+ rel
->r_type
;
430 if (howto
->pc_relative
)
431 *addendp
+= sec
->vma
;
433 if (sym
!= NULL
&& sym
->n_scnum
== 0 && sym
->n_value
!= 0)
435 /* This is a common symbol. The section contents include the
436 size (sym->n_value) as an addend. The relocate_section
437 function will be adding in the final value of the symbol. We
438 need to subtract out the current size in order to get the
440 BFD_ASSERT (h
!= NULL
);
443 if (howto
->pc_relative
)
447 /* If the symbol is defined, then the generic code is going to
448 add back the symbol value in order to cancel out an
449 adjustment it made to the addend. However, we set the addend
450 to 0 at the start of this function. We need to adjust here,
451 to avoid the adjustment the generic code will make. FIXME:
452 This is getting a bit hackish. */
453 if (sym
!= NULL
&& sym
->n_scnum
!= 0)
454 *addendp
-= sym
->n_value
;
457 if (rel
->r_type
== R_SH_IMAGEBASE
)
458 *addendp
-= pe_data (sec
->output_section
->owner
)->pe_opthdr
.ImageBase
;
463 #endif /* COFF_WITH_PE */
465 /* This structure is used to map BFD reloc codes to SH PE relocs. */
466 struct shcoff_reloc_map
468 bfd_reloc_code_real_type bfd_reloc_val
;
469 unsigned char shcoff_reloc_val
;
473 /* An array mapping BFD reloc codes to SH PE relocs. */
474 static const struct shcoff_reloc_map sh_reloc_map
[] =
476 { BFD_RELOC_32
, R_SH_IMM32CE
},
477 { BFD_RELOC_RVA
, R_SH_IMAGEBASE
},
478 { BFD_RELOC_CTOR
, R_SH_IMM32CE
},
481 /* An array mapping BFD reloc codes to SH PE relocs. */
482 static const struct shcoff_reloc_map sh_reloc_map
[] =
484 { BFD_RELOC_32
, R_SH_IMM32
},
485 { BFD_RELOC_CTOR
, R_SH_IMM32
},
489 /* Given a BFD reloc code, return the howto structure for the
490 corresponding SH PE reloc. */
491 #define coff_bfd_reloc_type_lookup sh_coff_reloc_type_lookup
492 #define coff_bfd_reloc_name_lookup sh_coff_reloc_name_lookup
494 static reloc_howto_type
*
495 sh_coff_reloc_type_lookup (bfd
*abfd
,
496 bfd_reloc_code_real_type code
)
500 for (i
= ARRAY_SIZE (sh_reloc_map
); i
--;)
501 if (sh_reloc_map
[i
].bfd_reloc_val
== code
)
502 return &sh_coff_howtos
[(int) sh_reloc_map
[i
].shcoff_reloc_val
];
504 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
505 abfd
, (unsigned int) code
);
509 static reloc_howto_type
*
510 sh_coff_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
515 for (i
= 0; i
< sizeof (sh_coff_howtos
) / sizeof (sh_coff_howtos
[0]); i
++)
516 if (sh_coff_howtos
[i
].name
!= NULL
517 && strcasecmp (sh_coff_howtos
[i
].name
, r_name
) == 0)
518 return &sh_coff_howtos
[i
];
523 /* This macro is used in coffcode.h to get the howto corresponding to
524 an internal reloc. */
526 #define RTYPE2HOWTO(relent, internal) \
528 ((internal)->r_type < SH_COFF_HOWTO_COUNT \
529 ? &sh_coff_howtos[(internal)->r_type] \
530 : (reloc_howto_type *) NULL))
532 /* This is the same as the macro in coffcode.h, except that it copies
533 r_offset into reloc_entry->addend for some relocs. */
534 #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
536 coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \
537 if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
538 coffsym = (obj_symbols (abfd) \
539 + (cache_ptr->sym_ptr_ptr - symbols)); \
541 coffsym = coff_symbol_from (ptr); \
542 if (coffsym != (coff_symbol_type *) NULL \
543 && coffsym->native->u.syment.n_scnum == 0) \
544 cache_ptr->addend = 0; \
545 else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
546 && ptr->section != (asection *) NULL) \
547 cache_ptr->addend = - (ptr->section->vma \
548 + COFF_PE_ADDEND_BIAS (ptr)); \
550 cache_ptr->addend = 0; \
551 if ((reloc).r_type == R_SH_SWITCH8 \
552 || (reloc).r_type == R_SH_SWITCH16 \
553 || (reloc).r_type == R_SH_SWITCH32 \
554 || (reloc).r_type == R_SH_USES \
555 || (reloc).r_type == R_SH_COUNT \
556 || (reloc).r_type == R_SH_ALIGN) \
557 cache_ptr->addend = (reloc).r_offset; \
560 /* This is the howto function for the SH relocations. */
562 static bfd_reloc_status_type
563 sh_reloc (bfd
* abfd
,
564 arelent
* reloc_entry
,
567 asection
* input_section
,
569 char ** error_message ATTRIBUTE_UNUSED
)
573 unsigned short r_type
;
574 bfd_vma addr
= reloc_entry
->address
;
575 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
577 r_type
= reloc_entry
->howto
->type
;
579 if (output_bfd
!= NULL
)
581 /* Partial linking--do nothing. */
582 reloc_entry
->address
+= input_section
->output_offset
;
586 /* Almost all relocs have to do with relaxing. If any work must be
587 done for them, it has been done in sh_relax_section. */
588 if (r_type
!= R_SH_IMM32
590 && r_type
!= R_SH_IMM32CE
591 && r_type
!= R_SH_IMAGEBASE
593 && (r_type
!= R_SH_PCDISP
594 || (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_reloc_offset_in_range (reloc_entry
->howto
, abfd
, input_section
,
603 return bfd_reloc_outofrange
;
605 sym_value
= get_symbol_value (symbol_in
);
613 insn
= bfd_get_32 (abfd
, hit_data
);
614 insn
+= sym_value
+ reloc_entry
->addend
;
615 bfd_put_32 (abfd
, insn
, hit_data
);
619 insn
= bfd_get_32 (abfd
, hit_data
);
620 insn
+= sym_value
+ reloc_entry
->addend
;
621 insn
-= pe_data (input_section
->output_section
->owner
)->pe_opthdr
.ImageBase
;
622 bfd_put_32 (abfd
, insn
, hit_data
);
626 insn
= bfd_get_16 (abfd
, hit_data
);
627 sym_value
+= reloc_entry
->addend
;
628 sym_value
-= (input_section
->output_section
->vma
629 + input_section
->output_offset
632 sym_value
+= (((insn
& 0xfff) ^ 0x800) - 0x800) << 1;
633 insn
= (insn
& 0xf000) | ((sym_value
>> 1) & 0xfff);
634 bfd_put_16 (abfd
, insn
, hit_data
);
635 if (sym_value
+ 0x1000 >= 0x2000 || (sym_value
& 1) != 0)
636 return bfd_reloc_overflow
;
646 #define coff_bfd_merge_private_bfd_data _bfd_generic_verify_endian_match
648 /* We can do relaxing. */
649 #define coff_bfd_relax_section sh_relax_section
651 /* We use the special COFF backend linker. */
652 #define coff_relocate_section sh_relocate_section
654 /* When relaxing, we need to use special code to get the relocated
656 #define coff_bfd_get_relocated_section_contents \
657 sh_coff_get_relocated_section_contents
659 #include "coffcode.h"
662 sh_relax_delete_bytes (bfd
*, asection
*, bfd_vma
, int);
664 /* This function handles relaxing on the SH.
666 Function calls on the SH look like this:
675 The compiler and assembler will cooperate to create R_SH_USES
676 relocs on the jsr instructions. The r_offset field of the
677 R_SH_USES reloc is the PC relative offset to the instruction which
678 loads the register (the r_offset field is computed as though it
679 were a jump instruction, so the offset value is actually from four
680 bytes past the instruction). The linker can use this reloc to
681 determine just which function is being called, and thus decide
682 whether it is possible to replace the jsr with a bsr.
684 If multiple function calls are all based on a single register load
685 (i.e., the same function is called multiple times), the compiler
686 guarantees that each function call will have an R_SH_USES reloc.
687 Therefore, if the linker is able to convert each R_SH_USES reloc
688 which refers to that address, it can safely eliminate the register
691 When the assembler creates an R_SH_USES reloc, it examines it to
692 determine which address is being loaded (L1 in the above example).
693 It then counts the number of references to that address, and
694 creates an R_SH_COUNT reloc at that address. The r_offset field of
695 the R_SH_COUNT reloc will be the number of references. If the
696 linker is able to eliminate a register load, it can use the
697 R_SH_COUNT reloc to see whether it can also eliminate the function
700 SH relaxing also handles another, unrelated, matter. On the SH, if
701 a load or store instruction is not aligned on a four byte boundary,
702 the memory cycle interferes with the 32 bit instruction fetch,
703 causing a one cycle bubble in the pipeline. Therefore, we try to
704 align load and store instructions on four byte boundaries if we
705 can, by swapping them with one of the adjacent instructions. */
708 sh_relax_section (bfd
*abfd
,
710 struct bfd_link_info
*link_info
,
713 struct internal_reloc
*internal_relocs
;
715 struct internal_reloc
*irel
, *irelend
;
716 bfd_byte
*contents
= NULL
;
720 if (bfd_link_relocatable (link_info
)
721 || (sec
->flags
& SEC_HAS_CONTENTS
) == 0
722 || (sec
->flags
& SEC_RELOC
) == 0
723 || sec
->reloc_count
== 0)
726 if (coff_section_data (abfd
, sec
) == NULL
)
728 size_t amt
= sizeof (struct coff_section_tdata
);
729 sec
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
730 if (sec
->used_by_bfd
== NULL
)
734 internal_relocs
= (_bfd_coff_read_internal_relocs
735 (abfd
, sec
, link_info
->keep_memory
,
736 (bfd_byte
*) NULL
, false,
737 (struct internal_reloc
*) NULL
));
738 if (internal_relocs
== NULL
)
743 irelend
= internal_relocs
+ sec
->reloc_count
;
744 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
746 bfd_vma laddr
, paddr
, symval
;
748 struct internal_reloc
*irelfn
, *irelscan
, *irelcount
;
749 struct internal_syment sym
;
752 if (irel
->r_type
== R_SH_CODE
)
755 if (irel
->r_type
!= R_SH_USES
)
758 /* Get the section contents. */
759 if (contents
== NULL
)
761 if (coff_section_data (abfd
, sec
)->contents
!= NULL
)
762 contents
= coff_section_data (abfd
, sec
)->contents
;
765 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
770 /* The r_offset field of the R_SH_USES reloc will point us to
771 the register load. The 4 is because the r_offset field is
772 computed as though it were a jump offset, which are based
773 from 4 bytes after the jump instruction. */
774 laddr
= irel
->r_vaddr
- sec
->vma
+ 4;
775 /* Careful to sign extend the 32-bit offset. */
776 laddr
+= ((irel
->r_offset
& 0xffffffff) ^ 0x80000000) - 0x80000000;
777 if (laddr
>= sec
->size
)
779 /* xgettext: c-format */
781 (_("%pB: %#" PRIx64
": warning: bad R_SH_USES offset"),
782 abfd
, (uint64_t) irel
->r_vaddr
);
785 insn
= bfd_get_16 (abfd
, contents
+ laddr
);
787 /* If the instruction is not mov.l NN,rN, we don't know what to do. */
788 if ((insn
& 0xf000) != 0xd000)
791 /* xgettext: c-format */
792 (_("%pB: %#" PRIx64
": warning: R_SH_USES points to unrecognized insn %#x"),
793 abfd
, (uint64_t) irel
->r_vaddr
, insn
);
797 /* Get the address from which the register is being loaded. The
798 displacement in the mov.l instruction is quadrupled. It is a
799 displacement from four bytes after the movl instruction, but,
800 before adding in the PC address, two least significant bits
801 of the PC are cleared. We assume that the section is aligned
802 on a four byte boundary. */
805 paddr
+= (laddr
+ 4) &~ (bfd_vma
) 3;
806 if (paddr
>= sec
->size
)
809 /* xgettext: c-format */
810 (_("%pB: %#" PRIx64
": warning: bad R_SH_USES load offset"),
811 abfd
, (uint64_t) irel
->r_vaddr
);
815 /* Get the reloc for the address from which the register is
816 being loaded. This reloc will tell us which function is
817 actually being called. */
819 for (irelfn
= internal_relocs
; irelfn
< irelend
; irelfn
++)
820 if (irelfn
->r_vaddr
== paddr
822 && (irelfn
->r_type
== R_SH_IMM32
823 || irelfn
->r_type
== R_SH_IMM32CE
824 || irelfn
->r_type
== R_SH_IMAGEBASE
)
827 && irelfn
->r_type
== R_SH_IMM32
831 if (irelfn
>= irelend
)
834 /* xgettext: c-format */
835 (_("%pB: %#" PRIx64
": warning: could not find expected reloc"),
836 abfd
, (uint64_t) paddr
);
840 /* Get the value of the symbol referred to by the reloc. */
841 if (! _bfd_coff_get_external_symbols (abfd
))
843 bfd_coff_swap_sym_in (abfd
,
844 ((bfd_byte
*) obj_coff_external_syms (abfd
)
846 * bfd_coff_symesz (abfd
))),
848 if (sym
.n_scnum
!= 0 && sym
.n_scnum
!= sec
->target_index
)
851 /* xgettext: c-format */
852 (_("%pB: %#" PRIx64
": warning: symbol in unexpected section"),
853 abfd
, (uint64_t) paddr
);
857 if (sym
.n_sclass
!= C_EXT
)
859 symval
= (sym
.n_value
861 + sec
->output_section
->vma
862 + sec
->output_offset
);
866 struct coff_link_hash_entry
*h
;
868 h
= obj_coff_sym_hashes (abfd
)[irelfn
->r_symndx
];
869 BFD_ASSERT (h
!= NULL
);
870 if (h
->root
.type
!= bfd_link_hash_defined
871 && h
->root
.type
!= bfd_link_hash_defweak
)
873 /* This appears to be a reference to an undefined
874 symbol. Just ignore it--it will be caught by the
875 regular reloc processing. */
879 symval
= (h
->root
.u
.def
.value
880 + h
->root
.u
.def
.section
->output_section
->vma
881 + h
->root
.u
.def
.section
->output_offset
);
884 symval
+= bfd_get_32 (abfd
, contents
+ paddr
- sec
->vma
);
886 /* See if this function call can be shortened. */
890 + sec
->output_section
->vma
893 if (foff
< -0x1000 || foff
>= 0x1000)
895 /* After all that work, we can't shorten this function call. */
899 /* Shorten the function call. */
901 /* For simplicity of coding, we are going to modify the section
902 contents, the section relocs, and the BFD symbol table. We
903 must tell the rest of the code not to free up this
904 information. It would be possible to instead create a table
905 of changes which have to be made, as is done in coff-mips.c;
906 that would be more work, but would require less memory when
907 the linker is run. */
909 coff_section_data (abfd
, sec
)->relocs
= internal_relocs
;
910 coff_section_data (abfd
, sec
)->contents
= contents
;
912 /* Replace the jsr with a bsr. */
914 /* Change the R_SH_USES reloc into an R_SH_PCDISP reloc, and
915 replace the jsr with a bsr. */
916 irel
->r_type
= R_SH_PCDISP
;
917 irel
->r_symndx
= irelfn
->r_symndx
;
918 if (sym
.n_sclass
!= C_EXT
)
920 /* If this needs to be changed because of future relaxing,
921 it will be handled here like other internal PCDISP
924 (bfd_vma
) 0xb000 | ((foff
>> 1) & 0xfff),
925 contents
+ irel
->r_vaddr
- sec
->vma
);
929 /* We can't fully resolve this yet, because the external
930 symbol value may be changed by future relaxing. We let
931 the final link phase handle it. */
932 bfd_put_16 (abfd
, (bfd_vma
) 0xb000,
933 contents
+ irel
->r_vaddr
- sec
->vma
);
936 /* See if there is another R_SH_USES reloc referring to the same
938 for (irelscan
= internal_relocs
; irelscan
< irelend
; irelscan
++)
939 if (irelscan
->r_type
== R_SH_USES
940 && laddr
== irelscan
->r_vaddr
- sec
->vma
+ 4 + irelscan
->r_offset
)
942 if (irelscan
< irelend
)
944 /* Some other function call depends upon this register load,
945 and we have not yet converted that function call.
946 Indeed, we may never be able to convert it. There is
947 nothing else we can do at this point. */
951 /* Look for a R_SH_COUNT reloc on the location where the
952 function address is stored. Do this before deleting any
953 bytes, to avoid confusion about the address. */
954 for (irelcount
= internal_relocs
; irelcount
< irelend
; irelcount
++)
955 if (irelcount
->r_vaddr
== paddr
956 && irelcount
->r_type
== R_SH_COUNT
)
959 /* Delete the register load. */
960 if (! sh_relax_delete_bytes (abfd
, sec
, laddr
, 2))
963 /* That will change things, so, just in case it permits some
964 other function call to come within range, we should relax
965 again. Note that this is not required, and it may be slow. */
968 /* Now check whether we got a COUNT reloc. */
969 if (irelcount
>= irelend
)
972 /* xgettext: c-format */
973 (_("%pB: %#" PRIx64
": warning: could not find expected COUNT reloc"),
974 abfd
, (uint64_t) paddr
);
978 /* The number of uses is stored in the r_offset field. We've
980 if (irelcount
->r_offset
== 0)
982 /* xgettext: c-format */
983 _bfd_error_handler (_("%pB: %#" PRIx64
": warning: bad count"),
984 abfd
, (uint64_t) paddr
);
988 --irelcount
->r_offset
;
990 /* If there are no more uses, we can delete the address. Reload
991 the address from irelfn, in case it was changed by the
992 previous call to sh_relax_delete_bytes. */
993 if (irelcount
->r_offset
== 0)
995 if (! sh_relax_delete_bytes (abfd
, sec
,
996 irelfn
->r_vaddr
- sec
->vma
, 4))
1000 /* We've done all we can with that function call. */
1003 /* Look for load and store instructions that we can align on four
1009 /* Get the section contents. */
1010 if (contents
== NULL
)
1012 if (coff_section_data (abfd
, sec
)->contents
!= NULL
)
1013 contents
= coff_section_data (abfd
, sec
)->contents
;
1016 if (!bfd_malloc_and_get_section (abfd
, sec
, &contents
))
1021 if (! sh_align_loads (abfd
, sec
, internal_relocs
, contents
, &swapped
))
1026 coff_section_data (abfd
, sec
)->relocs
= internal_relocs
;
1027 coff_section_data (abfd
, sec
)->contents
= contents
;
1031 if (internal_relocs
!= NULL
1032 && internal_relocs
!= coff_section_data (abfd
, sec
)->relocs
)
1034 if (! link_info
->keep_memory
)
1035 free (internal_relocs
);
1037 coff_section_data (abfd
, sec
)->relocs
= internal_relocs
;
1040 if (contents
!= NULL
&& contents
!= coff_section_data (abfd
, sec
)->contents
)
1042 if (! link_info
->keep_memory
)
1045 /* Cache the section contents for coff_link_input_bfd. */
1046 coff_section_data (abfd
, sec
)->contents
= contents
;
1052 if (internal_relocs
!= coff_section_data (abfd
, sec
)->relocs
)
1053 free (internal_relocs
);
1054 if (contents
!= coff_section_data (abfd
, sec
)->contents
)
1059 /* Delete some bytes from a section while relaxing. */
1062 sh_relax_delete_bytes (bfd
*abfd
,
1068 struct internal_reloc
*irel
, *irelend
;
1069 struct internal_reloc
*irelalign
;
1071 bfd_byte
*esym
, *esymend
;
1072 bfd_size_type symesz
;
1073 struct coff_link_hash_entry
**sym_hash
;
1076 contents
= coff_section_data (abfd
, sec
)->contents
;
1078 /* The deletion must stop at the next ALIGN reloc for an alignment
1079 power larger than the number of bytes we are deleting. */
1084 irel
= coff_section_data (abfd
, sec
)->relocs
;
1085 irelend
= irel
+ sec
->reloc_count
;
1086 for (; irel
< irelend
; irel
++)
1088 if (irel
->r_type
== R_SH_ALIGN
1089 && irel
->r_vaddr
- sec
->vma
> addr
1090 && count
< (1 << irel
->r_offset
))
1093 toaddr
= irel
->r_vaddr
- sec
->vma
;
1098 /* Actually delete the bytes. */
1099 memmove (contents
+ addr
, contents
+ addr
+ count
,
1100 (size_t) (toaddr
- addr
- count
));
1101 if (irelalign
== NULL
)
1107 #define NOP_OPCODE (0x0009)
1109 BFD_ASSERT ((count
& 1) == 0);
1110 for (i
= 0; i
< count
; i
+= 2)
1111 bfd_put_16 (abfd
, (bfd_vma
) NOP_OPCODE
, contents
+ toaddr
- count
+ i
);
1114 /* Adjust all the relocs. */
1115 for (irel
= coff_section_data (abfd
, sec
)->relocs
; irel
< irelend
; irel
++)
1117 bfd_vma nraddr
, stop
;
1120 struct internal_syment sym
;
1121 int off
, adjust
, oinsn
;
1122 bfd_signed_vma voff
= 0;
1125 /* Get the new reloc address. */
1126 nraddr
= irel
->r_vaddr
- sec
->vma
;
1127 if ((irel
->r_vaddr
- sec
->vma
> addr
1128 && irel
->r_vaddr
- sec
->vma
< toaddr
)
1129 || (irel
->r_type
== R_SH_ALIGN
1130 && irel
->r_vaddr
- sec
->vma
== toaddr
))
1133 /* See if this reloc was for the bytes we have deleted, in which
1134 case we no longer care about it. Don't delete relocs which
1135 represent addresses, though. */
1136 if (irel
->r_vaddr
- sec
->vma
>= addr
1137 && irel
->r_vaddr
- sec
->vma
< addr
+ count
1138 && irel
->r_type
!= R_SH_ALIGN
1139 && irel
->r_type
!= R_SH_CODE
1140 && irel
->r_type
!= R_SH_DATA
1141 && irel
->r_type
!= R_SH_LABEL
)
1142 irel
->r_type
= R_SH_UNUSED
;
1144 /* If this is a PC relative reloc, see if the range it covers
1145 includes the bytes we have deleted. */
1146 switch (irel
->r_type
)
1151 case R_SH_PCDISP8BY2
:
1153 case R_SH_PCRELIMM8BY2
:
1154 case R_SH_PCRELIMM8BY4
:
1155 start
= irel
->r_vaddr
- sec
->vma
;
1156 insn
= bfd_get_16 (abfd
, contents
+ nraddr
);
1160 switch (irel
->r_type
)
1163 start
= stop
= addr
;
1169 case R_SH_IMAGEBASE
:
1171 /* If this reloc is against a symbol defined in this
1172 section, and the symbol will not be adjusted below, we
1173 must check the addend to see it will put the value in
1174 range to be adjusted, and hence must be changed. */
1175 bfd_coff_swap_sym_in (abfd
,
1176 ((bfd_byte
*) obj_coff_external_syms (abfd
)
1178 * bfd_coff_symesz (abfd
))),
1180 if (sym
.n_sclass
!= C_EXT
1181 && sym
.n_scnum
== sec
->target_index
1182 && ((bfd_vma
) sym
.n_value
<= addr
1183 || (bfd_vma
) sym
.n_value
>= toaddr
))
1187 val
= bfd_get_32 (abfd
, contents
+ nraddr
);
1189 if (val
> addr
&& val
< toaddr
)
1190 bfd_put_32 (abfd
, val
- count
, contents
+ nraddr
);
1192 start
= stop
= addr
;
1195 case R_SH_PCDISP8BY2
:
1199 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
1203 bfd_coff_swap_sym_in (abfd
,
1204 ((bfd_byte
*) obj_coff_external_syms (abfd
)
1206 * bfd_coff_symesz (abfd
))),
1208 if (sym
.n_sclass
== C_EXT
)
1209 start
= stop
= addr
;
1215 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
1219 case R_SH_PCRELIMM8BY2
:
1221 stop
= start
+ 4 + off
* 2;
1224 case R_SH_PCRELIMM8BY4
:
1226 stop
= (start
&~ (bfd_vma
) 3) + 4 + off
* 4;
1232 /* These relocs types represent
1234 The r_offset field holds the difference between the reloc
1235 address and L1. That is the start of the reloc, and
1236 adding in the contents gives us the top. We must adjust
1237 both the r_offset field and the section contents. */
1239 start
= irel
->r_vaddr
- sec
->vma
;
1240 stop
= (bfd_vma
) ((bfd_signed_vma
) start
- (long) irel
->r_offset
);
1244 && (stop
<= addr
|| stop
>= toaddr
))
1245 irel
->r_offset
+= count
;
1246 else if (stop
> addr
1248 && (start
<= addr
|| start
>= toaddr
))
1249 irel
->r_offset
-= count
;
1253 if (irel
->r_type
== R_SH_SWITCH16
)
1254 voff
= bfd_get_signed_16 (abfd
, contents
+ nraddr
);
1255 else if (irel
->r_type
== R_SH_SWITCH8
)
1256 voff
= bfd_get_8 (abfd
, contents
+ nraddr
);
1258 voff
= bfd_get_signed_32 (abfd
, contents
+ nraddr
);
1259 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
1264 start
= irel
->r_vaddr
- sec
->vma
;
1265 stop
= (bfd_vma
) ((bfd_signed_vma
) start
1266 + (long) irel
->r_offset
1273 && (stop
<= addr
|| stop
>= toaddr
))
1275 else if (stop
> addr
1277 && (start
<= addr
|| start
>= toaddr
))
1286 switch (irel
->r_type
)
1292 case R_SH_PCDISP8BY2
:
1293 case R_SH_PCRELIMM8BY2
:
1295 if ((oinsn
& 0xff00) != (insn
& 0xff00))
1297 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
1302 if ((oinsn
& 0xf000) != (insn
& 0xf000))
1304 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
1307 case R_SH_PCRELIMM8BY4
:
1308 BFD_ASSERT (adjust
== count
|| count
>= 4);
1313 if ((irel
->r_vaddr
& 3) == 0)
1316 if ((oinsn
& 0xff00) != (insn
& 0xff00))
1318 bfd_put_16 (abfd
, (bfd_vma
) insn
, contents
+ nraddr
);
1323 if (voff
< 0 || voff
>= 0xff)
1325 bfd_put_8 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
1330 if (voff
< - 0x8000 || voff
>= 0x8000)
1332 bfd_put_signed_16 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
1337 bfd_put_signed_32 (abfd
, (bfd_vma
) voff
, contents
+ nraddr
);
1341 irel
->r_offset
+= adjust
;
1348 /* xgettext: c-format */
1349 (_("%pB: %#" PRIx64
": fatal: reloc overflow while relaxing"),
1350 abfd
, (uint64_t) irel
->r_vaddr
);
1351 bfd_set_error (bfd_error_bad_value
);
1356 irel
->r_vaddr
= nraddr
+ sec
->vma
;
1359 /* Look through all the other sections. If there contain any IMM32
1360 relocs against internal symbols which we are not going to adjust
1361 below, we may need to adjust the addends. */
1362 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
1364 struct internal_reloc
*internal_relocs
;
1365 struct internal_reloc
*irelscan
, *irelscanend
;
1366 bfd_byte
*ocontents
;
1369 || (o
->flags
& SEC_HAS_CONTENTS
) == 0
1370 || (o
->flags
& SEC_RELOC
) == 0
1371 || o
->reloc_count
== 0)
1374 /* We always cache the relocs. Perhaps, if info->keep_memory is
1375 FALSE, we should free them, if we are permitted to, when we
1376 leave sh_coff_relax_section. */
1377 internal_relocs
= (_bfd_coff_read_internal_relocs
1378 (abfd
, o
, true, (bfd_byte
*) NULL
, false,
1379 (struct internal_reloc
*) NULL
));
1380 if (internal_relocs
== NULL
)
1384 irelscanend
= internal_relocs
+ o
->reloc_count
;
1385 for (irelscan
= internal_relocs
; irelscan
< irelscanend
; irelscan
++)
1387 struct internal_syment sym
;
1390 if (irelscan
->r_type
!= R_SH_IMM32
1391 && irelscan
->r_type
!= R_SH_IMAGEBASE
1392 && irelscan
->r_type
!= R_SH_IMM32CE
)
1394 if (irelscan
->r_type
!= R_SH_IMM32
)
1398 bfd_coff_swap_sym_in (abfd
,
1399 ((bfd_byte
*) obj_coff_external_syms (abfd
)
1400 + (irelscan
->r_symndx
1401 * bfd_coff_symesz (abfd
))),
1403 if (sym
.n_sclass
!= C_EXT
1404 && sym
.n_scnum
== sec
->target_index
1405 && ((bfd_vma
) sym
.n_value
<= addr
1406 || (bfd_vma
) sym
.n_value
>= toaddr
))
1410 if (ocontents
== NULL
)
1412 if (coff_section_data (abfd
, o
)->contents
!= NULL
)
1413 ocontents
= coff_section_data (abfd
, o
)->contents
;
1416 if (!bfd_malloc_and_get_section (abfd
, o
, &ocontents
))
1418 /* We always cache the section contents.
1419 Perhaps, if info->keep_memory is FALSE, we
1420 should free them, if we are permitted to,
1421 when we leave sh_coff_relax_section. */
1422 coff_section_data (abfd
, o
)->contents
= ocontents
;
1426 val
= bfd_get_32 (abfd
, ocontents
+ irelscan
->r_vaddr
- o
->vma
);
1428 if (val
> addr
&& val
< toaddr
)
1429 bfd_put_32 (abfd
, val
- count
,
1430 ocontents
+ irelscan
->r_vaddr
- o
->vma
);
1435 /* Adjusting the internal symbols will not work if something has
1436 already retrieved the generic symbols. It would be possible to
1437 make this work by adjusting the generic symbols at the same time.
1438 However, this case should not arise in normal usage. */
1439 if (obj_symbols (abfd
) != NULL
1440 || obj_raw_syments (abfd
) != NULL
)
1443 (_("%pB: fatal: generic symbols retrieved before relaxing"), abfd
);
1444 bfd_set_error (bfd_error_invalid_operation
);
1448 /* Adjust all the symbols. */
1449 sym_hash
= obj_coff_sym_hashes (abfd
);
1450 symesz
= bfd_coff_symesz (abfd
);
1451 esym
= (bfd_byte
*) obj_coff_external_syms (abfd
);
1452 esymend
= esym
+ obj_raw_syment_count (abfd
) * symesz
;
1453 while (esym
< esymend
)
1455 struct internal_syment isym
;
1457 bfd_coff_swap_sym_in (abfd
, esym
, &isym
);
1459 if (isym
.n_scnum
== sec
->target_index
1460 && (bfd_vma
) isym
.n_value
> addr
1461 && (bfd_vma
) isym
.n_value
< toaddr
)
1463 isym
.n_value
-= count
;
1465 bfd_coff_swap_sym_out (abfd
, &isym
, esym
);
1467 if (*sym_hash
!= NULL
)
1469 BFD_ASSERT ((*sym_hash
)->root
.type
== bfd_link_hash_defined
1470 || (*sym_hash
)->root
.type
== bfd_link_hash_defweak
);
1471 BFD_ASSERT ((*sym_hash
)->root
.u
.def
.value
>= addr
1472 && (*sym_hash
)->root
.u
.def
.value
< toaddr
);
1473 (*sym_hash
)->root
.u
.def
.value
-= count
;
1477 esym
+= (isym
.n_numaux
+ 1) * symesz
;
1478 sym_hash
+= isym
.n_numaux
+ 1;
1481 /* See if we can move the ALIGN reloc forward. We have adjusted
1482 r_vaddr for it already. */
1483 if (irelalign
!= NULL
)
1485 bfd_vma alignto
, alignaddr
;
1487 alignto
= BFD_ALIGN (toaddr
, 1 << irelalign
->r_offset
);
1488 alignaddr
= BFD_ALIGN (irelalign
->r_vaddr
- sec
->vma
,
1489 1 << irelalign
->r_offset
);
1490 if (alignto
!= alignaddr
)
1492 /* Tail recursion. */
1493 return sh_relax_delete_bytes (abfd
, sec
, alignaddr
,
1494 (int) (alignto
- alignaddr
));
1501 /* This is yet another version of the SH opcode table, used to rapidly
1502 get information about a particular instruction. */
1504 /* The opcode map is represented by an array of these structures. The
1505 array is indexed by the high order four bits in the instruction. */
1507 struct sh_major_opcode
1509 /* A pointer to the instruction list. This is an array which
1510 contains all the instructions with this major opcode. */
1511 const struct sh_minor_opcode
*minor_opcodes
;
1512 /* The number of elements in minor_opcodes. */
1513 unsigned short count
;
1516 /* This structure holds information for a set of SH opcodes. The
1517 instruction code is anded with the mask value, and the resulting
1518 value is used to search the order opcode list. */
1520 struct sh_minor_opcode
1522 /* The sorted opcode list. */
1523 const struct sh_opcode
*opcodes
;
1524 /* The number of elements in opcodes. */
1525 unsigned short count
;
1526 /* The mask value to use when searching the opcode list. */
1527 unsigned short mask
;
1530 /* This structure holds information for an SH instruction. An array
1531 of these structures is sorted in order by opcode. */
1535 /* The code for this instruction, after it has been anded with the
1536 mask value in the sh_major_opcode structure. */
1537 unsigned short opcode
;
1538 /* Flags for this instruction. */
1539 unsigned long flags
;
1542 /* Flag which appear in the sh_opcode structure. */
1544 /* This instruction loads a value from memory. */
1547 /* This instruction stores a value to memory. */
1550 /* This instruction is a branch. */
1551 #define BRANCH (0x4)
1553 /* This instruction has a delay slot. */
1556 /* This instruction uses the value in the register in the field at
1557 mask 0x0f00 of the instruction. */
1558 #define USES1 (0x10)
1559 #define USES1_REG(x) ((x & 0x0f00) >> 8)
1561 /* This instruction uses the value in the register in the field at
1562 mask 0x00f0 of the instruction. */
1563 #define USES2 (0x20)
1564 #define USES2_REG(x) ((x & 0x00f0) >> 4)
1566 /* This instruction uses the value in register 0. */
1567 #define USESR0 (0x40)
1569 /* This instruction sets the value in the register in the field at
1570 mask 0x0f00 of the instruction. */
1571 #define SETS1 (0x80)
1572 #define SETS1_REG(x) ((x & 0x0f00) >> 8)
1574 /* This instruction sets the value in the register in the field at
1575 mask 0x00f0 of the instruction. */
1576 #define SETS2 (0x100)
1577 #define SETS2_REG(x) ((x & 0x00f0) >> 4)
1579 /* This instruction sets register 0. */
1580 #define SETSR0 (0x200)
1582 /* This instruction sets a special register. */
1583 #define SETSSP (0x400)
1585 /* This instruction uses a special register. */
1586 #define USESSP (0x800)
1588 /* This instruction uses the floating point register in the field at
1589 mask 0x0f00 of the instruction. */
1590 #define USESF1 (0x1000)
1591 #define USESF1_REG(x) ((x & 0x0f00) >> 8)
1593 /* This instruction uses the floating point register in the field at
1594 mask 0x00f0 of the instruction. */
1595 #define USESF2 (0x2000)
1596 #define USESF2_REG(x) ((x & 0x00f0) >> 4)
1598 /* This instruction uses floating point register 0. */
1599 #define USESF0 (0x4000)
1601 /* This instruction sets the floating point register in the field at
1602 mask 0x0f00 of the instruction. */
1603 #define SETSF1 (0x8000)
1604 #define SETSF1_REG(x) ((x & 0x0f00) >> 8)
1606 #define USESAS (0x10000)
1607 #define USESAS_REG(x) (((((x) >> 8) - 2) & 3) + 2)
1608 #define USESR8 (0x20000)
1609 #define SETSAS (0x40000)
1610 #define SETSAS_REG(x) USESAS_REG (x)
1612 #define MAP(a) a, sizeof a / sizeof a[0]
1614 #ifndef COFF_IMAGE_WITH_PE
1616 /* The opcode maps. */
1618 static const struct sh_opcode sh_opcode00
[] =
1620 { 0x0008, SETSSP
}, /* clrt */
1621 { 0x0009, 0 }, /* nop */
1622 { 0x000b, BRANCH
| DELAY
| USESSP
}, /* rts */
1623 { 0x0018, SETSSP
}, /* sett */
1624 { 0x0019, SETSSP
}, /* div0u */
1625 { 0x001b, 0 }, /* sleep */
1626 { 0x0028, SETSSP
}, /* clrmac */
1627 { 0x002b, BRANCH
| DELAY
| SETSSP
}, /* rte */
1628 { 0x0038, USESSP
| SETSSP
}, /* ldtlb */
1629 { 0x0048, SETSSP
}, /* clrs */
1630 { 0x0058, SETSSP
} /* sets */
1633 static const struct sh_opcode sh_opcode01
[] =
1635 { 0x0003, BRANCH
| DELAY
| USES1
| SETSSP
}, /* bsrf rn */
1636 { 0x000a, SETS1
| USESSP
}, /* sts mach,rn */
1637 { 0x001a, SETS1
| USESSP
}, /* sts macl,rn */
1638 { 0x0023, BRANCH
| DELAY
| USES1
}, /* braf rn */
1639 { 0x0029, SETS1
| USESSP
}, /* movt rn */
1640 { 0x002a, SETS1
| USESSP
}, /* sts pr,rn */
1641 { 0x005a, SETS1
| USESSP
}, /* sts fpul,rn */
1642 { 0x006a, SETS1
| USESSP
}, /* sts fpscr,rn / sts dsr,rn */
1643 { 0x0083, LOAD
| USES1
}, /* pref @rn */
1644 { 0x007a, SETS1
| USESSP
}, /* sts a0,rn */
1645 { 0x008a, SETS1
| USESSP
}, /* sts x0,rn */
1646 { 0x009a, SETS1
| USESSP
}, /* sts x1,rn */
1647 { 0x00aa, SETS1
| USESSP
}, /* sts y0,rn */
1648 { 0x00ba, SETS1
| USESSP
} /* sts y1,rn */
1651 static const struct sh_opcode sh_opcode02
[] =
1653 { 0x0002, SETS1
| USESSP
}, /* stc <special_reg>,rn */
1654 { 0x0004, STORE
| USES1
| USES2
| USESR0
}, /* mov.b rm,@(r0,rn) */
1655 { 0x0005, STORE
| USES1
| USES2
| USESR0
}, /* mov.w rm,@(r0,rn) */
1656 { 0x0006, STORE
| USES1
| USES2
| USESR0
}, /* mov.l rm,@(r0,rn) */
1657 { 0x0007, SETSSP
| USES1
| USES2
}, /* mul.l rm,rn */
1658 { 0x000c, LOAD
| SETS1
| USES2
| USESR0
}, /* mov.b @(r0,rm),rn */
1659 { 0x000d, LOAD
| SETS1
| USES2
| USESR0
}, /* mov.w @(r0,rm),rn */
1660 { 0x000e, LOAD
| SETS1
| USES2
| USESR0
}, /* mov.l @(r0,rm),rn */
1661 { 0x000f, LOAD
|SETS1
|SETS2
|SETSSP
|USES1
|USES2
|USESSP
}, /* mac.l @rm+,@rn+ */
1664 static const struct sh_minor_opcode sh_opcode0
[] =
1666 { MAP (sh_opcode00
), 0xffff },
1667 { MAP (sh_opcode01
), 0xf0ff },
1668 { MAP (sh_opcode02
), 0xf00f }
1671 static const struct sh_opcode sh_opcode10
[] =
1673 { 0x1000, STORE
| USES1
| USES2
} /* mov.l rm,@(disp,rn) */
1676 static const struct sh_minor_opcode sh_opcode1
[] =
1678 { MAP (sh_opcode10
), 0xf000 }
1681 static const struct sh_opcode sh_opcode20
[] =
1683 { 0x2000, STORE
| USES1
| USES2
}, /* mov.b rm,@rn */
1684 { 0x2001, STORE
| USES1
| USES2
}, /* mov.w rm,@rn */
1685 { 0x2002, STORE
| USES1
| USES2
}, /* mov.l rm,@rn */
1686 { 0x2004, STORE
| SETS1
| USES1
| USES2
}, /* mov.b rm,@-rn */
1687 { 0x2005, STORE
| SETS1
| USES1
| USES2
}, /* mov.w rm,@-rn */
1688 { 0x2006, STORE
| SETS1
| USES1
| USES2
}, /* mov.l rm,@-rn */
1689 { 0x2007, SETSSP
| USES1
| USES2
| USESSP
}, /* div0s */
1690 { 0x2008, SETSSP
| USES1
| USES2
}, /* tst rm,rn */
1691 { 0x2009, SETS1
| USES1
| USES2
}, /* and rm,rn */
1692 { 0x200a, SETS1
| USES1
| USES2
}, /* xor rm,rn */
1693 { 0x200b, SETS1
| USES1
| USES2
}, /* or rm,rn */
1694 { 0x200c, SETSSP
| USES1
| USES2
}, /* cmp/str rm,rn */
1695 { 0x200d, SETS1
| USES1
| USES2
}, /* xtrct rm,rn */
1696 { 0x200e, SETSSP
| USES1
| USES2
}, /* mulu.w rm,rn */
1697 { 0x200f, SETSSP
| USES1
| USES2
} /* muls.w rm,rn */
1700 static const struct sh_minor_opcode sh_opcode2
[] =
1702 { MAP (sh_opcode20
), 0xf00f }
1705 static const struct sh_opcode sh_opcode30
[] =
1707 { 0x3000, SETSSP
| USES1
| USES2
}, /* cmp/eq rm,rn */
1708 { 0x3002, SETSSP
| USES1
| USES2
}, /* cmp/hs rm,rn */
1709 { 0x3003, SETSSP
| USES1
| USES2
}, /* cmp/ge rm,rn */
1710 { 0x3004, SETSSP
| USESSP
| USES1
| USES2
}, /* div1 rm,rn */
1711 { 0x3005, SETSSP
| USES1
| USES2
}, /* dmulu.l rm,rn */
1712 { 0x3006, SETSSP
| USES1
| USES2
}, /* cmp/hi rm,rn */
1713 { 0x3007, SETSSP
| USES1
| USES2
}, /* cmp/gt rm,rn */
1714 { 0x3008, SETS1
| USES1
| USES2
}, /* sub rm,rn */
1715 { 0x300a, SETS1
| SETSSP
| USES1
| USES2
| USESSP
}, /* subc rm,rn */
1716 { 0x300b, SETS1
| SETSSP
| USES1
| USES2
}, /* subv rm,rn */
1717 { 0x300c, SETS1
| USES1
| USES2
}, /* add rm,rn */
1718 { 0x300d, SETSSP
| USES1
| USES2
}, /* dmuls.l rm,rn */
1719 { 0x300e, SETS1
| SETSSP
| USES1
| USES2
| USESSP
}, /* addc rm,rn */
1720 { 0x300f, SETS1
| SETSSP
| USES1
| USES2
} /* addv rm,rn */
1723 static const struct sh_minor_opcode sh_opcode3
[] =
1725 { MAP (sh_opcode30
), 0xf00f }
1728 static const struct sh_opcode sh_opcode40
[] =
1730 { 0x4000, SETS1
| SETSSP
| USES1
}, /* shll rn */
1731 { 0x4001, SETS1
| SETSSP
| USES1
}, /* shlr rn */
1732 { 0x4002, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l mach,@-rn */
1733 { 0x4004, SETS1
| SETSSP
| USES1
}, /* rotl rn */
1734 { 0x4005, SETS1
| SETSSP
| USES1
}, /* rotr rn */
1735 { 0x4006, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,mach */
1736 { 0x4008, SETS1
| USES1
}, /* shll2 rn */
1737 { 0x4009, SETS1
| USES1
}, /* shlr2 rn */
1738 { 0x400a, SETSSP
| USES1
}, /* lds rm,mach */
1739 { 0x400b, BRANCH
| DELAY
| USES1
}, /* jsr @rn */
1740 { 0x4010, SETS1
| SETSSP
| USES1
}, /* dt rn */
1741 { 0x4011, SETSSP
| USES1
}, /* cmp/pz rn */
1742 { 0x4012, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l macl,@-rn */
1743 { 0x4014, SETSSP
| USES1
}, /* setrc rm */
1744 { 0x4015, SETSSP
| USES1
}, /* cmp/pl rn */
1745 { 0x4016, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,macl */
1746 { 0x4018, SETS1
| USES1
}, /* shll8 rn */
1747 { 0x4019, SETS1
| USES1
}, /* shlr8 rn */
1748 { 0x401a, SETSSP
| USES1
}, /* lds rm,macl */
1749 { 0x401b, LOAD
| SETSSP
| USES1
}, /* tas.b @rn */
1750 { 0x4020, SETS1
| SETSSP
| USES1
}, /* shal rn */
1751 { 0x4021, SETS1
| SETSSP
| USES1
}, /* shar rn */
1752 { 0x4022, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l pr,@-rn */
1753 { 0x4024, SETS1
| SETSSP
| USES1
| USESSP
}, /* rotcl rn */
1754 { 0x4025, SETS1
| SETSSP
| USES1
| USESSP
}, /* rotcr rn */
1755 { 0x4026, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,pr */
1756 { 0x4028, SETS1
| USES1
}, /* shll16 rn */
1757 { 0x4029, SETS1
| USES1
}, /* shlr16 rn */
1758 { 0x402a, SETSSP
| USES1
}, /* lds rm,pr */
1759 { 0x402b, BRANCH
| DELAY
| USES1
}, /* jmp @rn */
1760 { 0x4052, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l fpul,@-rn */
1761 { 0x4056, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,fpul */
1762 { 0x405a, SETSSP
| USES1
}, /* lds.l rm,fpul */
1763 { 0x4062, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l fpscr / dsr,@-rn */
1764 { 0x4066, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,fpscr / dsr */
1765 { 0x406a, SETSSP
| USES1
}, /* lds rm,fpscr / lds rm,dsr */
1766 { 0x4072, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l a0,@-rn */
1767 { 0x4076, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,a0 */
1768 { 0x407a, SETSSP
| USES1
}, /* lds.l rm,a0 */
1769 { 0x4082, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l x0,@-rn */
1770 { 0x4086, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,x0 */
1771 { 0x408a, SETSSP
| USES1
}, /* lds.l rm,x0 */
1772 { 0x4092, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l x1,@-rn */
1773 { 0x4096, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,x1 */
1774 { 0x409a, SETSSP
| USES1
}, /* lds.l rm,x1 */
1775 { 0x40a2, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l y0,@-rn */
1776 { 0x40a6, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,y0 */
1777 { 0x40aa, SETSSP
| USES1
}, /* lds.l rm,y0 */
1778 { 0x40b2, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l y1,@-rn */
1779 { 0x40b6, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,y1 */
1780 { 0x40ba, SETSSP
| USES1
} /* lds.l rm,y1 */
1783 static const struct sh_opcode sh_opcode41
[] =
1785 { 0x4003, STORE
| SETS1
| USES1
| USESSP
}, /* stc.l <special_reg>,@-rn */
1786 { 0x4007, LOAD
| SETS1
| SETSSP
| USES1
}, /* ldc.l @rm+,<special_reg> */
1787 { 0x400c, SETS1
| USES1
| USES2
}, /* shad rm,rn */
1788 { 0x400d, SETS1
| USES1
| USES2
}, /* shld rm,rn */
1789 { 0x400e, SETSSP
| USES1
}, /* ldc rm,<special_reg> */
1790 { 0x400f, LOAD
|SETS1
|SETS2
|SETSSP
|USES1
|USES2
|USESSP
}, /* mac.w @rm+,@rn+ */
1793 static const struct sh_minor_opcode sh_opcode4
[] =
1795 { MAP (sh_opcode40
), 0xf0ff },
1796 { MAP (sh_opcode41
), 0xf00f }
1799 static const struct sh_opcode sh_opcode50
[] =
1801 { 0x5000, LOAD
| SETS1
| USES2
} /* mov.l @(disp,rm),rn */
1804 static const struct sh_minor_opcode sh_opcode5
[] =
1806 { MAP (sh_opcode50
), 0xf000 }
1809 static const struct sh_opcode sh_opcode60
[] =
1811 { 0x6000, LOAD
| SETS1
| USES2
}, /* mov.b @rm,rn */
1812 { 0x6001, LOAD
| SETS1
| USES2
}, /* mov.w @rm,rn */
1813 { 0x6002, LOAD
| SETS1
| USES2
}, /* mov.l @rm,rn */
1814 { 0x6003, SETS1
| USES2
}, /* mov rm,rn */
1815 { 0x6004, LOAD
| SETS1
| SETS2
| USES2
}, /* mov.b @rm+,rn */
1816 { 0x6005, LOAD
| SETS1
| SETS2
| USES2
}, /* mov.w @rm+,rn */
1817 { 0x6006, LOAD
| SETS1
| SETS2
| USES2
}, /* mov.l @rm+,rn */
1818 { 0x6007, SETS1
| USES2
}, /* not rm,rn */
1819 { 0x6008, SETS1
| USES2
}, /* swap.b rm,rn */
1820 { 0x6009, SETS1
| USES2
}, /* swap.w rm,rn */
1821 { 0x600a, SETS1
| SETSSP
| USES2
| USESSP
}, /* negc rm,rn */
1822 { 0x600b, SETS1
| USES2
}, /* neg rm,rn */
1823 { 0x600c, SETS1
| USES2
}, /* extu.b rm,rn */
1824 { 0x600d, SETS1
| USES2
}, /* extu.w rm,rn */
1825 { 0x600e, SETS1
| USES2
}, /* exts.b rm,rn */
1826 { 0x600f, SETS1
| USES2
} /* exts.w rm,rn */
1829 static const struct sh_minor_opcode sh_opcode6
[] =
1831 { MAP (sh_opcode60
), 0xf00f }
1834 static const struct sh_opcode sh_opcode70
[] =
1836 { 0x7000, SETS1
| USES1
} /* add #imm,rn */
1839 static const struct sh_minor_opcode sh_opcode7
[] =
1841 { MAP (sh_opcode70
), 0xf000 }
1844 static const struct sh_opcode sh_opcode80
[] =
1846 { 0x8000, STORE
| USES2
| USESR0
}, /* mov.b r0,@(disp,rn) */
1847 { 0x8100, STORE
| USES2
| USESR0
}, /* mov.w r0,@(disp,rn) */
1848 { 0x8200, SETSSP
}, /* setrc #imm */
1849 { 0x8400, LOAD
| SETSR0
| USES2
}, /* mov.b @(disp,rm),r0 */
1850 { 0x8500, LOAD
| SETSR0
| USES2
}, /* mov.w @(disp,rn),r0 */
1851 { 0x8800, SETSSP
| USESR0
}, /* cmp/eq #imm,r0 */
1852 { 0x8900, BRANCH
| USESSP
}, /* bt label */
1853 { 0x8b00, BRANCH
| USESSP
}, /* bf label */
1854 { 0x8c00, SETSSP
}, /* ldrs @(disp,pc) */
1855 { 0x8d00, BRANCH
| DELAY
| USESSP
}, /* bt/s label */
1856 { 0x8e00, SETSSP
}, /* ldre @(disp,pc) */
1857 { 0x8f00, BRANCH
| DELAY
| USESSP
} /* bf/s label */
1860 static const struct sh_minor_opcode sh_opcode8
[] =
1862 { MAP (sh_opcode80
), 0xff00 }
1865 static const struct sh_opcode sh_opcode90
[] =
1867 { 0x9000, LOAD
| SETS1
} /* mov.w @(disp,pc),rn */
1870 static const struct sh_minor_opcode sh_opcode9
[] =
1872 { MAP (sh_opcode90
), 0xf000 }
1875 static const struct sh_opcode sh_opcodea0
[] =
1877 { 0xa000, BRANCH
| DELAY
} /* bra label */
1880 static const struct sh_minor_opcode sh_opcodea
[] =
1882 { MAP (sh_opcodea0
), 0xf000 }
1885 static const struct sh_opcode sh_opcodeb0
[] =
1887 { 0xb000, BRANCH
| DELAY
} /* bsr label */
1890 static const struct sh_minor_opcode sh_opcodeb
[] =
1892 { MAP (sh_opcodeb0
), 0xf000 }
1895 static const struct sh_opcode sh_opcodec0
[] =
1897 { 0xc000, STORE
| USESR0
| USESSP
}, /* mov.b r0,@(disp,gbr) */
1898 { 0xc100, STORE
| USESR0
| USESSP
}, /* mov.w r0,@(disp,gbr) */
1899 { 0xc200, STORE
| USESR0
| USESSP
}, /* mov.l r0,@(disp,gbr) */
1900 { 0xc300, BRANCH
| USESSP
}, /* trapa #imm */
1901 { 0xc400, LOAD
| SETSR0
| USESSP
}, /* mov.b @(disp,gbr),r0 */
1902 { 0xc500, LOAD
| SETSR0
| USESSP
}, /* mov.w @(disp,gbr),r0 */
1903 { 0xc600, LOAD
| SETSR0
| USESSP
}, /* mov.l @(disp,gbr),r0 */
1904 { 0xc700, SETSR0
}, /* mova @(disp,pc),r0 */
1905 { 0xc800, SETSSP
| USESR0
}, /* tst #imm,r0 */
1906 { 0xc900, SETSR0
| USESR0
}, /* and #imm,r0 */
1907 { 0xca00, SETSR0
| USESR0
}, /* xor #imm,r0 */
1908 { 0xcb00, SETSR0
| USESR0
}, /* or #imm,r0 */
1909 { 0xcc00, LOAD
| SETSSP
| USESR0
| USESSP
}, /* tst.b #imm,@(r0,gbr) */
1910 { 0xcd00, LOAD
| STORE
| USESR0
| USESSP
}, /* and.b #imm,@(r0,gbr) */
1911 { 0xce00, LOAD
| STORE
| USESR0
| USESSP
}, /* xor.b #imm,@(r0,gbr) */
1912 { 0xcf00, LOAD
| STORE
| USESR0
| USESSP
} /* or.b #imm,@(r0,gbr) */
1915 static const struct sh_minor_opcode sh_opcodec
[] =
1917 { MAP (sh_opcodec0
), 0xff00 }
1920 static const struct sh_opcode sh_opcoded0
[] =
1922 { 0xd000, LOAD
| SETS1
} /* mov.l @(disp,pc),rn */
1925 static const struct sh_minor_opcode sh_opcoded
[] =
1927 { MAP (sh_opcoded0
), 0xf000 }
1930 static const struct sh_opcode sh_opcodee0
[] =
1932 { 0xe000, SETS1
} /* mov #imm,rn */
1935 static const struct sh_minor_opcode sh_opcodee
[] =
1937 { MAP (sh_opcodee0
), 0xf000 }
1940 static const struct sh_opcode sh_opcodef0
[] =
1942 { 0xf000, SETSF1
| USESF1
| USESF2
}, /* fadd fm,fn */
1943 { 0xf001, SETSF1
| USESF1
| USESF2
}, /* fsub fm,fn */
1944 { 0xf002, SETSF1
| USESF1
| USESF2
}, /* fmul fm,fn */
1945 { 0xf003, SETSF1
| USESF1
| USESF2
}, /* fdiv fm,fn */
1946 { 0xf004, SETSSP
| USESF1
| USESF2
}, /* fcmp/eq fm,fn */
1947 { 0xf005, SETSSP
| USESF1
| USESF2
}, /* fcmp/gt fm,fn */
1948 { 0xf006, LOAD
| SETSF1
| USES2
| USESR0
}, /* fmov.s @(r0,rm),fn */
1949 { 0xf007, STORE
| USES1
| USESF2
| USESR0
}, /* fmov.s fm,@(r0,rn) */
1950 { 0xf008, LOAD
| SETSF1
| USES2
}, /* fmov.s @rm,fn */
1951 { 0xf009, LOAD
| SETS2
| SETSF1
| USES2
}, /* fmov.s @rm+,fn */
1952 { 0xf00a, STORE
| USES1
| USESF2
}, /* fmov.s fm,@rn */
1953 { 0xf00b, STORE
| SETS1
| USES1
| USESF2
}, /* fmov.s fm,@-rn */
1954 { 0xf00c, SETSF1
| USESF2
}, /* fmov fm,fn */
1955 { 0xf00e, SETSF1
| USESF1
| USESF2
| USESF0
} /* fmac f0,fm,fn */
1958 static const struct sh_opcode sh_opcodef1
[] =
1960 { 0xf00d, SETSF1
| USESSP
}, /* fsts fpul,fn */
1961 { 0xf01d, SETSSP
| USESF1
}, /* flds fn,fpul */
1962 { 0xf02d, SETSF1
| USESSP
}, /* float fpul,fn */
1963 { 0xf03d, SETSSP
| USESF1
}, /* ftrc fn,fpul */
1964 { 0xf04d, SETSF1
| USESF1
}, /* fneg fn */
1965 { 0xf05d, SETSF1
| USESF1
}, /* fabs fn */
1966 { 0xf06d, SETSF1
| USESF1
}, /* fsqrt fn */
1967 { 0xf07d, SETSSP
| USESF1
}, /* ftst/nan fn */
1968 { 0xf08d, SETSF1
}, /* fldi0 fn */
1969 { 0xf09d, SETSF1
} /* fldi1 fn */
1972 static const struct sh_minor_opcode sh_opcodef
[] =
1974 { MAP (sh_opcodef0
), 0xf00f },
1975 { MAP (sh_opcodef1
), 0xf0ff }
1978 static struct sh_major_opcode sh_opcodes
[] =
1980 { MAP (sh_opcode0
) },
1981 { MAP (sh_opcode1
) },
1982 { MAP (sh_opcode2
) },
1983 { MAP (sh_opcode3
) },
1984 { MAP (sh_opcode4
) },
1985 { MAP (sh_opcode5
) },
1986 { MAP (sh_opcode6
) },
1987 { MAP (sh_opcode7
) },
1988 { MAP (sh_opcode8
) },
1989 { MAP (sh_opcode9
) },
1990 { MAP (sh_opcodea
) },
1991 { MAP (sh_opcodeb
) },
1992 { MAP (sh_opcodec
) },
1993 { MAP (sh_opcoded
) },
1994 { MAP (sh_opcodee
) },
1995 { MAP (sh_opcodef
) }
1998 /* The double data transfer / parallel processing insns are not
1999 described here. This will cause sh_align_load_span to leave them alone. */
2001 static const struct sh_opcode sh_dsp_opcodef0
[] =
2003 { 0xf400, USESAS
| SETSAS
| LOAD
| SETSSP
}, /* movs.x @-as,ds */
2004 { 0xf401, USESAS
| SETSAS
| STORE
| USESSP
}, /* movs.x ds,@-as */
2005 { 0xf404, USESAS
| LOAD
| SETSSP
}, /* movs.x @as,ds */
2006 { 0xf405, USESAS
| STORE
| USESSP
}, /* movs.x ds,@as */
2007 { 0xf408, USESAS
| SETSAS
| LOAD
| SETSSP
}, /* movs.x @as+,ds */
2008 { 0xf409, USESAS
| SETSAS
| STORE
| USESSP
}, /* movs.x ds,@as+ */
2009 { 0xf40c, USESAS
| SETSAS
| LOAD
| SETSSP
| USESR8
}, /* movs.x @as+r8,ds */
2010 { 0xf40d, USESAS
| SETSAS
| STORE
| USESSP
| USESR8
} /* movs.x ds,@as+r8 */
2013 static const struct sh_minor_opcode sh_dsp_opcodef
[] =
2015 { MAP (sh_dsp_opcodef0
), 0xfc0d }
2018 /* Given an instruction, return a pointer to the corresponding
2019 sh_opcode structure. Return NULL if the instruction is not
2022 static const struct sh_opcode
*
2023 sh_insn_info (unsigned int insn
)
2025 const struct sh_major_opcode
*maj
;
2026 const struct sh_minor_opcode
*min
, *minend
;
2028 maj
= &sh_opcodes
[(insn
& 0xf000) >> 12];
2029 min
= maj
->minor_opcodes
;
2030 minend
= min
+ maj
->count
;
2031 for (; min
< minend
; min
++)
2034 const struct sh_opcode
*op
, *opend
;
2036 l
= insn
& min
->mask
;
2038 opend
= op
+ min
->count
;
2040 /* Since the opcodes tables are sorted, we could use a binary
2041 search here if the count were above some cutoff value. */
2042 for (; op
< opend
; op
++)
2043 if (op
->opcode
== l
)
2050 /* See whether an instruction uses a general purpose register. */
2053 sh_insn_uses_reg (unsigned int insn
,
2054 const struct sh_opcode
*op
,
2061 if ((f
& USES1
) != 0
2062 && USES1_REG (insn
) == reg
)
2064 if ((f
& USES2
) != 0
2065 && USES2_REG (insn
) == reg
)
2067 if ((f
& USESR0
) != 0
2070 if ((f
& USESAS
) && reg
== USESAS_REG (insn
))
2072 if ((f
& USESR8
) && reg
== 8)
2078 /* See whether an instruction sets a general purpose register. */
2081 sh_insn_sets_reg (unsigned int insn
,
2082 const struct sh_opcode
*op
,
2089 if ((f
& SETS1
) != 0
2090 && SETS1_REG (insn
) == reg
)
2092 if ((f
& SETS2
) != 0
2093 && SETS2_REG (insn
) == reg
)
2095 if ((f
& SETSR0
) != 0
2098 if ((f
& SETSAS
) && reg
== SETSAS_REG (insn
))
2104 /* See whether an instruction uses or sets a general purpose register */
2107 sh_insn_uses_or_sets_reg (unsigned int insn
,
2108 const struct sh_opcode
*op
,
2111 if (sh_insn_uses_reg (insn
, op
, reg
))
2114 return sh_insn_sets_reg (insn
, op
, reg
);
2117 /* See whether an instruction uses a floating point register. */
2120 sh_insn_uses_freg (unsigned int insn
,
2121 const struct sh_opcode
*op
,
2128 /* We can't tell if this is a double-precision insn, so just play safe
2129 and assume that it might be. So not only have we test FREG against
2130 itself, but also even FREG against FREG+1 - if the using insn uses
2131 just the low part of a double precision value - but also an odd
2132 FREG against FREG-1 - if the setting insn sets just the low part
2133 of a double precision value.
2134 So what this all boils down to is that we have to ignore the lowest
2135 bit of the register number. */
2137 if ((f
& USESF1
) != 0
2138 && (USESF1_REG (insn
) & 0xe) == (freg
& 0xe))
2140 if ((f
& USESF2
) != 0
2141 && (USESF2_REG (insn
) & 0xe) == (freg
& 0xe))
2143 if ((f
& USESF0
) != 0
2150 /* See whether an instruction sets a floating point register. */
2153 sh_insn_sets_freg (unsigned int insn
,
2154 const struct sh_opcode
*op
,
2161 /* We can't tell if this is a double-precision insn, so just play safe
2162 and assume that it might be. So not only have we test FREG against
2163 itself, but also even FREG against FREG+1 - if the using insn uses
2164 just the low part of a double precision value - but also an odd
2165 FREG against FREG-1 - if the setting insn sets just the low part
2166 of a double precision value.
2167 So what this all boils down to is that we have to ignore the lowest
2168 bit of the register number. */
2170 if ((f
& SETSF1
) != 0
2171 && (SETSF1_REG (insn
) & 0xe) == (freg
& 0xe))
2177 /* See whether an instruction uses or sets a floating point register */
2180 sh_insn_uses_or_sets_freg (unsigned int insn
,
2181 const struct sh_opcode
*op
,
2184 if (sh_insn_uses_freg (insn
, op
, reg
))
2187 return sh_insn_sets_freg (insn
, op
, reg
);
2190 /* See whether instructions I1 and I2 conflict, assuming I1 comes
2191 before I2. OP1 and OP2 are the corresponding sh_opcode structures.
2192 This should return TRUE if there is a conflict, or FALSE if the
2193 instructions can be swapped safely. */
2196 sh_insns_conflict (unsigned int i1
,
2197 const struct sh_opcode
*op1
,
2199 const struct sh_opcode
*op2
)
2201 unsigned int f1
, f2
;
2206 /* Load of fpscr conflicts with floating point operations.
2207 FIXME: shouldn't test raw opcodes here. */
2208 if (((i1
& 0xf0ff) == 0x4066 && (i2
& 0xf000) == 0xf000)
2209 || ((i2
& 0xf0ff) == 0x4066 && (i1
& 0xf000) == 0xf000))
2212 if ((f1
& (BRANCH
| DELAY
)) != 0
2213 || (f2
& (BRANCH
| DELAY
)) != 0)
2216 if (((f1
| f2
) & SETSSP
)
2217 && (f1
& (SETSSP
| USESSP
))
2218 && (f2
& (SETSSP
| USESSP
)))
2221 if ((f1
& SETS1
) != 0
2222 && sh_insn_uses_or_sets_reg (i2
, op2
, SETS1_REG (i1
)))
2224 if ((f1
& SETS2
) != 0
2225 && sh_insn_uses_or_sets_reg (i2
, op2
, SETS2_REG (i1
)))
2227 if ((f1
& SETSR0
) != 0
2228 && sh_insn_uses_or_sets_reg (i2
, op2
, 0))
2231 && sh_insn_uses_or_sets_reg (i2
, op2
, SETSAS_REG (i1
)))
2233 if ((f1
& SETSF1
) != 0
2234 && sh_insn_uses_or_sets_freg (i2
, op2
, SETSF1_REG (i1
)))
2237 if ((f2
& SETS1
) != 0
2238 && sh_insn_uses_or_sets_reg (i1
, op1
, SETS1_REG (i2
)))
2240 if ((f2
& SETS2
) != 0
2241 && sh_insn_uses_or_sets_reg (i1
, op1
, SETS2_REG (i2
)))
2243 if ((f2
& SETSR0
) != 0
2244 && sh_insn_uses_or_sets_reg (i1
, op1
, 0))
2247 && sh_insn_uses_or_sets_reg (i1
, op1
, SETSAS_REG (i2
)))
2249 if ((f2
& SETSF1
) != 0
2250 && sh_insn_uses_or_sets_freg (i1
, op1
, SETSF1_REG (i2
)))
2253 /* The instructions do not conflict. */
2257 /* I1 is a load instruction, and I2 is some other instruction. Return
2258 TRUE if I1 loads a register which I2 uses. */
2261 sh_load_use (unsigned int i1
,
2262 const struct sh_opcode
*op1
,
2264 const struct sh_opcode
*op2
)
2270 if ((f1
& LOAD
) == 0)
2273 /* If both SETS1 and SETSSP are set, that means a load to a special
2274 register using postincrement addressing mode, which we don't care
2276 if ((f1
& SETS1
) != 0
2277 && (f1
& SETSSP
) == 0
2278 && sh_insn_uses_reg (i2
, op2
, (i1
& 0x0f00) >> 8))
2281 if ((f1
& SETSR0
) != 0
2282 && sh_insn_uses_reg (i2
, op2
, 0))
2285 if ((f1
& SETSF1
) != 0
2286 && sh_insn_uses_freg (i2
, op2
, (i1
& 0x0f00) >> 8))
2292 /* Try to align loads and stores within a span of memory. This is
2293 called by both the ELF and the COFF sh targets. ABFD and SEC are
2294 the BFD and section we are examining. CONTENTS is the contents of
2295 the section. SWAP is the routine to call to swap two instructions.
2296 RELOCS is a pointer to the internal relocation information, to be
2297 passed to SWAP. PLABEL is a pointer to the current label in a
2298 sorted list of labels; LABEL_END is the end of the list. START and
2299 STOP are the range of memory to examine. If a swap is made,
2300 *PSWAPPED is set to TRUE. */
2306 _bfd_sh_align_load_span (bfd
*abfd
,
2309 bool (*swap
) (bfd
*, asection
*, void *, bfd_byte
*, bfd_vma
),
2317 int dsp
= (abfd
->arch_info
->mach
== bfd_mach_sh_dsp
2318 || abfd
->arch_info
->mach
== bfd_mach_sh3_dsp
);
2321 /* The SH4 has a Harvard architecture, hence aligning loads is not
2322 desirable. In fact, it is counter-productive, since it interferes
2323 with the schedules generated by the compiler. */
2324 if (abfd
->arch_info
->mach
== bfd_mach_sh4
)
2327 /* If we are linking sh[3]-dsp code, swap the FPU instructions for DSP
2331 sh_opcodes
[0xf].minor_opcodes
= sh_dsp_opcodef
;
2332 sh_opcodes
[0xf].count
= sizeof sh_dsp_opcodef
/ sizeof sh_dsp_opcodef
[0];
2335 /* Instructions should be aligned on 2 byte boundaries. */
2336 if ((start
& 1) == 1)
2339 /* Now look through the unaligned addresses. */
2343 for (; i
< stop
; i
+= 4)
2346 const struct sh_opcode
*op
;
2347 unsigned int prev_insn
= 0;
2348 const struct sh_opcode
*prev_op
= NULL
;
2350 insn
= bfd_get_16 (abfd
, contents
+ i
);
2351 op
= sh_insn_info (insn
);
2353 || (op
->flags
& (LOAD
| STORE
)) == 0)
2356 /* This is a load or store which is not on a four byte boundary. */
2358 while (*plabel
< label_end
&& **plabel
< i
)
2363 prev_insn
= bfd_get_16 (abfd
, contents
+ i
- 2);
2364 /* If INSN is the field b of a parallel processing insn, it is not
2365 a load / store after all. Note that the test here might mistake
2366 the field_b of a pcopy insn for the starting code of a parallel
2367 processing insn; this might miss a swapping opportunity, but at
2368 least we're on the safe side. */
2369 if (dsp
&& (prev_insn
& 0xfc00) == 0xf800)
2372 /* Check if prev_insn is actually the field b of a parallel
2373 processing insn. Again, this can give a spurious match
2375 if (dsp
&& i
- 2 > start
)
2377 unsigned pprev_insn
= bfd_get_16 (abfd
, contents
+ i
- 4);
2379 if ((pprev_insn
& 0xfc00) == 0xf800)
2382 prev_op
= sh_insn_info (prev_insn
);
2385 prev_op
= sh_insn_info (prev_insn
);
2387 /* If the load/store instruction is in a delay slot, we
2390 || (prev_op
->flags
& DELAY
) != 0)
2394 && (*plabel
>= label_end
|| **plabel
!= i
)
2396 && (prev_op
->flags
& (LOAD
| STORE
)) == 0
2397 && ! sh_insns_conflict (prev_insn
, prev_op
, insn
, op
))
2401 /* The load/store instruction does not have a label, and
2402 there is a previous instruction; PREV_INSN is not
2403 itself a load/store instruction, and PREV_INSN and
2404 INSN do not conflict. */
2410 unsigned int prev2_insn
;
2411 const struct sh_opcode
*prev2_op
;
2413 prev2_insn
= bfd_get_16 (abfd
, contents
+ i
- 4);
2414 prev2_op
= sh_insn_info (prev2_insn
);
2416 /* If the instruction before PREV_INSN has a delay
2417 slot--that is, PREV_INSN is in a delay slot--we
2419 if (prev2_op
== NULL
2420 || (prev2_op
->flags
& DELAY
) != 0)
2423 /* If the instruction before PREV_INSN is a load,
2424 and it sets a register which INSN uses, then
2425 putting INSN immediately after PREV_INSN will
2426 cause a pipeline bubble, so there is no point to
2429 && (prev2_op
->flags
& LOAD
) != 0
2430 && sh_load_use (prev2_insn
, prev2_op
, insn
, op
))
2436 if (! (*swap
) (abfd
, sec
, relocs
, contents
, i
- 2))
2443 while (*plabel
< label_end
&& **plabel
< i
+ 2)
2447 && (*plabel
>= label_end
|| **plabel
!= i
+ 2))
2449 unsigned int next_insn
;
2450 const struct sh_opcode
*next_op
;
2452 /* There is an instruction after the load/store
2453 instruction, and it does not have a label. */
2454 next_insn
= bfd_get_16 (abfd
, contents
+ i
+ 2);
2455 next_op
= sh_insn_info (next_insn
);
2457 && (next_op
->flags
& (LOAD
| STORE
)) == 0
2458 && ! sh_insns_conflict (insn
, op
, next_insn
, next_op
))
2462 /* NEXT_INSN is not itself a load/store instruction,
2463 and it does not conflict with INSN. */
2467 /* If PREV_INSN is a load, and it sets a register
2468 which NEXT_INSN uses, then putting NEXT_INSN
2469 immediately after PREV_INSN will cause a pipeline
2470 bubble, so there is no reason to make this swap. */
2472 && (prev_op
->flags
& LOAD
) != 0
2473 && sh_load_use (prev_insn
, prev_op
, next_insn
, next_op
))
2476 /* If INSN is a load, and it sets a register which
2477 the insn after NEXT_INSN uses, then doing the
2478 swap will cause a pipeline bubble, so there is no
2479 reason to make the swap. However, if the insn
2480 after NEXT_INSN is itself a load or store
2481 instruction, then it is misaligned, so
2482 optimistically hope that it will be swapped
2483 itself, and just live with the pipeline bubble if
2487 && (op
->flags
& LOAD
) != 0)
2489 unsigned int next2_insn
;
2490 const struct sh_opcode
*next2_op
;
2492 next2_insn
= bfd_get_16 (abfd
, contents
+ i
+ 4);
2493 next2_op
= sh_insn_info (next2_insn
);
2494 if (next2_op
== NULL
2495 || ((next2_op
->flags
& (LOAD
| STORE
)) == 0
2496 && sh_load_use (insn
, op
, next2_insn
, next2_op
)))
2502 if (! (*swap
) (abfd
, sec
, relocs
, contents
, i
))
2513 #endif /* not COFF_IMAGE_WITH_PE */
2515 /* Swap two SH instructions. */
2518 sh_swap_insns (bfd
* abfd
,
2521 bfd_byte
* contents
,
2524 struct internal_reloc
*internal_relocs
= (struct internal_reloc
*) relocs
;
2525 unsigned short i1
, i2
;
2526 struct internal_reloc
*irel
, *irelend
;
2528 /* Swap the instructions themselves. */
2529 i1
= bfd_get_16 (abfd
, contents
+ addr
);
2530 i2
= bfd_get_16 (abfd
, contents
+ addr
+ 2);
2531 bfd_put_16 (abfd
, (bfd_vma
) i2
, contents
+ addr
);
2532 bfd_put_16 (abfd
, (bfd_vma
) i1
, contents
+ addr
+ 2);
2534 /* Adjust all reloc addresses. */
2535 irelend
= internal_relocs
+ sec
->reloc_count
;
2536 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2540 /* There are a few special types of relocs that we don't want to
2541 adjust. These relocs do not apply to the instruction itself,
2542 but are only associated with the address. */
2543 type
= irel
->r_type
;
2544 if (type
== R_SH_ALIGN
2545 || type
== R_SH_CODE
2546 || type
== R_SH_DATA
2547 || type
== R_SH_LABEL
)
2550 /* If an R_SH_USES reloc points to one of the addresses being
2551 swapped, we must adjust it. It would be incorrect to do this
2552 for a jump, though, since we want to execute both
2553 instructions after the jump. (We have avoided swapping
2554 around a label, so the jump will not wind up executing an
2555 instruction it shouldn't). */
2556 if (type
== R_SH_USES
)
2560 off
= irel
->r_vaddr
- sec
->vma
+ 4 + irel
->r_offset
;
2562 irel
->r_offset
+= 2;
2563 else if (off
== addr
+ 2)
2564 irel
->r_offset
-= 2;
2567 if (irel
->r_vaddr
- sec
->vma
== addr
)
2572 else if (irel
->r_vaddr
- sec
->vma
== addr
+ 2)
2583 unsigned short insn
, oinsn
;
2586 loc
= contents
+ irel
->r_vaddr
- sec
->vma
;
2593 case R_SH_PCDISP8BY2
:
2594 case R_SH_PCRELIMM8BY2
:
2595 insn
= bfd_get_16 (abfd
, loc
);
2598 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2600 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
2604 insn
= bfd_get_16 (abfd
, loc
);
2607 if ((oinsn
& 0xf000) != (insn
& 0xf000))
2609 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
2612 case R_SH_PCRELIMM8BY4
:
2613 /* This reloc ignores the least significant 3 bits of
2614 the program counter before adding in the offset.
2615 This means that if ADDR is at an even address, the
2616 swap will not affect the offset. If ADDR is an at an
2617 odd address, then the instruction will be crossing a
2618 four byte boundary, and must be adjusted. */
2619 if ((addr
& 3) != 0)
2621 insn
= bfd_get_16 (abfd
, loc
);
2624 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2626 bfd_put_16 (abfd
, (bfd_vma
) insn
, loc
);
2635 /* xgettext: c-format */
2636 (_("%pB: %#" PRIx64
": fatal: reloc overflow while relaxing"),
2637 abfd
, (uint64_t) irel
->r_vaddr
);
2638 bfd_set_error (bfd_error_bad_value
);
2647 /* Look for loads and stores which we can align to four byte
2648 boundaries. See the longer comment above sh_relax_section for why
2649 this is desirable. This sets *PSWAPPED if some instruction was
2653 sh_align_loads (bfd
*abfd
,
2655 struct internal_reloc
*internal_relocs
,
2659 struct internal_reloc
*irel
, *irelend
;
2660 bfd_vma
*labels
= NULL
;
2661 bfd_vma
*label
, *label_end
;
2666 irelend
= internal_relocs
+ sec
->reloc_count
;
2668 /* Get all the addresses with labels on them. */
2669 amt
= (bfd_size_type
) sec
->reloc_count
* sizeof (bfd_vma
);
2670 labels
= (bfd_vma
*) bfd_malloc (amt
);
2674 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2676 if (irel
->r_type
== R_SH_LABEL
)
2678 *label_end
= irel
->r_vaddr
- sec
->vma
;
2683 /* Note that the assembler currently always outputs relocs in
2684 address order. If that ever changes, this code will need to sort
2685 the label values and the relocs. */
2689 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2691 bfd_vma start
, stop
;
2693 if (irel
->r_type
!= R_SH_CODE
)
2696 start
= irel
->r_vaddr
- sec
->vma
;
2698 for (irel
++; irel
< irelend
; irel
++)
2699 if (irel
->r_type
== R_SH_DATA
)
2702 stop
= irel
->r_vaddr
- sec
->vma
;
2706 if (! _bfd_sh_align_load_span (abfd
, sec
, contents
, sh_swap_insns
,
2707 internal_relocs
, &label
,
2708 label_end
, start
, stop
, pswapped
))
2721 /* This is a modification of _bfd_coff_generic_relocate_section, which
2722 will handle SH relaxing. */
2725 sh_relocate_section (bfd
*output_bfd ATTRIBUTE_UNUSED
,
2726 struct bfd_link_info
*info
,
2728 asection
*input_section
,
2730 struct internal_reloc
*relocs
,
2731 struct internal_syment
*syms
,
2732 asection
**sections
)
2734 struct internal_reloc
*rel
;
2735 struct internal_reloc
*relend
;
2738 relend
= rel
+ input_section
->reloc_count
;
2739 for (; rel
< relend
; rel
++)
2742 struct coff_link_hash_entry
*h
;
2743 struct internal_syment
*sym
;
2746 reloc_howto_type
*howto
;
2747 bfd_reloc_status_type rstat
;
2749 /* Almost all relocs have to do with relaxing. If any work must
2750 be done for them, it has been done in sh_relax_section. */
2751 if (rel
->r_type
!= R_SH_IMM32
2753 && rel
->r_type
!= R_SH_IMM32CE
2754 && rel
->r_type
!= R_SH_IMAGEBASE
2756 && rel
->r_type
!= R_SH_PCDISP
)
2759 symndx
= rel
->r_symndx
;
2769 || (unsigned long) symndx
>= obj_raw_syment_count (input_bfd
))
2772 /* xgettext: c-format */
2773 (_("%pB: illegal symbol index %ld in relocs"),
2775 bfd_set_error (bfd_error_bad_value
);
2778 h
= obj_coff_sym_hashes (input_bfd
)[symndx
];
2779 sym
= syms
+ symndx
;
2782 if (sym
!= NULL
&& sym
->n_scnum
!= 0)
2783 addend
= - sym
->n_value
;
2787 if (rel
->r_type
== R_SH_PCDISP
)
2790 if (rel
->r_type
>= SH_COFF_HOWTO_COUNT
)
2793 howto
= &sh_coff_howtos
[rel
->r_type
];
2797 bfd_set_error (bfd_error_bad_value
);
2802 if (rel
->r_type
== R_SH_IMAGEBASE
)
2803 addend
-= pe_data (input_section
->output_section
->owner
)->pe_opthdr
.ImageBase
;
2812 /* There is nothing to do for an internal PCDISP reloc. */
2813 if (rel
->r_type
== R_SH_PCDISP
)
2818 sec
= bfd_abs_section_ptr
;
2823 sec
= sections
[symndx
];
2824 val
= (sec
->output_section
->vma
2825 + sec
->output_offset
2832 if (h
->root
.type
== bfd_link_hash_defined
2833 || h
->root
.type
== bfd_link_hash_defweak
)
2837 sec
= h
->root
.u
.def
.section
;
2838 val
= (h
->root
.u
.def
.value
2839 + sec
->output_section
->vma
2840 + sec
->output_offset
);
2842 else if (! bfd_link_relocatable (info
))
2843 (*info
->callbacks
->undefined_symbol
)
2844 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
2845 rel
->r_vaddr
- input_section
->vma
, true);
2848 rstat
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2850 rel
->r_vaddr
- input_section
->vma
,
2859 case bfd_reloc_overflow
:
2862 char buf
[SYMNMLEN
+ 1];
2868 else if (sym
->_n
._n_n
._n_zeroes
== 0
2869 && sym
->_n
._n_n
._n_offset
!= 0)
2871 if (sym
->_n
._n_n
._n_offset
< obj_coff_strings_len (input_bfd
))
2872 name
= obj_coff_strings (input_bfd
) + sym
->_n
._n_n
._n_offset
;
2878 strncpy (buf
, sym
->_n
._n_name
, SYMNMLEN
);
2879 buf
[SYMNMLEN
] = '\0';
2883 (*info
->callbacks
->reloc_overflow
)
2884 (info
, (h
? &h
->root
: NULL
), name
, howto
->name
,
2885 (bfd_vma
) 0, input_bfd
, input_section
,
2886 rel
->r_vaddr
- input_section
->vma
);
2894 /* This is a version of bfd_generic_get_relocated_section_contents
2895 which uses sh_relocate_section. */
2898 sh_coff_get_relocated_section_contents (bfd
*output_bfd
,
2899 struct bfd_link_info
*link_info
,
2900 struct bfd_link_order
*link_order
,
2905 asection
*input_section
= link_order
->u
.indirect
.section
;
2906 bfd
*input_bfd
= input_section
->owner
;
2907 asection
**sections
= NULL
;
2908 struct internal_reloc
*internal_relocs
= NULL
;
2909 struct internal_syment
*internal_syms
= NULL
;
2911 /* We only need to handle the case of relaxing, or of having a
2912 particular set of section contents, specially. */
2914 || coff_section_data (input_bfd
, input_section
) == NULL
2915 || coff_section_data (input_bfd
, input_section
)->contents
== NULL
)
2916 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
2921 bfd_byte
*orig_data
= data
;
2924 data
= bfd_malloc (input_section
->size
);
2928 memcpy (data
, coff_section_data (input_bfd
, input_section
)->contents
,
2929 (size_t) input_section
->size
);
2931 if ((input_section
->flags
& SEC_RELOC
) != 0
2932 && input_section
->reloc_count
> 0)
2934 bfd_size_type symesz
= bfd_coff_symesz (input_bfd
);
2935 bfd_byte
*esym
, *esymend
;
2936 struct internal_syment
*isymp
;
2940 if (! _bfd_coff_get_external_symbols (input_bfd
))
2943 internal_relocs
= (_bfd_coff_read_internal_relocs
2944 (input_bfd
, input_section
, false, (bfd_byte
*) NULL
,
2945 false, (struct internal_reloc
*) NULL
));
2946 if (internal_relocs
== NULL
)
2949 amt
= obj_raw_syment_count (input_bfd
);
2950 amt
*= sizeof (struct internal_syment
);
2951 internal_syms
= (struct internal_syment
*) bfd_malloc (amt
);
2952 if (internal_syms
== NULL
)
2955 amt
= obj_raw_syment_count (input_bfd
);
2956 amt
*= sizeof (asection
*);
2957 sections
= (asection
**) bfd_malloc (amt
);
2958 if (sections
== NULL
)
2961 isymp
= internal_syms
;
2963 esym
= (bfd_byte
*) obj_coff_external_syms (input_bfd
);
2964 esymend
= esym
+ obj_raw_syment_count (input_bfd
) * symesz
;
2965 while (esym
< esymend
)
2967 bfd_coff_swap_sym_in (input_bfd
, esym
, isymp
);
2969 if (isymp
->n_scnum
!= 0)
2970 *secpp
= coff_section_from_bfd_index (input_bfd
, isymp
->n_scnum
);
2973 if (isymp
->n_value
== 0)
2974 *secpp
= bfd_und_section_ptr
;
2976 *secpp
= bfd_com_section_ptr
;
2979 esym
+= (isymp
->n_numaux
+ 1) * symesz
;
2980 secpp
+= isymp
->n_numaux
+ 1;
2981 isymp
+= isymp
->n_numaux
+ 1;
2984 if (! sh_relocate_section (output_bfd
, link_info
, input_bfd
,
2985 input_section
, data
, internal_relocs
,
2986 internal_syms
, sections
))
2991 free (internal_syms
);
2992 internal_syms
= NULL
;
2993 free (internal_relocs
);
2994 internal_relocs
= NULL
;
3000 free (internal_relocs
);
3001 free (internal_syms
);
3003 if (orig_data
== NULL
)
3008 /* The target vectors. */
3010 #ifndef TARGET_SHL_SYM
3011 CREATE_BIG_COFF_TARGET_VEC (sh_coff_vec
, "coff-sh", BFD_IS_RELAXABLE
, 0, '_', NULL
, COFF_SWAP_TABLE
)
3014 #ifdef TARGET_SHL_SYM
3015 #define TARGET_SYM TARGET_SHL_SYM
3017 #define TARGET_SYM sh_coff_le_vec
3020 #ifndef TARGET_SHL_NAME
3021 #define TARGET_SHL_NAME "coff-shl"
3025 CREATE_LITTLE_COFF_TARGET_VEC (TARGET_SYM
, TARGET_SHL_NAME
, BFD_IS_RELAXABLE
,
3026 SEC_CODE
| SEC_DATA
, '_', NULL
, COFF_SWAP_TABLE
);
3028 CREATE_LITTLE_COFF_TARGET_VEC (TARGET_SYM
, TARGET_SHL_NAME
, BFD_IS_RELAXABLE
,
3029 0, '_', NULL
, COFF_SWAP_TABLE
)
3032 #ifndef TARGET_SHL_SYM
3034 /* Some people want versions of the SH COFF target which do not align
3035 to 16 byte boundaries. We implement that by adding a couple of new
3036 target vectors. These are just like the ones above, but they
3037 change the default section alignment. To generate them in the
3038 assembler, use -small. To use them in the linker, use -b
3039 coff-sh{l}-small and -oformat coff-sh{l}-small.
3041 Yes, this is a horrible hack. A general solution for setting
3042 section alignment in COFF is rather complex. ELF handles this
3045 /* Only recognize the small versions if the target was not defaulted.
3046 Otherwise we won't recognize the non default endianness. */
3049 coff_small_object_p (bfd
*abfd
)
3051 if (abfd
->target_defaulted
)
3053 bfd_set_error (bfd_error_wrong_format
);
3056 return coff_object_p (abfd
);
3059 /* Set the section alignment for the small versions. */
3062 coff_small_new_section_hook (bfd
*abfd
, asection
*section
)
3064 if (! coff_new_section_hook (abfd
, section
))
3067 /* We must align to at least a four byte boundary, because longword
3068 accesses must be on a four byte boundary. */
3069 if (section
->alignment_power
== COFF_DEFAULT_SECTION_ALIGNMENT_POWER
)
3070 section
->alignment_power
= 2;
3075 /* This is copied from bfd_coff_std_swap_table so that we can change
3076 the default section alignment power. */
3078 static const bfd_coff_backend_data bfd_coff_small_swap_table
=
3080 coff_swap_aux_in
, coff_swap_sym_in
, coff_swap_lineno_in
,
3081 coff_swap_aux_out
, coff_swap_sym_out
,
3082 coff_swap_lineno_out
, coff_swap_reloc_out
,
3083 coff_swap_filehdr_out
, coff_swap_aouthdr_out
,
3084 coff_swap_scnhdr_out
,
3085 FILHSZ
, AOUTSZ
, SCNHSZ
, SYMESZ
, AUXESZ
, RELSZ
, LINESZ
, FILNMLEN
,
3086 #ifdef COFF_LONG_FILENAMES
3091 COFF_DEFAULT_LONG_SECTION_NAMES
,
3093 #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
3098 #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
3104 coff_swap_filehdr_in
, coff_swap_aouthdr_in
, coff_swap_scnhdr_in
,
3105 coff_swap_reloc_in
, coff_bad_format_hook
, coff_set_arch_mach_hook
,
3106 coff_mkobject_hook
, styp_to_sec_flags
, coff_set_alignment_hook
,
3107 coff_slurp_symbol_table
, symname_in_debug_hook
, coff_pointerize_aux_hook
,
3108 coff_print_aux
, coff_reloc16_extra_cases
, coff_reloc16_estimate
,
3109 coff_classify_symbol
, coff_compute_section_file_positions
,
3110 coff_start_final_link
, coff_relocate_section
, coff_rtype_to_howto
,
3111 coff_adjust_symndx
, coff_link_add_one_symbol
,
3112 coff_link_output_has_begun
, coff_final_link_postscript
,
3116 #define coff_small_close_and_cleanup \
3117 coff_close_and_cleanup
3118 #define coff_small_bfd_free_cached_info \
3119 coff_bfd_free_cached_info
3120 #define coff_small_get_section_contents \
3121 coff_get_section_contents
3122 #define coff_small_get_section_contents_in_window \
3123 coff_get_section_contents_in_window
3125 extern const bfd_target sh_coff_small_le_vec
;
3127 const bfd_target sh_coff_small_vec
=
3129 "coff-sh-small", /* name */
3130 bfd_target_coff_flavour
,
3131 BFD_ENDIAN_BIG
, /* data byte order is big */
3132 BFD_ENDIAN_BIG
, /* header byte order is big */
3134 (HAS_RELOC
| EXEC_P
/* object flags */
3135 | HAS_LINENO
| HAS_DEBUG
3136 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| BFD_IS_RELAXABLE
),
3138 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
),
3139 '_', /* leading symbol underscore */
3140 '/', /* ar_pad_char */
3141 15, /* ar_max_namelen */
3142 0, /* match priority. */
3143 TARGET_KEEP_UNUSED_SECTION_SYMBOLS
, /* keep unused section symbols. */
3144 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3145 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3146 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
3147 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
3148 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
3149 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
3151 { /* bfd_check_format */
3153 coff_small_object_p
,
3154 bfd_generic_archive_p
,
3157 { /* bfd_set_format */
3158 _bfd_bool_bfd_false_error
,
3160 _bfd_generic_mkarchive
,
3161 _bfd_bool_bfd_false_error
3163 { /* bfd_write_contents */
3164 _bfd_bool_bfd_false_error
,
3165 coff_write_object_contents
,
3166 _bfd_write_archive_contents
,
3167 _bfd_bool_bfd_false_error
3170 BFD_JUMP_TABLE_GENERIC (coff_small
),
3171 BFD_JUMP_TABLE_COPY (coff
),
3172 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
3173 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
3174 BFD_JUMP_TABLE_SYMBOLS (coff
),
3175 BFD_JUMP_TABLE_RELOCS (coff
),
3176 BFD_JUMP_TABLE_WRITE (coff
),
3177 BFD_JUMP_TABLE_LINK (coff
),
3178 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
3180 &sh_coff_small_le_vec
,
3182 &bfd_coff_small_swap_table
3185 const bfd_target sh_coff_small_le_vec
=
3187 "coff-shl-small", /* name */
3188 bfd_target_coff_flavour
,
3189 BFD_ENDIAN_LITTLE
, /* data byte order is little */
3190 BFD_ENDIAN_LITTLE
, /* header byte order is little endian too*/
3192 (HAS_RELOC
| EXEC_P
/* object flags */
3193 | HAS_LINENO
| HAS_DEBUG
3194 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| BFD_IS_RELAXABLE
),
3196 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
),
3197 '_', /* leading symbol underscore */
3198 '/', /* ar_pad_char */
3199 15, /* ar_max_namelen */
3200 0, /* match priority. */
3201 TARGET_KEEP_UNUSED_SECTION_SYMBOLS
, /* keep unused section symbols. */
3202 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
3203 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
3204 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* data */
3205 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
3206 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
3207 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* hdrs */
3209 { /* bfd_check_format */
3211 coff_small_object_p
,
3212 bfd_generic_archive_p
,
3215 { /* bfd_set_format */
3216 _bfd_bool_bfd_false_error
,
3218 _bfd_generic_mkarchive
,
3219 _bfd_bool_bfd_false_error
3221 { /* bfd_write_contents */
3222 _bfd_bool_bfd_false_error
,
3223 coff_write_object_contents
,
3224 _bfd_write_archive_contents
,
3225 _bfd_bool_bfd_false_error
3228 BFD_JUMP_TABLE_GENERIC (coff_small
),
3229 BFD_JUMP_TABLE_COPY (coff
),
3230 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
3231 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
3232 BFD_JUMP_TABLE_SYMBOLS (coff
),
3233 BFD_JUMP_TABLE_RELOCS (coff
),
3234 BFD_JUMP_TABLE_WRITE (coff
),
3235 BFD_JUMP_TABLE_LINK (coff
),
3236 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
3240 &bfd_coff_small_swap_table