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