Home | History | Annotate | Line # | Download | only in bfd
coff-sh.c revision 1.1.1.3
      1      1.1  christos /* BFD back-end for Renesas Super-H COFF binaries.
      2  1.1.1.3  christos    Copyright (C) 1993-2015 Free Software Foundation, Inc.
      3      1.1  christos    Contributed by Cygnus Support.
      4      1.1  christos    Written by Steve Chamberlain, <sac (at) cygnus.com>.
      5      1.1  christos    Relaxing code written by Ian Lance Taylor, <ian (at) cygnus.com>.
      6      1.1  christos 
      7      1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      8      1.1  christos 
      9      1.1  christos    This program is free software; you can redistribute it and/or modify
     10      1.1  christos    it under the terms of the GNU General Public License as published by
     11      1.1  christos    the Free Software Foundation; either version 3 of the License, or
     12      1.1  christos    (at your option) any later version.
     13      1.1  christos 
     14      1.1  christos    This program is distributed in the hope that it will be useful,
     15      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     16      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17      1.1  christos    GNU General Public License for more details.
     18      1.1  christos 
     19      1.1  christos    You should have received a copy of the GNU General Public License
     20      1.1  christos    along with this program; if not, write to the Free Software
     21      1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     22      1.1  christos    MA 02110-1301, USA.  */
     23      1.1  christos 
     24      1.1  christos #include "sysdep.h"
     25      1.1  christos #include "bfd.h"
     26      1.1  christos #include "libiberty.h"
     27      1.1  christos #include "libbfd.h"
     28      1.1  christos #include "bfdlink.h"
     29      1.1  christos #include "coff/sh.h"
     30      1.1  christos #include "coff/internal.h"
     31      1.1  christos 
     32      1.1  christos #undef  bfd_pe_print_pdata
     33      1.1  christos 
     34      1.1  christos #ifdef COFF_WITH_PE
     35      1.1  christos #include "coff/pe.h"
     36      1.1  christos 
     37      1.1  christos #ifndef COFF_IMAGE_WITH_PE
     38      1.1  christos static bfd_boolean sh_align_load_span
     39  1.1.1.2  christos   (bfd *, asection *, bfd_byte *,
     40  1.1.1.2  christos    bfd_boolean (*) (bfd *, asection *, void *, bfd_byte *, bfd_vma),
     41  1.1.1.2  christos    void *, bfd_vma **, bfd_vma *, bfd_vma, bfd_vma, bfd_boolean *);
     42      1.1  christos 
     43      1.1  christos #define _bfd_sh_align_load_span sh_align_load_span
     44      1.1  christos #endif
     45      1.1  christos 
     46      1.1  christos #define	bfd_pe_print_pdata   _bfd_pe_print_ce_compressed_pdata
     47      1.1  christos 
     48      1.1  christos #else
     49      1.1  christos 
     50      1.1  christos #define	bfd_pe_print_pdata   NULL
     51      1.1  christos 
     52      1.1  christos #endif /* COFF_WITH_PE.  */
     53      1.1  christos 
     54      1.1  christos #include "libcoff.h"
     55      1.1  christos 
     56      1.1  christos /* Internal functions.  */
     57      1.1  christos 
     58      1.1  christos #ifdef COFF_WITH_PE
     59      1.1  christos /* Can't build import tables with 2**4 alignment.  */
     60      1.1  christos #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER	2
     61      1.1  christos #else
     62      1.1  christos /* Default section alignment to 2**4.  */
     63      1.1  christos #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER	4
     64      1.1  christos #endif
     65      1.1  christos 
     66      1.1  christos #ifdef COFF_IMAGE_WITH_PE
     67      1.1  christos /* Align PE executables.  */
     68      1.1  christos #define COFF_PAGE_SIZE 0x1000
     69      1.1  christos #endif
     70      1.1  christos 
     71      1.1  christos /* Generate long file names.  */
     72      1.1  christos #define COFF_LONG_FILENAMES
     73      1.1  christos 
     74      1.1  christos #ifdef COFF_WITH_PE
     75      1.1  christos /* Return TRUE if this relocation should
     76      1.1  christos    appear in the output .reloc section.  */
     77  1.1.1.2  christos 
     78  1.1.1.2  christos static bfd_boolean
     79  1.1.1.2  christos in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED,
     80  1.1.1.2  christos 	    reloc_howto_type * howto)
     81      1.1  christos {
     82      1.1  christos   return ! howto->pc_relative && howto->type != R_SH_IMAGEBASE;
     83      1.1  christos }
     84      1.1  christos #endif
     85      1.1  christos 
     86  1.1.1.2  christos static bfd_reloc_status_type
     87  1.1.1.2  christos sh_reloc (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
     88  1.1.1.2  christos static bfd_boolean
     89  1.1.1.2  christos sh_relocate_section (bfd *, struct bfd_link_info *, bfd *, asection *,
     90  1.1.1.2  christos 		     bfd_byte *, struct internal_reloc *,
     91  1.1.1.2  christos 		     struct internal_syment *, asection **);
     92  1.1.1.2  christos static bfd_boolean
     93  1.1.1.2  christos sh_align_loads (bfd *, asection *, struct internal_reloc *,
     94  1.1.1.2  christos 		bfd_byte *, bfd_boolean *);
     95  1.1.1.2  christos 
     96      1.1  christos /* The supported relocations.  There are a lot of relocations defined
     97      1.1  christos    in coff/internal.h which we do not expect to ever see.  */
     98      1.1  christos static reloc_howto_type sh_coff_howtos[] =
     99      1.1  christos {
    100      1.1  christos   EMPTY_HOWTO (0),
    101      1.1  christos   EMPTY_HOWTO (1),
    102      1.1  christos #ifdef COFF_WITH_PE
    103      1.1  christos   /* Windows CE */
    104      1.1  christos   HOWTO (R_SH_IMM32CE,		/* type */
    105      1.1  christos 	 0,			/* rightshift */
    106      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    107      1.1  christos 	 32,			/* bitsize */
    108      1.1  christos 	 FALSE,			/* pc_relative */
    109      1.1  christos 	 0,			/* bitpos */
    110      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    111      1.1  christos 	 sh_reloc,		/* special_function */
    112      1.1  christos 	 "r_imm32ce",		/* name */
    113      1.1  christos 	 TRUE,			/* partial_inplace */
    114      1.1  christos 	 0xffffffff,		/* src_mask */
    115      1.1  christos 	 0xffffffff,		/* dst_mask */
    116      1.1  christos 	 FALSE),		/* pcrel_offset */
    117      1.1  christos #else
    118      1.1  christos   EMPTY_HOWTO (2),
    119      1.1  christos #endif
    120      1.1  christos   EMPTY_HOWTO (3), /* R_SH_PCREL8 */
    121      1.1  christos   EMPTY_HOWTO (4), /* R_SH_PCREL16 */
    122      1.1  christos   EMPTY_HOWTO (5), /* R_SH_HIGH8 */
    123      1.1  christos   EMPTY_HOWTO (6), /* R_SH_IMM24 */
    124      1.1  christos   EMPTY_HOWTO (7), /* R_SH_LOW16 */
    125      1.1  christos   EMPTY_HOWTO (8),
    126      1.1  christos   EMPTY_HOWTO (9), /* R_SH_PCDISP8BY4 */
    127      1.1  christos 
    128      1.1  christos   HOWTO (R_SH_PCDISP8BY2,	/* type */
    129      1.1  christos 	 1,			/* rightshift */
    130      1.1  christos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    131      1.1  christos 	 8,			/* bitsize */
    132      1.1  christos 	 TRUE,			/* pc_relative */
    133      1.1  christos 	 0,			/* bitpos */
    134      1.1  christos 	 complain_overflow_signed, /* complain_on_overflow */
    135      1.1  christos 	 sh_reloc,		/* special_function */
    136      1.1  christos 	 "r_pcdisp8by2",	/* name */
    137      1.1  christos 	 TRUE,			/* partial_inplace */
    138      1.1  christos 	 0xff,			/* src_mask */
    139      1.1  christos 	 0xff,			/* dst_mask */
    140      1.1  christos 	 TRUE),			/* pcrel_offset */
    141      1.1  christos 
    142      1.1  christos   EMPTY_HOWTO (11), /* R_SH_PCDISP8 */
    143      1.1  christos 
    144      1.1  christos   HOWTO (R_SH_PCDISP,		/* type */
    145      1.1  christos 	 1,			/* rightshift */
    146      1.1  christos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    147      1.1  christos 	 12,			/* bitsize */
    148      1.1  christos 	 TRUE,			/* pc_relative */
    149      1.1  christos 	 0,			/* bitpos */
    150      1.1  christos 	 complain_overflow_signed, /* complain_on_overflow */
    151      1.1  christos 	 sh_reloc,		/* special_function */
    152      1.1  christos 	 "r_pcdisp12by2",	/* name */
    153      1.1  christos 	 TRUE,			/* partial_inplace */
    154      1.1  christos 	 0xfff,			/* src_mask */
    155      1.1  christos 	 0xfff,			/* dst_mask */
    156      1.1  christos 	 TRUE),			/* pcrel_offset */
    157      1.1  christos 
    158      1.1  christos   EMPTY_HOWTO (13),
    159      1.1  christos 
    160      1.1  christos   HOWTO (R_SH_IMM32,		/* type */
    161      1.1  christos 	 0,			/* rightshift */
    162      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    163      1.1  christos 	 32,			/* bitsize */
    164      1.1  christos 	 FALSE,			/* pc_relative */
    165      1.1  christos 	 0,			/* bitpos */
    166      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    167      1.1  christos 	 sh_reloc,		/* special_function */
    168      1.1  christos 	 "r_imm32",		/* name */
    169      1.1  christos 	 TRUE,			/* partial_inplace */
    170      1.1  christos 	 0xffffffff,		/* src_mask */
    171      1.1  christos 	 0xffffffff,		/* dst_mask */
    172      1.1  christos 	 FALSE),		/* pcrel_offset */
    173      1.1  christos 
    174      1.1  christos   EMPTY_HOWTO (15),
    175      1.1  christos #ifdef COFF_WITH_PE
    176      1.1  christos   HOWTO (R_SH_IMAGEBASE,        /* type */
    177      1.1  christos 	 0,	                /* rightshift */
    178      1.1  christos 	 2,	                /* size (0 = byte, 1 = short, 2 = long) */
    179      1.1  christos 	 32,	                /* bitsize */
    180      1.1  christos 	 FALSE,	                /* pc_relative */
    181      1.1  christos 	 0,	                /* bitpos */
    182      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    183      1.1  christos 	 sh_reloc,       	/* special_function */
    184      1.1  christos 	 "rva32",	        /* name */
    185      1.1  christos 	 TRUE,	                /* partial_inplace */
    186      1.1  christos 	 0xffffffff,            /* src_mask */
    187      1.1  christos 	 0xffffffff,            /* dst_mask */
    188      1.1  christos 	 FALSE),                /* pcrel_offset */
    189      1.1  christos #else
    190      1.1  christos   EMPTY_HOWTO (16), /* R_SH_IMM8 */
    191      1.1  christos #endif
    192      1.1  christos   EMPTY_HOWTO (17), /* R_SH_IMM8BY2 */
    193      1.1  christos   EMPTY_HOWTO (18), /* R_SH_IMM8BY4 */
    194      1.1  christos   EMPTY_HOWTO (19), /* R_SH_IMM4 */
    195      1.1  christos   EMPTY_HOWTO (20), /* R_SH_IMM4BY2 */
    196      1.1  christos   EMPTY_HOWTO (21), /* R_SH_IMM4BY4 */
    197      1.1  christos 
    198      1.1  christos   HOWTO (R_SH_PCRELIMM8BY2,	/* type */
    199      1.1  christos 	 1,			/* rightshift */
    200      1.1  christos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    201      1.1  christos 	 8,			/* bitsize */
    202      1.1  christos 	 TRUE,			/* pc_relative */
    203      1.1  christos 	 0,			/* bitpos */
    204      1.1  christos 	 complain_overflow_unsigned, /* complain_on_overflow */
    205      1.1  christos 	 sh_reloc,		/* special_function */
    206      1.1  christos 	 "r_pcrelimm8by2",	/* name */
    207      1.1  christos 	 TRUE,			/* partial_inplace */
    208      1.1  christos 	 0xff,			/* src_mask */
    209      1.1  christos 	 0xff,			/* dst_mask */
    210      1.1  christos 	 TRUE),			/* pcrel_offset */
    211      1.1  christos 
    212      1.1  christos   HOWTO (R_SH_PCRELIMM8BY4,	/* type */
    213      1.1  christos 	 2,			/* rightshift */
    214      1.1  christos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    215      1.1  christos 	 8,			/* bitsize */
    216      1.1  christos 	 TRUE,			/* pc_relative */
    217      1.1  christos 	 0,			/* bitpos */
    218      1.1  christos 	 complain_overflow_unsigned, /* complain_on_overflow */
    219      1.1  christos 	 sh_reloc,		/* special_function */
    220      1.1  christos 	 "r_pcrelimm8by4",	/* name */
    221      1.1  christos 	 TRUE,			/* partial_inplace */
    222      1.1  christos 	 0xff,			/* src_mask */
    223      1.1  christos 	 0xff,			/* dst_mask */
    224      1.1  christos 	 TRUE),			/* pcrel_offset */
    225      1.1  christos 
    226      1.1  christos   HOWTO (R_SH_IMM16,		/* type */
    227      1.1  christos 	 0,			/* rightshift */
    228      1.1  christos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    229      1.1  christos 	 16,			/* bitsize */
    230      1.1  christos 	 FALSE,			/* pc_relative */
    231      1.1  christos 	 0,			/* bitpos */
    232      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    233      1.1  christos 	 sh_reloc,		/* special_function */
    234      1.1  christos 	 "r_imm16",		/* name */
    235      1.1  christos 	 TRUE,			/* partial_inplace */
    236      1.1  christos 	 0xffff,		/* src_mask */
    237      1.1  christos 	 0xffff,		/* dst_mask */
    238      1.1  christos 	 FALSE),		/* pcrel_offset */
    239      1.1  christos 
    240      1.1  christos   HOWTO (R_SH_SWITCH16,		/* type */
    241      1.1  christos 	 0,			/* rightshift */
    242      1.1  christos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    243      1.1  christos 	 16,			/* bitsize */
    244      1.1  christos 	 FALSE,			/* pc_relative */
    245      1.1  christos 	 0,			/* bitpos */
    246      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    247      1.1  christos 	 sh_reloc,		/* special_function */
    248      1.1  christos 	 "r_switch16",		/* name */
    249      1.1  christos 	 TRUE,			/* partial_inplace */
    250      1.1  christos 	 0xffff,		/* src_mask */
    251      1.1  christos 	 0xffff,		/* dst_mask */
    252      1.1  christos 	 FALSE),		/* pcrel_offset */
    253      1.1  christos 
    254      1.1  christos   HOWTO (R_SH_SWITCH32,		/* type */
    255      1.1  christos 	 0,			/* rightshift */
    256      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    257      1.1  christos 	 32,			/* bitsize */
    258      1.1  christos 	 FALSE,			/* pc_relative */
    259      1.1  christos 	 0,			/* bitpos */
    260      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    261      1.1  christos 	 sh_reloc,		/* special_function */
    262      1.1  christos 	 "r_switch32",		/* name */
    263      1.1  christos 	 TRUE,			/* partial_inplace */
    264      1.1  christos 	 0xffffffff,		/* src_mask */
    265      1.1  christos 	 0xffffffff,		/* dst_mask */
    266      1.1  christos 	 FALSE),		/* pcrel_offset */
    267      1.1  christos 
    268      1.1  christos   HOWTO (R_SH_USES,		/* type */
    269      1.1  christos 	 0,			/* rightshift */
    270      1.1  christos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    271      1.1  christos 	 16,			/* bitsize */
    272      1.1  christos 	 FALSE,			/* pc_relative */
    273      1.1  christos 	 0,			/* bitpos */
    274      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    275      1.1  christos 	 sh_reloc,		/* special_function */
    276      1.1  christos 	 "r_uses",		/* name */
    277      1.1  christos 	 TRUE,			/* partial_inplace */
    278      1.1  christos 	 0xffff,		/* src_mask */
    279      1.1  christos 	 0xffff,		/* dst_mask */
    280      1.1  christos 	 FALSE),		/* pcrel_offset */
    281      1.1  christos 
    282      1.1  christos   HOWTO (R_SH_COUNT,		/* type */
    283      1.1  christos 	 0,			/* rightshift */
    284      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    285      1.1  christos 	 32,			/* bitsize */
    286      1.1  christos 	 FALSE,			/* pc_relative */
    287      1.1  christos 	 0,			/* bitpos */
    288      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    289      1.1  christos 	 sh_reloc,		/* special_function */
    290      1.1  christos 	 "r_count",		/* name */
    291      1.1  christos 	 TRUE,			/* partial_inplace */
    292      1.1  christos 	 0xffffffff,		/* src_mask */
    293      1.1  christos 	 0xffffffff,		/* dst_mask */
    294      1.1  christos 	 FALSE),		/* pcrel_offset */
    295      1.1  christos 
    296      1.1  christos   HOWTO (R_SH_ALIGN,		/* type */
    297      1.1  christos 	 0,			/* rightshift */
    298      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    299      1.1  christos 	 32,			/* bitsize */
    300      1.1  christos 	 FALSE,			/* pc_relative */
    301      1.1  christos 	 0,			/* bitpos */
    302      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    303      1.1  christos 	 sh_reloc,		/* special_function */
    304      1.1  christos 	 "r_align",		/* name */
    305      1.1  christos 	 TRUE,			/* partial_inplace */
    306      1.1  christos 	 0xffffffff,		/* src_mask */
    307      1.1  christos 	 0xffffffff,		/* dst_mask */
    308      1.1  christos 	 FALSE),		/* pcrel_offset */
    309      1.1  christos 
    310      1.1  christos   HOWTO (R_SH_CODE,		/* type */
    311      1.1  christos 	 0,			/* rightshift */
    312      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    313      1.1  christos 	 32,			/* bitsize */
    314      1.1  christos 	 FALSE,			/* pc_relative */
    315      1.1  christos 	 0,			/* bitpos */
    316      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    317      1.1  christos 	 sh_reloc,		/* special_function */
    318      1.1  christos 	 "r_code",		/* name */
    319      1.1  christos 	 TRUE,			/* partial_inplace */
    320      1.1  christos 	 0xffffffff,		/* src_mask */
    321      1.1  christos 	 0xffffffff,		/* dst_mask */
    322      1.1  christos 	 FALSE),		/* pcrel_offset */
    323      1.1  christos 
    324      1.1  christos   HOWTO (R_SH_DATA,		/* type */
    325      1.1  christos 	 0,			/* rightshift */
    326      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    327      1.1  christos 	 32,			/* bitsize */
    328      1.1  christos 	 FALSE,			/* pc_relative */
    329      1.1  christos 	 0,			/* bitpos */
    330      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    331      1.1  christos 	 sh_reloc,		/* special_function */
    332      1.1  christos 	 "r_data",		/* name */
    333      1.1  christos 	 TRUE,			/* partial_inplace */
    334      1.1  christos 	 0xffffffff,		/* src_mask */
    335      1.1  christos 	 0xffffffff,		/* dst_mask */
    336      1.1  christos 	 FALSE),		/* pcrel_offset */
    337      1.1  christos 
    338      1.1  christos   HOWTO (R_SH_LABEL,		/* type */
    339      1.1  christos 	 0,			/* rightshift */
    340      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    341      1.1  christos 	 32,			/* bitsize */
    342      1.1  christos 	 FALSE,			/* pc_relative */
    343      1.1  christos 	 0,			/* bitpos */
    344      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    345      1.1  christos 	 sh_reloc,		/* special_function */
    346      1.1  christos 	 "r_label",		/* name */
    347      1.1  christos 	 TRUE,			/* partial_inplace */
    348      1.1  christos 	 0xffffffff,		/* src_mask */
    349      1.1  christos 	 0xffffffff,		/* dst_mask */
    350      1.1  christos 	 FALSE),		/* pcrel_offset */
    351      1.1  christos 
    352      1.1  christos   HOWTO (R_SH_SWITCH8,		/* type */
    353      1.1  christos 	 0,			/* rightshift */
    354      1.1  christos 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
    355      1.1  christos 	 8,			/* bitsize */
    356      1.1  christos 	 FALSE,			/* pc_relative */
    357      1.1  christos 	 0,			/* bitpos */
    358      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    359      1.1  christos 	 sh_reloc,		/* special_function */
    360      1.1  christos 	 "r_switch8",		/* name */
    361      1.1  christos 	 TRUE,			/* partial_inplace */
    362      1.1  christos 	 0xff,			/* src_mask */
    363      1.1  christos 	 0xff,			/* dst_mask */
    364      1.1  christos 	 FALSE)			/* pcrel_offset */
    365      1.1  christos };
    366      1.1  christos 
    367      1.1  christos #define SH_COFF_HOWTO_COUNT (sizeof sh_coff_howtos / sizeof sh_coff_howtos[0])
    368      1.1  christos 
    369      1.1  christos /* Check for a bad magic number.  */
    370      1.1  christos #define BADMAG(x) SHBADMAG(x)
    371      1.1  christos 
    372      1.1  christos /* Customize coffcode.h (this is not currently used).  */
    373      1.1  christos #define SH 1
    374      1.1  christos 
    375      1.1  christos /* FIXME: This should not be set here.  */
    376      1.1  christos #define __A_MAGIC_SET__
    377      1.1  christos 
    378      1.1  christos #ifndef COFF_WITH_PE
    379      1.1  christos /* Swap the r_offset field in and out.  */
    380      1.1  christos #define SWAP_IN_RELOC_OFFSET  H_GET_32
    381      1.1  christos #define SWAP_OUT_RELOC_OFFSET H_PUT_32
    382      1.1  christos 
    383      1.1  christos /* Swap out extra information in the reloc structure.  */
    384      1.1  christos #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst)	\
    385      1.1  christos   do						\
    386      1.1  christos     {						\
    387      1.1  christos       dst->r_stuff[0] = 'S';			\
    388      1.1  christos       dst->r_stuff[1] = 'C';			\
    389      1.1  christos     }						\
    390      1.1  christos   while (0)
    391      1.1  christos #endif
    392      1.1  christos 
    393      1.1  christos /* Get the value of a symbol, when performing a relocation.  */
    394      1.1  christos 
    395      1.1  christos static long
    396  1.1.1.2  christos get_symbol_value (asymbol *symbol)
    397      1.1  christos {
    398      1.1  christos   bfd_vma relocation;
    399      1.1  christos 
    400      1.1  christos   if (bfd_is_com_section (symbol->section))
    401      1.1  christos     relocation = 0;
    402      1.1  christos   else
    403      1.1  christos     relocation = (symbol->value +
    404      1.1  christos 		  symbol->section->output_section->vma +
    405      1.1  christos 		  symbol->section->output_offset);
    406      1.1  christos 
    407      1.1  christos   return relocation;
    408      1.1  christos }
    409      1.1  christos 
    410      1.1  christos #ifdef COFF_WITH_PE
    411      1.1  christos /* Convert an rtype to howto for the COFF backend linker.
    412      1.1  christos    Copied from coff-i386.  */
    413      1.1  christos #define coff_rtype_to_howto coff_sh_rtype_to_howto
    414  1.1.1.2  christos 
    415      1.1  christos 
    416      1.1  christos static reloc_howto_type *
    417  1.1.1.2  christos coff_sh_rtype_to_howto (bfd * abfd ATTRIBUTE_UNUSED,
    418  1.1.1.2  christos 			asection * sec,
    419  1.1.1.2  christos 			struct internal_reloc * rel,
    420  1.1.1.2  christos 			struct coff_link_hash_entry * h,
    421  1.1.1.2  christos 			struct internal_syment * sym,
    422  1.1.1.2  christos 			bfd_vma * addendp)
    423      1.1  christos {
    424      1.1  christos   reloc_howto_type * howto;
    425      1.1  christos 
    426      1.1  christos   howto = sh_coff_howtos + rel->r_type;
    427      1.1  christos 
    428      1.1  christos   *addendp = 0;
    429      1.1  christos 
    430      1.1  christos   if (howto->pc_relative)
    431      1.1  christos     *addendp += sec->vma;
    432      1.1  christos 
    433      1.1  christos   if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
    434      1.1  christos     {
    435      1.1  christos       /* This is a common symbol.  The section contents include the
    436      1.1  christos 	 size (sym->n_value) as an addend.  The relocate_section
    437      1.1  christos 	 function will be adding in the final value of the symbol.  We
    438      1.1  christos 	 need to subtract out the current size in order to get the
    439      1.1  christos 	 correct result.  */
    440      1.1  christos       BFD_ASSERT (h != NULL);
    441      1.1  christos     }
    442      1.1  christos 
    443      1.1  christos   if (howto->pc_relative)
    444      1.1  christos     {
    445      1.1  christos       *addendp -= 4;
    446      1.1  christos 
    447      1.1  christos       /* If the symbol is defined, then the generic code is going to
    448      1.1  christos          add back the symbol value in order to cancel out an
    449      1.1  christos          adjustment it made to the addend.  However, we set the addend
    450      1.1  christos          to 0 at the start of this function.  We need to adjust here,
    451      1.1  christos          to avoid the adjustment the generic code will make.  FIXME:
    452      1.1  christos          This is getting a bit hackish.  */
    453      1.1  christos       if (sym != NULL && sym->n_scnum != 0)
    454      1.1  christos 	*addendp -= sym->n_value;
    455      1.1  christos     }
    456      1.1  christos 
    457      1.1  christos   if (rel->r_type == R_SH_IMAGEBASE)
    458      1.1  christos     *addendp -= pe_data (sec->output_section->owner)->pe_opthdr.ImageBase;
    459      1.1  christos 
    460      1.1  christos   return howto;
    461      1.1  christos }
    462      1.1  christos 
    463      1.1  christos #endif /* COFF_WITH_PE */
    464      1.1  christos 
    465      1.1  christos /* This structure is used to map BFD reloc codes to SH PE relocs.  */
    466      1.1  christos struct shcoff_reloc_map
    467      1.1  christos {
    468      1.1  christos   bfd_reloc_code_real_type bfd_reloc_val;
    469      1.1  christos   unsigned char shcoff_reloc_val;
    470      1.1  christos };
    471      1.1  christos 
    472      1.1  christos #ifdef COFF_WITH_PE
    473      1.1  christos /* An array mapping BFD reloc codes to SH PE relocs.  */
    474      1.1  christos static const struct shcoff_reloc_map sh_reloc_map[] =
    475      1.1  christos {
    476      1.1  christos   { BFD_RELOC_32, R_SH_IMM32CE },
    477      1.1  christos   { BFD_RELOC_RVA, R_SH_IMAGEBASE },
    478      1.1  christos   { BFD_RELOC_CTOR, R_SH_IMM32CE },
    479      1.1  christos };
    480      1.1  christos #else
    481      1.1  christos /* An array mapping BFD reloc codes to SH PE relocs.  */
    482      1.1  christos static const struct shcoff_reloc_map sh_reloc_map[] =
    483      1.1  christos {
    484      1.1  christos   { BFD_RELOC_32, R_SH_IMM32 },
    485      1.1  christos   { BFD_RELOC_CTOR, R_SH_IMM32 },
    486      1.1  christos };
    487      1.1  christos #endif
    488      1.1  christos 
    489      1.1  christos /* Given a BFD reloc code, return the howto structure for the
    490      1.1  christos    corresponding SH PE reloc.  */
    491      1.1  christos #define coff_bfd_reloc_type_lookup	sh_coff_reloc_type_lookup
    492      1.1  christos #define coff_bfd_reloc_name_lookup sh_coff_reloc_name_lookup
    493      1.1  christos 
    494      1.1  christos static reloc_howto_type *
    495  1.1.1.2  christos sh_coff_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
    496  1.1.1.2  christos 			   bfd_reloc_code_real_type code)
    497      1.1  christos {
    498      1.1  christos   unsigned int i;
    499      1.1  christos 
    500      1.1  christos   for (i = ARRAY_SIZE (sh_reloc_map); i--;)
    501      1.1  christos     if (sh_reloc_map[i].bfd_reloc_val == code)
    502      1.1  christos       return &sh_coff_howtos[(int) sh_reloc_map[i].shcoff_reloc_val];
    503      1.1  christos 
    504      1.1  christos   (*_bfd_error_handler) (_("SH Error: unknown reloc type %d"), code);
    505      1.1  christos   return NULL;
    506      1.1  christos }
    507      1.1  christos 
    508      1.1  christos static reloc_howto_type *
    509      1.1  christos sh_coff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
    510      1.1  christos 			   const char *r_name)
    511      1.1  christos {
    512      1.1  christos   unsigned int i;
    513      1.1  christos 
    514      1.1  christos   for (i = 0; i < sizeof (sh_coff_howtos) / sizeof (sh_coff_howtos[0]); i++)
    515      1.1  christos     if (sh_coff_howtos[i].name != NULL
    516      1.1  christos 	&& strcasecmp (sh_coff_howtos[i].name, r_name) == 0)
    517      1.1  christos       return &sh_coff_howtos[i];
    518      1.1  christos 
    519      1.1  christos   return NULL;
    520      1.1  christos }
    521      1.1  christos 
    522      1.1  christos /* This macro is used in coffcode.h to get the howto corresponding to
    523      1.1  christos    an internal reloc.  */
    524      1.1  christos 
    525      1.1  christos #define RTYPE2HOWTO(relent, internal)		\
    526      1.1  christos   ((relent)->howto =				\
    527      1.1  christos    ((internal)->r_type < SH_COFF_HOWTO_COUNT	\
    528      1.1  christos     ? &sh_coff_howtos[(internal)->r_type]	\
    529      1.1  christos     : (reloc_howto_type *) NULL))
    530      1.1  christos 
    531      1.1  christos /* This is the same as the macro in coffcode.h, except that it copies
    532      1.1  christos    r_offset into reloc_entry->addend for some relocs.  */
    533  1.1.1.3  christos #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr)		\
    534  1.1.1.3  christos   {								\
    535  1.1.1.3  christos     coff_symbol_type *coffsym = (coff_symbol_type *) NULL;	\
    536  1.1.1.3  christos     if (ptr && bfd_asymbol_bfd (ptr) != abfd)			\
    537  1.1.1.3  christos       coffsym = (obj_symbols (abfd)				\
    538  1.1.1.3  christos 		 + (cache_ptr->sym_ptr_ptr - symbols));		\
    539  1.1.1.3  christos     else if (ptr)						\
    540  1.1.1.3  christos       coffsym = coff_symbol_from (ptr);				\
    541  1.1.1.3  christos     if (coffsym != (coff_symbol_type *) NULL			\
    542  1.1.1.3  christos 	&& coffsym->native->u.syment.n_scnum == 0)		\
    543  1.1.1.3  christos       cache_ptr->addend = 0;					\
    544  1.1.1.3  christos     else if (ptr && bfd_asymbol_bfd (ptr) == abfd		\
    545  1.1.1.3  christos 	     && ptr->section != (asection *) NULL)		\
    546  1.1.1.3  christos       cache_ptr->addend = - (ptr->section->vma + ptr->value);	\
    547  1.1.1.3  christos     else							\
    548  1.1.1.3  christos       cache_ptr->addend = 0;					\
    549      1.1  christos     if ((reloc).r_type == R_SH_SWITCH8				\
    550      1.1  christos 	|| (reloc).r_type == R_SH_SWITCH16			\
    551      1.1  christos 	|| (reloc).r_type == R_SH_SWITCH32			\
    552      1.1  christos 	|| (reloc).r_type == R_SH_USES				\
    553      1.1  christos 	|| (reloc).r_type == R_SH_COUNT				\
    554      1.1  christos 	|| (reloc).r_type == R_SH_ALIGN)			\
    555      1.1  christos       cache_ptr->addend = (reloc).r_offset;			\
    556      1.1  christos   }
    557      1.1  christos 
    558      1.1  christos /* This is the howto function for the SH relocations.  */
    559      1.1  christos 
    560      1.1  christos static bfd_reloc_status_type
    561  1.1.1.2  christos sh_reloc (bfd *      abfd,
    562  1.1.1.2  christos 	  arelent *  reloc_entry,
    563  1.1.1.2  christos 	  asymbol *  symbol_in,
    564  1.1.1.2  christos 	  void *     data,
    565  1.1.1.2  christos 	  asection * input_section,
    566  1.1.1.2  christos 	  bfd *      output_bfd,
    567  1.1.1.2  christos 	  char **    error_message ATTRIBUTE_UNUSED)
    568      1.1  christos {
    569      1.1  christos   unsigned long insn;
    570      1.1  christos   bfd_vma sym_value;
    571      1.1  christos   unsigned short r_type;
    572      1.1  christos   bfd_vma addr = reloc_entry->address;
    573      1.1  christos   bfd_byte *hit_data = addr + (bfd_byte *) data;
    574      1.1  christos 
    575      1.1  christos   r_type = reloc_entry->howto->type;
    576      1.1  christos 
    577      1.1  christos   if (output_bfd != NULL)
    578      1.1  christos     {
    579      1.1  christos       /* Partial linking--do nothing.  */
    580      1.1  christos       reloc_entry->address += input_section->output_offset;
    581      1.1  christos       return bfd_reloc_ok;
    582      1.1  christos     }
    583      1.1  christos 
    584      1.1  christos   /* Almost all relocs have to do with relaxing.  If any work must be
    585      1.1  christos      done for them, it has been done in sh_relax_section.  */
    586      1.1  christos   if (r_type != R_SH_IMM32
    587      1.1  christos #ifdef COFF_WITH_PE
    588      1.1  christos       && r_type != R_SH_IMM32CE
    589      1.1  christos       && r_type != R_SH_IMAGEBASE
    590      1.1  christos #endif
    591      1.1  christos       && (r_type != R_SH_PCDISP
    592      1.1  christos 	  || (symbol_in->flags & BSF_LOCAL) != 0))
    593      1.1  christos     return bfd_reloc_ok;
    594      1.1  christos 
    595      1.1  christos   if (symbol_in != NULL
    596      1.1  christos       && bfd_is_und_section (symbol_in->section))
    597      1.1  christos     return bfd_reloc_undefined;
    598      1.1  christos 
    599      1.1  christos   sym_value = get_symbol_value (symbol_in);
    600      1.1  christos 
    601      1.1  christos   switch (r_type)
    602      1.1  christos     {
    603      1.1  christos     case R_SH_IMM32:
    604      1.1  christos #ifdef COFF_WITH_PE
    605      1.1  christos     case R_SH_IMM32CE:
    606      1.1  christos #endif
    607      1.1  christos       insn = bfd_get_32 (abfd, hit_data);
    608      1.1  christos       insn += sym_value + reloc_entry->addend;
    609      1.1  christos       bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
    610      1.1  christos       break;
    611      1.1  christos #ifdef COFF_WITH_PE
    612      1.1  christos     case R_SH_IMAGEBASE:
    613      1.1  christos       insn = bfd_get_32 (abfd, hit_data);
    614      1.1  christos       insn += sym_value + reloc_entry->addend;
    615      1.1  christos       insn -= pe_data (input_section->output_section->owner)->pe_opthdr.ImageBase;
    616      1.1  christos       bfd_put_32 (abfd, (bfd_vma) insn, hit_data);
    617      1.1  christos       break;
    618      1.1  christos #endif
    619      1.1  christos     case R_SH_PCDISP:
    620      1.1  christos       insn = bfd_get_16 (abfd, hit_data);
    621      1.1  christos       sym_value += reloc_entry->addend;
    622      1.1  christos       sym_value -= (input_section->output_section->vma
    623      1.1  christos 		    + input_section->output_offset
    624      1.1  christos 		    + addr
    625      1.1  christos 		    + 4);
    626      1.1  christos       sym_value += (insn & 0xfff) << 1;
    627      1.1  christos       if (insn & 0x800)
    628      1.1  christos 	sym_value -= 0x1000;
    629      1.1  christos       insn = (insn & 0xf000) | (sym_value & 0xfff);
    630      1.1  christos       bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
    631      1.1  christos       if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
    632      1.1  christos 	return bfd_reloc_overflow;
    633      1.1  christos       break;
    634      1.1  christos     default:
    635      1.1  christos       abort ();
    636      1.1  christos       break;
    637      1.1  christos     }
    638      1.1  christos 
    639      1.1  christos   return bfd_reloc_ok;
    640      1.1  christos }
    641      1.1  christos 
    642      1.1  christos #define coff_bfd_merge_private_bfd_data _bfd_generic_verify_endian_match
    643      1.1  christos 
    644      1.1  christos /* We can do relaxing.  */
    645      1.1  christos #define coff_bfd_relax_section sh_relax_section
    646      1.1  christos 
    647      1.1  christos /* We use the special COFF backend linker.  */
    648      1.1  christos #define coff_relocate_section sh_relocate_section
    649      1.1  christos 
    650      1.1  christos /* When relaxing, we need to use special code to get the relocated
    651      1.1  christos    section contents.  */
    652      1.1  christos #define coff_bfd_get_relocated_section_contents \
    653      1.1  christos   sh_coff_get_relocated_section_contents
    654      1.1  christos 
    655      1.1  christos #include "coffcode.h"
    656      1.1  christos 
    657  1.1.1.2  christos static bfd_boolean
    659  1.1.1.2  christos sh_relax_delete_bytes (bfd *, asection *, bfd_vma, int);
    660      1.1  christos 
    661      1.1  christos /* This function handles relaxing on the SH.
    662      1.1  christos 
    663      1.1  christos    Function calls on the SH look like this:
    664      1.1  christos 
    665      1.1  christos        movl  L1,r0
    666      1.1  christos        ...
    667      1.1  christos        jsr   @r0
    668      1.1  christos        ...
    669      1.1  christos      L1:
    670      1.1  christos        .long function
    671      1.1  christos 
    672      1.1  christos    The compiler and assembler will cooperate to create R_SH_USES
    673      1.1  christos    relocs on the jsr instructions.  The r_offset field of the
    674      1.1  christos    R_SH_USES reloc is the PC relative offset to the instruction which
    675      1.1  christos    loads the register (the r_offset field is computed as though it
    676      1.1  christos    were a jump instruction, so the offset value is actually from four
    677      1.1  christos    bytes past the instruction).  The linker can use this reloc to
    678      1.1  christos    determine just which function is being called, and thus decide
    679      1.1  christos    whether it is possible to replace the jsr with a bsr.
    680      1.1  christos 
    681      1.1  christos    If multiple function calls are all based on a single register load
    682      1.1  christos    (i.e., the same function is called multiple times), the compiler
    683      1.1  christos    guarantees that each function call will have an R_SH_USES reloc.
    684      1.1  christos    Therefore, if the linker is able to convert each R_SH_USES reloc
    685      1.1  christos    which refers to that address, it can safely eliminate the register
    686      1.1  christos    load.
    687      1.1  christos 
    688      1.1  christos    When the assembler creates an R_SH_USES reloc, it examines it to
    689      1.1  christos    determine which address is being loaded (L1 in the above example).
    690      1.1  christos    It then counts the number of references to that address, and
    691      1.1  christos    creates an R_SH_COUNT reloc at that address.  The r_offset field of
    692      1.1  christos    the R_SH_COUNT reloc will be the number of references.  If the
    693      1.1  christos    linker is able to eliminate a register load, it can use the
    694      1.1  christos    R_SH_COUNT reloc to see whether it can also eliminate the function
    695      1.1  christos    address.
    696      1.1  christos 
    697      1.1  christos    SH relaxing also handles another, unrelated, matter.  On the SH, if
    698      1.1  christos    a load or store instruction is not aligned on a four byte boundary,
    699      1.1  christos    the memory cycle interferes with the 32 bit instruction fetch,
    700      1.1  christos    causing a one cycle bubble in the pipeline.  Therefore, we try to
    701      1.1  christos    align load and store instructions on four byte boundaries if we
    702      1.1  christos    can, by swapping them with one of the adjacent instructions.  */
    703      1.1  christos 
    704  1.1.1.2  christos static bfd_boolean
    705  1.1.1.2  christos sh_relax_section (bfd *abfd,
    706  1.1.1.2  christos 		  asection *sec,
    707  1.1.1.2  christos 		  struct bfd_link_info *link_info,
    708      1.1  christos 		  bfd_boolean *again)
    709      1.1  christos {
    710      1.1  christos   struct internal_reloc *internal_relocs;
    711      1.1  christos   bfd_boolean have_code;
    712      1.1  christos   struct internal_reloc *irel, *irelend;
    713      1.1  christos   bfd_byte *contents = NULL;
    714      1.1  christos 
    715      1.1  christos   *again = FALSE;
    716      1.1  christos 
    717      1.1  christos   if (link_info->relocatable
    718      1.1  christos       || (sec->flags & SEC_RELOC) == 0
    719      1.1  christos       || sec->reloc_count == 0)
    720      1.1  christos     return TRUE;
    721      1.1  christos 
    722      1.1  christos   if (coff_section_data (abfd, sec) == NULL)
    723      1.1  christos     {
    724  1.1.1.2  christos       bfd_size_type amt = sizeof (struct coff_section_tdata);
    725      1.1  christos       sec->used_by_bfd = bfd_zalloc (abfd, amt);
    726      1.1  christos       if (sec->used_by_bfd == NULL)
    727      1.1  christos 	return FALSE;
    728      1.1  christos     }
    729      1.1  christos 
    730      1.1  christos   internal_relocs = (_bfd_coff_read_internal_relocs
    731      1.1  christos 		     (abfd, sec, link_info->keep_memory,
    732      1.1  christos 		      (bfd_byte *) NULL, FALSE,
    733      1.1  christos 		      (struct internal_reloc *) NULL));
    734      1.1  christos   if (internal_relocs == NULL)
    735      1.1  christos     goto error_return;
    736      1.1  christos 
    737      1.1  christos   have_code = FALSE;
    738      1.1  christos 
    739      1.1  christos   irelend = internal_relocs + sec->reloc_count;
    740      1.1  christos   for (irel = internal_relocs; irel < irelend; irel++)
    741      1.1  christos     {
    742      1.1  christos       bfd_vma laddr, paddr, symval;
    743      1.1  christos       unsigned short insn;
    744      1.1  christos       struct internal_reloc *irelfn, *irelscan, *irelcount;
    745      1.1  christos       struct internal_syment sym;
    746      1.1  christos       bfd_signed_vma foff;
    747      1.1  christos 
    748      1.1  christos       if (irel->r_type == R_SH_CODE)
    749      1.1  christos 	have_code = TRUE;
    750      1.1  christos 
    751      1.1  christos       if (irel->r_type != R_SH_USES)
    752      1.1  christos 	continue;
    753      1.1  christos 
    754      1.1  christos       /* Get the section contents.  */
    755      1.1  christos       if (contents == NULL)
    756      1.1  christos 	{
    757      1.1  christos 	  if (coff_section_data (abfd, sec)->contents != NULL)
    758      1.1  christos 	    contents = coff_section_data (abfd, sec)->contents;
    759      1.1  christos 	  else
    760      1.1  christos 	    {
    761      1.1  christos 	      if (!bfd_malloc_and_get_section (abfd, sec, &contents))
    762      1.1  christos 		goto error_return;
    763      1.1  christos 	    }
    764      1.1  christos 	}
    765      1.1  christos 
    766      1.1  christos       /* The r_offset field of the R_SH_USES reloc will point us to
    767      1.1  christos          the register load.  The 4 is because the r_offset field is
    768      1.1  christos          computed as though it were a jump offset, which are based
    769      1.1  christos          from 4 bytes after the jump instruction.  */
    770      1.1  christos       laddr = irel->r_vaddr - sec->vma + 4;
    771      1.1  christos       /* Careful to sign extend the 32-bit offset.  */
    772      1.1  christos       laddr += ((irel->r_offset & 0xffffffff) ^ 0x80000000) - 0x80000000;
    773      1.1  christos       if (laddr >= sec->size)
    774      1.1  christos 	{
    775      1.1  christos 	  (*_bfd_error_handler) ("%B: 0x%lx: warning: bad R_SH_USES offset",
    776      1.1  christos 				 abfd, (unsigned long) irel->r_vaddr);
    777      1.1  christos 	  continue;
    778      1.1  christos 	}
    779      1.1  christos       insn = bfd_get_16 (abfd, contents + laddr);
    780      1.1  christos 
    781      1.1  christos       /* If the instruction is not mov.l NN,rN, we don't know what to do.  */
    782      1.1  christos       if ((insn & 0xf000) != 0xd000)
    783      1.1  christos 	{
    784      1.1  christos 	  ((*_bfd_error_handler)
    785      1.1  christos 	   ("%B: 0x%lx: warning: R_SH_USES points to unrecognized insn 0x%x",
    786      1.1  christos 	    abfd, (unsigned long) irel->r_vaddr, insn));
    787      1.1  christos 	  continue;
    788      1.1  christos 	}
    789      1.1  christos 
    790      1.1  christos       /* Get the address from which the register is being loaded.  The
    791      1.1  christos       	 displacement in the mov.l instruction is quadrupled.  It is a
    792      1.1  christos       	 displacement from four bytes after the movl instruction, but,
    793      1.1  christos       	 before adding in the PC address, two least significant bits
    794      1.1  christos       	 of the PC are cleared.  We assume that the section is aligned
    795      1.1  christos       	 on a four byte boundary.  */
    796      1.1  christos       paddr = insn & 0xff;
    797      1.1  christos       paddr *= 4;
    798      1.1  christos       paddr += (laddr + 4) &~ (bfd_vma) 3;
    799      1.1  christos       if (paddr >= sec->size)
    800      1.1  christos 	{
    801      1.1  christos 	  ((*_bfd_error_handler)
    802      1.1  christos 	   ("%B: 0x%lx: warning: bad R_SH_USES load offset",
    803      1.1  christos 	    abfd, (unsigned long) irel->r_vaddr));
    804      1.1  christos 	  continue;
    805      1.1  christos 	}
    806      1.1  christos 
    807      1.1  christos       /* Get the reloc for the address from which the register is
    808      1.1  christos          being loaded.  This reloc will tell us which function is
    809      1.1  christos          actually being called.  */
    810      1.1  christos       paddr += sec->vma;
    811      1.1  christos       for (irelfn = internal_relocs; irelfn < irelend; irelfn++)
    812      1.1  christos 	if (irelfn->r_vaddr == paddr
    813      1.1  christos #ifdef COFF_WITH_PE
    814      1.1  christos 	    && (irelfn->r_type == R_SH_IMM32
    815      1.1  christos 		|| irelfn->r_type == R_SH_IMM32CE
    816      1.1  christos 		|| irelfn->r_type == R_SH_IMAGEBASE)
    817      1.1  christos 
    818      1.1  christos #else
    819      1.1  christos 	    && irelfn->r_type == R_SH_IMM32
    820      1.1  christos #endif
    821      1.1  christos 	    )
    822      1.1  christos 	  break;
    823      1.1  christos       if (irelfn >= irelend)
    824      1.1  christos 	{
    825      1.1  christos 	  ((*_bfd_error_handler)
    826      1.1  christos 	   ("%B: 0x%lx: warning: could not find expected reloc",
    827      1.1  christos 	    abfd, (unsigned long) paddr));
    828      1.1  christos 	  continue;
    829      1.1  christos 	}
    830      1.1  christos 
    831      1.1  christos       /* Get the value of the symbol referred to by the reloc.  */
    832      1.1  christos       if (! _bfd_coff_get_external_symbols (abfd))
    833      1.1  christos 	goto error_return;
    834      1.1  christos       bfd_coff_swap_sym_in (abfd,
    835      1.1  christos 			    ((bfd_byte *) obj_coff_external_syms (abfd)
    836      1.1  christos 			     + (irelfn->r_symndx
    837      1.1  christos 				* bfd_coff_symesz (abfd))),
    838      1.1  christos 			    &sym);
    839      1.1  christos       if (sym.n_scnum != 0 && sym.n_scnum != sec->target_index)
    840      1.1  christos 	{
    841      1.1  christos 	  ((*_bfd_error_handler)
    842      1.1  christos 	   ("%B: 0x%lx: warning: symbol in unexpected section",
    843      1.1  christos 	    abfd, (unsigned long) paddr));
    844      1.1  christos 	  continue;
    845      1.1  christos 	}
    846      1.1  christos 
    847      1.1  christos       if (sym.n_sclass != C_EXT)
    848      1.1  christos 	{
    849      1.1  christos 	  symval = (sym.n_value
    850      1.1  christos 		    - sec->vma
    851      1.1  christos 		    + sec->output_section->vma
    852      1.1  christos 		    + sec->output_offset);
    853      1.1  christos 	}
    854      1.1  christos       else
    855      1.1  christos 	{
    856      1.1  christos 	  struct coff_link_hash_entry *h;
    857      1.1  christos 
    858      1.1  christos 	  h = obj_coff_sym_hashes (abfd)[irelfn->r_symndx];
    859      1.1  christos 	  BFD_ASSERT (h != NULL);
    860      1.1  christos 	  if (h->root.type != bfd_link_hash_defined
    861      1.1  christos 	      && h->root.type != bfd_link_hash_defweak)
    862      1.1  christos 	    {
    863      1.1  christos 	      /* This appears to be a reference to an undefined
    864      1.1  christos                  symbol.  Just ignore it--it will be caught by the
    865      1.1  christos                  regular reloc processing.  */
    866      1.1  christos 	      continue;
    867      1.1  christos 	    }
    868      1.1  christos 
    869      1.1  christos 	  symval = (h->root.u.def.value
    870      1.1  christos 		    + h->root.u.def.section->output_section->vma
    871      1.1  christos 		    + h->root.u.def.section->output_offset);
    872      1.1  christos 	}
    873      1.1  christos 
    874      1.1  christos       symval += bfd_get_32 (abfd, contents + paddr - sec->vma);
    875      1.1  christos 
    876      1.1  christos       /* See if this function call can be shortened.  */
    877      1.1  christos       foff = (symval
    878      1.1  christos 	      - (irel->r_vaddr
    879      1.1  christos 		 - sec->vma
    880      1.1  christos 		 + sec->output_section->vma
    881      1.1  christos 		 + sec->output_offset
    882      1.1  christos 		 + 4));
    883      1.1  christos       if (foff < -0x1000 || foff >= 0x1000)
    884      1.1  christos 	{
    885      1.1  christos 	  /* After all that work, we can't shorten this function call.  */
    886      1.1  christos 	  continue;
    887      1.1  christos 	}
    888      1.1  christos 
    889      1.1  christos       /* Shorten the function call.  */
    890      1.1  christos 
    891      1.1  christos       /* For simplicity of coding, we are going to modify the section
    892      1.1  christos 	 contents, the section relocs, and the BFD symbol table.  We
    893      1.1  christos 	 must tell the rest of the code not to free up this
    894      1.1  christos 	 information.  It would be possible to instead create a table
    895      1.1  christos 	 of changes which have to be made, as is done in coff-mips.c;
    896      1.1  christos 	 that would be more work, but would require less memory when
    897      1.1  christos 	 the linker is run.  */
    898      1.1  christos 
    899      1.1  christos       coff_section_data (abfd, sec)->relocs = internal_relocs;
    900      1.1  christos       coff_section_data (abfd, sec)->keep_relocs = TRUE;
    901      1.1  christos 
    902      1.1  christos       coff_section_data (abfd, sec)->contents = contents;
    903      1.1  christos       coff_section_data (abfd, sec)->keep_contents = TRUE;
    904      1.1  christos 
    905      1.1  christos       obj_coff_keep_syms (abfd) = TRUE;
    906      1.1  christos 
    907      1.1  christos       /* Replace the jsr with a bsr.  */
    908      1.1  christos 
    909      1.1  christos       /* Change the R_SH_USES reloc into an R_SH_PCDISP reloc, and
    910      1.1  christos          replace the jsr with a bsr.  */
    911      1.1  christos       irel->r_type = R_SH_PCDISP;
    912      1.1  christos       irel->r_symndx = irelfn->r_symndx;
    913      1.1  christos       if (sym.n_sclass != C_EXT)
    914      1.1  christos 	{
    915      1.1  christos 	  /* If this needs to be changed because of future relaxing,
    916      1.1  christos              it will be handled here like other internal PCDISP
    917      1.1  christos              relocs.  */
    918      1.1  christos 	  bfd_put_16 (abfd,
    919      1.1  christos 		      (bfd_vma) 0xb000 | ((foff >> 1) & 0xfff),
    920      1.1  christos 		      contents + irel->r_vaddr - sec->vma);
    921      1.1  christos 	}
    922      1.1  christos       else
    923      1.1  christos 	{
    924      1.1  christos 	  /* We can't fully resolve this yet, because the external
    925      1.1  christos              symbol value may be changed by future relaxing.  We let
    926      1.1  christos              the final link phase handle it.  */
    927      1.1  christos 	  bfd_put_16 (abfd, (bfd_vma) 0xb000,
    928      1.1  christos 		      contents + irel->r_vaddr - sec->vma);
    929      1.1  christos 	}
    930      1.1  christos 
    931      1.1  christos       /* See if there is another R_SH_USES reloc referring to the same
    932      1.1  christos          register load.  */
    933      1.1  christos       for (irelscan = internal_relocs; irelscan < irelend; irelscan++)
    934      1.1  christos 	if (irelscan->r_type == R_SH_USES
    935      1.1  christos 	    && laddr == irelscan->r_vaddr - sec->vma + 4 + irelscan->r_offset)
    936      1.1  christos 	  break;
    937      1.1  christos       if (irelscan < irelend)
    938      1.1  christos 	{
    939      1.1  christos 	  /* Some other function call depends upon this register load,
    940      1.1  christos 	     and we have not yet converted that function call.
    941      1.1  christos 	     Indeed, we may never be able to convert it.  There is
    942      1.1  christos 	     nothing else we can do at this point.  */
    943      1.1  christos 	  continue;
    944      1.1  christos 	}
    945      1.1  christos 
    946      1.1  christos       /* Look for a R_SH_COUNT reloc on the location where the
    947      1.1  christos          function address is stored.  Do this before deleting any
    948      1.1  christos          bytes, to avoid confusion about the address.  */
    949      1.1  christos       for (irelcount = internal_relocs; irelcount < irelend; irelcount++)
    950      1.1  christos 	if (irelcount->r_vaddr == paddr
    951      1.1  christos 	    && irelcount->r_type == R_SH_COUNT)
    952      1.1  christos 	  break;
    953      1.1  christos 
    954      1.1  christos       /* Delete the register load.  */
    955      1.1  christos       if (! sh_relax_delete_bytes (abfd, sec, laddr, 2))
    956      1.1  christos 	goto error_return;
    957      1.1  christos 
    958      1.1  christos       /* That will change things, so, just in case it permits some
    959      1.1  christos          other function call to come within range, we should relax
    960      1.1  christos          again.  Note that this is not required, and it may be slow.  */
    961      1.1  christos       *again = TRUE;
    962      1.1  christos 
    963      1.1  christos       /* Now check whether we got a COUNT reloc.  */
    964      1.1  christos       if (irelcount >= irelend)
    965      1.1  christos 	{
    966      1.1  christos 	  ((*_bfd_error_handler)
    967      1.1  christos 	   ("%B: 0x%lx: warning: could not find expected COUNT reloc",
    968      1.1  christos 	    abfd, (unsigned long) paddr));
    969      1.1  christos 	  continue;
    970      1.1  christos 	}
    971      1.1  christos 
    972      1.1  christos       /* The number of uses is stored in the r_offset field.  We've
    973      1.1  christos          just deleted one.  */
    974      1.1  christos       if (irelcount->r_offset == 0)
    975      1.1  christos 	{
    976      1.1  christos 	  ((*_bfd_error_handler) ("%B: 0x%lx: warning: bad count",
    977      1.1  christos 				  abfd, (unsigned long) paddr));
    978      1.1  christos 	  continue;
    979      1.1  christos 	}
    980      1.1  christos 
    981      1.1  christos       --irelcount->r_offset;
    982      1.1  christos 
    983      1.1  christos       /* If there are no more uses, we can delete the address.  Reload
    984      1.1  christos          the address from irelfn, in case it was changed by the
    985      1.1  christos          previous call to sh_relax_delete_bytes.  */
    986      1.1  christos       if (irelcount->r_offset == 0)
    987      1.1  christos 	{
    988      1.1  christos 	  if (! sh_relax_delete_bytes (abfd, sec,
    989      1.1  christos 				       irelfn->r_vaddr - sec->vma, 4))
    990      1.1  christos 	    goto error_return;
    991      1.1  christos 	}
    992      1.1  christos 
    993      1.1  christos       /* We've done all we can with that function call.  */
    994      1.1  christos     }
    995      1.1  christos 
    996      1.1  christos   /* Look for load and store instructions that we can align on four
    997      1.1  christos      byte boundaries.  */
    998      1.1  christos   if (have_code)
    999      1.1  christos     {
   1000      1.1  christos       bfd_boolean swapped;
   1001      1.1  christos 
   1002      1.1  christos       /* Get the section contents.  */
   1003      1.1  christos       if (contents == NULL)
   1004      1.1  christos 	{
   1005      1.1  christos 	  if (coff_section_data (abfd, sec)->contents != NULL)
   1006      1.1  christos 	    contents = coff_section_data (abfd, sec)->contents;
   1007      1.1  christos 	  else
   1008      1.1  christos 	    {
   1009      1.1  christos 	      if (!bfd_malloc_and_get_section (abfd, sec, &contents))
   1010      1.1  christos 		goto error_return;
   1011      1.1  christos 	    }
   1012      1.1  christos 	}
   1013      1.1  christos 
   1014      1.1  christos       if (! sh_align_loads (abfd, sec, internal_relocs, contents, &swapped))
   1015      1.1  christos 	goto error_return;
   1016      1.1  christos 
   1017      1.1  christos       if (swapped)
   1018      1.1  christos 	{
   1019      1.1  christos 	  coff_section_data (abfd, sec)->relocs = internal_relocs;
   1020      1.1  christos 	  coff_section_data (abfd, sec)->keep_relocs = TRUE;
   1021      1.1  christos 
   1022      1.1  christos 	  coff_section_data (abfd, sec)->contents = contents;
   1023      1.1  christos 	  coff_section_data (abfd, sec)->keep_contents = TRUE;
   1024      1.1  christos 
   1025      1.1  christos 	  obj_coff_keep_syms (abfd) = TRUE;
   1026      1.1  christos 	}
   1027      1.1  christos     }
   1028      1.1  christos 
   1029      1.1  christos   if (internal_relocs != NULL
   1030      1.1  christos       && internal_relocs != coff_section_data (abfd, sec)->relocs)
   1031      1.1  christos     {
   1032      1.1  christos       if (! link_info->keep_memory)
   1033      1.1  christos 	free (internal_relocs);
   1034      1.1  christos       else
   1035      1.1  christos 	coff_section_data (abfd, sec)->relocs = internal_relocs;
   1036      1.1  christos     }
   1037      1.1  christos 
   1038      1.1  christos   if (contents != NULL && contents != coff_section_data (abfd, sec)->contents)
   1039      1.1  christos     {
   1040      1.1  christos       if (! link_info->keep_memory)
   1041      1.1  christos 	free (contents);
   1042      1.1  christos       else
   1043      1.1  christos 	/* Cache the section contents for coff_link_input_bfd.  */
   1044      1.1  christos 	coff_section_data (abfd, sec)->contents = contents;
   1045      1.1  christos     }
   1046      1.1  christos 
   1047      1.1  christos   return TRUE;
   1048      1.1  christos 
   1049      1.1  christos  error_return:
   1050      1.1  christos   if (internal_relocs != NULL
   1051      1.1  christos       && internal_relocs != coff_section_data (abfd, sec)->relocs)
   1052      1.1  christos     free (internal_relocs);
   1053      1.1  christos   if (contents != NULL && contents != coff_section_data (abfd, sec)->contents)
   1054      1.1  christos     free (contents);
   1055      1.1  christos   return FALSE;
   1056      1.1  christos }
   1057      1.1  christos 
   1058      1.1  christos /* Delete some bytes from a section while relaxing.  */
   1059      1.1  christos 
   1060  1.1.1.2  christos static bfd_boolean
   1061  1.1.1.2  christos sh_relax_delete_bytes (bfd *abfd,
   1062  1.1.1.2  christos 		       asection *sec,
   1063  1.1.1.2  christos 		       bfd_vma addr,
   1064      1.1  christos 		       int count)
   1065      1.1  christos {
   1066      1.1  christos   bfd_byte *contents;
   1067      1.1  christos   struct internal_reloc *irel, *irelend;
   1068      1.1  christos   struct internal_reloc *irelalign;
   1069      1.1  christos   bfd_vma toaddr;
   1070      1.1  christos   bfd_byte *esym, *esymend;
   1071      1.1  christos   bfd_size_type symesz;
   1072      1.1  christos   struct coff_link_hash_entry **sym_hash;
   1073      1.1  christos   asection *o;
   1074      1.1  christos 
   1075      1.1  christos   contents = coff_section_data (abfd, sec)->contents;
   1076      1.1  christos 
   1077      1.1  christos   /* The deletion must stop at the next ALIGN reloc for an aligment
   1078      1.1  christos      power larger than the number of bytes we are deleting.  */
   1079      1.1  christos 
   1080      1.1  christos   irelalign = NULL;
   1081      1.1  christos   toaddr = sec->size;
   1082      1.1  christos 
   1083      1.1  christos   irel = coff_section_data (abfd, sec)->relocs;
   1084      1.1  christos   irelend = irel + sec->reloc_count;
   1085      1.1  christos   for (; irel < irelend; irel++)
   1086      1.1  christos     {
   1087      1.1  christos       if (irel->r_type == R_SH_ALIGN
   1088      1.1  christos 	  && irel->r_vaddr - sec->vma > addr
   1089      1.1  christos 	  && count < (1 << irel->r_offset))
   1090      1.1  christos 	{
   1091      1.1  christos 	  irelalign = irel;
   1092      1.1  christos 	  toaddr = irel->r_vaddr - sec->vma;
   1093      1.1  christos 	  break;
   1094      1.1  christos 	}
   1095      1.1  christos     }
   1096      1.1  christos 
   1097      1.1  christos   /* Actually delete the bytes.  */
   1098      1.1  christos   memmove (contents + addr, contents + addr + count,
   1099      1.1  christos 	   (size_t) (toaddr - addr - count));
   1100      1.1  christos   if (irelalign == NULL)
   1101      1.1  christos     sec->size -= count;
   1102      1.1  christos   else
   1103      1.1  christos     {
   1104      1.1  christos       int i;
   1105      1.1  christos 
   1106      1.1  christos #define NOP_OPCODE (0x0009)
   1107      1.1  christos 
   1108      1.1  christos       BFD_ASSERT ((count & 1) == 0);
   1109      1.1  christos       for (i = 0; i < count; i += 2)
   1110      1.1  christos 	bfd_put_16 (abfd, (bfd_vma) NOP_OPCODE, contents + toaddr - count + i);
   1111      1.1  christos     }
   1112      1.1  christos 
   1113      1.1  christos   /* Adjust all the relocs.  */
   1114      1.1  christos   for (irel = coff_section_data (abfd, sec)->relocs; irel < irelend; irel++)
   1115      1.1  christos     {
   1116      1.1  christos       bfd_vma nraddr, stop;
   1117      1.1  christos       bfd_vma start = 0;
   1118      1.1  christos       int insn = 0;
   1119      1.1  christos       struct internal_syment sym;
   1120      1.1  christos       int off, adjust, oinsn;
   1121      1.1  christos       bfd_signed_vma voff = 0;
   1122      1.1  christos       bfd_boolean overflow;
   1123      1.1  christos 
   1124      1.1  christos       /* Get the new reloc address.  */
   1125      1.1  christos       nraddr = irel->r_vaddr - sec->vma;
   1126      1.1  christos       if ((irel->r_vaddr - sec->vma > addr
   1127      1.1  christos 	   && irel->r_vaddr - sec->vma < toaddr)
   1128      1.1  christos 	  || (irel->r_type == R_SH_ALIGN
   1129      1.1  christos 	      && irel->r_vaddr - sec->vma == toaddr))
   1130      1.1  christos 	nraddr -= count;
   1131      1.1  christos 
   1132      1.1  christos       /* See if this reloc was for the bytes we have deleted, in which
   1133      1.1  christos 	 case we no longer care about it.  Don't delete relocs which
   1134      1.1  christos 	 represent addresses, though.  */
   1135      1.1  christos       if (irel->r_vaddr - sec->vma >= addr
   1136      1.1  christos 	  && irel->r_vaddr - sec->vma < addr + count
   1137      1.1  christos 	  && irel->r_type != R_SH_ALIGN
   1138      1.1  christos 	  && irel->r_type != R_SH_CODE
   1139      1.1  christos 	  && irel->r_type != R_SH_DATA
   1140      1.1  christos 	  && irel->r_type != R_SH_LABEL)
   1141      1.1  christos 	irel->r_type = R_SH_UNUSED;
   1142      1.1  christos 
   1143      1.1  christos       /* If this is a PC relative reloc, see if the range it covers
   1144      1.1  christos          includes the bytes we have deleted.  */
   1145      1.1  christos       switch (irel->r_type)
   1146      1.1  christos 	{
   1147      1.1  christos 	default:
   1148      1.1  christos 	  break;
   1149      1.1  christos 
   1150      1.1  christos 	case R_SH_PCDISP8BY2:
   1151      1.1  christos 	case R_SH_PCDISP:
   1152      1.1  christos 	case R_SH_PCRELIMM8BY2:
   1153      1.1  christos 	case R_SH_PCRELIMM8BY4:
   1154      1.1  christos 	  start = irel->r_vaddr - sec->vma;
   1155      1.1  christos 	  insn = bfd_get_16 (abfd, contents + nraddr);
   1156      1.1  christos 	  break;
   1157      1.1  christos 	}
   1158      1.1  christos 
   1159      1.1  christos       switch (irel->r_type)
   1160      1.1  christos 	{
   1161      1.1  christos 	default:
   1162      1.1  christos 	  start = stop = addr;
   1163      1.1  christos 	  break;
   1164      1.1  christos 
   1165      1.1  christos 	case R_SH_IMM32:
   1166      1.1  christos #ifdef COFF_WITH_PE
   1167      1.1  christos 	case R_SH_IMM32CE:
   1168      1.1  christos 	case R_SH_IMAGEBASE:
   1169      1.1  christos #endif
   1170      1.1  christos 	  /* If this reloc is against a symbol defined in this
   1171      1.1  christos              section, and the symbol will not be adjusted below, we
   1172      1.1  christos              must check the addend to see it will put the value in
   1173      1.1  christos              range to be adjusted, and hence must be changed.  */
   1174      1.1  christos 	  bfd_coff_swap_sym_in (abfd,
   1175      1.1  christos 				((bfd_byte *) obj_coff_external_syms (abfd)
   1176      1.1  christos 				 + (irel->r_symndx
   1177      1.1  christos 				    * bfd_coff_symesz (abfd))),
   1178      1.1  christos 				&sym);
   1179      1.1  christos 	  if (sym.n_sclass != C_EXT
   1180      1.1  christos 	      && sym.n_scnum == sec->target_index
   1181      1.1  christos 	      && ((bfd_vma) sym.n_value <= addr
   1182      1.1  christos 		  || (bfd_vma) sym.n_value >= toaddr))
   1183      1.1  christos 	    {
   1184      1.1  christos 	      bfd_vma val;
   1185      1.1  christos 
   1186      1.1  christos 	      val = bfd_get_32 (abfd, contents + nraddr);
   1187      1.1  christos 	      val += sym.n_value;
   1188      1.1  christos 	      if (val > addr && val < toaddr)
   1189      1.1  christos 		bfd_put_32 (abfd, val - count, contents + nraddr);
   1190      1.1  christos 	    }
   1191      1.1  christos 	  start = stop = addr;
   1192      1.1  christos 	  break;
   1193      1.1  christos 
   1194      1.1  christos 	case R_SH_PCDISP8BY2:
   1195      1.1  christos 	  off = insn & 0xff;
   1196      1.1  christos 	  if (off & 0x80)
   1197      1.1  christos 	    off -= 0x100;
   1198      1.1  christos 	  stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
   1199      1.1  christos 	  break;
   1200      1.1  christos 
   1201      1.1  christos 	case R_SH_PCDISP:
   1202      1.1  christos 	  bfd_coff_swap_sym_in (abfd,
   1203      1.1  christos 				((bfd_byte *) obj_coff_external_syms (abfd)
   1204      1.1  christos 				 + (irel->r_symndx
   1205      1.1  christos 				    * bfd_coff_symesz (abfd))),
   1206      1.1  christos 				&sym);
   1207      1.1  christos 	  if (sym.n_sclass == C_EXT)
   1208      1.1  christos 	    start = stop = addr;
   1209      1.1  christos 	  else
   1210      1.1  christos 	    {
   1211      1.1  christos 	      off = insn & 0xfff;
   1212      1.1  christos 	      if (off & 0x800)
   1213      1.1  christos 		off -= 0x1000;
   1214      1.1  christos 	      stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
   1215      1.1  christos 	    }
   1216      1.1  christos 	  break;
   1217      1.1  christos 
   1218      1.1  christos 	case R_SH_PCRELIMM8BY2:
   1219      1.1  christos 	  off = insn & 0xff;
   1220      1.1  christos 	  stop = start + 4 + off * 2;
   1221      1.1  christos 	  break;
   1222      1.1  christos 
   1223      1.1  christos 	case R_SH_PCRELIMM8BY4:
   1224      1.1  christos 	  off = insn & 0xff;
   1225      1.1  christos 	  stop = (start &~ (bfd_vma) 3) + 4 + off * 4;
   1226      1.1  christos 	  break;
   1227      1.1  christos 
   1228      1.1  christos 	case R_SH_SWITCH8:
   1229      1.1  christos 	case R_SH_SWITCH16:
   1230      1.1  christos 	case R_SH_SWITCH32:
   1231      1.1  christos 	  /* These relocs types represent
   1232      1.1  christos 	       .word L2-L1
   1233      1.1  christos 	     The r_offset field holds the difference between the reloc
   1234      1.1  christos 	     address and L1.  That is the start of the reloc, and
   1235      1.1  christos 	     adding in the contents gives us the top.  We must adjust
   1236      1.1  christos 	     both the r_offset field and the section contents.  */
   1237      1.1  christos 
   1238      1.1  christos 	  start = irel->r_vaddr - sec->vma;
   1239      1.1  christos 	  stop = (bfd_vma) ((bfd_signed_vma) start - (long) irel->r_offset);
   1240      1.1  christos 
   1241      1.1  christos 	  if (start > addr
   1242      1.1  christos 	      && start < toaddr
   1243      1.1  christos 	      && (stop <= addr || stop >= toaddr))
   1244      1.1  christos 	    irel->r_offset += count;
   1245      1.1  christos 	  else if (stop > addr
   1246      1.1  christos 		   && stop < toaddr
   1247      1.1  christos 		   && (start <= addr || start >= toaddr))
   1248      1.1  christos 	    irel->r_offset -= count;
   1249      1.1  christos 
   1250      1.1  christos 	  start = stop;
   1251      1.1  christos 
   1252      1.1  christos 	  if (irel->r_type == R_SH_SWITCH16)
   1253      1.1  christos 	    voff = bfd_get_signed_16 (abfd, contents + nraddr);
   1254      1.1  christos 	  else if (irel->r_type == R_SH_SWITCH8)
   1255      1.1  christos 	    voff = bfd_get_8 (abfd, contents + nraddr);
   1256      1.1  christos 	  else
   1257      1.1  christos 	    voff = bfd_get_signed_32 (abfd, contents + nraddr);
   1258      1.1  christos 	  stop = (bfd_vma) ((bfd_signed_vma) start + voff);
   1259      1.1  christos 
   1260      1.1  christos 	  break;
   1261      1.1  christos 
   1262      1.1  christos 	case R_SH_USES:
   1263      1.1  christos 	  start = irel->r_vaddr - sec->vma;
   1264      1.1  christos 	  stop = (bfd_vma) ((bfd_signed_vma) start
   1265      1.1  christos 			    + (long) irel->r_offset
   1266      1.1  christos 			    + 4);
   1267      1.1  christos 	  break;
   1268      1.1  christos 	}
   1269      1.1  christos 
   1270      1.1  christos       if (start > addr
   1271      1.1  christos 	  && start < toaddr
   1272      1.1  christos 	  && (stop <= addr || stop >= toaddr))
   1273      1.1  christos 	adjust = count;
   1274      1.1  christos       else if (stop > addr
   1275      1.1  christos 	       && stop < toaddr
   1276      1.1  christos 	       && (start <= addr || start >= toaddr))
   1277      1.1  christos 	adjust = - count;
   1278      1.1  christos       else
   1279      1.1  christos 	adjust = 0;
   1280      1.1  christos 
   1281      1.1  christos       if (adjust != 0)
   1282      1.1  christos 	{
   1283      1.1  christos 	  oinsn = insn;
   1284      1.1  christos 	  overflow = FALSE;
   1285      1.1  christos 	  switch (irel->r_type)
   1286      1.1  christos 	    {
   1287      1.1  christos 	    default:
   1288      1.1  christos 	      abort ();
   1289      1.1  christos 	      break;
   1290      1.1  christos 
   1291      1.1  christos 	    case R_SH_PCDISP8BY2:
   1292      1.1  christos 	    case R_SH_PCRELIMM8BY2:
   1293      1.1  christos 	      insn += adjust / 2;
   1294      1.1  christos 	      if ((oinsn & 0xff00) != (insn & 0xff00))
   1295      1.1  christos 		overflow = TRUE;
   1296      1.1  christos 	      bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
   1297      1.1  christos 	      break;
   1298      1.1  christos 
   1299      1.1  christos 	    case R_SH_PCDISP:
   1300      1.1  christos 	      insn += adjust / 2;
   1301      1.1  christos 	      if ((oinsn & 0xf000) != (insn & 0xf000))
   1302      1.1  christos 		overflow = TRUE;
   1303      1.1  christos 	      bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
   1304      1.1  christos 	      break;
   1305      1.1  christos 
   1306      1.1  christos 	    case R_SH_PCRELIMM8BY4:
   1307      1.1  christos 	      BFD_ASSERT (adjust == count || count >= 4);
   1308      1.1  christos 	      if (count >= 4)
   1309      1.1  christos 		insn += adjust / 4;
   1310      1.1  christos 	      else
   1311      1.1  christos 		{
   1312      1.1  christos 		  if ((irel->r_vaddr & 3) == 0)
   1313      1.1  christos 		    ++insn;
   1314      1.1  christos 		}
   1315      1.1  christos 	      if ((oinsn & 0xff00) != (insn & 0xff00))
   1316      1.1  christos 		overflow = TRUE;
   1317      1.1  christos 	      bfd_put_16 (abfd, (bfd_vma) insn, contents + nraddr);
   1318      1.1  christos 	      break;
   1319      1.1  christos 
   1320      1.1  christos 	    case R_SH_SWITCH8:
   1321      1.1  christos 	      voff += adjust;
   1322      1.1  christos 	      if (voff < 0 || voff >= 0xff)
   1323      1.1  christos 		overflow = TRUE;
   1324      1.1  christos 	      bfd_put_8 (abfd, (bfd_vma) voff, contents + nraddr);
   1325      1.1  christos 	      break;
   1326      1.1  christos 
   1327      1.1  christos 	    case R_SH_SWITCH16:
   1328      1.1  christos 	      voff += adjust;
   1329      1.1  christos 	      if (voff < - 0x8000 || voff >= 0x8000)
   1330      1.1  christos 		overflow = TRUE;
   1331      1.1  christos 	      bfd_put_signed_16 (abfd, (bfd_vma) voff, contents + nraddr);
   1332      1.1  christos 	      break;
   1333      1.1  christos 
   1334      1.1  christos 	    case R_SH_SWITCH32:
   1335      1.1  christos 	      voff += adjust;
   1336      1.1  christos 	      bfd_put_signed_32 (abfd, (bfd_vma) voff, contents + nraddr);
   1337      1.1  christos 	      break;
   1338      1.1  christos 
   1339      1.1  christos 	    case R_SH_USES:
   1340      1.1  christos 	      irel->r_offset += adjust;
   1341      1.1  christos 	      break;
   1342      1.1  christos 	    }
   1343      1.1  christos 
   1344      1.1  christos 	  if (overflow)
   1345      1.1  christos 	    {
   1346      1.1  christos 	      ((*_bfd_error_handler)
   1347      1.1  christos 	       ("%B: 0x%lx: fatal: reloc overflow while relaxing",
   1348      1.1  christos 		abfd, (unsigned long) irel->r_vaddr));
   1349      1.1  christos 	      bfd_set_error (bfd_error_bad_value);
   1350      1.1  christos 	      return FALSE;
   1351      1.1  christos 	    }
   1352      1.1  christos 	}
   1353      1.1  christos 
   1354      1.1  christos       irel->r_vaddr = nraddr + sec->vma;
   1355      1.1  christos     }
   1356      1.1  christos 
   1357      1.1  christos   /* Look through all the other sections.  If there contain any IMM32
   1358      1.1  christos      relocs against internal symbols which we are not going to adjust
   1359      1.1  christos      below, we may need to adjust the addends.  */
   1360      1.1  christos   for (o = abfd->sections; o != NULL; o = o->next)
   1361      1.1  christos     {
   1362      1.1  christos       struct internal_reloc *internal_relocs;
   1363      1.1  christos       struct internal_reloc *irelscan, *irelscanend;
   1364      1.1  christos       bfd_byte *ocontents;
   1365      1.1  christos 
   1366      1.1  christos       if (o == sec
   1367      1.1  christos 	  || (o->flags & SEC_RELOC) == 0
   1368      1.1  christos 	  || o->reloc_count == 0)
   1369      1.1  christos 	continue;
   1370      1.1  christos 
   1371      1.1  christos       /* We always cache the relocs.  Perhaps, if info->keep_memory is
   1372      1.1  christos          FALSE, we should free them, if we are permitted to, when we
   1373      1.1  christos          leave sh_coff_relax_section.  */
   1374      1.1  christos       internal_relocs = (_bfd_coff_read_internal_relocs
   1375      1.1  christos 			 (abfd, o, TRUE, (bfd_byte *) NULL, FALSE,
   1376      1.1  christos 			  (struct internal_reloc *) NULL));
   1377      1.1  christos       if (internal_relocs == NULL)
   1378      1.1  christos 	return FALSE;
   1379      1.1  christos 
   1380      1.1  christos       ocontents = NULL;
   1381      1.1  christos       irelscanend = internal_relocs + o->reloc_count;
   1382      1.1  christos       for (irelscan = internal_relocs; irelscan < irelscanend; irelscan++)
   1383      1.1  christos 	{
   1384      1.1  christos 	  struct internal_syment sym;
   1385      1.1  christos 
   1386      1.1  christos #ifdef COFF_WITH_PE
   1387      1.1  christos 	  if (irelscan->r_type != R_SH_IMM32
   1388      1.1  christos 	      && irelscan->r_type != R_SH_IMAGEBASE
   1389      1.1  christos 	      && irelscan->r_type != R_SH_IMM32CE)
   1390      1.1  christos #else
   1391      1.1  christos 	  if (irelscan->r_type != R_SH_IMM32)
   1392      1.1  christos #endif
   1393      1.1  christos 	    continue;
   1394      1.1  christos 
   1395      1.1  christos 	  bfd_coff_swap_sym_in (abfd,
   1396      1.1  christos 				((bfd_byte *) obj_coff_external_syms (abfd)
   1397      1.1  christos 				 + (irelscan->r_symndx
   1398      1.1  christos 				    * bfd_coff_symesz (abfd))),
   1399      1.1  christos 				&sym);
   1400      1.1  christos 	  if (sym.n_sclass != C_EXT
   1401      1.1  christos 	      && sym.n_scnum == sec->target_index
   1402      1.1  christos 	      && ((bfd_vma) sym.n_value <= addr
   1403      1.1  christos 		  || (bfd_vma) sym.n_value >= toaddr))
   1404      1.1  christos 	    {
   1405      1.1  christos 	      bfd_vma val;
   1406      1.1  christos 
   1407      1.1  christos 	      if (ocontents == NULL)
   1408      1.1  christos 		{
   1409      1.1  christos 		  if (coff_section_data (abfd, o)->contents != NULL)
   1410      1.1  christos 		    ocontents = coff_section_data (abfd, o)->contents;
   1411      1.1  christos 		  else
   1412      1.1  christos 		    {
   1413      1.1  christos 		      if (!bfd_malloc_and_get_section (abfd, o, &ocontents))
   1414      1.1  christos 			return FALSE;
   1415      1.1  christos 		      /* We always cache the section contents.
   1416      1.1  christos                          Perhaps, if info->keep_memory is FALSE, we
   1417      1.1  christos                          should free them, if we are permitted to,
   1418      1.1  christos                          when we leave sh_coff_relax_section.  */
   1419      1.1  christos 		      coff_section_data (abfd, o)->contents = ocontents;
   1420      1.1  christos 		    }
   1421      1.1  christos 		}
   1422      1.1  christos 
   1423      1.1  christos 	      val = bfd_get_32 (abfd, ocontents + irelscan->r_vaddr - o->vma);
   1424      1.1  christos 	      val += sym.n_value;
   1425      1.1  christos 	      if (val > addr && val < toaddr)
   1426      1.1  christos 		bfd_put_32 (abfd, val - count,
   1427      1.1  christos 			    ocontents + irelscan->r_vaddr - o->vma);
   1428      1.1  christos 
   1429      1.1  christos 	      coff_section_data (abfd, o)->keep_contents = TRUE;
   1430      1.1  christos 	    }
   1431      1.1  christos 	}
   1432      1.1  christos     }
   1433      1.1  christos 
   1434      1.1  christos   /* Adjusting the internal symbols will not work if something has
   1435      1.1  christos      already retrieved the generic symbols.  It would be possible to
   1436      1.1  christos      make this work by adjusting the generic symbols at the same time.
   1437      1.1  christos      However, this case should not arise in normal usage.  */
   1438      1.1  christos   if (obj_symbols (abfd) != NULL
   1439      1.1  christos       || obj_raw_syments (abfd) != NULL)
   1440      1.1  christos     {
   1441      1.1  christos       ((*_bfd_error_handler)
   1442      1.1  christos        ("%B: fatal: generic symbols retrieved before relaxing", abfd));
   1443      1.1  christos       bfd_set_error (bfd_error_invalid_operation);
   1444      1.1  christos       return FALSE;
   1445      1.1  christos     }
   1446      1.1  christos 
   1447      1.1  christos   /* Adjust all the symbols.  */
   1448      1.1  christos   sym_hash = obj_coff_sym_hashes (abfd);
   1449      1.1  christos   symesz = bfd_coff_symesz (abfd);
   1450      1.1  christos   esym = (bfd_byte *) obj_coff_external_syms (abfd);
   1451      1.1  christos   esymend = esym + obj_raw_syment_count (abfd) * symesz;
   1452      1.1  christos   while (esym < esymend)
   1453      1.1  christos     {
   1454      1.1  christos       struct internal_syment isym;
   1455  1.1.1.2  christos 
   1456      1.1  christos       bfd_coff_swap_sym_in (abfd, esym, &isym);
   1457      1.1  christos 
   1458      1.1  christos       if (isym.n_scnum == sec->target_index
   1459      1.1  christos 	  && (bfd_vma) isym.n_value > addr
   1460      1.1  christos 	  && (bfd_vma) isym.n_value < toaddr)
   1461      1.1  christos 	{
   1462      1.1  christos 	  isym.n_value -= count;
   1463  1.1.1.2  christos 
   1464      1.1  christos 	  bfd_coff_swap_sym_out (abfd, &isym, esym);
   1465      1.1  christos 
   1466      1.1  christos 	  if (*sym_hash != NULL)
   1467      1.1  christos 	    {
   1468      1.1  christos 	      BFD_ASSERT ((*sym_hash)->root.type == bfd_link_hash_defined
   1469      1.1  christos 			  || (*sym_hash)->root.type == bfd_link_hash_defweak);
   1470      1.1  christos 	      BFD_ASSERT ((*sym_hash)->root.u.def.value >= addr
   1471      1.1  christos 			  && (*sym_hash)->root.u.def.value < toaddr);
   1472      1.1  christos 	      (*sym_hash)->root.u.def.value -= count;
   1473      1.1  christos 	    }
   1474      1.1  christos 	}
   1475      1.1  christos 
   1476      1.1  christos       esym += (isym.n_numaux + 1) * symesz;
   1477      1.1  christos       sym_hash += isym.n_numaux + 1;
   1478      1.1  christos     }
   1479      1.1  christos 
   1480      1.1  christos   /* See if we can move the ALIGN reloc forward.  We have adjusted
   1481      1.1  christos      r_vaddr for it already.  */
   1482      1.1  christos   if (irelalign != NULL)
   1483      1.1  christos     {
   1484      1.1  christos       bfd_vma alignto, alignaddr;
   1485      1.1  christos 
   1486      1.1  christos       alignto = BFD_ALIGN (toaddr, 1 << irelalign->r_offset);
   1487      1.1  christos       alignaddr = BFD_ALIGN (irelalign->r_vaddr - sec->vma,
   1488      1.1  christos 			     1 << irelalign->r_offset);
   1489      1.1  christos       if (alignto != alignaddr)
   1490      1.1  christos 	{
   1491      1.1  christos 	  /* Tail recursion.  */
   1492      1.1  christos 	  return sh_relax_delete_bytes (abfd, sec, alignaddr,
   1493      1.1  christos 					(int) (alignto - alignaddr));
   1494      1.1  christos 	}
   1495      1.1  christos     }
   1496      1.1  christos 
   1497      1.1  christos   return TRUE;
   1498      1.1  christos }
   1499      1.1  christos 
   1500      1.1  christos /* This is yet another version of the SH opcode table, used to rapidly
   1502      1.1  christos    get information about a particular instruction.  */
   1503      1.1  christos 
   1504      1.1  christos /* The opcode map is represented by an array of these structures.  The
   1505      1.1  christos    array is indexed by the high order four bits in the instruction.  */
   1506      1.1  christos 
   1507      1.1  christos struct sh_major_opcode
   1508      1.1  christos {
   1509      1.1  christos   /* A pointer to the instruction list.  This is an array which
   1510      1.1  christos      contains all the instructions with this major opcode.  */
   1511      1.1  christos   const struct sh_minor_opcode *minor_opcodes;
   1512      1.1  christos   /* The number of elements in minor_opcodes.  */
   1513      1.1  christos   unsigned short count;
   1514      1.1  christos };
   1515      1.1  christos 
   1516      1.1  christos /* This structure holds information for a set of SH opcodes.  The
   1517      1.1  christos    instruction code is anded with the mask value, and the resulting
   1518      1.1  christos    value is used to search the order opcode list.  */
   1519      1.1  christos 
   1520      1.1  christos struct sh_minor_opcode
   1521      1.1  christos {
   1522      1.1  christos   /* The sorted opcode list.  */
   1523      1.1  christos   const struct sh_opcode *opcodes;
   1524      1.1  christos   /* The number of elements in opcodes.  */
   1525      1.1  christos   unsigned short count;
   1526      1.1  christos   /* The mask value to use when searching the opcode list.  */
   1527      1.1  christos   unsigned short mask;
   1528      1.1  christos };
   1529      1.1  christos 
   1530      1.1  christos /* This structure holds information for an SH instruction.  An array
   1531      1.1  christos    of these structures is sorted in order by opcode.  */
   1532      1.1  christos 
   1533      1.1  christos struct sh_opcode
   1534      1.1  christos {
   1535      1.1  christos   /* The code for this instruction, after it has been anded with the
   1536      1.1  christos      mask value in the sh_major_opcode structure.  */
   1537      1.1  christos   unsigned short opcode;
   1538      1.1  christos   /* Flags for this instruction.  */
   1539      1.1  christos   unsigned long flags;
   1540      1.1  christos };
   1541      1.1  christos 
   1542      1.1  christos /* Flag which appear in the sh_opcode structure.  */
   1543      1.1  christos 
   1544      1.1  christos /* This instruction loads a value from memory.  */
   1545      1.1  christos #define LOAD (0x1)
   1546      1.1  christos 
   1547      1.1  christos /* This instruction stores a value to memory.  */
   1548      1.1  christos #define STORE (0x2)
   1549      1.1  christos 
   1550      1.1  christos /* This instruction is a branch.  */
   1551      1.1  christos #define BRANCH (0x4)
   1552      1.1  christos 
   1553      1.1  christos /* This instruction has a delay slot.  */
   1554      1.1  christos #define DELAY (0x8)
   1555      1.1  christos 
   1556      1.1  christos /* This instruction uses the value in the register in the field at
   1557      1.1  christos    mask 0x0f00 of the instruction.  */
   1558      1.1  christos #define USES1 (0x10)
   1559      1.1  christos #define USES1_REG(x) ((x & 0x0f00) >> 8)
   1560      1.1  christos 
   1561      1.1  christos /* This instruction uses the value in the register in the field at
   1562      1.1  christos    mask 0x00f0 of the instruction.  */
   1563      1.1  christos #define USES2 (0x20)
   1564      1.1  christos #define USES2_REG(x) ((x & 0x00f0) >> 4)
   1565      1.1  christos 
   1566      1.1  christos /* This instruction uses the value in register 0.  */
   1567      1.1  christos #define USESR0 (0x40)
   1568      1.1  christos 
   1569      1.1  christos /* This instruction sets the value in the register in the field at
   1570      1.1  christos    mask 0x0f00 of the instruction.  */
   1571      1.1  christos #define SETS1 (0x80)
   1572      1.1  christos #define SETS1_REG(x) ((x & 0x0f00) >> 8)
   1573      1.1  christos 
   1574      1.1  christos /* This instruction sets the value in the register in the field at
   1575      1.1  christos    mask 0x00f0 of the instruction.  */
   1576      1.1  christos #define SETS2 (0x100)
   1577      1.1  christos #define SETS2_REG(x) ((x & 0x00f0) >> 4)
   1578      1.1  christos 
   1579      1.1  christos /* This instruction sets register 0.  */
   1580      1.1  christos #define SETSR0 (0x200)
   1581      1.1  christos 
   1582      1.1  christos /* This instruction sets a special register.  */
   1583      1.1  christos #define SETSSP (0x400)
   1584      1.1  christos 
   1585      1.1  christos /* This instruction uses a special register.  */
   1586      1.1  christos #define USESSP (0x800)
   1587      1.1  christos 
   1588      1.1  christos /* This instruction uses the floating point register in the field at
   1589      1.1  christos    mask 0x0f00 of the instruction.  */
   1590      1.1  christos #define USESF1 (0x1000)
   1591      1.1  christos #define USESF1_REG(x) ((x & 0x0f00) >> 8)
   1592      1.1  christos 
   1593      1.1  christos /* This instruction uses the floating point register in the field at
   1594      1.1  christos    mask 0x00f0 of the instruction.  */
   1595      1.1  christos #define USESF2 (0x2000)
   1596      1.1  christos #define USESF2_REG(x) ((x & 0x00f0) >> 4)
   1597      1.1  christos 
   1598      1.1  christos /* This instruction uses floating point register 0.  */
   1599      1.1  christos #define USESF0 (0x4000)
   1600      1.1  christos 
   1601      1.1  christos /* This instruction sets the floating point register in the field at
   1602      1.1  christos    mask 0x0f00 of the instruction.  */
   1603      1.1  christos #define SETSF1 (0x8000)
   1604      1.1  christos #define SETSF1_REG(x) ((x & 0x0f00) >> 8)
   1605      1.1  christos 
   1606      1.1  christos #define USESAS (0x10000)
   1607      1.1  christos #define USESAS_REG(x) (((((x) >> 8) - 2) & 3) + 2)
   1608      1.1  christos #define USESR8 (0x20000)
   1609      1.1  christos #define SETSAS (0x40000)
   1610      1.1  christos #define SETSAS_REG(x) USESAS_REG (x)
   1611      1.1  christos 
   1612      1.1  christos #define MAP(a) a, sizeof a / sizeof a[0]
   1613      1.1  christos 
   1614      1.1  christos #ifndef COFF_IMAGE_WITH_PE
   1615      1.1  christos 
   1616      1.1  christos /* The opcode maps.  */
   1617      1.1  christos 
   1618      1.1  christos static const struct sh_opcode sh_opcode00[] =
   1619      1.1  christos {
   1620      1.1  christos   { 0x0008, SETSSP },			/* clrt */
   1621      1.1  christos   { 0x0009, 0 },			/* nop */
   1622      1.1  christos   { 0x000b, BRANCH | DELAY | USESSP },	/* rts */
   1623      1.1  christos   { 0x0018, SETSSP },			/* sett */
   1624      1.1  christos   { 0x0019, SETSSP },			/* div0u */
   1625      1.1  christos   { 0x001b, 0 },			/* sleep */
   1626      1.1  christos   { 0x0028, SETSSP },			/* clrmac */
   1627      1.1  christos   { 0x002b, BRANCH | DELAY | SETSSP },	/* rte */
   1628      1.1  christos   { 0x0038, USESSP | SETSSP },		/* ldtlb */
   1629      1.1  christos   { 0x0048, SETSSP },			/* clrs */
   1630      1.1  christos   { 0x0058, SETSSP }			/* sets */
   1631      1.1  christos };
   1632      1.1  christos 
   1633      1.1  christos static const struct sh_opcode sh_opcode01[] =
   1634      1.1  christos {
   1635      1.1  christos   { 0x0003, BRANCH | DELAY | USES1 | SETSSP },	/* bsrf rn */
   1636      1.1  christos   { 0x000a, SETS1 | USESSP },			/* sts mach,rn */
   1637      1.1  christos   { 0x001a, SETS1 | USESSP },			/* sts macl,rn */
   1638      1.1  christos   { 0x0023, BRANCH | DELAY | USES1 },		/* braf rn */
   1639      1.1  christos   { 0x0029, SETS1 | USESSP },			/* movt rn */
   1640      1.1  christos   { 0x002a, SETS1 | USESSP },			/* sts pr,rn */
   1641      1.1  christos   { 0x005a, SETS1 | USESSP },			/* sts fpul,rn */
   1642      1.1  christos   { 0x006a, SETS1 | USESSP },			/* sts fpscr,rn / sts dsr,rn */
   1643      1.1  christos   { 0x0083, LOAD | USES1 },			/* pref @rn */
   1644      1.1  christos   { 0x007a, SETS1 | USESSP },			/* sts a0,rn */
   1645      1.1  christos   { 0x008a, SETS1 | USESSP },			/* sts x0,rn */
   1646      1.1  christos   { 0x009a, SETS1 | USESSP },			/* sts x1,rn */
   1647      1.1  christos   { 0x00aa, SETS1 | USESSP },			/* sts y0,rn */
   1648      1.1  christos   { 0x00ba, SETS1 | USESSP }			/* sts y1,rn */
   1649      1.1  christos };
   1650      1.1  christos 
   1651      1.1  christos static const struct sh_opcode sh_opcode02[] =
   1652      1.1  christos {
   1653      1.1  christos   { 0x0002, SETS1 | USESSP },			/* stc <special_reg>,rn */
   1654      1.1  christos   { 0x0004, STORE | USES1 | USES2 | USESR0 },	/* mov.b rm,@(r0,rn) */
   1655      1.1  christos   { 0x0005, STORE | USES1 | USES2 | USESR0 },	/* mov.w rm,@(r0,rn) */
   1656      1.1  christos   { 0x0006, STORE | USES1 | USES2 | USESR0 },	/* mov.l rm,@(r0,rn) */
   1657      1.1  christos   { 0x0007, SETSSP | USES1 | USES2 },		/* mul.l rm,rn */
   1658      1.1  christos   { 0x000c, LOAD | SETS1 | USES2 | USESR0 },	/* mov.b @(r0,rm),rn */
   1659      1.1  christos   { 0x000d, LOAD | SETS1 | USES2 | USESR0 },	/* mov.w @(r0,rm),rn */
   1660      1.1  christos   { 0x000e, LOAD | SETS1 | USES2 | USESR0 },	/* mov.l @(r0,rm),rn */
   1661      1.1  christos   { 0x000f, LOAD|SETS1|SETS2|SETSSP|USES1|USES2|USESSP }, /* mac.l @rm+,@rn+ */
   1662      1.1  christos };
   1663      1.1  christos 
   1664      1.1  christos static const struct sh_minor_opcode sh_opcode0[] =
   1665      1.1  christos {
   1666      1.1  christos   { MAP (sh_opcode00), 0xffff },
   1667      1.1  christos   { MAP (sh_opcode01), 0xf0ff },
   1668      1.1  christos   { MAP (sh_opcode02), 0xf00f }
   1669      1.1  christos };
   1670      1.1  christos 
   1671      1.1  christos static const struct sh_opcode sh_opcode10[] =
   1672      1.1  christos {
   1673      1.1  christos   { 0x1000, STORE | USES1 | USES2 }	/* mov.l rm,@(disp,rn) */
   1674      1.1  christos };
   1675      1.1  christos 
   1676      1.1  christos static const struct sh_minor_opcode sh_opcode1[] =
   1677      1.1  christos {
   1678      1.1  christos   { MAP (sh_opcode10), 0xf000 }
   1679      1.1  christos };
   1680      1.1  christos 
   1681      1.1  christos static const struct sh_opcode sh_opcode20[] =
   1682      1.1  christos {
   1683      1.1  christos   { 0x2000, STORE | USES1 | USES2 },		/* mov.b rm,@rn */
   1684      1.1  christos   { 0x2001, STORE | USES1 | USES2 },		/* mov.w rm,@rn */
   1685      1.1  christos   { 0x2002, STORE | USES1 | USES2 },		/* mov.l rm,@rn */
   1686      1.1  christos   { 0x2004, STORE | SETS1 | USES1 | USES2 },	/* mov.b rm,@-rn */
   1687      1.1  christos   { 0x2005, STORE | SETS1 | USES1 | USES2 },	/* mov.w rm,@-rn */
   1688      1.1  christos   { 0x2006, STORE | SETS1 | USES1 | USES2 },	/* mov.l rm,@-rn */
   1689      1.1  christos   { 0x2007, SETSSP | USES1 | USES2 | USESSP },	/* div0s */
   1690      1.1  christos   { 0x2008, SETSSP | USES1 | USES2 },		/* tst rm,rn */
   1691      1.1  christos   { 0x2009, SETS1 | USES1 | USES2 },		/* and rm,rn */
   1692      1.1  christos   { 0x200a, SETS1 | USES1 | USES2 },		/* xor rm,rn */
   1693      1.1  christos   { 0x200b, SETS1 | USES1 | USES2 },		/* or rm,rn */
   1694      1.1  christos   { 0x200c, SETSSP | USES1 | USES2 },		/* cmp/str rm,rn */
   1695      1.1  christos   { 0x200d, SETS1 | USES1 | USES2 },		/* xtrct rm,rn */
   1696      1.1  christos   { 0x200e, SETSSP | USES1 | USES2 },		/* mulu.w rm,rn */
   1697      1.1  christos   { 0x200f, SETSSP | USES1 | USES2 }		/* muls.w rm,rn */
   1698      1.1  christos };
   1699      1.1  christos 
   1700      1.1  christos static const struct sh_minor_opcode sh_opcode2[] =
   1701      1.1  christos {
   1702      1.1  christos   { MAP (sh_opcode20), 0xf00f }
   1703      1.1  christos };
   1704      1.1  christos 
   1705      1.1  christos static const struct sh_opcode sh_opcode30[] =
   1706      1.1  christos {
   1707      1.1  christos   { 0x3000, SETSSP | USES1 | USES2 },		/* cmp/eq rm,rn */
   1708      1.1  christos   { 0x3002, SETSSP | USES1 | USES2 },		/* cmp/hs rm,rn */
   1709      1.1  christos   { 0x3003, SETSSP | USES1 | USES2 },		/* cmp/ge rm,rn */
   1710      1.1  christos   { 0x3004, SETSSP | USESSP | USES1 | USES2 },	/* div1 rm,rn */
   1711      1.1  christos   { 0x3005, SETSSP | USES1 | USES2 },		/* dmulu.l rm,rn */
   1712      1.1  christos   { 0x3006, SETSSP | USES1 | USES2 },		/* cmp/hi rm,rn */
   1713      1.1  christos   { 0x3007, SETSSP | USES1 | USES2 },		/* cmp/gt rm,rn */
   1714      1.1  christos   { 0x3008, SETS1 | USES1 | USES2 },		/* sub rm,rn */
   1715      1.1  christos   { 0x300a, SETS1 | SETSSP | USES1 | USES2 | USESSP }, /* subc rm,rn */
   1716      1.1  christos   { 0x300b, SETS1 | SETSSP | USES1 | USES2 },	/* subv rm,rn */
   1717      1.1  christos   { 0x300c, SETS1 | USES1 | USES2 },		/* add rm,rn */
   1718      1.1  christos   { 0x300d, SETSSP | USES1 | USES2 },		/* dmuls.l rm,rn */
   1719      1.1  christos   { 0x300e, SETS1 | SETSSP | USES1 | USES2 | USESSP }, /* addc rm,rn */
   1720      1.1  christos   { 0x300f, SETS1 | SETSSP | USES1 | USES2 }	/* addv rm,rn */
   1721      1.1  christos };
   1722      1.1  christos 
   1723      1.1  christos static const struct sh_minor_opcode sh_opcode3[] =
   1724      1.1  christos {
   1725      1.1  christos   { MAP (sh_opcode30), 0xf00f }
   1726      1.1  christos };
   1727      1.1  christos 
   1728      1.1  christos static const struct sh_opcode sh_opcode40[] =
   1729      1.1  christos {
   1730      1.1  christos   { 0x4000, SETS1 | SETSSP | USES1 },		/* shll rn */
   1731      1.1  christos   { 0x4001, SETS1 | SETSSP | USES1 },		/* shlr rn */
   1732      1.1  christos   { 0x4002, STORE | SETS1 | USES1 | USESSP },	/* sts.l mach,@-rn */
   1733      1.1  christos   { 0x4004, SETS1 | SETSSP | USES1 },		/* rotl rn */
   1734      1.1  christos   { 0x4005, SETS1 | SETSSP | USES1 },		/* rotr rn */
   1735      1.1  christos   { 0x4006, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,mach */
   1736      1.1  christos   { 0x4008, SETS1 | USES1 },			/* shll2 rn */
   1737      1.1  christos   { 0x4009, SETS1 | USES1 },			/* shlr2 rn */
   1738      1.1  christos   { 0x400a, SETSSP | USES1 },			/* lds rm,mach */
   1739      1.1  christos   { 0x400b, BRANCH | DELAY | USES1 },		/* jsr @rn */
   1740      1.1  christos   { 0x4010, SETS1 | SETSSP | USES1 },		/* dt rn */
   1741      1.1  christos   { 0x4011, SETSSP | USES1 },			/* cmp/pz rn */
   1742      1.1  christos   { 0x4012, STORE | SETS1 | USES1 | USESSP },	/* sts.l macl,@-rn */
   1743      1.1  christos   { 0x4014, SETSSP | USES1 },			/* setrc rm */
   1744      1.1  christos   { 0x4015, SETSSP | USES1 },			/* cmp/pl rn */
   1745      1.1  christos   { 0x4016, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,macl */
   1746      1.1  christos   { 0x4018, SETS1 | USES1 },			/* shll8 rn */
   1747      1.1  christos   { 0x4019, SETS1 | USES1 },			/* shlr8 rn */
   1748      1.1  christos   { 0x401a, SETSSP | USES1 },			/* lds rm,macl */
   1749      1.1  christos   { 0x401b, LOAD | SETSSP | USES1 },		/* tas.b @rn */
   1750      1.1  christos   { 0x4020, SETS1 | SETSSP | USES1 },		/* shal rn */
   1751      1.1  christos   { 0x4021, SETS1 | SETSSP | USES1 },		/* shar rn */
   1752      1.1  christos   { 0x4022, STORE | SETS1 | USES1 | USESSP },	/* sts.l pr,@-rn */
   1753      1.1  christos   { 0x4024, SETS1 | SETSSP | USES1 | USESSP },	/* rotcl rn */
   1754      1.1  christos   { 0x4025, SETS1 | SETSSP | USES1 | USESSP },	/* rotcr rn */
   1755      1.1  christos   { 0x4026, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,pr */
   1756      1.1  christos   { 0x4028, SETS1 | USES1 },			/* shll16 rn */
   1757      1.1  christos   { 0x4029, SETS1 | USES1 },			/* shlr16 rn */
   1758      1.1  christos   { 0x402a, SETSSP | USES1 },			/* lds rm,pr */
   1759      1.1  christos   { 0x402b, BRANCH | DELAY | USES1 },		/* jmp @rn */
   1760      1.1  christos   { 0x4052, STORE | SETS1 | USES1 | USESSP },	/* sts.l fpul,@-rn */
   1761      1.1  christos   { 0x4056, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,fpul */
   1762      1.1  christos   { 0x405a, SETSSP | USES1 },			/* lds.l rm,fpul */
   1763      1.1  christos   { 0x4062, STORE | SETS1 | USES1 | USESSP },	/* sts.l fpscr / dsr,@-rn */
   1764      1.1  christos   { 0x4066, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,fpscr / dsr */
   1765      1.1  christos   { 0x406a, SETSSP | USES1 },			/* lds rm,fpscr / lds rm,dsr */
   1766      1.1  christos   { 0x4072, STORE | SETS1 | USES1 | USESSP },	/* sts.l a0,@-rn */
   1767      1.1  christos   { 0x4076, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,a0 */
   1768      1.1  christos   { 0x407a, SETSSP | USES1 },			/* lds.l rm,a0 */
   1769      1.1  christos   { 0x4082, STORE | SETS1 | USES1 | USESSP },	/* sts.l x0,@-rn */
   1770      1.1  christos   { 0x4086, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,x0 */
   1771      1.1  christos   { 0x408a, SETSSP | USES1 },			/* lds.l rm,x0 */
   1772      1.1  christos   { 0x4092, STORE | SETS1 | USES1 | USESSP },	/* sts.l x1,@-rn */
   1773      1.1  christos   { 0x4096, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,x1 */
   1774      1.1  christos   { 0x409a, SETSSP | USES1 },			/* lds.l rm,x1 */
   1775      1.1  christos   { 0x40a2, STORE | SETS1 | USES1 | USESSP },	/* sts.l y0,@-rn */
   1776      1.1  christos   { 0x40a6, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,y0 */
   1777      1.1  christos   { 0x40aa, SETSSP | USES1 },			/* lds.l rm,y0 */
   1778      1.1  christos   { 0x40b2, STORE | SETS1 | USES1 | USESSP },	/* sts.l y1,@-rn */
   1779      1.1  christos   { 0x40b6, LOAD | SETS1 | SETSSP | USES1 },	/* lds.l @rm+,y1 */
   1780      1.1  christos   { 0x40ba, SETSSP | USES1 }			/* lds.l rm,y1 */
   1781      1.1  christos };
   1782      1.1  christos 
   1783      1.1  christos static const struct sh_opcode sh_opcode41[] =
   1784      1.1  christos {
   1785      1.1  christos   { 0x4003, STORE | SETS1 | USES1 | USESSP },	/* stc.l <special_reg>,@-rn */
   1786      1.1  christos   { 0x4007, LOAD | SETS1 | SETSSP | USES1 },	/* ldc.l @rm+,<special_reg> */
   1787      1.1  christos   { 0x400c, SETS1 | USES1 | USES2 },		/* shad rm,rn */
   1788      1.1  christos   { 0x400d, SETS1 | USES1 | USES2 },		/* shld rm,rn */
   1789      1.1  christos   { 0x400e, SETSSP | USES1 },			/* ldc rm,<special_reg> */
   1790      1.1  christos   { 0x400f, LOAD|SETS1|SETS2|SETSSP|USES1|USES2|USESSP }, /* mac.w @rm+,@rn+ */
   1791      1.1  christos };
   1792      1.1  christos 
   1793      1.1  christos static const struct sh_minor_opcode sh_opcode4[] =
   1794      1.1  christos {
   1795      1.1  christos   { MAP (sh_opcode40), 0xf0ff },
   1796      1.1  christos   { MAP (sh_opcode41), 0xf00f }
   1797      1.1  christos };
   1798      1.1  christos 
   1799      1.1  christos static const struct sh_opcode sh_opcode50[] =
   1800      1.1  christos {
   1801      1.1  christos   { 0x5000, LOAD | SETS1 | USES2 }	/* mov.l @(disp,rm),rn */
   1802      1.1  christos };
   1803      1.1  christos 
   1804      1.1  christos static const struct sh_minor_opcode sh_opcode5[] =
   1805      1.1  christos {
   1806      1.1  christos   { MAP (sh_opcode50), 0xf000 }
   1807      1.1  christos };
   1808      1.1  christos 
   1809      1.1  christos static const struct sh_opcode sh_opcode60[] =
   1810      1.1  christos {
   1811      1.1  christos   { 0x6000, LOAD | SETS1 | USES2 },		/* mov.b @rm,rn */
   1812      1.1  christos   { 0x6001, LOAD | SETS1 | USES2 },		/* mov.w @rm,rn */
   1813      1.1  christos   { 0x6002, LOAD | SETS1 | USES2 },		/* mov.l @rm,rn */
   1814      1.1  christos   { 0x6003, SETS1 | USES2 },			/* mov rm,rn */
   1815      1.1  christos   { 0x6004, LOAD | SETS1 | SETS2 | USES2 },	/* mov.b @rm+,rn */
   1816      1.1  christos   { 0x6005, LOAD | SETS1 | SETS2 | USES2 },	/* mov.w @rm+,rn */
   1817      1.1  christos   { 0x6006, LOAD | SETS1 | SETS2 | USES2 },	/* mov.l @rm+,rn */
   1818      1.1  christos   { 0x6007, SETS1 | USES2 },			/* not rm,rn */
   1819      1.1  christos   { 0x6008, SETS1 | USES2 },			/* swap.b rm,rn */
   1820      1.1  christos   { 0x6009, SETS1 | USES2 },			/* swap.w rm,rn */
   1821      1.1  christos   { 0x600a, SETS1 | SETSSP | USES2 | USESSP },	/* negc rm,rn */
   1822      1.1  christos   { 0x600b, SETS1 | USES2 },			/* neg rm,rn */
   1823      1.1  christos   { 0x600c, SETS1 | USES2 },			/* extu.b rm,rn */
   1824      1.1  christos   { 0x600d, SETS1 | USES2 },			/* extu.w rm,rn */
   1825      1.1  christos   { 0x600e, SETS1 | USES2 },			/* exts.b rm,rn */
   1826      1.1  christos   { 0x600f, SETS1 | USES2 }			/* exts.w rm,rn */
   1827      1.1  christos };
   1828      1.1  christos 
   1829      1.1  christos static const struct sh_minor_opcode sh_opcode6[] =
   1830      1.1  christos {
   1831      1.1  christos   { MAP (sh_opcode60), 0xf00f }
   1832      1.1  christos };
   1833      1.1  christos 
   1834      1.1  christos static const struct sh_opcode sh_opcode70[] =
   1835      1.1  christos {
   1836      1.1  christos   { 0x7000, SETS1 | USES1 }		/* add #imm,rn */
   1837      1.1  christos };
   1838      1.1  christos 
   1839      1.1  christos static const struct sh_minor_opcode sh_opcode7[] =
   1840      1.1  christos {
   1841      1.1  christos   { MAP (sh_opcode70), 0xf000 }
   1842      1.1  christos };
   1843      1.1  christos 
   1844      1.1  christos static const struct sh_opcode sh_opcode80[] =
   1845      1.1  christos {
   1846      1.1  christos   { 0x8000, STORE | USES2 | USESR0 },	/* mov.b r0,@(disp,rn) */
   1847      1.1  christos   { 0x8100, STORE | USES2 | USESR0 },	/* mov.w r0,@(disp,rn) */
   1848      1.1  christos   { 0x8200, SETSSP },			/* setrc #imm */
   1849      1.1  christos   { 0x8400, LOAD | SETSR0 | USES2 },	/* mov.b @(disp,rm),r0 */
   1850      1.1  christos   { 0x8500, LOAD | SETSR0 | USES2 },	/* mov.w @(disp,rn),r0 */
   1851      1.1  christos   { 0x8800, SETSSP | USESR0 },		/* cmp/eq #imm,r0 */
   1852      1.1  christos   { 0x8900, BRANCH | USESSP },		/* bt label */
   1853      1.1  christos   { 0x8b00, BRANCH | USESSP },		/* bf label */
   1854      1.1  christos   { 0x8c00, SETSSP },			/* ldrs @(disp,pc) */
   1855      1.1  christos   { 0x8d00, BRANCH | DELAY | USESSP },	/* bt/s label */
   1856      1.1  christos   { 0x8e00, SETSSP },			/* ldre @(disp,pc) */
   1857      1.1  christos   { 0x8f00, BRANCH | DELAY | USESSP }	/* bf/s label */
   1858      1.1  christos };
   1859      1.1  christos 
   1860      1.1  christos static const struct sh_minor_opcode sh_opcode8[] =
   1861      1.1  christos {
   1862      1.1  christos   { MAP (sh_opcode80), 0xff00 }
   1863      1.1  christos };
   1864      1.1  christos 
   1865      1.1  christos static const struct sh_opcode sh_opcode90[] =
   1866      1.1  christos {
   1867      1.1  christos   { 0x9000, LOAD | SETS1 }	/* mov.w @(disp,pc),rn */
   1868      1.1  christos };
   1869      1.1  christos 
   1870      1.1  christos static const struct sh_minor_opcode sh_opcode9[] =
   1871      1.1  christos {
   1872      1.1  christos   { MAP (sh_opcode90), 0xf000 }
   1873      1.1  christos };
   1874      1.1  christos 
   1875      1.1  christos static const struct sh_opcode sh_opcodea0[] =
   1876      1.1  christos {
   1877      1.1  christos   { 0xa000, BRANCH | DELAY }	/* bra label */
   1878      1.1  christos };
   1879      1.1  christos 
   1880      1.1  christos static const struct sh_minor_opcode sh_opcodea[] =
   1881      1.1  christos {
   1882      1.1  christos   { MAP (sh_opcodea0), 0xf000 }
   1883      1.1  christos };
   1884      1.1  christos 
   1885      1.1  christos static const struct sh_opcode sh_opcodeb0[] =
   1886      1.1  christos {
   1887      1.1  christos   { 0xb000, BRANCH | DELAY }	/* bsr label */
   1888      1.1  christos };
   1889      1.1  christos 
   1890      1.1  christos static const struct sh_minor_opcode sh_opcodeb[] =
   1891      1.1  christos {
   1892      1.1  christos   { MAP (sh_opcodeb0), 0xf000 }
   1893      1.1  christos };
   1894      1.1  christos 
   1895      1.1  christos static const struct sh_opcode sh_opcodec0[] =
   1896      1.1  christos {
   1897      1.1  christos   { 0xc000, STORE | USESR0 | USESSP },		/* mov.b r0,@(disp,gbr) */
   1898      1.1  christos   { 0xc100, STORE | USESR0 | USESSP },		/* mov.w r0,@(disp,gbr) */
   1899      1.1  christos   { 0xc200, STORE | USESR0 | USESSP },		/* mov.l r0,@(disp,gbr) */
   1900      1.1  christos   { 0xc300, BRANCH | USESSP },			/* trapa #imm */
   1901      1.1  christos   { 0xc400, LOAD | SETSR0 | USESSP },		/* mov.b @(disp,gbr),r0 */
   1902      1.1  christos   { 0xc500, LOAD | SETSR0 | USESSP },		/* mov.w @(disp,gbr),r0 */
   1903      1.1  christos   { 0xc600, LOAD | SETSR0 | USESSP },		/* mov.l @(disp,gbr),r0 */
   1904      1.1  christos   { 0xc700, SETSR0 },				/* mova @(disp,pc),r0 */
   1905      1.1  christos   { 0xc800, SETSSP | USESR0 },			/* tst #imm,r0 */
   1906      1.1  christos   { 0xc900, SETSR0 | USESR0 },			/* and #imm,r0 */
   1907      1.1  christos   { 0xca00, SETSR0 | USESR0 },			/* xor #imm,r0 */
   1908      1.1  christos   { 0xcb00, SETSR0 | USESR0 },			/* or #imm,r0 */
   1909      1.1  christos   { 0xcc00, LOAD | SETSSP | USESR0 | USESSP },	/* tst.b #imm,@(r0,gbr) */
   1910      1.1  christos   { 0xcd00, LOAD | STORE | USESR0 | USESSP },	/* and.b #imm,@(r0,gbr) */
   1911      1.1  christos   { 0xce00, LOAD | STORE | USESR0 | USESSP },	/* xor.b #imm,@(r0,gbr) */
   1912      1.1  christos   { 0xcf00, LOAD | STORE | USESR0 | USESSP }	/* or.b #imm,@(r0,gbr) */
   1913      1.1  christos };
   1914      1.1  christos 
   1915      1.1  christos static const struct sh_minor_opcode sh_opcodec[] =
   1916      1.1  christos {
   1917      1.1  christos   { MAP (sh_opcodec0), 0xff00 }
   1918      1.1  christos };
   1919      1.1  christos 
   1920      1.1  christos static const struct sh_opcode sh_opcoded0[] =
   1921      1.1  christos {
   1922      1.1  christos   { 0xd000, LOAD | SETS1 }		/* mov.l @(disp,pc),rn */
   1923      1.1  christos };
   1924      1.1  christos 
   1925      1.1  christos static const struct sh_minor_opcode sh_opcoded[] =
   1926      1.1  christos {
   1927      1.1  christos   { MAP (sh_opcoded0), 0xf000 }
   1928      1.1  christos };
   1929      1.1  christos 
   1930      1.1  christos static const struct sh_opcode sh_opcodee0[] =
   1931      1.1  christos {
   1932      1.1  christos   { 0xe000, SETS1 }		/* mov #imm,rn */
   1933      1.1  christos };
   1934      1.1  christos 
   1935      1.1  christos static const struct sh_minor_opcode sh_opcodee[] =
   1936      1.1  christos {
   1937      1.1  christos   { MAP (sh_opcodee0), 0xf000 }
   1938      1.1  christos };
   1939      1.1  christos 
   1940      1.1  christos static const struct sh_opcode sh_opcodef0[] =
   1941      1.1  christos {
   1942      1.1  christos   { 0xf000, SETSF1 | USESF1 | USESF2 },		/* fadd fm,fn */
   1943      1.1  christos   { 0xf001, SETSF1 | USESF1 | USESF2 },		/* fsub fm,fn */
   1944      1.1  christos   { 0xf002, SETSF1 | USESF1 | USESF2 },		/* fmul fm,fn */
   1945      1.1  christos   { 0xf003, SETSF1 | USESF1 | USESF2 },		/* fdiv fm,fn */
   1946      1.1  christos   { 0xf004, SETSSP | USESF1 | USESF2 },		/* fcmp/eq fm,fn */
   1947      1.1  christos   { 0xf005, SETSSP | USESF1 | USESF2 },		/* fcmp/gt fm,fn */
   1948      1.1  christos   { 0xf006, LOAD | SETSF1 | USES2 | USESR0 },	/* fmov.s @(r0,rm),fn */
   1949      1.1  christos   { 0xf007, STORE | USES1 | USESF2 | USESR0 },	/* fmov.s fm,@(r0,rn) */
   1950      1.1  christos   { 0xf008, LOAD | SETSF1 | USES2 },		/* fmov.s @rm,fn */
   1951      1.1  christos   { 0xf009, LOAD | SETS2 | SETSF1 | USES2 },	/* fmov.s @rm+,fn */
   1952      1.1  christos   { 0xf00a, STORE | USES1 | USESF2 },		/* fmov.s fm,@rn */
   1953      1.1  christos   { 0xf00b, STORE | SETS1 | USES1 | USESF2 },	/* fmov.s fm,@-rn */
   1954      1.1  christos   { 0xf00c, SETSF1 | USESF2 },			/* fmov fm,fn */
   1955      1.1  christos   { 0xf00e, SETSF1 | USESF1 | USESF2 | USESF0 }	/* fmac f0,fm,fn */
   1956      1.1  christos };
   1957      1.1  christos 
   1958      1.1  christos static const struct sh_opcode sh_opcodef1[] =
   1959      1.1  christos {
   1960      1.1  christos   { 0xf00d, SETSF1 | USESSP },	/* fsts fpul,fn */
   1961      1.1  christos   { 0xf01d, SETSSP | USESF1 },	/* flds fn,fpul */
   1962      1.1  christos   { 0xf02d, SETSF1 | USESSP },	/* float fpul,fn */
   1963      1.1  christos   { 0xf03d, SETSSP | USESF1 },	/* ftrc fn,fpul */
   1964      1.1  christos   { 0xf04d, SETSF1 | USESF1 },	/* fneg fn */
   1965      1.1  christos   { 0xf05d, SETSF1 | USESF1 },	/* fabs fn */
   1966      1.1  christos   { 0xf06d, SETSF1 | USESF1 },	/* fsqrt fn */
   1967      1.1  christos   { 0xf07d, SETSSP | USESF1 },	/* ftst/nan fn */
   1968      1.1  christos   { 0xf08d, SETSF1 },		/* fldi0 fn */
   1969      1.1  christos   { 0xf09d, SETSF1 }		/* fldi1 fn */
   1970      1.1  christos };
   1971      1.1  christos 
   1972      1.1  christos static const struct sh_minor_opcode sh_opcodef[] =
   1973      1.1  christos {
   1974      1.1  christos   { MAP (sh_opcodef0), 0xf00f },
   1975      1.1  christos   { MAP (sh_opcodef1), 0xf0ff }
   1976      1.1  christos };
   1977      1.1  christos 
   1978      1.1  christos static struct sh_major_opcode sh_opcodes[] =
   1979      1.1  christos {
   1980      1.1  christos   { MAP (sh_opcode0) },
   1981      1.1  christos   { MAP (sh_opcode1) },
   1982      1.1  christos   { MAP (sh_opcode2) },
   1983      1.1  christos   { MAP (sh_opcode3) },
   1984      1.1  christos   { MAP (sh_opcode4) },
   1985      1.1  christos   { MAP (sh_opcode5) },
   1986      1.1  christos   { MAP (sh_opcode6) },
   1987      1.1  christos   { MAP (sh_opcode7) },
   1988      1.1  christos   { MAP (sh_opcode8) },
   1989      1.1  christos   { MAP (sh_opcode9) },
   1990      1.1  christos   { MAP (sh_opcodea) },
   1991      1.1  christos   { MAP (sh_opcodeb) },
   1992      1.1  christos   { MAP (sh_opcodec) },
   1993      1.1  christos   { MAP (sh_opcoded) },
   1994      1.1  christos   { MAP (sh_opcodee) },
   1995      1.1  christos   { MAP (sh_opcodef) }
   1996      1.1  christos };
   1997      1.1  christos 
   1998      1.1  christos /* The double data transfer / parallel processing insns are not
   1999      1.1  christos    described here.  This will cause sh_align_load_span to leave them alone.  */
   2000      1.1  christos 
   2001      1.1  christos static const struct sh_opcode sh_dsp_opcodef0[] =
   2002      1.1  christos {
   2003      1.1  christos   { 0xf400, USESAS | SETSAS | LOAD | SETSSP },	/* movs.x @-as,ds */
   2004      1.1  christos   { 0xf401, USESAS | SETSAS | STORE | USESSP },	/* movs.x ds,@-as */
   2005      1.1  christos   { 0xf404, USESAS | LOAD | SETSSP },		/* movs.x @as,ds */
   2006      1.1  christos   { 0xf405, USESAS | STORE | USESSP },		/* movs.x ds,@as */
   2007      1.1  christos   { 0xf408, USESAS | SETSAS | LOAD | SETSSP },	/* movs.x @as+,ds */
   2008      1.1  christos   { 0xf409, USESAS | SETSAS | STORE | USESSP },	/* movs.x ds,@as+ */
   2009      1.1  christos   { 0xf40c, USESAS | SETSAS | LOAD | SETSSP | USESR8 },	/* movs.x @as+r8,ds */
   2010      1.1  christos   { 0xf40d, USESAS | SETSAS | STORE | USESSP | USESR8 }	/* movs.x ds,@as+r8 */
   2011      1.1  christos };
   2012      1.1  christos 
   2013      1.1  christos static const struct sh_minor_opcode sh_dsp_opcodef[] =
   2014      1.1  christos {
   2015      1.1  christos   { MAP (sh_dsp_opcodef0), 0xfc0d }
   2016      1.1  christos };
   2017      1.1  christos 
   2018      1.1  christos /* Given an instruction, return a pointer to the corresponding
   2019      1.1  christos    sh_opcode structure.  Return NULL if the instruction is not
   2020      1.1  christos    recognized.  */
   2021  1.1.1.2  christos 
   2022      1.1  christos static const struct sh_opcode *
   2023      1.1  christos sh_insn_info (unsigned int insn)
   2024      1.1  christos {
   2025      1.1  christos   const struct sh_major_opcode *maj;
   2026      1.1  christos   const struct sh_minor_opcode *min, *minend;
   2027      1.1  christos 
   2028      1.1  christos   maj = &sh_opcodes[(insn & 0xf000) >> 12];
   2029      1.1  christos   min = maj->minor_opcodes;
   2030      1.1  christos   minend = min + maj->count;
   2031      1.1  christos   for (; min < minend; min++)
   2032      1.1  christos     {
   2033      1.1  christos       unsigned int l;
   2034      1.1  christos       const struct sh_opcode *op, *opend;
   2035      1.1  christos 
   2036      1.1  christos       l = insn & min->mask;
   2037      1.1  christos       op = min->opcodes;
   2038      1.1  christos       opend = op + min->count;
   2039      1.1  christos 
   2040      1.1  christos       /* Since the opcodes tables are sorted, we could use a binary
   2041      1.1  christos          search here if the count were above some cutoff value.  */
   2042      1.1  christos       for (; op < opend; op++)
   2043      1.1  christos 	if (op->opcode == l)
   2044      1.1  christos 	  return op;
   2045      1.1  christos     }
   2046      1.1  christos 
   2047      1.1  christos   return NULL;
   2048      1.1  christos }
   2049      1.1  christos 
   2050      1.1  christos /* See whether an instruction uses a general purpose register.  */
   2051  1.1.1.2  christos 
   2052  1.1.1.2  christos static bfd_boolean
   2053  1.1.1.2  christos sh_insn_uses_reg (unsigned int insn,
   2054      1.1  christos 		  const struct sh_opcode *op,
   2055      1.1  christos 		  unsigned int reg)
   2056      1.1  christos {
   2057      1.1  christos   unsigned int f;
   2058      1.1  christos 
   2059      1.1  christos   f = op->flags;
   2060      1.1  christos 
   2061      1.1  christos   if ((f & USES1) != 0
   2062      1.1  christos       && USES1_REG (insn) == reg)
   2063      1.1  christos     return TRUE;
   2064      1.1  christos   if ((f & USES2) != 0
   2065      1.1  christos       && USES2_REG (insn) == reg)
   2066      1.1  christos     return TRUE;
   2067      1.1  christos   if ((f & USESR0) != 0
   2068      1.1  christos       && reg == 0)
   2069      1.1  christos     return TRUE;
   2070      1.1  christos   if ((f & USESAS) && reg == USESAS_REG (insn))
   2071      1.1  christos     return TRUE;
   2072      1.1  christos   if ((f & USESR8) && reg == 8)
   2073      1.1  christos     return TRUE;
   2074      1.1  christos 
   2075      1.1  christos   return FALSE;
   2076      1.1  christos }
   2077      1.1  christos 
   2078      1.1  christos /* See whether an instruction sets a general purpose register.  */
   2079  1.1.1.2  christos 
   2080  1.1.1.2  christos static bfd_boolean
   2081  1.1.1.2  christos sh_insn_sets_reg (unsigned int insn,
   2082      1.1  christos 		  const struct sh_opcode *op,
   2083      1.1  christos 		  unsigned int reg)
   2084      1.1  christos {
   2085      1.1  christos   unsigned int f;
   2086      1.1  christos 
   2087      1.1  christos   f = op->flags;
   2088      1.1  christos 
   2089      1.1  christos   if ((f & SETS1) != 0
   2090      1.1  christos       && SETS1_REG (insn) == reg)
   2091      1.1  christos     return TRUE;
   2092      1.1  christos   if ((f & SETS2) != 0
   2093      1.1  christos       && SETS2_REG (insn) == reg)
   2094      1.1  christos     return TRUE;
   2095      1.1  christos   if ((f & SETSR0) != 0
   2096      1.1  christos       && reg == 0)
   2097      1.1  christos     return TRUE;
   2098      1.1  christos   if ((f & SETSAS) && reg == SETSAS_REG (insn))
   2099      1.1  christos     return TRUE;
   2100      1.1  christos 
   2101      1.1  christos   return FALSE;
   2102  1.1.1.2  christos }
   2103      1.1  christos 
   2104      1.1  christos /* See whether an instruction uses or sets a general purpose register */
   2105  1.1.1.2  christos 
   2106  1.1.1.2  christos static bfd_boolean
   2107  1.1.1.2  christos sh_insn_uses_or_sets_reg (unsigned int insn,
   2108      1.1  christos 			  const struct sh_opcode *op,
   2109  1.1.1.2  christos 			  unsigned int reg)
   2110      1.1  christos {
   2111      1.1  christos   if (sh_insn_uses_reg (insn, op, reg))
   2112  1.1.1.2  christos     return TRUE;
   2113      1.1  christos 
   2114      1.1  christos   return sh_insn_sets_reg (insn, op, reg);
   2115      1.1  christos }
   2116      1.1  christos 
   2117      1.1  christos /* See whether an instruction uses a floating point register.  */
   2118  1.1.1.2  christos 
   2119  1.1.1.2  christos static bfd_boolean
   2120  1.1.1.2  christos sh_insn_uses_freg (unsigned int insn,
   2121      1.1  christos 		   const struct sh_opcode *op,
   2122      1.1  christos 		   unsigned int freg)
   2123      1.1  christos {
   2124      1.1  christos   unsigned int f;
   2125      1.1  christos 
   2126      1.1  christos   f = op->flags;
   2127      1.1  christos 
   2128      1.1  christos   /* We can't tell if this is a double-precision insn, so just play safe
   2129      1.1  christos      and assume that it might be.  So not only have we test FREG against
   2130      1.1  christos      itself, but also even FREG against FREG+1 - if the using insn uses
   2131      1.1  christos      just the low part of a double precision value - but also an odd
   2132      1.1  christos      FREG against FREG-1 -  if the setting insn sets just the low part
   2133      1.1  christos      of a double precision value.
   2134      1.1  christos      So what this all boils down to is that we have to ignore the lowest
   2135      1.1  christos      bit of the register number.  */
   2136      1.1  christos 
   2137      1.1  christos   if ((f & USESF1) != 0
   2138      1.1  christos       && (USESF1_REG (insn) & 0xe) == (freg & 0xe))
   2139      1.1  christos     return TRUE;
   2140      1.1  christos   if ((f & USESF2) != 0
   2141      1.1  christos       && (USESF2_REG (insn) & 0xe) == (freg & 0xe))
   2142      1.1  christos     return TRUE;
   2143      1.1  christos   if ((f & USESF0) != 0
   2144      1.1  christos       && freg == 0)
   2145      1.1  christos     return TRUE;
   2146      1.1  christos 
   2147      1.1  christos   return FALSE;
   2148      1.1  christos }
   2149      1.1  christos 
   2150      1.1  christos /* See whether an instruction sets a floating point register.  */
   2151  1.1.1.2  christos 
   2152  1.1.1.2  christos static bfd_boolean
   2153  1.1.1.2  christos sh_insn_sets_freg (unsigned int insn,
   2154      1.1  christos 		   const struct sh_opcode *op,
   2155      1.1  christos 		   unsigned int freg)
   2156      1.1  christos {
   2157      1.1  christos   unsigned int f;
   2158      1.1  christos 
   2159      1.1  christos   f = op->flags;
   2160      1.1  christos 
   2161      1.1  christos   /* We can't tell if this is a double-precision insn, so just play safe
   2162      1.1  christos      and assume that it might be.  So not only have we test FREG against
   2163      1.1  christos      itself, but also even FREG against FREG+1 - if the using insn uses
   2164      1.1  christos      just the low part of a double precision value - but also an odd
   2165      1.1  christos      FREG against FREG-1 -  if the setting insn sets just the low part
   2166      1.1  christos      of a double precision value.
   2167      1.1  christos      So what this all boils down to is that we have to ignore the lowest
   2168      1.1  christos      bit of the register number.  */
   2169      1.1  christos 
   2170      1.1  christos   if ((f & SETSF1) != 0
   2171      1.1  christos       && (SETSF1_REG (insn) & 0xe) == (freg & 0xe))
   2172      1.1  christos     return TRUE;
   2173      1.1  christos 
   2174      1.1  christos   return FALSE;
   2175  1.1.1.2  christos }
   2176  1.1.1.2  christos 
   2177  1.1.1.2  christos /* See whether an instruction uses or sets a floating point register */
   2178  1.1.1.2  christos 
   2179  1.1.1.2  christos static bfd_boolean
   2180  1.1.1.2  christos sh_insn_uses_or_sets_freg (unsigned int insn,
   2181  1.1.1.2  christos 			   const struct sh_opcode *op,
   2182  1.1.1.2  christos 			   unsigned int reg)
   2183  1.1.1.2  christos {
   2184  1.1.1.2  christos   if (sh_insn_uses_freg (insn, op, reg))
   2185  1.1.1.2  christos     return TRUE;
   2186  1.1.1.2  christos 
   2187  1.1.1.2  christos   return sh_insn_sets_freg (insn, op, reg);
   2188      1.1  christos }
   2189      1.1  christos 
   2190      1.1  christos /* See whether instructions I1 and I2 conflict, assuming I1 comes
   2191      1.1  christos    before I2.  OP1 and OP2 are the corresponding sh_opcode structures.
   2192      1.1  christos    This should return TRUE if there is a conflict, or FALSE if the
   2193      1.1  christos    instructions can be swapped safely.  */
   2194  1.1.1.2  christos 
   2195  1.1.1.2  christos static bfd_boolean
   2196  1.1.1.2  christos sh_insns_conflict (unsigned int i1,
   2197  1.1.1.2  christos 		   const struct sh_opcode *op1,
   2198      1.1  christos 		   unsigned int i2,
   2199      1.1  christos 		   const struct sh_opcode *op2)
   2200      1.1  christos {
   2201      1.1  christos   unsigned int f1, f2;
   2202      1.1  christos 
   2203      1.1  christos   f1 = op1->flags;
   2204      1.1  christos   f2 = op2->flags;
   2205      1.1  christos 
   2206      1.1  christos   /* Load of fpscr conflicts with floating point operations.
   2207      1.1  christos      FIXME: shouldn't test raw opcodes here.  */
   2208      1.1  christos   if (((i1 & 0xf0ff) == 0x4066 && (i2 & 0xf000) == 0xf000)
   2209      1.1  christos       || ((i2 & 0xf0ff) == 0x4066 && (i1 & 0xf000) == 0xf000))
   2210      1.1  christos     return TRUE;
   2211      1.1  christos 
   2212      1.1  christos   if ((f1 & (BRANCH | DELAY)) != 0
   2213      1.1  christos       || (f2 & (BRANCH | DELAY)) != 0)
   2214      1.1  christos     return TRUE;
   2215      1.1  christos 
   2216      1.1  christos   if (((f1 | f2) & SETSSP)
   2217      1.1  christos       && (f1 & (SETSSP | USESSP))
   2218      1.1  christos       && (f2 & (SETSSP | USESSP)))
   2219      1.1  christos     return TRUE;
   2220      1.1  christos 
   2221      1.1  christos   if ((f1 & SETS1) != 0
   2222      1.1  christos       && sh_insn_uses_or_sets_reg (i2, op2, SETS1_REG (i1)))
   2223      1.1  christos     return TRUE;
   2224      1.1  christos   if ((f1 & SETS2) != 0
   2225      1.1  christos       && sh_insn_uses_or_sets_reg (i2, op2, SETS2_REG (i1)))
   2226      1.1  christos     return TRUE;
   2227      1.1  christos   if ((f1 & SETSR0) != 0
   2228      1.1  christos       && sh_insn_uses_or_sets_reg (i2, op2, 0))
   2229      1.1  christos     return TRUE;
   2230      1.1  christos   if ((f1 & SETSAS)
   2231      1.1  christos       && sh_insn_uses_or_sets_reg (i2, op2, SETSAS_REG (i1)))
   2232      1.1  christos     return TRUE;
   2233      1.1  christos   if ((f1 & SETSF1) != 0
   2234      1.1  christos       && sh_insn_uses_or_sets_freg (i2, op2, SETSF1_REG (i1)))
   2235      1.1  christos     return TRUE;
   2236      1.1  christos 
   2237      1.1  christos   if ((f2 & SETS1) != 0
   2238      1.1  christos       && sh_insn_uses_or_sets_reg (i1, op1, SETS1_REG (i2)))
   2239      1.1  christos     return TRUE;
   2240      1.1  christos   if ((f2 & SETS2) != 0
   2241      1.1  christos       && sh_insn_uses_or_sets_reg (i1, op1, SETS2_REG (i2)))
   2242      1.1  christos     return TRUE;
   2243      1.1  christos   if ((f2 & SETSR0) != 0
   2244      1.1  christos       && sh_insn_uses_or_sets_reg (i1, op1, 0))
   2245      1.1  christos     return TRUE;
   2246      1.1  christos   if ((f2 & SETSAS)
   2247      1.1  christos       && sh_insn_uses_or_sets_reg (i1, op1, SETSAS_REG (i2)))
   2248      1.1  christos     return TRUE;
   2249      1.1  christos   if ((f2 & SETSF1) != 0
   2250      1.1  christos       && sh_insn_uses_or_sets_freg (i1, op1, SETSF1_REG (i2)))
   2251      1.1  christos     return TRUE;
   2252      1.1  christos 
   2253      1.1  christos   /* The instructions do not conflict.  */
   2254      1.1  christos   return FALSE;
   2255      1.1  christos }
   2256      1.1  christos 
   2257      1.1  christos /* I1 is a load instruction, and I2 is some other instruction.  Return
   2258      1.1  christos    TRUE if I1 loads a register which I2 uses.  */
   2259  1.1.1.2  christos 
   2260  1.1.1.2  christos static bfd_boolean
   2261  1.1.1.2  christos sh_load_use (unsigned int i1,
   2262  1.1.1.2  christos 	     const struct sh_opcode *op1,
   2263      1.1  christos 	     unsigned int i2,
   2264      1.1  christos 	     const struct sh_opcode *op2)
   2265      1.1  christos {
   2266      1.1  christos   unsigned int f1;
   2267      1.1  christos 
   2268      1.1  christos   f1 = op1->flags;
   2269      1.1  christos 
   2270      1.1  christos   if ((f1 & LOAD) == 0)
   2271      1.1  christos     return FALSE;
   2272      1.1  christos 
   2273      1.1  christos   /* If both SETS1 and SETSSP are set, that means a load to a special
   2274      1.1  christos      register using postincrement addressing mode, which we don't care
   2275      1.1  christos      about here.  */
   2276      1.1  christos   if ((f1 & SETS1) != 0
   2277      1.1  christos       && (f1 & SETSSP) == 0
   2278      1.1  christos       && sh_insn_uses_reg (i2, op2, (i1 & 0x0f00) >> 8))
   2279      1.1  christos     return TRUE;
   2280      1.1  christos 
   2281      1.1  christos   if ((f1 & SETSR0) != 0
   2282      1.1  christos       && sh_insn_uses_reg (i2, op2, 0))
   2283      1.1  christos     return TRUE;
   2284      1.1  christos 
   2285      1.1  christos   if ((f1 & SETSF1) != 0
   2286      1.1  christos       && sh_insn_uses_freg (i2, op2, (i1 & 0x0f00) >> 8))
   2287      1.1  christos     return TRUE;
   2288      1.1  christos 
   2289      1.1  christos   return FALSE;
   2290      1.1  christos }
   2291      1.1  christos 
   2292      1.1  christos /* Try to align loads and stores within a span of memory.  This is
   2293      1.1  christos    called by both the ELF and the COFF sh targets.  ABFD and SEC are
   2294      1.1  christos    the BFD and section we are examining.  CONTENTS is the contents of
   2295      1.1  christos    the section.  SWAP is the routine to call to swap two instructions.
   2296      1.1  christos    RELOCS is a pointer to the internal relocation information, to be
   2297      1.1  christos    passed to SWAP.  PLABEL is a pointer to the current label in a
   2298      1.1  christos    sorted list of labels; LABEL_END is the end of the list.  START and
   2299      1.1  christos    STOP are the range of memory to examine.  If a swap is made,
   2300      1.1  christos    *PSWAPPED is set to TRUE.  */
   2301      1.1  christos 
   2302      1.1  christos #ifdef COFF_WITH_PE
   2303      1.1  christos static
   2304  1.1.1.2  christos #endif
   2305  1.1.1.2  christos bfd_boolean
   2306  1.1.1.2  christos _bfd_sh_align_load_span (bfd *abfd,
   2307  1.1.1.2  christos 			 asection *sec,
   2308  1.1.1.2  christos 			 bfd_byte *contents,
   2309  1.1.1.2  christos 			 bfd_boolean (*swap) (bfd *, asection *, void *, bfd_byte *, bfd_vma),
   2310  1.1.1.2  christos 			 void * relocs,
   2311  1.1.1.2  christos 			 bfd_vma **plabel,
   2312  1.1.1.2  christos 			 bfd_vma *label_end,
   2313  1.1.1.2  christos 			 bfd_vma start,
   2314      1.1  christos 			 bfd_vma stop,
   2315      1.1  christos 			 bfd_boolean *pswapped)
   2316      1.1  christos {
   2317      1.1  christos   int dsp = (abfd->arch_info->mach == bfd_mach_sh_dsp
   2318      1.1  christos 	     || abfd->arch_info->mach == bfd_mach_sh3_dsp);
   2319      1.1  christos   bfd_vma i;
   2320      1.1  christos 
   2321      1.1  christos   /* The SH4 has a Harvard architecture, hence aligning loads is not
   2322      1.1  christos      desirable.  In fact, it is counter-productive, since it interferes
   2323      1.1  christos      with the schedules generated by the compiler.  */
   2324      1.1  christos   if (abfd->arch_info->mach == bfd_mach_sh4)
   2325      1.1  christos     return TRUE;
   2326      1.1  christos 
   2327      1.1  christos   /* If we are linking sh[3]-dsp code, swap the FPU instructions for DSP
   2328      1.1  christos      instructions.  */
   2329      1.1  christos   if (dsp)
   2330      1.1  christos     {
   2331      1.1  christos       sh_opcodes[0xf].minor_opcodes = sh_dsp_opcodef;
   2332      1.1  christos       sh_opcodes[0xf].count = sizeof sh_dsp_opcodef / sizeof sh_dsp_opcodef;
   2333      1.1  christos     }
   2334      1.1  christos 
   2335      1.1  christos   /* Instructions should be aligned on 2 byte boundaries.  */
   2336      1.1  christos   if ((start & 1) == 1)
   2337      1.1  christos     ++start;
   2338      1.1  christos 
   2339      1.1  christos   /* Now look through the unaligned addresses.  */
   2340      1.1  christos   i = start;
   2341      1.1  christos   if ((i & 2) == 0)
   2342      1.1  christos     i += 2;
   2343      1.1  christos   for (; i < stop; i += 4)
   2344      1.1  christos     {
   2345      1.1  christos       unsigned int insn;
   2346      1.1  christos       const struct sh_opcode *op;
   2347      1.1  christos       unsigned int prev_insn = 0;
   2348      1.1  christos       const struct sh_opcode *prev_op = NULL;
   2349      1.1  christos 
   2350      1.1  christos       insn = bfd_get_16 (abfd, contents + i);
   2351      1.1  christos       op = sh_insn_info (insn);
   2352      1.1  christos       if (op == NULL
   2353      1.1  christos 	  || (op->flags & (LOAD | STORE)) == 0)
   2354      1.1  christos 	continue;
   2355      1.1  christos 
   2356      1.1  christos       /* This is a load or store which is not on a four byte boundary.  */
   2357      1.1  christos 
   2358      1.1  christos       while (*plabel < label_end && **plabel < i)
   2359      1.1  christos 	++*plabel;
   2360      1.1  christos 
   2361      1.1  christos       if (i > start)
   2362      1.1  christos 	{
   2363      1.1  christos 	  prev_insn = bfd_get_16 (abfd, contents + i - 2);
   2364      1.1  christos 	  /* If INSN is the field b of a parallel processing insn, it is not
   2365      1.1  christos 	     a load / store after all.  Note that the test here might mistake
   2366      1.1  christos 	     the field_b of a pcopy insn for the starting code of a parallel
   2367      1.1  christos 	     processing insn; this might miss a swapping opportunity, but at
   2368      1.1  christos 	     least we're on the safe side.  */
   2369      1.1  christos 	  if (dsp && (prev_insn & 0xfc00) == 0xf800)
   2370      1.1  christos 	    continue;
   2371      1.1  christos 
   2372      1.1  christos 	  /* Check if prev_insn is actually the field b of a parallel
   2373      1.1  christos 	     processing insn.  Again, this can give a spurious match
   2374      1.1  christos 	     after a pcopy.  */
   2375      1.1  christos 	  if (dsp && i - 2 > start)
   2376      1.1  christos 	    {
   2377      1.1  christos 	      unsigned pprev_insn = bfd_get_16 (abfd, contents + i - 4);
   2378      1.1  christos 
   2379      1.1  christos 	      if ((pprev_insn & 0xfc00) == 0xf800)
   2380      1.1  christos 		prev_op = NULL;
   2381      1.1  christos 	      else
   2382      1.1  christos 		prev_op = sh_insn_info (prev_insn);
   2383      1.1  christos 	    }
   2384      1.1  christos 	  else
   2385      1.1  christos 	    prev_op = sh_insn_info (prev_insn);
   2386      1.1  christos 
   2387      1.1  christos 	  /* If the load/store instruction is in a delay slot, we
   2388      1.1  christos 	     can't swap.  */
   2389      1.1  christos 	  if (prev_op == NULL
   2390      1.1  christos 	      || (prev_op->flags & DELAY) != 0)
   2391      1.1  christos 	    continue;
   2392      1.1  christos 	}
   2393      1.1  christos       if (i > start
   2394      1.1  christos 	  && (*plabel >= label_end || **plabel != i)
   2395      1.1  christos 	  && prev_op != NULL
   2396      1.1  christos 	  && (prev_op->flags & (LOAD | STORE)) == 0
   2397      1.1  christos 	  && ! sh_insns_conflict (prev_insn, prev_op, insn, op))
   2398      1.1  christos 	{
   2399      1.1  christos 	  bfd_boolean ok;
   2400      1.1  christos 
   2401      1.1  christos 	  /* The load/store instruction does not have a label, and
   2402      1.1  christos 	     there is a previous instruction; PREV_INSN is not
   2403      1.1  christos 	     itself a load/store instruction, and PREV_INSN and
   2404      1.1  christos 	     INSN do not conflict.  */
   2405      1.1  christos 
   2406      1.1  christos 	  ok = TRUE;
   2407      1.1  christos 
   2408      1.1  christos 	  if (i >= start + 4)
   2409      1.1  christos 	    {
   2410      1.1  christos 	      unsigned int prev2_insn;
   2411      1.1  christos 	      const struct sh_opcode *prev2_op;
   2412      1.1  christos 
   2413      1.1  christos 	      prev2_insn = bfd_get_16 (abfd, contents + i - 4);
   2414      1.1  christos 	      prev2_op = sh_insn_info (prev2_insn);
   2415      1.1  christos 
   2416      1.1  christos 	      /* If the instruction before PREV_INSN has a delay
   2417      1.1  christos 		 slot--that is, PREV_INSN is in a delay slot--we
   2418      1.1  christos 		 can not swap.  */
   2419      1.1  christos 	      if (prev2_op == NULL
   2420      1.1  christos 		  || (prev2_op->flags & DELAY) != 0)
   2421      1.1  christos 		ok = FALSE;
   2422      1.1  christos 
   2423      1.1  christos 	      /* If the instruction before PREV_INSN is a load,
   2424      1.1  christos 		 and it sets a register which INSN uses, then
   2425      1.1  christos 		 putting INSN immediately after PREV_INSN will
   2426      1.1  christos 		 cause a pipeline bubble, so there is no point to
   2427      1.1  christos 		 making the swap.  */
   2428      1.1  christos 	      if (ok
   2429      1.1  christos 		  && (prev2_op->flags & LOAD) != 0
   2430      1.1  christos 		  && sh_load_use (prev2_insn, prev2_op, insn, op))
   2431      1.1  christos 		ok = FALSE;
   2432      1.1  christos 	    }
   2433      1.1  christos 
   2434      1.1  christos 	  if (ok)
   2435      1.1  christos 	    {
   2436      1.1  christos 	      if (! (*swap) (abfd, sec, relocs, contents, i - 2))
   2437      1.1  christos 		return FALSE;
   2438      1.1  christos 	      *pswapped = TRUE;
   2439      1.1  christos 	      continue;
   2440      1.1  christos 	    }
   2441      1.1  christos 	}
   2442      1.1  christos 
   2443      1.1  christos       while (*plabel < label_end && **plabel < i + 2)
   2444      1.1  christos 	++*plabel;
   2445      1.1  christos 
   2446      1.1  christos       if (i + 2 < stop
   2447      1.1  christos 	  && (*plabel >= label_end || **plabel != i + 2))
   2448      1.1  christos 	{
   2449      1.1  christos 	  unsigned int next_insn;
   2450      1.1  christos 	  const struct sh_opcode *next_op;
   2451      1.1  christos 
   2452      1.1  christos 	  /* There is an instruction after the load/store
   2453      1.1  christos 	     instruction, and it does not have a label.  */
   2454      1.1  christos 	  next_insn = bfd_get_16 (abfd, contents + i + 2);
   2455      1.1  christos 	  next_op = sh_insn_info (next_insn);
   2456      1.1  christos 	  if (next_op != NULL
   2457      1.1  christos 	      && (next_op->flags & (LOAD | STORE)) == 0
   2458      1.1  christos 	      && ! sh_insns_conflict (insn, op, next_insn, next_op))
   2459      1.1  christos 	    {
   2460      1.1  christos 	      bfd_boolean ok;
   2461      1.1  christos 
   2462      1.1  christos 	      /* NEXT_INSN is not itself a load/store instruction,
   2463      1.1  christos 		 and it does not conflict with INSN.  */
   2464      1.1  christos 
   2465      1.1  christos 	      ok = TRUE;
   2466      1.1  christos 
   2467      1.1  christos 	      /* If PREV_INSN is a load, and it sets a register
   2468      1.1  christos 		 which NEXT_INSN uses, then putting NEXT_INSN
   2469      1.1  christos 		 immediately after PREV_INSN will cause a pipeline
   2470      1.1  christos 		 bubble, so there is no reason to make this swap.  */
   2471      1.1  christos 	      if (prev_op != NULL
   2472      1.1  christos 		  && (prev_op->flags & LOAD) != 0
   2473      1.1  christos 		  && sh_load_use (prev_insn, prev_op, next_insn, next_op))
   2474      1.1  christos 		ok = FALSE;
   2475      1.1  christos 
   2476      1.1  christos 	      /* If INSN is a load, and it sets a register which
   2477      1.1  christos 		 the insn after NEXT_INSN uses, then doing the
   2478      1.1  christos 		 swap will cause a pipeline bubble, so there is no
   2479      1.1  christos 		 reason to make the swap.  However, if the insn
   2480      1.1  christos 		 after NEXT_INSN is itself a load or store
   2481      1.1  christos 		 instruction, then it is misaligned, so
   2482      1.1  christos 		 optimistically hope that it will be swapped
   2483      1.1  christos 		 itself, and just live with the pipeline bubble if
   2484      1.1  christos 		 it isn't.  */
   2485      1.1  christos 	      if (ok
   2486      1.1  christos 		  && i + 4 < stop
   2487      1.1  christos 		  && (op->flags & LOAD) != 0)
   2488      1.1  christos 		{
   2489      1.1  christos 		  unsigned int next2_insn;
   2490      1.1  christos 		  const struct sh_opcode *next2_op;
   2491      1.1  christos 
   2492      1.1  christos 		  next2_insn = bfd_get_16 (abfd, contents + i + 4);
   2493      1.1  christos 		  next2_op = sh_insn_info (next2_insn);
   2494      1.1  christos 		  if (next2_op == NULL
   2495      1.1  christos 		      || ((next2_op->flags & (LOAD | STORE)) == 0
   2496      1.1  christos 			  && sh_load_use (insn, op, next2_insn, next2_op)))
   2497      1.1  christos 		    ok = FALSE;
   2498      1.1  christos 		}
   2499      1.1  christos 
   2500      1.1  christos 	      if (ok)
   2501      1.1  christos 		{
   2502      1.1  christos 		  if (! (*swap) (abfd, sec, relocs, contents, i))
   2503      1.1  christos 		    return FALSE;
   2504      1.1  christos 		  *pswapped = TRUE;
   2505      1.1  christos 		  continue;
   2506      1.1  christos 		}
   2507      1.1  christos 	    }
   2508      1.1  christos 	}
   2509      1.1  christos     }
   2510      1.1  christos 
   2511      1.1  christos   return TRUE;
   2512      1.1  christos }
   2513      1.1  christos #endif /* not COFF_IMAGE_WITH_PE */
   2514      1.1  christos 
   2515      1.1  christos /* Swap two SH instructions.  */
   2516  1.1.1.2  christos 
   2517  1.1.1.2  christos static bfd_boolean
   2518  1.1.1.2  christos sh_swap_insns (bfd *      abfd,
   2519  1.1.1.2  christos 	       asection * sec,
   2520  1.1.1.2  christos 	       void *     relocs,
   2521      1.1  christos 	       bfd_byte * contents,
   2522      1.1  christos 	       bfd_vma    addr)
   2523      1.1  christos {
   2524      1.1  christos   struct internal_reloc *internal_relocs = (struct internal_reloc *) relocs;
   2525      1.1  christos   unsigned short i1, i2;
   2526      1.1  christos   struct internal_reloc *irel, *irelend;
   2527      1.1  christos 
   2528      1.1  christos   /* Swap the instructions themselves.  */
   2529      1.1  christos   i1 = bfd_get_16 (abfd, contents + addr);
   2530      1.1  christos   i2 = bfd_get_16 (abfd, contents + addr + 2);
   2531      1.1  christos   bfd_put_16 (abfd, (bfd_vma) i2, contents + addr);
   2532      1.1  christos   bfd_put_16 (abfd, (bfd_vma) i1, contents + addr + 2);
   2533      1.1  christos 
   2534      1.1  christos   /* Adjust all reloc addresses.  */
   2535      1.1  christos   irelend = internal_relocs + sec->reloc_count;
   2536      1.1  christos   for (irel = internal_relocs; irel < irelend; irel++)
   2537      1.1  christos     {
   2538      1.1  christos       int type, add;
   2539      1.1  christos 
   2540      1.1  christos       /* There are a few special types of relocs that we don't want to
   2541      1.1  christos          adjust.  These relocs do not apply to the instruction itself,
   2542      1.1  christos          but are only associated with the address.  */
   2543      1.1  christos       type = irel->r_type;
   2544      1.1  christos       if (type == R_SH_ALIGN
   2545      1.1  christos 	  || type == R_SH_CODE
   2546      1.1  christos 	  || type == R_SH_DATA
   2547      1.1  christos 	  || type == R_SH_LABEL)
   2548      1.1  christos 	continue;
   2549      1.1  christos 
   2550      1.1  christos       /* If an R_SH_USES reloc points to one of the addresses being
   2551      1.1  christos          swapped, we must adjust it.  It would be incorrect to do this
   2552      1.1  christos          for a jump, though, since we want to execute both
   2553      1.1  christos          instructions after the jump.  (We have avoided swapping
   2554      1.1  christos          around a label, so the jump will not wind up executing an
   2555      1.1  christos          instruction it shouldn't).  */
   2556      1.1  christos       if (type == R_SH_USES)
   2557      1.1  christos 	{
   2558      1.1  christos 	  bfd_vma off;
   2559      1.1  christos 
   2560      1.1  christos 	  off = irel->r_vaddr - sec->vma + 4 + irel->r_offset;
   2561      1.1  christos 	  if (off == addr)
   2562      1.1  christos 	    irel->r_offset += 2;
   2563      1.1  christos 	  else if (off == addr + 2)
   2564      1.1  christos 	    irel->r_offset -= 2;
   2565      1.1  christos 	}
   2566      1.1  christos 
   2567      1.1  christos       if (irel->r_vaddr - sec->vma == addr)
   2568      1.1  christos 	{
   2569      1.1  christos 	  irel->r_vaddr += 2;
   2570      1.1  christos 	  add = -2;
   2571      1.1  christos 	}
   2572      1.1  christos       else if (irel->r_vaddr - sec->vma == addr + 2)
   2573      1.1  christos 	{
   2574      1.1  christos 	  irel->r_vaddr -= 2;
   2575      1.1  christos 	  add = 2;
   2576      1.1  christos 	}
   2577      1.1  christos       else
   2578      1.1  christos 	add = 0;
   2579      1.1  christos 
   2580      1.1  christos       if (add != 0)
   2581      1.1  christos 	{
   2582      1.1  christos 	  bfd_byte *loc;
   2583      1.1  christos 	  unsigned short insn, oinsn;
   2584      1.1  christos 	  bfd_boolean overflow;
   2585      1.1  christos 
   2586      1.1  christos 	  loc = contents + irel->r_vaddr - sec->vma;
   2587      1.1  christos 	  overflow = FALSE;
   2588      1.1  christos 	  switch (type)
   2589      1.1  christos 	    {
   2590      1.1  christos 	    default:
   2591      1.1  christos 	      break;
   2592      1.1  christos 
   2593      1.1  christos 	    case R_SH_PCDISP8BY2:
   2594      1.1  christos 	    case R_SH_PCRELIMM8BY2:
   2595      1.1  christos 	      insn = bfd_get_16 (abfd, loc);
   2596      1.1  christos 	      oinsn = insn;
   2597      1.1  christos 	      insn += add / 2;
   2598      1.1  christos 	      if ((oinsn & 0xff00) != (insn & 0xff00))
   2599      1.1  christos 		overflow = TRUE;
   2600      1.1  christos 	      bfd_put_16 (abfd, (bfd_vma) insn, loc);
   2601      1.1  christos 	      break;
   2602      1.1  christos 
   2603      1.1  christos 	    case R_SH_PCDISP:
   2604      1.1  christos 	      insn = bfd_get_16 (abfd, loc);
   2605      1.1  christos 	      oinsn = insn;
   2606      1.1  christos 	      insn += add / 2;
   2607      1.1  christos 	      if ((oinsn & 0xf000) != (insn & 0xf000))
   2608      1.1  christos 		overflow = TRUE;
   2609      1.1  christos 	      bfd_put_16 (abfd, (bfd_vma) insn, loc);
   2610      1.1  christos 	      break;
   2611      1.1  christos 
   2612      1.1  christos 	    case R_SH_PCRELIMM8BY4:
   2613      1.1  christos 	      /* This reloc ignores the least significant 3 bits of
   2614      1.1  christos                  the program counter before adding in the offset.
   2615      1.1  christos                  This means that if ADDR is at an even address, the
   2616      1.1  christos                  swap will not affect the offset.  If ADDR is an at an
   2617      1.1  christos                  odd address, then the instruction will be crossing a
   2618      1.1  christos                  four byte boundary, and must be adjusted.  */
   2619      1.1  christos 	      if ((addr & 3) != 0)
   2620      1.1  christos 		{
   2621      1.1  christos 		  insn = bfd_get_16 (abfd, loc);
   2622      1.1  christos 		  oinsn = insn;
   2623      1.1  christos 		  insn += add / 2;
   2624      1.1  christos 		  if ((oinsn & 0xff00) != (insn & 0xff00))
   2625      1.1  christos 		    overflow = TRUE;
   2626      1.1  christos 		  bfd_put_16 (abfd, (bfd_vma) insn, loc);
   2627      1.1  christos 		}
   2628      1.1  christos 
   2629      1.1  christos 	      break;
   2630      1.1  christos 	    }
   2631      1.1  christos 
   2632      1.1  christos 	  if (overflow)
   2633      1.1  christos 	    {
   2634      1.1  christos 	      ((*_bfd_error_handler)
   2635      1.1  christos 	       ("%B: 0x%lx: fatal: reloc overflow while relaxing",
   2636      1.1  christos 		abfd, (unsigned long) irel->r_vaddr));
   2637      1.1  christos 	      bfd_set_error (bfd_error_bad_value);
   2638      1.1  christos 	      return FALSE;
   2639      1.1  christos 	    }
   2640      1.1  christos 	}
   2641      1.1  christos     }
   2642      1.1  christos 
   2643  1.1.1.2  christos   return TRUE;
   2644  1.1.1.2  christos }
   2645  1.1.1.2  christos 
   2646  1.1.1.2  christos /* Look for loads and stores which we can align to four byte
   2647  1.1.1.2  christos    boundaries.  See the longer comment above sh_relax_section for why
   2648  1.1.1.2  christos    this is desirable.  This sets *PSWAPPED if some instruction was
   2649  1.1.1.2  christos    swapped.  */
   2650  1.1.1.2  christos 
   2651  1.1.1.2  christos static bfd_boolean
   2652  1.1.1.2  christos sh_align_loads (bfd *abfd,
   2653  1.1.1.2  christos 		asection *sec,
   2654  1.1.1.2  christos 		struct internal_reloc *internal_relocs,
   2655  1.1.1.2  christos 		bfd_byte *contents,
   2656  1.1.1.2  christos 		bfd_boolean *pswapped)
   2657  1.1.1.2  christos {
   2658  1.1.1.2  christos   struct internal_reloc *irel, *irelend;
   2659  1.1.1.2  christos   bfd_vma *labels = NULL;
   2660  1.1.1.2  christos   bfd_vma *label, *label_end;
   2661  1.1.1.2  christos   bfd_size_type amt;
   2662  1.1.1.2  christos 
   2663  1.1.1.2  christos   *pswapped = FALSE;
   2664  1.1.1.2  christos 
   2665  1.1.1.2  christos   irelend = internal_relocs + sec->reloc_count;
   2666  1.1.1.2  christos 
   2667  1.1.1.2  christos   /* Get all the addresses with labels on them.  */
   2668  1.1.1.2  christos   amt = (bfd_size_type) sec->reloc_count * sizeof (bfd_vma);
   2669  1.1.1.2  christos   labels = (bfd_vma *) bfd_malloc (amt);
   2670  1.1.1.2  christos   if (labels == NULL)
   2671  1.1.1.2  christos     goto error_return;
   2672  1.1.1.2  christos   label_end = labels;
   2673  1.1.1.2  christos   for (irel = internal_relocs; irel < irelend; irel++)
   2674  1.1.1.2  christos     {
   2675  1.1.1.2  christos       if (irel->r_type == R_SH_LABEL)
   2676  1.1.1.2  christos 	{
   2677  1.1.1.2  christos 	  *label_end = irel->r_vaddr - sec->vma;
   2678  1.1.1.2  christos 	  ++label_end;
   2679  1.1.1.2  christos 	}
   2680  1.1.1.2  christos     }
   2681  1.1.1.2  christos 
   2682  1.1.1.2  christos   /* Note that the assembler currently always outputs relocs in
   2683  1.1.1.2  christos      address order.  If that ever changes, this code will need to sort
   2684  1.1.1.2  christos      the label values and the relocs.  */
   2685  1.1.1.2  christos 
   2686  1.1.1.2  christos   label = labels;
   2687  1.1.1.2  christos 
   2688  1.1.1.2  christos   for (irel = internal_relocs; irel < irelend; irel++)
   2689  1.1.1.2  christos     {
   2690  1.1.1.2  christos       bfd_vma start, stop;
   2691  1.1.1.2  christos 
   2692  1.1.1.2  christos       if (irel->r_type != R_SH_CODE)
   2693  1.1.1.2  christos 	continue;
   2694  1.1.1.2  christos 
   2695  1.1.1.2  christos       start = irel->r_vaddr - sec->vma;
   2696  1.1.1.2  christos 
   2697  1.1.1.2  christos       for (irel++; irel < irelend; irel++)
   2698  1.1.1.2  christos 	if (irel->r_type == R_SH_DATA)
   2699  1.1.1.2  christos 	  break;
   2700  1.1.1.2  christos       if (irel < irelend)
   2701  1.1.1.2  christos 	stop = irel->r_vaddr - sec->vma;
   2702  1.1.1.2  christos       else
   2703  1.1.1.2  christos 	stop = sec->size;
   2704  1.1.1.2  christos 
   2705  1.1.1.2  christos       if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_swap_insns,
   2706  1.1.1.2  christos 				     internal_relocs, &label,
   2707  1.1.1.2  christos 				     label_end, start, stop, pswapped))
   2708  1.1.1.2  christos 	goto error_return;
   2709  1.1.1.2  christos     }
   2710  1.1.1.2  christos 
   2711  1.1.1.2  christos   free (labels);
   2712  1.1.1.2  christos 
   2713  1.1.1.2  christos   return TRUE;
   2714  1.1.1.2  christos 
   2715  1.1.1.2  christos  error_return:
   2716  1.1.1.2  christos   if (labels != NULL)
   2717  1.1.1.2  christos     free (labels);
   2718      1.1  christos   return FALSE;
   2719      1.1  christos }
   2720      1.1  christos 
   2721      1.1  christos /* This is a modification of _bfd_coff_generic_relocate_section, which
   2723  1.1.1.2  christos    will handle SH relaxing.  */
   2724  1.1.1.2  christos 
   2725  1.1.1.2  christos static bfd_boolean
   2726  1.1.1.2  christos sh_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
   2727  1.1.1.2  christos 		     struct bfd_link_info *info,
   2728  1.1.1.2  christos 		     bfd *input_bfd,
   2729  1.1.1.2  christos 		     asection *input_section,
   2730  1.1.1.2  christos 		     bfd_byte *contents,
   2731      1.1  christos 		     struct internal_reloc *relocs,
   2732      1.1  christos 		     struct internal_syment *syms,
   2733      1.1  christos 		     asection **sections)
   2734      1.1  christos {
   2735      1.1  christos   struct internal_reloc *rel;
   2736      1.1  christos   struct internal_reloc *relend;
   2737      1.1  christos 
   2738      1.1  christos   rel = relocs;
   2739      1.1  christos   relend = rel + input_section->reloc_count;
   2740      1.1  christos   for (; rel < relend; rel++)
   2741      1.1  christos     {
   2742      1.1  christos       long symndx;
   2743      1.1  christos       struct coff_link_hash_entry *h;
   2744      1.1  christos       struct internal_syment *sym;
   2745      1.1  christos       bfd_vma addend;
   2746      1.1  christos       bfd_vma val;
   2747      1.1  christos       reloc_howto_type *howto;
   2748      1.1  christos       bfd_reloc_status_type rstat;
   2749      1.1  christos 
   2750      1.1  christos       /* Almost all relocs have to do with relaxing.  If any work must
   2751      1.1  christos          be done for them, it has been done in sh_relax_section.  */
   2752      1.1  christos       if (rel->r_type != R_SH_IMM32
   2753      1.1  christos #ifdef COFF_WITH_PE
   2754      1.1  christos 	  && rel->r_type != R_SH_IMM32CE
   2755      1.1  christos 	  && rel->r_type != R_SH_IMAGEBASE
   2756      1.1  christos #endif
   2757      1.1  christos 	  && rel->r_type != R_SH_PCDISP)
   2758      1.1  christos 	continue;
   2759      1.1  christos 
   2760      1.1  christos       symndx = rel->r_symndx;
   2761      1.1  christos 
   2762      1.1  christos       if (symndx == -1)
   2763      1.1  christos 	{
   2764      1.1  christos 	  h = NULL;
   2765      1.1  christos 	  sym = NULL;
   2766      1.1  christos 	}
   2767      1.1  christos       else
   2768      1.1  christos 	{
   2769      1.1  christos 	  if (symndx < 0
   2770      1.1  christos 	      || (unsigned long) symndx >= obj_raw_syment_count (input_bfd))
   2771      1.1  christos 	    {
   2772      1.1  christos 	      (*_bfd_error_handler)
   2773      1.1  christos 		("%B: illegal symbol index %ld in relocs",
   2774      1.1  christos 		 input_bfd, symndx);
   2775      1.1  christos 	      bfd_set_error (bfd_error_bad_value);
   2776      1.1  christos 	      return FALSE;
   2777      1.1  christos 	    }
   2778      1.1  christos 	  h = obj_coff_sym_hashes (input_bfd)[symndx];
   2779      1.1  christos 	  sym = syms + symndx;
   2780      1.1  christos 	}
   2781      1.1  christos 
   2782      1.1  christos       if (sym != NULL && sym->n_scnum != 0)
   2783      1.1  christos 	addend = - sym->n_value;
   2784      1.1  christos       else
   2785      1.1  christos 	addend = 0;
   2786      1.1  christos 
   2787      1.1  christos       if (rel->r_type == R_SH_PCDISP)
   2788      1.1  christos 	addend -= 4;
   2789      1.1  christos 
   2790      1.1  christos       if (rel->r_type >= SH_COFF_HOWTO_COUNT)
   2791      1.1  christos 	howto = NULL;
   2792      1.1  christos       else
   2793      1.1  christos 	howto = &sh_coff_howtos[rel->r_type];
   2794      1.1  christos 
   2795      1.1  christos       if (howto == NULL)
   2796      1.1  christos 	{
   2797      1.1  christos 	  bfd_set_error (bfd_error_bad_value);
   2798      1.1  christos 	  return FALSE;
   2799      1.1  christos 	}
   2800      1.1  christos 
   2801      1.1  christos #ifdef COFF_WITH_PE
   2802      1.1  christos       if (rel->r_type == R_SH_IMAGEBASE)
   2803      1.1  christos 	addend -= pe_data (input_section->output_section->owner)->pe_opthdr.ImageBase;
   2804      1.1  christos #endif
   2805      1.1  christos 
   2806      1.1  christos       val = 0;
   2807      1.1  christos 
   2808      1.1  christos       if (h == NULL)
   2809      1.1  christos 	{
   2810      1.1  christos 	  asection *sec;
   2811      1.1  christos 
   2812      1.1  christos 	  /* There is nothing to do for an internal PCDISP reloc.  */
   2813      1.1  christos 	  if (rel->r_type == R_SH_PCDISP)
   2814      1.1  christos 	    continue;
   2815      1.1  christos 
   2816      1.1  christos 	  if (symndx == -1)
   2817      1.1  christos 	    {
   2818      1.1  christos 	      sec = bfd_abs_section_ptr;
   2819      1.1  christos 	      val = 0;
   2820      1.1  christos 	    }
   2821      1.1  christos 	  else
   2822      1.1  christos 	    {
   2823      1.1  christos 	      sec = sections[symndx];
   2824      1.1  christos               val = (sec->output_section->vma
   2825      1.1  christos 		     + sec->output_offset
   2826      1.1  christos 		     + sym->n_value
   2827      1.1  christos 		     - sec->vma);
   2828      1.1  christos 	    }
   2829      1.1  christos 	}
   2830      1.1  christos       else
   2831      1.1  christos 	{
   2832      1.1  christos 	  if (h->root.type == bfd_link_hash_defined
   2833      1.1  christos 	      || h->root.type == bfd_link_hash_defweak)
   2834      1.1  christos 	    {
   2835      1.1  christos 	      asection *sec;
   2836      1.1  christos 
   2837      1.1  christos 	      sec = h->root.u.def.section;
   2838      1.1  christos 	      val = (h->root.u.def.value
   2839      1.1  christos 		     + sec->output_section->vma
   2840      1.1  christos 		     + sec->output_offset);
   2841      1.1  christos 	    }
   2842      1.1  christos 	  else if (! info->relocatable)
   2843      1.1  christos 	    {
   2844      1.1  christos 	      if (! ((*info->callbacks->undefined_symbol)
   2845      1.1  christos 		     (info, h->root.root.string, input_bfd, input_section,
   2846      1.1  christos 		      rel->r_vaddr - input_section->vma, TRUE)))
   2847      1.1  christos 		return FALSE;
   2848      1.1  christos 	    }
   2849      1.1  christos 	}
   2850      1.1  christos 
   2851      1.1  christos       rstat = _bfd_final_link_relocate (howto, input_bfd, input_section,
   2852      1.1  christos 					contents,
   2853      1.1  christos 					rel->r_vaddr - input_section->vma,
   2854      1.1  christos 					val, addend);
   2855      1.1  christos 
   2856      1.1  christos       switch (rstat)
   2857      1.1  christos 	{
   2858      1.1  christos 	default:
   2859      1.1  christos 	  abort ();
   2860      1.1  christos 	case bfd_reloc_ok:
   2861      1.1  christos 	  break;
   2862      1.1  christos 	case bfd_reloc_overflow:
   2863      1.1  christos 	  {
   2864      1.1  christos 	    const char *name;
   2865      1.1  christos 	    char buf[SYMNMLEN + 1];
   2866      1.1  christos 
   2867      1.1  christos 	    if (symndx == -1)
   2868      1.1  christos 	      name = "*ABS*";
   2869      1.1  christos 	    else if (h != NULL)
   2870      1.1  christos 	      name = NULL;
   2871      1.1  christos 	    else if (sym->_n._n_n._n_zeroes == 0
   2872      1.1  christos 		     && sym->_n._n_n._n_offset != 0)
   2873      1.1  christos 	      name = obj_coff_strings (input_bfd) + sym->_n._n_n._n_offset;
   2874      1.1  christos 	    else
   2875      1.1  christos 	      {
   2876      1.1  christos  		strncpy (buf, sym->_n._n_name, SYMNMLEN);
   2877      1.1  christos 		buf[SYMNMLEN] = '\0';
   2878      1.1  christos 		name = buf;
   2879      1.1  christos 	      }
   2880      1.1  christos 
   2881      1.1  christos 	    if (! ((*info->callbacks->reloc_overflow)
   2882      1.1  christos 		   (info, (h ? &h->root : NULL), name, howto->name,
   2883      1.1  christos 		    (bfd_vma) 0, input_bfd, input_section,
   2884      1.1  christos 		    rel->r_vaddr - input_section->vma)))
   2885      1.1  christos 	      return FALSE;
   2886      1.1  christos 	  }
   2887      1.1  christos 	}
   2888      1.1  christos     }
   2889      1.1  christos 
   2890      1.1  christos   return TRUE;
   2891      1.1  christos }
   2892      1.1  christos 
   2893      1.1  christos /* This is a version of bfd_generic_get_relocated_section_contents
   2894  1.1.1.2  christos    which uses sh_relocate_section.  */
   2895  1.1.1.2  christos 
   2896  1.1.1.2  christos static bfd_byte *
   2897  1.1.1.2  christos sh_coff_get_relocated_section_contents (bfd *output_bfd,
   2898  1.1.1.2  christos 					struct bfd_link_info *link_info,
   2899  1.1.1.2  christos 					struct bfd_link_order *link_order,
   2900      1.1  christos 					bfd_byte *data,
   2901      1.1  christos 					bfd_boolean relocatable,
   2902      1.1  christos 					asymbol **symbols)
   2903      1.1  christos {
   2904      1.1  christos   asection *input_section = link_order->u.indirect.section;
   2905      1.1  christos   bfd *input_bfd = input_section->owner;
   2906      1.1  christos   asection **sections = NULL;
   2907      1.1  christos   struct internal_reloc *internal_relocs = NULL;
   2908      1.1  christos   struct internal_syment *internal_syms = NULL;
   2909      1.1  christos 
   2910      1.1  christos   /* We only need to handle the case of relaxing, or of having a
   2911      1.1  christos      particular set of section contents, specially.  */
   2912      1.1  christos   if (relocatable
   2913      1.1  christos       || coff_section_data (input_bfd, input_section) == NULL
   2914      1.1  christos       || coff_section_data (input_bfd, input_section)->contents == NULL)
   2915      1.1  christos     return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
   2916      1.1  christos 						       link_order, data,
   2917      1.1  christos 						       relocatable,
   2918      1.1  christos 						       symbols);
   2919      1.1  christos 
   2920      1.1  christos   memcpy (data, coff_section_data (input_bfd, input_section)->contents,
   2921      1.1  christos 	  (size_t) input_section->size);
   2922      1.1  christos 
   2923      1.1  christos   if ((input_section->flags & SEC_RELOC) != 0
   2924      1.1  christos       && input_section->reloc_count > 0)
   2925      1.1  christos     {
   2926      1.1  christos       bfd_size_type symesz = bfd_coff_symesz (input_bfd);
   2927      1.1  christos       bfd_byte *esym, *esymend;
   2928      1.1  christos       struct internal_syment *isymp;
   2929      1.1  christos       asection **secpp;
   2930      1.1  christos       bfd_size_type amt;
   2931      1.1  christos 
   2932      1.1  christos       if (! _bfd_coff_get_external_symbols (input_bfd))
   2933      1.1  christos 	goto error_return;
   2934      1.1  christos 
   2935      1.1  christos       internal_relocs = (_bfd_coff_read_internal_relocs
   2936      1.1  christos 			 (input_bfd, input_section, FALSE, (bfd_byte *) NULL,
   2937      1.1  christos 			  FALSE, (struct internal_reloc *) NULL));
   2938      1.1  christos       if (internal_relocs == NULL)
   2939      1.1  christos 	goto error_return;
   2940      1.1  christos 
   2941      1.1  christos       amt = obj_raw_syment_count (input_bfd);
   2942      1.1  christos       amt *= sizeof (struct internal_syment);
   2943      1.1  christos       internal_syms = (struct internal_syment *) bfd_malloc (amt);
   2944      1.1  christos       if (internal_syms == NULL)
   2945      1.1  christos 	goto error_return;
   2946      1.1  christos 
   2947      1.1  christos       amt = obj_raw_syment_count (input_bfd);
   2948      1.1  christos       amt *= sizeof (asection *);
   2949      1.1  christos       sections = (asection **) bfd_malloc (amt);
   2950      1.1  christos       if (sections == NULL)
   2951      1.1  christos 	goto error_return;
   2952      1.1  christos 
   2953      1.1  christos       isymp = internal_syms;
   2954      1.1  christos       secpp = sections;
   2955      1.1  christos       esym = (bfd_byte *) obj_coff_external_syms (input_bfd);
   2956  1.1.1.2  christos       esymend = esym + obj_raw_syment_count (input_bfd) * symesz;
   2957      1.1  christos       while (esym < esymend)
   2958      1.1  christos 	{
   2959      1.1  christos 	  bfd_coff_swap_sym_in (input_bfd, esym, isymp);
   2960      1.1  christos 
   2961      1.1  christos 	  if (isymp->n_scnum != 0)
   2962      1.1  christos 	    *secpp = coff_section_from_bfd_index (input_bfd, isymp->n_scnum);
   2963      1.1  christos 	  else
   2964      1.1  christos 	    {
   2965      1.1  christos 	      if (isymp->n_value == 0)
   2966      1.1  christos 		*secpp = bfd_und_section_ptr;
   2967      1.1  christos 	      else
   2968      1.1  christos 		*secpp = bfd_com_section_ptr;
   2969      1.1  christos 	    }
   2970      1.1  christos 
   2971      1.1  christos 	  esym += (isymp->n_numaux + 1) * symesz;
   2972      1.1  christos 	  secpp += isymp->n_numaux + 1;
   2973      1.1  christos 	  isymp += isymp->n_numaux + 1;
   2974      1.1  christos 	}
   2975      1.1  christos 
   2976      1.1  christos       if (! sh_relocate_section (output_bfd, link_info, input_bfd,
   2977      1.1  christos 				 input_section, data, internal_relocs,
   2978      1.1  christos 				 internal_syms, sections))
   2979      1.1  christos 	goto error_return;
   2980      1.1  christos 
   2981      1.1  christos       free (sections);
   2982      1.1  christos       sections = NULL;
   2983      1.1  christos       free (internal_syms);
   2984      1.1  christos       internal_syms = NULL;
   2985      1.1  christos       free (internal_relocs);
   2986      1.1  christos       internal_relocs = NULL;
   2987      1.1  christos     }
   2988      1.1  christos 
   2989      1.1  christos   return data;
   2990      1.1  christos 
   2991      1.1  christos  error_return:
   2992      1.1  christos   if (internal_relocs != NULL)
   2993      1.1  christos     free (internal_relocs);
   2994      1.1  christos   if (internal_syms != NULL)
   2995      1.1  christos     free (internal_syms);
   2996      1.1  christos   if (sections != NULL)
   2997      1.1  christos     free (sections);
   2998      1.1  christos   return NULL;
   2999      1.1  christos }
   3000      1.1  christos 
   3001  1.1.1.3  christos /* The target vectors.  */
   3002      1.1  christos 
   3003      1.1  christos #ifndef TARGET_SHL_SYM
   3004      1.1  christos CREATE_BIG_COFF_TARGET_VEC (sh_coff_vec, "coff-sh", BFD_IS_RELAXABLE, 0, '_', NULL, COFF_SWAP_TABLE)
   3005      1.1  christos #endif
   3006      1.1  christos 
   3007  1.1.1.3  christos #ifdef TARGET_SHL_SYM
   3008      1.1  christos #define TARGET_SYM TARGET_SHL_SYM
   3009      1.1  christos #else
   3010      1.1  christos #define TARGET_SYM sh_coff_le_vec
   3011      1.1  christos #endif
   3012      1.1  christos 
   3013      1.1  christos #ifndef TARGET_SHL_NAME
   3014      1.1  christos #define TARGET_SHL_NAME "coff-shl"
   3015      1.1  christos #endif
   3016      1.1  christos 
   3017      1.1  christos #ifdef COFF_WITH_PE
   3018      1.1  christos CREATE_LITTLE_COFF_TARGET_VEC (TARGET_SYM, TARGET_SHL_NAME, BFD_IS_RELAXABLE,
   3019      1.1  christos 			       SEC_CODE | SEC_DATA, '_', NULL, COFF_SWAP_TABLE);
   3020      1.1  christos #else
   3021      1.1  christos CREATE_LITTLE_COFF_TARGET_VEC (TARGET_SYM, TARGET_SHL_NAME, BFD_IS_RELAXABLE,
   3022      1.1  christos 			       0, '_', NULL, COFF_SWAP_TABLE)
   3023  1.1.1.2  christos #endif
   3024      1.1  christos 
   3025      1.1  christos #ifndef TARGET_SHL_SYM
   3026      1.1  christos 
   3027      1.1  christos /* Some people want versions of the SH COFF target which do not align
   3028      1.1  christos    to 16 byte boundaries.  We implement that by adding a couple of new
   3029      1.1  christos    target vectors.  These are just like the ones above, but they
   3030      1.1  christos    change the default section alignment.  To generate them in the
   3031      1.1  christos    assembler, use -small.  To use them in the linker, use -b
   3032      1.1  christos    coff-sh{l}-small and -oformat coff-sh{l}-small.
   3033      1.1  christos 
   3034      1.1  christos    Yes, this is a horrible hack.  A general solution for setting
   3035      1.1  christos    section alignment in COFF is rather complex.  ELF handles this
   3036      1.1  christos    correctly.  */
   3037      1.1  christos 
   3038      1.1  christos /* Only recognize the small versions if the target was not defaulted.
   3039  1.1.1.2  christos    Otherwise we won't recognize the non default endianness.  */
   3040      1.1  christos 
   3041      1.1  christos static const bfd_target *
   3042      1.1  christos coff_small_object_p (bfd *abfd)
   3043      1.1  christos {
   3044      1.1  christos   if (abfd->target_defaulted)
   3045      1.1  christos     {
   3046      1.1  christos       bfd_set_error (bfd_error_wrong_format);
   3047      1.1  christos       return NULL;
   3048      1.1  christos     }
   3049      1.1  christos   return coff_object_p (abfd);
   3050      1.1  christos }
   3051      1.1  christos 
   3052  1.1.1.2  christos /* Set the section alignment for the small versions.  */
   3053      1.1  christos 
   3054      1.1  christos static bfd_boolean
   3055      1.1  christos coff_small_new_section_hook (bfd *abfd, asection *section)
   3056      1.1  christos {
   3057      1.1  christos   if (! coff_new_section_hook (abfd, section))
   3058      1.1  christos     return FALSE;
   3059      1.1  christos 
   3060      1.1  christos   /* We must align to at least a four byte boundary, because longword
   3061      1.1  christos      accesses must be on a four byte boundary.  */
   3062      1.1  christos   if (section->alignment_power == COFF_DEFAULT_SECTION_ALIGNMENT_POWER)
   3063      1.1  christos     section->alignment_power = 2;
   3064      1.1  christos 
   3065      1.1  christos   return TRUE;
   3066      1.1  christos }
   3067      1.1  christos 
   3068      1.1  christos /* This is copied from bfd_coff_std_swap_table so that we can change
   3069      1.1  christos    the default section alignment power.  */
   3070      1.1  christos 
   3071      1.1  christos static bfd_coff_backend_data bfd_coff_small_swap_table =
   3072      1.1  christos {
   3073      1.1  christos   coff_swap_aux_in, coff_swap_sym_in, coff_swap_lineno_in,
   3074      1.1  christos   coff_swap_aux_out, coff_swap_sym_out,
   3075      1.1  christos   coff_swap_lineno_out, coff_swap_reloc_out,
   3076      1.1  christos   coff_swap_filehdr_out, coff_swap_aouthdr_out,
   3077      1.1  christos   coff_swap_scnhdr_out,
   3078      1.1  christos   FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
   3079      1.1  christos #ifdef COFF_LONG_FILENAMES
   3080      1.1  christos   TRUE,
   3081      1.1  christos #else
   3082      1.1  christos   FALSE,
   3083      1.1  christos #endif
   3084      1.1  christos   COFF_DEFAULT_LONG_SECTION_NAMES,
   3085      1.1  christos   2,
   3086      1.1  christos #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
   3087      1.1  christos   TRUE,
   3088      1.1  christos #else
   3089      1.1  christos   FALSE,
   3090      1.1  christos #endif
   3091      1.1  christos #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
   3092      1.1  christos   4,
   3093  1.1.1.3  christos #else
   3094      1.1  christos   2,
   3095      1.1  christos #endif
   3096      1.1  christos   32768,
   3097      1.1  christos   coff_swap_filehdr_in, coff_swap_aouthdr_in, coff_swap_scnhdr_in,
   3098      1.1  christos   coff_swap_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
   3099      1.1  christos   coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
   3100      1.1  christos   coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
   3101      1.1  christos   coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
   3102      1.1  christos   coff_classify_symbol, coff_compute_section_file_positions,
   3103      1.1  christos   coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
   3104      1.1  christos   coff_adjust_symndx, coff_link_add_one_symbol,
   3105      1.1  christos   coff_link_output_has_begun, coff_final_link_postscript,
   3106      1.1  christos   bfd_pe_print_pdata
   3107      1.1  christos };
   3108      1.1  christos 
   3109      1.1  christos #define coff_small_close_and_cleanup \
   3110      1.1  christos   coff_close_and_cleanup
   3111      1.1  christos #define coff_small_bfd_free_cached_info \
   3112      1.1  christos   coff_bfd_free_cached_info
   3113      1.1  christos #define coff_small_get_section_contents \
   3114      1.1  christos   coff_get_section_contents
   3115  1.1.1.3  christos #define coff_small_get_section_contents_in_window \
   3116      1.1  christos   coff_get_section_contents_in_window
   3117  1.1.1.3  christos 
   3118      1.1  christos extern const bfd_target sh_coff_small_le_vec;
   3119      1.1  christos 
   3120      1.1  christos const bfd_target sh_coff_small_vec =
   3121      1.1  christos {
   3122      1.1  christos   "coff-sh-small",		/* name */
   3123      1.1  christos   bfd_target_coff_flavour,
   3124      1.1  christos   BFD_ENDIAN_BIG,		/* data byte order is big */
   3125      1.1  christos   BFD_ENDIAN_BIG,		/* header byte order is big */
   3126      1.1  christos 
   3127      1.1  christos   (HAS_RELOC | EXEC_P |		/* object flags */
   3128      1.1  christos    HAS_LINENO | HAS_DEBUG |
   3129      1.1  christos    HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE),
   3130      1.1  christos 
   3131      1.1  christos   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),
   3132  1.1.1.2  christos   '_',				/* leading symbol underscore */
   3133      1.1  christos   '/',				/* ar_pad_char */
   3134      1.1  christos   15,				/* ar_max_namelen */
   3135      1.1  christos   0,				/* match priority.  */
   3136      1.1  christos   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
   3137      1.1  christos   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
   3138      1.1  christos   bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
   3139      1.1  christos   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
   3140      1.1  christos   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
   3141      1.1  christos   bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
   3142      1.1  christos 
   3143      1.1  christos   {_bfd_dummy_target, coff_small_object_p, /* bfd_check_format */
   3144      1.1  christos      bfd_generic_archive_p, _bfd_dummy_target},
   3145      1.1  christos   {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
   3146      1.1  christos      bfd_false},
   3147      1.1  christos   {bfd_false, coff_write_object_contents, /* bfd_write_contents */
   3148      1.1  christos      _bfd_write_archive_contents, bfd_false},
   3149      1.1  christos 
   3150      1.1  christos   BFD_JUMP_TABLE_GENERIC (coff_small),
   3151      1.1  christos   BFD_JUMP_TABLE_COPY (coff),
   3152      1.1  christos   BFD_JUMP_TABLE_CORE (_bfd_nocore),
   3153      1.1  christos   BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
   3154      1.1  christos   BFD_JUMP_TABLE_SYMBOLS (coff),
   3155      1.1  christos   BFD_JUMP_TABLE_RELOCS (coff),
   3156      1.1  christos   BFD_JUMP_TABLE_WRITE (coff),
   3157  1.1.1.3  christos   BFD_JUMP_TABLE_LINK (coff),
   3158      1.1  christos   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
   3159  1.1.1.2  christos 
   3160      1.1  christos   & sh_coff_small_le_vec,
   3161      1.1  christos 
   3162  1.1.1.3  christos   & bfd_coff_small_swap_table
   3163      1.1  christos };
   3164      1.1  christos 
   3165      1.1  christos const bfd_target sh_coff_small_le_vec =
   3166      1.1  christos {
   3167      1.1  christos   "coff-shl-small",		/* name */
   3168      1.1  christos   bfd_target_coff_flavour,
   3169      1.1  christos   BFD_ENDIAN_LITTLE,		/* data byte order is little */
   3170      1.1  christos   BFD_ENDIAN_LITTLE,		/* header byte order is little endian too*/
   3171      1.1  christos 
   3172      1.1  christos   (HAS_RELOC | EXEC_P |		/* object flags */
   3173      1.1  christos    HAS_LINENO | HAS_DEBUG |
   3174      1.1  christos    HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE),
   3175      1.1  christos 
   3176      1.1  christos   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC),
   3177  1.1.1.2  christos   '_',				/* leading symbol underscore */
   3178      1.1  christos   '/',				/* ar_pad_char */
   3179      1.1  christos   15,				/* ar_max_namelen */
   3180      1.1  christos   0,				/* match priority.  */
   3181      1.1  christos   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
   3182      1.1  christos   bfd_getl32, bfd_getl_signed_32, bfd_putl32,
   3183      1.1  christos   bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
   3184      1.1  christos   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
   3185      1.1  christos   bfd_getl32, bfd_getl_signed_32, bfd_putl32,
   3186      1.1  christos   bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
   3187      1.1  christos 
   3188      1.1  christos   {_bfd_dummy_target, coff_small_object_p, /* bfd_check_format */
   3189      1.1  christos      bfd_generic_archive_p, _bfd_dummy_target},
   3190      1.1  christos   {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
   3191      1.1  christos      bfd_false},
   3192      1.1  christos   {bfd_false, coff_write_object_contents, /* bfd_write_contents */
   3193      1.1  christos      _bfd_write_archive_contents, bfd_false},
   3194      1.1  christos 
   3195      1.1  christos   BFD_JUMP_TABLE_GENERIC (coff_small),
   3196      1.1  christos   BFD_JUMP_TABLE_COPY (coff),
   3197      1.1  christos   BFD_JUMP_TABLE_CORE (_bfd_nocore),
   3198      1.1  christos   BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
   3199      1.1  christos   BFD_JUMP_TABLE_SYMBOLS (coff),
   3200      1.1  christos   BFD_JUMP_TABLE_RELOCS (coff),
   3201      1.1  christos   BFD_JUMP_TABLE_WRITE (coff),
   3202  1.1.1.3  christos   BFD_JUMP_TABLE_LINK (coff),
   3203      1.1  christos   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
   3204  1.1.1.2  christos 
   3205      1.1  christos   & sh_coff_small_vec,
   3206      1.1  christos 
   3207                      & bfd_coff_small_swap_table
   3208                    };
   3209                    #endif
   3210