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