Home | History | Annotate | Line # | Download | only in bfd
coff-mips.c revision 1.8
      1  1.1  christos /* BFD back-end for MIPS Extended-Coff files.
      2  1.8  christos    Copyright (C) 1990-2019 Free Software Foundation, Inc.
      3  1.1  christos    Original version by Per Bothner.
      4  1.1  christos    Full support added by Ian Lance Taylor, ian (at) cygnus.com.
      5  1.1  christos 
      6  1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      7  1.1  christos 
      8  1.1  christos    This program is free software; you can redistribute it and/or modify
      9  1.1  christos    it under the terms of the GNU General Public License as published by
     10  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     11  1.1  christos    (at your option) any later version.
     12  1.1  christos 
     13  1.1  christos    This program is distributed in the hope that it will be useful,
     14  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  1.1  christos    GNU General Public License for more details.
     17  1.1  christos 
     18  1.1  christos    You should have received a copy of the GNU General Public License
     19  1.1  christos    along with this program; if not, write to the Free Software
     20  1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     21  1.1  christos    MA 02110-1301, USA.  */
     22  1.1  christos 
     23  1.1  christos #include "sysdep.h"
     24  1.1  christos #include "bfd.h"
     25  1.1  christos #include "bfdlink.h"
     26  1.1  christos #include "libbfd.h"
     27  1.1  christos #include "coff/internal.h"
     28  1.1  christos #include "coff/sym.h"
     29  1.1  christos #include "coff/symconst.h"
     30  1.1  christos #include "coff/ecoff.h"
     31  1.1  christos #include "coff/mips.h"
     32  1.1  christos #include "libcoff.h"
     33  1.1  christos #include "libecoff.h"
     34  1.1  christos 
     35  1.1  christos /* Prototypes for static functions.  */
     37  1.1  christos static bfd_reloc_status_type
     38  1.1  christos mips_generic_reloc
     39  1.1  christos   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
     40  1.1  christos static bfd_reloc_status_type
     41  1.1  christos mips_refhi_reloc
     42  1.1  christos   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
     43  1.1  christos static bfd_reloc_status_type
     44  1.1  christos mips_reflo_reloc
     45  1.1  christos   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
     46  1.1  christos static bfd_reloc_status_type
     47  1.1  christos mips_gprel_reloc
     48  1.1  christos   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
     49  1.1  christos 
     50  1.1  christos 
     51  1.1  christos /* ECOFF has COFF sections, but the debugging information is stored in
     53  1.1  christos    a completely different format.  ECOFF targets use some of the
     54  1.1  christos    swapping routines from coffswap.h, and some of the generic COFF
     55  1.1  christos    routines in coffgen.c, but, unlike the real COFF targets, do not
     56  1.1  christos    use coffcode.h itself.
     57  1.1  christos 
     58  1.1  christos    Get the generic COFF swapping routines, except for the reloc,
     59  1.1  christos    symbol, and lineno ones.  Give them ECOFF names.  */
     60  1.1  christos #define MIPSECOFF
     61  1.1  christos #define NO_COFF_RELOCS
     62  1.1  christos #define NO_COFF_SYMBOLS
     63  1.1  christos #define NO_COFF_LINENOS
     64  1.1  christos #define coff_swap_filehdr_in  mips_ecoff_swap_filehdr_in
     65  1.1  christos #define coff_swap_filehdr_out mips_ecoff_swap_filehdr_out
     66  1.1  christos #define coff_swap_aouthdr_in  mips_ecoff_swap_aouthdr_in
     67  1.1  christos #define coff_swap_aouthdr_out mips_ecoff_swap_aouthdr_out
     68  1.1  christos #define coff_swap_scnhdr_in   mips_ecoff_swap_scnhdr_in
     69  1.1  christos #define coff_swap_scnhdr_out  mips_ecoff_swap_scnhdr_out
     70  1.1  christos 
     71  1.1  christos #include "coffswap.h"
     72  1.1  christos 
     73  1.1  christos /* Get the ECOFF swapping routines.  */
     74  1.1  christos #define ECOFF_32
     75  1.1  christos #include "ecoffswap.h"
     76  1.1  christos 
     77  1.1  christos /* How to process the various relocs types.  */
     79  1.1  christos 
     80  1.1  christos static reloc_howto_type mips_howto_table[] =
     81  1.1  christos {
     82  1.1  christos   /* Reloc type 0 is ignored.  The reloc reading code ensures that
     83  1.1  christos      this is a reference to the .abs section, which will cause
     84  1.1  christos      bfd_perform_relocation to do nothing.  */
     85  1.1  christos   HOWTO (MIPS_R_IGNORE,	/* type */
     86  1.1  christos 	 0,			/* rightshift */
     87  1.1  christos 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
     88  1.1  christos 	 8,			/* bitsize */
     89  1.1  christos 	 FALSE,			/* pc_relative */
     90  1.1  christos 	 0,			/* bitpos */
     91  1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
     92  1.1  christos 	 0,			/* special_function */
     93  1.1  christos 	 "IGNORE",		/* name */
     94  1.1  christos 	 FALSE,			/* partial_inplace */
     95  1.1  christos 	 0,			/* src_mask */
     96  1.1  christos 	 0,			/* dst_mask */
     97  1.1  christos 	 FALSE),		/* pcrel_offset */
     98  1.1  christos 
     99  1.1  christos   /* A 16 bit reference to a symbol, normally from a data section.  */
    100  1.1  christos   HOWTO (MIPS_R_REFHALF,	/* type */
    101  1.1  christos 	 0,			/* rightshift */
    102  1.1  christos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    103  1.1  christos 	 16,			/* bitsize */
    104  1.1  christos 	 FALSE,			/* pc_relative */
    105  1.1  christos 	 0,			/* bitpos */
    106  1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    107  1.1  christos 	 mips_generic_reloc,	/* special_function */
    108  1.1  christos 	 "REFHALF",		/* name */
    109  1.1  christos 	 TRUE,			/* partial_inplace */
    110  1.1  christos 	 0xffff,		/* src_mask */
    111  1.1  christos 	 0xffff,		/* dst_mask */
    112  1.1  christos 	 FALSE),		/* pcrel_offset */
    113  1.1  christos 
    114  1.1  christos   /* A 32 bit reference to a symbol, normally from a data section.  */
    115  1.1  christos   HOWTO (MIPS_R_REFWORD,	/* type */
    116  1.1  christos 	 0,			/* rightshift */
    117  1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    118  1.1  christos 	 32,			/* bitsize */
    119  1.1  christos 	 FALSE,			/* pc_relative */
    120  1.1  christos 	 0,			/* bitpos */
    121  1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    122  1.1  christos 	 mips_generic_reloc,	/* special_function */
    123  1.1  christos 	 "REFWORD",		/* name */
    124  1.1  christos 	 TRUE,			/* partial_inplace */
    125  1.1  christos 	 0xffffffff,		/* src_mask */
    126  1.1  christos 	 0xffffffff,		/* dst_mask */
    127  1.1  christos 	 FALSE),		/* pcrel_offset */
    128  1.1  christos 
    129  1.1  christos   /* A 26 bit absolute jump address.  */
    130  1.1  christos   HOWTO (MIPS_R_JMPADDR,	/* type */
    131  1.1  christos 	 2,			/* rightshift */
    132  1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    133  1.1  christos 	 26,			/* bitsize */
    134  1.8  christos 	 FALSE,			/* pc_relative */
    135  1.1  christos 	 0,			/* bitpos */
    136  1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    137  1.1  christos 				/* This needs complex overflow
    138  1.1  christos 				   detection, because the upper four
    139  1.1  christos 				   bits must match the PC.  */
    140  1.1  christos 	 mips_generic_reloc,	/* special_function */
    141  1.1  christos 	 "JMPADDR",		/* name */
    142  1.1  christos 	 TRUE,			/* partial_inplace */
    143  1.1  christos 	 0x3ffffff,		/* src_mask */
    144  1.1  christos 	 0x3ffffff,		/* dst_mask */
    145  1.1  christos 	 FALSE),		/* pcrel_offset */
    146  1.1  christos 
    147  1.1  christos   /* The high 16 bits of a symbol value.  Handled by the function
    148  1.1  christos      mips_refhi_reloc.  */
    149  1.1  christos   HOWTO (MIPS_R_REFHI,		/* type */
    150  1.1  christos 	 16,			/* rightshift */
    151  1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    152  1.1  christos 	 16,			/* bitsize */
    153  1.1  christos 	 FALSE,			/* pc_relative */
    154  1.1  christos 	 0,			/* bitpos */
    155  1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    156  1.1  christos 	 mips_refhi_reloc,	/* special_function */
    157  1.1  christos 	 "REFHI",		/* name */
    158  1.1  christos 	 TRUE,			/* partial_inplace */
    159  1.1  christos 	 0xffff,		/* src_mask */
    160  1.1  christos 	 0xffff,		/* dst_mask */
    161  1.1  christos 	 FALSE),		/* pcrel_offset */
    162  1.1  christos 
    163  1.1  christos   /* The low 16 bits of a symbol value.  */
    164  1.1  christos   HOWTO (MIPS_R_REFLO,		/* type */
    165  1.1  christos 	 0,			/* rightshift */
    166  1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    167  1.1  christos 	 16,			/* bitsize */
    168  1.1  christos 	 FALSE,			/* pc_relative */
    169  1.1  christos 	 0,			/* bitpos */
    170  1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    171  1.1  christos 	 mips_reflo_reloc,	/* special_function */
    172  1.1  christos 	 "REFLO",		/* name */
    173  1.1  christos 	 TRUE,			/* partial_inplace */
    174  1.1  christos 	 0xffff,		/* src_mask */
    175  1.1  christos 	 0xffff,		/* dst_mask */
    176  1.1  christos 	 FALSE),		/* pcrel_offset */
    177  1.1  christos 
    178  1.1  christos   /* A reference to an offset from the gp register.  Handled by the
    179  1.1  christos      function mips_gprel_reloc.  */
    180  1.1  christos   HOWTO (MIPS_R_GPREL,		/* type */
    181  1.1  christos 	 0,			/* rightshift */
    182  1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    183  1.1  christos 	 16,			/* bitsize */
    184  1.1  christos 	 FALSE,			/* pc_relative */
    185  1.1  christos 	 0,			/* bitpos */
    186  1.1  christos 	 complain_overflow_signed, /* complain_on_overflow */
    187  1.1  christos 	 mips_gprel_reloc,	/* special_function */
    188  1.1  christos 	 "GPREL",		/* name */
    189  1.1  christos 	 TRUE,			/* partial_inplace */
    190  1.1  christos 	 0xffff,		/* src_mask */
    191  1.1  christos 	 0xffff,		/* dst_mask */
    192  1.1  christos 	 FALSE),		/* pcrel_offset */
    193  1.1  christos 
    194  1.1  christos   /* A reference to a literal using an offset from the gp register.
    195  1.1  christos      Handled by the function mips_gprel_reloc.  */
    196  1.1  christos   HOWTO (MIPS_R_LITERAL,	/* type */
    197  1.1  christos 	 0,			/* rightshift */
    198  1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    199  1.1  christos 	 16,			/* bitsize */
    200  1.1  christos 	 FALSE,			/* pc_relative */
    201  1.1  christos 	 0,			/* bitpos */
    202  1.1  christos 	 complain_overflow_signed, /* complain_on_overflow */
    203  1.1  christos 	 mips_gprel_reloc,	/* special_function */
    204  1.1  christos 	 "LITERAL",		/* name */
    205  1.1  christos 	 TRUE,			/* partial_inplace */
    206  1.1  christos 	 0xffff,		/* src_mask */
    207  1.1  christos 	 0xffff,		/* dst_mask */
    208  1.1  christos 	 FALSE),		/* pcrel_offset */
    209  1.1  christos 
    210  1.1  christos   EMPTY_HOWTO (8),
    211  1.1  christos   EMPTY_HOWTO (9),
    212  1.1  christos   EMPTY_HOWTO (10),
    213  1.1  christos   EMPTY_HOWTO (11),
    214  1.1  christos 
    215  1.1  christos   /* FIXME: This relocation is used (internally only) to represent branches
    216  1.1  christos      when assembling.  It should never appear in output files, and
    217  1.1  christos      be removed.  (It used to be used for embedded-PIC support.)  */
    218  1.1  christos   HOWTO (MIPS_R_PCREL16,	/* type */
    219  1.1  christos 	 2,			/* rightshift */
    220  1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    221  1.1  christos 	 16,			/* bitsize */
    222  1.1  christos 	 TRUE,			/* pc_relative */
    223  1.1  christos 	 0,			/* bitpos */
    224  1.1  christos 	 complain_overflow_signed, /* complain_on_overflow */
    225  1.1  christos 	 mips_generic_reloc,	/* special_function */
    226  1.1  christos 	 "PCREL16",		/* name */
    227  1.1  christos 	 TRUE,			/* partial_inplace */
    228  1.1  christos 	 0xffff,		/* src_mask */
    229  1.1  christos 	 0xffff,		/* dst_mask */
    230  1.1  christos 	 TRUE),			/* pcrel_offset */
    231  1.1  christos };
    232  1.1  christos 
    233  1.1  christos #define MIPS_HOWTO_COUNT \
    234  1.1  christos   (sizeof mips_howto_table / sizeof mips_howto_table[0])
    235  1.1  christos 
    236  1.1  christos /* See whether the magic number matches.  */
    238  1.1  christos 
    239  1.1  christos static bfd_boolean
    240  1.1  christos mips_ecoff_bad_format_hook (bfd * abfd, void * filehdr)
    241  1.1  christos {
    242  1.1  christos   struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
    243  1.1  christos 
    244  1.1  christos   switch (internal_f->f_magic)
    245  1.1  christos     {
    246  1.1  christos     case MIPS_MAGIC_1:
    247  1.1  christos       /* I don't know what endianness this implies.  */
    248  1.1  christos       return TRUE;
    249  1.1  christos 
    250  1.1  christos     case MIPS_MAGIC_BIG:
    251  1.1  christos     case MIPS_MAGIC_BIG2:
    252  1.1  christos     case MIPS_MAGIC_BIG3:
    253  1.1  christos       return bfd_big_endian (abfd);
    254  1.1  christos 
    255  1.1  christos     case MIPS_MAGIC_LITTLE:
    256  1.1  christos     case MIPS_MAGIC_LITTLE2:
    257  1.1  christos     case MIPS_MAGIC_LITTLE3:
    258  1.1  christos       return bfd_little_endian (abfd);
    259  1.1  christos 
    260  1.1  christos     default:
    261  1.1  christos       return FALSE;
    262  1.1  christos     }
    263  1.1  christos }
    264  1.1  christos 
    265  1.1  christos /* Reloc handling.  MIPS ECOFF relocs are packed into 8 bytes in
    267  1.1  christos    external form.  They use a bit which indicates whether the symbol
    268  1.1  christos    is external.  */
    269  1.1  christos 
    270  1.1  christos /* Swap a reloc in.  */
    271  1.1  christos 
    272  1.1  christos static void
    273  1.1  christos mips_ecoff_swap_reloc_in (bfd *  abfd,
    274  1.1  christos 			  void * ext_ptr,
    275  1.1  christos 			  struct internal_reloc *intern)
    276  1.1  christos {
    277  1.1  christos   const RELOC *ext = (RELOC *) ext_ptr;
    278  1.1  christos 
    279  1.1  christos   intern->r_vaddr = H_GET_32 (abfd, ext->r_vaddr);
    280  1.1  christos   if (bfd_header_big_endian (abfd))
    281  1.1  christos     {
    282  1.1  christos       intern->r_symndx = (((int) ext->r_bits[0]
    283  1.1  christos 			   << RELOC_BITS0_SYMNDX_SH_LEFT_BIG)
    284  1.1  christos 			  | ((int) ext->r_bits[1]
    285  1.1  christos 			     << RELOC_BITS1_SYMNDX_SH_LEFT_BIG)
    286  1.1  christos 			  | ((int) ext->r_bits[2]
    287  1.1  christos 			     << RELOC_BITS2_SYMNDX_SH_LEFT_BIG));
    288  1.1  christos       intern->r_type = ((ext->r_bits[3] & RELOC_BITS3_TYPE_BIG)
    289  1.1  christos 			>> RELOC_BITS3_TYPE_SH_BIG);
    290  1.1  christos       intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_BIG) != 0;
    291  1.1  christos     }
    292  1.1  christos   else
    293  1.1  christos     {
    294  1.1  christos       intern->r_symndx = (((int) ext->r_bits[0]
    295  1.1  christos 			   << RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE)
    296  1.1  christos 			  | ((int) ext->r_bits[1]
    297  1.1  christos 			     << RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE)
    298  1.1  christos 			  | ((int) ext->r_bits[2]
    299  1.1  christos 			     << RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE));
    300  1.1  christos       intern->r_type = (((ext->r_bits[3] & RELOC_BITS3_TYPE_LITTLE)
    301  1.1  christos 			 >> RELOC_BITS3_TYPE_SH_LITTLE)
    302  1.1  christos 			| ((ext->r_bits[3] & RELOC_BITS3_TYPEHI_LITTLE)
    303  1.1  christos 			   << RELOC_BITS3_TYPEHI_SH_LITTLE));
    304  1.1  christos       intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_LITTLE) != 0;
    305  1.1  christos     }
    306  1.1  christos }
    307  1.1  christos 
    308  1.1  christos /* Swap a reloc out.  */
    309  1.1  christos 
    310  1.1  christos static void
    311  1.1  christos mips_ecoff_swap_reloc_out (bfd * abfd,
    312  1.1  christos 			   const struct internal_reloc * intern,
    313  1.1  christos 			   void * dst)
    314  1.1  christos {
    315  1.1  christos   RELOC *ext = (RELOC *) dst;
    316  1.1  christos   long r_symndx;
    317  1.1  christos 
    318  1.1  christos   BFD_ASSERT (intern->r_extern
    319  1.1  christos 	      || (intern->r_symndx >= 0 && intern->r_symndx <= 12));
    320  1.1  christos 
    321  1.1  christos   r_symndx = intern->r_symndx;
    322  1.1  christos 
    323  1.1  christos   H_PUT_32 (abfd, intern->r_vaddr, ext->r_vaddr);
    324  1.1  christos   if (bfd_header_big_endian (abfd))
    325  1.1  christos     {
    326  1.1  christos       ext->r_bits[0] = r_symndx >> RELOC_BITS0_SYMNDX_SH_LEFT_BIG;
    327  1.1  christos       ext->r_bits[1] = r_symndx >> RELOC_BITS1_SYMNDX_SH_LEFT_BIG;
    328  1.1  christos       ext->r_bits[2] = r_symndx >> RELOC_BITS2_SYMNDX_SH_LEFT_BIG;
    329  1.1  christos       ext->r_bits[3] = (((intern->r_type << RELOC_BITS3_TYPE_SH_BIG)
    330  1.1  christos 			 & RELOC_BITS3_TYPE_BIG)
    331  1.1  christos 			| (intern->r_extern ? RELOC_BITS3_EXTERN_BIG : 0));
    332  1.1  christos     }
    333  1.1  christos   else
    334  1.1  christos     {
    335  1.1  christos       ext->r_bits[0] = r_symndx >> RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE;
    336  1.1  christos       ext->r_bits[1] = r_symndx >> RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE;
    337  1.1  christos       ext->r_bits[2] = r_symndx >> RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE;
    338  1.1  christos       ext->r_bits[3] = (((intern->r_type << RELOC_BITS3_TYPE_SH_LITTLE)
    339  1.1  christos 			 & RELOC_BITS3_TYPE_LITTLE)
    340  1.1  christos 			| ((intern->r_type >> RELOC_BITS3_TYPEHI_SH_LITTLE
    341  1.1  christos 			    & RELOC_BITS3_TYPEHI_LITTLE))
    342  1.1  christos 			| (intern->r_extern ? RELOC_BITS3_EXTERN_LITTLE : 0));
    343  1.1  christos     }
    344  1.1  christos }
    345  1.1  christos 
    346  1.1  christos /* Finish canonicalizing a reloc.  Part of this is generic to all
    347  1.1  christos    ECOFF targets, and that part is in ecoff.c.  The rest is done in
    348  1.1  christos    this backend routine.  It must fill in the howto field.  */
    349  1.1  christos 
    350  1.1  christos static void
    351  1.1  christos mips_adjust_reloc_in (bfd *abfd,
    352  1.1  christos 		      const struct internal_reloc *intern,
    353  1.1  christos 		      arelent *rptr)
    354  1.1  christos {
    355  1.1  christos   if (intern->r_type > MIPS_R_PCREL16)
    356  1.1  christos     abort ();
    357  1.1  christos 
    358  1.1  christos   if (! intern->r_extern
    359  1.1  christos       && (intern->r_type == MIPS_R_GPREL
    360  1.1  christos 	  || intern->r_type == MIPS_R_LITERAL))
    361  1.1  christos     rptr->addend += ecoff_data (abfd)->gp;
    362  1.1  christos 
    363  1.1  christos   /* If the type is MIPS_R_IGNORE, make sure this is a reference to
    364  1.1  christos      the absolute section so that the reloc is ignored.  */
    365  1.1  christos   if (intern->r_type == MIPS_R_IGNORE)
    366  1.1  christos     rptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
    367  1.1  christos 
    368  1.1  christos   rptr->howto = &mips_howto_table[intern->r_type];
    369  1.1  christos }
    370  1.1  christos 
    371  1.1  christos /* Make any adjustments needed to a reloc before writing it out.  None
    372  1.1  christos    are needed for MIPS.  */
    373  1.1  christos 
    374  1.1  christos static void
    375  1.1  christos mips_adjust_reloc_out (bfd *abfd ATTRIBUTE_UNUSED,
    376  1.1  christos 		       const arelent *rel ATTRIBUTE_UNUSED,
    377  1.1  christos 		       struct internal_reloc *intern ATTRIBUTE_UNUSED)
    378  1.1  christos {
    379  1.1  christos }
    380  1.1  christos 
    381  1.1  christos /* ECOFF relocs are either against external symbols, or against
    382  1.1  christos    sections.  If we are producing relocatable output, and the reloc
    383  1.1  christos    is against an external symbol, and nothing has given us any
    384  1.1  christos    additional addend, the resulting reloc will also be against the
    385  1.1  christos    same symbol.  In such a case, we don't want to change anything
    386  1.1  christos    about the way the reloc is handled, since it will all be done at
    387  1.1  christos    final link time.  Rather than put special case code into
    388  1.1  christos    bfd_perform_relocation, all the reloc types use this howto
    389  1.1  christos    function.  It just short circuits the reloc if producing
    390  1.1  christos    relocatable output against an external symbol.  */
    391  1.1  christos 
    392  1.1  christos static bfd_reloc_status_type
    393  1.1  christos mips_generic_reloc (bfd *abfd ATTRIBUTE_UNUSED,
    394  1.1  christos 		    arelent *reloc_entry,
    395  1.1  christos 		    asymbol *symbol,
    396  1.1  christos 		    void * data ATTRIBUTE_UNUSED,
    397  1.1  christos 		    asection *input_section,
    398  1.1  christos 		    bfd *output_bfd,
    399  1.1  christos 		    char **error_message ATTRIBUTE_UNUSED)
    400  1.1  christos {
    401  1.1  christos   if (output_bfd != (bfd *) NULL
    402  1.1  christos       && (symbol->flags & BSF_SECTION_SYM) == 0
    403  1.1  christos       && reloc_entry->addend == 0)
    404  1.1  christos     {
    405  1.1  christos       reloc_entry->address += input_section->output_offset;
    406  1.1  christos       return bfd_reloc_ok;
    407  1.1  christos     }
    408  1.1  christos 
    409  1.1  christos   return bfd_reloc_continue;
    410  1.1  christos }
    411  1.1  christos 
    412  1.1  christos /* Do a REFHI relocation.  This has to be done in combination with a
    413  1.1  christos    REFLO reloc, because there is a carry from the REFLO to the REFHI.
    414  1.1  christos    Here we just save the information we need; we do the actual
    415  1.1  christos    relocation when we see the REFLO.  MIPS ECOFF requires that the
    416  1.1  christos    REFLO immediately follow the REFHI.  As a GNU extension, we permit
    417  1.1  christos    an arbitrary number of HI relocs to be associated with a single LO
    418  1.1  christos    reloc.  This extension permits gcc to output the HI and LO relocs
    419  1.1  christos    itself.  */
    420  1.1  christos 
    421  1.1  christos struct mips_hi
    422  1.1  christos {
    423  1.1  christos   struct mips_hi *next;
    424  1.1  christos   bfd_byte *addr;
    425  1.1  christos   bfd_vma addend;
    426  1.1  christos };
    427  1.1  christos 
    428  1.1  christos /* FIXME: This should not be a static variable.  */
    429  1.1  christos 
    430  1.1  christos static struct mips_hi *mips_refhi_list;
    431  1.1  christos 
    432  1.1  christos static bfd_reloc_status_type
    433  1.1  christos mips_refhi_reloc (bfd *abfd ATTRIBUTE_UNUSED,
    434  1.1  christos 		  arelent *reloc_entry,
    435  1.1  christos 		  asymbol *symbol,
    436  1.1  christos 		  void * data,
    437  1.1  christos 		  asection *input_section,
    438  1.1  christos 		  bfd *output_bfd,
    439  1.1  christos 		  char **error_message ATTRIBUTE_UNUSED)
    440  1.1  christos {
    441  1.1  christos   bfd_reloc_status_type ret;
    442  1.1  christos   bfd_vma relocation;
    443  1.1  christos   struct mips_hi *n;
    444  1.1  christos 
    445  1.1  christos   /* If we're relocating, and this an external symbol, we don't want
    446  1.1  christos      to change anything.  */
    447  1.1  christos   if (output_bfd != (bfd *) NULL
    448  1.1  christos       && (symbol->flags & BSF_SECTION_SYM) == 0
    449  1.1  christos       && reloc_entry->addend == 0)
    450  1.1  christos     {
    451  1.1  christos       reloc_entry->address += input_section->output_offset;
    452  1.1  christos       return bfd_reloc_ok;
    453  1.1  christos     }
    454  1.1  christos 
    455  1.1  christos   ret = bfd_reloc_ok;
    456  1.1  christos   if (bfd_is_und_section (symbol->section)
    457  1.1  christos       && output_bfd == (bfd *) NULL)
    458  1.1  christos     ret = bfd_reloc_undefined;
    459  1.1  christos 
    460  1.1  christos   if (bfd_is_com_section (symbol->section))
    461  1.1  christos     relocation = 0;
    462  1.1  christos   else
    463  1.1  christos     relocation = symbol->value;
    464  1.1  christos 
    465  1.1  christos   relocation += symbol->section->output_section->vma;
    466  1.1  christos   relocation += symbol->section->output_offset;
    467  1.1  christos   relocation += reloc_entry->addend;
    468  1.1  christos 
    469  1.1  christos   if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
    470  1.1  christos     return bfd_reloc_outofrange;
    471  1.1  christos 
    472  1.1  christos   /* Save the information, and let REFLO do the actual relocation.  */
    473  1.1  christos   n = (struct mips_hi *) bfd_malloc ((bfd_size_type) sizeof *n);
    474  1.1  christos   if (n == NULL)
    475  1.1  christos     return bfd_reloc_outofrange;
    476  1.1  christos   n->addr = (bfd_byte *) data + reloc_entry->address;
    477  1.1  christos   n->addend = relocation;
    478  1.1  christos   n->next = mips_refhi_list;
    479  1.1  christos   mips_refhi_list = n;
    480  1.1  christos 
    481  1.1  christos   if (output_bfd != (bfd *) NULL)
    482  1.1  christos     reloc_entry->address += input_section->output_offset;
    483  1.1  christos 
    484  1.1  christos   return ret;
    485  1.1  christos }
    486  1.1  christos 
    487  1.1  christos /* Do a REFLO relocation.  This is a straightforward 16 bit inplace
    488  1.1  christos    relocation; this function exists in order to do the REFHI
    489  1.1  christos    relocation described above.  */
    490  1.1  christos 
    491  1.1  christos static bfd_reloc_status_type
    492  1.1  christos mips_reflo_reloc (bfd *abfd ATTRIBUTE_UNUSED,
    493  1.1  christos 		  arelent *reloc_entry,
    494  1.1  christos 		  asymbol *symbol,
    495  1.1  christos 		  void * data,
    496  1.1  christos 		  asection *input_section,
    497  1.1  christos 		  bfd *output_bfd,
    498  1.1  christos 		  char **error_message ATTRIBUTE_UNUSED)
    499  1.1  christos {
    500  1.1  christos   if (mips_refhi_list != NULL)
    501  1.1  christos     {
    502  1.1  christos       struct mips_hi *l;
    503  1.1  christos 
    504  1.1  christos       l = mips_refhi_list;
    505  1.1  christos       while (l != NULL)
    506  1.1  christos 	{
    507  1.8  christos 	  unsigned long insn;
    508  1.8  christos 	  unsigned long val;
    509  1.8  christos 	  unsigned long vallo;
    510  1.8  christos 	  struct mips_hi *next;
    511  1.8  christos 
    512  1.8  christos 	  if (! bfd_reloc_offset_in_range (reloc_entry->howto, abfd,
    513  1.1  christos 					   input_section,
    514  1.1  christos 					   reloc_entry->address
    515  1.1  christos 					   * bfd_octets_per_byte (abfd)))
    516  1.1  christos 	    return bfd_reloc_outofrange;
    517  1.1  christos 
    518  1.1  christos 	  /* Do the REFHI relocation.  Note that we actually don't
    519  1.1  christos 	     need to know anything about the REFLO itself, except
    520  1.1  christos 	     where to find the low 16 bits of the addend needed by the
    521  1.1  christos 	     REFHI.  */
    522  1.1  christos 	  insn = bfd_get_32 (abfd, l->addr);
    523  1.1  christos 	  vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address)
    524  1.1  christos 		   & 0xffff);
    525  1.1  christos 	  val = ((insn & 0xffff) << 16) + vallo;
    526  1.1  christos 	  val += l->addend;
    527  1.1  christos 
    528  1.1  christos 	  /* The low order 16 bits are always treated as a signed
    529  1.1  christos 	     value.  Therefore, a negative value in the low order bits
    530  1.1  christos 	     requires an adjustment in the high order bits.  We need
    531  1.1  christos 	     to make this adjustment in two ways: once for the bits we
    532  1.1  christos 	     took from the data, and once for the bits we are putting
    533  1.1  christos 	     back in to the data.  */
    534  1.1  christos 	  if ((vallo & 0x8000) != 0)
    535  1.1  christos 	    val -= 0x10000;
    536  1.1  christos 	  if ((val & 0x8000) != 0)
    537  1.1  christos 	    val += 0x10000;
    538  1.1  christos 
    539  1.1  christos 	  insn = (insn &~ (unsigned) 0xffff) | ((val >> 16) & 0xffff);
    540  1.1  christos 	  bfd_put_32 (abfd, (bfd_vma) insn, l->addr);
    541  1.1  christos 
    542  1.1  christos 	  next = l->next;
    543  1.1  christos 	  free (l);
    544  1.1  christos 	  l = next;
    545  1.1  christos 	}
    546  1.1  christos 
    547  1.1  christos       mips_refhi_list = NULL;
    548  1.1  christos     }
    549  1.1  christos 
    550  1.1  christos   /* Now do the REFLO reloc in the usual way.  */
    551  1.1  christos   return mips_generic_reloc (abfd, reloc_entry, symbol, data,
    552  1.1  christos 			      input_section, output_bfd, error_message);
    553  1.1  christos }
    554  1.1  christos 
    555  1.1  christos /* Do a GPREL relocation.  This is a 16 bit value which must become
    556  1.1  christos    the offset from the gp register.  */
    557  1.1  christos 
    558  1.1  christos static bfd_reloc_status_type
    559  1.1  christos mips_gprel_reloc (bfd *abfd ATTRIBUTE_UNUSED,
    560  1.1  christos 		  arelent *reloc_entry,
    561  1.1  christos 		  asymbol *symbol,
    562  1.1  christos 		  void * data,
    563  1.1  christos 		  asection *input_section,
    564  1.1  christos 		  bfd *output_bfd,
    565  1.1  christos 		  char **error_message ATTRIBUTE_UNUSED)
    566  1.1  christos {
    567  1.1  christos   bfd_boolean relocatable;
    568  1.1  christos   bfd_vma gp;
    569  1.1  christos   bfd_vma relocation;
    570  1.1  christos   unsigned long val;
    571  1.1  christos   unsigned long insn;
    572  1.1  christos 
    573  1.1  christos   /* If we're relocating, and this is an external symbol with no
    574  1.1  christos      addend, we don't want to change anything.  We will only have an
    575  1.1  christos      addend if this is a newly created reloc, not read from an ECOFF
    576  1.1  christos      file.  */
    577  1.1  christos   if (output_bfd != (bfd *) NULL
    578  1.1  christos       && (symbol->flags & BSF_SECTION_SYM) == 0
    579  1.1  christos       && reloc_entry->addend == 0)
    580  1.1  christos     {
    581  1.1  christos       reloc_entry->address += input_section->output_offset;
    582  1.1  christos       return bfd_reloc_ok;
    583  1.1  christos     }
    584  1.1  christos 
    585  1.1  christos   if (output_bfd != (bfd *) NULL)
    586  1.1  christos     relocatable = TRUE;
    587  1.1  christos   else
    588  1.1  christos     {
    589  1.1  christos       relocatable = FALSE;
    590  1.1  christos       output_bfd = symbol->section->output_section->owner;
    591  1.1  christos     }
    592  1.1  christos 
    593  1.1  christos   if (bfd_is_und_section (symbol->section) && ! relocatable)
    594  1.1  christos     return bfd_reloc_undefined;
    595  1.1  christos 
    596  1.1  christos   /* We have to figure out the gp value, so that we can adjust the
    597  1.1  christos      symbol value correctly.  We look up the symbol _gp in the output
    598  1.1  christos      BFD.  If we can't find it, we're stuck.  We cache it in the ECOFF
    599  1.1  christos      target data.  We don't need to adjust the symbol value for an
    600  1.1  christos      external symbol if we are producing relocatable output.  */
    601  1.1  christos   gp = _bfd_get_gp_value (output_bfd);
    602  1.1  christos   if (gp == 0
    603  1.1  christos       && (! relocatable
    604  1.1  christos 	  || (symbol->flags & BSF_SECTION_SYM) != 0))
    605  1.1  christos     {
    606  1.1  christos       if (relocatable)
    607  1.1  christos 	{
    608  1.1  christos 	  /* Make up a value.  */
    609  1.1  christos 	  gp = symbol->section->output_section->vma + 0x4000;
    610  1.1  christos 	  _bfd_set_gp_value (output_bfd, gp);
    611  1.1  christos 	}
    612  1.1  christos       else
    613  1.1  christos 	{
    614  1.1  christos 	  unsigned int count;
    615  1.1  christos 	  asymbol **sym;
    616  1.1  christos 	  unsigned int i;
    617  1.1  christos 
    618  1.1  christos 	  count = bfd_get_symcount (output_bfd);
    619  1.1  christos 	  sym = bfd_get_outsymbols (output_bfd);
    620  1.1  christos 
    621  1.1  christos 	  if (sym == (asymbol **) NULL)
    622  1.1  christos 	    i = count;
    623  1.1  christos 	  else
    624  1.1  christos 	    {
    625  1.1  christos 	      for (i = 0; i < count; i++, sym++)
    626  1.1  christos 		{
    627  1.1  christos 		  register const char *name;
    628  1.1  christos 
    629  1.1  christos 		  name = bfd_asymbol_name (*sym);
    630  1.1  christos 		  if (*name == '_' && strcmp (name, "_gp") == 0)
    631  1.1  christos 		    {
    632  1.1  christos 		      gp = bfd_asymbol_value (*sym);
    633  1.1  christos 		      _bfd_set_gp_value (output_bfd, gp);
    634  1.1  christos 		      break;
    635  1.1  christos 		    }
    636  1.1  christos 		}
    637  1.1  christos 	    }
    638  1.1  christos 
    639  1.1  christos 	  if (i >= count)
    640  1.1  christos 	    {
    641  1.1  christos 	      /* Only get the error once.  */
    642  1.1  christos 	      gp = 4;
    643  1.1  christos 	      _bfd_set_gp_value (output_bfd, gp);
    644  1.1  christos 	      *error_message =
    645  1.1  christos 		(char *) _("GP relative relocation when _gp not defined");
    646  1.1  christos 	      return bfd_reloc_dangerous;
    647  1.1  christos 	    }
    648  1.1  christos 	}
    649  1.1  christos     }
    650  1.1  christos 
    651  1.1  christos   if (bfd_is_com_section (symbol->section))
    652  1.1  christos     relocation = 0;
    653  1.1  christos   else
    654  1.1  christos     relocation = symbol->value;
    655  1.1  christos 
    656  1.1  christos   relocation += symbol->section->output_section->vma;
    657  1.1  christos   relocation += symbol->section->output_offset;
    658  1.1  christos 
    659  1.1  christos   if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
    660  1.1  christos     return bfd_reloc_outofrange;
    661  1.1  christos 
    662  1.1  christos   insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
    663  1.1  christos 
    664  1.1  christos   /* Set val to the offset into the section or symbol.  */
    665  1.1  christos   val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff;
    666  1.1  christos   if (val & 0x8000)
    667  1.1  christos     val -= 0x10000;
    668  1.1  christos 
    669  1.1  christos   /* Adjust val for the final section location and GP value.  If we
    670  1.1  christos      are producing relocatable output, we don't want to do this for
    671  1.1  christos      an external symbol.  */
    672  1.1  christos   if (! relocatable
    673  1.1  christos       || (symbol->flags & BSF_SECTION_SYM) != 0)
    674  1.1  christos     val += relocation - gp;
    675  1.1  christos 
    676  1.1  christos   insn = (insn &~ (unsigned) 0xffff) | (val & 0xffff);
    677  1.1  christos   bfd_put_32 (abfd, (bfd_vma) insn, (bfd_byte *) data + reloc_entry->address);
    678  1.1  christos 
    679  1.1  christos   if (relocatable)
    680  1.1  christos     reloc_entry->address += input_section->output_offset;
    681  1.1  christos 
    682  1.1  christos   /* Make sure it fit in 16 bits.  */
    683  1.1  christos   if ((long) val >= 0x8000 || (long) val < -0x8000)
    684  1.1  christos     return bfd_reloc_overflow;
    685  1.1  christos 
    686  1.1  christos   return bfd_reloc_ok;
    687  1.1  christos }
    688  1.1  christos 
    689  1.1  christos /* Get the howto structure for a generic reloc type.  */
    690  1.1  christos 
    691  1.1  christos static reloc_howto_type *
    692  1.1  christos mips_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
    693  1.1  christos 			    bfd_reloc_code_real_type code)
    694  1.1  christos {
    695  1.1  christos   int mips_type;
    696  1.1  christos 
    697  1.1  christos   switch (code)
    698  1.1  christos     {
    699  1.1  christos     case BFD_RELOC_16:
    700  1.1  christos       mips_type = MIPS_R_REFHALF;
    701  1.1  christos       break;
    702  1.1  christos     case BFD_RELOC_32:
    703  1.1  christos     case BFD_RELOC_CTOR:
    704  1.1  christos       mips_type = MIPS_R_REFWORD;
    705  1.1  christos       break;
    706  1.1  christos     case BFD_RELOC_MIPS_JMP:
    707  1.1  christos       mips_type = MIPS_R_JMPADDR;
    708  1.1  christos       break;
    709  1.1  christos     case BFD_RELOC_HI16_S:
    710  1.1  christos       mips_type = MIPS_R_REFHI;
    711  1.1  christos       break;
    712  1.1  christos     case BFD_RELOC_LO16:
    713  1.1  christos       mips_type = MIPS_R_REFLO;
    714  1.1  christos       break;
    715  1.1  christos     case BFD_RELOC_GPREL16:
    716  1.1  christos       mips_type = MIPS_R_GPREL;
    717  1.1  christos       break;
    718  1.1  christos     case BFD_RELOC_MIPS_LITERAL:
    719  1.1  christos       mips_type = MIPS_R_LITERAL;
    720  1.1  christos       break;
    721  1.1  christos     case BFD_RELOC_16_PCREL_S2:
    722  1.1  christos       mips_type = MIPS_R_PCREL16;
    723  1.1  christos       break;
    724  1.1  christos     default:
    725  1.1  christos       return (reloc_howto_type *) NULL;
    726  1.1  christos     }
    727  1.1  christos 
    728  1.1  christos   return &mips_howto_table[mips_type];
    729  1.1  christos }
    730  1.1  christos 
    731  1.1  christos static reloc_howto_type *
    732  1.1  christos mips_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
    733  1.1  christos 			    const char *r_name)
    734  1.1  christos {
    735  1.1  christos   unsigned int i;
    736  1.1  christos 
    737  1.1  christos   for (i = 0;
    738  1.1  christos        i < sizeof (mips_howto_table) / sizeof (mips_howto_table[0]);
    739  1.1  christos        i++)
    740  1.1  christos     if (mips_howto_table[i].name != NULL
    741  1.1  christos 	&& strcasecmp (mips_howto_table[i].name, r_name) == 0)
    742  1.1  christos       return &mips_howto_table[i];
    743  1.1  christos 
    744  1.1  christos   return NULL;
    745  1.1  christos }
    746  1.1  christos 
    747  1.1  christos /* A helper routine for mips_relocate_section which handles the REFHI
    749  1.1  christos    relocations.  The REFHI relocation must be followed by a REFLO
    750  1.1  christos    relocation, and the addend used is formed from the addends of both
    751  1.1  christos    instructions.  */
    752  1.1  christos 
    753  1.1  christos static void
    754  1.1  christos mips_relocate_hi (struct internal_reloc *refhi,
    755  1.1  christos 		  struct internal_reloc *reflo,
    756  1.1  christos 		  bfd *input_bfd,
    757  1.1  christos 		  asection *input_section,
    758  1.1  christos 		  bfd_byte *contents,
    759  1.1  christos 		  bfd_vma relocation)
    760  1.1  christos {
    761  1.1  christos   unsigned long insn;
    762  1.1  christos   unsigned long val;
    763  1.1  christos   unsigned long vallo;
    764  1.1  christos 
    765  1.1  christos   if (refhi == NULL)
    766  1.1  christos     return;
    767  1.1  christos 
    768  1.1  christos   insn = bfd_get_32 (input_bfd,
    769  1.1  christos 		     contents + refhi->r_vaddr - input_section->vma);
    770  1.1  christos   if (reflo == NULL)
    771  1.1  christos     vallo = 0;
    772  1.1  christos   else
    773  1.1  christos     vallo = (bfd_get_32 (input_bfd,
    774  1.1  christos 			 contents + reflo->r_vaddr - input_section->vma)
    775  1.1  christos 	     & 0xffff);
    776  1.1  christos 
    777  1.1  christos   val = ((insn & 0xffff) << 16) + vallo;
    778  1.1  christos   val += relocation;
    779  1.1  christos 
    780  1.1  christos   /* The low order 16 bits are always treated as a signed value.
    781  1.1  christos      Therefore, a negative value in the low order bits requires an
    782  1.1  christos      adjustment in the high order bits.  We need to make this
    783  1.1  christos      adjustment in two ways: once for the bits we took from the data,
    784  1.1  christos      and once for the bits we are putting back in to the data.  */
    785  1.1  christos   if ((vallo & 0x8000) != 0)
    786  1.1  christos     val -= 0x10000;
    787  1.1  christos 
    788  1.1  christos   if ((val & 0x8000) != 0)
    789  1.1  christos     val += 0x10000;
    790  1.1  christos 
    791  1.1  christos   insn = (insn &~ (unsigned) 0xffff) | ((val >> 16) & 0xffff);
    792  1.1  christos   bfd_put_32 (input_bfd, (bfd_vma) insn,
    793  1.1  christos 	      contents + refhi->r_vaddr - input_section->vma);
    794  1.1  christos }
    795  1.1  christos 
    796  1.1  christos /* Relocate a section while linking a MIPS ECOFF file.  */
    797  1.1  christos 
    798  1.1  christos static bfd_boolean
    799  1.1  christos mips_relocate_section (bfd *output_bfd,
    800  1.1  christos 		       struct bfd_link_info *info,
    801  1.1  christos 		       bfd *input_bfd,
    802  1.1  christos 		       asection *input_section,
    803  1.1  christos 		       bfd_byte *contents,
    804  1.1  christos 		       void * external_relocs)
    805  1.1  christos {
    806  1.1  christos   asection **symndx_to_section;
    807  1.1  christos   struct ecoff_link_hash_entry **sym_hashes;
    808  1.1  christos   bfd_vma gp;
    809  1.1  christos   bfd_boolean gp_undefined;
    810  1.1  christos   struct external_reloc *ext_rel;
    811  1.1  christos   struct external_reloc *ext_rel_end;
    812  1.1  christos   unsigned int i;
    813  1.1  christos   bfd_boolean got_lo;
    814  1.1  christos   struct internal_reloc lo_int_rel;
    815  1.1  christos   bfd_size_type amt;
    816  1.1  christos 
    817  1.1  christos   BFD_ASSERT (input_bfd->xvec->byteorder
    818  1.1  christos 	      == output_bfd->xvec->byteorder);
    819  1.1  christos 
    820  1.1  christos   /* We keep a table mapping the symndx found in an internal reloc to
    821  1.1  christos      the appropriate section.  This is faster than looking up the
    822  1.1  christos      section by name each time.  */
    823  1.1  christos   symndx_to_section = ecoff_data (input_bfd)->symndx_to_section;
    824  1.1  christos   if (symndx_to_section == (asection **) NULL)
    825  1.1  christos     {
    826  1.1  christos       amt = NUM_RELOC_SECTIONS * sizeof (asection *);
    827  1.1  christos       symndx_to_section = (asection **) bfd_alloc (input_bfd, amt);
    828  1.1  christos       if (!symndx_to_section)
    829  1.1  christos 	return FALSE;
    830  1.1  christos 
    831  1.1  christos       symndx_to_section[RELOC_SECTION_NONE] = NULL;
    832  1.1  christos       symndx_to_section[RELOC_SECTION_TEXT] =
    833  1.1  christos 	bfd_get_section_by_name (input_bfd, ".text");
    834  1.1  christos       symndx_to_section[RELOC_SECTION_RDATA] =
    835  1.1  christos 	bfd_get_section_by_name (input_bfd, ".rdata");
    836  1.1  christos       symndx_to_section[RELOC_SECTION_DATA] =
    837  1.1  christos 	bfd_get_section_by_name (input_bfd, ".data");
    838  1.1  christos       symndx_to_section[RELOC_SECTION_SDATA] =
    839  1.1  christos 	bfd_get_section_by_name (input_bfd, ".sdata");
    840  1.1  christos       symndx_to_section[RELOC_SECTION_SBSS] =
    841  1.1  christos 	bfd_get_section_by_name (input_bfd, ".sbss");
    842  1.1  christos       symndx_to_section[RELOC_SECTION_BSS] =
    843  1.1  christos 	bfd_get_section_by_name (input_bfd, ".bss");
    844  1.1  christos       symndx_to_section[RELOC_SECTION_INIT] =
    845  1.1  christos 	bfd_get_section_by_name (input_bfd, ".init");
    846  1.1  christos       symndx_to_section[RELOC_SECTION_LIT8] =
    847  1.1  christos 	bfd_get_section_by_name (input_bfd, ".lit8");
    848  1.1  christos       symndx_to_section[RELOC_SECTION_LIT4] =
    849  1.1  christos 	bfd_get_section_by_name (input_bfd, ".lit4");
    850  1.1  christos       symndx_to_section[RELOC_SECTION_XDATA] = NULL;
    851  1.1  christos       symndx_to_section[RELOC_SECTION_PDATA] = NULL;
    852  1.1  christos       symndx_to_section[RELOC_SECTION_FINI] =
    853  1.1  christos 	bfd_get_section_by_name (input_bfd, ".fini");
    854  1.1  christos       symndx_to_section[RELOC_SECTION_LITA] = NULL;
    855  1.1  christos       symndx_to_section[RELOC_SECTION_ABS] = NULL;
    856  1.1  christos 
    857  1.1  christos       ecoff_data (input_bfd)->symndx_to_section = symndx_to_section;
    858  1.1  christos     }
    859  1.1  christos 
    860  1.1  christos   sym_hashes = ecoff_data (input_bfd)->sym_hashes;
    861  1.1  christos 
    862  1.1  christos   gp = _bfd_get_gp_value (output_bfd);
    863  1.1  christos   if (gp == 0)
    864  1.1  christos     gp_undefined = TRUE;
    865  1.1  christos   else
    866  1.1  christos     gp_undefined = FALSE;
    867  1.1  christos 
    868  1.1  christos   got_lo = FALSE;
    869  1.1  christos 
    870  1.1  christos   ext_rel = (struct external_reloc *) external_relocs;
    871  1.1  christos   ext_rel_end = ext_rel + input_section->reloc_count;
    872  1.1  christos   for (i = 0; ext_rel < ext_rel_end; ext_rel++, i++)
    873  1.1  christos     {
    874  1.1  christos       struct internal_reloc int_rel;
    875  1.1  christos       bfd_boolean use_lo = FALSE;
    876  1.1  christos       bfd_vma addend;
    877  1.1  christos       reloc_howto_type *howto;
    878  1.1  christos       struct ecoff_link_hash_entry *h = NULL;
    879  1.1  christos       asection *s = NULL;
    880  1.1  christos       bfd_vma relocation;
    881  1.1  christos       bfd_reloc_status_type r;
    882  1.1  christos 
    883  1.1  christos       if (! got_lo)
    884  1.1  christos 	mips_ecoff_swap_reloc_in (input_bfd, ext_rel, &int_rel);
    885  1.1  christos       else
    886  1.1  christos 	{
    887  1.1  christos 	  int_rel = lo_int_rel;
    888  1.1  christos 	  got_lo = FALSE;
    889  1.1  christos 	}
    890  1.1  christos 
    891  1.1  christos       BFD_ASSERT (int_rel.r_type
    892  1.1  christos 		  < sizeof mips_howto_table / sizeof mips_howto_table[0]);
    893  1.1  christos 
    894  1.1  christos       /* The REFHI reloc requires special handling.  It must be followed
    895  1.8  christos 	 by a REFLO reloc, and the addend is formed from both relocs.  */
    896  1.1  christos       if (int_rel.r_type == MIPS_R_REFHI)
    897  1.1  christos 	{
    898  1.1  christos 	  struct external_reloc *lo_ext_rel;
    899  1.1  christos 
    900  1.1  christos 	  /* As a GNU extension, permit an arbitrary number of REFHI
    901  1.1  christos 	     relocs before the REFLO reloc.  This permits gcc to emit
    902  1.1  christos 	     the HI and LO relocs itself.  */
    903  1.1  christos 	  for (lo_ext_rel = ext_rel + 1;
    904  1.1  christos 	       lo_ext_rel < ext_rel_end;
    905  1.1  christos 	       lo_ext_rel++)
    906  1.1  christos 	    {
    907  1.1  christos 	      mips_ecoff_swap_reloc_in (input_bfd, lo_ext_rel,
    908  1.1  christos 					&lo_int_rel);
    909  1.1  christos 	      if (lo_int_rel.r_type != int_rel.r_type)
    910  1.1  christos 		break;
    911  1.1  christos 	    }
    912  1.1  christos 
    913  1.1  christos 	  if (lo_ext_rel < ext_rel_end
    914  1.1  christos 	      && lo_int_rel.r_type == MIPS_R_REFLO
    915  1.1  christos 	      && int_rel.r_extern == lo_int_rel.r_extern
    916  1.1  christos 	      && int_rel.r_symndx == lo_int_rel.r_symndx)
    917  1.1  christos 	    {
    918  1.1  christos 	      use_lo = TRUE;
    919  1.1  christos 	      if (lo_ext_rel == ext_rel + 1)
    920  1.1  christos 		got_lo = TRUE;
    921  1.1  christos 	    }
    922  1.1  christos 	}
    923  1.1  christos 
    924  1.1  christos       howto = &mips_howto_table[int_rel.r_type];
    925  1.1  christos 
    926  1.1  christos       if (int_rel.r_extern)
    927  1.1  christos 	{
    928  1.1  christos 	  h = sym_hashes[int_rel.r_symndx];
    929  1.1  christos 	  /* If h is NULL, that means that there is a reloc against an
    930  1.1  christos 	     external symbol which we thought was just a debugging
    931  1.1  christos 	     symbol.  This should not happen.  */
    932  1.1  christos 	  if (h == (struct ecoff_link_hash_entry *) NULL)
    933  1.1  christos 	    abort ();
    934  1.1  christos 	}
    935  1.1  christos       else
    936  1.1  christos 	{
    937  1.1  christos 	  if (int_rel.r_symndx < 0 || int_rel.r_symndx >= NUM_RELOC_SECTIONS)
    938  1.1  christos 	    s = NULL;
    939  1.1  christos 	  else
    940  1.1  christos 	    s = symndx_to_section[int_rel.r_symndx];
    941  1.1  christos 
    942  1.1  christos 	  if (s == (asection *) NULL)
    943  1.1  christos 	    abort ();
    944  1.1  christos 	}
    945  1.1  christos 
    946  1.1  christos       /* The GPREL reloc uses an addend: the difference in the GP
    947  1.1  christos 	 values.  */
    948  1.1  christos       if (int_rel.r_type != MIPS_R_GPREL
    949  1.6  christos 	  && int_rel.r_type != MIPS_R_LITERAL)
    950  1.6  christos 	addend = 0;
    951  1.6  christos       else
    952  1.6  christos 	{
    953  1.1  christos 	  if (gp_undefined)
    954  1.1  christos 	    {
    955  1.1  christos 	      (*info->callbacks->reloc_dangerous)
    956  1.1  christos 		(info, _("GP relative relocation used when GP not defined"),
    957  1.1  christos 		 input_bfd, input_section,
    958  1.1  christos 		 int_rel.r_vaddr - input_section->vma);
    959  1.1  christos 	      /* Only give the error once per link.  */
    960  1.1  christos 	      gp = 4;
    961  1.1  christos 	      _bfd_set_gp_value (output_bfd, gp);
    962  1.1  christos 	      gp_undefined = FALSE;
    963  1.1  christos 	    }
    964  1.1  christos 	  if (! int_rel.r_extern)
    965  1.1  christos 	    {
    966  1.1  christos 	      /* This is a relocation against a section.  The current
    967  1.1  christos 		 addend in the instruction is the difference between
    968  1.6  christos 		 INPUT_SECTION->vma and the GP value of INPUT_BFD.  We
    969  1.1  christos 		 must change this to be the difference between the
    970  1.1  christos 		 final definition (which will end up in RELOCATION)
    971  1.1  christos 		 and the GP value of OUTPUT_BFD (which is in GP).  */
    972  1.1  christos 	      addend = ecoff_data (input_bfd)->gp - gp;
    973  1.1  christos 	    }
    974  1.1  christos 	  else if (! bfd_link_relocatable (info)
    975  1.1  christos 		   || h->root.type == bfd_link_hash_defined
    976  1.1  christos 		   || h->root.type == bfd_link_hash_defweak)
    977  1.1  christos 	    {
    978  1.1  christos 	      /* This is a relocation against a defined symbol.  The
    979  1.1  christos 		 current addend in the instruction is simply the
    980  1.1  christos 		 desired offset into the symbol (normally zero).  We
    981  1.1  christos 		 are going to change this into a relocation against a
    982  1.1  christos 		 defined symbol, so we want the instruction to hold
    983  1.1  christos 		 the difference between the final definition of the
    984  1.1  christos 		 symbol (which will end up in RELOCATION) and the GP
    985  1.1  christos 		 value of OUTPUT_BFD (which is in GP).  */
    986  1.1  christos 	      addend = - gp;
    987  1.1  christos 	    }
    988  1.1  christos 	  else
    989  1.1  christos 	    {
    990  1.1  christos 	      /* This is a relocation against an undefined or common
    991  1.1  christos 		 symbol.  The current addend in the instruction is
    992  1.1  christos 		 simply the desired offset into the symbol (normally
    993  1.1  christos 		 zero).  We are generating relocatable output, and we
    994  1.6  christos 		 aren't going to define this symbol, so we just leave
    995  1.1  christos 		 the instruction alone.  */
    996  1.1  christos 	      addend = 0;
    997  1.1  christos 	    }
    998  1.1  christos 	}
    999  1.1  christos 
   1000  1.1  christos       if (bfd_link_relocatable (info))
   1001  1.1  christos 	{
   1002  1.1  christos 	  /* We are generating relocatable output, and must convert
   1003  1.1  christos 	     the existing reloc.  */
   1004  1.1  christos 	  if (int_rel.r_extern)
   1005  1.1  christos 	    {
   1006  1.1  christos 	      if ((h->root.type == bfd_link_hash_defined
   1007  1.1  christos 		   || h->root.type == bfd_link_hash_defweak)
   1008  1.1  christos 		  && ! bfd_is_abs_section (h->root.u.def.section))
   1009  1.1  christos 		{
   1010  1.1  christos 		  const char *name;
   1011  1.1  christos 
   1012  1.1  christos 		  /* This symbol is defined in the output.  Convert
   1013  1.1  christos 		     the reloc from being against the symbol to being
   1014  1.1  christos 		     against the section.  */
   1015  1.1  christos 
   1016  1.1  christos 		  /* Clear the r_extern bit.  */
   1017  1.1  christos 		  int_rel.r_extern = 0;
   1018  1.1  christos 
   1019  1.1  christos 		  /* Compute a new r_symndx value.  */
   1020  1.1  christos 		  s = h->root.u.def.section;
   1021  1.1  christos 		  name = bfd_get_section_name (output_bfd,
   1022  1.1  christos 					       s->output_section);
   1023  1.1  christos 
   1024  1.1  christos 		  int_rel.r_symndx = -1;
   1025  1.1  christos 		  switch (name[1])
   1026  1.1  christos 		    {
   1027  1.1  christos 		    case 'b':
   1028  1.1  christos 		      if (strcmp (name, ".bss") == 0)
   1029  1.1  christos 			int_rel.r_symndx = RELOC_SECTION_BSS;
   1030  1.1  christos 		      break;
   1031  1.1  christos 		    case 'd':
   1032  1.1  christos 		      if (strcmp (name, ".data") == 0)
   1033  1.1  christos 			int_rel.r_symndx = RELOC_SECTION_DATA;
   1034  1.1  christos 		      break;
   1035  1.1  christos 		    case 'f':
   1036  1.1  christos 		      if (strcmp (name, ".fini") == 0)
   1037  1.1  christos 			int_rel.r_symndx = RELOC_SECTION_FINI;
   1038  1.1  christos 		      break;
   1039  1.1  christos 		    case 'i':
   1040  1.1  christos 		      if (strcmp (name, ".init") == 0)
   1041  1.1  christos 			int_rel.r_symndx = RELOC_SECTION_INIT;
   1042  1.1  christos 		      break;
   1043  1.1  christos 		    case 'l':
   1044  1.1  christos 		      if (strcmp (name, ".lit8") == 0)
   1045  1.1  christos 			int_rel.r_symndx = RELOC_SECTION_LIT8;
   1046  1.1  christos 		      else if (strcmp (name, ".lit4") == 0)
   1047  1.1  christos 			int_rel.r_symndx = RELOC_SECTION_LIT4;
   1048  1.1  christos 		      break;
   1049  1.1  christos 		    case 'r':
   1050  1.1  christos 		      if (strcmp (name, ".rdata") == 0)
   1051  1.1  christos 			int_rel.r_symndx = RELOC_SECTION_RDATA;
   1052  1.1  christos 		      break;
   1053  1.1  christos 		    case 's':
   1054  1.1  christos 		      if (strcmp (name, ".sdata") == 0)
   1055  1.1  christos 			int_rel.r_symndx = RELOC_SECTION_SDATA;
   1056  1.1  christos 		      else if (strcmp (name, ".sbss") == 0)
   1057  1.1  christos 			int_rel.r_symndx = RELOC_SECTION_SBSS;
   1058  1.1  christos 		      break;
   1059  1.1  christos 		    case 't':
   1060  1.1  christos 		      if (strcmp (name, ".text") == 0)
   1061  1.1  christos 			int_rel.r_symndx = RELOC_SECTION_TEXT;
   1062  1.1  christos 		      break;
   1063  1.1  christos 		    }
   1064  1.1  christos 
   1065  1.1  christos 		  if (int_rel.r_symndx == -1)
   1066  1.1  christos 		    abort ();
   1067  1.1  christos 
   1068  1.1  christos 		  /* Add the section VMA and the symbol value.  */
   1069  1.1  christos 		  relocation = (h->root.u.def.value
   1070  1.1  christos 				+ s->output_section->vma
   1071  1.1  christos 				+ s->output_offset);
   1072  1.1  christos 
   1073  1.1  christos 		  /* For a PC relative relocation, the object file
   1074  1.1  christos 		     currently holds just the addend.  We must adjust
   1075  1.1  christos 		     by the address to get the right value.  */
   1076  1.1  christos 		  if (howto->pc_relative)
   1077  1.1  christos 		    relocation -= int_rel.r_vaddr - input_section->vma;
   1078  1.1  christos 
   1079  1.1  christos 		  h = NULL;
   1080  1.1  christos 		}
   1081  1.1  christos 	      else
   1082  1.1  christos 		{
   1083  1.6  christos 		  /* Change the symndx value to the right one for the
   1084  1.6  christos 		     output BFD.  */
   1085  1.6  christos 		  int_rel.r_symndx = h->indx;
   1086  1.1  christos 		  if (int_rel.r_symndx == -1)
   1087  1.1  christos 		    {
   1088  1.1  christos 		      /* This symbol is not being written out.  */
   1089  1.1  christos 		      (*info->callbacks->unattached_reloc)
   1090  1.1  christos 			(info, h->root.root.string, input_bfd, input_section,
   1091  1.1  christos 			 int_rel.r_vaddr - input_section->vma);
   1092  1.1  christos 		      int_rel.r_symndx = 0;
   1093  1.1  christos 		    }
   1094  1.1  christos 		  relocation = 0;
   1095  1.1  christos 		}
   1096  1.1  christos 	    }
   1097  1.1  christos 	  else
   1098  1.1  christos 	    {
   1099  1.1  christos 	      /* This is a relocation against a section.  Adjust the
   1100  1.1  christos 		 value by the amount the section moved.  */
   1101  1.1  christos 	      relocation = (s->output_section->vma
   1102  1.1  christos 			    + s->output_offset
   1103  1.1  christos 			    - s->vma);
   1104  1.1  christos 	    }
   1105  1.1  christos 
   1106  1.1  christos 	  relocation += addend;
   1107  1.1  christos 	  addend = 0;
   1108  1.1  christos 
   1109  1.1  christos 	  /* Adjust a PC relative relocation by removing the reference
   1110  1.1  christos 	     to the original address in the section and including the
   1111  1.1  christos 	     reference to the new address.  */
   1112  1.1  christos 	  if (howto->pc_relative)
   1113  1.1  christos 	    relocation -= (input_section->output_section->vma
   1114  1.1  christos 			   + input_section->output_offset
   1115  1.1  christos 			   - input_section->vma);
   1116  1.1  christos 
   1117  1.1  christos 	  /* Adjust the contents.  */
   1118  1.1  christos 	  if (relocation == 0)
   1119  1.1  christos 	    r = bfd_reloc_ok;
   1120  1.1  christos 	  else
   1121  1.1  christos 	    {
   1122  1.1  christos 	      if (int_rel.r_type != MIPS_R_REFHI)
   1123  1.1  christos 		r = _bfd_relocate_contents (howto, input_bfd, relocation,
   1124  1.1  christos 					    (contents
   1125  1.1  christos 					     + int_rel.r_vaddr
   1126  1.1  christos 					     - input_section->vma));
   1127  1.1  christos 	      else
   1128  1.1  christos 		{
   1129  1.1  christos 		  mips_relocate_hi (&int_rel,
   1130  1.1  christos 				    use_lo ? &lo_int_rel : NULL,
   1131  1.1  christos 				    input_bfd, input_section, contents,
   1132  1.1  christos 				    relocation);
   1133  1.1  christos 		  r = bfd_reloc_ok;
   1134  1.1  christos 		}
   1135  1.1  christos 	    }
   1136  1.1  christos 
   1137  1.1  christos 	  /* Adjust the reloc address.  */
   1138  1.1  christos 	  int_rel.r_vaddr += (input_section->output_section->vma
   1139  1.1  christos 			      + input_section->output_offset
   1140  1.1  christos 			      - input_section->vma);
   1141  1.1  christos 
   1142  1.1  christos 	  /* Save the changed reloc information.  */
   1143  1.1  christos 	  mips_ecoff_swap_reloc_out (input_bfd, &int_rel, ext_rel);
   1144  1.1  christos 	}
   1145  1.1  christos       else
   1146  1.1  christos 	{
   1147  1.1  christos 	  /* We are producing a final executable.  */
   1148  1.1  christos 	  if (int_rel.r_extern)
   1149  1.1  christos 	    {
   1150  1.1  christos 	      /* This is a reloc against a symbol.  */
   1151  1.1  christos 	      if (h->root.type == bfd_link_hash_defined
   1152  1.1  christos 		  || h->root.type == bfd_link_hash_defweak)
   1153  1.1  christos 		{
   1154  1.1  christos 		  asection *hsec;
   1155  1.1  christos 
   1156  1.1  christos 		  hsec = h->root.u.def.section;
   1157  1.6  christos 		  relocation = (h->root.u.def.value
   1158  1.6  christos 				+ hsec->output_section->vma
   1159  1.6  christos 				+ hsec->output_offset);
   1160  1.1  christos 		}
   1161  1.1  christos 	      else
   1162  1.1  christos 		{
   1163  1.1  christos 		  (*info->callbacks->undefined_symbol)
   1164  1.1  christos 		    (info, h->root.root.string, input_bfd, input_section,
   1165  1.1  christos 		     int_rel.r_vaddr - input_section->vma, TRUE);
   1166  1.1  christos 		  relocation = 0;
   1167  1.1  christos 		}
   1168  1.1  christos 	    }
   1169  1.1  christos 	  else
   1170  1.1  christos 	    {
   1171  1.1  christos 	      /* This is a reloc against a section.  */
   1172  1.1  christos 	      relocation = (s->output_section->vma
   1173  1.1  christos 			    + s->output_offset
   1174  1.1  christos 			    - s->vma);
   1175  1.1  christos 
   1176  1.1  christos 	      /* A PC relative reloc is already correct in the object
   1177  1.1  christos 		 file.  Make it look like a pcrel_offset relocation by
   1178  1.1  christos 		 adding in the start address.  */
   1179  1.1  christos 	      if (howto->pc_relative)
   1180  1.1  christos 		relocation += int_rel.r_vaddr;
   1181  1.1  christos 	    }
   1182  1.1  christos 
   1183  1.1  christos 	  if (int_rel.r_type != MIPS_R_REFHI)
   1184  1.1  christos 	    r = _bfd_final_link_relocate (howto,
   1185  1.1  christos 					  input_bfd,
   1186  1.1  christos 					  input_section,
   1187  1.1  christos 					  contents,
   1188  1.1  christos 					  (int_rel.r_vaddr
   1189  1.1  christos 					   - input_section->vma),
   1190  1.1  christos 					  relocation,
   1191  1.1  christos 					  addend);
   1192  1.1  christos 	  else
   1193  1.1  christos 	    {
   1194  1.1  christos 	      mips_relocate_hi (&int_rel,
   1195  1.1  christos 				use_lo ? &lo_int_rel : NULL,
   1196  1.1  christos 				input_bfd, input_section, contents,
   1197  1.1  christos 				relocation);
   1198  1.1  christos 	      r = bfd_reloc_ok;
   1199  1.1  christos 	    }
   1200  1.1  christos 	}
   1201  1.1  christos 
   1202  1.1  christos       /* MIPS_R_JMPADDR requires peculiar overflow detection.  The
   1203  1.1  christos 	 instruction provides a 28 bit address (the two lower bits are
   1204  1.1  christos 	 implicit zeroes) which is combined with the upper four bits
   1205  1.1  christos 	 of the instruction address.  */
   1206  1.1  christos       if (r == bfd_reloc_ok
   1207  1.1  christos 	  && int_rel.r_type == MIPS_R_JMPADDR
   1208  1.1  christos 	  && (((relocation
   1209  1.1  christos 		+ addend
   1210  1.1  christos 		+ (int_rel.r_extern ? 0 : s->vma))
   1211  1.1  christos 	       & 0xf0000000)
   1212  1.1  christos 	      != ((input_section->output_section->vma
   1213  1.1  christos 		   + input_section->output_offset
   1214  1.1  christos 		   + (int_rel.r_vaddr - input_section->vma))
   1215  1.1  christos 		  & 0xf0000000)))
   1216  1.1  christos 	r = bfd_reloc_overflow;
   1217  1.1  christos 
   1218  1.1  christos       if (r != bfd_reloc_ok)
   1219  1.1  christos 	{
   1220  1.1  christos 	  switch (r)
   1221  1.1  christos 	    {
   1222  1.1  christos 	    default:
   1223  1.1  christos 	    case bfd_reloc_outofrange:
   1224  1.1  christos 	      abort ();
   1225  1.1  christos 	    case bfd_reloc_overflow:
   1226  1.1  christos 	      {
   1227  1.6  christos 		const char *name;
   1228  1.6  christos 
   1229  1.6  christos 		if (int_rel.r_extern)
   1230  1.6  christos 		  name = NULL;
   1231  1.1  christos 		else
   1232  1.1  christos 		  name = bfd_section_name (input_bfd, s);
   1233  1.1  christos 		(*info->callbacks->reloc_overflow)
   1234  1.1  christos 		  (info, (h ? &h->root : NULL), name, howto->name,
   1235  1.1  christos 		   (bfd_vma) 0, input_bfd, input_section,
   1236  1.1  christos 		   int_rel.r_vaddr - input_section->vma);
   1237  1.1  christos 	      }
   1238  1.1  christos 	      break;
   1239  1.8  christos 	    }
   1240  1.8  christos 	}
   1241  1.8  christos     }
   1242  1.8  christos 
   1243  1.8  christos   return TRUE;
   1244  1.8  christos }
   1245  1.8  christos 
   1246  1.8  christos static void
   1247  1.8  christos mips_ecoff_swap_coff_aux_in (bfd *abfd ATTRIBUTE_UNUSED,
   1248  1.8  christos 			     void *ext1 ATTRIBUTE_UNUSED,
   1249  1.8  christos 			     int type ATTRIBUTE_UNUSED,
   1250  1.8  christos 			     int in_class ATTRIBUTE_UNUSED,
   1251  1.8  christos 			     int indx ATTRIBUTE_UNUSED,
   1252  1.8  christos 			     int numaux ATTRIBUTE_UNUSED,
   1253  1.8  christos 			     void *in1 ATTRIBUTE_UNUSED)
   1254  1.8  christos {
   1255  1.8  christos }
   1256  1.8  christos 
   1257  1.8  christos static void
   1258  1.8  christos mips_ecoff_swap_coff_sym_in (bfd *abfd ATTRIBUTE_UNUSED,
   1259  1.8  christos 			     void *ext1 ATTRIBUTE_UNUSED,
   1260  1.8  christos 			     void *in1 ATTRIBUTE_UNUSED)
   1261  1.8  christos {
   1262  1.8  christos }
   1263  1.8  christos 
   1264  1.8  christos static void
   1265  1.8  christos mips_ecoff_swap_coff_lineno_in (bfd *abfd ATTRIBUTE_UNUSED,
   1266  1.8  christos 				void *ext1 ATTRIBUTE_UNUSED,
   1267  1.8  christos 				void *in1 ATTRIBUTE_UNUSED)
   1268  1.8  christos {
   1269  1.8  christos }
   1270  1.8  christos 
   1271  1.8  christos static unsigned int
   1272  1.8  christos mips_ecoff_swap_coff_aux_out (bfd *abfd ATTRIBUTE_UNUSED,
   1273  1.8  christos 			      void *inp ATTRIBUTE_UNUSED,
   1274  1.8  christos 			      int type ATTRIBUTE_UNUSED,
   1275  1.8  christos 			      int in_class ATTRIBUTE_UNUSED,
   1276  1.8  christos 			      int indx ATTRIBUTE_UNUSED,
   1277  1.8  christos 			      int numaux ATTRIBUTE_UNUSED,
   1278  1.8  christos 			      void *extp ATTRIBUTE_UNUSED)
   1279  1.8  christos {
   1280  1.8  christos   return 0;
   1281  1.8  christos }
   1282  1.8  christos 
   1283  1.8  christos static unsigned int
   1284  1.8  christos mips_ecoff_swap_coff_sym_out (bfd *abfd ATTRIBUTE_UNUSED,
   1285  1.8  christos 			      void *inp ATTRIBUTE_UNUSED,
   1286  1.8  christos 			      void *extp ATTRIBUTE_UNUSED)
   1287  1.8  christos {
   1288  1.8  christos   return 0;
   1289  1.8  christos }
   1290  1.8  christos 
   1291  1.8  christos static unsigned int
   1292  1.8  christos mips_ecoff_swap_coff_lineno_out (bfd *abfd ATTRIBUTE_UNUSED,
   1293  1.8  christos 				 void *inp ATTRIBUTE_UNUSED,
   1294  1.8  christos 				 void *extp ATTRIBUTE_UNUSED)
   1295  1.8  christos {
   1296  1.8  christos   return 0;
   1297  1.8  christos }
   1298  1.8  christos 
   1299  1.8  christos static unsigned int
   1300  1.1  christos mips_ecoff_swap_coff_reloc_out (bfd *abfd ATTRIBUTE_UNUSED,
   1301  1.1  christos 				void *inp ATTRIBUTE_UNUSED,
   1302  1.1  christos 				void *extp ATTRIBUTE_UNUSED)
   1303  1.1  christos {
   1304  1.1  christos   return 0;
   1305  1.1  christos }
   1306  1.1  christos 
   1307  1.1  christos /* This is the ECOFF backend structure.  The backend field of the
   1309  1.8  christos    target vector points to this.  */
   1310  1.8  christos 
   1311  1.8  christos static const struct ecoff_backend_data mips_ecoff_backend_data =
   1312  1.1  christos {
   1313  1.1  christos   /* COFF backend structure.  */
   1314  1.1  christos   {
   1315  1.3  christos     mips_ecoff_swap_coff_aux_in, mips_ecoff_swap_coff_sym_in,
   1316  1.1  christos     mips_ecoff_swap_coff_lineno_in, mips_ecoff_swap_coff_aux_out,
   1317  1.1  christos     mips_ecoff_swap_coff_sym_out, mips_ecoff_swap_coff_lineno_out,
   1318  1.1  christos     mips_ecoff_swap_coff_reloc_out,
   1319  1.1  christos     mips_ecoff_swap_filehdr_out, mips_ecoff_swap_aouthdr_out,
   1320  1.1  christos     mips_ecoff_swap_scnhdr_out,
   1321  1.1  christos     FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, 0, FILNMLEN, TRUE,
   1322  1.1  christos     ECOFF_NO_LONG_SECTION_NAMES, 4, FALSE, 2, 32768,
   1323  1.1  christos     mips_ecoff_swap_filehdr_in, mips_ecoff_swap_aouthdr_in,
   1324  1.1  christos     mips_ecoff_swap_scnhdr_in, NULL,
   1325  1.1  christos     mips_ecoff_bad_format_hook, _bfd_ecoff_set_arch_mach_hook,
   1326  1.1  christos     _bfd_ecoff_mkobject_hook, _bfd_ecoff_styp_to_sec_flags,
   1327  1.1  christos     _bfd_ecoff_set_alignment_hook, _bfd_ecoff_slurp_symbol_table,
   1328  1.1  christos     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
   1329  1.1  christos     NULL, NULL, NULL
   1330  1.1  christos   },
   1331  1.1  christos   /* Supported architecture.  */
   1332  1.1  christos   bfd_arch_mips,
   1333  1.1  christos   /* Initial portion of armap string.  */
   1334  1.1  christos   "__________",
   1335  1.1  christos   /* The page boundary used to align sections in a demand-paged
   1336  1.1  christos      executable file.  E.g., 0x1000.  */
   1337  1.1  christos   0x1000,
   1338  1.1  christos   /* TRUE if the .rdata section is part of the text segment, as on the
   1339  1.1  christos      Alpha.  FALSE if .rdata is part of the data segment, as on the
   1340  1.1  christos      MIPS.  */
   1341  1.1  christos   FALSE,
   1342  1.1  christos   /* Bitsize of constructor entries.  */
   1343  1.1  christos   32,
   1344  1.1  christos   /* Reloc to use for constructor entries.  */
   1345  1.1  christos   &mips_howto_table[MIPS_R_REFWORD],
   1346  1.1  christos   {
   1347  1.1  christos     /* Symbol table magic number.  */
   1348  1.1  christos     magicSym,
   1349  1.1  christos     /* Alignment of debugging information.  E.g., 4.  */
   1350  1.1  christos     4,
   1351  1.1  christos     /* Sizes of external symbolic information.  */
   1352  1.1  christos     sizeof (struct hdr_ext),
   1353  1.1  christos     sizeof (struct dnr_ext),
   1354  1.1  christos     sizeof (struct pdr_ext),
   1355  1.1  christos     sizeof (struct sym_ext),
   1356  1.1  christos     sizeof (struct opt_ext),
   1357  1.1  christos     sizeof (struct fdr_ext),
   1358  1.1  christos     sizeof (struct rfd_ext),
   1359  1.1  christos     sizeof (struct ext_ext),
   1360  1.1  christos     /* Functions to swap in external symbolic data.  */
   1361  1.1  christos     ecoff_swap_hdr_in,
   1362  1.1  christos     ecoff_swap_dnr_in,
   1363  1.1  christos     ecoff_swap_pdr_in,
   1364  1.1  christos     ecoff_swap_sym_in,
   1365  1.1  christos     ecoff_swap_opt_in,
   1366  1.1  christos     ecoff_swap_fdr_in,
   1367  1.1  christos     ecoff_swap_rfd_in,
   1368  1.1  christos     ecoff_swap_ext_in,
   1369  1.1  christos     _bfd_ecoff_swap_tir_in,
   1370  1.1  christos     _bfd_ecoff_swap_rndx_in,
   1371  1.1  christos     /* Functions to swap out external symbolic data.  */
   1372  1.1  christos     ecoff_swap_hdr_out,
   1373  1.1  christos     ecoff_swap_dnr_out,
   1374  1.1  christos     ecoff_swap_pdr_out,
   1375  1.1  christos     ecoff_swap_sym_out,
   1376  1.1  christos     ecoff_swap_opt_out,
   1377  1.1  christos     ecoff_swap_fdr_out,
   1378  1.1  christos     ecoff_swap_rfd_out,
   1379  1.1  christos     ecoff_swap_ext_out,
   1380  1.1  christos     _bfd_ecoff_swap_tir_out,
   1381  1.1  christos     _bfd_ecoff_swap_rndx_out,
   1382  1.1  christos     /* Function to read in symbolic data.  */
   1383  1.1  christos     _bfd_ecoff_slurp_symbolic_info
   1384  1.1  christos   },
   1385  1.1  christos   /* External reloc size.  */
   1386  1.1  christos   RELSZ,
   1387  1.1  christos   /* Reloc swapping functions.  */
   1388  1.1  christos   mips_ecoff_swap_reloc_in,
   1389  1.1  christos   mips_ecoff_swap_reloc_out,
   1390  1.1  christos   /* Backend reloc tweaking.  */
   1391  1.1  christos   mips_adjust_reloc_in,
   1392  1.1  christos   mips_adjust_reloc_out,
   1393  1.1  christos   /* Relocate section contents while linking.  */
   1394  1.1  christos   mips_relocate_section,
   1395  1.1  christos   /* Do final adjustments to filehdr and aouthdr.  */
   1396  1.1  christos   NULL,
   1397  1.1  christos   /* Read an element from an archive at a given file position.  */
   1398  1.1  christos   _bfd_get_elt_at_filepos
   1399  1.1  christos };
   1400  1.1  christos 
   1401  1.1  christos /* Looking up a reloc type is MIPS specific.  */
   1402  1.1  christos #define _bfd_ecoff_bfd_reloc_type_lookup mips_bfd_reloc_type_lookup
   1403  1.1  christos #define _bfd_ecoff_bfd_reloc_name_lookup mips_bfd_reloc_name_lookup
   1404  1.1  christos 
   1405  1.1  christos /* Getting relocated section contents is generic.  */
   1406  1.1  christos #define _bfd_ecoff_bfd_get_relocated_section_contents \
   1407  1.1  christos   bfd_generic_get_relocated_section_contents
   1408  1.1  christos 
   1409  1.1  christos /* Handling file windows is generic.  */
   1410  1.1  christos #define _bfd_ecoff_get_section_contents_in_window \
   1411  1.1  christos   _bfd_generic_get_section_contents_in_window
   1412  1.1  christos 
   1413  1.1  christos /* Relaxing sections is MIPS specific.  */
   1414  1.1  christos #define _bfd_ecoff_bfd_relax_section bfd_generic_relax_section
   1415  1.1  christos 
   1416  1.1  christos /* GC of sections is not done.  */
   1417  1.1  christos #define _bfd_ecoff_bfd_gc_sections bfd_generic_gc_sections
   1418  1.1  christos 
   1419  1.1  christos /* Input section flags is not implemented.  */
   1420  1.1  christos #define _bfd_ecoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
   1421  1.1  christos 
   1422  1.1  christos /* Merging of sections is not done.  */
   1423  1.8  christos #define _bfd_ecoff_bfd_merge_sections bfd_generic_merge_sections
   1424  1.8  christos 
   1425  1.8  christos #define _bfd_ecoff_bfd_is_group_section bfd_generic_is_group_section
   1426  1.1  christos #define _bfd_ecoff_bfd_discard_group bfd_generic_discard_group
   1427  1.3  christos #define _bfd_ecoff_section_already_linked \
   1428  1.1  christos   _bfd_coff_section_already_linked
   1429  1.3  christos #define _bfd_ecoff_bfd_define_common_symbol bfd_generic_define_common_symbol
   1430  1.1  christos #define _bfd_ecoff_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
   1431  1.1  christos #define _bfd_ecoff_bfd_define_start_stop bfd_generic_define_start_stop
   1432  1.1  christos #define _bfd_ecoff_set_reloc _bfd_generic_set_reloc
   1433  1.1  christos 
   1434  1.1  christos extern const bfd_target mips_ecoff_be_vec;
   1435  1.1  christos 
   1436  1.8  christos const bfd_target mips_ecoff_le_vec =
   1437  1.8  christos {
   1438  1.8  christos   "ecoff-littlemips",		/* name */
   1439  1.1  christos   bfd_target_ecoff_flavour,
   1440  1.1  christos   BFD_ENDIAN_LITTLE,		/* data byte order is little */
   1441  1.1  christos   BFD_ENDIAN_LITTLE,		/* header byte order is little */
   1442  1.1  christos 
   1443  1.1  christos   (HAS_RELOC | EXEC_P		/* object flags */
   1444  1.1  christos    | HAS_LINENO | HAS_DEBUG
   1445  1.1  christos    | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
   1446  1.1  christos 
   1447  1.1  christos   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA),
   1448  1.1  christos   0,				/* leading underscore */
   1449  1.1  christos   ' ',				/* ar_pad_char */
   1450  1.1  christos   15,				/* ar_max_namelen */
   1451  1.1  christos   0,				/* match priority.  */
   1452  1.8  christos   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
   1453  1.8  christos      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
   1454  1.8  christos      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
   1455  1.8  christos   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
   1456  1.8  christos      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
   1457  1.8  christos      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
   1458  1.8  christos 
   1459  1.8  christos   {				/* bfd_check_format */
   1460  1.8  christos     _bfd_dummy_target,
   1461  1.8  christos     coff_object_p,
   1462  1.8  christos     bfd_generic_archive_p,
   1463  1.8  christos     _bfd_dummy_target
   1464  1.8  christos   },
   1465  1.8  christos   {				/* bfd_set_format */
   1466  1.8  christos     _bfd_bool_bfd_false_error,
   1467  1.8  christos     _bfd_ecoff_mkobject,
   1468  1.8  christos     _bfd_generic_mkarchive,
   1469  1.8  christos     _bfd_bool_bfd_false_error
   1470  1.8  christos   },
   1471  1.8  christos   {				/* bfd_write_contents */
   1472  1.8  christos     _bfd_bool_bfd_false_error,
   1473  1.8  christos     _bfd_ecoff_write_object_contents,
   1474  1.8  christos     _bfd_write_archive_contents,
   1475  1.8  christos     _bfd_bool_bfd_false_error
   1476  1.8  christos   },
   1477  1.8  christos 
   1478  1.8  christos   BFD_JUMP_TABLE_GENERIC (_bfd_ecoff),
   1479  1.8  christos   BFD_JUMP_TABLE_COPY (_bfd_ecoff),
   1480  1.1  christos   BFD_JUMP_TABLE_CORE (_bfd_nocore),
   1481  1.8  christos   BFD_JUMP_TABLE_ARCHIVE (_bfd_ecoff),
   1482  1.1  christos   BFD_JUMP_TABLE_SYMBOLS (_bfd_ecoff),
   1483  1.8  christos   BFD_JUMP_TABLE_RELOCS (_bfd_ecoff),
   1484  1.1  christos   BFD_JUMP_TABLE_WRITE (_bfd_ecoff),
   1485  1.1  christos   BFD_JUMP_TABLE_LINK (_bfd_ecoff),
   1486  1.3  christos   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
   1487  1.1  christos 
   1488  1.1  christos   &mips_ecoff_be_vec,
   1489  1.1  christos 
   1490  1.1  christos   &mips_ecoff_backend_data
   1491  1.1  christos };
   1492  1.1  christos 
   1493  1.8  christos const bfd_target mips_ecoff_be_vec =
   1494  1.8  christos {
   1495  1.8  christos   "ecoff-bigmips",		/* name */
   1496  1.1  christos   bfd_target_ecoff_flavour,
   1497  1.1  christos   BFD_ENDIAN_BIG,		/* data byte order is big */
   1498  1.1  christos   BFD_ENDIAN_BIG,		/* header byte order is big */
   1499  1.1  christos 
   1500  1.1  christos   (HAS_RELOC | EXEC_P		/* object flags */
   1501  1.1  christos    | HAS_LINENO | HAS_DEBUG
   1502  1.1  christos    | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
   1503  1.1  christos 
   1504  1.1  christos   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA),
   1505  1.1  christos   0,				/* leading underscore */
   1506  1.1  christos   ' ',				/* ar_pad_char */
   1507  1.1  christos   15,				/* ar_max_namelen */
   1508  1.1  christos   0,				/* match priority.  */
   1509  1.8  christos   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
   1510  1.8  christos      bfd_getb32, bfd_getb_signed_32, bfd_putb32,
   1511  1.8  christos      bfd_getb16, bfd_getb_signed_16, bfd_putb16,
   1512  1.8  christos   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
   1513  1.8  christos      bfd_getb32, bfd_getb_signed_32, bfd_putb32,
   1514  1.8  christos      bfd_getb16, bfd_getb_signed_16, bfd_putb16,
   1515  1.8  christos 
   1516  1.8  christos   {				/* bfd_check_format */
   1517  1.8  christos     _bfd_dummy_target,
   1518  1.8  christos     coff_object_p,
   1519  1.8  christos     bfd_generic_archive_p,
   1520  1.8  christos     _bfd_dummy_target
   1521  1.8  christos   },
   1522  1.8  christos   {				/* bfd_set_format */
   1523  1.8  christos     _bfd_bool_bfd_false_error,
   1524  1.8  christos     _bfd_ecoff_mkobject,
   1525  1.8  christos     _bfd_generic_mkarchive,
   1526  1.8  christos     _bfd_bool_bfd_false_error
   1527  1.8  christos   },
   1528  1.8  christos   {				/* bfd_write_contents */
   1529  1.8  christos     _bfd_bool_bfd_false_error,
   1530  1.8  christos     _bfd_ecoff_write_object_contents,
   1531  1.8  christos     _bfd_write_archive_contents,
   1532  1.8  christos     _bfd_bool_bfd_false_error
   1533  1.8  christos   },
   1534  1.8  christos 
   1535  1.8  christos   BFD_JUMP_TABLE_GENERIC (_bfd_ecoff),
   1536  1.8  christos   BFD_JUMP_TABLE_COPY (_bfd_ecoff),
   1537  1.8  christos   BFD_JUMP_TABLE_CORE (_bfd_nocore),
   1538  1.8  christos   BFD_JUMP_TABLE_ARCHIVE (_bfd_ecoff),
   1539  1.1  christos   BFD_JUMP_TABLE_SYMBOLS (_bfd_ecoff),
   1540  1.8  christos   BFD_JUMP_TABLE_RELOCS (_bfd_ecoff),
   1541  1.1  christos   BFD_JUMP_TABLE_WRITE (_bfd_ecoff),
   1542  1.1  christos   BFD_JUMP_TABLE_LINK (_bfd_ecoff),
   1543  1.3  christos   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
   1544  1.1  christos 
   1545  1.1  christos   &mips_ecoff_le_vec,
   1546  1.1  christos 
   1547  1.1  christos   &mips_ecoff_backend_data
   1548  1.1  christos };
   1549  1.1  christos 
   1550  1.8  christos const bfd_target mips_ecoff_bele_vec =
   1551  1.8  christos {
   1552  1.8  christos   "ecoff-biglittlemips",		/* name */
   1553  1.1  christos   bfd_target_ecoff_flavour,
   1554  1.1  christos   BFD_ENDIAN_LITTLE,		/* data byte order is little */
   1555  1.1  christos   BFD_ENDIAN_BIG,		/* header byte order is big */
   1556  1.1  christos 
   1557  1.1  christos   (HAS_RELOC | EXEC_P		/* object flags */
   1558  1.1  christos    | HAS_LINENO | HAS_DEBUG
   1559  1.1  christos    | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
   1560  1.1  christos 
   1561  1.1  christos   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA),
   1562  1.1  christos   0,				/* leading underscore */
   1563  1.1  christos   ' ',				/* ar_pad_char */
   1564  1.1  christos   15,				/* ar_max_namelen */
   1565  1.1  christos   0,				/* match priority.  */
   1566  1.8  christos   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
   1567  1.8  christos      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
   1568  1.8  christos      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
   1569  1.8  christos   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
   1570  1.8  christos      bfd_getb32, bfd_getb_signed_32, bfd_putb32,
   1571  1.8  christos      bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
   1572  1.8  christos 
   1573  1.8  christos   {				/* bfd_check_format */
   1574  1.8  christos     _bfd_dummy_target,
   1575  1.8  christos     coff_object_p,
   1576  1.8  christos     bfd_generic_archive_p,
   1577  1.8  christos     _bfd_dummy_target
   1578  1.8  christos   },
   1579  1.8  christos   {				/* bfd_set_format */
   1580  1.8  christos     _bfd_bool_bfd_false_error,
   1581  1.8  christos     _bfd_ecoff_mkobject,
   1582  1.8  christos     _bfd_generic_mkarchive,
   1583  1.8  christos     _bfd_bool_bfd_false_error
   1584  1.8  christos   },
   1585  1.8  christos   {				/* bfd_write_contents */
   1586  1.8  christos     _bfd_bool_bfd_false_error,
   1587  1.8  christos     _bfd_ecoff_write_object_contents,
   1588  1.8  christos     _bfd_write_archive_contents,
   1589  1.8  christos     _bfd_bool_bfd_false_error
   1590  1.8  christos   },
   1591  1.8  christos 
   1592  1.8  christos   BFD_JUMP_TABLE_GENERIC (_bfd_ecoff),
   1593  1.8  christos   BFD_JUMP_TABLE_COPY (_bfd_ecoff),
   1594  1.1  christos   BFD_JUMP_TABLE_CORE (_bfd_nocore),
   1595  1.1  christos   BFD_JUMP_TABLE_ARCHIVE (_bfd_ecoff),
   1596  1.1  christos   BFD_JUMP_TABLE_SYMBOLS (_bfd_ecoff),
   1597  1.8  christos   BFD_JUMP_TABLE_RELOCS (_bfd_ecoff),
   1598  1.1  christos   BFD_JUMP_TABLE_WRITE (_bfd_ecoff),
   1599                  BFD_JUMP_TABLE_LINK (_bfd_ecoff),
   1600                  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
   1601                
   1602                  NULL,
   1603                
   1604                  &mips_ecoff_backend_data
   1605                };
   1606