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