Home | History | Annotate | Download | only in bfd
      1 /* MIPS-specific support for 64-bit ELF
      2    Copyright (C) 1996-2016 Free Software Foundation, Inc.
      3    Ian Lance Taylor, Cygnus Support
      4    Linker support added by Mark Mitchell, CodeSourcery, LLC.
      5    <mark (at) codesourcery.com>
      6 
      7    This file is part of BFD, the Binary File Descriptor library.
      8 
      9    This program is free software; you can redistribute it and/or modify
     10    it under the terms of the GNU General Public License as published by
     11    the Free Software Foundation; either version 3 of the License, or
     12    (at your option) any later version.
     13 
     14    This program is distributed in the hope that it will be useful,
     15    but WITHOUT ANY WARRANTY; without even the implied warranty of
     16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17    GNU General Public License for more details.
     18 
     19    You should have received a copy of the GNU General Public License
     20    along with this program; if not, write to the Free Software
     21    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     22    MA 02110-1301, USA.  */
     23 
     24 
     25 /* This file supports the 64-bit MIPS ELF ABI.
     26 
     27    The MIPS 64-bit ELF ABI uses an unusual reloc format.  This file
     28    overrides the usual ELF reloc handling, and handles reading and
     29    writing the relocations here.  */
     30 
     31 /* TODO: Many things are unsupported, even if there is some code for it
     32  .       (which was mostly stolen from elf32-mips.c and slightly adapted).
     33  .
     34  .   - Relocation handling for REL relocs is wrong in many cases and
     35  .     generally untested.
     36  .   - Relocation handling for RELA relocs related to GOT support are
     37  .     also likely to be wrong.
     38  .   - Support for MIPS16 is untested.
     39  .   - Combined relocs with RSS_* entries are unsupported.
     40  .   - The whole GOT handling for NewABI is missing, some parts of
     41  .     the OldABI version is still lying around and should be removed.
     42  */
     43 
     44 #include "sysdep.h"
     45 #include "bfd.h"
     46 #include "libbfd.h"
     47 #include "aout/ar.h"
     48 #include "bfdlink.h"
     49 #include "genlink.h"
     50 #include "elf-bfd.h"
     51 #include "elfxx-mips.h"
     52 #include "elf/mips.h"
     53 
     54 /* Get the ECOFF swapping routines.  The 64-bit ABI is not supposed to
     55    use ECOFF.  However, we support it anyhow for an easier changeover.  */
     56 #include "coff/sym.h"
     57 #include "coff/symconst.h"
     58 #include "coff/internal.h"
     59 #include "coff/ecoff.h"
     60 /* The 64 bit versions of the mdebug data structures are in alpha.h.  */
     61 #include "coff/alpha.h"
     62 #define ECOFF_SIGNED_64
     63 #include "ecoffswap.h"
     64 
     65 static void mips_elf64_swap_reloc_in
     66   (bfd *, const Elf64_Mips_External_Rel *, Elf64_Mips_Internal_Rela *);
     67 static void mips_elf64_swap_reloca_in
     68   (bfd *, const Elf64_Mips_External_Rela *, Elf64_Mips_Internal_Rela *);
     69 static void mips_elf64_swap_reloc_out
     70   (bfd *, const Elf64_Mips_Internal_Rela *, Elf64_Mips_External_Rel *);
     71 static void mips_elf64_swap_reloca_out
     72   (bfd *, const Elf64_Mips_Internal_Rela *, Elf64_Mips_External_Rela *);
     73 static void mips_elf64_be_swap_reloc_in
     74   (bfd *, const bfd_byte *, Elf_Internal_Rela *);
     75 static void mips_elf64_be_swap_reloc_out
     76   (bfd *, const Elf_Internal_Rela *, bfd_byte *);
     77 static void mips_elf64_be_swap_reloca_in
     78   (bfd *, const bfd_byte *, Elf_Internal_Rela *);
     79 static void mips_elf64_be_swap_reloca_out
     80   (bfd *, const Elf_Internal_Rela *, bfd_byte *);
     81 static reloc_howto_type *bfd_elf64_bfd_reloc_type_lookup
     82   (bfd *, bfd_reloc_code_real_type);
     83 static reloc_howto_type *mips_elf64_rtype_to_howto
     84   (unsigned int, bfd_boolean);
     85 static void mips_elf64_info_to_howto_rel
     86   (bfd *, arelent *, Elf_Internal_Rela *);
     87 static void mips_elf64_info_to_howto_rela
     88   (bfd *, arelent *, Elf_Internal_Rela *);
     89 static long mips_elf64_get_reloc_upper_bound
     90   (bfd *, asection *);
     91 static long mips_elf64_canonicalize_reloc
     92   (bfd *, asection *, arelent **, asymbol **);
     93 static long mips_elf64_get_dynamic_reloc_upper_bound
     94   (bfd *);
     95 static long mips_elf64_canonicalize_dynamic_reloc
     96   (bfd *, arelent **, asymbol **);
     97 static bfd_boolean mips_elf64_slurp_one_reloc_table
     98   (bfd *, asection *, Elf_Internal_Shdr *, bfd_size_type, arelent *,
     99    asymbol **, bfd_boolean);
    100 static bfd_boolean mips_elf64_slurp_reloc_table
    101   (bfd *, asection *, asymbol **, bfd_boolean);
    102 static void mips_elf64_write_relocs
    103   (bfd *, asection *, void *);
    104 static void mips_elf64_write_rel
    105   (bfd *, asection *, Elf_Internal_Shdr *, int *, void *);
    106 static void mips_elf64_write_rela
    107   (bfd *, asection *, Elf_Internal_Shdr *, int *, void *);
    108 static bfd_reloc_status_type mips_elf64_gprel16_reloc
    109   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
    110 static bfd_reloc_status_type mips_elf64_literal_reloc
    111   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
    112 static bfd_reloc_status_type mips_elf64_gprel32_reloc
    113   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
    114 static bfd_reloc_status_type mips_elf64_shift6_reloc
    115   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
    116 static bfd_reloc_status_type mips16_gprel_reloc
    117   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
    118 static bfd_boolean mips_elf64_assign_gp
    119   (bfd *, bfd_vma *);
    120 static bfd_reloc_status_type mips_elf64_final_gp
    121   (bfd *, asymbol *, bfd_boolean, char **, bfd_vma *);
    122 static bfd_boolean mips_elf64_object_p
    123   (bfd *);
    124 static irix_compat_t elf64_mips_irix_compat
    125   (bfd *);
    126 static bfd_boolean elf64_mips_grok_prstatus
    127   (bfd *, Elf_Internal_Note *);
    128 static bfd_boolean elf64_mips_grok_psinfo
    129   (bfd *, Elf_Internal_Note *);
    130 
    131 extern const bfd_target mips_elf64_be_vec;
    132 extern const bfd_target mips_elf64_le_vec;
    133 
    134 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
    135    from smaller values.  Start with zero, widen, *then* decrement.  */
    136 #define MINUS_ONE	(((bfd_vma)0) - 1)
    137 
    138 /* The number of local .got entries we reserve.  */
    139 #define MIPS_RESERVED_GOTNO (2)
    140 
    141 /* The relocation table used for SHT_REL sections.  */
    143 
    144 static reloc_howto_type mips_elf64_howto_table_rel[] =
    145 {
    146   /* No relocation.  */
    147   HOWTO (R_MIPS_NONE,		/* type */
    148 	 0,			/* rightshift */
    149 	 3,			/* size (0 = byte, 1 = short, 2 = long) */
    150 	 0,			/* bitsize */
    151 	 FALSE,			/* pc_relative */
    152 	 0,			/* bitpos */
    153 	 complain_overflow_dont, /* complain_on_overflow */
    154 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    155 	 "R_MIPS_NONE",		/* name */
    156 	 FALSE,			/* partial_inplace */
    157 	 0,			/* src_mask */
    158 	 0,			/* dst_mask */
    159 	 FALSE),		/* pcrel_offset */
    160 
    161   /* 16 bit relocation.  */
    162   HOWTO (R_MIPS_16,		/* type */
    163 	 0,			/* rightshift */
    164 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    165 	 16,			/* bitsize */
    166 	 FALSE,			/* pc_relative */
    167 	 0,			/* bitpos */
    168 	 complain_overflow_signed, /* complain_on_overflow */
    169 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    170 	 "R_MIPS_16",		/* name */
    171 	 TRUE,			/* partial_inplace */
    172 	 0x0000ffff,		/* src_mask */
    173 	 0x0000ffff,		/* dst_mask */
    174 	 FALSE),		/* pcrel_offset */
    175 
    176   /* 32 bit relocation.  */
    177   HOWTO (R_MIPS_32,		/* type */
    178 	 0,			/* rightshift */
    179 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    180 	 32,			/* bitsize */
    181 	 FALSE,			/* pc_relative */
    182 	 0,			/* bitpos */
    183 	 complain_overflow_dont, /* complain_on_overflow */
    184 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    185 	 "R_MIPS_32",		/* name */
    186 	 TRUE,			/* partial_inplace */
    187 	 0xffffffff,		/* src_mask */
    188 	 0xffffffff,		/* dst_mask */
    189 	 FALSE),		/* pcrel_offset */
    190 
    191   /* 32 bit symbol relative relocation.  */
    192   HOWTO (R_MIPS_REL32,		/* type */
    193 	 0,			/* rightshift */
    194 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    195 	 32,			/* bitsize */
    196 	 FALSE,			/* pc_relative */
    197 	 0,			/* bitpos */
    198 	 complain_overflow_dont, /* complain_on_overflow */
    199 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    200 	 "R_MIPS_REL32",	/* name */
    201 	 TRUE,			/* partial_inplace */
    202 	 0xffffffff,		/* src_mask */
    203 	 0xffffffff,		/* dst_mask */
    204 	 FALSE),		/* pcrel_offset */
    205 
    206   /* 26 bit jump address.  */
    207   HOWTO (R_MIPS_26,		/* type */
    208 	 2,			/* rightshift */
    209 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    210 	 26,			/* bitsize */
    211 	 FALSE,			/* pc_relative */
    212 	 0,			/* bitpos */
    213 	 complain_overflow_dont, /* complain_on_overflow */
    214 				/* This needs complex overflow
    215 				   detection, because the upper 36
    216 				   bits must match the PC + 4.  */
    217 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    218 	 "R_MIPS_26",		/* name */
    219 	 TRUE,			/* partial_inplace */
    220 	 0x03ffffff,		/* src_mask */
    221 	 0x03ffffff,		/* dst_mask */
    222 	 FALSE),		/* pcrel_offset */
    223 
    224   /* R_MIPS_HI16 and R_MIPS_LO16 are unsupported for NewABI REL.
    225      However, the native IRIX6 tools use them, so we try our best. */
    226 
    227   /* High 16 bits of symbol value.  */
    228   HOWTO (R_MIPS_HI16,		/* type */
    229 	 16,			/* rightshift */
    230 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    231 	 16,			/* bitsize */
    232 	 FALSE,			/* pc_relative */
    233 	 0,			/* bitpos */
    234 	 complain_overflow_dont, /* complain_on_overflow */
    235 	 _bfd_mips_elf_hi16_reloc, /* special_function */
    236 	 "R_MIPS_HI16",		/* name */
    237 	 TRUE,			/* partial_inplace */
    238 	 0x0000ffff,		/* src_mask */
    239 	 0x0000ffff,		/* dst_mask */
    240 	 FALSE),		/* pcrel_offset */
    241 
    242   /* Low 16 bits of symbol value.  */
    243   HOWTO (R_MIPS_LO16,		/* type */
    244 	 0,			/* rightshift */
    245 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    246 	 16,			/* bitsize */
    247 	 FALSE,			/* pc_relative */
    248 	 0,			/* bitpos */
    249 	 complain_overflow_dont, /* complain_on_overflow */
    250 	 _bfd_mips_elf_lo16_reloc, /* special_function */
    251 	 "R_MIPS_LO16",		/* name */
    252 	 TRUE,			/* partial_inplace */
    253 	 0x0000ffff,		/* src_mask */
    254 	 0x0000ffff,		/* dst_mask */
    255 	 FALSE),		/* pcrel_offset */
    256 
    257   /* GP relative reference.  */
    258   HOWTO (R_MIPS_GPREL16,	/* type */
    259 	 0,			/* rightshift */
    260 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    261 	 16,			/* bitsize */
    262 	 FALSE,			/* pc_relative */
    263 	 0,			/* bitpos */
    264 	 complain_overflow_signed, /* complain_on_overflow */
    265 	 mips_elf64_gprel16_reloc, /* special_function */
    266 	 "R_MIPS_GPREL16",	/* name */
    267 	 TRUE,			/* partial_inplace */
    268 	 0x0000ffff,		/* src_mask */
    269 	 0x0000ffff,		/* dst_mask */
    270 	 FALSE),		/* pcrel_offset */
    271 
    272   /* Reference to literal section.  */
    273   HOWTO (R_MIPS_LITERAL,	/* type */
    274 	 0,			/* rightshift */
    275 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    276 	 16,			/* bitsize */
    277 	 FALSE,			/* pc_relative */
    278 	 0,			/* bitpos */
    279 	 complain_overflow_signed, /* complain_on_overflow */
    280 	 mips_elf64_literal_reloc, /* special_function */
    281 	 "R_MIPS_LITERAL",	/* name */
    282 	 TRUE,			/* partial_inplace */
    283 	 0x0000ffff,		/* src_mask */
    284 	 0x0000ffff,		/* dst_mask */
    285 	 FALSE),		/* pcrel_offset */
    286 
    287   /* Reference to global offset table.  */
    288   HOWTO (R_MIPS_GOT16,		/* type */
    289 	 0,			/* rightshift */
    290 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    291 	 16,			/* bitsize */
    292 	 FALSE,			/* pc_relative */
    293 	 0,			/* bitpos */
    294 	 complain_overflow_signed, /* complain_on_overflow */
    295 	 _bfd_mips_elf_got16_reloc, /* special_function */
    296 	 "R_MIPS_GOT16",	/* name */
    297 	 TRUE,			/* partial_inplace */
    298 	 0x0000ffff,		/* src_mask */
    299 	 0x0000ffff,		/* dst_mask */
    300 	 FALSE),		/* pcrel_offset */
    301 
    302   /* 16 bit PC relative reference.  Note that the ABI document has a typo
    303      and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
    304      We do the right thing here.  */
    305   HOWTO (R_MIPS_PC16,		/* type */
    306 	 2,			/* rightshift */
    307 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    308 	 16,			/* bitsize */
    309 	 TRUE,			/* pc_relative */
    310 	 0,			/* bitpos */
    311 	 complain_overflow_signed, /* complain_on_overflow */
    312 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    313 	 "R_MIPS_PC16",		/* name */
    314 	 TRUE,			/* partial_inplace */
    315 	 0x0000ffff,		/* src_mask */
    316 	 0x0000ffff,		/* dst_mask */
    317 	 TRUE),			/* pcrel_offset */
    318 
    319   /* 16 bit call through global offset table.  */
    320   HOWTO (R_MIPS_CALL16,		/* type */
    321 	 0,			/* rightshift */
    322 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    323 	 16,			/* bitsize */
    324 	 FALSE,			/* pc_relative */
    325 	 0,			/* bitpos */
    326 	 complain_overflow_signed, /* complain_on_overflow */
    327 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    328 	 "R_MIPS_CALL16",	/* name */
    329 	 TRUE,			/* partial_inplace */
    330 	 0x0000ffff,		/* src_mask */
    331 	 0x0000ffff,		/* dst_mask */
    332 	 FALSE),		/* pcrel_offset */
    333 
    334   /* 32 bit GP relative reference.  */
    335   HOWTO (R_MIPS_GPREL32,	/* type */
    336 	 0,			/* rightshift */
    337 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    338 	 32,			/* bitsize */
    339 	 FALSE,			/* pc_relative */
    340 	 0,			/* bitpos */
    341 	 complain_overflow_dont, /* complain_on_overflow */
    342 	 mips_elf64_gprel32_reloc, /* special_function */
    343 	 "R_MIPS_GPREL32",	/* name */
    344 	 TRUE,			/* partial_inplace */
    345 	 0xffffffff,		/* src_mask */
    346 	 0xffffffff,		/* dst_mask */
    347 	 FALSE),		/* pcrel_offset */
    348 
    349   EMPTY_HOWTO (13),
    350   EMPTY_HOWTO (14),
    351   EMPTY_HOWTO (15),
    352 
    353   /* A 5 bit shift field.  */
    354   HOWTO (R_MIPS_SHIFT5,		/* type */
    355 	 0,			/* rightshift */
    356 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    357 	 5,			/* bitsize */
    358 	 FALSE,			/* pc_relative */
    359 	 6,			/* bitpos */
    360 	 complain_overflow_bitfield, /* complain_on_overflow */
    361 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    362 	 "R_MIPS_SHIFT5",	/* name */
    363 	 TRUE,			/* partial_inplace */
    364 	 0x000007c0,		/* src_mask */
    365 	 0x000007c0,		/* dst_mask */
    366 	 FALSE),		/* pcrel_offset */
    367 
    368   /* A 6 bit shift field.  */
    369   HOWTO (R_MIPS_SHIFT6,		/* type */
    370 	 0,			/* rightshift */
    371 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    372 	 6,			/* bitsize */
    373 	 FALSE,			/* pc_relative */
    374 	 6,			/* bitpos */
    375 	 complain_overflow_bitfield, /* complain_on_overflow */
    376 	 mips_elf64_shift6_reloc, /* special_function */
    377 	 "R_MIPS_SHIFT6",	/* name */
    378 	 TRUE,			/* partial_inplace */
    379 	 0x000007c4,		/* src_mask */
    380 	 0x000007c4,		/* dst_mask */
    381 	 FALSE),		/* pcrel_offset */
    382 
    383   /* 64 bit relocation.  */
    384   HOWTO (R_MIPS_64,		/* type */
    385 	 0,			/* rightshift */
    386 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
    387 	 64,			/* bitsize */
    388 	 FALSE,			/* pc_relative */
    389 	 0,			/* bitpos */
    390 	 complain_overflow_dont, /* complain_on_overflow */
    391 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    392 	 "R_MIPS_64",		/* name */
    393 	 TRUE,			/* partial_inplace */
    394 	 MINUS_ONE,		/* src_mask */
    395 	 MINUS_ONE,		/* dst_mask */
    396 	 FALSE),		/* pcrel_offset */
    397 
    398   /* Displacement in the global offset table.  */
    399   HOWTO (R_MIPS_GOT_DISP,	/* type */
    400 	 0,			/* rightshift */
    401 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    402 	 16,			/* bitsize */
    403 	 FALSE,			/* pc_relative */
    404 	 0,			/* bitpos */
    405 	 complain_overflow_signed, /* complain_on_overflow */
    406 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    407 	 "R_MIPS_GOT_DISP",	/* name */
    408 	 TRUE,			/* partial_inplace */
    409 	 0x0000ffff,		/* src_mask */
    410 	 0x0000ffff,		/* dst_mask */
    411 	 FALSE),		/* pcrel_offset */
    412 
    413   /* Displacement to page pointer in the global offset table.  */
    414   HOWTO (R_MIPS_GOT_PAGE,	/* type */
    415 	 0,			/* rightshift */
    416 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    417 	 16,			/* bitsize */
    418 	 FALSE,			/* pc_relative */
    419 	 0,			/* bitpos */
    420 	 complain_overflow_signed, /* complain_on_overflow */
    421 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    422 	 "R_MIPS_GOT_PAGE",	/* name */
    423 	 TRUE,			/* partial_inplace */
    424 	 0x0000ffff,		/* src_mask */
    425 	 0x0000ffff,		/* dst_mask */
    426 	 FALSE),		/* pcrel_offset */
    427 
    428   /* Offset from page pointer in the global offset table.  */
    429   HOWTO (R_MIPS_GOT_OFST,	/* type */
    430 	 0,			/* rightshift */
    431 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    432 	 16,			/* bitsize */
    433 	 FALSE,			/* pc_relative */
    434 	 0,			/* bitpos */
    435 	 complain_overflow_signed, /* complain_on_overflow */
    436 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    437 	 "R_MIPS_GOT_OFST",	/* name */
    438 	 TRUE,			/* partial_inplace */
    439 	 0x0000ffff,		/* src_mask */
    440 	 0x0000ffff,		/* dst_mask */
    441 	 FALSE),		/* pcrel_offset */
    442 
    443   /* High 16 bits of displacement in global offset table.  */
    444   HOWTO (R_MIPS_GOT_HI16,	/* type */
    445 	 0,			/* rightshift */
    446 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    447 	 16,			/* bitsize */
    448 	 FALSE,			/* pc_relative */
    449 	 0,			/* bitpos */
    450 	 complain_overflow_dont, /* complain_on_overflow */
    451 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    452 	 "R_MIPS_GOT_HI16",	/* name */
    453 	 TRUE,			/* partial_inplace */
    454 	 0x0000ffff,		/* src_mask */
    455 	 0x0000ffff,		/* dst_mask */
    456 	 FALSE),		/* pcrel_offset */
    457 
    458   /* Low 16 bits of displacement in global offset table.  */
    459   HOWTO (R_MIPS_GOT_LO16,	/* type */
    460 	 0,			/* rightshift */
    461 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    462 	 16,			/* bitsize */
    463 	 FALSE,			/* pc_relative */
    464 	 0,			/* bitpos */
    465 	 complain_overflow_dont, /* complain_on_overflow */
    466 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    467 	 "R_MIPS_GOT_LO16",	/* name */
    468 	 TRUE,			/* partial_inplace */
    469 	 0x0000ffff,		/* src_mask */
    470 	 0x0000ffff,		/* dst_mask */
    471 	 FALSE),		/* pcrel_offset */
    472 
    473   /* 64 bit subtraction.  */
    474   HOWTO (R_MIPS_SUB,		/* type */
    475 	 0,			/* rightshift */
    476 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
    477 	 64,			/* bitsize */
    478 	 FALSE,			/* pc_relative */
    479 	 0,			/* bitpos */
    480 	 complain_overflow_dont, /* complain_on_overflow */
    481 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    482 	 "R_MIPS_SUB",		/* name */
    483 	 TRUE,			/* partial_inplace */
    484 	 MINUS_ONE,		/* src_mask */
    485 	 MINUS_ONE,		/* dst_mask */
    486 	 FALSE),		/* pcrel_offset */
    487 
    488   /* Insert the addend as an instruction.  */
    489   /* FIXME: Not handled correctly.  */
    490   HOWTO (R_MIPS_INSERT_A,	/* type */
    491 	 0,			/* rightshift */
    492 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    493 	 32,			/* bitsize */
    494 	 FALSE,			/* pc_relative */
    495 	 0,			/* bitpos */
    496 	 complain_overflow_dont, /* complain_on_overflow */
    497 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    498 	 "R_MIPS_INSERT_A",	/* name */
    499 	 TRUE,			/* partial_inplace */
    500 	 0xffffffff,		/* src_mask */
    501 	 0xffffffff,		/* dst_mask */
    502 	 FALSE),		/* pcrel_offset */
    503 
    504   /* Insert the addend as an instruction, and change all relocations
    505      to refer to the old instruction at the address.  */
    506   /* FIXME: Not handled correctly.  */
    507   HOWTO (R_MIPS_INSERT_B,	/* type */
    508 	 0,			/* rightshift */
    509 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    510 	 32,			/* bitsize */
    511 	 FALSE,			/* pc_relative */
    512 	 0,			/* bitpos */
    513 	 complain_overflow_dont, /* complain_on_overflow */
    514 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    515 	 "R_MIPS_INSERT_B",	/* name */
    516 	 TRUE,			/* partial_inplace */
    517 	 0xffffffff,		/* src_mask */
    518 	 0xffffffff,		/* dst_mask */
    519 	 FALSE),		/* pcrel_offset */
    520 
    521   /* Delete a 32 bit instruction.  */
    522   /* FIXME: Not handled correctly.  */
    523   HOWTO (R_MIPS_DELETE,		/* type */
    524 	 0,			/* rightshift */
    525 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    526 	 32,			/* bitsize */
    527 	 FALSE,			/* pc_relative */
    528 	 0,			/* bitpos */
    529 	 complain_overflow_dont, /* complain_on_overflow */
    530 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    531 	 "R_MIPS_DELETE",	/* name */
    532 	 TRUE,			/* partial_inplace */
    533 	 0xffffffff,		/* src_mask */
    534 	 0xffffffff,		/* dst_mask */
    535 	 FALSE),		/* pcrel_offset */
    536 
    537   /* The MIPS ELF64 ABI Draft wants us to support these for REL relocations.
    538      We don't, because
    539        a) It means building the addend from a R_MIPS_HIGHEST/R_MIPS_HIGHER/
    540 	  R_MIPS_HI16/R_MIPS_LO16 sequence with varying ordering, using
    541 	  fallable heuristics.
    542        b) No other NewABI toolchain actually emits such relocations.  */
    543   EMPTY_HOWTO (R_MIPS_HIGHER),
    544   EMPTY_HOWTO (R_MIPS_HIGHEST),
    545 
    546   /* High 16 bits of displacement in global offset table.  */
    547   HOWTO (R_MIPS_CALL_HI16,	/* type */
    548 	 0,			/* rightshift */
    549 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    550 	 16,			/* bitsize */
    551 	 FALSE,			/* pc_relative */
    552 	 0,			/* bitpos */
    553 	 complain_overflow_dont, /* complain_on_overflow */
    554 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    555 	 "R_MIPS_CALL_HI16",	/* name */
    556 	 TRUE,			/* partial_inplace */
    557 	 0x0000ffff,		/* src_mask */
    558 	 0x0000ffff,		/* dst_mask */
    559 	 FALSE),		/* pcrel_offset */
    560 
    561   /* Low 16 bits of displacement in global offset table.  */
    562   HOWTO (R_MIPS_CALL_LO16,	/* type */
    563 	 0,			/* rightshift */
    564 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    565 	 16,			/* bitsize */
    566 	 FALSE,			/* pc_relative */
    567 	 0,			/* bitpos */
    568 	 complain_overflow_dont, /* complain_on_overflow */
    569 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    570 	 "R_MIPS_CALL_LO16",	/* name */
    571 	 TRUE,			/* partial_inplace */
    572 	 0x0000ffff,		/* src_mask */
    573 	 0x0000ffff,		/* dst_mask */
    574 	 FALSE),		/* pcrel_offset */
    575 
    576   /* Section displacement, used by an associated event location section.  */
    577   HOWTO (R_MIPS_SCN_DISP,	/* type */
    578 	 0,			/* rightshift */
    579 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    580 	 32,			/* bitsize */
    581 	 FALSE,			/* pc_relative */
    582 	 0,			/* bitpos */
    583 	 complain_overflow_dont, /* complain_on_overflow */
    584 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    585 	 "R_MIPS_SCN_DISP",	/* name */
    586 	 TRUE,			/* partial_inplace */
    587 	 0xffffffff,		/* src_mask */
    588 	 0xffffffff,		/* dst_mask */
    589 	 FALSE),		/* pcrel_offset */
    590 
    591   HOWTO (R_MIPS_REL16,		/* type */
    592 	 0,			/* rightshift */
    593 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    594 	 16,			/* bitsize */
    595 	 FALSE,			/* pc_relative */
    596 	 0,			/* bitpos */
    597 	 complain_overflow_signed, /* complain_on_overflow */
    598 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    599 	 "R_MIPS_REL16",	/* name */
    600 	 TRUE,			/* partial_inplace */
    601 	 0xffff,		/* src_mask */
    602 	 0xffff,		/* dst_mask */
    603 	 FALSE),		/* pcrel_offset */
    604 
    605   /* These two are obsolete.  */
    606   EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
    607   EMPTY_HOWTO (R_MIPS_PJUMP),
    608 
    609   /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section.
    610      It must be used for multigot GOT's (and only there).  */
    611   HOWTO (R_MIPS_RELGOT,		/* type */
    612 	 0,			/* rightshift */
    613 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    614 	 32,			/* bitsize */
    615 	 FALSE,			/* pc_relative */
    616 	 0,			/* bitpos */
    617 	 complain_overflow_dont, /* complain_on_overflow */
    618 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    619 	 "R_MIPS_RELGOT",	/* name */
    620 	 TRUE,			/* partial_inplace */
    621 	 0xffffffff,		/* src_mask */
    622 	 0xffffffff,		/* dst_mask */
    623 	 FALSE),		/* pcrel_offset */
    624 
    625   /* Protected jump conversion.  This is an optimization hint.  No
    626      relocation is required for correctness.  */
    627   HOWTO (R_MIPS_JALR,		/* type */
    628 	 0,			/* rightshift */
    629 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    630 	 32,			/* bitsize */
    631 	 FALSE,			/* pc_relative */
    632 	 0,			/* bitpos */
    633 	 complain_overflow_dont, /* complain_on_overflow */
    634 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    635 	 "R_MIPS_JALR",		/* name */
    636 	 FALSE,			/* partial_inplace */
    637 	 0,			/* src_mask */
    638 	 0x00000000,		/* dst_mask */
    639 	 FALSE),		/* pcrel_offset */
    640 
    641   /* TLS relocations.  */
    642   EMPTY_HOWTO (R_MIPS_TLS_DTPMOD32),
    643   EMPTY_HOWTO (R_MIPS_TLS_DTPREL32),
    644 
    645   HOWTO (R_MIPS_TLS_DTPMOD64,	/* type */
    646 	 0,			/* rightshift */
    647 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
    648 	 64,			/* bitsize */
    649 	 FALSE,			/* pc_relative */
    650 	 0,			/* bitpos */
    651 	 complain_overflow_dont, /* complain_on_overflow */
    652 	 _bfd_mips_elf_generic_reloc, /* special_function */
    653 	 "R_MIPS_TLS_DTPMOD64",	/* name */
    654 	 TRUE,			/* partial_inplace */
    655 	 MINUS_ONE,		/* src_mask */
    656 	 MINUS_ONE,		/* dst_mask */
    657 	 FALSE),		/* pcrel_offset */
    658 
    659   HOWTO (R_MIPS_TLS_DTPREL64,	/* type */
    660 	 0,			/* rightshift */
    661 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
    662 	 64,			/* bitsize */
    663 	 FALSE,			/* pc_relative */
    664 	 0,			/* bitpos */
    665 	 complain_overflow_dont, /* complain_on_overflow */
    666 	 _bfd_mips_elf_generic_reloc, /* special_function */
    667 	 "R_MIPS_TLS_DTPREL64",	/* name */
    668 	 TRUE,			/* partial_inplace */
    669 	 MINUS_ONE,		/* src_mask */
    670 	 MINUS_ONE,		/* dst_mask */
    671 	 FALSE),		/* pcrel_offset */
    672 
    673   /* TLS general dynamic variable reference.  */
    674   HOWTO (R_MIPS_TLS_GD,		/* type */
    675 	 0,			/* rightshift */
    676 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    677 	 16,			/* bitsize */
    678 	 FALSE,			/* pc_relative */
    679 	 0,			/* bitpos */
    680 	 complain_overflow_signed, /* complain_on_overflow */
    681 	 _bfd_mips_elf_generic_reloc, /* special_function */
    682 	 "R_MIPS_TLS_GD",	/* name */
    683 	 TRUE,			/* partial_inplace */
    684 	 0x0000ffff,		/* src_mask */
    685 	 0x0000ffff,		/* dst_mask */
    686 	 FALSE),		/* pcrel_offset */
    687 
    688   /* TLS local dynamic variable reference.  */
    689   HOWTO (R_MIPS_TLS_LDM,	/* type */
    690 	 0,			/* rightshift */
    691 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    692 	 16,			/* bitsize */
    693 	 FALSE,			/* pc_relative */
    694 	 0,			/* bitpos */
    695 	 complain_overflow_signed, /* complain_on_overflow */
    696 	 _bfd_mips_elf_generic_reloc, /* special_function */
    697 	 "R_MIPS_TLS_LDM",	/* name */
    698 	 TRUE,			/* partial_inplace */
    699 	 0x0000ffff,		/* src_mask */
    700 	 0x0000ffff,		/* dst_mask */
    701 	 FALSE),		/* pcrel_offset */
    702 
    703   /* TLS local dynamic offset.  */
    704   HOWTO (R_MIPS_TLS_DTPREL_HI16,	/* type */
    705 	 0,			/* rightshift */
    706 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    707 	 16,			/* bitsize */
    708 	 FALSE,			/* pc_relative */
    709 	 0,			/* bitpos */
    710 	 complain_overflow_signed, /* complain_on_overflow */
    711 	 _bfd_mips_elf_generic_reloc, /* special_function */
    712 	 "R_MIPS_TLS_DTPREL_HI16",	/* name */
    713 	 TRUE,			/* partial_inplace */
    714 	 0x0000ffff,		/* src_mask */
    715 	 0x0000ffff,		/* dst_mask */
    716 	 FALSE),		/* pcrel_offset */
    717 
    718   /* TLS local dynamic offset.  */
    719   HOWTO (R_MIPS_TLS_DTPREL_LO16,	/* type */
    720 	 0,			/* rightshift */
    721 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    722 	 16,			/* bitsize */
    723 	 FALSE,			/* pc_relative */
    724 	 0,			/* bitpos */
    725 	 complain_overflow_signed, /* complain_on_overflow */
    726 	 _bfd_mips_elf_generic_reloc, /* special_function */
    727 	 "R_MIPS_TLS_DTPREL_LO16",	/* name */
    728 	 TRUE,			/* partial_inplace */
    729 	 0x0000ffff,		/* src_mask */
    730 	 0x0000ffff,		/* dst_mask */
    731 	 FALSE),		/* pcrel_offset */
    732 
    733   /* TLS thread pointer offset.  */
    734   HOWTO (R_MIPS_TLS_GOTTPREL,	/* type */
    735 	 0,			/* rightshift */
    736 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    737 	 16,			/* bitsize */
    738 	 FALSE,			/* pc_relative */
    739 	 0,			/* bitpos */
    740 	 complain_overflow_signed, /* complain_on_overflow */
    741 	 _bfd_mips_elf_generic_reloc, /* special_function */
    742 	 "R_MIPS_TLS_GOTTPREL",	/* name */
    743 	 TRUE,			/* partial_inplace */
    744 	 0x0000ffff,		/* src_mask */
    745 	 0x0000ffff,		/* dst_mask */
    746 	 FALSE),		/* pcrel_offset */
    747 
    748   /* TLS IE dynamic relocations.  */
    749   EMPTY_HOWTO (R_MIPS_TLS_TPREL32),
    750 
    751   HOWTO (R_MIPS_TLS_TPREL64,	/* type */
    752 	 0,			/* rightshift */
    753 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
    754 	 64,			/* bitsize */
    755 	 FALSE,			/* pc_relative */
    756 	 0,			/* bitpos */
    757 	 complain_overflow_dont, /* complain_on_overflow */
    758 	 _bfd_mips_elf_generic_reloc, /* special_function */
    759 	 "R_MIPS_TLS_TPREL64",	/* name */
    760 	 TRUE,			/* partial_inplace */
    761 	 MINUS_ONE,		/* src_mask */
    762 	 MINUS_ONE,		/* dst_mask */
    763 	 FALSE),		/* pcrel_offset */
    764 
    765   /* TLS thread pointer offset.  */
    766   HOWTO (R_MIPS_TLS_TPREL_HI16,	/* type */
    767 	 0,			/* rightshift */
    768 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    769 	 16,			/* bitsize */
    770 	 FALSE,			/* pc_relative */
    771 	 0,			/* bitpos */
    772 	 complain_overflow_signed, /* complain_on_overflow */
    773 	 _bfd_mips_elf_generic_reloc, /* special_function */
    774 	 "R_MIPS_TLS_TPREL_HI16", /* name */
    775 	 TRUE,			/* partial_inplace */
    776 	 0x0000ffff,		/* src_mask */
    777 	 0x0000ffff,		/* dst_mask */
    778 	 FALSE),		/* pcrel_offset */
    779 
    780   /* TLS thread pointer offset.  */
    781   HOWTO (R_MIPS_TLS_TPREL_LO16,	/* type */
    782 	 0,			/* rightshift */
    783 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    784 	 16,			/* bitsize */
    785 	 FALSE,			/* pc_relative */
    786 	 0,			/* bitpos */
    787 	 complain_overflow_signed, /* complain_on_overflow */
    788 	 _bfd_mips_elf_generic_reloc, /* special_function */
    789 	 "R_MIPS_TLS_TPREL_LO16", /* name */
    790 	 TRUE,			/* partial_inplace */
    791 	 0x0000ffff,		/* src_mask */
    792 	 0x0000ffff,		/* dst_mask */
    793 	 FALSE),		/* pcrel_offset */
    794 
    795   /* 32 bit relocation with no addend.  */
    796   HOWTO (R_MIPS_GLOB_DAT,	/* type */
    797 	 0,			/* rightshift */
    798 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    799 	 32,			/* bitsize */
    800 	 FALSE,			/* pc_relative */
    801 	 0,			/* bitpos */
    802 	 complain_overflow_dont, /* complain_on_overflow */
    803 	 _bfd_mips_elf_generic_reloc, /* special_function */
    804 	 "R_MIPS_GLOB_DAT",	/* name */
    805 	 FALSE,			/* partial_inplace */
    806 	 0x0,			/* src_mask */
    807 	 0xffffffff,		/* dst_mask */
    808 	 FALSE),		/* pcrel_offset */
    809 
    810   EMPTY_HOWTO (52),
    811   EMPTY_HOWTO (53),
    812   EMPTY_HOWTO (54),
    813   EMPTY_HOWTO (55),
    814   EMPTY_HOWTO (56),
    815   EMPTY_HOWTO (57),
    816   EMPTY_HOWTO (58),
    817   EMPTY_HOWTO (59),
    818 
    819   HOWTO (R_MIPS_PC21_S2,	/* type */
    820 	 2,			/* rightshift */
    821 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    822 	 21,			/* bitsize */
    823 	 TRUE,			/* pc_relative */
    824 	 0,			/* bitpos */
    825 	 complain_overflow_signed, /* complain_on_overflow */
    826 	 _bfd_mips_elf_generic_reloc, /* special_function */
    827 	 "R_MIPS_PC21_S2",	/* name */
    828 	 TRUE,			/* partial_inplace */
    829 	 0x001fffff,		/* src_mask */
    830 	 0x001fffff,		/* dst_mask */
    831 	 TRUE),			/* pcrel_offset */
    832 
    833   HOWTO (R_MIPS_PC26_S2,	/* type */
    834 	 2,			/* rightshift */
    835 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    836 	 26,			/* bitsize */
    837 	 TRUE,			/* pc_relative */
    838 	 0,			/* bitpos */
    839 	 complain_overflow_signed, /* complain_on_overflow */
    840 	 _bfd_mips_elf_generic_reloc, /* special_function */
    841 	 "R_MIPS_PC26_S2",	/* name */
    842 	 TRUE,			/* partial_inplace */
    843 	 0x03ffffff,		/* src_mask */
    844 	 0x03ffffff,		/* dst_mask */
    845 	 TRUE),			/* pcrel_offset */
    846 
    847   HOWTO (R_MIPS_PC18_S3,	/* type */
    848 	 3,			/* rightshift */
    849 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    850 	 18,			/* bitsize */
    851 	 TRUE,			/* pc_relative */
    852 	 0,			/* bitpos */
    853 	 complain_overflow_signed, /* complain_on_overflow */
    854 	 _bfd_mips_elf_generic_reloc,   /* special_function */
    855 	 "R_MIPS_PC18_S3",	/* name */
    856 	 TRUE,			/* partial_inplace */
    857 	 0x0003ffff,		/* src_mask */
    858 	 0x0003ffff,		/* dst_mask */
    859 	 TRUE),			/* pcrel_offset */
    860 
    861   HOWTO (R_MIPS_PC19_S2,	/* type */
    862 	 2,			/* rightshift */
    863 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    864 	 19,			/* bitsize */
    865 	 TRUE,			/* pc_relative */
    866 	 0,			/* bitpos */
    867 	 complain_overflow_signed, /* complain_on_overflow */
    868 	 _bfd_mips_elf_generic_reloc,   /* special_function */
    869 	 "R_MIPS_PC19_S2",	/* name */
    870 	 TRUE,			/* partial_inplace */
    871 	 0x0007ffff,		/* src_mask */
    872 	 0x0007ffff,		/* dst_mask */
    873 	 TRUE),			/* pcrel_offset */
    874 
    875   HOWTO (R_MIPS_PCHI16,		/* type */
    876 	 16,			/* rightshift */
    877 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    878 	 16,			/* bitsize */
    879 	 TRUE,			/* pc_relative */
    880 	 0,			/* bitpos */
    881 	 complain_overflow_signed, /* complain_on_overflow */
    882 	 _bfd_mips_elf_generic_reloc,   /* special_function */
    883 	 "R_MIPS_PCHI16",	/* name */
    884 	 TRUE,			/* partial_inplace */
    885 	 0x0000ffff,		/* src_mask */
    886 	 0x0000ffff,		/* dst_mask */
    887 	 TRUE),			/* pcrel_offset */
    888 
    889   HOWTO (R_MIPS_PCLO16,		/* type */
    890 	 0,			/* rightshift */
    891 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    892 	 16,			/* bitsize */
    893 	 TRUE,			/* pc_relative */
    894 	 0,			/* bitpos */
    895 	 complain_overflow_dont, /* complain_on_overflow */
    896 	 _bfd_mips_elf_generic_reloc,   /* special_function */
    897 	 "R_MIPS_PCLO16",	/* name */
    898 	 TRUE,			/* partial_inplace */
    899 	 0x0000ffff,		/* src_mask */
    900 	 0x0000ffff,		/* dst_mask */
    901 	 TRUE),			/* pcrel_offset */
    902 
    903 };
    904 
    905 /* The relocation table used for SHT_RELA sections.  */
    906 
    907 static reloc_howto_type mips_elf64_howto_table_rela[] =
    908 {
    909   /* No relocation.  */
    910   HOWTO (R_MIPS_NONE,		/* type */
    911 	 0,			/* rightshift */
    912 	 3,			/* size (0 = byte, 1 = short, 2 = long) */
    913 	 0,			/* bitsize */
    914 	 FALSE,			/* pc_relative */
    915 	 0,			/* bitpos */
    916 	 complain_overflow_dont, /* complain_on_overflow */
    917 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    918 	 "R_MIPS_NONE",		/* name */
    919 	 FALSE,			/* partial_inplace */
    920 	 0,			/* src_mask */
    921 	 0,			/* dst_mask */
    922 	 FALSE),		/* pcrel_offset */
    923 
    924   /* 16 bit relocation.  */
    925   HOWTO (R_MIPS_16,		/* type */
    926 	 0,			/* rightshift */
    927 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    928 	 16,			/* bitsize */
    929 	 FALSE,			/* pc_relative */
    930 	 0,			/* bitpos */
    931 	 complain_overflow_signed, /* complain_on_overflow */
    932 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    933 	 "R_MIPS_16",		/* name */
    934 	 FALSE,			/* partial_inplace */
    935 	 0,			/* src_mask */
    936 	 0x0000ffff,		/* dst_mask */
    937 	 FALSE),		/* pcrel_offset */
    938 
    939   /* 32 bit relocation.  */
    940   HOWTO (R_MIPS_32,		/* type */
    941 	 0,			/* rightshift */
    942 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    943 	 32,			/* bitsize */
    944 	 FALSE,			/* pc_relative */
    945 	 0,			/* bitpos */
    946 	 complain_overflow_dont, /* complain_on_overflow */
    947 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    948 	 "R_MIPS_32",		/* name */
    949 	 FALSE,			/* partial_inplace */
    950 	 0,			/* src_mask */
    951 	 0xffffffff,		/* dst_mask */
    952 	 FALSE),		/* pcrel_offset */
    953 
    954   /* 32 bit symbol relative relocation.  */
    955   HOWTO (R_MIPS_REL32,		/* type */
    956 	 0,			/* rightshift */
    957 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    958 	 32,			/* bitsize */
    959 	 FALSE,			/* pc_relative */
    960 	 0,			/* bitpos */
    961 	 complain_overflow_dont, /* complain_on_overflow */
    962 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    963 	 "R_MIPS_REL32",	/* name */
    964 	 FALSE,			/* partial_inplace */
    965 	 0,			/* src_mask */
    966 	 0xffffffff,		/* dst_mask */
    967 	 FALSE),		/* pcrel_offset */
    968 
    969   /* 26 bit jump address.  */
    970   HOWTO (R_MIPS_26,		/* type */
    971 	 2,			/* rightshift */
    972 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    973 	 26,			/* bitsize */
    974 	 FALSE,			/* pc_relative */
    975 	 0,			/* bitpos */
    976 	 complain_overflow_dont, /* complain_on_overflow */
    977 				/* This needs complex overflow
    978 				   detection, because the upper 36
    979 				   bits must match the PC + 4.  */
    980 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    981 	 "R_MIPS_26",		/* name */
    982 	 FALSE,			/* partial_inplace */
    983 	 0,			/* src_mask */
    984 	 0x03ffffff,		/* dst_mask */
    985 	 FALSE),		/* pcrel_offset */
    986 
    987   /* High 16 bits of symbol value.  */
    988   HOWTO (R_MIPS_HI16,		/* type */
    989 	 0,			/* rightshift */
    990 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    991 	 16,			/* bitsize */
    992 	 FALSE,			/* pc_relative */
    993 	 0,			/* bitpos */
    994 	 complain_overflow_dont, /* complain_on_overflow */
    995 	 _bfd_mips_elf_generic_reloc,	/* special_function */
    996 	 "R_MIPS_HI16",		/* name */
    997 	 FALSE,			/* partial_inplace */
    998 	 0,			/* src_mask */
    999 	 0x0000ffff,		/* dst_mask */
   1000 	 FALSE),		/* pcrel_offset */
   1001 
   1002   /* Low 16 bits of symbol value.  */
   1003   HOWTO (R_MIPS_LO16,		/* type */
   1004 	 0,			/* rightshift */
   1005 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1006 	 16,			/* bitsize */
   1007 	 FALSE,			/* pc_relative */
   1008 	 0,			/* bitpos */
   1009 	 complain_overflow_dont, /* complain_on_overflow */
   1010 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1011 	 "R_MIPS_LO16",		/* name */
   1012 	 FALSE,			/* partial_inplace */
   1013 	 0,			/* src_mask */
   1014 	 0x0000ffff,		/* dst_mask */
   1015 	 FALSE),		/* pcrel_offset */
   1016 
   1017   /* GP relative reference.  */
   1018   HOWTO (R_MIPS_GPREL16,	/* type */
   1019 	 0,			/* rightshift */
   1020 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1021 	 16,			/* bitsize */
   1022 	 FALSE,			/* pc_relative */
   1023 	 0,			/* bitpos */
   1024 	 complain_overflow_signed, /* complain_on_overflow */
   1025 	 mips_elf64_gprel16_reloc, /* special_function */
   1026 	 "R_MIPS_GPREL16",	/* name */
   1027 	 FALSE,			/* partial_inplace */
   1028 	 0,			/* src_mask */
   1029 	 0x0000ffff,		/* dst_mask */
   1030 	 FALSE),		/* pcrel_offset */
   1031 
   1032   /* Reference to literal section.  */
   1033   HOWTO (R_MIPS_LITERAL,	/* type */
   1034 	 0,			/* rightshift */
   1035 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1036 	 16,			/* bitsize */
   1037 	 FALSE,			/* pc_relative */
   1038 	 0,			/* bitpos */
   1039 	 complain_overflow_signed, /* complain_on_overflow */
   1040 	 mips_elf64_literal_reloc, /* special_function */
   1041 	 "R_MIPS_LITERAL",	/* name */
   1042 	 FALSE,			/* partial_inplace */
   1043 	 0,			/* src_mask */
   1044 	 0x0000ffff,		/* dst_mask */
   1045 	 FALSE),		/* pcrel_offset */
   1046 
   1047   /* Reference to global offset table.  */
   1048   HOWTO (R_MIPS_GOT16,		/* type */
   1049 	 0,			/* rightshift */
   1050 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1051 	 16,			/* bitsize */
   1052 	 FALSE,			/* pc_relative */
   1053 	 0,			/* bitpos */
   1054 	 complain_overflow_signed, /* complain_on_overflow */
   1055 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1056 	 "R_MIPS_GOT16",	/* name */
   1057 	 FALSE,			/* partial_inplace */
   1058 	 0,			/* src_mask */
   1059 	 0x0000ffff,		/* dst_mask */
   1060 	 FALSE),		/* pcrel_offset */
   1061 
   1062   /* 16 bit PC relative reference.  Note that the ABI document has a typo
   1063      and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
   1064      We do the right thing here.  */
   1065   HOWTO (R_MIPS_PC16,		/* type */
   1066 	 2,			/* rightshift */
   1067 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1068 	 16,			/* bitsize */
   1069 	 TRUE,			/* pc_relative */
   1070 	 0,			/* bitpos */
   1071 	 complain_overflow_signed, /* complain_on_overflow */
   1072 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1073 	 "R_MIPS_PC16",		/* name */
   1074 	 FALSE,			/* partial_inplace */
   1075 	 0,			/* src_mask */
   1076 	 0x0000ffff,		/* dst_mask */
   1077 	 TRUE),			/* pcrel_offset */
   1078 
   1079   /* 16 bit call through global offset table.  */
   1080   HOWTO (R_MIPS_CALL16,		/* type */
   1081 	 0,			/* rightshift */
   1082 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1083 	 16,			/* bitsize */
   1084 	 FALSE,			/* pc_relative */
   1085 	 0,			/* bitpos */
   1086 	 complain_overflow_signed, /* complain_on_overflow */
   1087 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1088 	 "R_MIPS_CALL16",	/* name */
   1089 	 FALSE,			/* partial_inplace */
   1090 	 0,			/* src_mask */
   1091 	 0x0000ffff,		/* dst_mask */
   1092 	 FALSE),		/* pcrel_offset */
   1093 
   1094   /* 32 bit GP relative reference.  */
   1095   HOWTO (R_MIPS_GPREL32,	/* type */
   1096 	 0,			/* rightshift */
   1097 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1098 	 32,			/* bitsize */
   1099 	 FALSE,			/* pc_relative */
   1100 	 0,			/* bitpos */
   1101 	 complain_overflow_dont, /* complain_on_overflow */
   1102 	 mips_elf64_gprel32_reloc, /* special_function */
   1103 	 "R_MIPS_GPREL32",	/* name */
   1104 	 FALSE,			/* partial_inplace */
   1105 	 0,			/* src_mask */
   1106 	 0xffffffff,		/* dst_mask */
   1107 	 FALSE),		/* pcrel_offset */
   1108 
   1109   EMPTY_HOWTO (13),
   1110   EMPTY_HOWTO (14),
   1111   EMPTY_HOWTO (15),
   1112 
   1113   /* A 5 bit shift field.  */
   1114   HOWTO (R_MIPS_SHIFT5,		/* type */
   1115 	 0,			/* rightshift */
   1116 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1117 	 5,			/* bitsize */
   1118 	 FALSE,			/* pc_relative */
   1119 	 6,			/* bitpos */
   1120 	 complain_overflow_bitfield, /* complain_on_overflow */
   1121 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1122 	 "R_MIPS_SHIFT5",	/* name */
   1123 	 FALSE,			/* partial_inplace */
   1124 	 0,			/* src_mask */
   1125 	 0x000007c0,		/* dst_mask */
   1126 	 FALSE),		/* pcrel_offset */
   1127 
   1128   /* A 6 bit shift field.  */
   1129   HOWTO (R_MIPS_SHIFT6,		/* type */
   1130 	 0,			/* rightshift */
   1131 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1132 	 6,			/* bitsize */
   1133 	 FALSE,			/* pc_relative */
   1134 	 6,			/* bitpos */
   1135 	 complain_overflow_bitfield, /* complain_on_overflow */
   1136 	 mips_elf64_shift6_reloc, /* special_function */
   1137 	 "R_MIPS_SHIFT6",	/* name */
   1138 	 FALSE,			/* partial_inplace */
   1139 	 0,			/* src_mask */
   1140 	 0x000007c4,		/* dst_mask */
   1141 	 FALSE),		/* pcrel_offset */
   1142 
   1143   /* 64 bit relocation.  */
   1144   HOWTO (R_MIPS_64,		/* type */
   1145 	 0,			/* rightshift */
   1146 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
   1147 	 64,			/* bitsize */
   1148 	 FALSE,			/* pc_relative */
   1149 	 0,			/* bitpos */
   1150 	 complain_overflow_dont, /* complain_on_overflow */
   1151 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1152 	 "R_MIPS_64",		/* name */
   1153 	 FALSE,			/* partial_inplace */
   1154 	 0,			/* src_mask */
   1155 	 MINUS_ONE,		/* dst_mask */
   1156 	 FALSE),		/* pcrel_offset */
   1157 
   1158   /* Displacement in the global offset table.  */
   1159   HOWTO (R_MIPS_GOT_DISP,	/* type */
   1160 	 0,			/* rightshift */
   1161 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1162 	 16,			/* bitsize */
   1163 	 FALSE,			/* pc_relative */
   1164 	 0,			/* bitpos */
   1165 	 complain_overflow_signed, /* complain_on_overflow */
   1166 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1167 	 "R_MIPS_GOT_DISP",	/* name */
   1168 	 FALSE,			/* partial_inplace */
   1169 	 0,			/* src_mask */
   1170 	 0x0000ffff,		/* dst_mask */
   1171 	 FALSE),		/* pcrel_offset */
   1172 
   1173   /* Displacement to page pointer in the global offset table.  */
   1174   HOWTO (R_MIPS_GOT_PAGE,	/* type */
   1175 	 0,			/* rightshift */
   1176 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1177 	 16,			/* bitsize */
   1178 	 FALSE,			/* pc_relative */
   1179 	 0,			/* bitpos */
   1180 	 complain_overflow_signed, /* complain_on_overflow */
   1181 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1182 	 "R_MIPS_GOT_PAGE",	/* name */
   1183 	 FALSE,			/* partial_inplace */
   1184 	 0,			/* src_mask */
   1185 	 0x0000ffff,		/* dst_mask */
   1186 	 FALSE),		/* pcrel_offset */
   1187 
   1188   /* Offset from page pointer in the global offset table.  */
   1189   HOWTO (R_MIPS_GOT_OFST,	/* type */
   1190 	 0,			/* rightshift */
   1191 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1192 	 16,			/* bitsize */
   1193 	 FALSE,			/* pc_relative */
   1194 	 0,			/* bitpos */
   1195 	 complain_overflow_signed, /* complain_on_overflow */
   1196 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1197 	 "R_MIPS_GOT_OFST",	/* name */
   1198 	 FALSE,			/* partial_inplace */
   1199 	 0,			/* src_mask */
   1200 	 0x0000ffff,		/* dst_mask */
   1201 	 FALSE),		/* pcrel_offset */
   1202 
   1203   /* High 16 bits of displacement in global offset table.  */
   1204   HOWTO (R_MIPS_GOT_HI16,	/* type */
   1205 	 0,			/* rightshift */
   1206 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1207 	 16,			/* bitsize */
   1208 	 FALSE,			/* pc_relative */
   1209 	 0,			/* bitpos */
   1210 	 complain_overflow_dont, /* complain_on_overflow */
   1211 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1212 	 "R_MIPS_GOT_HI16",	/* name */
   1213 	 FALSE,			/* partial_inplace */
   1214 	 0,			/* src_mask */
   1215 	 0x0000ffff,		/* dst_mask */
   1216 	 FALSE),		/* pcrel_offset */
   1217 
   1218   /* Low 16 bits of displacement in global offset table.  */
   1219   HOWTO (R_MIPS_GOT_LO16,	/* type */
   1220 	 0,			/* rightshift */
   1221 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1222 	 16,			/* bitsize */
   1223 	 FALSE,			/* pc_relative */
   1224 	 0,			/* bitpos */
   1225 	 complain_overflow_dont, /* complain_on_overflow */
   1226 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1227 	 "R_MIPS_GOT_LO16",	/* name */
   1228 	 FALSE,			/* partial_inplace */
   1229 	 0,			/* src_mask */
   1230 	 0x0000ffff,		/* dst_mask */
   1231 	 FALSE),		/* pcrel_offset */
   1232 
   1233   /* 64 bit subtraction.  */
   1234   HOWTO (R_MIPS_SUB,		/* type */
   1235 	 0,			/* rightshift */
   1236 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
   1237 	 64,			/* bitsize */
   1238 	 FALSE,			/* pc_relative */
   1239 	 0,			/* bitpos */
   1240 	 complain_overflow_dont, /* complain_on_overflow */
   1241 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1242 	 "R_MIPS_SUB",		/* name */
   1243 	 FALSE,			/* partial_inplace */
   1244 	 0,			/* src_mask */
   1245 	 MINUS_ONE,		/* dst_mask */
   1246 	 FALSE),		/* pcrel_offset */
   1247 
   1248   /* Insert the addend as an instruction.  */
   1249   /* FIXME: Not handled correctly.  */
   1250   HOWTO (R_MIPS_INSERT_A,	/* type */
   1251 	 0,			/* rightshift */
   1252 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1253 	 32,			/* bitsize */
   1254 	 FALSE,			/* pc_relative */
   1255 	 0,			/* bitpos */
   1256 	 complain_overflow_dont, /* complain_on_overflow */
   1257 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1258 	 "R_MIPS_INSERT_A",	/* name */
   1259 	 FALSE,			/* partial_inplace */
   1260 	 0,			/* src_mask */
   1261 	 0xffffffff,		/* dst_mask */
   1262 	 FALSE),		/* pcrel_offset */
   1263 
   1264   /* Insert the addend as an instruction, and change all relocations
   1265      to refer to the old instruction at the address.  */
   1266   /* FIXME: Not handled correctly.  */
   1267   HOWTO (R_MIPS_INSERT_B,	/* type */
   1268 	 0,			/* rightshift */
   1269 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1270 	 32,			/* bitsize */
   1271 	 FALSE,			/* pc_relative */
   1272 	 0,			/* bitpos */
   1273 	 complain_overflow_dont, /* complain_on_overflow */
   1274 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1275 	 "R_MIPS_INSERT_B",	/* name */
   1276 	 FALSE,			/* partial_inplace */
   1277 	 0,			/* src_mask */
   1278 	 0xffffffff,		/* dst_mask */
   1279 	 FALSE),		/* pcrel_offset */
   1280 
   1281   /* Delete a 32 bit instruction.  */
   1282   /* FIXME: Not handled correctly.  */
   1283   HOWTO (R_MIPS_DELETE,		/* type */
   1284 	 0,			/* rightshift */
   1285 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1286 	 32,			/* bitsize */
   1287 	 FALSE,			/* pc_relative */
   1288 	 0,			/* bitpos */
   1289 	 complain_overflow_dont, /* complain_on_overflow */
   1290 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1291 	 "R_MIPS_DELETE",	/* name */
   1292 	 FALSE,			/* partial_inplace */
   1293 	 0,			/* src_mask */
   1294 	 0xffffffff,		/* dst_mask */
   1295 	 FALSE),		/* pcrel_offset */
   1296 
   1297   /* Get the higher value of a 64 bit addend.  */
   1298   HOWTO (R_MIPS_HIGHER,		/* type */
   1299 	 0,			/* rightshift */
   1300 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1301 	 16,			/* bitsize */
   1302 	 FALSE,			/* pc_relative */
   1303 	 0,			/* bitpos */
   1304 	 complain_overflow_dont, /* complain_on_overflow */
   1305 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1306 	 "R_MIPS_HIGHER",	/* name */
   1307 	 FALSE,			/* partial_inplace */
   1308 	 0,			/* src_mask */
   1309 	 0x0000ffff,		/* dst_mask */
   1310 	 FALSE),		/* pcrel_offset */
   1311 
   1312   /* Get the highest value of a 64 bit addend.  */
   1313   HOWTO (R_MIPS_HIGHEST,	/* type */
   1314 	 0,			/* rightshift */
   1315 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1316 	 16,			/* bitsize */
   1317 	 FALSE,			/* pc_relative */
   1318 	 0,			/* bitpos */
   1319 	 complain_overflow_dont, /* complain_on_overflow */
   1320 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1321 	 "R_MIPS_HIGHEST",	/* name */
   1322 	 FALSE,			/* partial_inplace */
   1323 	 0,			/* src_mask */
   1324 	 0x0000ffff,		/* dst_mask */
   1325 	 FALSE),		/* pcrel_offset */
   1326 
   1327   /* High 16 bits of displacement in global offset table.  */
   1328   HOWTO (R_MIPS_CALL_HI16,	/* type */
   1329 	 0,			/* rightshift */
   1330 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1331 	 16,			/* bitsize */
   1332 	 FALSE,			/* pc_relative */
   1333 	 0,			/* bitpos */
   1334 	 complain_overflow_dont, /* complain_on_overflow */
   1335 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1336 	 "R_MIPS_CALL_HI16",	/* name */
   1337 	 FALSE,			/* partial_inplace */
   1338 	 0,			/* src_mask */
   1339 	 0x0000ffff,		/* dst_mask */
   1340 	 FALSE),		/* pcrel_offset */
   1341 
   1342   /* Low 16 bits of displacement in global offset table.  */
   1343   HOWTO (R_MIPS_CALL_LO16,	/* type */
   1344 	 0,			/* rightshift */
   1345 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1346 	 16,			/* bitsize */
   1347 	 FALSE,			/* pc_relative */
   1348 	 0,			/* bitpos */
   1349 	 complain_overflow_dont, /* complain_on_overflow */
   1350 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1351 	 "R_MIPS_CALL_LO16",	/* name */
   1352 	 FALSE,			/* partial_inplace */
   1353 	 0,			/* src_mask */
   1354 	 0x0000ffff,		/* dst_mask */
   1355 	 FALSE),		/* pcrel_offset */
   1356 
   1357   /* Section displacement, used by an associated event location section.  */
   1358   HOWTO (R_MIPS_SCN_DISP,	/* type */
   1359 	 0,			/* rightshift */
   1360 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1361 	 32,			/* bitsize */
   1362 	 FALSE,			/* pc_relative */
   1363 	 0,			/* bitpos */
   1364 	 complain_overflow_dont, /* complain_on_overflow */
   1365 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1366 	 "R_MIPS_SCN_DISP",	/* name */
   1367 	 FALSE,			/* partial_inplace */
   1368 	 0,			/* src_mask */
   1369 	 0xffffffff,		/* dst_mask */
   1370 	 FALSE),		/* pcrel_offset */
   1371 
   1372   HOWTO (R_MIPS_REL16,		/* type */
   1373 	 0,			/* rightshift */
   1374 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1375 	 16,			/* bitsize */
   1376 	 FALSE,			/* pc_relative */
   1377 	 0,			/* bitpos */
   1378 	 complain_overflow_signed, /* complain_on_overflow */
   1379 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1380 	 "R_MIPS_REL16",	/* name */
   1381 	 FALSE,			/* partial_inplace */
   1382 	 0,			/* src_mask */
   1383 	 0xffff,		/* dst_mask */
   1384 	 FALSE),		/* pcrel_offset */
   1385 
   1386   /* These two are obsolete.  */
   1387   EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
   1388   EMPTY_HOWTO (R_MIPS_PJUMP),
   1389 
   1390   /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section.
   1391      It must be used for multigot GOT's (and only there).  */
   1392   HOWTO (R_MIPS_RELGOT,		/* type */
   1393 	 0,			/* rightshift */
   1394 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1395 	 32,			/* bitsize */
   1396 	 FALSE,			/* pc_relative */
   1397 	 0,			/* bitpos */
   1398 	 complain_overflow_dont, /* complain_on_overflow */
   1399 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1400 	 "R_MIPS_RELGOT",	/* name */
   1401 	 FALSE,			/* partial_inplace */
   1402 	 0,			/* src_mask */
   1403 	 0xffffffff,		/* dst_mask */
   1404 	 FALSE),		/* pcrel_offset */
   1405 
   1406   /* Protected jump conversion.  This is an optimization hint.  No
   1407      relocation is required for correctness.  */
   1408   HOWTO (R_MIPS_JALR,		/* type */
   1409 	 0,			/* rightshift */
   1410 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1411 	 32,			/* bitsize */
   1412 	 FALSE,			/* pc_relative */
   1413 	 0,			/* bitpos */
   1414 	 complain_overflow_dont, /* complain_on_overflow */
   1415 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   1416 	 "R_MIPS_JALR",		/* name */
   1417 	 FALSE,			/* partial_inplace */
   1418 	 0,			/* src_mask */
   1419 	 0x00000000,		/* dst_mask */
   1420 	 FALSE),		/* pcrel_offset */
   1421 
   1422   /* TLS relocations.  */
   1423   EMPTY_HOWTO (R_MIPS_TLS_DTPMOD32),
   1424   EMPTY_HOWTO (R_MIPS_TLS_DTPREL32),
   1425 
   1426   HOWTO (R_MIPS_TLS_DTPMOD64,	/* type */
   1427 	 0,			/* rightshift */
   1428 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
   1429 	 64,			/* bitsize */
   1430 	 FALSE,			/* pc_relative */
   1431 	 0,			/* bitpos */
   1432 	 complain_overflow_dont, /* complain_on_overflow */
   1433 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1434 	 "R_MIPS_TLS_DTPMOD64", /* name */
   1435 	 FALSE,			/* partial_inplace */
   1436 	 0,			/* src_mask */
   1437 	 MINUS_ONE,		/* dst_mask */
   1438 	 FALSE),		/* pcrel_offset */
   1439 
   1440   HOWTO (R_MIPS_TLS_DTPREL64,	/* type */
   1441 	 0,			/* rightshift */
   1442 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
   1443 	 64,			/* bitsize */
   1444 	 FALSE,			/* pc_relative */
   1445 	 0,			/* bitpos */
   1446 	 complain_overflow_dont, /* complain_on_overflow */
   1447 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1448 	 "R_MIPS_TLS_DTPREL64",	/* name */
   1449 	 FALSE,			/* partial_inplace */
   1450 	 0,			/* src_mask */
   1451 	 MINUS_ONE,		/* dst_mask */
   1452 	 FALSE),		/* pcrel_offset */
   1453 
   1454   /* TLS general dynamic variable reference.  */
   1455   HOWTO (R_MIPS_TLS_GD,		/* type */
   1456 	 0,			/* rightshift */
   1457 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1458 	 16,			/* bitsize */
   1459 	 FALSE,			/* pc_relative */
   1460 	 0,			/* bitpos */
   1461 	 complain_overflow_signed, /* complain_on_overflow */
   1462 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1463 	 "R_MIPS_TLS_GD",	/* name */
   1464 	 FALSE,			/* partial_inplace */
   1465 	 0,			/* src_mask */
   1466 	 0x0000ffff,		/* dst_mask */
   1467 	 FALSE),		/* pcrel_offset */
   1468 
   1469   /* TLS local dynamic variable reference.  */
   1470   HOWTO (R_MIPS_TLS_LDM,	/* type */
   1471 	 0,			/* rightshift */
   1472 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1473 	 16,			/* bitsize */
   1474 	 FALSE,			/* pc_relative */
   1475 	 0,			/* bitpos */
   1476 	 complain_overflow_signed, /* complain_on_overflow */
   1477 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1478 	 "R_MIPS_TLS_LDM",	/* name */
   1479 	 FALSE,			/* partial_inplace */
   1480 	 0,			/* src_mask */
   1481 	 0x0000ffff,		/* dst_mask */
   1482 	 FALSE),		/* pcrel_offset */
   1483 
   1484   /* TLS local dynamic offset.  */
   1485   HOWTO (R_MIPS_TLS_DTPREL_HI16,	/* type */
   1486 	 0,			/* rightshift */
   1487 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1488 	 16,			/* bitsize */
   1489 	 FALSE,			/* pc_relative */
   1490 	 0,			/* bitpos */
   1491 	 complain_overflow_signed, /* complain_on_overflow */
   1492 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1493 	 "R_MIPS_TLS_DTPREL_HI16",	/* name */
   1494 	 FALSE,			/* partial_inplace */
   1495 	 0,			/* src_mask */
   1496 	 0x0000ffff,		/* dst_mask */
   1497 	 FALSE),		/* pcrel_offset */
   1498 
   1499   /* TLS local dynamic offset.  */
   1500   HOWTO (R_MIPS_TLS_DTPREL_LO16,	/* type */
   1501 	 0,			/* rightshift */
   1502 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1503 	 16,			/* bitsize */
   1504 	 FALSE,			/* pc_relative */
   1505 	 0,			/* bitpos */
   1506 	 complain_overflow_signed, /* complain_on_overflow */
   1507 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1508 	 "R_MIPS_TLS_DTPREL_LO16",	/* name */
   1509 	 FALSE,			/* partial_inplace */
   1510 	 0,			/* src_mask */
   1511 	 0x0000ffff,		/* dst_mask */
   1512 	 FALSE),		/* pcrel_offset */
   1513 
   1514   /* TLS thread pointer offset.  */
   1515   HOWTO (R_MIPS_TLS_GOTTPREL,	/* type */
   1516 	 0,			/* rightshift */
   1517 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1518 	 16,			/* bitsize */
   1519 	 FALSE,			/* pc_relative */
   1520 	 0,			/* bitpos */
   1521 	 complain_overflow_signed, /* complain_on_overflow */
   1522 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1523 	 "R_MIPS_TLS_GOTTPREL",	/* name */
   1524 	 FALSE,			/* partial_inplace */
   1525 	 0,			/* src_mask */
   1526 	 0x0000ffff,		/* dst_mask */
   1527 	 FALSE),		/* pcrel_offset */
   1528 
   1529   /* TLS IE dynamic relocations.  */
   1530   EMPTY_HOWTO (R_MIPS_TLS_TPREL32),
   1531 
   1532   HOWTO (R_MIPS_TLS_TPREL64,	/* type */
   1533 	 0,			/* rightshift */
   1534 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
   1535 	 64,			/* bitsize */
   1536 	 FALSE,			/* pc_relative */
   1537 	 0,			/* bitpos */
   1538 	 complain_overflow_dont, /* complain_on_overflow */
   1539 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1540 	 "R_MIPS_TLS_TPREL64",	/* name */
   1541 	 FALSE,			/* partial_inplace */
   1542 	 0,			/* src_mask */
   1543 	 MINUS_ONE,		/* dst_mask */
   1544 	 FALSE),		/* pcrel_offset */
   1545 
   1546   /* TLS thread pointer offset.  */
   1547   HOWTO (R_MIPS_TLS_TPREL_HI16,	/* type */
   1548 	 0,			/* rightshift */
   1549 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1550 	 16,			/* bitsize */
   1551 	 FALSE,			/* pc_relative */
   1552 	 0,			/* bitpos */
   1553 	 complain_overflow_signed, /* complain_on_overflow */
   1554 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1555 	 "R_MIPS_TLS_TPREL_HI16", /* name */
   1556 	 FALSE,			/* partial_inplace */
   1557 	 0,			/* src_mask */
   1558 	 0x0000ffff,		/* dst_mask */
   1559 	 FALSE),		/* pcrel_offset */
   1560 
   1561   /* TLS thread pointer offset.  */
   1562   HOWTO (R_MIPS_TLS_TPREL_LO16,	/* type */
   1563 	 0,			/* rightshift */
   1564 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1565 	 16,			/* bitsize */
   1566 	 FALSE,			/* pc_relative */
   1567 	 0,			/* bitpos */
   1568 	 complain_overflow_signed, /* complain_on_overflow */
   1569 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1570 	 "R_MIPS_TLS_TPREL_LO16", /* name */
   1571 	 FALSE,			/* partial_inplace */
   1572 	 0,			/* src_mask */
   1573 	 0x0000ffff,		/* dst_mask */
   1574 	 FALSE),		/* pcrel_offset */
   1575 
   1576   /* 32 bit relocation with no addend.  */
   1577   HOWTO (R_MIPS_GLOB_DAT,	/* type */
   1578 	 0,			/* rightshift */
   1579 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1580 	 32,			/* bitsize */
   1581 	 FALSE,			/* pc_relative */
   1582 	 0,			/* bitpos */
   1583 	 complain_overflow_dont, /* complain_on_overflow */
   1584 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1585 	 "R_MIPS_GLOB_DAT",	/* name */
   1586 	 FALSE,			/* partial_inplace */
   1587 	 0x0,			/* src_mask */
   1588 	 0xffffffff,		/* dst_mask */
   1589 	 FALSE),		/* pcrel_offset */
   1590 
   1591   EMPTY_HOWTO (52),
   1592   EMPTY_HOWTO (53),
   1593   EMPTY_HOWTO (54),
   1594   EMPTY_HOWTO (55),
   1595   EMPTY_HOWTO (56),
   1596   EMPTY_HOWTO (57),
   1597   EMPTY_HOWTO (58),
   1598   EMPTY_HOWTO (59),
   1599 
   1600   HOWTO (R_MIPS_PC21_S2,	/* type */
   1601 	 2,			/* rightshift */
   1602 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1603 	 21,			/* bitsize */
   1604 	 TRUE,			/* pc_relative */
   1605 	 0,			/* bitpos */
   1606 	 complain_overflow_signed, /* complain_on_overflow */
   1607 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1608 	 "R_MIPS_PC21_S2",	/* name */
   1609 	 FALSE,			/* partial_inplace */
   1610 	 0,			/* src_mask */
   1611 	 0x001fffff,		/* dst_mask */
   1612 	 TRUE),			/* pcrel_offset */
   1613 
   1614   HOWTO (R_MIPS_PC26_S2,	/* type */
   1615 	 2,			/* rightshift */
   1616 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1617 	 26,			/* bitsize */
   1618 	 TRUE,			/* pc_relative */
   1619 	 0,			/* bitpos */
   1620 	 complain_overflow_signed, /* complain_on_overflow */
   1621 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1622 	 "R_MIPS_PC26_S2",	/* name */
   1623 	 FALSE,			/* partial_inplace */
   1624 	 0,			/* src_mask */
   1625 	 0x03ffffff,		/* dst_mask */
   1626 	 TRUE),			/* pcrel_offset */
   1627 
   1628   HOWTO (R_MIPS_PC18_S3,	/* type */
   1629 	 3,			/* rightshift */
   1630 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1631 	 18,			/* bitsize */
   1632 	 TRUE,			/* pc_relative */
   1633 	 0,			/* bitpos */
   1634 	 complain_overflow_signed, /* complain_on_overflow */
   1635 	 _bfd_mips_elf_generic_reloc,   /* special_function */
   1636 	 "R_MIPS_PC18_S3",	/* name */
   1637 	 FALSE,			/* partial_inplace */
   1638 	 0,			/* src_mask */
   1639 	 0x0003ffff,		/* dst_mask */
   1640 	 TRUE),			/* pcrel_offset */
   1641 
   1642   HOWTO (R_MIPS_PC19_S2,	/* type */
   1643 	 2,			/* rightshift */
   1644 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1645 	 19,			/* bitsize */
   1646 	 TRUE,			/* pc_relative */
   1647 	 0,			/* bitpos */
   1648 	 complain_overflow_signed, /* complain_on_overflow */
   1649 	 _bfd_mips_elf_generic_reloc,   /* special_function */
   1650 	 "R_MIPS_PC19_S2",	/* name */
   1651 	 FALSE,			/* partial_inplace */
   1652 	 0,			/* src_mask */
   1653 	 0x0007ffff,		/* dst_mask */
   1654 	 TRUE),			/* pcrel_offset */
   1655 
   1656   HOWTO (R_MIPS_PCHI16,		/* type */
   1657 	 16,			/* rightshift */
   1658 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1659 	 16,			/* bitsize */
   1660 	 TRUE,			/* pc_relative */
   1661 	 0,			/* bitpos */
   1662 	 complain_overflow_signed, /* complain_on_overflow */
   1663 	 _bfd_mips_elf_generic_reloc,   /* special_function */
   1664 	 "R_MIPS_PCHI16",	/* name */
   1665 	 FALSE,			/* partial_inplace */
   1666 	 0,			/* src_mask */
   1667 	 0x0000ffff,		/* dst_mask */
   1668 	 TRUE),			/* pcrel_offset */
   1669 
   1670   HOWTO (R_MIPS_PCLO16,		/* type */
   1671 	 0,			/* rightshift */
   1672 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1673 	 16,			/* bitsize */
   1674 	 TRUE,			/* pc_relative */
   1675 	 0,			/* bitpos */
   1676 	 complain_overflow_dont, /* complain_on_overflow */
   1677 	 _bfd_mips_elf_generic_reloc,   /* special_function */
   1678 	 "R_MIPS_PCLO16",	/* name */
   1679 	 FALSE,			/* partial_inplace */
   1680 	 0,			/* src_mask */
   1681 	 0x0000ffff,		/* dst_mask */
   1682 	 TRUE),			/* pcrel_offset */
   1683 
   1684 };
   1685 
   1686 static reloc_howto_type mips16_elf64_howto_table_rel[] =
   1687 {
   1688   /* The reloc used for the mips16 jump instruction.  */
   1689   HOWTO (R_MIPS16_26,		/* type */
   1690 	 2,			/* rightshift */
   1691 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1692 	 26,			/* bitsize */
   1693 	 FALSE,			/* pc_relative */
   1694 	 0,			/* bitpos */
   1695 	 complain_overflow_dont, /* complain_on_overflow */
   1696 	 			/* This needs complex overflow
   1697 				   detection, because the upper four
   1698 				   bits must match the PC.  */
   1699 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1700 	 "R_MIPS16_26",		/* name */
   1701 	 TRUE,			/* partial_inplace */
   1702 	 0x3ffffff,		/* src_mask */
   1703 	 0x3ffffff,		/* dst_mask */
   1704 	 FALSE),		/* pcrel_offset */
   1705 
   1706   /* The reloc used for the mips16 gprel instruction.  */
   1707   HOWTO (R_MIPS16_GPREL,	/* type */
   1708 	 0,			/* rightshift */
   1709 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1710 	 16,			/* bitsize */
   1711 	 FALSE,			/* pc_relative */
   1712 	 0,			/* bitpos */
   1713 	 complain_overflow_signed, /* complain_on_overflow */
   1714 	 mips16_gprel_reloc,	/* special_function */
   1715 	 "R_MIPS16_GPREL",	/* name */
   1716 	 TRUE,			/* partial_inplace */
   1717 	 0x0000ffff,		/* src_mask */
   1718 	 0x0000ffff,	        /* dst_mask */
   1719 	 FALSE),		/* pcrel_offset */
   1720 
   1721   /* A MIPS16 reference to the global offset table.  */
   1722   HOWTO (R_MIPS16_GOT16,	/* type */
   1723 	 0,			/* rightshift */
   1724 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1725 	 16,			/* bitsize */
   1726 	 FALSE,			/* pc_relative */
   1727 	 0,			/* bitpos */
   1728 	 complain_overflow_dont, /* complain_on_overflow */
   1729 	 _bfd_mips_elf_got16_reloc, /* special_function */
   1730 	 "R_MIPS16_GOT16",	/* name */
   1731 	 TRUE,			/* partial_inplace */
   1732 	 0x0000ffff,		/* src_mask */
   1733 	 0x0000ffff,	        /* dst_mask */
   1734 	 FALSE),		/* pcrel_offset */
   1735 
   1736   /* A MIPS16 call through the global offset table.  */
   1737   HOWTO (R_MIPS16_CALL16,	/* type */
   1738 	 0,			/* rightshift */
   1739 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1740 	 16,			/* bitsize */
   1741 	 FALSE,			/* pc_relative */
   1742 	 0,			/* bitpos */
   1743 	 complain_overflow_dont, /* complain_on_overflow */
   1744 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1745 	 "R_MIPS16_CALL16",	/* name */
   1746 	 TRUE,			/* partial_inplace */
   1747 	 0x0000ffff,		/* src_mask */
   1748 	 0x0000ffff,	        /* dst_mask */
   1749 	 FALSE),		/* pcrel_offset */
   1750 
   1751   /* MIPS16 high 16 bits of symbol value.  */
   1752   HOWTO (R_MIPS16_HI16,		/* type */
   1753 	 16,			/* rightshift */
   1754 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1755 	 16,			/* bitsize */
   1756 	 FALSE,			/* pc_relative */
   1757 	 0,			/* bitpos */
   1758 	 complain_overflow_dont, /* complain_on_overflow */
   1759 	 _bfd_mips_elf_hi16_reloc, /* special_function */
   1760 	 "R_MIPS16_HI16",	/* name */
   1761 	 TRUE,			/* partial_inplace */
   1762 	 0x0000ffff,		/* src_mask */
   1763 	 0x0000ffff,		/* dst_mask */
   1764 	 FALSE),		/* pcrel_offset */
   1765 
   1766   /* MIPS16 low 16 bits of symbol value.  */
   1767   HOWTO (R_MIPS16_LO16,		/* type */
   1768 	 0,			/* rightshift */
   1769 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1770 	 16,			/* bitsize */
   1771 	 FALSE,			/* pc_relative */
   1772 	 0,			/* bitpos */
   1773 	 complain_overflow_dont, /* complain_on_overflow */
   1774 	 _bfd_mips_elf_lo16_reloc, /* special_function */
   1775 	 "R_MIPS16_LO16",	/* name */
   1776 	 TRUE,			/* partial_inplace */
   1777 	 0x0000ffff,		/* src_mask */
   1778 	 0x0000ffff,		/* dst_mask */
   1779 	 FALSE),		/* pcrel_offset */
   1780 
   1781   /* MIPS16 TLS general dynamic variable reference.  */
   1782   HOWTO (R_MIPS16_TLS_GD,	/* type */
   1783 	 0,			/* rightshift */
   1784 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1785 	 16,			/* bitsize */
   1786 	 FALSE,			/* pc_relative */
   1787 	 0,			/* bitpos */
   1788 	 complain_overflow_signed, /* complain_on_overflow */
   1789 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1790 	 "R_MIPS16_TLS_GD",	/* name */
   1791 	 TRUE,			/* partial_inplace */
   1792 	 0x0000ffff,		/* src_mask */
   1793 	 0x0000ffff,		/* dst_mask */
   1794 	 FALSE),		/* pcrel_offset */
   1795 
   1796   /* MIPS16 TLS local dynamic variable reference.  */
   1797   HOWTO (R_MIPS16_TLS_LDM,	/* type */
   1798 	 0,			/* rightshift */
   1799 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1800 	 16,			/* bitsize */
   1801 	 FALSE,			/* pc_relative */
   1802 	 0,			/* bitpos */
   1803 	 complain_overflow_signed, /* complain_on_overflow */
   1804 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1805 	 "R_MIPS16_TLS_LDM",	/* name */
   1806 	 TRUE,			/* partial_inplace */
   1807 	 0x0000ffff,		/* src_mask */
   1808 	 0x0000ffff,		/* dst_mask */
   1809 	 FALSE),		/* pcrel_offset */
   1810 
   1811   /* MIPS16 TLS local dynamic offset.  */
   1812   HOWTO (R_MIPS16_TLS_DTPREL_HI16,	/* type */
   1813 	 0,			/* rightshift */
   1814 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1815 	 16,			/* bitsize */
   1816 	 FALSE,			/* pc_relative */
   1817 	 0,			/* bitpos */
   1818 	 complain_overflow_signed, /* complain_on_overflow */
   1819 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1820 	 "R_MIPS16_TLS_DTPREL_HI16",	/* name */
   1821 	 TRUE,			/* partial_inplace */
   1822 	 0x0000ffff,		/* src_mask */
   1823 	 0x0000ffff,		/* dst_mask */
   1824 	 FALSE),		/* pcrel_offset */
   1825 
   1826   /* MIPS16 TLS local dynamic offset.  */
   1827   HOWTO (R_MIPS16_TLS_DTPREL_LO16,	/* type */
   1828 	 0,			/* rightshift */
   1829 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1830 	 16,			/* bitsize */
   1831 	 FALSE,			/* pc_relative */
   1832 	 0,			/* bitpos */
   1833 	 complain_overflow_signed, /* complain_on_overflow */
   1834 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1835 	 "R_MIPS16_TLS_DTPREL_LO16",	/* name */
   1836 	 TRUE,			/* partial_inplace */
   1837 	 0x0000ffff,		/* src_mask */
   1838 	 0x0000ffff,		/* dst_mask */
   1839 	 FALSE),		/* pcrel_offset */
   1840 
   1841   /* MIPS16 TLS thread pointer offset.  */
   1842   HOWTO (R_MIPS16_TLS_GOTTPREL,	/* type */
   1843 	 0,			/* rightshift */
   1844 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1845 	 16,			/* bitsize */
   1846 	 FALSE,			/* pc_relative */
   1847 	 0,			/* bitpos */
   1848 	 complain_overflow_signed, /* complain_on_overflow */
   1849 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1850 	 "R_MIPS16_TLS_GOTTPREL",	/* name */
   1851 	 TRUE,			/* partial_inplace */
   1852 	 0x0000ffff,		/* src_mask */
   1853 	 0x0000ffff,		/* dst_mask */
   1854 	 FALSE),		/* pcrel_offset */
   1855 
   1856   /* MIPS16 TLS thread pointer offset.  */
   1857   HOWTO (R_MIPS16_TLS_TPREL_HI16,	/* type */
   1858 	 0,			/* rightshift */
   1859 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1860 	 16,			/* bitsize */
   1861 	 FALSE,			/* pc_relative */
   1862 	 0,			/* bitpos */
   1863 	 complain_overflow_signed, /* complain_on_overflow */
   1864 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1865 	 "R_MIPS16_TLS_TPREL_HI16", /* name */
   1866 	 TRUE,			/* partial_inplace */
   1867 	 0x0000ffff,		/* src_mask */
   1868 	 0x0000ffff,		/* dst_mask */
   1869 	 FALSE),		/* pcrel_offset */
   1870 
   1871   /* MIPS16 TLS thread pointer offset.  */
   1872   HOWTO (R_MIPS16_TLS_TPREL_LO16,	/* type */
   1873 	 0,			/* rightshift */
   1874 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1875 	 16,			/* bitsize */
   1876 	 FALSE,			/* pc_relative */
   1877 	 0,			/* bitpos */
   1878 	 complain_overflow_signed, /* complain_on_overflow */
   1879 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1880 	 "R_MIPS16_TLS_TPREL_LO16", /* name */
   1881 	 TRUE,			/* partial_inplace */
   1882 	 0x0000ffff,		/* src_mask */
   1883 	 0x0000ffff,		/* dst_mask */
   1884 	 FALSE),		/* pcrel_offset */
   1885 
   1886   /* MIPS16 16-bit PC-relative branch offset.  */
   1887   HOWTO (R_MIPS16_PC16_S1,	/* type */
   1888 	 1,			/* rightshift */
   1889 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1890 	 16,			/* bitsize */
   1891 	 TRUE,			/* pc_relative */
   1892 	 0,			/* bitpos */
   1893 	 complain_overflow_signed, /* complain_on_overflow */
   1894 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1895 	 "R_MIPS16_PC16_S1",	/* name */
   1896 	 TRUE,			/* partial_inplace */
   1897 	 0x0000ffff,		/* src_mask */
   1898 	 0x0000ffff,		/* dst_mask */
   1899 	 TRUE),			/* pcrel_offset */
   1900 };
   1901 
   1902 static reloc_howto_type mips16_elf64_howto_table_rela[] =
   1903 {
   1904   /* The reloc used for the mips16 jump instruction.  */
   1905   HOWTO (R_MIPS16_26,		/* type */
   1906 	 2,			/* rightshift */
   1907 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1908 	 26,			/* bitsize */
   1909 	 FALSE,			/* pc_relative */
   1910 	 0,			/* bitpos */
   1911 	 complain_overflow_dont, /* complain_on_overflow */
   1912 	 			/* This needs complex overflow
   1913 				   detection, because the upper four
   1914 				   bits must match the PC.  */
   1915 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1916 	 "R_MIPS16_26",		/* name */
   1917 	 FALSE,			/* partial_inplace */
   1918 	 0,			/* src_mask */
   1919 	 0x3ffffff,		/* dst_mask */
   1920 	 FALSE),		/* pcrel_offset */
   1921 
   1922   /* The reloc used for the mips16 gprel instruction.  */
   1923   HOWTO (R_MIPS16_GPREL,	/* type */
   1924 	 0,			/* rightshift */
   1925 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1926 	 16,			/* bitsize */
   1927 	 FALSE,			/* pc_relative */
   1928 	 0,			/* bitpos */
   1929 	 complain_overflow_signed, /* complain_on_overflow */
   1930 	 mips16_gprel_reloc,	/* special_function */
   1931 	 "R_MIPS16_GPREL",	/* name */
   1932 	 FALSE,			/* partial_inplace */
   1933 	 0,			/* src_mask */
   1934 	 0x0000ffff,	        /* dst_mask */
   1935 	 FALSE),		/* pcrel_offset */
   1936 
   1937   /* A MIPS16 reference to the global offset table.  */
   1938   HOWTO (R_MIPS16_GOT16,	/* type */
   1939 	 0,			/* rightshift */
   1940 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1941 	 16,			/* bitsize */
   1942 	 FALSE,			/* pc_relative */
   1943 	 0,			/* bitpos */
   1944 	 complain_overflow_dont, /* complain_on_overflow */
   1945 	 _bfd_mips_elf_got16_reloc, /* special_function */
   1946 	 "R_MIPS16_GOT16",	/* name */
   1947 	 FALSE,			/* partial_inplace */
   1948 	 0,			/* src_mask */
   1949 	 0x0000ffff,	        /* dst_mask */
   1950 	 FALSE),		/* pcrel_offset */
   1951 
   1952   /* A MIPS16 call through the global offset table.  */
   1953   HOWTO (R_MIPS16_CALL16,	/* type */
   1954 	 0,			/* rightshift */
   1955 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1956 	 16,			/* bitsize */
   1957 	 FALSE,			/* pc_relative */
   1958 	 0,			/* bitpos */
   1959 	 complain_overflow_dont, /* complain_on_overflow */
   1960 	 _bfd_mips_elf_generic_reloc, /* special_function */
   1961 	 "R_MIPS16_CALL16",	/* name */
   1962 	 FALSE,			/* partial_inplace */
   1963 	 0,			/* src_mask */
   1964 	 0x0000ffff,	        /* dst_mask */
   1965 	 FALSE),		/* pcrel_offset */
   1966 
   1967   /* MIPS16 high 16 bits of symbol value.  */
   1968   HOWTO (R_MIPS16_HI16,		/* type */
   1969 	 16,			/* rightshift */
   1970 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1971 	 16,			/* bitsize */
   1972 	 FALSE,			/* pc_relative */
   1973 	 0,			/* bitpos */
   1974 	 complain_overflow_dont, /* complain_on_overflow */
   1975 	 _bfd_mips_elf_hi16_reloc, /* special_function */
   1976 	 "R_MIPS16_HI16",	/* name */
   1977 	 FALSE,			/* partial_inplace */
   1978 	 0,			/* src_mask */
   1979 	 0x0000ffff,		/* dst_mask */
   1980 	 FALSE),		/* pcrel_offset */
   1981 
   1982   /* MIPS16 low 16 bits of symbol value.  */
   1983   HOWTO (R_MIPS16_LO16,		/* type */
   1984 	 0,			/* rightshift */
   1985 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1986 	 16,			/* bitsize */
   1987 	 FALSE,			/* pc_relative */
   1988 	 0,			/* bitpos */
   1989 	 complain_overflow_dont, /* complain_on_overflow */
   1990 	 _bfd_mips_elf_lo16_reloc, /* special_function */
   1991 	 "R_MIPS16_LO16",	/* name */
   1992 	 FALSE,			/* partial_inplace */
   1993 	 0,			/* src_mask */
   1994 	 0x0000ffff,		/* dst_mask */
   1995 	 FALSE),		/* pcrel_offset */
   1996 
   1997   /* MIPS16 TLS general dynamic variable reference.  */
   1998   HOWTO (R_MIPS16_TLS_GD,	/* type */
   1999 	 0,			/* rightshift */
   2000 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2001 	 16,			/* bitsize */
   2002 	 FALSE,			/* pc_relative */
   2003 	 0,			/* bitpos */
   2004 	 complain_overflow_signed, /* complain_on_overflow */
   2005 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2006 	 "R_MIPS16_TLS_GD",	/* name */
   2007 	 FALSE,			/* partial_inplace */
   2008 	 0,			/* src_mask */
   2009 	 0x0000ffff,		/* dst_mask */
   2010 	 FALSE),		/* pcrel_offset */
   2011 
   2012   /* MIPS16 TLS local dynamic variable reference.  */
   2013   HOWTO (R_MIPS16_TLS_LDM,	/* type */
   2014 	 0,			/* rightshift */
   2015 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2016 	 16,			/* bitsize */
   2017 	 FALSE,			/* pc_relative */
   2018 	 0,			/* bitpos */
   2019 	 complain_overflow_signed, /* complain_on_overflow */
   2020 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2021 	 "R_MIPS16_TLS_LDM",	/* name */
   2022 	 FALSE,			/* partial_inplace */
   2023 	 0,			/* src_mask */
   2024 	 0x0000ffff,		/* dst_mask */
   2025 	 FALSE),		/* pcrel_offset */
   2026 
   2027   /* MIPS16 TLS local dynamic offset.  */
   2028   HOWTO (R_MIPS16_TLS_DTPREL_HI16,	/* type */
   2029 	 0,			/* rightshift */
   2030 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2031 	 16,			/* bitsize */
   2032 	 FALSE,			/* pc_relative */
   2033 	 0,			/* bitpos */
   2034 	 complain_overflow_signed, /* complain_on_overflow */
   2035 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2036 	 "R_MIPS16_TLS_DTPREL_HI16",	/* name */
   2037 	 FALSE,			/* partial_inplace */
   2038 	 0,			/* src_mask */
   2039 	 0x0000ffff,		/* dst_mask */
   2040 	 FALSE),		/* pcrel_offset */
   2041 
   2042   /* MIPS16 TLS local dynamic offset.  */
   2043   HOWTO (R_MIPS16_TLS_DTPREL_LO16,	/* type */
   2044 	 0,			/* rightshift */
   2045 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2046 	 16,			/* bitsize */
   2047 	 FALSE,			/* pc_relative */
   2048 	 0,			/* bitpos */
   2049 	 complain_overflow_signed, /* complain_on_overflow */
   2050 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2051 	 "R_MIPS16_TLS_DTPREL_LO16",	/* name */
   2052 	 FALSE,			/* partial_inplace */
   2053 	 0,			/* src_mask */
   2054 	 0x0000ffff,		/* dst_mask */
   2055 	 FALSE),		/* pcrel_offset */
   2056 
   2057   /* MIPS16 TLS thread pointer offset.  */
   2058   HOWTO (R_MIPS16_TLS_GOTTPREL,	/* type */
   2059 	 0,			/* rightshift */
   2060 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2061 	 16,			/* bitsize */
   2062 	 FALSE,			/* pc_relative */
   2063 	 0,			/* bitpos */
   2064 	 complain_overflow_signed, /* complain_on_overflow */
   2065 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2066 	 "R_MIPS16_TLS_GOTTPREL",	/* name */
   2067 	 FALSE,			/* partial_inplace */
   2068 	 0,			/* src_mask */
   2069 	 0x0000ffff,		/* dst_mask */
   2070 	 FALSE),		/* pcrel_offset */
   2071 
   2072   /* MIPS16 TLS thread pointer offset.  */
   2073   HOWTO (R_MIPS16_TLS_TPREL_HI16,	/* type */
   2074 	 0,			/* rightshift */
   2075 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2076 	 16,			/* bitsize */
   2077 	 FALSE,			/* pc_relative */
   2078 	 0,			/* bitpos */
   2079 	 complain_overflow_signed, /* complain_on_overflow */
   2080 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2081 	 "R_MIPS16_TLS_TPREL_HI16", /* name */
   2082 	 FALSE,			/* partial_inplace */
   2083 	 0,			/* src_mask */
   2084 	 0x0000ffff,		/* dst_mask */
   2085 	 FALSE),		/* pcrel_offset */
   2086 
   2087   /* MIPS16 TLS thread pointer offset.  */
   2088   HOWTO (R_MIPS16_TLS_TPREL_LO16,	/* type */
   2089 	 0,			/* rightshift */
   2090 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2091 	 16,			/* bitsize */
   2092 	 FALSE,			/* pc_relative */
   2093 	 0,			/* bitpos */
   2094 	 complain_overflow_signed, /* complain_on_overflow */
   2095 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2096 	 "R_MIPS16_TLS_TPREL_LO16", /* name */
   2097 	 FALSE,			/* partial_inplace */
   2098 	 0,			/* src_mask */
   2099 	 0x0000ffff,		/* dst_mask */
   2100 	 FALSE),		/* pcrel_offset */
   2101 
   2102   /* MIPS16 16-bit PC-relative branch offset.  */
   2103   HOWTO (R_MIPS16_PC16_S1,	/* type */
   2104 	 1,			/* rightshift */
   2105 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2106 	 16,			/* bitsize */
   2107 	 TRUE,			/* pc_relative */
   2108 	 0,			/* bitpos */
   2109 	 complain_overflow_signed, /* complain_on_overflow */
   2110 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2111 	 "R_MIPS16_PC16_S1",	/* name */
   2112 	 FALSE,			/* partial_inplace */
   2113 	 0,			/* src_mask */
   2114 	 0x0000ffff,		/* dst_mask */
   2115 	 TRUE),			/* pcrel_offset */
   2116 };
   2117 
   2118 static reloc_howto_type micromips_elf64_howto_table_rel[] =
   2119 {
   2120   EMPTY_HOWTO (130),
   2121   EMPTY_HOWTO (131),
   2122   EMPTY_HOWTO (132),
   2123 
   2124   /* 26 bit jump address.  */
   2125   HOWTO (R_MICROMIPS_26_S1,	/* type */
   2126 	 1,			/* rightshift */
   2127 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2128 	 26,			/* bitsize */
   2129 	 FALSE,			/* pc_relative */
   2130 	 0,			/* bitpos */
   2131 	 complain_overflow_dont, /* complain_on_overflow */
   2132 	 			/* This needs complex overflow
   2133 				   detection, because the upper four
   2134 				   bits must match the PC.  */
   2135 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2136 	 "R_MICROMIPS_26_S1",	/* name */
   2137 	 TRUE,			/* partial_inplace */
   2138 	 0x3ffffff,		/* src_mask */
   2139 	 0x3ffffff,		/* dst_mask */
   2140 	 FALSE),		/* pcrel_offset */
   2141 
   2142   /* High 16 bits of symbol value.  */
   2143   HOWTO (R_MICROMIPS_HI16,	/* type */
   2144 	 16,			/* rightshift */
   2145 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2146 	 16,			/* bitsize */
   2147 	 FALSE,			/* pc_relative */
   2148 	 0,			/* bitpos */
   2149 	 complain_overflow_dont, /* complain_on_overflow */
   2150 	 _bfd_mips_elf_hi16_reloc, /* special_function */
   2151 	 "R_MICROMIPS_HI16",	/* name */
   2152 	 TRUE,			/* partial_inplace */
   2153 	 0x0000ffff,		/* src_mask */
   2154 	 0x0000ffff,		/* dst_mask */
   2155 	 FALSE),		/* pcrel_offset */
   2156 
   2157   /* Low 16 bits of symbol value.  */
   2158   HOWTO (R_MICROMIPS_LO16,	/* type */
   2159 	 0,			/* rightshift */
   2160 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2161 	 16,			/* bitsize */
   2162 	 FALSE,			/* pc_relative */
   2163 	 0,			/* bitpos */
   2164 	 complain_overflow_dont, /* complain_on_overflow */
   2165 	 _bfd_mips_elf_lo16_reloc, /* special_function */
   2166 	 "R_MICROMIPS_LO16",	/* name */
   2167 	 TRUE,			/* partial_inplace */
   2168 	 0x0000ffff,		/* src_mask */
   2169 	 0x0000ffff,		/* dst_mask */
   2170 	 FALSE),		/* pcrel_offset */
   2171 
   2172   /* GP relative reference.  */
   2173   HOWTO (R_MICROMIPS_GPREL16,	/* type */
   2174 	 0,			/* rightshift */
   2175 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2176 	 16,			/* bitsize */
   2177 	 FALSE,			/* pc_relative */
   2178 	 0,			/* bitpos */
   2179 	 complain_overflow_signed, /* complain_on_overflow */
   2180 	 _bfd_mips_elf32_gprel16_reloc, /* special_function */
   2181 	 "R_MICROMIPS_GPREL16",	/* name */
   2182 	 TRUE,			/* partial_inplace */
   2183 	 0x0000ffff,		/* src_mask */
   2184 	 0x0000ffff,		/* dst_mask */
   2185 	 FALSE),		/* pcrel_offset */
   2186 
   2187   /* Reference to literal section.  */
   2188   HOWTO (R_MICROMIPS_LITERAL,	/* type */
   2189 	 0,			/* rightshift */
   2190 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2191 	 16,			/* bitsize */
   2192 	 FALSE,			/* pc_relative */
   2193 	 0,			/* bitpos */
   2194 	 complain_overflow_signed, /* complain_on_overflow */
   2195 	 _bfd_mips_elf32_gprel16_reloc, /* special_function */
   2196 	 "R_MICROMIPS_LITERAL",	/* name */
   2197 	 TRUE,			/* partial_inplace */
   2198 	 0x0000ffff,		/* src_mask */
   2199 	 0x0000ffff,		/* dst_mask */
   2200 	 FALSE),		/* pcrel_offset */
   2201 
   2202   /* Reference to global offset table.  */
   2203   HOWTO (R_MICROMIPS_GOT16,	/* type */
   2204 	 0,			/* rightshift */
   2205 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2206 	 16,			/* bitsize */
   2207 	 FALSE,			/* pc_relative */
   2208 	 0,			/* bitpos */
   2209 	 complain_overflow_signed, /* complain_on_overflow */
   2210 	 _bfd_mips_elf_got16_reloc, /* special_function */
   2211 	 "R_MICROMIPS_GOT16",	/* name */
   2212 	 TRUE,			/* partial_inplace */
   2213 	 0x0000ffff,		/* src_mask */
   2214 	 0x0000ffff,		/* dst_mask */
   2215 	 FALSE),		/* pcrel_offset */
   2216 
   2217   /* This is for microMIPS branches.  */
   2218   HOWTO (R_MICROMIPS_PC7_S1,	/* type */
   2219 	 1,			/* rightshift */
   2220 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   2221 	 7,			/* bitsize */
   2222 	 TRUE,			/* pc_relative */
   2223 	 0,			/* bitpos */
   2224 	 complain_overflow_signed, /* complain_on_overflow */
   2225 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2226 	 "R_MICROMIPS_PC7_S1",	/* name */
   2227 	 TRUE,			/* partial_inplace */
   2228 	 0x0000007f,		/* src_mask */
   2229 	 0x0000007f,		/* dst_mask */
   2230 	 TRUE),			/* pcrel_offset */
   2231 
   2232   HOWTO (R_MICROMIPS_PC10_S1,	/* type */
   2233 	 1,			/* rightshift */
   2234 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   2235 	 10,			/* bitsize */
   2236 	 TRUE,			/* pc_relative */
   2237 	 0,			/* bitpos */
   2238 	 complain_overflow_signed, /* complain_on_overflow */
   2239 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2240 	 "R_MICROMIPS_PC10_S1",	/* name */
   2241 	 TRUE,			/* partial_inplace */
   2242 	 0x000003ff,		/* src_mask */
   2243 	 0x000003ff,		/* dst_mask */
   2244 	 TRUE),			/* pcrel_offset */
   2245 
   2246   HOWTO (R_MICROMIPS_PC16_S1,	/* type */
   2247 	 1,			/* rightshift */
   2248 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2249 	 16,			/* bitsize */
   2250 	 TRUE,			/* pc_relative */
   2251 	 0,			/* bitpos */
   2252 	 complain_overflow_signed, /* complain_on_overflow */
   2253 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2254 	 "R_MICROMIPS_PC16_S1",	/* name */
   2255 	 TRUE,			/* partial_inplace */
   2256 	 0x0000ffff,		/* src_mask */
   2257 	 0x0000ffff,		/* dst_mask */
   2258 	 TRUE),			/* pcrel_offset */
   2259 
   2260   /* 16 bit call through global offset table.  */
   2261   HOWTO (R_MICROMIPS_CALL16,	/* type */
   2262 	 0,			/* rightshift */
   2263 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2264 	 16,			/* bitsize */
   2265 	 FALSE,			/* pc_relative */
   2266 	 0,			/* bitpos */
   2267 	 complain_overflow_signed, /* complain_on_overflow */
   2268 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2269 	 "R_MICROMIPS_CALL16",	/* name */
   2270 	 TRUE,			/* partial_inplace */
   2271 	 0x0000ffff,		/* src_mask */
   2272 	 0x0000ffff,		/* dst_mask */
   2273 	 FALSE),		/* pcrel_offset */
   2274 
   2275   EMPTY_HOWTO (143),
   2276   EMPTY_HOWTO (144),
   2277 
   2278   /* Displacement in the global offset table.  */
   2279   HOWTO (R_MICROMIPS_GOT_DISP,	/* type */
   2280 	 0,			/* rightshift */
   2281 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2282 	 16,			/* bitsize */
   2283 	 FALSE,			/* pc_relative */
   2284 	 0,			/* bitpos */
   2285 	 complain_overflow_signed, /* complain_on_overflow */
   2286 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2287 	 "R_MICROMIPS_GOT_DISP",/* name */
   2288 	 TRUE,			/* partial_inplace */
   2289 	 0x0000ffff,		/* src_mask */
   2290 	 0x0000ffff,		/* dst_mask */
   2291 	 FALSE),		/* pcrel_offset */
   2292 
   2293   /* Displacement to page pointer in the global offset table.  */
   2294   HOWTO (R_MICROMIPS_GOT_PAGE,	/* type */
   2295 	 0,			/* rightshift */
   2296 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2297 	 16,			/* bitsize */
   2298 	 FALSE,			/* pc_relative */
   2299 	 0,			/* bitpos */
   2300 	 complain_overflow_signed, /* complain_on_overflow */
   2301 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2302 	 "R_MICROMIPS_GOT_PAGE",/* name */
   2303 	 TRUE,			/* partial_inplace */
   2304 	 0x0000ffff,		/* src_mask */
   2305 	 0x0000ffff,		/* dst_mask */
   2306 	 FALSE),		/* pcrel_offset */
   2307 
   2308   /* Offset from page pointer in the global offset table.  */
   2309   HOWTO (R_MICROMIPS_GOT_OFST,	/* type */
   2310 	 0,			/* rightshift */
   2311 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2312 	 16,			/* bitsize */
   2313 	 FALSE,			/* pc_relative */
   2314 	 0,			/* bitpos */
   2315 	 complain_overflow_signed, /* complain_on_overflow */
   2316 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2317 	 "R_MICROMIPS_GOT_OFST",/* name */
   2318 	 TRUE,			/* partial_inplace */
   2319 	 0x0000ffff,		/* src_mask */
   2320 	 0x0000ffff,		/* dst_mask */
   2321 	 FALSE),		/* pcrel_offset */
   2322 
   2323   /* High 16 bits of displacement in global offset table.  */
   2324   HOWTO (R_MICROMIPS_GOT_HI16,	/* type */
   2325 	 0,			/* rightshift */
   2326 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2327 	 16,			/* bitsize */
   2328 	 FALSE,			/* pc_relative */
   2329 	 0,			/* bitpos */
   2330 	 complain_overflow_dont, /* complain_on_overflow */
   2331 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2332 	 "R_MICROMIPS_GOT_HI16",/* name */
   2333 	 TRUE,			/* partial_inplace */
   2334 	 0x0000ffff,		/* src_mask */
   2335 	 0x0000ffff,		/* dst_mask */
   2336 	 FALSE),		/* pcrel_offset */
   2337 
   2338   /* Low 16 bits of displacement in global offset table.  */
   2339   HOWTO (R_MICROMIPS_GOT_LO16,	/* type */
   2340 	 0,			/* rightshift */
   2341 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2342 	 16,			/* bitsize */
   2343 	 FALSE,			/* pc_relative */
   2344 	 0,			/* bitpos */
   2345 	 complain_overflow_dont, /* complain_on_overflow */
   2346 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2347 	 "R_MICROMIPS_GOT_LO16",/* name */
   2348 	 TRUE,			/* partial_inplace */
   2349 	 0x0000ffff,		/* src_mask */
   2350 	 0x0000ffff,		/* dst_mask */
   2351 	 FALSE),		/* pcrel_offset */
   2352 
   2353   /* 64 bit subtraction.  Used in the N32 ABI.  */
   2354   HOWTO (R_MICROMIPS_SUB,	/* type */
   2355 	 0,			/* rightshift */
   2356 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
   2357 	 64,			/* bitsize */
   2358 	 FALSE,			/* pc_relative */
   2359 	 0,			/* bitpos */
   2360 	 complain_overflow_dont, /* complain_on_overflow */
   2361 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2362 	 "R_MICROMIPS_SUB",	/* name */
   2363 	 TRUE,			/* partial_inplace */
   2364 	 MINUS_ONE,		/* src_mask */
   2365 	 MINUS_ONE,		/* dst_mask */
   2366 	 FALSE),		/* pcrel_offset */
   2367 
   2368   /* We don't support these for REL relocations, because it means building
   2369      the addend from a R_MICROMIPS_HIGHEST/R_MICROMIPS_HIGHER/
   2370      R_MICROMIPS_HI16/R_MICROMIPS_LO16 sequence with varying ordering,
   2371      using fallable heuristics.  */
   2372   EMPTY_HOWTO (R_MICROMIPS_HIGHER),
   2373   EMPTY_HOWTO (R_MICROMIPS_HIGHEST),
   2374 
   2375   /* High 16 bits of displacement in global offset table.  */
   2376   HOWTO (R_MICROMIPS_CALL_HI16,	/* type */
   2377 	 0,			/* rightshift */
   2378 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2379 	 16,			/* bitsize */
   2380 	 FALSE,			/* pc_relative */
   2381 	 0,			/* bitpos */
   2382 	 complain_overflow_dont, /* complain_on_overflow */
   2383 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2384 	 "R_MICROMIPS_CALL_HI16",/* name */
   2385 	 TRUE,			/* partial_inplace */
   2386 	 0x0000ffff,		/* src_mask */
   2387 	 0x0000ffff,		/* dst_mask */
   2388 	 FALSE),		/* pcrel_offset */
   2389 
   2390   /* Low 16 bits of displacement in global offset table.  */
   2391   HOWTO (R_MICROMIPS_CALL_LO16,	/* type */
   2392 	 0,			/* rightshift */
   2393 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2394 	 16,			/* bitsize */
   2395 	 FALSE,			/* pc_relative */
   2396 	 0,			/* bitpos */
   2397 	 complain_overflow_dont, /* complain_on_overflow */
   2398 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2399 	 "R_MICROMIPS_CALL_LO16",/* name */
   2400 	 TRUE,			/* partial_inplace */
   2401 	 0x0000ffff,		/* src_mask */
   2402 	 0x0000ffff,		/* dst_mask */
   2403 	 FALSE),		/* pcrel_offset */
   2404 
   2405   /* Section displacement.  */
   2406   HOWTO (R_MICROMIPS_SCN_DISP,  /* type */
   2407 	 0,			/* rightshift */
   2408 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2409 	 32,			/* bitsize */
   2410 	 FALSE,			/* pc_relative */
   2411 	 0,			/* bitpos */
   2412 	 complain_overflow_dont, /* complain_on_overflow */
   2413 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2414 	 "R_MICROMIPS_SCN_DISP", /* name */
   2415 	 TRUE,			/* partial_inplace */
   2416 	 0xffffffff,		/* src_mask */
   2417 	 0xffffffff,		/* dst_mask */
   2418 	 FALSE),		/* pcrel_offset */
   2419 
   2420   /* Protected jump conversion.  This is an optimization hint.  No
   2421      relocation is required for correctness.  */
   2422   HOWTO (R_MICROMIPS_JALR,	/* type */
   2423 	 0,			/* rightshift */
   2424 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2425 	 32,			/* bitsize */
   2426 	 FALSE,			/* pc_relative */
   2427 	 0,			/* bitpos */
   2428 	 complain_overflow_dont, /* complain_on_overflow */
   2429 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2430 	 "R_MICROMIPS_JALR",	/* name */
   2431 	 FALSE,			/* partial_inplace */
   2432 	 0,			/* src_mask */
   2433 	 0x00000000,		/* dst_mask */
   2434 	 FALSE),		/* pcrel_offset */
   2435 };
   2436 
   2437 static reloc_howto_type micromips_elf64_howto_table_rela[] =
   2438 {
   2439   EMPTY_HOWTO (130),
   2440   EMPTY_HOWTO (131),
   2441   EMPTY_HOWTO (132),
   2442 
   2443   /* 26 bit jump address.  */
   2444   HOWTO (R_MICROMIPS_26_S1,	/* type */
   2445 	 1,			/* rightshift */
   2446 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2447 	 26,			/* bitsize */
   2448 	 FALSE,			/* pc_relative */
   2449 	 0,			/* bitpos */
   2450 	 complain_overflow_dont, /* complain_on_overflow */
   2451 	 			/* This needs complex overflow
   2452 				   detection, because the upper four
   2453 				   bits must match the PC.  */
   2454 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2455 	 "R_MICROMIPS_26_S1",	/* name */
   2456 	 FALSE,			/* partial_inplace */
   2457 	 0,			/* src_mask */
   2458 	 0x3ffffff,		/* dst_mask */
   2459 	 FALSE),		/* pcrel_offset */
   2460 
   2461   /* High 16 bits of symbol value.  */
   2462   HOWTO (R_MICROMIPS_HI16,	/* type */
   2463 	 16,			/* rightshift */
   2464 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2465 	 16,			/* bitsize */
   2466 	 FALSE,			/* pc_relative */
   2467 	 0,			/* bitpos */
   2468 	 complain_overflow_dont, /* complain_on_overflow */
   2469 	 _bfd_mips_elf_hi16_reloc, /* special_function */
   2470 	 "R_MICROMIPS_HI16",	/* name */
   2471 	 FALSE,			/* partial_inplace */
   2472 	 0,			/* src_mask */
   2473 	 0x0000ffff,		/* dst_mask */
   2474 	 FALSE),		/* pcrel_offset */
   2475 
   2476   /* Low 16 bits of symbol value.  */
   2477   HOWTO (R_MICROMIPS_LO16,	/* type */
   2478 	 0,			/* rightshift */
   2479 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2480 	 16,			/* bitsize */
   2481 	 FALSE,			/* pc_relative */
   2482 	 0,			/* bitpos */
   2483 	 complain_overflow_dont, /* complain_on_overflow */
   2484 	 _bfd_mips_elf_lo16_reloc, /* special_function */
   2485 	 "R_MICROMIPS_LO16",	/* name */
   2486 	 FALSE,			/* partial_inplace */
   2487 	 0,			/* src_mask */
   2488 	 0x0000ffff,		/* dst_mask */
   2489 	 FALSE),		/* pcrel_offset */
   2490 
   2491   /* GP relative reference.  */
   2492   HOWTO (R_MICROMIPS_GPREL16,	/* type */
   2493 	 0,			/* rightshift */
   2494 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2495 	 16,			/* bitsize */
   2496 	 FALSE,			/* pc_relative */
   2497 	 0,			/* bitpos */
   2498 	 complain_overflow_signed, /* complain_on_overflow */
   2499 	 _bfd_mips_elf32_gprel16_reloc, /* special_function */
   2500 	 "R_MICROMIPS_GPREL16",	/* name */
   2501 	 FALSE,			/* partial_inplace */
   2502 	 0,			/* src_mask */
   2503 	 0x0000ffff,		/* dst_mask */
   2504 	 FALSE),		/* pcrel_offset */
   2505 
   2506   /* Reference to literal section.  */
   2507   HOWTO (R_MICROMIPS_LITERAL,	/* type */
   2508 	 0,			/* rightshift */
   2509 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2510 	 16,			/* bitsize */
   2511 	 FALSE,			/* pc_relative */
   2512 	 0,			/* bitpos */
   2513 	 complain_overflow_signed, /* complain_on_overflow */
   2514 	 _bfd_mips_elf32_gprel16_reloc, /* special_function */
   2515 	 "R_MICROMIPS_LITERAL",	/* name */
   2516 	 FALSE,			/* partial_inplace */
   2517 	 0,			/* src_mask */
   2518 	 0x0000ffff,		/* dst_mask */
   2519 	 FALSE),		/* pcrel_offset */
   2520 
   2521   /* Reference to global offset table.  */
   2522   HOWTO (R_MICROMIPS_GOT16,	/* type */
   2523 	 0,			/* rightshift */
   2524 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2525 	 16,			/* bitsize */
   2526 	 FALSE,			/* pc_relative */
   2527 	 0,			/* bitpos */
   2528 	 complain_overflow_signed, /* complain_on_overflow */
   2529 	 _bfd_mips_elf_got16_reloc, /* special_function */
   2530 	 "R_MICROMIPS_GOT16",	/* name */
   2531 	 FALSE,			/* partial_inplace */
   2532 	 0,			/* src_mask */
   2533 	 0x0000ffff,		/* dst_mask */
   2534 	 FALSE),		/* pcrel_offset */
   2535 
   2536   /* This is for microMIPS branches.  */
   2537   HOWTO (R_MICROMIPS_PC7_S1,	/* type */
   2538 	 1,			/* rightshift */
   2539 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   2540 	 7,			/* bitsize */
   2541 	 TRUE,			/* pc_relative */
   2542 	 0,			/* bitpos */
   2543 	 complain_overflow_signed, /* complain_on_overflow */
   2544 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2545 	 "R_MICROMIPS_PC7_S1",	/* name */
   2546 	 FALSE,			/* partial_inplace */
   2547 	 0,			/* src_mask */
   2548 	 0x0000007f,		/* dst_mask */
   2549 	 TRUE),			/* pcrel_offset */
   2550 
   2551   HOWTO (R_MICROMIPS_PC10_S1,	/* type */
   2552 	 1,			/* rightshift */
   2553 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   2554 	 10,			/* bitsize */
   2555 	 TRUE,			/* pc_relative */
   2556 	 0,			/* bitpos */
   2557 	 complain_overflow_signed, /* complain_on_overflow */
   2558 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2559 	 "R_MICROMIPS_PC10_S1",	/* name */
   2560 	 FALSE,			/* partial_inplace */
   2561 	 0,			/* src_mask */
   2562 	 0x000003ff,		/* dst_mask */
   2563 	 TRUE),			/* pcrel_offset */
   2564 
   2565   HOWTO (R_MICROMIPS_PC16_S1,	/* type */
   2566 	 1,			/* rightshift */
   2567 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2568 	 16,			/* bitsize */
   2569 	 TRUE,			/* pc_relative */
   2570 	 0,			/* bitpos */
   2571 	 complain_overflow_signed, /* complain_on_overflow */
   2572 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2573 	 "R_MICROMIPS_PC16_S1",	/* name */
   2574 	 FALSE,			/* partial_inplace */
   2575 	 0,			/* src_mask */
   2576 	 0x0000ffff,		/* dst_mask */
   2577 	 TRUE),			/* pcrel_offset */
   2578 
   2579   /* 16 bit call through global offset table.  */
   2580   HOWTO (R_MICROMIPS_CALL16,	/* type */
   2581 	 0,			/* rightshift */
   2582 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2583 	 16,			/* bitsize */
   2584 	 FALSE,			/* pc_relative */
   2585 	 0,			/* bitpos */
   2586 	 complain_overflow_signed, /* complain_on_overflow */
   2587 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2588 	 "R_MICROMIPS_CALL16",	/* name */
   2589 	 FALSE,			/* partial_inplace */
   2590 	 0,			/* src_mask */
   2591 	 0x0000ffff,		/* dst_mask */
   2592 	 FALSE),		/* pcrel_offset */
   2593 
   2594   EMPTY_HOWTO (143),
   2595   EMPTY_HOWTO (144),
   2596 
   2597   /* Displacement in the global offset table.  */
   2598   HOWTO (R_MICROMIPS_GOT_DISP,	/* type */
   2599 	 0,			/* rightshift */
   2600 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2601 	 16,			/* bitsize */
   2602 	 FALSE,			/* pc_relative */
   2603 	 0,			/* bitpos */
   2604 	 complain_overflow_signed, /* complain_on_overflow */
   2605 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2606 	 "R_MICROMIPS_GOT_DISP",/* name */
   2607 	 FALSE,			/* partial_inplace */
   2608 	 0,			/* src_mask */
   2609 	 0x0000ffff,		/* dst_mask */
   2610 	 FALSE),		/* pcrel_offset */
   2611 
   2612   /* Displacement to page pointer in the global offset table.  */
   2613   HOWTO (R_MICROMIPS_GOT_PAGE,	/* type */
   2614 	 0,			/* rightshift */
   2615 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2616 	 16,			/* bitsize */
   2617 	 FALSE,			/* pc_relative */
   2618 	 0,			/* bitpos */
   2619 	 complain_overflow_signed, /* complain_on_overflow */
   2620 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2621 	 "R_MICROMIPS_GOT_PAGE",/* name */
   2622 	 FALSE,			/* partial_inplace */
   2623 	 0,			/* src_mask */
   2624 	 0x0000ffff,		/* dst_mask */
   2625 	 FALSE),		/* pcrel_offset */
   2626 
   2627   /* Offset from page pointer in the global offset table.  */
   2628   HOWTO (R_MICROMIPS_GOT_OFST,	/* type */
   2629 	 0,			/* rightshift */
   2630 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2631 	 16,			/* bitsize */
   2632 	 FALSE,			/* pc_relative */
   2633 	 0,			/* bitpos */
   2634 	 complain_overflow_signed, /* complain_on_overflow */
   2635 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2636 	 "R_MICROMIPS_GOT_OFST",/* name */
   2637 	 FALSE,			/* partial_inplace */
   2638 	 0,			/* src_mask */
   2639 	 0x0000ffff,		/* dst_mask */
   2640 	 FALSE),		/* pcrel_offset */
   2641 
   2642   /* High 16 bits of displacement in global offset table.  */
   2643   HOWTO (R_MICROMIPS_GOT_HI16,	/* type */
   2644 	 0,			/* rightshift */
   2645 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2646 	 16,			/* bitsize */
   2647 	 FALSE,			/* pc_relative */
   2648 	 0,			/* bitpos */
   2649 	 complain_overflow_dont, /* complain_on_overflow */
   2650 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2651 	 "R_MICROMIPS_GOT_HI16",/* name */
   2652 	 FALSE,			/* partial_inplace */
   2653 	 0,			/* src_mask */
   2654 	 0x0000ffff,		/* dst_mask */
   2655 	 FALSE),		/* pcrel_offset */
   2656 
   2657   /* Low 16 bits of displacement in global offset table.  */
   2658   HOWTO (R_MICROMIPS_GOT_LO16,	/* type */
   2659 	 0,			/* rightshift */
   2660 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2661 	 16,			/* bitsize */
   2662 	 FALSE,			/* pc_relative */
   2663 	 0,			/* bitpos */
   2664 	 complain_overflow_dont, /* complain_on_overflow */
   2665 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2666 	 "R_MICROMIPS_GOT_LO16",/* name */
   2667 	 FALSE,			/* partial_inplace */
   2668 	 0,			/* src_mask */
   2669 	 0x0000ffff,		/* dst_mask */
   2670 	 FALSE),		/* pcrel_offset */
   2671 
   2672   /* 64 bit subtraction.  Used in the N32 ABI.  */
   2673   HOWTO (R_MICROMIPS_SUB,	/* type */
   2674 	 0,			/* rightshift */
   2675 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
   2676 	 64,			/* bitsize */
   2677 	 FALSE,			/* pc_relative */
   2678 	 0,			/* bitpos */
   2679 	 complain_overflow_dont, /* complain_on_overflow */
   2680 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2681 	 "R_MICROMIPS_SUB",	/* name */
   2682 	 FALSE,			/* partial_inplace */
   2683 	 0,			/* src_mask */
   2684 	 MINUS_ONE,		/* dst_mask */
   2685 	 FALSE),		/* pcrel_offset */
   2686 
   2687   /* Get the higher value of a 64 bit addend.  */
   2688   HOWTO (R_MICROMIPS_HIGHER,	/* type */
   2689 	 0,			/* rightshift */
   2690 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2691 	 16,			/* bitsize */
   2692 	 FALSE,			/* pc_relative */
   2693 	 0,			/* bitpos */
   2694 	 complain_overflow_dont, /* complain_on_overflow */
   2695 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2696 	 "R_MICROMIPS_HIGHER",	/* name */
   2697 	 FALSE,			/* partial_inplace */
   2698 	 0,			/* src_mask */
   2699 	 0x0000ffff,		/* dst_mask */
   2700 	 FALSE),		/* pcrel_offset */
   2701 
   2702   /* Get the highest value of a 64 bit addend.  */
   2703   HOWTO (R_MICROMIPS_HIGHEST,	/* type */
   2704 	 0,			/* rightshift */
   2705 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2706 	 16,			/* bitsize */
   2707 	 FALSE,			/* pc_relative */
   2708 	 0,			/* bitpos */
   2709 	 complain_overflow_dont, /* complain_on_overflow */
   2710 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2711 	 "R_MICROMIPS_HIGHEST",	/* name */
   2712 	 FALSE,			/* partial_inplace */
   2713 	 0,			/* src_mask */
   2714 	 0x0000ffff,		/* dst_mask */
   2715 	 FALSE),		/* pcrel_offset */
   2716 
   2717   /* High 16 bits of displacement in global offset table.  */
   2718   HOWTO (R_MICROMIPS_CALL_HI16,	/* type */
   2719 	 0,			/* rightshift */
   2720 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2721 	 16,			/* bitsize */
   2722 	 FALSE,			/* pc_relative */
   2723 	 0,			/* bitpos */
   2724 	 complain_overflow_dont, /* complain_on_overflow */
   2725 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2726 	 "R_MICROMIPS_CALL_HI16",/* name */
   2727 	 FALSE,			/* partial_inplace */
   2728 	 0,			/* src_mask */
   2729 	 0x0000ffff,		/* dst_mask */
   2730 	 FALSE),		/* pcrel_offset */
   2731 
   2732   /* Low 16 bits of displacement in global offset table.  */
   2733   HOWTO (R_MICROMIPS_CALL_LO16,	/* type */
   2734 	 0,			/* rightshift */
   2735 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2736 	 16,			/* bitsize */
   2737 	 FALSE,			/* pc_relative */
   2738 	 0,			/* bitpos */
   2739 	 complain_overflow_dont, /* complain_on_overflow */
   2740 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2741 	 "R_MICROMIPS_CALL_LO16",/* name */
   2742 	 FALSE,			/* partial_inplace */
   2743 	 0,			/* src_mask */
   2744 	 0x0000ffff,		/* dst_mask */
   2745 	 FALSE),		/* pcrel_offset */
   2746 
   2747   /* Section displacement.  */
   2748   HOWTO (R_MICROMIPS_SCN_DISP,  /* type */
   2749 	 0,			/* rightshift */
   2750 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2751 	 32,			/* bitsize */
   2752 	 FALSE,			/* pc_relative */
   2753 	 0,			/* bitpos */
   2754 	 complain_overflow_dont, /* complain_on_overflow */
   2755 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2756 	 "R_MICROMIPS_SCN_DISP", /* name */
   2757 	 FALSE,			/* partial_inplace */
   2758 	 0,			/* src_mask */
   2759 	 0xffffffff,		/* dst_mask */
   2760 	 FALSE),		/* pcrel_offset */
   2761 
   2762   /* Protected jump conversion.  This is an optimization hint.  No
   2763      relocation is required for correctness.  */
   2764   HOWTO (R_MICROMIPS_JALR,	/* type */
   2765 	 0,			/* rightshift */
   2766 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2767 	 32,			/* bitsize */
   2768 	 FALSE,			/* pc_relative */
   2769 	 0,			/* bitpos */
   2770 	 complain_overflow_dont, /* complain_on_overflow */
   2771 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2772 	 "R_MICROMIPS_JALR",	/* name */
   2773 	 FALSE,			/* partial_inplace */
   2774 	 0,			/* src_mask */
   2775 	 0x00000000,		/* dst_mask */
   2776 	 FALSE),		/* pcrel_offset */
   2777 };
   2778 
   2779 /* GNU extension to record C++ vtable hierarchy */
   2780 static reloc_howto_type elf_mips_gnu_vtinherit_howto =
   2781   HOWTO (R_MIPS_GNU_VTINHERIT,	/* type */
   2782 	 0,			/* rightshift */
   2783 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2784 	 0,			/* bitsize */
   2785 	 FALSE,			/* pc_relative */
   2786 	 0,			/* bitpos */
   2787 	 complain_overflow_dont, /* complain_on_overflow */
   2788 	 NULL,			/* special_function */
   2789 	 "R_MIPS_GNU_VTINHERIT", /* name */
   2790 	 FALSE,			/* partial_inplace */
   2791 	 0,			/* src_mask */
   2792 	 0,			/* dst_mask */
   2793 	 FALSE);		/* pcrel_offset */
   2794 
   2795 /* GNU extension to record C++ vtable member usage */
   2796 static reloc_howto_type elf_mips_gnu_vtentry_howto =
   2797   HOWTO (R_MIPS_GNU_VTENTRY,	/* type */
   2798 	 0,			/* rightshift */
   2799 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2800 	 0,			/* bitsize */
   2801 	 FALSE,			/* pc_relative */
   2802 	 0,			/* bitpos */
   2803 	 complain_overflow_dont, /* complain_on_overflow */
   2804 	 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
   2805 	 "R_MIPS_GNU_VTENTRY",	/* name */
   2806 	 FALSE,			/* partial_inplace */
   2807 	 0,			/* src_mask */
   2808 	 0,			/* dst_mask */
   2809 	 FALSE);		/* pcrel_offset */
   2810 
   2811 /* 16 bit offset for pc-relative branches.  */
   2813 static reloc_howto_type elf_mips_gnu_rel16_s2 =
   2814   HOWTO (R_MIPS_GNU_REL16_S2,	/* type */
   2815 	 2,			/* rightshift */
   2816 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2817 	 16,			/* bitsize */
   2818 	 TRUE,			/* pc_relative */
   2819 	 0,			/* bitpos */
   2820 	 complain_overflow_signed, /* complain_on_overflow */
   2821 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   2822 	 "R_MIPS_GNU_REL16_S2",	/* name */
   2823 	 TRUE,			/* partial_inplace */
   2824 	 0x0000ffff,		/* src_mask */
   2825 	 0x0000ffff,		/* dst_mask */
   2826 	 TRUE);			/* pcrel_offset */
   2827 
   2828 /* 16 bit offset for pc-relative branches.  */
   2829 static reloc_howto_type elf_mips_gnu_rela16_s2 =
   2830   HOWTO (R_MIPS_GNU_REL16_S2,	/* type */
   2831 	 2,			/* rightshift */
   2832 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2833 	 16,			/* bitsize */
   2834 	 TRUE,			/* pc_relative */
   2835 	 0,			/* bitpos */
   2836 	 complain_overflow_signed, /* complain_on_overflow */
   2837 	 _bfd_mips_elf_generic_reloc,	/* special_function */
   2838 	 "R_MIPS_GNU_REL16_S2",	/* name */
   2839 	 FALSE,			/* partial_inplace */
   2840 	 0,			/* src_mask */
   2841 	 0x0000ffff,		/* dst_mask */
   2842 	 TRUE);			/* pcrel_offset */
   2843 
   2844 /* 32 bit pc-relative.  Used for compact EH tables.  */
   2845 static reloc_howto_type elf_mips_gnu_pcrel32 =
   2846   HOWTO (R_MIPS_PC32,		/* type */
   2847 	 0,			/* rightshift */
   2848 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2849 	 32,			/* bitsize */
   2850 	 TRUE,			/* pc_relative */
   2851 	 0,			/* bitpos */
   2852 	 complain_overflow_signed, /* complain_on_overflow */
   2853 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2854 	 "R_MIPS_PC32",		/* name */
   2855 	 TRUE,			/* partial_inplace */
   2856 	 0xffffffff,		/* src_mask */
   2857 	 0xffffffff,		/* dst_mask */
   2858 	 TRUE);			/* pcrel_offset */
   2859 
   2860 
   2861 /* Originally a VxWorks extension, but now used for other systems too.  */
   2863 static reloc_howto_type elf_mips_copy_howto =
   2864   HOWTO (R_MIPS_COPY,		/* type */
   2865 	 0,			/* rightshift */
   2866 	 0,			/* this one is variable size */
   2867 	 0,			/* bitsize */
   2868 	 FALSE,			/* pc_relative */
   2869 	 0,			/* bitpos */
   2870 	 complain_overflow_bitfield, /* complain_on_overflow */
   2871 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2872 	 "R_MIPS_COPY",		/* name */
   2873 	 FALSE,			/* partial_inplace */
   2874 	 0x0,         		/* src_mask */
   2875 	 0x0,		        /* dst_mask */
   2876 	 FALSE);		/* pcrel_offset */
   2877 
   2878 /* Originally a VxWorks extension, but now used for other systems too.  */
   2879 static reloc_howto_type elf_mips_jump_slot_howto =
   2880   HOWTO (R_MIPS_JUMP_SLOT,	/* type */
   2881 	 0,			/* rightshift */
   2882 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
   2883 	 64,			/* bitsize */
   2884 	 FALSE,			/* pc_relative */
   2885 	 0,			/* bitpos */
   2886 	 complain_overflow_bitfield, /* complain_on_overflow */
   2887 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2888 	 "R_MIPS_JUMP_SLOT",	/* name */
   2889 	 FALSE,			/* partial_inplace */
   2890 	 0x0,         		/* src_mask */
   2891 	 0x0,		        /* dst_mask */
   2892 	 FALSE);		/* pcrel_offset */
   2893 
   2894 /* Used in EH tables.  */
   2895 static reloc_howto_type elf_mips_eh_howto =
   2896   HOWTO (R_MIPS_EH,		/* type */
   2897 	 0,			/* rightshift */
   2898 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   2899 	 32,			/* bitsize */
   2900 	 FALSE,			/* pc_relative */
   2901 	 0,			/* bitpos */
   2902 	 complain_overflow_signed, /* complain_on_overflow */
   2903 	 _bfd_mips_elf_generic_reloc, /* special_function */
   2904 	 "R_MIPS_EH",		/* name */
   2905 	 TRUE,			/* partial_inplace */
   2906 	 0xffffffff,		/* src_mask */
   2907 	 0xffffffff,	        /* dst_mask */
   2908 	 FALSE);		/* pcrel_offset */
   2909 
   2910 
   2911 /* Swap in a MIPS 64-bit Rel reloc.  */
   2913 
   2914 static void
   2915 mips_elf64_swap_reloc_in (bfd *abfd, const Elf64_Mips_External_Rel *src,
   2916 			  Elf64_Mips_Internal_Rela *dst)
   2917 {
   2918   dst->r_offset = H_GET_64 (abfd, src->r_offset);
   2919   dst->r_sym = H_GET_32 (abfd, src->r_sym);
   2920   dst->r_ssym = H_GET_8 (abfd, src->r_ssym);
   2921   dst->r_type3 = H_GET_8 (abfd, src->r_type3);
   2922   dst->r_type2 = H_GET_8 (abfd, src->r_type2);
   2923   dst->r_type = H_GET_8 (abfd, src->r_type);
   2924   dst->r_addend = 0;
   2925 }
   2926 
   2927 /* Swap in a MIPS 64-bit Rela reloc.  */
   2928 
   2929 static void
   2930 mips_elf64_swap_reloca_in (bfd *abfd, const Elf64_Mips_External_Rela *src,
   2931 			   Elf64_Mips_Internal_Rela *dst)
   2932 {
   2933   dst->r_offset = H_GET_64 (abfd, src->r_offset);
   2934   dst->r_sym = H_GET_32 (abfd, src->r_sym);
   2935   dst->r_ssym = H_GET_8 (abfd, src->r_ssym);
   2936   dst->r_type3 = H_GET_8 (abfd, src->r_type3);
   2937   dst->r_type2 = H_GET_8 (abfd, src->r_type2);
   2938   dst->r_type = H_GET_8 (abfd, src->r_type);
   2939   dst->r_addend = H_GET_S64 (abfd, src->r_addend);
   2940 }
   2941 
   2942 /* Swap out a MIPS 64-bit Rel reloc.  */
   2943 
   2944 static void
   2945 mips_elf64_swap_reloc_out (bfd *abfd, const Elf64_Mips_Internal_Rela *src,
   2946 			   Elf64_Mips_External_Rel *dst)
   2947 {
   2948   H_PUT_64 (abfd, src->r_offset, dst->r_offset);
   2949   H_PUT_32 (abfd, src->r_sym, dst->r_sym);
   2950   H_PUT_8 (abfd, src->r_ssym, dst->r_ssym);
   2951   H_PUT_8 (abfd, src->r_type3, dst->r_type3);
   2952   H_PUT_8 (abfd, src->r_type2, dst->r_type2);
   2953   H_PUT_8 (abfd, src->r_type, dst->r_type);
   2954 }
   2955 
   2956 /* Swap out a MIPS 64-bit Rela reloc.  */
   2957 
   2958 static void
   2959 mips_elf64_swap_reloca_out (bfd *abfd, const Elf64_Mips_Internal_Rela *src,
   2960 			    Elf64_Mips_External_Rela *dst)
   2961 {
   2962   H_PUT_64 (abfd, src->r_offset, dst->r_offset);
   2963   H_PUT_32 (abfd, src->r_sym, dst->r_sym);
   2964   H_PUT_8 (abfd, src->r_ssym, dst->r_ssym);
   2965   H_PUT_8 (abfd, src->r_type3, dst->r_type3);
   2966   H_PUT_8 (abfd, src->r_type2, dst->r_type2);
   2967   H_PUT_8 (abfd, src->r_type, dst->r_type);
   2968   H_PUT_S64 (abfd, src->r_addend, dst->r_addend);
   2969 }
   2970 
   2971 /* Swap in a MIPS 64-bit Rel reloc.  */
   2972 
   2973 static void
   2974 mips_elf64_be_swap_reloc_in (bfd *abfd, const bfd_byte *src,
   2975 			     Elf_Internal_Rela *dst)
   2976 {
   2977   Elf64_Mips_Internal_Rela mirel;
   2978 
   2979   mips_elf64_swap_reloc_in (abfd,
   2980 			    (const Elf64_Mips_External_Rel *) src,
   2981 			    &mirel);
   2982 
   2983   dst[0].r_offset = mirel.r_offset;
   2984   dst[0].r_info = ELF64_R_INFO (mirel.r_sym, mirel.r_type);
   2985   dst[0].r_addend = 0;
   2986   dst[1].r_offset = mirel.r_offset;
   2987   dst[1].r_info = ELF64_R_INFO (mirel.r_ssym, mirel.r_type2);
   2988   dst[1].r_addend = 0;
   2989   dst[2].r_offset = mirel.r_offset;
   2990   dst[2].r_info = ELF64_R_INFO (STN_UNDEF, mirel.r_type3);
   2991   dst[2].r_addend = 0;
   2992 }
   2993 
   2994 /* Swap in a MIPS 64-bit Rela reloc.  */
   2995 
   2996 static void
   2997 mips_elf64_be_swap_reloca_in (bfd *abfd, const bfd_byte *src,
   2998 			      Elf_Internal_Rela *dst)
   2999 {
   3000   Elf64_Mips_Internal_Rela mirela;
   3001 
   3002   mips_elf64_swap_reloca_in (abfd,
   3003 			     (const Elf64_Mips_External_Rela *) src,
   3004 			     &mirela);
   3005 
   3006   dst[0].r_offset = mirela.r_offset;
   3007   dst[0].r_info = ELF64_R_INFO (mirela.r_sym, mirela.r_type);
   3008   dst[0].r_addend = mirela.r_addend;
   3009   dst[1].r_offset = mirela.r_offset;
   3010   dst[1].r_info = ELF64_R_INFO (mirela.r_ssym, mirela.r_type2);
   3011   dst[1].r_addend = 0;
   3012   dst[2].r_offset = mirela.r_offset;
   3013   dst[2].r_info = ELF64_R_INFO (STN_UNDEF, mirela.r_type3);
   3014   dst[2].r_addend = 0;
   3015 }
   3016 
   3017 /* Swap out a MIPS 64-bit Rel reloc.  */
   3018 
   3019 static void
   3020 mips_elf64_be_swap_reloc_out (bfd *abfd, const Elf_Internal_Rela *src,
   3021 			      bfd_byte *dst)
   3022 {
   3023   Elf64_Mips_Internal_Rela mirel;
   3024 
   3025   mirel.r_offset = src[0].r_offset;
   3026   BFD_ASSERT(src[0].r_offset == src[1].r_offset);
   3027   BFD_ASSERT(src[0].r_offset == src[2].r_offset);
   3028 
   3029   mirel.r_type = ELF64_MIPS_R_TYPE (src[0].r_info);
   3030   mirel.r_sym = ELF64_R_SYM (src[0].r_info);
   3031   mirel.r_type2 = ELF64_MIPS_R_TYPE (src[1].r_info);
   3032   mirel.r_ssym = ELF64_MIPS_R_SSYM (src[1].r_info);
   3033   mirel.r_type3 = ELF64_MIPS_R_TYPE (src[2].r_info);
   3034 
   3035   mips_elf64_swap_reloc_out (abfd, &mirel,
   3036 			     (Elf64_Mips_External_Rel *) dst);
   3037 }
   3038 
   3039 /* Swap out a MIPS 64-bit Rela reloc.  */
   3040 
   3041 static void
   3042 mips_elf64_be_swap_reloca_out (bfd *abfd, const Elf_Internal_Rela *src,
   3043 			       bfd_byte *dst)
   3044 {
   3045   Elf64_Mips_Internal_Rela mirela;
   3046 
   3047   mirela.r_offset = src[0].r_offset;
   3048   BFD_ASSERT(src[0].r_offset == src[1].r_offset);
   3049   BFD_ASSERT(src[0].r_offset == src[2].r_offset);
   3050 
   3051   mirela.r_type = ELF64_MIPS_R_TYPE (src[0].r_info);
   3052   mirela.r_sym = ELF64_R_SYM (src[0].r_info);
   3053   mirela.r_addend = src[0].r_addend;
   3054   BFD_ASSERT(src[1].r_addend == 0);
   3055   BFD_ASSERT(src[2].r_addend == 0);
   3056 
   3057   mirela.r_type2 = ELF64_MIPS_R_TYPE (src[1].r_info);
   3058   mirela.r_ssym = ELF64_MIPS_R_SSYM (src[1].r_info);
   3059   mirela.r_type3 = ELF64_MIPS_R_TYPE (src[2].r_info);
   3060 
   3061   mips_elf64_swap_reloca_out (abfd, &mirela,
   3062 			      (Elf64_Mips_External_Rela *) dst);
   3063 }
   3064 
   3065 /* Set the GP value for OUTPUT_BFD.  Returns FALSE if this is a
   3067    dangerous relocation.  */
   3068 
   3069 static bfd_boolean
   3070 mips_elf64_assign_gp (bfd *output_bfd, bfd_vma *pgp)
   3071 {
   3072   unsigned int count;
   3073   asymbol **sym;
   3074   unsigned int i;
   3075 
   3076   /* If we've already figured out what GP will be, just return it.  */
   3077   *pgp = _bfd_get_gp_value (output_bfd);
   3078   if (*pgp)
   3079     return TRUE;
   3080 
   3081   count = bfd_get_symcount (output_bfd);
   3082   sym = bfd_get_outsymbols (output_bfd);
   3083 
   3084   /* The linker script will have created a symbol named `_gp' with the
   3085      appropriate value.  */
   3086   if (sym == NULL)
   3087     i = count;
   3088   else
   3089     {
   3090       for (i = 0; i < count; i++, sym++)
   3091 	{
   3092 	  register const char *name;
   3093 
   3094 	  name = bfd_asymbol_name (*sym);
   3095 	  if (*name == '_' && strcmp (name, "_gp") == 0)
   3096 	    {
   3097 	      *pgp = bfd_asymbol_value (*sym);
   3098 	      _bfd_set_gp_value (output_bfd, *pgp);
   3099 	      break;
   3100 	    }
   3101 	}
   3102     }
   3103 
   3104   if (i >= count)
   3105     {
   3106       /* Only get the error once.  */
   3107       *pgp = 4;
   3108       _bfd_set_gp_value (output_bfd, *pgp);
   3109       return FALSE;
   3110     }
   3111 
   3112   return TRUE;
   3113 }
   3114 
   3115 /* We have to figure out the gp value, so that we can adjust the
   3116    symbol value correctly.  We look up the symbol _gp in the output
   3117    BFD.  If we can't find it, we're stuck.  We cache it in the ELF
   3118    target data.  We don't need to adjust the symbol value for an
   3119    external symbol if we are producing relocatable output.  */
   3120 
   3121 static bfd_reloc_status_type
   3122 mips_elf64_final_gp (bfd *output_bfd, asymbol *symbol, bfd_boolean relocatable,
   3123 		     char **error_message, bfd_vma *pgp)
   3124 {
   3125   if (bfd_is_und_section (symbol->section)
   3126       && ! relocatable)
   3127     {
   3128       *pgp = 0;
   3129       return bfd_reloc_undefined;
   3130     }
   3131 
   3132   *pgp = _bfd_get_gp_value (output_bfd);
   3133   if (*pgp == 0
   3134       && (! relocatable
   3135 	  || (symbol->flags & BSF_SECTION_SYM) != 0))
   3136     {
   3137       if (relocatable)
   3138 	{
   3139 	  /* Make up a value.  */
   3140 	  *pgp = symbol->section->output_section->vma /*+ 0x4000*/;
   3141 	  _bfd_set_gp_value (output_bfd, *pgp);
   3142 	}
   3143       else if (!mips_elf64_assign_gp (output_bfd, pgp))
   3144 	{
   3145 	  *error_message =
   3146 	    (char *) _("GP relative relocation when _gp not defined");
   3147 	  return bfd_reloc_dangerous;
   3148 	}
   3149     }
   3150 
   3151   return bfd_reloc_ok;
   3152 }
   3153 
   3154 /* Do a R_MIPS_GPREL16 relocation.  This is a 16 bit value which must
   3155    become the offset from the gp register.  */
   3156 
   3157 static bfd_reloc_status_type
   3158 mips_elf64_gprel16_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   3159 			  void *data, asection *input_section, bfd *output_bfd,
   3160 			  char **error_message)
   3161 {
   3162   bfd_boolean relocatable;
   3163   bfd_reloc_status_type ret;
   3164   bfd_vma gp;
   3165 
   3166   /* If we're relocating, and this is an external symbol, we don't want
   3167      to change anything.  */
   3168   if (output_bfd != NULL
   3169       && (symbol->flags & BSF_SECTION_SYM) == 0
   3170       && (symbol->flags & BSF_LOCAL) != 0)
   3171     {
   3172       reloc_entry->address += input_section->output_offset;
   3173       return bfd_reloc_ok;
   3174     }
   3175 
   3176   if (output_bfd != NULL)
   3177     relocatable = TRUE;
   3178   else
   3179     {
   3180       relocatable = FALSE;
   3181       output_bfd = symbol->section->output_section->owner;
   3182     }
   3183 
   3184   ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message,
   3185 			     &gp);
   3186   if (ret != bfd_reloc_ok)
   3187     return ret;
   3188 
   3189   return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
   3190 					input_section, relocatable,
   3191 					data, gp);
   3192 }
   3193 
   3194 /* Do a R_MIPS_LITERAL relocation.  */
   3195 
   3196 static bfd_reloc_status_type
   3197 mips_elf64_literal_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   3198 			  void *data, asection *input_section, bfd *output_bfd,
   3199 			  char **error_message)
   3200 {
   3201   bfd_boolean relocatable;
   3202   bfd_reloc_status_type ret;
   3203   bfd_vma gp;
   3204 
   3205   /* R_MIPS_LITERAL relocations are defined for local symbols only.  */
   3206   if (output_bfd != NULL
   3207       && (symbol->flags & BSF_SECTION_SYM) == 0
   3208       && (symbol->flags & BSF_LOCAL) != 0)
   3209     {
   3210       *error_message = (char *)
   3211 	_("literal relocation occurs for an external symbol");
   3212       return bfd_reloc_outofrange;
   3213     }
   3214 
   3215   /* FIXME: The entries in the .lit8 and .lit4 sections should be merged.  */
   3216   if (output_bfd != NULL)
   3217     relocatable = TRUE;
   3218   else
   3219     {
   3220       relocatable = FALSE;
   3221       output_bfd = symbol->section->output_section->owner;
   3222     }
   3223 
   3224   ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message,
   3225 			     &gp);
   3226   if (ret != bfd_reloc_ok)
   3227     return ret;
   3228 
   3229   return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
   3230 					input_section, relocatable,
   3231 					data, gp);
   3232 }
   3233 
   3234 /* Do a R_MIPS_GPREL32 relocation.  This is a 32 bit value which must
   3235    become the offset from the gp register.  */
   3236 
   3237 static bfd_reloc_status_type
   3238 mips_elf64_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   3239 			  void *data, asection *input_section, bfd *output_bfd,
   3240 			  char **error_message)
   3241 {
   3242   bfd_boolean relocatable;
   3243   bfd_reloc_status_type ret;
   3244   bfd_vma gp;
   3245   bfd_vma relocation;
   3246   bfd_vma val;
   3247 
   3248   /* R_MIPS_GPREL32 relocations are defined for local symbols only.  */
   3249   if (output_bfd != NULL
   3250       && (symbol->flags & BSF_SECTION_SYM) == 0
   3251       && (symbol->flags & BSF_LOCAL) != 0)
   3252     {
   3253       *error_message = (char *)
   3254 	_("32bits gp relative relocation occurs for an external symbol");
   3255       return bfd_reloc_outofrange;
   3256     }
   3257 
   3258   if (output_bfd != NULL)
   3259     relocatable = TRUE;
   3260   else
   3261     {
   3262       relocatable = FALSE;
   3263       output_bfd = symbol->section->output_section->owner;
   3264     }
   3265 
   3266   ret = mips_elf64_final_gp (output_bfd, symbol, relocatable,
   3267 			     error_message, &gp);
   3268   if (ret != bfd_reloc_ok)
   3269     return ret;
   3270 
   3271   if (bfd_is_com_section (symbol->section))
   3272     relocation = 0;
   3273   else
   3274     relocation = symbol->value;
   3275 
   3276   relocation += symbol->section->output_section->vma;
   3277   relocation += symbol->section->output_offset;
   3278 
   3279   if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
   3280     return bfd_reloc_outofrange;
   3281 
   3282   /* Set val to the offset into the section or symbol.  */
   3283   val = reloc_entry->addend;
   3284 
   3285   if (reloc_entry->howto->partial_inplace)
   3286     val += bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
   3287 
   3288   /* Adjust val for the final section location and GP value.  If we
   3289      are producing relocatable output, we don't want to do this for
   3290      an external symbol.  */
   3291   if (! relocatable
   3292       || (symbol->flags & BSF_SECTION_SYM) != 0)
   3293     val += relocation - gp;
   3294 
   3295   if (reloc_entry->howto->partial_inplace)
   3296     bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
   3297   else
   3298     reloc_entry->addend = val;
   3299 
   3300   if (relocatable)
   3301     reloc_entry->address += input_section->output_offset;
   3302 
   3303   return bfd_reloc_ok;
   3304 }
   3305 
   3306 /* Do a R_MIPS_SHIFT6 relocation. The MSB of the shift is stored at bit 2,
   3307    the rest is at bits 6-10. The bitpos already got right by the howto.  */
   3308 
   3309 static bfd_reloc_status_type
   3310 mips_elf64_shift6_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   3311 			 void *data, asection *input_section, bfd *output_bfd,
   3312 			 char **error_message)
   3313 {
   3314   if (reloc_entry->howto->partial_inplace)
   3315     {
   3316       reloc_entry->addend = ((reloc_entry->addend & 0x00007c0)
   3317 			     | (reloc_entry->addend & 0x00000800) >> 9);
   3318     }
   3319 
   3320   return _bfd_mips_elf_generic_reloc (abfd, reloc_entry, symbol, data,
   3321 				      input_section, output_bfd,
   3322 				      error_message);
   3323 }
   3324 
   3325 /* Handle a mips16 GP relative reloc.  */
   3326 
   3327 static bfd_reloc_status_type
   3328 mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   3329 		    void *data, asection *input_section, bfd *output_bfd,
   3330 		    char **error_message)
   3331 {
   3332   bfd_boolean relocatable;
   3333   bfd_reloc_status_type ret;
   3334   bfd_byte *location;
   3335   bfd_vma gp;
   3336 
   3337   /* If we're relocating, and this is an external symbol, we don't want
   3338      to change anything.  */
   3339   if (output_bfd != NULL
   3340       && (symbol->flags & BSF_SECTION_SYM) == 0
   3341       && (symbol->flags & BSF_LOCAL) != 0)
   3342     {
   3343       reloc_entry->address += input_section->output_offset;
   3344       return bfd_reloc_ok;
   3345     }
   3346 
   3347   if (output_bfd != NULL)
   3348     relocatable = TRUE;
   3349   else
   3350     {
   3351       relocatable = FALSE;
   3352       output_bfd = symbol->section->output_section->owner;
   3353     }
   3354 
   3355   ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message,
   3356 			     &gp);
   3357   if (ret != bfd_reloc_ok)
   3358     return ret;
   3359 
   3360   location = (bfd_byte *) data + reloc_entry->address;
   3361   _bfd_mips_elf_reloc_unshuffle (abfd, reloc_entry->howto->type, FALSE,
   3362 				 location);
   3363   ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
   3364 				       input_section, relocatable,
   3365 				       data, gp);
   3366   _bfd_mips_elf_reloc_shuffle (abfd, reloc_entry->howto->type, !relocatable,
   3367 			       location);
   3368 
   3369   return ret;
   3370 }
   3371 
   3372 /* A mapping from BFD reloc types to MIPS ELF reloc types.  */
   3374 
   3375 struct elf_reloc_map {
   3376   bfd_reloc_code_real_type bfd_val;
   3377   enum elf_mips_reloc_type elf_val;
   3378 };
   3379 
   3380 static const struct elf_reloc_map mips_reloc_map[] =
   3381 {
   3382   { BFD_RELOC_NONE, R_MIPS_NONE },
   3383   { BFD_RELOC_16, R_MIPS_16 },
   3384   { BFD_RELOC_32, R_MIPS_32 },
   3385   /* There is no BFD reloc for R_MIPS_REL32.  */
   3386   { BFD_RELOC_64, R_MIPS_64 },
   3387   { BFD_RELOC_CTOR, R_MIPS_64 },
   3388   { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
   3389   { BFD_RELOC_HI16_S, R_MIPS_HI16 },
   3390   { BFD_RELOC_LO16, R_MIPS_LO16 },
   3391   { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
   3392   { BFD_RELOC_GPREL32, R_MIPS_GPREL32 },
   3393   { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
   3394   { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
   3395   { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
   3396   { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
   3397   { BFD_RELOC_MIPS_SHIFT5, R_MIPS_SHIFT5 },
   3398   { BFD_RELOC_MIPS_SHIFT6, R_MIPS_SHIFT6 },
   3399   { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP },
   3400   { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
   3401   { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
   3402   { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
   3403   { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
   3404   { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
   3405   { BFD_RELOC_MIPS_INSERT_A, R_MIPS_INSERT_A },
   3406   { BFD_RELOC_MIPS_INSERT_B, R_MIPS_INSERT_B },
   3407   { BFD_RELOC_MIPS_DELETE, R_MIPS_DELETE },
   3408   { BFD_RELOC_MIPS_HIGHEST, R_MIPS_HIGHEST },
   3409   { BFD_RELOC_MIPS_HIGHER, R_MIPS_HIGHER },
   3410   { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
   3411   { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
   3412   { BFD_RELOC_MIPS_SCN_DISP, R_MIPS_SCN_DISP },
   3413   { BFD_RELOC_MIPS_REL16, R_MIPS_REL16 },
   3414   /* Use of R_MIPS_ADD_IMMEDIATE and R_MIPS_PJUMP is deprecated.  */
   3415   { BFD_RELOC_MIPS_RELGOT, R_MIPS_RELGOT },
   3416   { BFD_RELOC_MIPS_JALR, R_MIPS_JALR },
   3417   { BFD_RELOC_MIPS_TLS_DTPMOD32, R_MIPS_TLS_DTPMOD32 },
   3418   { BFD_RELOC_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL32 },
   3419   { BFD_RELOC_MIPS_TLS_DTPMOD64, R_MIPS_TLS_DTPMOD64 },
   3420   { BFD_RELOC_MIPS_TLS_DTPREL64, R_MIPS_TLS_DTPREL64 },
   3421   { BFD_RELOC_MIPS_TLS_GD, R_MIPS_TLS_GD },
   3422   { BFD_RELOC_MIPS_TLS_LDM, R_MIPS_TLS_LDM },
   3423   { BFD_RELOC_MIPS_TLS_DTPREL_HI16, R_MIPS_TLS_DTPREL_HI16 },
   3424   { BFD_RELOC_MIPS_TLS_DTPREL_LO16, R_MIPS_TLS_DTPREL_LO16 },
   3425   { BFD_RELOC_MIPS_TLS_GOTTPREL, R_MIPS_TLS_GOTTPREL },
   3426   { BFD_RELOC_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL32 },
   3427   { BFD_RELOC_MIPS_TLS_TPREL64, R_MIPS_TLS_TPREL64 },
   3428   { BFD_RELOC_MIPS_TLS_TPREL_HI16, R_MIPS_TLS_TPREL_HI16 },
   3429   { BFD_RELOC_MIPS_TLS_TPREL_LO16, R_MIPS_TLS_TPREL_LO16 },
   3430   { BFD_RELOC_MIPS_21_PCREL_S2, R_MIPS_PC21_S2 },
   3431   { BFD_RELOC_MIPS_26_PCREL_S2, R_MIPS_PC26_S2 },
   3432   { BFD_RELOC_MIPS_18_PCREL_S3, R_MIPS_PC18_S3 },
   3433   { BFD_RELOC_MIPS_19_PCREL_S2, R_MIPS_PC19_S2 },
   3434   { BFD_RELOC_HI16_S_PCREL, R_MIPS_PCHI16 },
   3435   { BFD_RELOC_LO16_PCREL, R_MIPS_PCLO16 }
   3436 };
   3437 
   3438 static const struct elf_reloc_map mips16_reloc_map[] =
   3439 {
   3440   { BFD_RELOC_MIPS16_JMP, R_MIPS16_26 - R_MIPS16_min },
   3441   { BFD_RELOC_MIPS16_GPREL, R_MIPS16_GPREL - R_MIPS16_min },
   3442   { BFD_RELOC_MIPS16_GOT16, R_MIPS16_GOT16 - R_MIPS16_min },
   3443   { BFD_RELOC_MIPS16_CALL16, R_MIPS16_CALL16 - R_MIPS16_min },
   3444   { BFD_RELOC_MIPS16_HI16_S, R_MIPS16_HI16 - R_MIPS16_min },
   3445   { BFD_RELOC_MIPS16_LO16, R_MIPS16_LO16 - R_MIPS16_min },
   3446   { BFD_RELOC_MIPS16_TLS_GD, R_MIPS16_TLS_GD - R_MIPS16_min },
   3447   { BFD_RELOC_MIPS16_TLS_LDM, R_MIPS16_TLS_LDM - R_MIPS16_min },
   3448   { BFD_RELOC_MIPS16_TLS_DTPREL_HI16,
   3449     R_MIPS16_TLS_DTPREL_HI16 - R_MIPS16_min },
   3450   { BFD_RELOC_MIPS16_TLS_DTPREL_LO16,
   3451     R_MIPS16_TLS_DTPREL_LO16 - R_MIPS16_min },
   3452   { BFD_RELOC_MIPS16_TLS_GOTTPREL, R_MIPS16_TLS_GOTTPREL - R_MIPS16_min },
   3453   { BFD_RELOC_MIPS16_TLS_TPREL_HI16, R_MIPS16_TLS_TPREL_HI16 - R_MIPS16_min },
   3454   { BFD_RELOC_MIPS16_TLS_TPREL_LO16, R_MIPS16_TLS_TPREL_LO16 - R_MIPS16_min },
   3455   { BFD_RELOC_MIPS16_16_PCREL_S1, R_MIPS16_PC16_S1 - R_MIPS16_min }
   3456 };
   3457 
   3458 static const struct elf_reloc_map micromips_reloc_map[] =
   3459 {
   3460   { BFD_RELOC_MICROMIPS_JMP, R_MICROMIPS_26_S1 - R_MICROMIPS_min },
   3461   { BFD_RELOC_MICROMIPS_HI16_S, R_MICROMIPS_HI16 - R_MICROMIPS_min },
   3462   { BFD_RELOC_MICROMIPS_LO16, R_MICROMIPS_LO16 - R_MICROMIPS_min },
   3463   { BFD_RELOC_MICROMIPS_GPREL16, R_MICROMIPS_GPREL16 - R_MICROMIPS_min },
   3464   { BFD_RELOC_MICROMIPS_LITERAL, R_MICROMIPS_LITERAL - R_MICROMIPS_min },
   3465   { BFD_RELOC_MICROMIPS_GOT16, R_MICROMIPS_GOT16 - R_MICROMIPS_min },
   3466   { BFD_RELOC_MICROMIPS_7_PCREL_S1, R_MICROMIPS_PC7_S1 - R_MICROMIPS_min },
   3467   { BFD_RELOC_MICROMIPS_10_PCREL_S1, R_MICROMIPS_PC10_S1 - R_MICROMIPS_min },
   3468   { BFD_RELOC_MICROMIPS_16_PCREL_S1, R_MICROMIPS_PC16_S1 - R_MICROMIPS_min },
   3469   { BFD_RELOC_MICROMIPS_CALL16, R_MICROMIPS_CALL16 - R_MICROMIPS_min },
   3470   { BFD_RELOC_MICROMIPS_GOT_DISP, R_MICROMIPS_GOT_DISP - R_MICROMIPS_min },
   3471   { BFD_RELOC_MICROMIPS_GOT_PAGE, R_MICROMIPS_GOT_PAGE - R_MICROMIPS_min },
   3472   { BFD_RELOC_MICROMIPS_GOT_OFST, R_MICROMIPS_GOT_OFST - R_MICROMIPS_min },
   3473   { BFD_RELOC_MICROMIPS_GOT_HI16, R_MICROMIPS_GOT_HI16 - R_MICROMIPS_min },
   3474   { BFD_RELOC_MICROMIPS_GOT_LO16, R_MICROMIPS_GOT_LO16 - R_MICROMIPS_min },
   3475   { BFD_RELOC_MICROMIPS_SUB, R_MICROMIPS_SUB - R_MICROMIPS_min },
   3476   { BFD_RELOC_MICROMIPS_HIGHER, R_MICROMIPS_HIGHER - R_MICROMIPS_min },
   3477   { BFD_RELOC_MICROMIPS_HIGHEST, R_MICROMIPS_HIGHEST - R_MICROMIPS_min },
   3478   { BFD_RELOC_MICROMIPS_CALL_HI16, R_MICROMIPS_CALL_HI16 - R_MICROMIPS_min },
   3479   { BFD_RELOC_MICROMIPS_CALL_LO16, R_MICROMIPS_CALL_LO16 - R_MICROMIPS_min },
   3480   { BFD_RELOC_MICROMIPS_SCN_DISP, R_MICROMIPS_SCN_DISP - R_MICROMIPS_min },
   3481   { BFD_RELOC_MICROMIPS_JALR, R_MICROMIPS_JALR - R_MICROMIPS_min },
   3482 };
   3483 /* Given a BFD reloc type, return a howto structure.  */
   3484 
   3485 static reloc_howto_type *
   3486 bfd_elf64_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   3487 				 bfd_reloc_code_real_type code)
   3488 {
   3489   unsigned int i;
   3490   /* FIXME: We default to RELA here instead of choosing the right
   3491      relocation variant.  */
   3492   reloc_howto_type *howto_table = mips_elf64_howto_table_rela;
   3493   reloc_howto_type *howto16_table = mips16_elf64_howto_table_rela;
   3494   reloc_howto_type *howto_micromips_table = micromips_elf64_howto_table_rela;
   3495 
   3496   for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map);
   3497        i++)
   3498     {
   3499       if (mips_reloc_map[i].bfd_val == code)
   3500 	return &howto_table[(int) mips_reloc_map[i].elf_val];
   3501     }
   3502 
   3503   for (i = 0; i < sizeof (mips16_reloc_map) / sizeof (struct elf_reloc_map);
   3504        i++)
   3505     {
   3506       if (mips16_reloc_map[i].bfd_val == code)
   3507 	return &howto16_table[(int) mips16_reloc_map[i].elf_val];
   3508     }
   3509 
   3510   for (i = 0; i < sizeof (micromips_reloc_map) / sizeof (struct elf_reloc_map);
   3511        i++)
   3512     {
   3513       if (micromips_reloc_map[i].bfd_val == code)
   3514 	return &howto_micromips_table[(int) micromips_reloc_map[i].elf_val];
   3515     }
   3516 
   3517   switch (code)
   3518     {
   3519     case BFD_RELOC_VTABLE_INHERIT:
   3520       return &elf_mips_gnu_vtinherit_howto;
   3521     case BFD_RELOC_VTABLE_ENTRY:
   3522       return &elf_mips_gnu_vtentry_howto;
   3523     case BFD_RELOC_32_PCREL:
   3524       return &elf_mips_gnu_pcrel32;
   3525     case BFD_RELOC_MIPS_EH:
   3526       return &elf_mips_eh_howto;
   3527     case BFD_RELOC_MIPS_COPY:
   3528       return &elf_mips_copy_howto;
   3529     case BFD_RELOC_MIPS_JUMP_SLOT:
   3530       return &elf_mips_jump_slot_howto;
   3531     default:
   3532       bfd_set_error (bfd_error_bad_value);
   3533       return NULL;
   3534     }
   3535 }
   3536 
   3537 static reloc_howto_type *
   3538 bfd_elf64_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   3539 				 const char *r_name)
   3540 {
   3541   unsigned int i;
   3542 
   3543   for (i = 0;
   3544        i < (sizeof (mips_elf64_howto_table_rela)
   3545 	    / sizeof (mips_elf64_howto_table_rela[0])); i++)
   3546     if (mips_elf64_howto_table_rela[i].name != NULL
   3547 	&& strcasecmp (mips_elf64_howto_table_rela[i].name, r_name) == 0)
   3548       return &mips_elf64_howto_table_rela[i];
   3549 
   3550   for (i = 0;
   3551        i < (sizeof (mips16_elf64_howto_table_rela)
   3552 	    / sizeof (mips16_elf64_howto_table_rela[0]));
   3553        i++)
   3554     if (mips16_elf64_howto_table_rela[i].name != NULL
   3555 	&& strcasecmp (mips16_elf64_howto_table_rela[i].name, r_name) == 0)
   3556       return &mips16_elf64_howto_table_rela[i];
   3557 
   3558   for (i = 0;
   3559        i < (sizeof (micromips_elf64_howto_table_rela)
   3560 	    / sizeof (micromips_elf64_howto_table_rela[0]));
   3561        i++)
   3562     if (micromips_elf64_howto_table_rela[i].name != NULL
   3563 	&& strcasecmp (micromips_elf64_howto_table_rela[i].name, r_name) == 0)
   3564       return &micromips_elf64_howto_table_rela[i];
   3565 
   3566   if (strcasecmp (elf_mips_gnu_vtinherit_howto.name, r_name) == 0)
   3567     return &elf_mips_gnu_vtinherit_howto;
   3568   if (strcasecmp (elf_mips_gnu_vtentry_howto.name, r_name) == 0)
   3569     return &elf_mips_gnu_vtentry_howto;
   3570   if (strcasecmp (elf_mips_gnu_rel16_s2.name, r_name) == 0)
   3571     return &elf_mips_gnu_rel16_s2;
   3572   if (strcasecmp (elf_mips_gnu_rela16_s2.name, r_name) == 0)
   3573     return &elf_mips_gnu_rela16_s2;
   3574   if (strcasecmp (elf_mips_gnu_pcrel32.name, r_name) == 0)
   3575     return &elf_mips_gnu_pcrel32;
   3576   if (strcasecmp (elf_mips_eh_howto.name, r_name) == 0)
   3577     return &elf_mips_eh_howto;
   3578   if (strcasecmp (elf_mips_copy_howto.name, r_name) == 0)
   3579     return &elf_mips_copy_howto;
   3580   if (strcasecmp (elf_mips_jump_slot_howto.name, r_name) == 0)
   3581     return &elf_mips_jump_slot_howto;
   3582 
   3583   return NULL;
   3584 }
   3585 
   3586 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure.  */
   3587 
   3588 static reloc_howto_type *
   3589 mips_elf64_rtype_to_howto (unsigned int r_type, bfd_boolean rela_p)
   3590 {
   3591   switch (r_type)
   3592     {
   3593     case R_MIPS_GNU_VTINHERIT:
   3594       return &elf_mips_gnu_vtinherit_howto;
   3595     case R_MIPS_GNU_VTENTRY:
   3596       return &elf_mips_gnu_vtentry_howto;
   3597     case R_MIPS_GNU_REL16_S2:
   3598       if (rela_p)
   3599 	return &elf_mips_gnu_rela16_s2;
   3600       else
   3601 	return &elf_mips_gnu_rel16_s2;
   3602     case R_MIPS_PC32:
   3603       return &elf_mips_gnu_pcrel32;
   3604     case R_MIPS_EH:
   3605       return &elf_mips_eh_howto;
   3606     case R_MIPS_COPY:
   3607       return &elf_mips_copy_howto;
   3608     case R_MIPS_JUMP_SLOT:
   3609       return &elf_mips_jump_slot_howto;
   3610     default:
   3611       if (r_type >= R_MICROMIPS_min && r_type < R_MICROMIPS_max)
   3612 	{
   3613 	  if (rela_p)
   3614 	    return &micromips_elf64_howto_table_rela[r_type - R_MICROMIPS_min];
   3615 	  else
   3616 	    return &micromips_elf64_howto_table_rel[r_type - R_MICROMIPS_min];
   3617 	}
   3618       if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max)
   3619 	{
   3620 	  if (rela_p)
   3621 	    return &mips16_elf64_howto_table_rela[r_type - R_MIPS16_min];
   3622 	  else
   3623 	    return &mips16_elf64_howto_table_rel[r_type - R_MIPS16_min];
   3624 	}
   3625       if (r_type >= R_MIPS_max)
   3626 	{
   3627 	  (*_bfd_error_handler) (_("unrecognised MIPS reloc number: %d"), r_type);
   3628 	  bfd_set_error (bfd_error_bad_value);
   3629 	  r_type = R_MIPS_NONE;
   3630 	}
   3631       if (rela_p)
   3632 	return &mips_elf64_howto_table_rela[r_type];
   3633       else
   3634 	return &mips_elf64_howto_table_rel[r_type];
   3635       break;
   3636     }
   3637 }
   3638 
   3639 /* Prevent relocation handling by bfd for MIPS ELF64.  */
   3640 
   3641 static void
   3642 mips_elf64_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
   3643 			      arelent *cache_ptr ATTRIBUTE_UNUSED,
   3644 			      Elf_Internal_Rela *dst ATTRIBUTE_UNUSED)
   3645 {
   3646   BFD_ASSERT (0);
   3647 }
   3648 
   3649 static void
   3650 mips_elf64_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
   3651 			       arelent *cache_ptr ATTRIBUTE_UNUSED,
   3652 			       Elf_Internal_Rela *dst ATTRIBUTE_UNUSED)
   3653 {
   3654   BFD_ASSERT (0);
   3655 }
   3656 
   3657 /* Since each entry in an SHT_REL or SHT_RELA section can represent up
   3658    to three relocs, we must tell the user to allocate more space.  */
   3659 
   3660 static long
   3661 mips_elf64_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
   3662 {
   3663   return (sec->reloc_count * 3 + 1) * sizeof (arelent *);
   3664 }
   3665 
   3666 static long
   3667 mips_elf64_get_dynamic_reloc_upper_bound (bfd *abfd)
   3668 {
   3669   return _bfd_elf_get_dynamic_reloc_upper_bound (abfd) * 3;
   3670 }
   3671 
   3672 /* We must also copy more relocations than the corresponding functions
   3673    in elf.c would, so the two following functions are slightly
   3674    modified from elf.c, that multiply the external relocation count by
   3675    3 to obtain the internal relocation count.  */
   3676 
   3677 static long
   3678 mips_elf64_canonicalize_reloc (bfd *abfd, sec_ptr section,
   3679 			       arelent **relptr, asymbol **symbols)
   3680 {
   3681   arelent *tblptr;
   3682   unsigned int i;
   3683   const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   3684 
   3685   if (! bed->s->slurp_reloc_table (abfd, section, symbols, FALSE))
   3686     return -1;
   3687 
   3688   tblptr = section->relocation;
   3689   for (i = 0; i < section->reloc_count * 3; i++)
   3690     *relptr++ = tblptr++;
   3691 
   3692   *relptr = NULL;
   3693 
   3694   return section->reloc_count * 3;
   3695 }
   3696 
   3697 static long
   3698 mips_elf64_canonicalize_dynamic_reloc (bfd *abfd, arelent **storage,
   3699 				       asymbol **syms)
   3700 {
   3701   bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
   3702   asection *s;
   3703   long ret;
   3704 
   3705   if (elf_dynsymtab (abfd) == 0)
   3706     {
   3707       bfd_set_error (bfd_error_invalid_operation);
   3708       return -1;
   3709     }
   3710 
   3711   slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
   3712   ret = 0;
   3713   for (s = abfd->sections; s != NULL; s = s->next)
   3714     {
   3715       if (elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
   3716 	  && (elf_section_data (s)->this_hdr.sh_type == SHT_REL
   3717 	      || elf_section_data (s)->this_hdr.sh_type == SHT_RELA))
   3718 	{
   3719 	  arelent *p;
   3720 	  long count, i;
   3721 
   3722 	  if (! (*slurp_relocs) (abfd, s, syms, TRUE))
   3723 	    return -1;
   3724 	  count = s->size / elf_section_data (s)->this_hdr.sh_entsize * 3;
   3725 	  p = s->relocation;
   3726 	  for (i = 0; i < count; i++)
   3727 	    *storage++ = p++;
   3728 	  ret += count;
   3729 	}
   3730     }
   3731 
   3732   *storage = NULL;
   3733 
   3734   return ret;
   3735 }
   3736 
   3737 /* Read the relocations from one reloc section.  This is mostly copied
   3738    from elfcode.h, except for the changes to expand one external
   3739    relocation to 3 internal ones.  We must unfortunately set
   3740    reloc_count to the number of external relocations, because a lot of
   3741    generic code seems to depend on this.  */
   3742 
   3743 static bfd_boolean
   3744 mips_elf64_slurp_one_reloc_table (bfd *abfd, asection *asect,
   3745 				  Elf_Internal_Shdr *rel_hdr,
   3746 				  bfd_size_type reloc_count,
   3747 				  arelent *relents, asymbol **symbols,
   3748 				  bfd_boolean dynamic)
   3749 {
   3750   void *allocated;
   3751   bfd_byte *native_relocs;
   3752   arelent *relent;
   3753   bfd_vma i;
   3754   int entsize;
   3755   bfd_boolean rela_p;
   3756 
   3757   allocated = bfd_malloc (rel_hdr->sh_size);
   3758   if (allocated == NULL)
   3759     return FALSE;
   3760 
   3761   if (bfd_seek (abfd, rel_hdr->sh_offset, SEEK_SET) != 0
   3762       || (bfd_bread (allocated, rel_hdr->sh_size, abfd)
   3763 	  != rel_hdr->sh_size))
   3764     goto error_return;
   3765 
   3766   native_relocs = allocated;
   3767 
   3768   entsize = rel_hdr->sh_entsize;
   3769   BFD_ASSERT (entsize == sizeof (Elf64_Mips_External_Rel)
   3770 	      || entsize == sizeof (Elf64_Mips_External_Rela));
   3771 
   3772   if (entsize == sizeof (Elf64_Mips_External_Rel))
   3773     rela_p = FALSE;
   3774   else
   3775     rela_p = TRUE;
   3776 
   3777   for (i = 0, relent = relents;
   3778        i < reloc_count;
   3779        i++, native_relocs += entsize)
   3780     {
   3781       Elf64_Mips_Internal_Rela rela;
   3782       bfd_boolean used_sym, used_ssym;
   3783       int ir;
   3784 
   3785       if (entsize == sizeof (Elf64_Mips_External_Rela))
   3786 	mips_elf64_swap_reloca_in (abfd,
   3787 				   (Elf64_Mips_External_Rela *) native_relocs,
   3788 				   &rela);
   3789       else
   3790 	mips_elf64_swap_reloc_in (abfd,
   3791 				  (Elf64_Mips_External_Rel *) native_relocs,
   3792 				  &rela);
   3793 
   3794       /* Each entry represents exactly three actual relocations.  */
   3795 
   3796       used_sym = FALSE;
   3797       used_ssym = FALSE;
   3798       for (ir = 0; ir < 3; ir++)
   3799 	{
   3800 	  enum elf_mips_reloc_type type;
   3801 
   3802 	  switch (ir)
   3803 	    {
   3804 	    default:
   3805 	      abort ();
   3806 	    case 0:
   3807 	      type = (enum elf_mips_reloc_type) rela.r_type;
   3808 	      break;
   3809 	    case 1:
   3810 	      type = (enum elf_mips_reloc_type) rela.r_type2;
   3811 	      break;
   3812 	    case 2:
   3813 	      type = (enum elf_mips_reloc_type) rela.r_type3;
   3814 	      break;
   3815 	    }
   3816 
   3817 	  /* Some types require symbols, whereas some do not.  */
   3818 	  switch (type)
   3819 	    {
   3820 	    case R_MIPS_NONE:
   3821 	    case R_MIPS_LITERAL:
   3822 	    case R_MIPS_INSERT_A:
   3823 	    case R_MIPS_INSERT_B:
   3824 	    case R_MIPS_DELETE:
   3825 	      relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
   3826 	      break;
   3827 
   3828 	    default:
   3829 	      if (! used_sym)
   3830 		{
   3831 		  if (rela.r_sym == STN_UNDEF)
   3832 		    relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
   3833 		  else
   3834 		    {
   3835 		      asymbol **ps, *s;
   3836 
   3837 		      ps = symbols + rela.r_sym - 1;
   3838 		      s = *ps;
   3839 		      if ((s->flags & BSF_SECTION_SYM) == 0)
   3840 			relent->sym_ptr_ptr = ps;
   3841 		      else
   3842 			relent->sym_ptr_ptr = s->section->symbol_ptr_ptr;
   3843 		    }
   3844 
   3845 		  used_sym = TRUE;
   3846 		}
   3847 	      else if (! used_ssym)
   3848 		{
   3849 		  switch (rela.r_ssym)
   3850 		    {
   3851 		    case RSS_UNDEF:
   3852 		      relent->sym_ptr_ptr =
   3853 			bfd_abs_section_ptr->symbol_ptr_ptr;
   3854 		      break;
   3855 
   3856 		    case RSS_GP:
   3857 		    case RSS_GP0:
   3858 		    case RSS_LOC:
   3859 		      /* FIXME: I think these need to be handled using
   3860 			 special howto structures.  */
   3861 		      BFD_ASSERT (0);
   3862 		      break;
   3863 
   3864 		    default:
   3865 		      BFD_ASSERT (0);
   3866 		      break;
   3867 		    }
   3868 
   3869 		  used_ssym = TRUE;
   3870 		}
   3871 	      else
   3872 		relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
   3873 
   3874 	      break;
   3875 	    }
   3876 
   3877 	  /* The address of an ELF reloc is section relative for an
   3878 	     object file, and absolute for an executable file or
   3879 	     shared library.  The address of a BFD reloc is always
   3880 	     section relative.  */
   3881 	  if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0 || dynamic)
   3882 	    relent->address = rela.r_offset;
   3883 	  else
   3884 	    relent->address = rela.r_offset - asect->vma;
   3885 
   3886 	  relent->addend = rela.r_addend;
   3887 
   3888 	  relent->howto = mips_elf64_rtype_to_howto (type, rela_p);
   3889 
   3890 	  ++relent;
   3891 	}
   3892     }
   3893 
   3894   asect->reloc_count += (relent - relents) / 3;
   3895 
   3896   if (allocated != NULL)
   3897     free (allocated);
   3898 
   3899   return TRUE;
   3900 
   3901  error_return:
   3902   if (allocated != NULL)
   3903     free (allocated);
   3904   return FALSE;
   3905 }
   3906 
   3907 /* Read the relocations.  On Irix 6, there can be two reloc sections
   3908    associated with a single data section.  This is copied from
   3909    elfcode.h as well, with changes as small as accounting for 3
   3910    internal relocs per external reloc and resetting reloc_count to
   3911    zero before processing the relocs of a section.  */
   3912 
   3913 static bfd_boolean
   3914 mips_elf64_slurp_reloc_table (bfd *abfd, asection *asect,
   3915 			      asymbol **symbols, bfd_boolean dynamic)
   3916 {
   3917   struct bfd_elf_section_data * const d = elf_section_data (asect);
   3918   Elf_Internal_Shdr *rel_hdr;
   3919   Elf_Internal_Shdr *rel_hdr2;
   3920   bfd_size_type reloc_count;
   3921   bfd_size_type reloc_count2;
   3922   arelent *relents;
   3923   bfd_size_type amt;
   3924 
   3925   if (asect->relocation != NULL)
   3926     return TRUE;
   3927 
   3928   if (! dynamic)
   3929     {
   3930       if ((asect->flags & SEC_RELOC) == 0
   3931 	  || asect->reloc_count == 0)
   3932 	return TRUE;
   3933 
   3934       rel_hdr = d->rel.hdr;
   3935       reloc_count = rel_hdr ? NUM_SHDR_ENTRIES (rel_hdr) : 0;
   3936       rel_hdr2 = d->rela.hdr;
   3937       reloc_count2 = (rel_hdr2 ? NUM_SHDR_ENTRIES (rel_hdr2) : 0);
   3938 
   3939       BFD_ASSERT (asect->reloc_count == reloc_count + reloc_count2);
   3940       BFD_ASSERT ((rel_hdr && asect->rel_filepos == rel_hdr->sh_offset)
   3941 		  || (rel_hdr2 && asect->rel_filepos == rel_hdr2->sh_offset));
   3942 
   3943     }
   3944   else
   3945     {
   3946       /* Note that ASECT->RELOC_COUNT tends not to be accurate in this
   3947 	 case because relocations against this section may use the
   3948 	 dynamic symbol table, and in that case bfd_section_from_shdr
   3949 	 in elf.c does not update the RELOC_COUNT.  */
   3950       if (asect->size == 0)
   3951 	return TRUE;
   3952 
   3953       rel_hdr = &d->this_hdr;
   3954       reloc_count = NUM_SHDR_ENTRIES (rel_hdr);
   3955       rel_hdr2 = NULL;
   3956       reloc_count2 = 0;
   3957     }
   3958 
   3959   /* Allocate space for 3 arelent structures for each Rel structure.  */
   3960   amt = (reloc_count + reloc_count2) * 3 * sizeof (arelent);
   3961   relents = bfd_alloc (abfd, amt);
   3962   if (relents == NULL)
   3963     return FALSE;
   3964 
   3965   /* The slurp_one_reloc_table routine increments reloc_count.  */
   3966   asect->reloc_count = 0;
   3967 
   3968   if (rel_hdr != NULL
   3969       && ! mips_elf64_slurp_one_reloc_table (abfd, asect,
   3970 					     rel_hdr, reloc_count,
   3971 					     relents,
   3972 					     symbols, dynamic))
   3973     return FALSE;
   3974   if (rel_hdr2 != NULL
   3975       && ! mips_elf64_slurp_one_reloc_table (abfd, asect,
   3976 					     rel_hdr2, reloc_count2,
   3977 					     relents + reloc_count * 3,
   3978 					     symbols, dynamic))
   3979     return FALSE;
   3980 
   3981   asect->relocation = relents;
   3982   return TRUE;
   3983 }
   3984 
   3985 /* Write out the relocations.  */
   3986 
   3987 static void
   3988 mips_elf64_write_relocs (bfd *abfd, asection *sec, void *data)
   3989 {
   3990   bfd_boolean *failedp = data;
   3991   int count;
   3992   Elf_Internal_Shdr *rel_hdr;
   3993   unsigned int idx;
   3994 
   3995   /* If we have already failed, don't do anything.  */
   3996   if (*failedp)
   3997     return;
   3998 
   3999   if ((sec->flags & SEC_RELOC) == 0)
   4000     return;
   4001 
   4002   /* The linker backend writes the relocs out itself, and sets the
   4003      reloc_count field to zero to inhibit writing them here.  Also,
   4004      sometimes the SEC_RELOC flag gets set even when there aren't any
   4005      relocs.  */
   4006   if (sec->reloc_count == 0)
   4007     return;
   4008 
   4009   /* We can combine up to three relocs that refer to the same address
   4010      if the latter relocs have no associated symbol.  */
   4011   count = 0;
   4012   for (idx = 0; idx < sec->reloc_count; idx++)
   4013     {
   4014       bfd_vma addr;
   4015       unsigned int i;
   4016 
   4017       ++count;
   4018 
   4019       addr = sec->orelocation[idx]->address;
   4020       for (i = 0; i < 2; i++)
   4021 	{
   4022 	  arelent *r;
   4023 
   4024 	  if (idx + 1 >= sec->reloc_count)
   4025 	    break;
   4026 	  r = sec->orelocation[idx + 1];
   4027 	  if (r->address != addr
   4028 	      || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
   4029 	      || (*r->sym_ptr_ptr)->value != 0)
   4030 	    break;
   4031 
   4032 	  /* We can merge the reloc at IDX + 1 with the reloc at IDX.  */
   4033 
   4034 	  ++idx;
   4035 	}
   4036     }
   4037 
   4038   rel_hdr = _bfd_elf_single_rel_hdr (sec);
   4039 
   4040   /* Do the actual relocation.  */
   4041 
   4042   if (rel_hdr->sh_entsize == sizeof(Elf64_Mips_External_Rel))
   4043     mips_elf64_write_rel (abfd, sec, rel_hdr, &count, data);
   4044   else if (rel_hdr->sh_entsize == sizeof(Elf64_Mips_External_Rela))
   4045     mips_elf64_write_rela (abfd, sec, rel_hdr, &count, data);
   4046   else
   4047     BFD_ASSERT (0);
   4048 }
   4049 
   4050 static void
   4051 mips_elf64_write_rel (bfd *abfd, asection *sec,
   4052 		      Elf_Internal_Shdr *rel_hdr,
   4053 		      int *count, void *data)
   4054 {
   4055   bfd_boolean *failedp = data;
   4056   Elf64_Mips_External_Rel *ext_rel;
   4057   unsigned int idx;
   4058   asymbol *last_sym = 0;
   4059   int last_sym_idx = 0;
   4060 
   4061   rel_hdr->sh_size = rel_hdr->sh_entsize * *count;
   4062   rel_hdr->contents = bfd_alloc (abfd, rel_hdr->sh_size);
   4063   if (rel_hdr->contents == NULL)
   4064     {
   4065       *failedp = TRUE;
   4066       return;
   4067     }
   4068 
   4069   ext_rel = (Elf64_Mips_External_Rel *) rel_hdr->contents;
   4070   for (idx = 0; idx < sec->reloc_count; idx++, ext_rel++)
   4071     {
   4072       arelent *ptr;
   4073       Elf64_Mips_Internal_Rela int_rel;
   4074       asymbol *sym;
   4075       int n;
   4076       unsigned int i;
   4077 
   4078       ptr = sec->orelocation[idx];
   4079 
   4080       /* The address of an ELF reloc is section relative for an object
   4081 	 file, and absolute for an executable file or shared library.
   4082 	 The address of a BFD reloc is always section relative.  */
   4083       if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
   4084 	int_rel.r_offset = ptr->address;
   4085       else
   4086 	int_rel.r_offset = ptr->address + sec->vma;
   4087 
   4088       sym = *ptr->sym_ptr_ptr;
   4089       if (sym == last_sym)
   4090 	n = last_sym_idx;
   4091       else if (bfd_is_abs_section (sym->section) && sym->value == 0)
   4092 	n = STN_UNDEF;
   4093       else
   4094 	{
   4095 	  last_sym = sym;
   4096 	  n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
   4097 	  if (n < 0)
   4098 	    {
   4099 	      *failedp = TRUE;
   4100 	      return;
   4101 	    }
   4102 	  last_sym_idx = n;
   4103 	}
   4104 
   4105       int_rel.r_sym = n;
   4106       int_rel.r_ssym = RSS_UNDEF;
   4107 
   4108       if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
   4109 	  && ! _bfd_elf_validate_reloc (abfd, ptr))
   4110 	{
   4111 	  *failedp = TRUE;
   4112 	  return;
   4113 	}
   4114 
   4115       int_rel.r_type = ptr->howto->type;
   4116       int_rel.r_type2 = (int) R_MIPS_NONE;
   4117       int_rel.r_type3 = (int) R_MIPS_NONE;
   4118 
   4119       for (i = 0; i < 2; i++)
   4120 	{
   4121 	  arelent *r;
   4122 
   4123 	  if (idx + 1 >= sec->reloc_count)
   4124 	    break;
   4125 	  r = sec->orelocation[idx + 1];
   4126 	  if (r->address != ptr->address
   4127 	      || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
   4128 	      || (*r->sym_ptr_ptr)->value != 0)
   4129 	    break;
   4130 
   4131 	  /* We can merge the reloc at IDX + 1 with the reloc at IDX.  */
   4132 
   4133 	  if (i == 0)
   4134 	    int_rel.r_type2 = r->howto->type;
   4135 	  else
   4136 	    int_rel.r_type3 = r->howto->type;
   4137 
   4138 	  ++idx;
   4139 	}
   4140 
   4141       mips_elf64_swap_reloc_out (abfd, &int_rel, ext_rel);
   4142     }
   4143 
   4144   BFD_ASSERT (ext_rel - (Elf64_Mips_External_Rel *) rel_hdr->contents
   4145 	      == *count);
   4146 }
   4147 
   4148 static void
   4149 mips_elf64_write_rela (bfd *abfd, asection *sec,
   4150 		       Elf_Internal_Shdr *rela_hdr,
   4151 		       int *count, void *data)
   4152 {
   4153   bfd_boolean *failedp = data;
   4154   Elf64_Mips_External_Rela *ext_rela;
   4155   unsigned int idx;
   4156   asymbol *last_sym = 0;
   4157   int last_sym_idx = 0;
   4158 
   4159   rela_hdr->sh_size = rela_hdr->sh_entsize * *count;
   4160   rela_hdr->contents = bfd_alloc (abfd, rela_hdr->sh_size);
   4161   if (rela_hdr->contents == NULL)
   4162     {
   4163       *failedp = TRUE;
   4164       return;
   4165     }
   4166 
   4167   ext_rela = (Elf64_Mips_External_Rela *) rela_hdr->contents;
   4168   for (idx = 0; idx < sec->reloc_count; idx++, ext_rela++)
   4169     {
   4170       arelent *ptr;
   4171       Elf64_Mips_Internal_Rela int_rela;
   4172       asymbol *sym;
   4173       int n;
   4174       unsigned int i;
   4175 
   4176       ptr = sec->orelocation[idx];
   4177 
   4178       /* The address of an ELF reloc is section relative for an object
   4179 	 file, and absolute for an executable file or shared library.
   4180 	 The address of a BFD reloc is always section relative.  */
   4181       if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
   4182 	int_rela.r_offset = ptr->address;
   4183       else
   4184 	int_rela.r_offset = ptr->address + sec->vma;
   4185 
   4186       sym = *ptr->sym_ptr_ptr;
   4187       if (sym == last_sym)
   4188 	n = last_sym_idx;
   4189       else if (bfd_is_abs_section (sym->section) && sym->value == 0)
   4190 	n = STN_UNDEF;
   4191       else
   4192 	{
   4193 	  last_sym = sym;
   4194 	  n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
   4195 	  if (n < 0)
   4196 	    {
   4197 	      *failedp = TRUE;
   4198 	      return;
   4199 	    }
   4200 	  last_sym_idx = n;
   4201 	}
   4202 
   4203       int_rela.r_sym = n;
   4204       int_rela.r_addend = ptr->addend;
   4205       int_rela.r_ssym = RSS_UNDEF;
   4206 
   4207       if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
   4208 	  && ! _bfd_elf_validate_reloc (abfd, ptr))
   4209 	{
   4210 	  *failedp = TRUE;
   4211 	  return;
   4212 	}
   4213 
   4214       int_rela.r_type = ptr->howto->type;
   4215       int_rela.r_type2 = (int) R_MIPS_NONE;
   4216       int_rela.r_type3 = (int) R_MIPS_NONE;
   4217 
   4218       for (i = 0; i < 2; i++)
   4219 	{
   4220 	  arelent *r;
   4221 
   4222 	  if (idx + 1 >= sec->reloc_count)
   4223 	    break;
   4224 	  r = sec->orelocation[idx + 1];
   4225 	  if (r->address != ptr->address
   4226 	      || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
   4227 	      || (*r->sym_ptr_ptr)->value != 0)
   4228 	    break;
   4229 
   4230 	  /* We can merge the reloc at IDX + 1 with the reloc at IDX.  */
   4231 
   4232 	  if (i == 0)
   4233 	    int_rela.r_type2 = r->howto->type;
   4234 	  else
   4235 	    int_rela.r_type3 = r->howto->type;
   4236 
   4237 	  ++idx;
   4238 	}
   4239 
   4240       mips_elf64_swap_reloca_out (abfd, &int_rela, ext_rela);
   4241     }
   4242 
   4243   BFD_ASSERT (ext_rela - (Elf64_Mips_External_Rela *) rela_hdr->contents
   4244 	      == *count);
   4245 }
   4246 
   4247 /* Set the right machine number for a MIPS ELF file.  */
   4249 
   4250 static bfd_boolean
   4251 mips_elf64_object_p (bfd *abfd)
   4252 {
   4253   unsigned long mach;
   4254 
   4255   /* Irix 6 is broken.  Object file symbol tables are not always
   4256      sorted correctly such that local symbols precede global symbols,
   4257      and the sh_info field in the symbol table is not always right.  */
   4258   if (elf64_mips_irix_compat (abfd) != ict_none)
   4259     elf_bad_symtab (abfd) = TRUE;
   4260 
   4261   mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
   4262   bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
   4263   return TRUE;
   4264 }
   4265 
   4266 /* Depending on the target vector we generate some version of Irix
   4267    executables or "normal" MIPS ELF ABI executables.  */
   4268 static irix_compat_t
   4269 elf64_mips_irix_compat (bfd *abfd)
   4270 {
   4271   if ((abfd->xvec == &mips_elf64_be_vec)
   4272       || (abfd->xvec == &mips_elf64_le_vec))
   4273     return ict_irix6;
   4274   else
   4275     return ict_none;
   4276 }
   4277 
   4278 /* Support for core dump NOTE sections.  */
   4280 static bfd_boolean
   4281 elf64_mips_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
   4282 {
   4283   int offset;
   4284   unsigned int size;
   4285 
   4286   switch (note->descsz)
   4287     {
   4288       default:
   4289 	return FALSE;
   4290 
   4291       case 480:		/* Linux/MIPS - N64 kernel */
   4292 	/* pr_cursig */
   4293 	elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
   4294 
   4295 	/* pr_pid */
   4296 	elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32);
   4297 
   4298 	/* pr_reg */
   4299 	offset = 112;
   4300 	size = 360;
   4301 
   4302 	break;
   4303     }
   4304 
   4305   /* Make a ".reg/999" section.  */
   4306   return _bfd_elfcore_make_pseudosection (abfd, ".reg",
   4307 					  size, note->descpos + offset);
   4308 }
   4309 
   4310 static bfd_boolean
   4311 elf64_mips_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
   4312 {
   4313   switch (note->descsz)
   4314     {
   4315       default:
   4316 	return FALSE;
   4317 
   4318       case 136:		/* Linux/MIPS - N64 kernel elf_prpsinfo */
   4319 	elf_tdata (abfd)->core->program
   4320 	 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
   4321 	elf_tdata (abfd)->core->command
   4322 	 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
   4323     }
   4324 
   4325   /* Note that for some reason, a spurious space is tacked
   4326      onto the end of the args in some (at least one anyway)
   4327      implementations, so strip it off if it exists.  */
   4328 
   4329   {
   4330     char *command = elf_tdata (abfd)->core->command;
   4331     int n = strlen (command);
   4332 
   4333     if (0 < n && command[n - 1] == ' ')
   4334       command[n - 1] = '\0';
   4335   }
   4336 
   4337   return TRUE;
   4338 }
   4339 
   4340 /* ECOFF swapping routines.  These are used when dealing with the
   4342    .mdebug section, which is in the ECOFF debugging format.  */
   4343 static const struct ecoff_debug_swap mips_elf64_ecoff_debug_swap =
   4344 {
   4345   /* Symbol table magic number.  */
   4346   magicSym2,
   4347   /* Alignment of debugging information.  E.g., 4.  */
   4348   8,
   4349   /* Sizes of external symbolic information.  */
   4350   sizeof (struct hdr_ext),
   4351   sizeof (struct dnr_ext),
   4352   sizeof (struct pdr_ext),
   4353   sizeof (struct sym_ext),
   4354   sizeof (struct opt_ext),
   4355   sizeof (struct fdr_ext),
   4356   sizeof (struct rfd_ext),
   4357   sizeof (struct ext_ext),
   4358   /* Functions to swap in external symbolic data.  */
   4359   ecoff_swap_hdr_in,
   4360   ecoff_swap_dnr_in,
   4361   ecoff_swap_pdr_in,
   4362   ecoff_swap_sym_in,
   4363   ecoff_swap_opt_in,
   4364   ecoff_swap_fdr_in,
   4365   ecoff_swap_rfd_in,
   4366   ecoff_swap_ext_in,
   4367   _bfd_ecoff_swap_tir_in,
   4368   _bfd_ecoff_swap_rndx_in,
   4369   /* Functions to swap out external symbolic data.  */
   4370   ecoff_swap_hdr_out,
   4371   ecoff_swap_dnr_out,
   4372   ecoff_swap_pdr_out,
   4373   ecoff_swap_sym_out,
   4374   ecoff_swap_opt_out,
   4375   ecoff_swap_fdr_out,
   4376   ecoff_swap_rfd_out,
   4377   ecoff_swap_ext_out,
   4378   _bfd_ecoff_swap_tir_out,
   4379   _bfd_ecoff_swap_rndx_out,
   4380   /* Function to read in symbolic data.  */
   4381   _bfd_mips_elf_read_ecoff_info
   4382 };
   4383 
   4384 /* Relocations in the 64 bit MIPS ELF ABI are more complex than in
   4386    standard ELF.  This structure is used to redirect the relocation
   4387    handling routines.  */
   4388 
   4389 const struct elf_size_info mips_elf64_size_info =
   4390 {
   4391   sizeof (Elf64_External_Ehdr),
   4392   sizeof (Elf64_External_Phdr),
   4393   sizeof (Elf64_External_Shdr),
   4394   sizeof (Elf64_Mips_External_Rel),
   4395   sizeof (Elf64_Mips_External_Rela),
   4396   sizeof (Elf64_External_Sym),
   4397   sizeof (Elf64_External_Dyn),
   4398   sizeof (Elf_External_Note),
   4399   4,		/* hash-table entry size */
   4400   3,		/* internal relocations per external relocations */
   4401   64,		/* arch_size */
   4402   3,		/* log_file_align */
   4403   ELFCLASS64,
   4404   EV_CURRENT,
   4405   bfd_elf64_write_out_phdrs,
   4406   bfd_elf64_write_shdrs_and_ehdr,
   4407   bfd_elf64_checksum_contents,
   4408   mips_elf64_write_relocs,
   4409   bfd_elf64_swap_symbol_in,
   4410   bfd_elf64_swap_symbol_out,
   4411   mips_elf64_slurp_reloc_table,
   4412   bfd_elf64_slurp_symbol_table,
   4413   bfd_elf64_swap_dyn_in,
   4414   bfd_elf64_swap_dyn_out,
   4415   mips_elf64_be_swap_reloc_in,
   4416   mips_elf64_be_swap_reloc_out,
   4417   mips_elf64_be_swap_reloca_in,
   4418   mips_elf64_be_swap_reloca_out
   4419 };
   4420 
   4421 #define ELF_ARCH			bfd_arch_mips
   4422 #define ELF_TARGET_ID			MIPS_ELF_DATA
   4423 #define ELF_MACHINE_CODE		EM_MIPS
   4424 
   4425 #define elf_backend_collect		TRUE
   4426 #define elf_backend_type_change_ok	TRUE
   4427 #define elf_backend_can_gc_sections	TRUE
   4428 #define elf_backend_gc_mark_extra_sections \
   4429 					_bfd_mips_elf_gc_mark_extra_sections
   4430 #define elf_info_to_howto		mips_elf64_info_to_howto_rela
   4431 #define elf_info_to_howto_rel		mips_elf64_info_to_howto_rel
   4432 #define elf_backend_object_p		mips_elf64_object_p
   4433 #define elf_backend_symbol_processing	_bfd_mips_elf_symbol_processing
   4434 #define elf_backend_section_processing	_bfd_mips_elf_section_processing
   4435 #define elf_backend_section_from_shdr	_bfd_mips_elf_section_from_shdr
   4436 #define elf_backend_fake_sections	_bfd_mips_elf_fake_sections
   4437 #define elf_backend_section_from_bfd_section \
   4438 				_bfd_mips_elf_section_from_bfd_section
   4439 #define elf_backend_add_symbol_hook	_bfd_mips_elf_add_symbol_hook
   4440 #define elf_backend_link_output_symbol_hook \
   4441 				_bfd_mips_elf_link_output_symbol_hook
   4442 #define elf_backend_create_dynamic_sections \
   4443 				_bfd_mips_elf_create_dynamic_sections
   4444 #define elf_backend_check_relocs	_bfd_mips_elf_check_relocs
   4445 #define elf_backend_merge_symbol_attribute \
   4446 				_bfd_mips_elf_merge_symbol_attribute
   4447 #define elf_backend_get_target_dtag	_bfd_mips_elf_get_target_dtag
   4448 #define elf_backend_adjust_dynamic_symbol \
   4449 				_bfd_mips_elf_adjust_dynamic_symbol
   4450 #define elf_backend_always_size_sections \
   4451 				_bfd_mips_elf_always_size_sections
   4452 #define elf_backend_size_dynamic_sections \
   4453 				_bfd_mips_elf_size_dynamic_sections
   4454 #define elf_backend_init_index_section	_bfd_elf_init_1_index_section
   4455 #define elf_backend_relocate_section    _bfd_mips_elf_relocate_section
   4456 #define elf_backend_finish_dynamic_symbol \
   4457 				_bfd_mips_elf_finish_dynamic_symbol
   4458 #define elf_backend_finish_dynamic_sections \
   4459 				_bfd_mips_elf_finish_dynamic_sections
   4460 #define elf_backend_final_write_processing \
   4461 				_bfd_mips_elf_final_write_processing
   4462 #define elf_backend_additional_program_headers \
   4463 				_bfd_mips_elf_additional_program_headers
   4464 #define elf_backend_modify_segment_map	_bfd_mips_elf_modify_segment_map
   4465 #define elf_backend_gc_mark_hook	_bfd_mips_elf_gc_mark_hook
   4466 #define elf_backend_gc_sweep_hook	_bfd_mips_elf_gc_sweep_hook
   4467 #define elf_backend_copy_indirect_symbol \
   4468 					_bfd_mips_elf_copy_indirect_symbol
   4469 #define elf_backend_ignore_discarded_relocs \
   4470 					_bfd_mips_elf_ignore_discarded_relocs
   4471 #define elf_backend_mips_irix_compat	elf64_mips_irix_compat
   4472 #define elf_backend_mips_rtype_to_howto	mips_elf64_rtype_to_howto
   4473 #define elf_backend_ecoff_debug_swap	&mips_elf64_ecoff_debug_swap
   4474 #define elf_backend_size_info		mips_elf64_size_info
   4475 
   4476 #define elf_backend_grok_prstatus	elf64_mips_grok_prstatus
   4477 #define elf_backend_grok_psinfo		elf64_mips_grok_psinfo
   4478 
   4479 #define elf_backend_got_header_size	(8 * MIPS_RESERVED_GOTNO)
   4480 
   4481 /* MIPS ELF64 can use a mixture of REL and RELA, but some Relocations
   4482    work better/work only in RELA, so we default to this.  */
   4483 #define elf_backend_may_use_rel_p	1
   4484 #define elf_backend_may_use_rela_p	1
   4485 #define elf_backend_default_use_rela_p	1
   4486 #define elf_backend_rela_plts_and_copies_p 0
   4487 #define elf_backend_plt_readonly	1
   4488 #define elf_backend_plt_sym_val		_bfd_mips_elf_plt_sym_val
   4489 
   4490 #define elf_backend_sign_extend_vma	TRUE
   4491 
   4492 #define elf_backend_write_section	_bfd_mips_elf_write_section
   4493 #define elf_backend_sort_relocs_p	_bfd_mips_elf_sort_relocs_p
   4494 
   4495 /* We don't set bfd_elf64_bfd_is_local_label_name because the 32-bit
   4496    MIPS-specific function only applies to IRIX5, which had no 64-bit
   4497    ABI.  */
   4498 #define bfd_elf64_bfd_is_target_special_symbol \
   4499 					_bfd_mips_elf_is_target_special_symbol
   4500 #define bfd_elf64_find_nearest_line	_bfd_mips_elf_find_nearest_line
   4501 #define bfd_elf64_find_inliner_info	_bfd_mips_elf_find_inliner_info
   4502 #define bfd_elf64_new_section_hook	_bfd_mips_elf_new_section_hook
   4503 #define bfd_elf64_set_section_contents	_bfd_mips_elf_set_section_contents
   4504 #define bfd_elf64_bfd_get_relocated_section_contents \
   4505 				_bfd_elf_mips_get_relocated_section_contents
   4506 #define bfd_elf64_bfd_link_hash_table_create \
   4507 				_bfd_mips_elf_link_hash_table_create
   4508 #define bfd_elf64_bfd_final_link	_bfd_mips_elf_final_link
   4509 #define bfd_elf64_bfd_merge_private_bfd_data \
   4510 				_bfd_mips_elf_merge_private_bfd_data
   4511 #define bfd_elf64_bfd_set_private_flags	_bfd_mips_elf_set_private_flags
   4512 #define bfd_elf64_bfd_print_private_bfd_data \
   4513 				_bfd_mips_elf_print_private_bfd_data
   4514 
   4515 #define bfd_elf64_get_reloc_upper_bound mips_elf64_get_reloc_upper_bound
   4516 #define bfd_elf64_canonicalize_reloc mips_elf64_canonicalize_reloc
   4517 #define bfd_elf64_get_dynamic_reloc_upper_bound mips_elf64_get_dynamic_reloc_upper_bound
   4518 #define bfd_elf64_canonicalize_dynamic_reloc mips_elf64_canonicalize_dynamic_reloc
   4519 #define bfd_elf64_bfd_relax_section     _bfd_mips_relax_section
   4520 #define bfd_elf64_mkobject		_bfd_mips_elf_mkobject
   4521 
   4522 /* The SGI style (n)64 NewABI.  */
   4523 #define TARGET_LITTLE_SYM		mips_elf64_le_vec
   4524 #define TARGET_LITTLE_NAME		"elf64-littlemips"
   4525 #define TARGET_BIG_SYM			mips_elf64_be_vec
   4526 #define TARGET_BIG_NAME			"elf64-bigmips"
   4527 
   4528 #define ELF_MAXPAGESIZE			0x10000
   4529 #define ELF_COMMONPAGESIZE		0x1000
   4530 
   4531 #include "elf64-target.h"
   4532 
   4533 /* The SYSV-style 'traditional' (n)64 NewABI.  */
   4534 #undef TARGET_LITTLE_SYM
   4535 #undef TARGET_LITTLE_NAME
   4536 #undef TARGET_BIG_SYM
   4537 #undef TARGET_BIG_NAME
   4538 
   4539 #undef ELF_MAXPAGESIZE
   4540 #undef ELF_COMMONPAGESIZE
   4541 
   4542 #define TARGET_LITTLE_SYM		mips_elf64_trad_le_vec
   4543 #define TARGET_LITTLE_NAME		"elf64-tradlittlemips"
   4544 #define TARGET_BIG_SYM			mips_elf64_trad_be_vec
   4545 #define TARGET_BIG_NAME			"elf64-tradbigmips"
   4546 
   4547 #define ELF_MAXPAGESIZE			0x10000
   4548 #define ELF_COMMONPAGESIZE		0x1000
   4549 #define elf64_bed			elf64_tradbed
   4550 
   4551 /* Include the target file again for this target.  */
   4552 #include "elf64-target.h"
   4553 
   4554 
   4555 /* FreeBSD support.  */
   4556 
   4557 #undef TARGET_LITTLE_SYM
   4558 #undef TARGET_LITTLE_NAME
   4559 #undef TARGET_BIG_SYM
   4560 #undef TARGET_BIG_NAME
   4561 
   4562 #define	TARGET_LITTLE_SYM		mips_elf64_tradfbsd_le_vec
   4563 #define	TARGET_LITTLE_NAME		"elf64-tradlittlemips-freebsd"
   4564 #define	TARGET_BIG_SYM			mips_elf64_tradfbsd_be_vec
   4565 #define	TARGET_BIG_NAME			"elf64-tradbigmips-freebsd"
   4566 
   4567 #undef	ELF_OSABI
   4568 #define	ELF_OSABI			ELFOSABI_FREEBSD
   4569 
   4570 #undef	elf64_bed
   4571 #define elf64_bed				elf64_fbsd_tradbed
   4572 
   4573 #include "elf64-target.h"
   4574