1 /* BFD back-end for Hitachi Super-H COFF binaries.
2 Copyright 1993, 94, 95, 96, 97, 1998 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include "coff/internal.h"
31 /* Internal functions. */
32 static bfd_reloc_status_type sh_reloc
33 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
34 static long get_symbol_value
PARAMS ((asymbol
*));
35 static boolean sh_merge_private_data
PARAMS ((bfd
*, bfd
*));
36 static boolean sh_relax_section
37 PARAMS ((bfd
*, asection
*, struct bfd_link_info
*, boolean
*));
38 static boolean sh_relax_delete_bytes
39 PARAMS ((bfd
*, asection
*, bfd_vma
, int));
40 static const struct sh_opcode
*sh_insn_info
PARAMS ((unsigned int));
41 static boolean sh_align_loads
42 PARAMS ((bfd
*, asection
*, struct internal_reloc
*, bfd_byte
*, boolean
*));
43 static boolean sh_swap_insns
44 PARAMS ((bfd
*, asection
*, PTR
, bfd_byte
*, bfd_vma
));
45 static boolean sh_relocate_section
46 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
47 struct internal_reloc
*, struct internal_syment
*, asection
**));
48 static bfd_byte
*sh_coff_get_relocated_section_contents
49 PARAMS ((bfd
*, struct bfd_link_info
*, struct bfd_link_order
*,
50 bfd_byte
*, boolean
, asymbol
**));
52 /* Default section alignment to 2**4. */
53 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (4)
55 /* Generate long file names. */
56 #define COFF_LONG_FILENAMES
58 /* The supported relocations. There are a lot of relocations defined
59 in coff/internal.h which we do not expect to ever see. */
60 static reloc_howto_type sh_coff_howtos
[] =
65 { 3 }, /* R_SH_PCREL8 */
66 { 4 }, /* R_SH_PCREL16 */
67 { 5 }, /* R_SH_HIGH8 */
68 { 6 }, /* R_SH_IMM24 */
69 { 7 }, /* R_SH_LOW16 */
71 { 9 }, /* R_SH_PCDISP8BY4 */
73 HOWTO (R_SH_PCDISP8BY2
, /* type */
75 1, /* size (0 = byte, 1 = short, 2 = long) */
77 true, /* pc_relative */
79 complain_overflow_signed
, /* complain_on_overflow */
80 sh_reloc
, /* special_function */
81 "r_pcdisp8by2", /* name */
82 true, /* partial_inplace */
85 true), /* pcrel_offset */
87 { 11 }, /* R_SH_PCDISP8 */
89 HOWTO (R_SH_PCDISP
, /* type */
91 1, /* size (0 = byte, 1 = short, 2 = long) */
93 true, /* pc_relative */
95 complain_overflow_signed
, /* complain_on_overflow */
96 sh_reloc
, /* special_function */
97 "r_pcdisp12by2", /* name */
98 true, /* partial_inplace */
100 0xfff, /* dst_mask */
101 true), /* pcrel_offset */
105 HOWTO (R_SH_IMM32
, /* type */
107 2, /* size (0 = byte, 1 = short, 2 = long) */
109 false, /* pc_relative */
111 complain_overflow_bitfield
, /* complain_on_overflow */
112 sh_reloc
, /* special_function */
113 "r_imm32", /* name */
114 true, /* partial_inplace */
115 0xffffffff, /* src_mask */
116 0xffffffff, /* dst_mask */
117 false), /* pcrel_offset */
120 { 16 }, /* R_SH_IMM8 */
121 { 17 }, /* R_SH_IMM8BY2 */
122 { 18 }, /* R_SH_IMM8BY4 */
123 { 19 }, /* R_SH_IMM4 */
124 { 20 }, /* R_SH_IMM4BY2 */
125 { 21 }, /* R_SH_IMM4BY4 */
127 HOWTO (R_SH_PCRELIMM8BY2
, /* type */
129 1, /* size (0 = byte, 1 = short, 2 = long) */
131 true, /* pc_relative */
133 complain_overflow_unsigned
, /* complain_on_overflow */
134 sh_reloc
, /* special_function */
135 "r_pcrelimm8by2", /* name */
136 true, /* partial_inplace */
139 true), /* pcrel_offset */
141 HOWTO (R_SH_PCRELIMM8BY4
, /* type */
143 1, /* size (0 = byte, 1 = short, 2 = long) */
145 true, /* pc_relative */
147 complain_overflow_unsigned
, /* complain_on_overflow */
148 sh_reloc
, /* special_function */
149 "r_pcrelimm8by4", /* name */
150 true, /* partial_inplace */
153 true), /* pcrel_offset */
155 HOWTO (R_SH_IMM16
, /* type */
157 1, /* size (0 = byte, 1 = short, 2 = long) */
159 false, /* pc_relative */
161 complain_overflow_bitfield
, /* complain_on_overflow */
162 sh_reloc
, /* special_function */
163 "r_imm16", /* name */
164 true, /* partial_inplace */
165 0xffff, /* src_mask */
166 0xffff, /* dst_mask */
167 false), /* pcrel_offset */
169 HOWTO (R_SH_SWITCH16
, /* type */
171 1, /* size (0 = byte, 1 = short, 2 = long) */
173 false, /* pc_relative */
175 complain_overflow_bitfield
, /* complain_on_overflow */
176 sh_reloc
, /* special_function */
177 "r_switch16", /* name */
178 true, /* partial_inplace */
179 0xffff, /* src_mask */
180 0xffff, /* dst_mask */
181 false), /* pcrel_offset */
183 HOWTO (R_SH_SWITCH32
, /* type */
185 2, /* size (0 = byte, 1 = short, 2 = long) */
187 false, /* pc_relative */
189 complain_overflow_bitfield
, /* complain_on_overflow */
190 sh_reloc
, /* special_function */
191 "r_switch32", /* name */
192 true, /* partial_inplace */
193 0xffffffff, /* src_mask */
194 0xffffffff, /* dst_mask */
195 false), /* pcrel_offset */
197 HOWTO (R_SH_USES
, /* type */
199 1, /* size (0 = byte, 1 = short, 2 = long) */
201 false, /* pc_relative */
203 complain_overflow_bitfield
, /* complain_on_overflow */
204 sh_reloc
, /* special_function */
206 true, /* partial_inplace */
207 0xffff, /* src_mask */
208 0xffff, /* dst_mask */
209 false), /* pcrel_offset */
211 HOWTO (R_SH_COUNT
, /* type */
213 2, /* size (0 = byte, 1 = short, 2 = long) */
215 false, /* pc_relative */
217 complain_overflow_bitfield
, /* complain_on_overflow */
218 sh_reloc
, /* special_function */
219 "r_count", /* name */
220 true, /* partial_inplace */
221 0xffffffff, /* src_mask */
222 0xffffffff, /* dst_mask */
223 false), /* pcrel_offset */
225 HOWTO (R_SH_ALIGN
, /* type */
227 2, /* size (0 = byte, 1 = short, 2 = long) */
229 false, /* pc_relative */
231 complain_overflow_bitfield
, /* complain_on_overflow */
232 sh_reloc
, /* special_function */
233 "r_align", /* name */
234 true, /* partial_inplace */
235 0xffffffff, /* src_mask */
236 0xffffffff, /* dst_mask */
237 false), /* pcrel_offset */
239 HOWTO (R_SH_CODE
, /* type */
241 2, /* size (0 = byte, 1 = short, 2 = long) */
243 false, /* pc_relative */
245 complain_overflow_bitfield
, /* complain_on_overflow */
246 sh_reloc
, /* special_function */
248 true, /* partial_inplace */
249 0xffffffff, /* src_mask */
250 0xffffffff, /* dst_mask */
251 false), /* pcrel_offset */
253 HOWTO (R_SH_DATA
, /* type */
255 2, /* size (0 = byte, 1 = short, 2 = long) */
257 false, /* pc_relative */
259 complain_overflow_bitfield
, /* complain_on_overflow */
260 sh_reloc
, /* special_function */
262 true, /* partial_inplace */
263 0xffffffff, /* src_mask */
264 0xffffffff, /* dst_mask */
265 false), /* pcrel_offset */
267 HOWTO (R_SH_LABEL
, /* type */
269 2, /* size (0 = byte, 1 = short, 2 = long) */
271 false, /* pc_relative */
273 complain_overflow_bitfield
, /* complain_on_overflow */
274 sh_reloc
, /* special_function */
275 "r_label", /* name */
276 true, /* partial_inplace */
277 0xffffffff, /* src_mask */
278 0xffffffff, /* dst_mask */
279 false), /* pcrel_offset */
281 HOWTO (R_SH_SWITCH8
, /* type */
283 0, /* size (0 = byte, 1 = short, 2 = long) */
285 false, /* pc_relative */
287 complain_overflow_bitfield
, /* complain_on_overflow */
288 sh_reloc
, /* special_function */
289 "r_switch8", /* name */
290 true, /* partial_inplace */
293 false) /* pcrel_offset */
296 #define SH_COFF_HOWTO_COUNT (sizeof sh_coff_howtos / sizeof sh_coff_howtos[0])
298 /* Check for a bad magic number. */
299 #define BADMAG(x) SHBADMAG(x)
301 /* Customize coffcode.h (this is not currently used). */
304 /* FIXME: This should not be set here. */
305 #define __A_MAGIC_SET__
307 /* Swap the r_offset field in and out. */
308 #define SWAP_IN_RELOC_OFFSET bfd_h_get_32
309 #define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
311 /* Swap out extra information in the reloc structure. */
312 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
315 dst->r_stuff[0] = 'S'; \
316 dst->r_stuff[1] = 'C'; \
320 /* Get the value of a symbol, when performing a relocation. */
323 get_symbol_value (symbol
)
328 if (bfd_is_com_section (symbol
->section
))
331 relocation
= (symbol
->value
+
332 symbol
->section
->output_section
->vma
+
333 symbol
->section
->output_offset
);
338 /* This macro is used in coffcode.h to get the howto corresponding to
339 an internal reloc. */
341 #define RTYPE2HOWTO(relent, internal) \
343 ((internal)->r_type < SH_COFF_HOWTO_COUNT \
344 ? &sh_coff_howtos[(internal)->r_type] \
345 : (reloc_howto_type *) NULL))
347 /* This is the same as the macro in coffcode.h, except that it copies
348 r_offset into reloc_entry->addend for some relocs. */
349 #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
351 coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \
352 if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
353 coffsym = (obj_symbols (abfd) \
354 + (cache_ptr->sym_ptr_ptr - symbols)); \
356 coffsym = coff_symbol_from (abfd, ptr); \
357 if (coffsym != (coff_symbol_type *) NULL \
358 && coffsym->native->u.syment.n_scnum == 0) \
359 cache_ptr->addend = 0; \
360 else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
361 && ptr->section != (asection *) NULL) \
362 cache_ptr->addend = - (ptr->section->vma + ptr->value); \
364 cache_ptr->addend = 0; \
365 if ((reloc).r_type == R_SH_SWITCH8 \
366 || (reloc).r_type == R_SH_SWITCH16 \
367 || (reloc).r_type == R_SH_SWITCH32 \
368 || (reloc).r_type == R_SH_USES \
369 || (reloc).r_type == R_SH_COUNT \
370 || (reloc).r_type == R_SH_ALIGN) \
371 cache_ptr->addend = (reloc).r_offset; \
374 /* This is the howto function for the SH relocations. */
376 static bfd_reloc_status_type
377 sh_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
380 arelent
*reloc_entry
;
383 asection
*input_section
;
385 char **error_message
;
389 unsigned short r_type
;
390 bfd_vma addr
= reloc_entry
->address
;
391 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
393 r_type
= reloc_entry
->howto
->type
;
395 if (output_bfd
!= NULL
)
397 /* Partial linking--do nothing. */
398 reloc_entry
->address
+= input_section
->output_offset
;
402 /* Almost all relocs have to do with relaxing. If any work must be
403 done for them, it has been done in sh_relax_section. */
404 if (r_type
!= R_SH_IMM32
405 && (r_type
!= R_SH_PCDISP
406 || (symbol_in
->flags
& BSF_LOCAL
) != 0))
409 if (symbol_in
!= NULL
410 && bfd_is_und_section (symbol_in
->section
))
411 return bfd_reloc_undefined
;
413 sym_value
= get_symbol_value (symbol_in
);
418 insn
= bfd_get_32 (abfd
, hit_data
);
419 insn
+= sym_value
+ reloc_entry
->addend
;
420 bfd_put_32 (abfd
, insn
, hit_data
);
423 insn
= bfd_get_16 (abfd
, hit_data
);
424 sym_value
+= reloc_entry
->addend
;
425 sym_value
-= (input_section
->output_section
->vma
426 + input_section
->output_offset
429 sym_value
+= (insn
& 0xfff) << 1;
432 insn
= (insn
& 0xf000) | (sym_value
& 0xfff);
433 bfd_put_16 (abfd
, insn
, hit_data
);
434 if (sym_value
< (bfd_vma
) -0x1000 || sym_value
>= 0x1000)
435 return bfd_reloc_overflow
;
445 /* This routine checks for linking big and little endian objects
449 sh_merge_private_data (ibfd
, obfd
)
453 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
454 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
456 (*_bfd_error_handler
)
457 ("%s: compiled for a %s endian system and target is %s endian",
458 bfd_get_filename (ibfd
),
459 bfd_big_endian (ibfd
) ? "big" : "little",
460 bfd_big_endian (obfd
) ? "big" : "little");
462 bfd_set_error (bfd_error_wrong_format
);
469 #define coff_bfd_merge_private_bfd_data sh_merge_private_data
471 /* We can do relaxing. */
472 #define coff_bfd_relax_section sh_relax_section
474 /* We use the special COFF backend linker. */
475 #define coff_relocate_section sh_relocate_section
477 /* When relaxing, we need to use special code to get the relocated
479 #define coff_bfd_get_relocated_section_contents \
480 sh_coff_get_relocated_section_contents
482 #include "coffcode.h"
484 /* This function handles relaxing on the SH.
486 Function calls on the SH look like this:
495 The compiler and assembler will cooperate to create R_SH_USES
496 relocs on the jsr instructions. The r_offset field of the
497 R_SH_USES reloc is the PC relative offset to the instruction which
498 loads the register (the r_offset field is computed as though it
499 were a jump instruction, so the offset value is actually from four
500 bytes past the instruction). The linker can use this reloc to
501 determine just which function is being called, and thus decide
502 whether it is possible to replace the jsr with a bsr.
504 If multiple function calls are all based on a single register load
505 (i.e., the same function is called multiple times), the compiler
506 guarantees that each function call will have an R_SH_USES reloc.
507 Therefore, if the linker is able to convert each R_SH_USES reloc
508 which refers to that address, it can safely eliminate the register
511 When the assembler creates an R_SH_USES reloc, it examines it to
512 determine which address is being loaded (L1 in the above example).
513 It then counts the number of references to that address, and
514 creates an R_SH_COUNT reloc at that address. The r_offset field of
515 the R_SH_COUNT reloc will be the number of references. If the
516 linker is able to eliminate a register load, it can use the
517 R_SH_COUNT reloc to see whether it can also eliminate the function
520 SH relaxing also handles another, unrelated, matter. On the SH, if
521 a load or store instruction is not aligned on a four byte boundary,
522 the memory cycle interferes with the 32 bit instruction fetch,
523 causing a one cycle bubble in the pipeline. Therefore, we try to
524 align load and store instructions on four byte boundaries if we
525 can, by swapping them with one of the adjacent instructions. */
528 sh_relax_section (abfd
, sec
, link_info
, again
)
531 struct bfd_link_info
*link_info
;
534 struct internal_reloc
*internal_relocs
;
535 struct internal_reloc
*free_relocs
= NULL
;
537 struct internal_reloc
*irel
, *irelend
;
538 bfd_byte
*contents
= NULL
;
539 bfd_byte
*free_contents
= NULL
;
543 if (link_info
->relocateable
544 || (sec
->flags
& SEC_RELOC
) == 0
545 || sec
->reloc_count
== 0)
548 /* If this is the first time we have been called for this section,
549 initialize the cooked size. */
550 if (sec
->_cooked_size
== 0)
551 sec
->_cooked_size
= sec
->_raw_size
;
553 internal_relocs
= (_bfd_coff_read_internal_relocs
554 (abfd
, sec
, link_info
->keep_memory
,
555 (bfd_byte
*) NULL
, false,
556 (struct internal_reloc
*) NULL
));
557 if (internal_relocs
== NULL
)
559 if (! link_info
->keep_memory
)
560 free_relocs
= internal_relocs
;
564 irelend
= internal_relocs
+ sec
->reloc_count
;
565 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
567 bfd_vma laddr
, paddr
, symval
;
569 struct internal_reloc
*irelfn
, *irelscan
, *irelcount
;
570 struct internal_syment sym
;
573 if (irel
->r_type
== R_SH_CODE
)
576 if (irel
->r_type
!= R_SH_USES
)
579 /* Get the section contents. */
580 if (contents
== NULL
)
582 if (coff_section_data (abfd
, sec
) != NULL
583 && coff_section_data (abfd
, sec
)->contents
!= NULL
)
584 contents
= coff_section_data (abfd
, sec
)->contents
;
587 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
588 if (contents
== NULL
)
590 free_contents
= contents
;
592 if (! bfd_get_section_contents (abfd
, sec
, contents
,
593 (file_ptr
) 0, sec
->_raw_size
))
598 /* The r_offset field of the R_SH_USES reloc will point us to
599 the register load. The 4 is because the r_offset field is
600 computed as though it were a jump offset, which are based
601 from 4 bytes after the jump instruction. */
602 laddr
= irel
->r_vaddr
- sec
->vma
+ 4;
603 /* Careful to sign extend the 32-bit offset. */
604 laddr
+= ((irel
->r_offset
& 0xffffffff) ^ 0x80000000) - 0x80000000;
605 if (laddr
>= sec
->_raw_size
)
607 (*_bfd_error_handler
) ("%s: 0x%lx: warning: bad R_SH_USES offset",
608 bfd_get_filename (abfd
),
609 (unsigned long) irel
->r_vaddr
);
612 insn
= bfd_get_16 (abfd
, contents
+ laddr
);
614 /* If the instruction is not mov.l NN,rN, we don't know what to do. */
615 if ((insn
& 0xf000) != 0xd000)
617 ((*_bfd_error_handler
)
618 ("%s: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x",
619 bfd_get_filename (abfd
), (unsigned long) irel
->r_vaddr
, insn
));
623 /* Get the address from which the register is being loaded. The
624 displacement in the mov.l instruction is quadrupled. It is a
625 displacement from four bytes after the movl instruction, but,
626 before adding in the PC address, two least significant bits
627 of the PC are cleared. We assume that the section is aligned
628 on a four byte boundary. */
631 paddr
+= (laddr
+ 4) &~ 3;
632 if (paddr
>= sec
->_raw_size
)
634 ((*_bfd_error_handler
)
635 ("%s: 0x%lx: warning: bad R_SH_USES load offset",
636 bfd_get_filename (abfd
), (unsigned long) irel
->r_vaddr
));
640 /* Get the reloc for the address from which the register is
641 being loaded. This reloc will tell us which function is
642 actually being called. */
644 for (irelfn
= internal_relocs
; irelfn
< irelend
; irelfn
++)
645 if (irelfn
->r_vaddr
== paddr
646 && irelfn
->r_type
== R_SH_IMM32
)
648 if (irelfn
>= irelend
)
650 ((*_bfd_error_handler
)
651 ("%s: 0x%lx: warning: could not find expected reloc",
652 bfd_get_filename (abfd
), (unsigned long) paddr
));
656 /* Get the value of the symbol referred to by the reloc. */
657 if (! _bfd_coff_get_external_symbols (abfd
))
659 bfd_coff_swap_sym_in (abfd
,
660 ((bfd_byte
*) obj_coff_external_syms (abfd
)
662 * bfd_coff_symesz (abfd
))),
664 if (sym
.n_scnum
!= 0 && sym
.n_scnum
!= sec
->target_index
)
666 ((*_bfd_error_handler
)
667 ("%s: 0x%lx: warning: symbol in unexpected section",
668 bfd_get_filename (abfd
), (unsigned long) paddr
));
672 if (sym
.n_sclass
!= C_EXT
)
674 symval
= (sym
.n_value
676 + sec
->output_section
->vma
677 + sec
->output_offset
);
681 struct coff_link_hash_entry
*h
;
683 h
= obj_coff_sym_hashes (abfd
)[irelfn
->r_symndx
];
684 BFD_ASSERT (h
!= NULL
);
685 if (h
->root
.type
!= bfd_link_hash_defined
686 && h
->root
.type
!= bfd_link_hash_defweak
)
688 /* This appears to be a reference to an undefined
689 symbol. Just ignore it--it will be caught by the
690 regular reloc processing. */
694 symval
= (h
->root
.u
.def
.value
695 + h
->root
.u
.def
.section
->output_section
->vma
696 + h
->root
.u
.def
.section
->output_offset
);
699 symval
+= bfd_get_32 (abfd
, contents
+ paddr
- sec
->vma
);
701 /* See if this function call can be shortened. */
705 + sec
->output_section
->vma
708 if (foff
< -0x1000 || foff
>= 0x1000)
710 /* After all that work, we can't shorten this function call. */
714 /* Shorten the function call. */
716 /* For simplicity of coding, we are going to modify the section
717 contents, the section relocs, and the BFD symbol table. We
718 must tell the rest of the code not to free up this
719 information. It would be possible to instead create a table
720 of changes which have to be made, as is done in coff-mips.c;
721 that would be more work, but would require less memory when
722 the linker is run. */
724 if (coff_section_data (abfd
, sec
) == NULL
)
727 ((PTR
) bfd_zalloc (abfd
, sizeof (struct coff_section_tdata
)));
728 if (sec
->used_by_bfd
== NULL
)
732 coff_section_data (abfd
, sec
)->relocs
= internal_relocs
;
733 coff_section_data (abfd
, sec
)->keep_relocs
= true;
736 coff_section_data (abfd
, sec
)->contents
= contents
;
737 coff_section_data (abfd
, sec
)->keep_contents
= true;
738 free_contents
= NULL
;
740 obj_coff_keep_syms (abfd
) = true;
742 /* Replace the jsr with a bsr. */
744 /* Change the R_SH_USES reloc into an R_SH_PCDISP reloc, and
745 replace the jsr with a bsr. */
746 irel
->r_type
= R_SH_PCDISP
;
747 irel
->r_symndx
= irelfn
->r_symndx
;
748 if (sym
.n_sclass
!= C_EXT
)
750 /* If this needs to be changed because of future relaxing,
751 it will be handled here like other internal PCDISP
754 0xb000 | ((foff
>> 1) & 0xfff),
755 contents
+ irel
->r_vaddr
- sec
->vma
);
759 /* We can't fully resolve this yet, because the external
760 symbol value may be changed by future relaxing. We let
761 the final link phase handle it. */
762 bfd_put_16 (abfd
, 0xb000, contents
+ irel
->r_vaddr
- sec
->vma
);
765 /* See if there is another R_SH_USES reloc referring to the same
767 for (irelscan
= internal_relocs
; irelscan
< irelend
; irelscan
++)
768 if (irelscan
->r_type
== R_SH_USES
769 && laddr
== irelscan
->r_vaddr
- sec
->vma
+ 4 + irelscan
->r_offset
)
771 if (irelscan
< irelend
)
773 /* Some other function call depends upon this register load,
774 and we have not yet converted that function call.
775 Indeed, we may never be able to convert it. There is
776 nothing else we can do at this point. */
780 /* Look for a R_SH_COUNT reloc on the location where the
781 function address is stored. Do this before deleting any
782 bytes, to avoid confusion about the address. */
783 for (irelcount
= internal_relocs
; irelcount
< irelend
; irelcount
++)
784 if (irelcount
->r_vaddr
== paddr
785 && irelcount
->r_type
== R_SH_COUNT
)
788 /* Delete the register load. */
789 if (! sh_relax_delete_bytes (abfd
, sec
, laddr
, 2))
792 /* That will change things, so, just in case it permits some
793 other function call to come within range, we should relax
794 again. Note that this is not required, and it may be slow. */
797 /* Now check whether we got a COUNT reloc. */
798 if (irelcount
>= irelend
)
800 ((*_bfd_error_handler
)
801 ("%s: 0x%lx: warning: could not find expected COUNT reloc",
802 bfd_get_filename (abfd
), (unsigned long) paddr
));
806 /* The number of uses is stored in the r_offset field. We've
808 if (irelcount
->r_offset
== 0)
810 ((*_bfd_error_handler
) ("%s: 0x%lx: warning: bad count",
811 bfd_get_filename (abfd
),
812 (unsigned long) paddr
));
816 --irelcount
->r_offset
;
818 /* If there are no more uses, we can delete the address. Reload
819 the address from irelfn, in case it was changed by the
820 previous call to sh_relax_delete_bytes. */
821 if (irelcount
->r_offset
== 0)
823 if (! sh_relax_delete_bytes (abfd
, sec
,
824 irelfn
->r_vaddr
- sec
->vma
, 4))
828 /* We've done all we can with that function call. */
831 /* Look for load and store instructions that we can align on four
837 /* Get the section contents. */
838 if (contents
== NULL
)
840 if (coff_section_data (abfd
, sec
) != NULL
841 && coff_section_data (abfd
, sec
)->contents
!= NULL
)
842 contents
= coff_section_data (abfd
, sec
)->contents
;
845 contents
= (bfd_byte
*) bfd_malloc (sec
->_raw_size
);
846 if (contents
== NULL
)
848 free_contents
= contents
;
850 if (! bfd_get_section_contents (abfd
, sec
, contents
,
851 (file_ptr
) 0, sec
->_raw_size
))
856 if (! sh_align_loads (abfd
, sec
, internal_relocs
, contents
, &swapped
))
861 if (coff_section_data (abfd
, sec
) == NULL
)
864 ((PTR
) bfd_zalloc (abfd
, sizeof (struct coff_section_tdata
)));
865 if (sec
->used_by_bfd
== NULL
)
869 coff_section_data (abfd
, sec
)->relocs
= internal_relocs
;
870 coff_section_data (abfd
, sec
)->keep_relocs
= true;
873 coff_section_data (abfd
, sec
)->contents
= contents
;
874 coff_section_data (abfd
, sec
)->keep_contents
= true;
875 free_contents
= NULL
;
877 obj_coff_keep_syms (abfd
) = true;
881 if (free_relocs
!= NULL
)
887 if (free_contents
!= NULL
)
889 if (! link_info
->keep_memory
)
890 free (free_contents
);
893 /* Cache the section contents for coff_link_input_bfd. */
894 if (coff_section_data (abfd
, sec
) == NULL
)
897 ((PTR
) bfd_zalloc (abfd
, sizeof (struct coff_section_tdata
)));
898 if (sec
->used_by_bfd
== NULL
)
900 coff_section_data (abfd
, sec
)->relocs
= NULL
;
902 coff_section_data (abfd
, sec
)->contents
= contents
;
909 if (free_relocs
!= NULL
)
911 if (free_contents
!= NULL
)
912 free (free_contents
);
916 /* Delete some bytes from a section while relaxing. */
919 sh_relax_delete_bytes (abfd
, sec
, addr
, count
)
926 struct internal_reloc
*irel
, *irelend
;
927 struct internal_reloc
*irelalign
;
929 bfd_byte
*esym
, *esymend
;
930 bfd_size_type symesz
;
931 struct coff_link_hash_entry
**sym_hash
;
934 contents
= coff_section_data (abfd
, sec
)->contents
;
936 /* The deletion must stop at the next ALIGN reloc for an aligment
937 power larger than the number of bytes we are deleting. */
940 toaddr
= sec
->_cooked_size
;
942 irel
= coff_section_data (abfd
, sec
)->relocs
;
943 irelend
= irel
+ sec
->reloc_count
;
944 for (; irel
< irelend
; irel
++)
946 if (irel
->r_type
== R_SH_ALIGN
947 && irel
->r_vaddr
- sec
->vma
> addr
948 && count
< (1 << irel
->r_offset
))
951 toaddr
= irel
->r_vaddr
- sec
->vma
;
956 /* Actually delete the bytes. */
957 memmove (contents
+ addr
, contents
+ addr
+ count
, toaddr
- addr
- count
);
958 if (irelalign
== NULL
)
959 sec
->_cooked_size
-= count
;
964 #define NOP_OPCODE (0x0009)
966 BFD_ASSERT ((count
& 1) == 0);
967 for (i
= 0; i
< count
; i
+= 2)
968 bfd_put_16 (abfd
, NOP_OPCODE
, contents
+ toaddr
- count
+ i
);
971 /* Adjust all the relocs. */
972 for (irel
= coff_section_data (abfd
, sec
)->relocs
; irel
< irelend
; irel
++)
974 bfd_vma nraddr
, stop
;
977 struct internal_syment sym
;
978 int off
, adjust
, oinsn
;
979 bfd_signed_vma voff
= 0;
982 /* Get the new reloc address. */
983 nraddr
= irel
->r_vaddr
- sec
->vma
;
984 if ((irel
->r_vaddr
- sec
->vma
> addr
985 && irel
->r_vaddr
- sec
->vma
< toaddr
)
986 || (irel
->r_type
== R_SH_ALIGN
987 && irel
->r_vaddr
- sec
->vma
== toaddr
))
990 /* See if this reloc was for the bytes we have deleted, in which
991 case we no longer care about it. Don't delete relocs which
992 represent addresses, though. */
993 if (irel
->r_vaddr
- sec
->vma
>= addr
994 && irel
->r_vaddr
- sec
->vma
< addr
+ count
995 && irel
->r_type
!= R_SH_ALIGN
996 && irel
->r_type
!= R_SH_CODE
997 && irel
->r_type
!= R_SH_DATA
998 && irel
->r_type
!= R_SH_LABEL
)
999 irel
->r_type
= R_SH_UNUSED
;
1001 /* If this is a PC relative reloc, see if the range it covers
1002 includes the bytes we have deleted. */
1003 switch (irel
->r_type
)
1008 case R_SH_PCDISP8BY2
:
1010 case R_SH_PCRELIMM8BY2
:
1011 case R_SH_PCRELIMM8BY4
:
1012 start
= irel
->r_vaddr
- sec
->vma
;
1013 insn
= bfd_get_16 (abfd
, contents
+ nraddr
);
1017 switch (irel
->r_type
)
1020 start
= stop
= addr
;
1024 /* If this reloc is against a symbol defined in this
1025 section, and the symbol will not be adjusted below, we
1026 must check the addend to see it will put the value in
1027 range to be adjusted, and hence must be changed. */
1028 bfd_coff_swap_sym_in (abfd
,
1029 ((bfd_byte
*) obj_coff_external_syms (abfd
)
1031 * bfd_coff_symesz (abfd
))),
1033 if (sym
.n_sclass
!= C_EXT
1034 && sym
.n_scnum
== sec
->target_index
1035 && ((bfd_vma
) sym
.n_value
<= addr
1036 || (bfd_vma
) sym
.n_value
>= toaddr
))
1040 val
= bfd_get_32 (abfd
, contents
+ nraddr
);
1042 if (val
> addr
&& val
< toaddr
)
1043 bfd_put_32 (abfd
, val
- count
, contents
+ nraddr
);
1045 start
= stop
= addr
;
1048 case R_SH_PCDISP8BY2
:
1052 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
1056 bfd_coff_swap_sym_in (abfd
,
1057 ((bfd_byte
*) obj_coff_external_syms (abfd
)
1059 * bfd_coff_symesz (abfd
))),
1061 if (sym
.n_sclass
== C_EXT
)
1062 start
= stop
= addr
;
1068 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ 4 + off
* 2);
1072 case R_SH_PCRELIMM8BY2
:
1074 stop
= start
+ 4 + off
* 2;
1077 case R_SH_PCRELIMM8BY4
:
1079 stop
= (start
&~ (bfd_vma
) 3) + 4 + off
* 4;
1085 /* These relocs types represent
1087 The r_offset field holds the difference between the reloc
1088 address and L1. That is the start of the reloc, and
1089 adding in the contents gives us the top. We must adjust
1090 both the r_offset field and the section contents. */
1092 start
= irel
->r_vaddr
- sec
->vma
;
1093 stop
= (bfd_vma
) ((bfd_signed_vma
) start
- (long) irel
->r_offset
);
1097 && (stop
<= addr
|| stop
>= toaddr
))
1098 irel
->r_offset
+= count
;
1099 else if (stop
> addr
1101 && (start
<= addr
|| start
>= toaddr
))
1102 irel
->r_offset
-= count
;
1106 if (irel
->r_type
== R_SH_SWITCH16
)
1107 voff
= bfd_get_signed_16 (abfd
, contents
+ nraddr
);
1108 else if (irel
->r_type
== R_SH_SWITCH8
)
1109 voff
= bfd_get_8 (abfd
, contents
+ nraddr
);
1111 voff
= bfd_get_signed_32 (abfd
, contents
+ nraddr
);
1112 stop
= (bfd_vma
) ((bfd_signed_vma
) start
+ voff
);
1117 start
= irel
->r_vaddr
- sec
->vma
;
1118 stop
= (bfd_vma
) ((bfd_signed_vma
) start
1119 + (long) irel
->r_offset
1126 && (stop
<= addr
|| stop
>= toaddr
))
1128 else if (stop
> addr
1130 && (start
<= addr
|| start
>= toaddr
))
1139 switch (irel
->r_type
)
1145 case R_SH_PCDISP8BY2
:
1146 case R_SH_PCRELIMM8BY2
:
1148 if ((oinsn
& 0xff00) != (insn
& 0xff00))
1150 bfd_put_16 (abfd
, insn
, contents
+ nraddr
);
1155 if ((oinsn
& 0xf000) != (insn
& 0xf000))
1157 bfd_put_16 (abfd
, insn
, contents
+ nraddr
);
1160 case R_SH_PCRELIMM8BY4
:
1161 BFD_ASSERT (adjust
== count
|| count
>= 4);
1166 if ((irel
->r_vaddr
& 3) == 0)
1169 if ((oinsn
& 0xff00) != (insn
& 0xff00))
1171 bfd_put_16 (abfd
, insn
, contents
+ nraddr
);
1176 if (voff
< 0 || voff
>= 0xff)
1178 bfd_put_8 (abfd
, voff
, contents
+ nraddr
);
1183 if (voff
< - 0x8000 || voff
>= 0x8000)
1185 bfd_put_signed_16 (abfd
, voff
, contents
+ nraddr
);
1190 bfd_put_signed_32 (abfd
, voff
, contents
+ nraddr
);
1194 irel
->r_offset
+= adjust
;
1200 ((*_bfd_error_handler
)
1201 ("%s: 0x%lx: fatal: reloc overflow while relaxing",
1202 bfd_get_filename (abfd
), (unsigned long) irel
->r_vaddr
));
1203 bfd_set_error (bfd_error_bad_value
);
1208 irel
->r_vaddr
= nraddr
+ sec
->vma
;
1211 /* Look through all the other sections. If there contain any IMM32
1212 relocs against internal symbols which we are not going to adjust
1213 below, we may need to adjust the addends. */
1214 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
1216 struct internal_reloc
*internal_relocs
;
1217 struct internal_reloc
*irelscan
, *irelscanend
;
1218 bfd_byte
*ocontents
;
1221 || (o
->flags
& SEC_RELOC
) == 0
1222 || o
->reloc_count
== 0)
1225 /* We always cache the relocs. Perhaps, if info->keep_memory is
1226 false, we should free them, if we are permitted to, when we
1227 leave sh_coff_relax_section. */
1228 internal_relocs
= (_bfd_coff_read_internal_relocs
1229 (abfd
, o
, true, (bfd_byte
*) NULL
, false,
1230 (struct internal_reloc
*) NULL
));
1231 if (internal_relocs
== NULL
)
1235 irelscanend
= internal_relocs
+ o
->reloc_count
;
1236 for (irelscan
= internal_relocs
; irelscan
< irelscanend
; irelscan
++)
1238 struct internal_syment sym
;
1240 if (irelscan
->r_type
!= R_SH_IMM32
)
1243 bfd_coff_swap_sym_in (abfd
,
1244 ((bfd_byte
*) obj_coff_external_syms (abfd
)
1245 + (irelscan
->r_symndx
1246 * bfd_coff_symesz (abfd
))),
1248 if (sym
.n_sclass
!= C_EXT
1249 && sym
.n_scnum
== sec
->target_index
1250 && ((bfd_vma
) sym
.n_value
<= addr
1251 || (bfd_vma
) sym
.n_value
>= toaddr
))
1255 if (ocontents
== NULL
)
1257 if (coff_section_data (abfd
, o
)->contents
!= NULL
)
1258 ocontents
= coff_section_data (abfd
, o
)->contents
;
1261 /* We always cache the section contents.
1262 Perhaps, if info->keep_memory is false, we
1263 should free them, if we are permitted to,
1264 when we leave sh_coff_relax_section. */
1265 ocontents
= (bfd_byte
*) bfd_malloc (o
->_raw_size
);
1266 if (ocontents
== NULL
)
1268 if (! bfd_get_section_contents (abfd
, o
, ocontents
,
1272 coff_section_data (abfd
, o
)->contents
= ocontents
;
1276 val
= bfd_get_32 (abfd
, ocontents
+ irelscan
->r_vaddr
- o
->vma
);
1278 if (val
> addr
&& val
< toaddr
)
1279 bfd_put_32 (abfd
, val
- count
,
1280 ocontents
+ irelscan
->r_vaddr
- o
->vma
);
1282 coff_section_data (abfd
, o
)->keep_contents
= true;
1287 /* Adjusting the internal symbols will not work if something has
1288 already retrieved the generic symbols. It would be possible to
1289 make this work by adjusting the generic symbols at the same time.
1290 However, this case should not arise in normal usage. */
1291 if (obj_symbols (abfd
) != NULL
1292 || obj_raw_syments (abfd
) != NULL
)
1294 ((*_bfd_error_handler
)
1295 ("%s: fatal: generic symbols retrieved before relaxing",
1296 bfd_get_filename (abfd
)));
1297 bfd_set_error (bfd_error_invalid_operation
);
1301 /* Adjust all the symbols. */
1302 sym_hash
= obj_coff_sym_hashes (abfd
);
1303 symesz
= bfd_coff_symesz (abfd
);
1304 esym
= (bfd_byte
*) obj_coff_external_syms (abfd
);
1305 esymend
= esym
+ obj_raw_syment_count (abfd
) * symesz
;
1306 while (esym
< esymend
)
1308 struct internal_syment isym
;
1310 bfd_coff_swap_sym_in (abfd
, (PTR
) esym
, (PTR
) &isym
);
1312 if (isym
.n_scnum
== sec
->target_index
1313 && (bfd_vma
) isym
.n_value
> addr
1314 && (bfd_vma
) isym
.n_value
< toaddr
)
1316 isym
.n_value
-= count
;
1318 bfd_coff_swap_sym_out (abfd
, (PTR
) &isym
, (PTR
) esym
);
1320 if (*sym_hash
!= NULL
)
1322 BFD_ASSERT ((*sym_hash
)->root
.type
== bfd_link_hash_defined
1323 || (*sym_hash
)->root
.type
== bfd_link_hash_defweak
);
1324 BFD_ASSERT ((*sym_hash
)->root
.u
.def
.value
>= addr
1325 && (*sym_hash
)->root
.u
.def
.value
< toaddr
);
1326 (*sym_hash
)->root
.u
.def
.value
-= count
;
1330 esym
+= (isym
.n_numaux
+ 1) * symesz
;
1331 sym_hash
+= isym
.n_numaux
+ 1;
1334 /* See if we can move the ALIGN reloc forward. We have adjusted
1335 r_vaddr for it already. */
1336 if (irelalign
!= NULL
)
1338 bfd_vma alignto
, alignaddr
;
1340 alignto
= BFD_ALIGN (toaddr
, 1 << irelalign
->r_offset
);
1341 alignaddr
= BFD_ALIGN (irelalign
->r_vaddr
- sec
->vma
,
1342 1 << irelalign
->r_offset
);
1343 if (alignto
!= alignaddr
)
1345 /* Tail recursion. */
1346 return sh_relax_delete_bytes (abfd
, sec
, alignaddr
,
1347 alignto
- alignaddr
);
1354 /* This is yet another version of the SH opcode table, used to rapidly
1355 get information about a particular instruction. */
1357 /* The opcode map is represented by an array of these structures. The
1358 array is indexed by the high order four bits in the instruction. */
1360 struct sh_major_opcode
1362 /* A pointer to the instruction list. This is an array which
1363 contains all the instructions with this major opcode. */
1364 const struct sh_minor_opcode
*minor_opcodes
;
1365 /* The number of elements in minor_opcodes. */
1366 unsigned short count
;
1369 /* This structure holds information for a set of SH opcodes. The
1370 instruction code is anded with the mask value, and the resulting
1371 value is used to search the order opcode list. */
1373 struct sh_minor_opcode
1375 /* The sorted opcode list. */
1376 const struct sh_opcode
*opcodes
;
1377 /* The number of elements in opcodes. */
1378 unsigned short count
;
1379 /* The mask value to use when searching the opcode list. */
1380 unsigned short mask
;
1383 /* This structure holds information for an SH instruction. An array
1384 of these structures is sorted in order by opcode. */
1388 /* The code for this instruction, after it has been anded with the
1389 mask value in the sh_major_opcode structure. */
1390 unsigned short opcode
;
1391 /* Flags for this instruction. */
1392 unsigned short flags
;
1395 /* Flag which appear in the sh_opcode structure. */
1397 /* This instruction loads a value from memory. */
1400 /* This instruction stores a value to memory. */
1403 /* This instruction is a branch. */
1404 #define BRANCH (0x4)
1406 /* This instruction has a delay slot. */
1409 /* This instruction uses the value in the register in the field at
1410 mask 0x0f00 of the instruction. */
1411 #define USES1 (0x10)
1413 /* This instruction uses the value in the register in the field at
1414 mask 0x00f0 of the instruction. */
1415 #define USES2 (0x20)
1417 /* This instruction uses the value in register 0. */
1418 #define USESR0 (0x40)
1420 /* This instruction sets the value in the register in the field at
1421 mask 0x0f00 of the instruction. */
1422 #define SETS1 (0x80)
1424 /* This instruction sets the value in the register in the field at
1425 mask 0x00f0 of the instruction. */
1426 #define SETS2 (0x100)
1428 /* This instruction sets register 0. */
1429 #define SETSR0 (0x200)
1431 /* This instruction sets a special register. */
1432 #define SETSSP (0x400)
1434 /* This instruction uses a special register. */
1435 #define USESSP (0x800)
1437 /* This instruction uses the floating point register in the field at
1438 mask 0x0f00 of the instruction. */
1439 #define USESF1 (0x1000)
1441 /* This instruction uses the floating point register in the field at
1442 mask 0x00f0 of the instruction. */
1443 #define USESF2 (0x2000)
1445 /* This instruction uses floating point register 0. */
1446 #define USESF0 (0x4000)
1448 /* This instruction sets the floating point register in the field at
1449 mask 0x0f00 of the instruction. */
1450 #define SETSF1 (0x8000)
1452 static boolean sh_insn_uses_reg
1453 PARAMS ((unsigned int, const struct sh_opcode
*, unsigned int));
1454 static boolean sh_insn_uses_freg
1455 PARAMS ((unsigned int, const struct sh_opcode
*, unsigned int));
1456 static boolean sh_insns_conflict
1457 PARAMS ((unsigned int, const struct sh_opcode
*, unsigned int,
1458 const struct sh_opcode
*));
1459 static boolean sh_load_use
1460 PARAMS ((unsigned int, const struct sh_opcode
*, unsigned int,
1461 const struct sh_opcode
*));
1463 /* The opcode maps. */
1465 #define MAP(a) a, sizeof a / sizeof a[0]
1467 static const struct sh_opcode sh_opcode00
[] =
1469 { 0x0008, SETSSP
}, /* clrt */
1470 { 0x0009, 0 }, /* nop */
1471 { 0x000b, BRANCH
| DELAY
| USESSP
}, /* rts */
1472 { 0x0018, SETSSP
}, /* sett */
1473 { 0x0019, SETSSP
}, /* div0u */
1474 { 0x001b, 0 }, /* sleep */
1475 { 0x0028, SETSSP
}, /* clrmac */
1476 { 0x002b, BRANCH
| DELAY
| SETSSP
}, /* rte */
1477 { 0x0038, USESSP
| SETSSP
}, /* ldtlb */
1478 { 0x0048, SETSSP
}, /* clrs */
1479 { 0x0058, SETSSP
} /* sets */
1482 static const struct sh_opcode sh_opcode01
[] =
1484 { 0x0002, SETS1
| USESSP
}, /* stc sr,rn */
1485 { 0x0003, BRANCH
| DELAY
| USES1
| SETSSP
}, /* bsrf rn */
1486 { 0x000a, SETS1
| USESSP
}, /* sts mach,rn */
1487 { 0x0012, SETS1
| USESSP
}, /* stc gbr,rn */
1488 { 0x001a, SETS1
| USESSP
}, /* sts macl,rn */
1489 { 0x0022, SETS1
| USESSP
}, /* stc vbr,rn */
1490 { 0x0023, BRANCH
| DELAY
| USES1
}, /* braf rn */
1491 { 0x0029, SETS1
| USESSP
}, /* movt rn */
1492 { 0x002a, SETS1
| USESSP
}, /* sts pr,rn */
1493 { 0x0032, SETS1
| USESSP
}, /* stc ssr,rn */
1494 { 0x0042, SETS1
| USESSP
}, /* stc spc,rn */
1495 { 0x005a, SETS1
| USESSP
}, /* sts fpul,rn */
1496 { 0x006a, SETS1
| USESSP
}, /* sts fpscr,rn */
1497 { 0x0082, SETS1
| USESSP
}, /* stc r0_bank,rn */
1498 { 0x0083, LOAD
| USES1
}, /* pref @rn */
1499 { 0x0092, SETS1
| USESSP
}, /* stc r1_bank,rn */
1500 { 0x00a2, SETS1
| USESSP
}, /* stc r2_bank,rn */
1501 { 0x00b2, SETS1
| USESSP
}, /* stc r3_bank,rn */
1502 { 0x00c2, SETS1
| USESSP
}, /* stc r4_bank,rn */
1503 { 0x00d2, SETS1
| USESSP
}, /* stc r5_bank,rn */
1504 { 0x00e2, SETS1
| USESSP
}, /* stc r6_bank,rn */
1505 { 0x00f2, SETS1
| USESSP
} /* stc r7_bank,rn */
1508 static const struct sh_opcode sh_opcode02
[] =
1510 { 0x0004, STORE
| USES1
| USES2
| USESR0
}, /* mov.b rm,@(r0,rn) */
1511 { 0x0005, STORE
| USES1
| USES2
| USESR0
}, /* mov.w rm,@(r0,rn) */
1512 { 0x0006, STORE
| USES1
| USES2
| USESR0
}, /* mov.l rm,@(r0,rn) */
1513 { 0x0007, SETSSP
| USES1
| USES2
}, /* mul.l rm,rn */
1514 { 0x000c, LOAD
| SETS1
| USES2
| USESR0
}, /* mov.b @(r0,rm),rn */
1515 { 0x000d, LOAD
| SETS1
| USES2
| USESR0
}, /* mov.w @(r0,rm),rn */
1516 { 0x000e, LOAD
| SETS1
| USES2
| USESR0
}, /* mov.l @(r0,rm),rn */
1517 { 0x000f, LOAD
|SETS1
|SETS2
|SETSSP
|USES1
|USES2
|USESSP
}, /* mac.l @rm+,@rn+ */
1520 static const struct sh_minor_opcode sh_opcode0
[] =
1522 { MAP (sh_opcode00
), 0xffff },
1523 { MAP (sh_opcode01
), 0xf0ff },
1524 { MAP (sh_opcode02
), 0xf00f }
1527 static const struct sh_opcode sh_opcode10
[] =
1529 { 0x1000, STORE
| USES1
| USES2
} /* mov.l rm,@(disp,rn) */
1532 static const struct sh_minor_opcode sh_opcode1
[] =
1534 { MAP (sh_opcode10
), 0xf000 }
1537 static const struct sh_opcode sh_opcode20
[] =
1539 { 0x2000, STORE
| USES1
| USES2
}, /* mov.b rm,@rn */
1540 { 0x2001, STORE
| USES1
| USES2
}, /* mov.w rm,@rn */
1541 { 0x2002, STORE
| USES1
| USES2
}, /* mov.l rm,@rn */
1542 { 0x2004, STORE
| SETS1
| USES1
| USES2
}, /* mov.b rm,@-rn */
1543 { 0x2005, STORE
| SETS1
| USES1
| USES2
}, /* mov.w rm,@-rn */
1544 { 0x2006, STORE
| SETS1
| USES1
| USES2
}, /* mov.l rm,@-rn */
1545 { 0x2007, SETSSP
| USES1
| USES2
| USESSP
}, /* div0s */
1546 { 0x2008, SETSSP
| USES1
| USES2
}, /* tst rm,rn */
1547 { 0x2009, SETS1
| USES1
| USES2
}, /* and rm,rn */
1548 { 0x200a, SETS1
| USES1
| USES2
}, /* xor rm,rn */
1549 { 0x200b, SETS1
| USES1
| USES2
}, /* or rm,rn */
1550 { 0x200c, SETSSP
| USES1
| USES2
}, /* cmp/str rm,rn */
1551 { 0x200d, SETS1
| USES1
| USES2
}, /* xtrct rm,rn */
1552 { 0x200e, SETSSP
| USES1
| USES2
}, /* mulu.w rm,rn */
1553 { 0x200f, SETSSP
| USES1
| USES2
} /* muls.w rm,rn */
1556 static const struct sh_minor_opcode sh_opcode2
[] =
1558 { MAP (sh_opcode20
), 0xf00f }
1561 static const struct sh_opcode sh_opcode30
[] =
1563 { 0x3000, SETSSP
| USES1
| USES2
}, /* cmp/eq rm,rn */
1564 { 0x3002, SETSSP
| USES1
| USES2
}, /* cmp/hs rm,rn */
1565 { 0x3003, SETSSP
| USES1
| USES2
}, /* cmp/ge rm,rn */
1566 { 0x3004, SETSSP
| USESSP
| USES1
| USES2
}, /* div1 rm,rn */
1567 { 0x3005, SETSSP
| USES1
| USES2
}, /* dmulu.l rm,rn */
1568 { 0x3006, SETSSP
| USES1
| USES2
}, /* cmp/hi rm,rn */
1569 { 0x3007, SETSSP
| USES1
| USES2
}, /* cmp/gt rm,rn */
1570 { 0x3008, SETS1
| USES1
| USES2
}, /* sub rm,rn */
1571 { 0x300a, SETS1
| SETSSP
| USES1
| USES2
| USESSP
}, /* subc rm,rn */
1572 { 0x300b, SETS1
| SETSSP
| USES1
| USES2
}, /* subv rm,rn */
1573 { 0x300c, SETS1
| USES1
| USES2
}, /* add rm,rn */
1574 { 0x300d, SETSSP
| USES1
| USES2
}, /* dmuls.l rm,rn */
1575 { 0x300e, SETS1
| SETSSP
| USES1
| USES2
| USESSP
}, /* addc rm,rn */
1576 { 0x300f, SETS1
| SETSSP
| USES1
| USES2
} /* addv rm,rn */
1579 static const struct sh_minor_opcode sh_opcode3
[] =
1581 { MAP (sh_opcode30
), 0xf00f }
1584 static const struct sh_opcode sh_opcode40
[] =
1586 { 0x4000, SETS1
| SETSSP
| USES1
}, /* shll rn */
1587 { 0x4001, SETS1
| SETSSP
| USES1
}, /* shlr rn */
1588 { 0x4002, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l mach,@-rn */
1589 { 0x4003, STORE
| SETS1
| USES1
| USESSP
}, /* stc.l sr,@-rn */
1590 { 0x4004, SETS1
| SETSSP
| USES1
}, /* rotl rn */
1591 { 0x4005, SETS1
| SETSSP
| USES1
}, /* rotr rn */
1592 { 0x4006, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,mach */
1593 { 0x4007, LOAD
| SETS1
| SETSSP
| USES1
}, /* ldc.l @rm+,sr */
1594 { 0x4008, SETS1
| USES1
}, /* shll2 rn */
1595 { 0x4009, SETS1
| USES1
}, /* shlr2 rn */
1596 { 0x400a, SETSSP
| USES1
}, /* lds rm,mach */
1597 { 0x400b, BRANCH
| DELAY
| USES1
}, /* jsr @rn */
1598 { 0x400e, SETSSP
| USES1
}, /* ldc rm,sr */
1599 { 0x4010, SETS1
| SETSSP
| USES1
}, /* dt rn */
1600 { 0x4011, SETSSP
| USES1
}, /* cmp/pz rn */
1601 { 0x4012, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l macl,@-rn */
1602 { 0x4013, STORE
| SETS1
| USES1
| USESSP
}, /* stc.l gbr,@-rn */
1603 { 0x4015, SETSSP
| USES1
}, /* cmp/pl rn */
1604 { 0x4016, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,macl */
1605 { 0x4017, LOAD
| SETS1
| SETSSP
| USES1
}, /* ldc.l @rm+,gbr */
1606 { 0x4018, SETS1
| USES1
}, /* shll8 rn */
1607 { 0x4019, SETS1
| USES1
}, /* shlr8 rn */
1608 { 0x401a, SETSSP
| USES1
}, /* lds rm,macl */
1609 { 0x401b, LOAD
| SETSSP
| USES1
}, /* tas.b @rn */
1610 { 0x401e, SETSSP
| USES1
}, /* ldc rm,gbr */
1611 { 0x4020, SETS1
| SETSSP
| USES1
}, /* shal rn */
1612 { 0x4021, SETS1
| SETSSP
| USES1
}, /* shar rn */
1613 { 0x4022, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l pr,@-rn */
1614 { 0x4023, STORE
| SETS1
| USES1
| USESSP
}, /* stc.l vbr,@-rn */
1615 { 0x4024, SETS1
| SETSSP
| USES1
| USESSP
}, /* rotcl rn */
1616 { 0x4025, SETS1
| SETSSP
| USES1
| USESSP
}, /* rotcr rn */
1617 { 0x4026, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,pr */
1618 { 0x4027, LOAD
| SETS1
| SETSSP
| USES1
}, /* ldc.l @rm+,vbr */
1619 { 0x4028, SETS1
| USES1
}, /* shll16 rn */
1620 { 0x4029, SETS1
| USES1
}, /* shlr16 rn */
1621 { 0x402a, SETSSP
| USES1
}, /* lds rm,pr */
1622 { 0x402b, BRANCH
| DELAY
| USES1
}, /* jmp @rn */
1623 { 0x402e, SETSSP
| USES1
}, /* ldc rm,vbr */
1624 { 0x4033, STORE
| SETS1
| USES1
| USESSP
}, /* stc.l ssr,@-rn */
1625 { 0x4037, LOAD
| SETS1
| SETSSP
| USES1
}, /* ldc.l @rm+,ssr */
1626 { 0x403e, SETSSP
| USES1
}, /* ldc rm,ssr */
1627 { 0x4043, STORE
| SETS1
| USES1
| USESSP
}, /* stc.l spc,@-rn */
1628 { 0x4047, LOAD
| SETS1
| SETSSP
| USES1
}, /* ldc.l @rm+,spc */
1629 { 0x404e, SETSSP
| USES1
}, /* ldc rm,spc */
1630 { 0x4052, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l fpul,@-rn */
1631 { 0x4056, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,fpul */
1632 { 0x405a, SETSSP
| USES1
}, /* lds.l rm,fpul */
1633 { 0x4062, STORE
| SETS1
| USES1
| USESSP
}, /* sts.l fpscr,@-rn */
1634 { 0x4066, LOAD
| SETS1
| SETSSP
| USES1
}, /* lds.l @rm+,fpscr */
1635 { 0x406a, SETSSP
| USES1
} /* lds rm,fpscr */
1638 static const struct sh_opcode sh_opcode41
[] =
1640 { 0x4083, STORE
| SETS1
| USES1
| USESSP
}, /* stc.l rx_bank,@-rn */
1641 { 0x4087, LOAD
| SETS1
| SETSSP
| USES1
}, /* ldc.l @rm+,rx_bank */
1642 { 0x408e, SETSSP
| USES1
} /* ldc rm,rx_bank */
1645 static const struct sh_opcode sh_opcode42
[] =
1647 { 0x400c, SETS1
| USES1
| USES2
}, /* shad rm,rn */
1648 { 0x400d, SETS1
| USES1
| USES2
}, /* shld rm,rn */
1649 { 0x400f, LOAD
|SETS1
|SETS2
|SETSSP
|USES1
|USES2
|USESSP
}, /* mac.w @rm+,@rn+ */
1652 static const struct sh_minor_opcode sh_opcode4
[] =
1654 { MAP (sh_opcode40
), 0xf0ff },
1655 { MAP (sh_opcode41
), 0xf08f },
1656 { MAP (sh_opcode42
), 0xf00f }
1659 static const struct sh_opcode sh_opcode50
[] =
1661 { 0x5000, LOAD
| SETS1
| USES2
} /* mov.l @(disp,rm),rn */
1664 static const struct sh_minor_opcode sh_opcode5
[] =
1666 { MAP (sh_opcode50
), 0xf000 }
1669 static const struct sh_opcode sh_opcode60
[] =
1671 { 0x6000, LOAD
| SETS1
| USES2
}, /* mov.b @rm,rn */
1672 { 0x6001, LOAD
| SETS1
| USES2
}, /* mov.w @rm,rn */
1673 { 0x6002, LOAD
| SETS1
| USES2
}, /* mov.l @rm,rn */
1674 { 0x6003, SETS1
| USES2
}, /* mov rm,rn */
1675 { 0x6004, LOAD
| SETS1
| SETS2
| USES2
}, /* mov.b @rm+,rn */
1676 { 0x6005, LOAD
| SETS1
| SETS2
| USES2
}, /* mov.w @rm+,rn */
1677 { 0x6006, LOAD
| SETS1
| SETS2
| USES2
}, /* mov.l @rm+,rn */
1678 { 0x6007, SETS1
| USES2
}, /* not rm,rn */
1679 { 0x6008, SETS1
| USES2
}, /* swap.b rm,rn */
1680 { 0x6009, SETS1
| USES2
}, /* swap.w rm,rn */
1681 { 0x600a, SETS1
| SETSSP
| USES2
| USESSP
}, /* negc rm,rn */
1682 { 0x600b, SETS1
| USES2
}, /* neg rm,rn */
1683 { 0x600c, SETS1
| USES2
}, /* extu.b rm,rn */
1684 { 0x600d, SETS1
| USES2
}, /* extu.w rm,rn */
1685 { 0x600e, SETS1
| USES2
}, /* exts.b rm,rn */
1686 { 0x600f, SETS1
| USES2
} /* exts.w rm,rn */
1689 static const struct sh_minor_opcode sh_opcode6
[] =
1691 { MAP (sh_opcode60
), 0xf00f }
1694 static const struct sh_opcode sh_opcode70
[] =
1696 { 0x7000, SETS1
| USES1
} /* add #imm,rn */
1699 static const struct sh_minor_opcode sh_opcode7
[] =
1701 { MAP (sh_opcode70
), 0xf000 }
1704 static const struct sh_opcode sh_opcode80
[] =
1706 { 0x8000, STORE
| USES2
| USESR0
}, /* mov.b r0,@(disp,rn) */
1707 { 0x8100, STORE
| USES2
| USESR0
}, /* mov.w r0,@(disp,rn) */
1708 { 0x8400, LOAD
| SETSR0
| USES2
}, /* mov.b @(disp,rm),r0 */
1709 { 0x8500, LOAD
| SETSR0
| USES2
}, /* mov.w @(disp,rn),r0 */
1710 { 0x8800, SETSSP
| USESR0
}, /* cmp/eq #imm,r0 */
1711 { 0x8900, BRANCH
| USESSP
}, /* bt label */
1712 { 0x8b00, BRANCH
| USESSP
}, /* bf label */
1713 { 0x8d00, BRANCH
| DELAY
| USESSP
}, /* bt/s label */
1714 { 0x8f00, BRANCH
| DELAY
| USESSP
} /* bf/s label */
1717 static const struct sh_minor_opcode sh_opcode8
[] =
1719 { MAP (sh_opcode80
), 0xff00 }
1722 static const struct sh_opcode sh_opcode90
[] =
1724 { 0x9000, LOAD
| SETS1
} /* mov.w @(disp,pc),rn */
1727 static const struct sh_minor_opcode sh_opcode9
[] =
1729 { MAP (sh_opcode90
), 0xf000 }
1732 static const struct sh_opcode sh_opcodea0
[] =
1734 { 0xa000, BRANCH
| DELAY
} /* bra label */
1737 static const struct sh_minor_opcode sh_opcodea
[] =
1739 { MAP (sh_opcodea0
), 0xf000 }
1742 static const struct sh_opcode sh_opcodeb0
[] =
1744 { 0xb000, BRANCH
| DELAY
} /* bsr label */
1747 static const struct sh_minor_opcode sh_opcodeb
[] =
1749 { MAP (sh_opcodeb0
), 0xf000 }
1752 static const struct sh_opcode sh_opcodec0
[] =
1754 { 0xc000, STORE
| USESR0
| USESSP
}, /* mov.b r0,@(disp,gbr) */
1755 { 0xc100, STORE
| USESR0
| USESSP
}, /* mov.w r0,@(disp,gbr) */
1756 { 0xc200, STORE
| USESR0
| USESSP
}, /* mov.l r0,@(disp,gbr) */
1757 { 0xc300, BRANCH
| USESSP
}, /* trapa #imm */
1758 { 0xc400, LOAD
| SETSR0
| USESSP
}, /* mov.b @(disp,gbr),r0 */
1759 { 0xc500, LOAD
| SETSR0
| USESSP
}, /* mov.w @(disp,gbr),r0 */
1760 { 0xc600, LOAD
| SETSR0
| USESSP
}, /* mov.l @(disp,gbr),r0 */
1761 { 0xc700, SETSR0
}, /* mova @(disp,pc),r0 */
1762 { 0xc800, SETSSP
| USESR0
}, /* tst #imm,r0 */
1763 { 0xc900, SETSR0
| USESR0
}, /* and #imm,r0 */
1764 { 0xca00, SETSR0
| USESR0
}, /* xor #imm,r0 */
1765 { 0xcb00, SETSR0
| USESR0
}, /* or #imm,r0 */
1766 { 0xcc00, LOAD
| SETSSP
| USESR0
| USESSP
}, /* tst.b #imm,@(r0,gbr) */
1767 { 0xcd00, LOAD
| STORE
| USESR0
| USESSP
}, /* and.b #imm,@(r0,gbr) */
1768 { 0xce00, LOAD
| STORE
| USESR0
| USESSP
}, /* xor.b #imm,@(r0,gbr) */
1769 { 0xcf00, LOAD
| STORE
| USESR0
| USESSP
} /* or.b #imm,@(r0,gbr) */
1772 static const struct sh_minor_opcode sh_opcodec
[] =
1774 { MAP (sh_opcodec0
), 0xff00 }
1777 static const struct sh_opcode sh_opcoded0
[] =
1779 { 0xd000, LOAD
| SETS1
} /* mov.l @(disp,pc),rn */
1782 static const struct sh_minor_opcode sh_opcoded
[] =
1784 { MAP (sh_opcoded0
), 0xf000 }
1787 static const struct sh_opcode sh_opcodee0
[] =
1789 { 0xe000, SETS1
} /* mov #imm,rn */
1792 static const struct sh_minor_opcode sh_opcodee
[] =
1794 { MAP (sh_opcodee0
), 0xf000 }
1797 static const struct sh_opcode sh_opcodef0
[] =
1799 { 0xf000, SETSF1
| USESF1
| USESF2
}, /* fadd fm,fn */
1800 { 0xf001, SETSF1
| USESF1
| USESF2
}, /* fsub fm,fn */
1801 { 0xf002, SETSF1
| USESF1
| USESF2
}, /* fmul fm,fn */
1802 { 0xf003, SETSF1
| USESF1
| USESF2
}, /* fdiv fm,fn */
1803 { 0xf004, SETSSP
| USESF1
| USESF2
}, /* fcmp/eq fm,fn */
1804 { 0xf005, SETSSP
| USESF1
| USESF2
}, /* fcmp/gt fm,fn */
1805 { 0xf006, LOAD
| SETSF1
| USES2
| USESR0
}, /* fmov.s @(r0,rm),fn */
1806 { 0xf007, STORE
| USES1
| USESF2
| USESR0
}, /* fmov.s fm,@(r0,rn) */
1807 { 0xf008, LOAD
| SETSF1
| USES2
}, /* fmov.s @rm,fn */
1808 { 0xf009, LOAD
| SETS2
| SETSF1
| USES2
}, /* fmov.s @rm+,fn */
1809 { 0xf00a, STORE
| USES1
| USESF2
}, /* fmov.s fm,@rn */
1810 { 0xf00b, STORE
| SETS1
| USES1
| USESF2
}, /* fmov.s fm,@-rn */
1811 { 0xf00c, SETSF1
| USESF2
}, /* fmov fm,fn */
1812 { 0xf00e, SETSF1
| USESF1
| USESF2
| USESF0
} /* fmac f0,fm,fn */
1815 static const struct sh_opcode sh_opcodef1
[] =
1817 { 0xf00d, SETSF1
| USESSP
}, /* fsts fpul,fn */
1818 { 0xf01d, SETSSP
| USESF1
}, /* flds fn,fpul */
1819 { 0xf02d, SETSF1
| USESSP
}, /* float fpul,fn */
1820 { 0xf03d, SETSSP
| USESF1
}, /* ftrc fn,fpul */
1821 { 0xf04d, SETSF1
| USESF1
}, /* fneg fn */
1822 { 0xf05d, SETSF1
| USESF1
}, /* fabs fn */
1823 { 0xf06d, SETSF1
| USESF1
}, /* fsqrt fn */
1824 { 0xf07d, SETSSP
| USESF1
}, /* ftst/nan fn */
1825 { 0xf08d, SETSF1
}, /* fldi0 fn */
1826 { 0xf09d, SETSF1
} /* fldi1 fn */
1829 static const struct sh_minor_opcode sh_opcodef
[] =
1831 { MAP (sh_opcodef0
), 0xf00f },
1832 { MAP (sh_opcodef1
), 0xf0ff }
1835 static const struct sh_major_opcode sh_opcodes
[] =
1837 { MAP (sh_opcode0
) },
1838 { MAP (sh_opcode1
) },
1839 { MAP (sh_opcode2
) },
1840 { MAP (sh_opcode3
) },
1841 { MAP (sh_opcode4
) },
1842 { MAP (sh_opcode5
) },
1843 { MAP (sh_opcode6
) },
1844 { MAP (sh_opcode7
) },
1845 { MAP (sh_opcode8
) },
1846 { MAP (sh_opcode9
) },
1847 { MAP (sh_opcodea
) },
1848 { MAP (sh_opcodeb
) },
1849 { MAP (sh_opcodec
) },
1850 { MAP (sh_opcoded
) },
1851 { MAP (sh_opcodee
) },
1852 { MAP (sh_opcodef
) }
1855 /* Given an instruction, return a pointer to the corresponding
1856 sh_opcode structure. Return NULL if the instruction is not
1859 static const struct sh_opcode
*
1863 const struct sh_major_opcode
*maj
;
1864 const struct sh_minor_opcode
*min
, *minend
;
1866 maj
= &sh_opcodes
[(insn
& 0xf000) >> 12];
1867 min
= maj
->minor_opcodes
;
1868 minend
= min
+ maj
->count
;
1869 for (; min
< minend
; min
++)
1872 const struct sh_opcode
*op
, *opend
;
1874 l
= insn
& min
->mask
;
1876 opend
= op
+ min
->count
;
1878 /* Since the opcodes tables are sorted, we could use a binary
1879 search here if the count were above some cutoff value. */
1880 for (; op
< opend
; op
++)
1881 if (op
->opcode
== l
)
1888 /* See whether an instruction uses a general purpose register. */
1891 sh_insn_uses_reg (insn
, op
, reg
)
1893 const struct sh_opcode
*op
;
1900 if ((f
& USES1
) != 0
1901 && ((insn
& 0x0f00) >> 8) == reg
)
1903 if ((f
& USES2
) != 0
1904 && ((insn
& 0x00f0) >> 4) == reg
)
1906 if ((f
& USESR0
) != 0
1913 /* See whether an instruction uses a floating point register. */
1916 sh_insn_uses_freg (insn
, op
, freg
)
1918 const struct sh_opcode
*op
;
1925 /* We can't tell if this is a double-precision insn, so just play safe
1926 and assume that it might be. So not only have we test FREG against
1927 itself, but also even FREG against FREG+1 - if the using insn uses
1928 just the low part of a double precision value - but also an odd
1929 FREG against FREG-1 - if the setting insn sets just the low part
1930 of a double precision value.
1931 So what this all boils down to is that we have to ignore the lowest
1932 bit of the register number. */
1934 if ((f
& USESF1
) != 0
1935 && ((insn
& 0x0e00) >> 8) == (freg
& 0xe))
1937 if ((f
& USESF2
) != 0
1938 && ((insn
& 0x00e0) >> 4) == (freg
& 0xe))
1940 if ((f
& USESF0
) != 0
1947 /* See whether instructions I1 and I2 conflict, assuming I1 comes
1948 before I2. OP1 and OP2 are the corresponding sh_opcode structures.
1949 This should return true if there is a conflict, or false if the
1950 instructions can be swapped safely. */
1953 sh_insns_conflict (i1
, op1
, i2
, op2
)
1955 const struct sh_opcode
*op1
;
1957 const struct sh_opcode
*op2
;
1959 unsigned int f1
, f2
;
1964 /* Load of fpscr conflicts with floating point operations.
1965 FIXME: shouldn't test raw opcodes here. */
1966 if (((i1
& 0xf0ff) == 0x4066 && (i2
& 0xf000) == 0xf000)
1967 || ((i2
& 0xf0ff) == 0x4066 && (i1
& 0xf000) == 0xf000))
1970 if ((f1
& (BRANCH
| DELAY
)) != 0
1971 || (f2
& (BRANCH
| DELAY
)) != 0)
1974 if ((f1
& SETSSP
) != 0 && (f2
& USESSP
) != 0)
1976 if ((f2
& SETSSP
) != 0 && (f1
& USESSP
) != 0)
1979 if ((f1
& SETS1
) != 0
1980 && sh_insn_uses_reg (i2
, op2
, (i1
& 0x0f00) >> 8))
1982 if ((f1
& SETS2
) != 0
1983 && sh_insn_uses_reg (i2
, op2
, (i1
& 0x00f0) >> 4))
1985 if ((f1
& SETSR0
) != 0
1986 && sh_insn_uses_reg (i2
, op2
, 0))
1988 if ((f1
& SETSF1
) != 0
1989 && sh_insn_uses_freg (i2
, op2
, (i1
& 0x0f00) >> 8))
1992 if ((f2
& SETS1
) != 0
1993 && sh_insn_uses_reg (i1
, op1
, (i2
& 0x0f00) >> 8))
1995 if ((f2
& SETS2
) != 0
1996 && sh_insn_uses_reg (i1
, op1
, (i2
& 0x00f0) >> 4))
1998 if ((f2
& SETSR0
) != 0
1999 && sh_insn_uses_reg (i1
, op1
, 0))
2001 if ((f2
& SETSF1
) != 0
2002 && sh_insn_uses_freg (i1
, op1
, (i2
& 0x0f00) >> 8))
2005 /* The instructions do not conflict. */
2009 /* I1 is a load instruction, and I2 is some other instruction. Return
2010 true if I1 loads a register which I2 uses. */
2013 sh_load_use (i1
, op1
, i2
, op2
)
2015 const struct sh_opcode
*op1
;
2017 const struct sh_opcode
*op2
;
2023 if ((f1
& LOAD
) == 0)
2026 /* If both SETS1 and SETSSP are set, that means a load to a special
2027 register using postincrement addressing mode, which we don't care
2029 if ((f1
& SETS1
) != 0
2030 && (f1
& SETSSP
) == 0
2031 && sh_insn_uses_reg (i2
, op2
, (i1
& 0x0f00) >> 8))
2034 if ((f1
& SETSR0
) != 0
2035 && sh_insn_uses_reg (i2
, op2
, 0))
2038 if ((f1
& SETSF1
) != 0
2039 && sh_insn_uses_freg (i2
, op2
, (i1
& 0x0f00) >> 8))
2045 /* Try to align loads and stores within a span of memory. This is
2046 called by both the ELF and the COFF sh targets. ABFD and SEC are
2047 the BFD and section we are examining. CONTENTS is the contents of
2048 the section. SWAP is the routine to call to swap two instructions.
2049 RELOCS is a pointer to the internal relocation information, to be
2050 passed to SWAP. PLABEL is a pointer to the current label in a
2051 sorted list of labels; LABEL_END is the end of the list. START and
2052 STOP are the range of memory to examine. If a swap is made,
2053 *PSWAPPED is set to true. */
2056 _bfd_sh_align_load_span (abfd
, sec
, contents
, swap
, relocs
,
2057 plabel
, label_end
, start
, stop
, pswapped
)
2061 boolean (*swap
) PARAMS ((bfd
*, asection
*, PTR
, bfd_byte
*, bfd_vma
));
2071 /* Instructions should be aligned on 2 byte boundaries. */
2072 if ((start
& 1) == 1)
2075 /* Now look through the unaligned addresses. */
2079 for (; i
< stop
; i
+= 4)
2082 const struct sh_opcode
*op
;
2083 unsigned int prev_insn
= 0;
2084 const struct sh_opcode
*prev_op
= NULL
;
2086 insn
= bfd_get_16 (abfd
, contents
+ i
);
2087 op
= sh_insn_info (insn
);
2089 || (op
->flags
& (LOAD
| STORE
)) == 0)
2092 /* This is a load or store which is not on a four byte boundary. */
2094 while (*plabel
< label_end
&& **plabel
< i
)
2099 prev_insn
= bfd_get_16 (abfd
, contents
+ i
- 2);
2100 prev_op
= sh_insn_info (prev_insn
);
2102 /* If the load/store instruction is in a delay slot, we
2105 || (prev_op
->flags
& DELAY
) != 0)
2109 && (*plabel
>= label_end
|| **plabel
!= i
)
2111 && (prev_op
->flags
& (LOAD
| STORE
)) == 0
2112 && ! sh_insns_conflict (prev_insn
, prev_op
, insn
, op
))
2116 /* The load/store instruction does not have a label, and
2117 there is a previous instruction; PREV_INSN is not
2118 itself a load/store instruction, and PREV_INSN and
2119 INSN do not conflict. */
2125 unsigned int prev2_insn
;
2126 const struct sh_opcode
*prev2_op
;
2128 prev2_insn
= bfd_get_16 (abfd
, contents
+ i
- 4);
2129 prev2_op
= sh_insn_info (prev2_insn
);
2131 /* If the instruction before PREV_INSN has a delay
2132 slot--that is, PREV_INSN is in a delay slot--we
2134 if (prev2_op
== NULL
2135 || (prev2_op
->flags
& DELAY
) != 0)
2138 /* If the instruction before PREV_INSN is a load,
2139 and it sets a register which INSN uses, then
2140 putting INSN immediately after PREV_INSN will
2141 cause a pipeline bubble, so there is no point to
2144 && (prev2_op
->flags
& LOAD
) != 0
2145 && sh_load_use (prev2_insn
, prev2_op
, insn
, op
))
2151 if (! (*swap
) (abfd
, sec
, relocs
, contents
, i
- 2))
2158 while (*plabel
< label_end
&& **plabel
< i
+ 2)
2162 && (*plabel
>= label_end
|| **plabel
!= i
+ 2))
2164 unsigned int next_insn
;
2165 const struct sh_opcode
*next_op
;
2167 /* There is an instruction after the load/store
2168 instruction, and it does not have a label. */
2169 next_insn
= bfd_get_16 (abfd
, contents
+ i
+ 2);
2170 next_op
= sh_insn_info (next_insn
);
2172 && (next_op
->flags
& (LOAD
| STORE
)) == 0
2173 && ! sh_insns_conflict (insn
, op
, next_insn
, next_op
))
2177 /* NEXT_INSN is not itself a load/store instruction,
2178 and it does not conflict with INSN. */
2182 /* If PREV_INSN is a load, and it sets a register
2183 which NEXT_INSN uses, then putting NEXT_INSN
2184 immediately after PREV_INSN will cause a pipeline
2185 bubble, so there is no reason to make this swap. */
2187 && (prev_op
->flags
& LOAD
) != 0
2188 && sh_load_use (prev_insn
, prev_op
, next_insn
, next_op
))
2191 /* If INSN is a load, and it sets a register which
2192 the insn after NEXT_INSN uses, then doing the
2193 swap will cause a pipeline bubble, so there is no
2194 reason to make the swap. However, if the insn
2195 after NEXT_INSN is itself a load or store
2196 instruction, then it is misaligned, so
2197 optimistically hope that it will be swapped
2198 itself, and just live with the pipeline bubble if
2202 && (op
->flags
& LOAD
) != 0)
2204 unsigned int next2_insn
;
2205 const struct sh_opcode
*next2_op
;
2207 next2_insn
= bfd_get_16 (abfd
, contents
+ i
+ 4);
2208 next2_op
= sh_insn_info (next2_insn
);
2209 if ((next2_op
->flags
& (LOAD
| STORE
)) == 0
2210 && sh_load_use (insn
, op
, next2_insn
, next2_op
))
2216 if (! (*swap
) (abfd
, sec
, relocs
, contents
, i
))
2228 /* Look for loads and stores which we can align to four byte
2229 boundaries. See the longer comment above sh_relax_section for why
2230 this is desirable. This sets *PSWAPPED if some instruction was
2234 sh_align_loads (abfd
, sec
, internal_relocs
, contents
, pswapped
)
2237 struct internal_reloc
*internal_relocs
;
2241 struct internal_reloc
*irel
, *irelend
;
2242 bfd_vma
*labels
= NULL
;
2243 bfd_vma
*label
, *label_end
;
2247 irelend
= internal_relocs
+ sec
->reloc_count
;
2249 /* Get all the addresses with labels on them. */
2250 labels
= (bfd_vma
*) bfd_malloc (sec
->reloc_count
* sizeof (bfd_vma
));
2254 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2256 if (irel
->r_type
== R_SH_LABEL
)
2258 *label_end
= irel
->r_vaddr
- sec
->vma
;
2263 /* Note that the assembler currently always outputs relocs in
2264 address order. If that ever changes, this code will need to sort
2265 the label values and the relocs. */
2269 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2271 bfd_vma start
, stop
;
2273 if (irel
->r_type
!= R_SH_CODE
)
2276 start
= irel
->r_vaddr
- sec
->vma
;
2278 for (irel
++; irel
< irelend
; irel
++)
2279 if (irel
->r_type
== R_SH_DATA
)
2282 stop
= irel
->r_vaddr
- sec
->vma
;
2284 stop
= sec
->_cooked_size
;
2286 if (! _bfd_sh_align_load_span (abfd
, sec
, contents
, sh_swap_insns
,
2287 (PTR
) internal_relocs
, &label
,
2288 label_end
, start
, stop
, pswapped
))
2302 /* Swap two SH instructions. */
2305 sh_swap_insns (abfd
, sec
, relocs
, contents
, addr
)
2312 struct internal_reloc
*internal_relocs
= (struct internal_reloc
*) relocs
;
2313 unsigned short i1
, i2
;
2314 struct internal_reloc
*irel
, *irelend
;
2316 /* Swap the instructions themselves. */
2317 i1
= bfd_get_16 (abfd
, contents
+ addr
);
2318 i2
= bfd_get_16 (abfd
, contents
+ addr
+ 2);
2319 bfd_put_16 (abfd
, i2
, contents
+ addr
);
2320 bfd_put_16 (abfd
, i1
, contents
+ addr
+ 2);
2322 /* Adjust all reloc addresses. */
2323 irelend
= internal_relocs
+ sec
->reloc_count
;
2324 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
2328 /* There are a few special types of relocs that we don't want to
2329 adjust. These relocs do not apply to the instruction itself,
2330 but are only associated with the address. */
2331 type
= irel
->r_type
;
2332 if (type
== R_SH_ALIGN
2333 || type
== R_SH_CODE
2334 || type
== R_SH_DATA
2335 || type
== R_SH_LABEL
)
2338 /* If an R_SH_USES reloc points to one of the addresses being
2339 swapped, we must adjust it. It would be incorrect to do this
2340 for a jump, though, since we want to execute both
2341 instructions after the jump. (We have avoided swapping
2342 around a label, so the jump will not wind up executing an
2343 instruction it shouldn't). */
2344 if (type
== R_SH_USES
)
2348 off
= irel
->r_vaddr
- sec
->vma
+ 4 + irel
->r_offset
;
2350 irel
->r_offset
+= 2;
2351 else if (off
== addr
+ 2)
2352 irel
->r_offset
-= 2;
2355 if (irel
->r_vaddr
- sec
->vma
== addr
)
2360 else if (irel
->r_vaddr
- sec
->vma
== addr
+ 2)
2371 unsigned short insn
, oinsn
;
2374 loc
= contents
+ irel
->r_vaddr
- sec
->vma
;
2381 case R_SH_PCDISP8BY2
:
2382 case R_SH_PCRELIMM8BY2
:
2383 insn
= bfd_get_16 (abfd
, loc
);
2386 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2388 bfd_put_16 (abfd
, insn
, loc
);
2392 insn
= bfd_get_16 (abfd
, loc
);
2395 if ((oinsn
& 0xf000) != (insn
& 0xf000))
2397 bfd_put_16 (abfd
, insn
, loc
);
2400 case R_SH_PCRELIMM8BY4
:
2401 /* This reloc ignores the least significant 3 bits of
2402 the program counter before adding in the offset.
2403 This means that if ADDR is at an even address, the
2404 swap will not affect the offset. If ADDR is an at an
2405 odd address, then the instruction will be crossing a
2406 four byte boundary, and must be adjusted. */
2407 if ((addr
& 3) != 0)
2409 insn
= bfd_get_16 (abfd
, loc
);
2412 if ((oinsn
& 0xff00) != (insn
& 0xff00))
2414 bfd_put_16 (abfd
, insn
, loc
);
2422 ((*_bfd_error_handler
)
2423 ("%s: 0x%lx: fatal: reloc overflow while relaxing",
2424 bfd_get_filename (abfd
), (unsigned long) irel
->r_vaddr
));
2425 bfd_set_error (bfd_error_bad_value
);
2434 /* This is a modification of _bfd_coff_generic_relocate_section, which
2435 will handle SH relaxing. */
2438 sh_relocate_section (output_bfd
, info
, input_bfd
, input_section
, contents
,
2439 relocs
, syms
, sections
)
2441 struct bfd_link_info
*info
;
2443 asection
*input_section
;
2445 struct internal_reloc
*relocs
;
2446 struct internal_syment
*syms
;
2447 asection
**sections
;
2449 struct internal_reloc
*rel
;
2450 struct internal_reloc
*relend
;
2453 relend
= rel
+ input_section
->reloc_count
;
2454 for (; rel
< relend
; rel
++)
2457 struct coff_link_hash_entry
*h
;
2458 struct internal_syment
*sym
;
2461 reloc_howto_type
*howto
;
2462 bfd_reloc_status_type rstat
;
2464 /* Almost all relocs have to do with relaxing. If any work must
2465 be done for them, it has been done in sh_relax_section. */
2466 if (rel
->r_type
!= R_SH_IMM32
2467 && rel
->r_type
!= R_SH_PCDISP
)
2470 symndx
= rel
->r_symndx
;
2480 || (unsigned long) symndx
>= obj_raw_syment_count (input_bfd
))
2482 (*_bfd_error_handler
)
2483 ("%s: illegal symbol index %ld in relocs",
2484 bfd_get_filename (input_bfd
), symndx
);
2485 bfd_set_error (bfd_error_bad_value
);
2488 h
= obj_coff_sym_hashes (input_bfd
)[symndx
];
2489 sym
= syms
+ symndx
;
2492 if (sym
!= NULL
&& sym
->n_scnum
!= 0)
2493 addend
= - sym
->n_value
;
2497 if (rel
->r_type
== R_SH_PCDISP
)
2500 if (rel
->r_type
>= SH_COFF_HOWTO_COUNT
)
2503 howto
= &sh_coff_howtos
[rel
->r_type
];
2507 bfd_set_error (bfd_error_bad_value
);
2517 /* There is nothing to do for an internal PCDISP reloc. */
2518 if (rel
->r_type
== R_SH_PCDISP
)
2523 sec
= bfd_abs_section_ptr
;
2528 sec
= sections
[symndx
];
2529 val
= (sec
->output_section
->vma
2530 + sec
->output_offset
2537 if (h
->root
.type
== bfd_link_hash_defined
2538 || h
->root
.type
== bfd_link_hash_defweak
)
2542 sec
= h
->root
.u
.def
.section
;
2543 val
= (h
->root
.u
.def
.value
2544 + sec
->output_section
->vma
2545 + sec
->output_offset
);
2547 else if (! info
->relocateable
)
2549 if (! ((*info
->callbacks
->undefined_symbol
)
2550 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
2551 rel
->r_vaddr
- input_section
->vma
)))
2556 rstat
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2558 rel
->r_vaddr
- input_section
->vma
,
2567 case bfd_reloc_overflow
:
2570 char buf
[SYMNMLEN
+ 1];
2575 name
= h
->root
.root
.string
;
2576 else if (sym
->_n
._n_n
._n_zeroes
== 0
2577 && sym
->_n
._n_n
._n_offset
!= 0)
2578 name
= obj_coff_strings (input_bfd
) + sym
->_n
._n_n
._n_offset
;
2581 strncpy (buf
, sym
->_n
._n_name
, SYMNMLEN
);
2582 buf
[SYMNMLEN
] = '\0';
2586 if (! ((*info
->callbacks
->reloc_overflow
)
2587 (info
, name
, howto
->name
, (bfd_vma
) 0, input_bfd
,
2588 input_section
, rel
->r_vaddr
- input_section
->vma
)))
2597 /* This is a version of bfd_generic_get_relocated_section_contents
2598 which uses sh_relocate_section. */
2601 sh_coff_get_relocated_section_contents (output_bfd
, link_info
, link_order
,
2602 data
, relocateable
, symbols
)
2604 struct bfd_link_info
*link_info
;
2605 struct bfd_link_order
*link_order
;
2607 boolean relocateable
;
2610 asection
*input_section
= link_order
->u
.indirect
.section
;
2611 bfd
*input_bfd
= input_section
->owner
;
2612 asection
**sections
= NULL
;
2613 struct internal_reloc
*internal_relocs
= NULL
;
2614 struct internal_syment
*internal_syms
= NULL
;
2616 /* We only need to handle the case of relaxing, or of having a
2617 particular set of section contents, specially. */
2619 || coff_section_data (input_bfd
, input_section
) == NULL
2620 || coff_section_data (input_bfd
, input_section
)->contents
== NULL
)
2621 return bfd_generic_get_relocated_section_contents (output_bfd
, link_info
,
2626 memcpy (data
, coff_section_data (input_bfd
, input_section
)->contents
,
2627 input_section
->_raw_size
);
2629 if ((input_section
->flags
& SEC_RELOC
) != 0
2630 && input_section
->reloc_count
> 0)
2632 bfd_size_type symesz
= bfd_coff_symesz (input_bfd
);
2633 bfd_byte
*esym
, *esymend
;
2634 struct internal_syment
*isymp
;
2637 if (! _bfd_coff_get_external_symbols (input_bfd
))
2640 internal_relocs
= (_bfd_coff_read_internal_relocs
2641 (input_bfd
, input_section
, false, (bfd_byte
*) NULL
,
2642 false, (struct internal_reloc
*) NULL
));
2643 if (internal_relocs
== NULL
)
2646 internal_syms
= ((struct internal_syment
*)
2647 bfd_malloc (obj_raw_syment_count (input_bfd
)
2648 * sizeof (struct internal_syment
)));
2649 if (internal_syms
== NULL
)
2652 sections
= (asection
**) bfd_malloc (obj_raw_syment_count (input_bfd
)
2653 * sizeof (asection
*));
2654 if (sections
== NULL
)
2657 isymp
= internal_syms
;
2659 esym
= (bfd_byte
*) obj_coff_external_syms (input_bfd
);
2660 esymend
= esym
+ obj_raw_syment_count (input_bfd
) * symesz
;
2661 while (esym
< esymend
)
2663 bfd_coff_swap_sym_in (input_bfd
, (PTR
) esym
, (PTR
) isymp
);
2665 if (isymp
->n_scnum
!= 0)
2666 *secpp
= coff_section_from_bfd_index (input_bfd
, isymp
->n_scnum
);
2669 if (isymp
->n_value
== 0)
2670 *secpp
= bfd_und_section_ptr
;
2672 *secpp
= bfd_com_section_ptr
;
2675 esym
+= (isymp
->n_numaux
+ 1) * symesz
;
2676 secpp
+= isymp
->n_numaux
+ 1;
2677 isymp
+= isymp
->n_numaux
+ 1;
2680 if (! sh_relocate_section (output_bfd
, link_info
, input_bfd
,
2681 input_section
, data
, internal_relocs
,
2682 internal_syms
, sections
))
2687 free (internal_syms
);
2688 internal_syms
= NULL
;
2689 free (internal_relocs
);
2690 internal_relocs
= NULL
;
2696 if (internal_relocs
!= NULL
)
2697 free (internal_relocs
);
2698 if (internal_syms
!= NULL
)
2699 free (internal_syms
);
2700 if (sections
!= NULL
)
2705 /* The target vectors. */
2707 const bfd_target shcoff_vec
=
2709 "coff-sh", /* name */
2710 bfd_target_coff_flavour
,
2711 BFD_ENDIAN_BIG
, /* data byte order is big */
2712 BFD_ENDIAN_BIG
, /* header byte order is big */
2714 (HAS_RELOC
| EXEC_P
| /* object flags */
2715 HAS_LINENO
| HAS_DEBUG
|
2716 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| BFD_IS_RELAXABLE
),
2718 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
),
2719 '_', /* leading symbol underscore */
2720 '/', /* ar_pad_char */
2721 15, /* ar_max_namelen */
2722 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
2723 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
2724 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
2725 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
2726 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
2727 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
2729 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
2730 bfd_generic_archive_p
, _bfd_dummy_target
},
2731 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
2733 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
2734 _bfd_write_archive_contents
, bfd_false
},
2736 BFD_JUMP_TABLE_GENERIC (coff
),
2737 BFD_JUMP_TABLE_COPY (coff
),
2738 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
2739 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
2740 BFD_JUMP_TABLE_SYMBOLS (coff
),
2741 BFD_JUMP_TABLE_RELOCS (coff
),
2742 BFD_JUMP_TABLE_WRITE (coff
),
2743 BFD_JUMP_TABLE_LINK (coff
),
2744 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
2749 const bfd_target shlcoff_vec
=
2751 "coff-shl", /* name */
2752 bfd_target_coff_flavour
,
2753 BFD_ENDIAN_LITTLE
, /* data byte order is little */
2754 BFD_ENDIAN_LITTLE
, /* header byte order is little endian too*/
2756 (HAS_RELOC
| EXEC_P
| /* object flags */
2757 HAS_LINENO
| HAS_DEBUG
|
2758 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| BFD_IS_RELAXABLE
),
2760 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
),
2761 '_', /* leading symbol underscore */
2762 '/', /* ar_pad_char */
2763 15, /* ar_max_namelen */
2764 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2765 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2766 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* data */
2767 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2768 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2769 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* hdrs */
2771 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
2772 bfd_generic_archive_p
, _bfd_dummy_target
},
2773 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
2775 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
2776 _bfd_write_archive_contents
, bfd_false
},
2778 BFD_JUMP_TABLE_GENERIC (coff
),
2779 BFD_JUMP_TABLE_COPY (coff
),
2780 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
2781 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
2782 BFD_JUMP_TABLE_SYMBOLS (coff
),
2783 BFD_JUMP_TABLE_RELOCS (coff
),
2784 BFD_JUMP_TABLE_WRITE (coff
),
2785 BFD_JUMP_TABLE_LINK (coff
),
2786 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
2791 /* Some people want versions of the SH COFF target which do not align
2792 to 16 byte boundaries. We implement that by adding a couple of new
2793 target vectors. These are just like the ones above, but they
2794 change the default section alignment. To generate them in the
2795 assembler, use -small. To use them in the linker, use -b
2796 coff-sh{l}-small and -oformat coff-sh{l}-small.
2798 Yes, this is a horrible hack. A general solution for setting
2799 section alignment in COFF is rather complex. ELF handles this
2802 /* Only recognize the small versions if the target was not defaulted.
2803 Otherwise we won't recognize the non default endianness. */
2805 static const bfd_target
*
2806 coff_small_object_p (abfd
)
2809 if (abfd
->target_defaulted
)
2811 bfd_set_error (bfd_error_wrong_format
);
2814 return coff_object_p (abfd
);
2817 /* Set the section alignment for the small versions. */
2820 coff_small_new_section_hook (abfd
, section
)
2824 if (! coff_new_section_hook (abfd
, section
))
2827 /* We must align to at least a four byte boundary, because longword
2828 accesses must be on a four byte boundary. */
2829 if (section
->alignment_power
== COFF_DEFAULT_SECTION_ALIGNMENT_POWER
)
2830 section
->alignment_power
= 2;
2835 /* This is copied from bfd_coff_std_swap_table so that we can change
2836 the default section alignment power. */
2838 static const bfd_coff_backend_data bfd_coff_small_swap_table
=
2840 coff_swap_aux_in
, coff_swap_sym_in
, coff_swap_lineno_in
,
2841 coff_swap_aux_out
, coff_swap_sym_out
,
2842 coff_swap_lineno_out
, coff_swap_reloc_out
,
2843 coff_swap_filehdr_out
, coff_swap_aouthdr_out
,
2844 coff_swap_scnhdr_out
,
2845 FILHSZ
, AOUTSZ
, SCNHSZ
, SYMESZ
, AUXESZ
, RELSZ
, LINESZ
,
2846 #ifdef COFF_LONG_FILENAMES
2851 #ifdef COFF_LONG_SECTION_NAMES
2857 coff_swap_filehdr_in
, coff_swap_aouthdr_in
, coff_swap_scnhdr_in
,
2858 coff_swap_reloc_in
, coff_bad_format_hook
, coff_set_arch_mach_hook
,
2859 coff_mkobject_hook
, styp_to_sec_flags
, coff_set_alignment_hook
,
2860 coff_slurp_symbol_table
, symname_in_debug_hook
, coff_pointerize_aux_hook
,
2861 coff_print_aux
, coff_reloc16_extra_cases
, coff_reloc16_estimate
,
2862 coff_sym_is_global
, coff_compute_section_file_positions
,
2863 coff_start_final_link
, coff_relocate_section
, coff_rtype_to_howto
,
2864 coff_adjust_symndx
, coff_link_add_one_symbol
,
2865 coff_link_output_has_begun
, coff_final_link_postscript
2868 #define coff_small_close_and_cleanup \
2869 coff_close_and_cleanup
2870 #define coff_small_bfd_free_cached_info \
2871 coff_bfd_free_cached_info
2872 #define coff_small_get_section_contents \
2873 coff_get_section_contents
2874 #define coff_small_get_section_contents_in_window \
2875 coff_get_section_contents_in_window
2877 const bfd_target shcoff_small_vec
=
2879 "coff-sh-small", /* name */
2880 bfd_target_coff_flavour
,
2881 BFD_ENDIAN_BIG
, /* data byte order is big */
2882 BFD_ENDIAN_BIG
, /* header byte order is big */
2884 (HAS_RELOC
| EXEC_P
| /* object flags */
2885 HAS_LINENO
| HAS_DEBUG
|
2886 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| BFD_IS_RELAXABLE
),
2888 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
),
2889 '_', /* leading symbol underscore */
2890 '/', /* ar_pad_char */
2891 15, /* ar_max_namelen */
2892 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
2893 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
2894 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
2895 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
2896 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
2897 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
2899 {_bfd_dummy_target
, coff_small_object_p
, /* bfd_check_format */
2900 bfd_generic_archive_p
, _bfd_dummy_target
},
2901 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
2903 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
2904 _bfd_write_archive_contents
, bfd_false
},
2906 BFD_JUMP_TABLE_GENERIC (coff_small
),
2907 BFD_JUMP_TABLE_COPY (coff
),
2908 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
2909 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
2910 BFD_JUMP_TABLE_SYMBOLS (coff
),
2911 BFD_JUMP_TABLE_RELOCS (coff
),
2912 BFD_JUMP_TABLE_WRITE (coff
),
2913 BFD_JUMP_TABLE_LINK (coff
),
2914 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
2916 (PTR
) &bfd_coff_small_swap_table
2919 const bfd_target shlcoff_small_vec
=
2921 "coff-shl-small", /* name */
2922 bfd_target_coff_flavour
,
2923 BFD_ENDIAN_LITTLE
, /* data byte order is little */
2924 BFD_ENDIAN_LITTLE
, /* header byte order is little endian too*/
2926 (HAS_RELOC
| EXEC_P
| /* object flags */
2927 HAS_LINENO
| HAS_DEBUG
|
2928 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| BFD_IS_RELAXABLE
),
2930 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
),
2931 '_', /* leading symbol underscore */
2932 '/', /* ar_pad_char */
2933 15, /* ar_max_namelen */
2934 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2935 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2936 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* data */
2937 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
2938 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
2939 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* hdrs */
2941 {_bfd_dummy_target
, coff_small_object_p
, /* bfd_check_format */
2942 bfd_generic_archive_p
, _bfd_dummy_target
},
2943 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
2945 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
2946 _bfd_write_archive_contents
, bfd_false
},
2948 BFD_JUMP_TABLE_GENERIC (coff_small
),
2949 BFD_JUMP_TABLE_COPY (coff
),
2950 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
2951 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
2952 BFD_JUMP_TABLE_SYMBOLS (coff
),
2953 BFD_JUMP_TABLE_RELOCS (coff
),
2954 BFD_JUMP_TABLE_WRITE (coff
),
2955 BFD_JUMP_TABLE_LINK (coff
),
2956 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
2958 (PTR
) &bfd_coff_small_swap_table