Have info_to_howto functions return a success/fail status. Check this result. Stop...
[external/binutils.git] / bfd / elf32-mips.c
1 /* MIPS-specific support for 32-bit ELF
2    Copyright (C) 1993-2018 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 #include "elf-vxworks.h"
42
43 /* Get the ECOFF swapping routines.  */
44 #include "coff/sym.h"
45 #include "coff/symconst.h"
46 #include "coff/internal.h"
47 #include "coff/ecoff.h"
48 #include "coff/mips.h"
49 #define ECOFF_SIGNED_32
50 #include "ecoffswap.h"
51
52 static bfd_reloc_status_type gprel32_with_gp
53   (bfd *, asymbol *, arelent *, asection *, bfd_boolean, void *, bfd_vma);
54 static bfd_reloc_status_type mips_elf_gprel32_reloc
55   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
56 static bfd_reloc_status_type mips32_64bit_reloc
57   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
58 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
59   (bfd *, bfd_reloc_code_real_type);
60 static bfd_boolean mips_info_to_howto_rel
61   (bfd *, arelent *, Elf_Internal_Rela *);
62 static bfd_boolean mips_info_to_howto_rela
63   (bfd *, arelent *, Elf_Internal_Rela *);
64 static bfd_boolean mips_elf_sym_is_global
65   (bfd *, asymbol *);
66 static bfd_boolean mips_elf32_object_p
67   (bfd *);
68 static bfd_boolean mips_elf_is_local_label_name
69   (bfd *, const char *);
70 static bfd_reloc_status_type mips16_gprel_reloc
71   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
72 static bfd_reloc_status_type mips_elf_final_gp
73   (bfd *, asymbol *, bfd_boolean, char **, bfd_vma *);
74 static bfd_boolean mips_elf_assign_gp
75   (bfd *, bfd_vma *);
76 static bfd_boolean elf32_mips_grok_prstatus
77   (bfd *, Elf_Internal_Note *);
78 static bfd_boolean elf32_mips_grok_psinfo
79   (bfd *, Elf_Internal_Note *);
80 static irix_compat_t elf32_mips_irix_compat
81   (bfd *);
82
83 extern const bfd_target mips_elf32_be_vec;
84 extern const bfd_target mips_elf32_le_vec;
85
86 /* Nonzero if ABFD is using the N32 ABI.  */
87 #define ABI_N32_P(abfd) \
88   ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
89
90 /* Whether we are trying to be compatible with IRIX at all.  */
91 #define SGI_COMPAT(abfd) \
92   (elf32_mips_irix_compat (abfd) != ict_none)
93
94 /* The number of local .got entries we reserve.  */
95 #define MIPS_RESERVED_GOTNO (2)
96
97 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
98    from smaller values.  Start with zero, widen, *then* decrement.  */
99 #define MINUS_ONE       (((bfd_vma)0) - 1)
100
101 /* The relocation table used for SHT_REL sections.  */
102
103 static reloc_howto_type elf_mips_howto_table_rel[] =
104 {
105   /* No relocation.  */
106   HOWTO (R_MIPS_NONE,           /* type */
107          0,                     /* rightshift */
108          3,                     /* size (0 = byte, 1 = short, 2 = long) */
109          0,                     /* bitsize */
110          FALSE,                 /* pc_relative */
111          0,                     /* bitpos */
112          complain_overflow_dont, /* complain_on_overflow */
113          _bfd_mips_elf_generic_reloc, /* special_function */
114          "R_MIPS_NONE",         /* name */
115          FALSE,                 /* partial_inplace */
116          0,                     /* src_mask */
117          0,                     /* dst_mask */
118          FALSE),                /* pcrel_offset */
119
120   /* 16 bit relocation.  */
121   HOWTO (R_MIPS_16,             /* type */
122          0,                     /* rightshift */
123          2,                     /* size (0 = byte, 1 = short, 2 = long) */
124          16,                    /* bitsize */
125          FALSE,                 /* pc_relative */
126          0,                     /* bitpos */
127          complain_overflow_signed, /* complain_on_overflow */
128          _bfd_mips_elf_generic_reloc, /* special_function */
129          "R_MIPS_16",           /* name */
130          TRUE,                  /* partial_inplace */
131          0x0000ffff,            /* src_mask */
132          0x0000ffff,            /* dst_mask */
133          FALSE),                /* pcrel_offset */
134
135   /* 32 bit relocation.  */
136   HOWTO (R_MIPS_32,             /* type */
137          0,                     /* rightshift */
138          2,                     /* size (0 = byte, 1 = short, 2 = long) */
139          32,                    /* bitsize */
140          FALSE,                 /* pc_relative */
141          0,                     /* bitpos */
142          complain_overflow_dont, /* complain_on_overflow */
143          _bfd_mips_elf_generic_reloc, /* special_function */
144          "R_MIPS_32",           /* name */
145          TRUE,                  /* partial_inplace */
146          0xffffffff,            /* src_mask */
147          0xffffffff,            /* dst_mask */
148          FALSE),                /* pcrel_offset */
149
150   /* 32 bit symbol relative relocation.  */
151   HOWTO (R_MIPS_REL32,          /* type */
152          0,                     /* rightshift */
153          2,                     /* size (0 = byte, 1 = short, 2 = long) */
154          32,                    /* bitsize */
155          FALSE,                 /* pc_relative */
156          0,                     /* bitpos */
157          complain_overflow_dont, /* complain_on_overflow */
158          _bfd_mips_elf_generic_reloc, /* special_function */
159          "R_MIPS_REL32",        /* name */
160          TRUE,                  /* partial_inplace */
161          0xffffffff,            /* src_mask */
162          0xffffffff,            /* dst_mask */
163          FALSE),                /* pcrel_offset */
164
165   /* 26 bit jump address.  */
166   HOWTO (R_MIPS_26,             /* type */
167          2,                     /* rightshift */
168          2,                     /* size (0 = byte, 1 = short, 2 = long) */
169          26,                    /* bitsize */
170          FALSE,                 /* pc_relative */
171          0,                     /* bitpos */
172          complain_overflow_dont, /* complain_on_overflow */
173                                 /* This needs complex overflow
174                                    detection, because the upper four
175                                    bits must match the PC + 4.  */
176          _bfd_mips_elf_generic_reloc, /* special_function */
177          "R_MIPS_26",           /* name */
178          TRUE,                  /* partial_inplace */
179          0x03ffffff,            /* src_mask */
180          0x03ffffff,            /* dst_mask */
181          FALSE),                /* pcrel_offset */
182
183   /* High 16 bits of symbol value.  */
184   HOWTO (R_MIPS_HI16,           /* type */
185          16,                    /* rightshift */
186          2,                     /* size (0 = byte, 1 = short, 2 = long) */
187          16,                    /* bitsize */
188          FALSE,                 /* pc_relative */
189          0,                     /* bitpos */
190          complain_overflow_dont, /* complain_on_overflow */
191          _bfd_mips_elf_hi16_reloc, /* special_function */
192          "R_MIPS_HI16",         /* name */
193          TRUE,                  /* partial_inplace */
194          0x0000ffff,            /* src_mask */
195          0x0000ffff,            /* dst_mask */
196          FALSE),                /* pcrel_offset */
197
198   /* Low 16 bits of symbol value.  */
199   HOWTO (R_MIPS_LO16,           /* type */
200          0,                     /* rightshift */
201          2,                     /* size (0 = byte, 1 = short, 2 = long) */
202          16,                    /* bitsize */
203          FALSE,                 /* pc_relative */
204          0,                     /* bitpos */
205          complain_overflow_dont, /* complain_on_overflow */
206          _bfd_mips_elf_lo16_reloc, /* special_function */
207          "R_MIPS_LO16",         /* name */
208          TRUE,                  /* partial_inplace */
209          0x0000ffff,            /* src_mask */
210          0x0000ffff,            /* dst_mask */
211          FALSE),                /* pcrel_offset */
212
213   /* GP relative reference.  */
214   HOWTO (R_MIPS_GPREL16,        /* type */
215          0,                     /* rightshift */
216          2,                     /* size (0 = byte, 1 = short, 2 = long) */
217          16,                    /* bitsize */
218          FALSE,                 /* pc_relative */
219          0,                     /* bitpos */
220          complain_overflow_signed, /* complain_on_overflow */
221          _bfd_mips_elf32_gprel16_reloc, /* special_function */
222          "R_MIPS_GPREL16",      /* name */
223          TRUE,                  /* partial_inplace */
224          0x0000ffff,            /* src_mask */
225          0x0000ffff,            /* dst_mask */
226          FALSE),                /* pcrel_offset */
227
228   /* Reference to literal section.  */
229   HOWTO (R_MIPS_LITERAL,        /* type */
230          0,                     /* rightshift */
231          2,                     /* size (0 = byte, 1 = short, 2 = long) */
232          16,                    /* bitsize */
233          FALSE,                 /* pc_relative */
234          0,                     /* bitpos */
235          complain_overflow_signed, /* complain_on_overflow */
236          _bfd_mips_elf32_gprel16_reloc, /* special_function */
237          "R_MIPS_LITERAL",      /* name */
238          TRUE,                  /* partial_inplace */
239          0x0000ffff,            /* src_mask */
240          0x0000ffff,            /* dst_mask */
241          FALSE),                /* pcrel_offset */
242
243   /* Reference to global offset table.  */
244   HOWTO (R_MIPS_GOT16,          /* type */
245          0,                     /* rightshift */
246          2,                     /* size (0 = byte, 1 = short, 2 = long) */
247          16,                    /* bitsize */
248          FALSE,                 /* pc_relative */
249          0,                     /* bitpos */
250          complain_overflow_signed, /* complain_on_overflow */
251          _bfd_mips_elf_got16_reloc, /* special_function */
252          "R_MIPS_GOT16",        /* name */
253          TRUE,                  /* partial_inplace */
254          0x0000ffff,            /* src_mask */
255          0x0000ffff,            /* dst_mask */
256          FALSE),                /* pcrel_offset */
257
258   /* 16 bit PC relative reference.  Note that the ABI document has a typo
259      and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
260      We do the right thing here.  */
261   HOWTO (R_MIPS_PC16,           /* type */
262          2,                     /* rightshift */
263          2,                     /* size (0 = byte, 1 = short, 2 = long) */
264          16,                    /* bitsize */
265          TRUE,                  /* pc_relative */
266          0,                     /* bitpos */
267          complain_overflow_signed, /* complain_on_overflow */
268          _bfd_mips_elf_generic_reloc, /* special_function */
269          "R_MIPS_PC16",         /* name */
270          TRUE,                  /* partial_inplace */
271          0x0000ffff,            /* src_mask */
272          0x0000ffff,            /* dst_mask */
273          TRUE),                 /* pcrel_offset */
274
275   /* 16 bit call through global offset table.  */
276   HOWTO (R_MIPS_CALL16,         /* type */
277          0,                     /* rightshift */
278          2,                     /* size (0 = byte, 1 = short, 2 = long) */
279          16,                    /* bitsize */
280          FALSE,                 /* pc_relative */
281          0,                     /* bitpos */
282          complain_overflow_signed, /* complain_on_overflow */
283          _bfd_mips_elf_generic_reloc, /* special_function */
284          "R_MIPS_CALL16",       /* name */
285          TRUE,                  /* partial_inplace */
286          0x0000ffff,            /* src_mask */
287          0x0000ffff,            /* dst_mask */
288          FALSE),                /* pcrel_offset */
289
290   /* 32 bit GP relative reference.  */
291   HOWTO (R_MIPS_GPREL32,        /* type */
292          0,                     /* rightshift */
293          2,                     /* size (0 = byte, 1 = short, 2 = long) */
294          32,                    /* bitsize */
295          FALSE,                 /* pc_relative */
296          0,                     /* bitpos */
297          complain_overflow_dont, /* complain_on_overflow */
298          mips_elf_gprel32_reloc, /* special_function */
299          "R_MIPS_GPREL32",      /* name */
300          TRUE,                  /* partial_inplace */
301          0xffffffff,            /* src_mask */
302          0xffffffff,            /* dst_mask */
303          FALSE),                /* pcrel_offset */
304
305   /* The remaining relocs are defined on Irix 5, although they are
306      not defined by the ABI.  */
307   EMPTY_HOWTO (13),
308   EMPTY_HOWTO (14),
309   EMPTY_HOWTO (15),
310
311   /* A 5 bit shift field.  */
312   HOWTO (R_MIPS_SHIFT5,         /* type */
313          0,                     /* rightshift */
314          2,                     /* size (0 = byte, 1 = short, 2 = long) */
315          5,                     /* bitsize */
316          FALSE,                 /* pc_relative */
317          6,                     /* bitpos */
318          complain_overflow_bitfield, /* complain_on_overflow */
319          _bfd_mips_elf_generic_reloc, /* special_function */
320          "R_MIPS_SHIFT5",       /* name */
321          TRUE,                  /* partial_inplace */
322          0x000007c0,            /* src_mask */
323          0x000007c0,            /* dst_mask */
324          FALSE),                /* pcrel_offset */
325
326   /* A 6 bit shift field.  */
327   /* FIXME: This is not handled correctly; a special function is
328      needed to put the most significant bit in the right place.  */
329   HOWTO (R_MIPS_SHIFT6,         /* type */
330          0,                     /* rightshift */
331          2,                     /* size (0 = byte, 1 = short, 2 = long) */
332          6,                     /* bitsize */
333          FALSE,                 /* pc_relative */
334          6,                     /* bitpos */
335          complain_overflow_bitfield, /* complain_on_overflow */
336          _bfd_mips_elf_generic_reloc, /* special_function */
337          "R_MIPS_SHIFT6",       /* name */
338          TRUE,                  /* partial_inplace */
339          0x000007c4,            /* src_mask */
340          0x000007c4,            /* dst_mask */
341          FALSE),                /* pcrel_offset */
342
343   /* A 64 bit relocation.  */
344   HOWTO (R_MIPS_64,             /* type */
345          0,                     /* rightshift */
346          4,                     /* size (0 = byte, 1 = short, 2 = long) */
347          64,                    /* bitsize */
348          FALSE,                 /* pc_relative */
349          0,                     /* bitpos */
350          complain_overflow_dont, /* complain_on_overflow */
351          mips32_64bit_reloc,    /* special_function */
352          "R_MIPS_64",           /* name */
353          TRUE,                  /* partial_inplace */
354          MINUS_ONE,             /* src_mask */
355          MINUS_ONE,             /* dst_mask */
356          FALSE),                /* pcrel_offset */
357
358   /* Displacement in the global offset table.  */
359   HOWTO (R_MIPS_GOT_DISP,       /* type */
360          0,                     /* rightshift */
361          2,                     /* size (0 = byte, 1 = short, 2 = long) */
362          16,                    /* bitsize */
363          FALSE,                 /* pc_relative */
364          0,                     /* bitpos */
365          complain_overflow_signed, /* complain_on_overflow */
366          _bfd_mips_elf_generic_reloc, /* special_function */
367          "R_MIPS_GOT_DISP",     /* name */
368          TRUE,                  /* partial_inplace */
369          0x0000ffff,            /* src_mask */
370          0x0000ffff,            /* dst_mask */
371          FALSE),                /* pcrel_offset */
372
373   /* Displacement to page pointer in the global offset table.  */
374   HOWTO (R_MIPS_GOT_PAGE,       /* type */
375          0,                     /* rightshift */
376          2,                     /* size (0 = byte, 1 = short, 2 = long) */
377          16,                    /* bitsize */
378          FALSE,                 /* pc_relative */
379          0,                     /* bitpos */
380          complain_overflow_signed, /* complain_on_overflow */
381          _bfd_mips_elf_generic_reloc, /* special_function */
382          "R_MIPS_GOT_PAGE",     /* name */
383          TRUE,                  /* partial_inplace */
384          0x0000ffff,            /* src_mask */
385          0x0000ffff,            /* dst_mask */
386          FALSE),                /* pcrel_offset */
387
388   /* Offset from page pointer in the global offset table.  */
389   HOWTO (R_MIPS_GOT_OFST,       /* type */
390          0,                     /* rightshift */
391          2,                     /* size (0 = byte, 1 = short, 2 = long) */
392          16,                    /* bitsize */
393          FALSE,                 /* pc_relative */
394          0,                     /* bitpos */
395          complain_overflow_signed, /* complain_on_overflow */
396          _bfd_mips_elf_generic_reloc, /* special_function */
397          "R_MIPS_GOT_OFST",     /* name */
398          TRUE,                  /* partial_inplace */
399          0x0000ffff,            /* src_mask */
400          0x0000ffff,            /* dst_mask */
401          FALSE),                /* pcrel_offset */
402
403   /* High 16 bits of displacement in global offset table.  */
404   HOWTO (R_MIPS_GOT_HI16,       /* type */
405          0,                     /* rightshift */
406          2,                     /* size (0 = byte, 1 = short, 2 = long) */
407          16,                    /* bitsize */
408          FALSE,                 /* pc_relative */
409          0,                     /* bitpos */
410          complain_overflow_dont, /* complain_on_overflow */
411          _bfd_mips_elf_generic_reloc, /* special_function */
412          "R_MIPS_GOT_HI16",     /* name */
413          TRUE,                  /* partial_inplace */
414          0x0000ffff,            /* src_mask */
415          0x0000ffff,            /* dst_mask */
416          FALSE),                /* pcrel_offset */
417
418   /* Low 16 bits of displacement in global offset table.  */
419   HOWTO (R_MIPS_GOT_LO16,       /* type */
420          0,                     /* rightshift */
421          2,                     /* size (0 = byte, 1 = short, 2 = long) */
422          16,                    /* bitsize */
423          FALSE,                 /* pc_relative */
424          0,                     /* bitpos */
425          complain_overflow_dont, /* complain_on_overflow */
426          _bfd_mips_elf_generic_reloc, /* special_function */
427          "R_MIPS_GOT_LO16",     /* name */
428          TRUE,                  /* partial_inplace */
429          0x0000ffff,            /* src_mask */
430          0x0000ffff,            /* dst_mask */
431          FALSE),                /* pcrel_offset */
432
433   /* 64 bit subtraction.  Used in the N32 ABI.  */
434   HOWTO (R_MIPS_SUB,            /* type */
435          0,                     /* rightshift */
436          4,                     /* size (0 = byte, 1 = short, 2 = long) */
437          64,                    /* bitsize */
438          FALSE,                 /* pc_relative */
439          0,                     /* bitpos */
440          complain_overflow_dont, /* complain_on_overflow */
441          _bfd_mips_elf_generic_reloc, /* special_function */
442          "R_MIPS_SUB",          /* name */
443          TRUE,                  /* partial_inplace */
444          MINUS_ONE,             /* src_mask */
445          MINUS_ONE,             /* dst_mask */
446          FALSE),                /* pcrel_offset */
447
448   /* Used to cause the linker to insert and delete instructions?  */
449   EMPTY_HOWTO (R_MIPS_INSERT_A),
450   EMPTY_HOWTO (R_MIPS_INSERT_B),
451   EMPTY_HOWTO (R_MIPS_DELETE),
452
453   /* Get the higher value of a 64 bit addend.  */
454   HOWTO (R_MIPS_HIGHER,         /* type */
455          0,                     /* rightshift */
456          2,                     /* size (0 = byte, 1 = short, 2 = long) */
457          16,                    /* bitsize */
458          FALSE,                 /* pc_relative */
459          0,                     /* bitpos */
460          complain_overflow_dont, /* complain_on_overflow */
461          _bfd_mips_elf_generic_reloc, /* special_function */
462          "R_MIPS_HIGHER",       /* name */
463          TRUE,                  /* partial_inplace */
464          0x0000ffff,            /* src_mask */
465          0x0000ffff,            /* dst_mask */
466          FALSE),                /* pcrel_offset */
467
468   /* Get the highest value of a 64 bit addend.  */
469   HOWTO (R_MIPS_HIGHEST,        /* type */
470          0,                     /* rightshift */
471          2,                     /* size (0 = byte, 1 = short, 2 = long) */
472          16,                    /* bitsize */
473          FALSE,                 /* pc_relative */
474          0,                     /* bitpos */
475          complain_overflow_dont, /* complain_on_overflow */
476          _bfd_mips_elf_generic_reloc, /* special_function */
477          "R_MIPS_HIGHEST",      /* name */
478          TRUE,                  /* partial_inplace */
479          0x0000ffff,            /* src_mask */
480          0x0000ffff,            /* dst_mask */
481          FALSE),                /* pcrel_offset */
482
483   /* High 16 bits of displacement in global offset table.  */
484   HOWTO (R_MIPS_CALL_HI16,      /* type */
485          0,                     /* rightshift */
486          2,                     /* size (0 = byte, 1 = short, 2 = long) */
487          16,                    /* bitsize */
488          FALSE,                 /* pc_relative */
489          0,                     /* bitpos */
490          complain_overflow_dont, /* complain_on_overflow */
491          _bfd_mips_elf_generic_reloc, /* special_function */
492          "R_MIPS_CALL_HI16",    /* name */
493          TRUE,                  /* partial_inplace */
494          0x0000ffff,            /* src_mask */
495          0x0000ffff,            /* dst_mask */
496          FALSE),                /* pcrel_offset */
497
498   /* Low 16 bits of displacement in global offset table.  */
499   HOWTO (R_MIPS_CALL_LO16,      /* type */
500          0,                     /* rightshift */
501          2,                     /* size (0 = byte, 1 = short, 2 = long) */
502          16,                    /* bitsize */
503          FALSE,                 /* pc_relative */
504          0,                     /* bitpos */
505          complain_overflow_dont, /* complain_on_overflow */
506          _bfd_mips_elf_generic_reloc, /* special_function */
507          "R_MIPS_CALL_LO16",    /* name */
508          TRUE,                  /* partial_inplace */
509          0x0000ffff,            /* src_mask */
510          0x0000ffff,            /* dst_mask */
511          FALSE),                /* pcrel_offset */
512
513   /* Section displacement.  */
514   HOWTO (R_MIPS_SCN_DISP,       /* type */
515          0,                     /* rightshift */
516          2,                     /* size (0 = byte, 1 = short, 2 = long) */
517          32,                    /* bitsize */
518          FALSE,                 /* pc_relative */
519          0,                     /* bitpos */
520          complain_overflow_dont, /* complain_on_overflow */
521          _bfd_mips_elf_generic_reloc, /* special_function */
522          "R_MIPS_SCN_DISP",     /* name */
523          TRUE,                  /* partial_inplace */
524          0xffffffff,            /* src_mask */
525          0xffffffff,            /* dst_mask */
526          FALSE),                /* pcrel_offset */
527
528   EMPTY_HOWTO (R_MIPS_REL16),
529   EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
530   EMPTY_HOWTO (R_MIPS_PJUMP),
531   EMPTY_HOWTO (R_MIPS_RELGOT),
532
533   /* Protected jump conversion.  This is an optimization hint.  No
534      relocation is required for correctness.  */
535   HOWTO (R_MIPS_JALR,           /* type */
536          0,                     /* rightshift */
537          2,                     /* size (0 = byte, 1 = short, 2 = long) */
538          32,                    /* bitsize */
539          FALSE,                 /* pc_relative */
540          0,                     /* bitpos */
541          complain_overflow_dont, /* complain_on_overflow */
542          _bfd_mips_elf_generic_reloc, /* special_function */
543          "R_MIPS_JALR",         /* name */
544          FALSE,                 /* partial_inplace */
545          0x00000000,            /* src_mask */
546          0x00000000,            /* dst_mask */
547          FALSE),                /* pcrel_offset */
548
549   /* TLS GD/LD dynamic relocations.  */
550   HOWTO (R_MIPS_TLS_DTPMOD32,   /* type */
551          0,                     /* rightshift */
552          2,                     /* size (0 = byte, 1 = short, 2 = long) */
553          32,                    /* bitsize */
554          FALSE,                 /* pc_relative */
555          0,                     /* bitpos */
556          complain_overflow_dont, /* complain_on_overflow */
557          _bfd_mips_elf_generic_reloc, /* special_function */
558          "R_MIPS_TLS_DTPMOD32", /* name */
559          TRUE,                  /* partial_inplace */
560          0xffffffff,            /* src_mask */
561          0xffffffff,            /* dst_mask */
562          FALSE),                /* pcrel_offset */
563
564   HOWTO (R_MIPS_TLS_DTPREL32,   /* type */
565          0,                     /* rightshift */
566          2,                     /* size (0 = byte, 1 = short, 2 = long) */
567          32,                    /* bitsize */
568          FALSE,                 /* pc_relative */
569          0,                     /* bitpos */
570          complain_overflow_dont, /* complain_on_overflow */
571          _bfd_mips_elf_generic_reloc, /* special_function */
572          "R_MIPS_TLS_DTPREL32", /* name */
573          TRUE,                  /* partial_inplace */
574          0xffffffff,            /* src_mask */
575          0xffffffff,            /* dst_mask */
576          FALSE),                /* pcrel_offset */
577
578   EMPTY_HOWTO (R_MIPS_TLS_DTPMOD64),
579   EMPTY_HOWTO (R_MIPS_TLS_DTPREL64),
580
581   /* TLS general dynamic variable reference.  */
582   HOWTO (R_MIPS_TLS_GD,         /* type */
583          0,                     /* rightshift */
584          2,                     /* size (0 = byte, 1 = short, 2 = long) */
585          16,                    /* bitsize */
586          FALSE,                 /* pc_relative */
587          0,                     /* bitpos */
588          complain_overflow_signed, /* complain_on_overflow */
589          _bfd_mips_elf_generic_reloc, /* special_function */
590          "R_MIPS_TLS_GD",       /* name */
591          TRUE,                  /* partial_inplace */
592          0x0000ffff,            /* src_mask */
593          0x0000ffff,            /* dst_mask */
594          FALSE),                /* pcrel_offset */
595
596   /* TLS local dynamic variable reference.  */
597   HOWTO (R_MIPS_TLS_LDM,        /* type */
598          0,                     /* rightshift */
599          2,                     /* size (0 = byte, 1 = short, 2 = long) */
600          16,                    /* bitsize */
601          FALSE,                 /* pc_relative */
602          0,                     /* bitpos */
603          complain_overflow_signed, /* complain_on_overflow */
604          _bfd_mips_elf_generic_reloc, /* special_function */
605          "R_MIPS_TLS_LDM",      /* name */
606          TRUE,                  /* partial_inplace */
607          0x0000ffff,            /* src_mask */
608          0x0000ffff,            /* dst_mask */
609          FALSE),                /* pcrel_offset */
610
611   /* TLS local dynamic offset.  */
612   HOWTO (R_MIPS_TLS_DTPREL_HI16,        /* type */
613          0,                     /* rightshift */
614          2,                     /* size (0 = byte, 1 = short, 2 = long) */
615          16,                    /* bitsize */
616          FALSE,                 /* pc_relative */
617          0,                     /* bitpos */
618          complain_overflow_signed, /* complain_on_overflow */
619          _bfd_mips_elf_generic_reloc, /* special_function */
620          "R_MIPS_TLS_DTPREL_HI16",      /* name */
621          TRUE,                  /* partial_inplace */
622          0x0000ffff,            /* src_mask */
623          0x0000ffff,            /* dst_mask */
624          FALSE),                /* pcrel_offset */
625
626   /* TLS local dynamic offset.  */
627   HOWTO (R_MIPS_TLS_DTPREL_LO16,        /* type */
628          0,                     /* rightshift */
629          2,                     /* size (0 = byte, 1 = short, 2 = long) */
630          16,                    /* bitsize */
631          FALSE,                 /* pc_relative */
632          0,                     /* bitpos */
633          complain_overflow_signed, /* complain_on_overflow */
634          _bfd_mips_elf_generic_reloc, /* special_function */
635          "R_MIPS_TLS_DTPREL_LO16",      /* name */
636          TRUE,                  /* partial_inplace */
637          0x0000ffff,            /* src_mask */
638          0x0000ffff,            /* dst_mask */
639          FALSE),                /* pcrel_offset */
640
641   /* TLS thread pointer offset.  */
642   HOWTO (R_MIPS_TLS_GOTTPREL,   /* 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_GOTTPREL", /* name */
651          TRUE,                  /* partial_inplace */
652          0x0000ffff,            /* src_mask */
653          0x0000ffff,            /* dst_mask */
654          FALSE),                /* pcrel_offset */
655
656   /* TLS IE dynamic relocations.  */
657   HOWTO (R_MIPS_TLS_TPREL32,    /* type */
658          0,                     /* rightshift */
659          2,                     /* size (0 = byte, 1 = short, 2 = long) */
660          32,                    /* bitsize */
661          FALSE,                 /* pc_relative */
662          0,                     /* bitpos */
663          complain_overflow_dont, /* complain_on_overflow */
664          _bfd_mips_elf_generic_reloc, /* special_function */
665          "R_MIPS_TLS_TPREL32",  /* name */
666          TRUE,                  /* partial_inplace */
667          0xffffffff,            /* src_mask */
668          0xffffffff,            /* dst_mask */
669          FALSE),                /* pcrel_offset */
670
671   EMPTY_HOWTO (R_MIPS_TLS_TPREL64),
672
673   /* TLS thread pointer offset.  */
674   HOWTO (R_MIPS_TLS_TPREL_HI16, /* type */
675          0,                     /* rightshift */
676          2,                     /* size (0 = byte, 1 = short, 2 = long) */
677          16,                    /* bitsize */
678          FALSE,                 /* pc_relative */
679          0,                     /* bitpos */
680          complain_overflow_signed, /* complain_on_overflow */
681          _bfd_mips_elf_generic_reloc, /* special_function */
682          "R_MIPS_TLS_TPREL_HI16", /* name */
683          TRUE,                  /* partial_inplace */
684          0x0000ffff,            /* src_mask */
685          0x0000ffff,            /* dst_mask */
686          FALSE),                /* pcrel_offset */
687
688   /* TLS thread pointer offset.  */
689   HOWTO (R_MIPS_TLS_TPREL_LO16, /* type */
690          0,                     /* rightshift */
691          2,                     /* size (0 = byte, 1 = short, 2 = long) */
692          16,                    /* bitsize */
693          FALSE,                 /* pc_relative */
694          0,                     /* bitpos */
695          complain_overflow_signed, /* complain_on_overflow */
696          _bfd_mips_elf_generic_reloc, /* special_function */
697          "R_MIPS_TLS_TPREL_LO16", /* name */
698          TRUE,                  /* partial_inplace */
699          0x0000ffff,            /* src_mask */
700          0x0000ffff,            /* dst_mask */
701          FALSE),                /* pcrel_offset */
702
703   /* 32 bit relocation with no addend.  */
704   HOWTO (R_MIPS_GLOB_DAT,       /* type */
705          0,                     /* rightshift */
706          2,                     /* size (0 = byte, 1 = short, 2 = long) */
707          32,                    /* bitsize */
708          FALSE,                 /* pc_relative */
709          0,                     /* bitpos */
710          complain_overflow_dont, /* complain_on_overflow */
711          _bfd_mips_elf_generic_reloc, /* special_function */
712          "R_MIPS_GLOB_DAT",     /* name */
713          FALSE,                 /* partial_inplace */
714          0x0,                   /* src_mask */
715          0xffffffff,            /* dst_mask */
716          FALSE),                /* pcrel_offset */
717
718   EMPTY_HOWTO (52),
719   EMPTY_HOWTO (53),
720   EMPTY_HOWTO (54),
721   EMPTY_HOWTO (55),
722   EMPTY_HOWTO (56),
723   EMPTY_HOWTO (57),
724   EMPTY_HOWTO (58),
725   EMPTY_HOWTO (59),
726
727   HOWTO (R_MIPS_PC21_S2,        /* type */
728          2,                     /* rightshift */
729          2,                     /* size (0 = byte, 1 = short, 2 = long) */
730          21,                    /* bitsize */
731          TRUE,                  /* pc_relative */
732          0,                     /* bitpos */
733          complain_overflow_signed, /* complain_on_overflow */
734          _bfd_mips_elf_generic_reloc, /* special_function */
735          "R_MIPS_PC21_S2",      /* name */
736          TRUE,                  /* partial_inplace */
737          0x001fffff,            /* src_mask */
738          0x001fffff,            /* dst_mask */
739          TRUE),                 /* pcrel_offset */
740
741   HOWTO (R_MIPS_PC26_S2,        /* type */
742          2,                     /* rightshift */
743          2,                     /* size (0 = byte, 1 = short, 2 = long) */
744          26,                    /* bitsize */
745          TRUE,                  /* pc_relative */
746          0,                     /* bitpos */
747          complain_overflow_signed, /* complain_on_overflow */
748          _bfd_mips_elf_generic_reloc, /* special_function */
749          "R_MIPS_PC26_S2",      /* name */
750          TRUE,                  /* partial_inplace */
751          0x03ffffff,            /* src_mask */
752          0x03ffffff,            /* dst_mask */
753          TRUE),                 /* pcrel_offset */
754
755   HOWTO (R_MIPS_PC18_S3,        /* type */
756          3,                     /* rightshift */
757          2,                     /* size (0 = byte, 1 = short, 2 = long) */
758          18,                    /* bitsize */
759          TRUE,                  /* pc_relative */
760          0,                     /* bitpos */
761          complain_overflow_signed, /* complain_on_overflow */
762          _bfd_mips_elf_generic_reloc,   /* special_function */
763          "R_MIPS_PC18_S3",      /* name */
764          TRUE,                  /* partial_inplace */
765          0x0003ffff,            /* src_mask */
766          0x0003ffff,            /* dst_mask */
767          TRUE),                 /* pcrel_offset */
768
769   HOWTO (R_MIPS_PC19_S2,        /* type */
770          2,                     /* rightshift */
771          2,                     /* size (0 = byte, 1 = short, 2 = long) */
772          19,                    /* bitsize */
773          TRUE,                  /* pc_relative */
774          0,                     /* bitpos */
775          complain_overflow_signed, /* complain_on_overflow */
776          _bfd_mips_elf_generic_reloc,   /* special_function */
777          "R_MIPS_PC19_S2",      /* name */
778          TRUE,                  /* partial_inplace */
779          0x0007ffff,            /* src_mask */
780          0x0007ffff,            /* dst_mask */
781          TRUE),                 /* pcrel_offset */
782
783   HOWTO (R_MIPS_PCHI16,         /* type */
784          16,                    /* rightshift */
785          2,                     /* size (0 = byte, 1 = short, 2 = long) */
786          16,                    /* bitsize */
787          TRUE,                  /* pc_relative */
788          0,                     /* bitpos */
789          complain_overflow_signed, /* complain_on_overflow */
790          _bfd_mips_elf_generic_reloc,   /* special_function */
791          "R_MIPS_PCHI16",       /* name */
792          TRUE,                  /* partial_inplace */
793          0x0000ffff,            /* src_mask */
794          0x0000ffff,            /* dst_mask */
795          TRUE),                 /* pcrel_offset */
796
797   HOWTO (R_MIPS_PCLO16,         /* type */
798          0,                     /* rightshift */
799          2,                     /* size (0 = byte, 1 = short, 2 = long) */
800          16,                    /* bitsize */
801          TRUE,                  /* pc_relative */
802          0,                     /* bitpos */
803          complain_overflow_dont, /* complain_on_overflow */
804          _bfd_mips_elf_generic_reloc,   /* special_function */
805          "R_MIPS_PCLO16",       /* name */
806          TRUE,                  /* partial_inplace */
807          0x0000ffff,            /* src_mask */
808          0x0000ffff,            /* dst_mask */
809          TRUE),                 /* pcrel_offset */
810 };
811
812 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link.  This
813    is a hack to make the linker think that we need 64 bit values.  */
814 static reloc_howto_type elf_mips_ctor64_howto =
815   HOWTO (R_MIPS_64,             /* type */
816          0,                     /* rightshift */
817          4,                     /* size (0 = byte, 1 = short, 2 = long) */
818          32,                    /* bitsize */
819          FALSE,                 /* pc_relative */
820          0,                     /* bitpos */
821          complain_overflow_signed, /* complain_on_overflow */
822          mips32_64bit_reloc,    /* special_function */
823          "R_MIPS_64",           /* name */
824          TRUE,                  /* partial_inplace */
825          0xffffffff,            /* src_mask */
826          0xffffffff,            /* dst_mask */
827          FALSE);                /* pcrel_offset */
828
829 static reloc_howto_type elf_mips16_howto_table_rel[] =
830 {
831   /* The reloc used for the mips16 jump instruction.  */
832   HOWTO (R_MIPS16_26,           /* type */
833          2,                     /* rightshift */
834          2,                     /* size (0 = byte, 1 = short, 2 = long) */
835          26,                    /* bitsize */
836          FALSE,                 /* pc_relative */
837          0,                     /* bitpos */
838          complain_overflow_dont, /* complain_on_overflow */
839                                 /* This needs complex overflow
840                                    detection, because the upper four
841                                    bits must match the PC.  */
842          _bfd_mips_elf_generic_reloc, /* special_function */
843          "R_MIPS16_26",         /* name */
844          TRUE,                  /* partial_inplace */
845          0x3ffffff,             /* src_mask */
846          0x3ffffff,             /* dst_mask */
847          FALSE),                /* pcrel_offset */
848
849   /* The reloc used for the mips16 gprel instruction.  */
850   HOWTO (R_MIPS16_GPREL,        /* type */
851          0,                     /* rightshift */
852          2,                     /* size (0 = byte, 1 = short, 2 = long) */
853          16,                    /* bitsize */
854          FALSE,                 /* pc_relative */
855          0,                     /* bitpos */
856          complain_overflow_signed, /* complain_on_overflow */
857          mips16_gprel_reloc,    /* special_function */
858          "R_MIPS16_GPREL",      /* name */
859          TRUE,                  /* partial_inplace */
860          0x0000ffff,            /* src_mask */
861          0x0000ffff,            /* dst_mask */
862          FALSE),                /* pcrel_offset */
863
864   /* A MIPS16 reference to the global offset table.  */
865   HOWTO (R_MIPS16_GOT16,        /* type */
866          0,                     /* rightshift */
867          2,                     /* size (0 = byte, 1 = short, 2 = long) */
868          16,                    /* bitsize */
869          FALSE,                 /* pc_relative */
870          0,                     /* bitpos */
871          complain_overflow_dont, /* complain_on_overflow */
872          _bfd_mips_elf_got16_reloc, /* special_function */
873          "R_MIPS16_GOT16",      /* name */
874          TRUE,                  /* partial_inplace */
875          0x0000ffff,            /* src_mask */
876          0x0000ffff,            /* dst_mask */
877          FALSE),                /* pcrel_offset */
878
879   /* A MIPS16 call through the global offset table.  */
880   HOWTO (R_MIPS16_CALL16,       /* type */
881          0,                     /* rightshift */
882          2,                     /* size (0 = byte, 1 = short, 2 = long) */
883          16,                    /* bitsize */
884          FALSE,                 /* pc_relative */
885          0,                     /* bitpos */
886          complain_overflow_dont, /* complain_on_overflow */
887          _bfd_mips_elf_generic_reloc, /* special_function */
888          "R_MIPS16_CALL16",     /* name */
889          TRUE,                  /* partial_inplace */
890          0x0000ffff,            /* src_mask */
891          0x0000ffff,            /* dst_mask */
892          FALSE),                /* pcrel_offset */
893
894   /* MIPS16 high 16 bits of symbol value.  */
895   HOWTO (R_MIPS16_HI16,         /* type */
896          16,                    /* rightshift */
897          2,                     /* size (0 = byte, 1 = short, 2 = long) */
898          16,                    /* bitsize */
899          FALSE,                 /* pc_relative */
900          0,                     /* bitpos */
901          complain_overflow_dont, /* complain_on_overflow */
902          _bfd_mips_elf_hi16_reloc, /* special_function */
903          "R_MIPS16_HI16",       /* name */
904          TRUE,                  /* partial_inplace */
905          0x0000ffff,            /* src_mask */
906          0x0000ffff,            /* dst_mask */
907          FALSE),                /* pcrel_offset */
908
909   /* MIPS16 low 16 bits of symbol value.  */
910   HOWTO (R_MIPS16_LO16,         /* type */
911          0,                     /* rightshift */
912          2,                     /* size (0 = byte, 1 = short, 2 = long) */
913          16,                    /* bitsize */
914          FALSE,                 /* pc_relative */
915          0,                     /* bitpos */
916          complain_overflow_dont, /* complain_on_overflow */
917          _bfd_mips_elf_lo16_reloc, /* special_function */
918          "R_MIPS16_LO16",       /* name */
919          TRUE,                  /* partial_inplace */
920          0x0000ffff,            /* src_mask */
921          0x0000ffff,            /* dst_mask */
922          FALSE),                /* pcrel_offset */
923
924   /* MIPS16 TLS general dynamic variable reference.  */
925   HOWTO (R_MIPS16_TLS_GD,       /* type */
926          0,                     /* rightshift */
927          2,                     /* size (0 = byte, 1 = short, 2 = long) */
928          16,                    /* bitsize */
929          FALSE,                 /* pc_relative */
930          0,                     /* bitpos */
931          complain_overflow_signed, /* complain_on_overflow */
932          _bfd_mips_elf_generic_reloc, /* special_function */
933          "R_MIPS16_TLS_GD",     /* name */
934          TRUE,                  /* partial_inplace */
935          0x0000ffff,            /* src_mask */
936          0x0000ffff,            /* dst_mask */
937          FALSE),                /* pcrel_offset */
938
939   /* MIPS16 TLS local dynamic variable reference.  */
940   HOWTO (R_MIPS16_TLS_LDM,      /* type */
941          0,                     /* rightshift */
942          2,                     /* size (0 = byte, 1 = short, 2 = long) */
943          16,                    /* bitsize */
944          FALSE,                 /* pc_relative */
945          0,                     /* bitpos */
946          complain_overflow_signed, /* complain_on_overflow */
947          _bfd_mips_elf_generic_reloc, /* special_function */
948          "R_MIPS16_TLS_LDM",    /* name */
949          TRUE,                  /* partial_inplace */
950          0x0000ffff,            /* src_mask */
951          0x0000ffff,            /* dst_mask */
952          FALSE),                /* pcrel_offset */
953
954   /* MIPS16 TLS local dynamic offset.  */
955   HOWTO (R_MIPS16_TLS_DTPREL_HI16,      /* type */
956          0,                     /* rightshift */
957          2,                     /* size (0 = byte, 1 = short, 2 = long) */
958          16,                    /* bitsize */
959          FALSE,                 /* pc_relative */
960          0,                     /* bitpos */
961          complain_overflow_signed, /* complain_on_overflow */
962          _bfd_mips_elf_generic_reloc, /* special_function */
963          "R_MIPS16_TLS_DTPREL_HI16",    /* name */
964          TRUE,                  /* partial_inplace */
965          0x0000ffff,            /* src_mask */
966          0x0000ffff,            /* dst_mask */
967          FALSE),                /* pcrel_offset */
968
969   /* MIPS16 TLS local dynamic offset.  */
970   HOWTO (R_MIPS16_TLS_DTPREL_LO16,      /* type */
971          0,                     /* rightshift */
972          2,                     /* size (0 = byte, 1 = short, 2 = long) */
973          16,                    /* bitsize */
974          FALSE,                 /* pc_relative */
975          0,                     /* bitpos */
976          complain_overflow_signed, /* complain_on_overflow */
977          _bfd_mips_elf_generic_reloc, /* special_function */
978          "R_MIPS16_TLS_DTPREL_LO16",    /* name */
979          TRUE,                  /* partial_inplace */
980          0x0000ffff,            /* src_mask */
981          0x0000ffff,            /* dst_mask */
982          FALSE),                /* pcrel_offset */
983
984   /* MIPS16 TLS thread pointer offset.  */
985   HOWTO (R_MIPS16_TLS_GOTTPREL, /* type */
986          0,                     /* rightshift */
987          2,                     /* size (0 = byte, 1 = short, 2 = long) */
988          16,                    /* bitsize */
989          FALSE,                 /* pc_relative */
990          0,                     /* bitpos */
991          complain_overflow_signed, /* complain_on_overflow */
992          _bfd_mips_elf_generic_reloc, /* special_function */
993          "R_MIPS16_TLS_GOTTPREL",       /* name */
994          TRUE,                  /* partial_inplace */
995          0x0000ffff,            /* src_mask */
996          0x0000ffff,            /* dst_mask */
997          FALSE),                /* pcrel_offset */
998
999   /* MIPS16 TLS thread pointer offset.  */
1000   HOWTO (R_MIPS16_TLS_TPREL_HI16,       /* type */
1001          0,                     /* rightshift */
1002          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1003          16,                    /* bitsize */
1004          FALSE,                 /* pc_relative */
1005          0,                     /* bitpos */
1006          complain_overflow_signed, /* complain_on_overflow */
1007          _bfd_mips_elf_generic_reloc, /* special_function */
1008          "R_MIPS16_TLS_TPREL_HI16", /* name */
1009          TRUE,                  /* partial_inplace */
1010          0x0000ffff,            /* src_mask */
1011          0x0000ffff,            /* dst_mask */
1012          FALSE),                /* pcrel_offset */
1013
1014   /* MIPS16 TLS thread pointer offset.  */
1015   HOWTO (R_MIPS16_TLS_TPREL_LO16,       /* type */
1016          0,                     /* rightshift */
1017          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1018          16,                    /* bitsize */
1019          FALSE,                 /* pc_relative */
1020          0,                     /* bitpos */
1021          complain_overflow_signed, /* complain_on_overflow */
1022          _bfd_mips_elf_generic_reloc, /* special_function */
1023          "R_MIPS16_TLS_TPREL_LO16", /* name */
1024          TRUE,                  /* partial_inplace */
1025          0x0000ffff,            /* src_mask */
1026          0x0000ffff,            /* dst_mask */
1027          FALSE),                /* pcrel_offset */
1028
1029   /* MIPS16 16-bit PC-relative branch offset.  */
1030   HOWTO (R_MIPS16_PC16_S1,      /* type */
1031          1,                     /* rightshift */
1032          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1033          16,                    /* bitsize */
1034          TRUE,                  /* pc_relative */
1035          0,                     /* bitpos */
1036          complain_overflow_signed, /* complain_on_overflow */
1037          _bfd_mips_elf_generic_reloc, /* special_function */
1038          "R_MIPS16_PC16_S1",    /* name */
1039          TRUE,                  /* partial_inplace */
1040          0x0000ffff,            /* src_mask */
1041          0x0000ffff,            /* dst_mask */
1042          TRUE),                 /* pcrel_offset */
1043 };
1044
1045 static reloc_howto_type elf_micromips_howto_table_rel[] =
1046 {
1047   EMPTY_HOWTO (130),
1048   EMPTY_HOWTO (131),
1049   EMPTY_HOWTO (132),
1050
1051   /* 26 bit jump address.  */
1052   HOWTO (R_MICROMIPS_26_S1,     /* type */
1053          1,                     /* rightshift */
1054          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1055          26,                    /* bitsize */
1056          FALSE,                 /* pc_relative */
1057          0,                     /* bitpos */
1058          complain_overflow_dont, /* complain_on_overflow */
1059                                 /* This needs complex overflow
1060                                    detection, because the upper four
1061                                    bits must match the PC.  */
1062          _bfd_mips_elf_generic_reloc, /* special_function */
1063          "R_MICROMIPS_26_S1",   /* name */
1064          TRUE,                  /* partial_inplace */
1065          0x3ffffff,             /* src_mask */
1066          0x3ffffff,             /* dst_mask */
1067          FALSE),                /* pcrel_offset */
1068
1069   /* High 16 bits of symbol value.  */
1070   HOWTO (R_MICROMIPS_HI16,      /* type */
1071          16,                    /* rightshift */
1072          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1073          16,                    /* bitsize */
1074          FALSE,                 /* pc_relative */
1075          0,                     /* bitpos */
1076          complain_overflow_dont, /* complain_on_overflow */
1077          _bfd_mips_elf_hi16_reloc, /* special_function */
1078          "R_MICROMIPS_HI16",    /* name */
1079          TRUE,                  /* partial_inplace */
1080          0x0000ffff,            /* src_mask */
1081          0x0000ffff,            /* dst_mask */
1082          FALSE),                /* pcrel_offset */
1083
1084   /* Low 16 bits of symbol value.  */
1085   HOWTO (R_MICROMIPS_LO16,      /* type */
1086          0,                     /* rightshift */
1087          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1088          16,                    /* bitsize */
1089          FALSE,                 /* pc_relative */
1090          0,                     /* bitpos */
1091          complain_overflow_dont, /* complain_on_overflow */
1092          _bfd_mips_elf_lo16_reloc, /* special_function */
1093          "R_MICROMIPS_LO16",    /* name */
1094          TRUE,                  /* partial_inplace */
1095          0x0000ffff,            /* src_mask */
1096          0x0000ffff,            /* dst_mask */
1097          FALSE),                /* pcrel_offset */
1098
1099   /* GP relative reference.  */
1100   HOWTO (R_MICROMIPS_GPREL16,   /* type */
1101          0,                     /* rightshift */
1102          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1103          16,                    /* bitsize */
1104          FALSE,                 /* pc_relative */
1105          0,                     /* bitpos */
1106          complain_overflow_signed, /* complain_on_overflow */
1107          _bfd_mips_elf32_gprel16_reloc, /* special_function */
1108          "R_MICROMIPS_GPREL16", /* name */
1109          TRUE,                  /* partial_inplace */
1110          0x0000ffff,            /* src_mask */
1111          0x0000ffff,            /* dst_mask */
1112          FALSE),                /* pcrel_offset */
1113
1114   /* Reference to literal section.  */
1115   HOWTO (R_MICROMIPS_LITERAL,   /* type */
1116          0,                     /* rightshift */
1117          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1118          16,                    /* bitsize */
1119          FALSE,                 /* pc_relative */
1120          0,                     /* bitpos */
1121          complain_overflow_signed, /* complain_on_overflow */
1122          _bfd_mips_elf32_gprel16_reloc, /* special_function */
1123          "R_MICROMIPS_LITERAL", /* name */
1124          TRUE,                  /* partial_inplace */
1125          0x0000ffff,            /* src_mask */
1126          0x0000ffff,            /* dst_mask */
1127          FALSE),                /* pcrel_offset */
1128
1129   /* Reference to global offset table.  */
1130   HOWTO (R_MICROMIPS_GOT16,     /* type */
1131          0,                     /* rightshift */
1132          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1133          16,                    /* bitsize */
1134          FALSE,                 /* pc_relative */
1135          0,                     /* bitpos */
1136          complain_overflow_signed, /* complain_on_overflow */
1137          _bfd_mips_elf_got16_reloc, /* special_function */
1138          "R_MICROMIPS_GOT16",   /* name */
1139          TRUE,                  /* partial_inplace */
1140          0x0000ffff,            /* src_mask */
1141          0x0000ffff,            /* dst_mask */
1142          FALSE),                /* pcrel_offset */
1143
1144   /* This is for microMIPS branches.  */
1145   HOWTO (R_MICROMIPS_PC7_S1,    /* type */
1146          1,                     /* rightshift */
1147          1,                     /* size (0 = byte, 1 = short, 2 = long) */
1148          7,                     /* bitsize */
1149          TRUE,                  /* pc_relative */
1150          0,                     /* bitpos */
1151          complain_overflow_signed, /* complain_on_overflow */
1152          _bfd_mips_elf_generic_reloc, /* special_function */
1153          "R_MICROMIPS_PC7_S1",  /* name */
1154          TRUE,                  /* partial_inplace */
1155          0x0000007f,            /* src_mask */
1156          0x0000007f,            /* dst_mask */
1157          TRUE),                 /* pcrel_offset */
1158
1159   HOWTO (R_MICROMIPS_PC10_S1,   /* type */
1160          1,                     /* rightshift */
1161          1,                     /* size (0 = byte, 1 = short, 2 = long) */
1162          10,                    /* bitsize */
1163          TRUE,                  /* pc_relative */
1164          0,                     /* bitpos */
1165          complain_overflow_signed, /* complain_on_overflow */
1166          _bfd_mips_elf_generic_reloc, /* special_function */
1167          "R_MICROMIPS_PC10_S1", /* name */
1168          TRUE,                  /* partial_inplace */
1169          0x000003ff,            /* src_mask */
1170          0x000003ff,            /* dst_mask */
1171          TRUE),                 /* pcrel_offset */
1172
1173   HOWTO (R_MICROMIPS_PC16_S1,   /* type */
1174          1,                     /* rightshift */
1175          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1176          16,                    /* bitsize */
1177          TRUE,                  /* pc_relative */
1178          0,                     /* bitpos */
1179          complain_overflow_signed, /* complain_on_overflow */
1180          _bfd_mips_elf_generic_reloc, /* special_function */
1181          "R_MICROMIPS_PC16_S1", /* name */
1182          TRUE,                  /* partial_inplace */
1183          0x0000ffff,            /* src_mask */
1184          0x0000ffff,            /* dst_mask */
1185          TRUE),                 /* pcrel_offset */
1186
1187   /* 16 bit call through global offset table.  */
1188   HOWTO (R_MICROMIPS_CALL16,    /* type */
1189          0,                     /* rightshift */
1190          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1191          16,                    /* bitsize */
1192          FALSE,                 /* pc_relative */
1193          0,                     /* bitpos */
1194          complain_overflow_signed, /* complain_on_overflow */
1195          _bfd_mips_elf_generic_reloc, /* special_function */
1196          "R_MICROMIPS_CALL16",  /* name */
1197          TRUE,                  /* partial_inplace */
1198          0x0000ffff,            /* src_mask */
1199          0x0000ffff,            /* dst_mask */
1200          FALSE),                /* pcrel_offset */
1201
1202   EMPTY_HOWTO (143),
1203   EMPTY_HOWTO (144),
1204
1205   /* Displacement in the global offset table.  */
1206   HOWTO (R_MICROMIPS_GOT_DISP,  /* type */
1207          0,                     /* rightshift */
1208          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1209          16,                    /* bitsize */
1210          FALSE,                 /* pc_relative */
1211          0,                     /* bitpos */
1212          complain_overflow_signed, /* complain_on_overflow */
1213          _bfd_mips_elf_generic_reloc, /* special_function */
1214          "R_MICROMIPS_GOT_DISP",/* name */
1215          TRUE,                  /* partial_inplace */
1216          0x0000ffff,            /* src_mask */
1217          0x0000ffff,            /* dst_mask */
1218          FALSE),                /* pcrel_offset */
1219
1220   /* Displacement to page pointer in the global offset table.  */
1221   HOWTO (R_MICROMIPS_GOT_PAGE,  /* type */
1222          0,                     /* rightshift */
1223          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1224          16,                    /* bitsize */
1225          FALSE,                 /* pc_relative */
1226          0,                     /* bitpos */
1227          complain_overflow_signed, /* complain_on_overflow */
1228          _bfd_mips_elf_generic_reloc, /* special_function */
1229          "R_MICROMIPS_GOT_PAGE",/* name */
1230          TRUE,                  /* partial_inplace */
1231          0x0000ffff,            /* src_mask */
1232          0x0000ffff,            /* dst_mask */
1233          FALSE),                /* pcrel_offset */
1234
1235   /* Offset from page pointer in the global offset table.  */
1236   HOWTO (R_MICROMIPS_GOT_OFST,  /* type */
1237          0,                     /* rightshift */
1238          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1239          16,                    /* bitsize */
1240          FALSE,                 /* pc_relative */
1241          0,                     /* bitpos */
1242          complain_overflow_signed, /* complain_on_overflow */
1243          _bfd_mips_elf_generic_reloc, /* special_function */
1244          "R_MICROMIPS_GOT_OFST",/* name */
1245          TRUE,                  /* partial_inplace */
1246          0x0000ffff,            /* src_mask */
1247          0x0000ffff,            /* dst_mask */
1248          FALSE),                /* pcrel_offset */
1249
1250   /* High 16 bits of displacement in global offset table.  */
1251   HOWTO (R_MICROMIPS_GOT_HI16,  /* type */
1252          0,                     /* rightshift */
1253          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1254          16,                    /* 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_MICROMIPS_GOT_HI16",/* name */
1260          TRUE,                  /* partial_inplace */
1261          0x0000ffff,            /* src_mask */
1262          0x0000ffff,            /* dst_mask */
1263          FALSE),                /* pcrel_offset */
1264
1265   /* Low 16 bits of displacement in global offset table.  */
1266   HOWTO (R_MICROMIPS_GOT_LO16,  /* 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_MICROMIPS_GOT_LO16",/* name */
1275          TRUE,                  /* partial_inplace */
1276          0x0000ffff,            /* src_mask */
1277          0x0000ffff,            /* dst_mask */
1278          FALSE),                /* pcrel_offset */
1279
1280   /* 64 bit subtraction.  Used in the N32 ABI.  */
1281   HOWTO (R_MICROMIPS_SUB,       /* type */
1282          0,                     /* rightshift */
1283          4,                     /* size (0 = byte, 1 = short, 2 = long) */
1284          64,                    /* 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_MICROMIPS_SUB",     /* name */
1290          TRUE,                  /* partial_inplace */
1291          MINUS_ONE,             /* src_mask */
1292          MINUS_ONE,             /* dst_mask */
1293          FALSE),                /* pcrel_offset */
1294
1295   /* Get the higher value of a 64 bit addend.  */
1296   HOWTO (R_MICROMIPS_HIGHER,    /* 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_MICROMIPS_HIGHER",  /* name */
1305          TRUE,                  /* partial_inplace */
1306          0x0000ffff,            /* src_mask */
1307          0x0000ffff,            /* dst_mask */
1308          FALSE),                /* pcrel_offset */
1309
1310   /* Get the highest value of a 64 bit addend.  */
1311   HOWTO (R_MICROMIPS_HIGHEST,   /* 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_MICROMIPS_HIGHEST", /* name */
1320          TRUE,                  /* partial_inplace */
1321          0x0000ffff,            /* src_mask */
1322          0x0000ffff,            /* dst_mask */
1323          FALSE),                /* pcrel_offset */
1324
1325   /* High 16 bits of displacement in global offset table.  */
1326   HOWTO (R_MICROMIPS_CALL_HI16, /* type */
1327          0,                     /* rightshift */
1328          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1329          16,                    /* 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_MICROMIPS_CALL_HI16",/* name */
1335          TRUE,                  /* partial_inplace */
1336          0x0000ffff,            /* src_mask */
1337          0x0000ffff,            /* dst_mask */
1338          FALSE),                /* pcrel_offset */
1339
1340   /* Low 16 bits of displacement in global offset table.  */
1341   HOWTO (R_MICROMIPS_CALL_LO16, /* type */
1342          0,                     /* rightshift */
1343          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1344          16,                    /* bitsize */
1345          FALSE,                 /* pc_relative */
1346          0,                     /* bitpos */
1347          complain_overflow_dont, /* complain_on_overflow */
1348          _bfd_mips_elf_generic_reloc, /* special_function */
1349          "R_MICROMIPS_CALL_LO16",/* name */
1350          TRUE,                  /* partial_inplace */
1351          0x0000ffff,            /* src_mask */
1352          0x0000ffff,            /* dst_mask */
1353          FALSE),                /* pcrel_offset */
1354
1355   /* Section displacement.  */
1356   HOWTO (R_MICROMIPS_SCN_DISP,  /* type */
1357          0,                     /* rightshift */
1358          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1359          32,                    /* bitsize */
1360          FALSE,                 /* pc_relative */
1361          0,                     /* bitpos */
1362          complain_overflow_dont, /* complain_on_overflow */
1363          _bfd_mips_elf_generic_reloc, /* special_function */
1364          "R_MICROMIPS_SCN_DISP",/* name */
1365          TRUE,                  /* partial_inplace */
1366          0xffffffff,            /* src_mask */
1367          0xffffffff,            /* dst_mask */
1368          FALSE),                /* pcrel_offset */
1369
1370   /* Protected jump conversion.  This is an optimization hint.  No
1371      relocation is required for correctness.  */
1372   HOWTO (R_MICROMIPS_JALR,      /* type */
1373          0,                     /* rightshift */
1374          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1375          32,                    /* bitsize */
1376          FALSE,                 /* pc_relative */
1377          0,                     /* bitpos */
1378          complain_overflow_dont, /* complain_on_overflow */
1379          _bfd_mips_elf_generic_reloc, /* special_function */
1380          "R_MICROMIPS_JALR",    /* name */
1381          FALSE,                 /* partial_inplace */
1382          0x00000000,            /* src_mask */
1383          0x00000000,            /* dst_mask */
1384          FALSE),                /* pcrel_offset */
1385
1386   /* Low 16 bits of symbol value.  Note that the high 16 bits of symbol values
1387      must be zero.  This is used for relaxation.  */
1388   HOWTO (R_MICROMIPS_HI0_LO16,  /* type */
1389          0,                     /* rightshift */
1390          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1391          16,                    /* bitsize */
1392          FALSE,                 /* pc_relative */
1393          0,                     /* bitpos */
1394          complain_overflow_dont, /* complain_on_overflow */
1395          _bfd_mips_elf_generic_reloc, /* special_function */
1396          "R_MICROMIPS_HI0_LO16",/* name */
1397          TRUE,                  /* partial_inplace */
1398          0x0000ffff,            /* src_mask */
1399          0x0000ffff,            /* dst_mask */
1400          FALSE),                /* pcrel_offset */
1401
1402   EMPTY_HOWTO (158),
1403   EMPTY_HOWTO (159),
1404   EMPTY_HOWTO (160),
1405   EMPTY_HOWTO (161),
1406
1407   /* TLS general dynamic variable reference.  */
1408   HOWTO (R_MICROMIPS_TLS_GD,            /* type */
1409          0,                     /* rightshift */
1410          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1411          16,                    /* bitsize */
1412          FALSE,                 /* pc_relative */
1413          0,                     /* bitpos */
1414          complain_overflow_signed, /* complain_on_overflow */
1415          _bfd_mips_elf_generic_reloc, /* special_function */
1416          "R_MICROMIPS_TLS_GD",  /* name */
1417          TRUE,                  /* partial_inplace */
1418          0x0000ffff,            /* src_mask */
1419          0x0000ffff,            /* dst_mask */
1420          FALSE),                /* pcrel_offset */
1421
1422   /* TLS local dynamic variable reference.  */
1423   HOWTO (R_MICROMIPS_TLS_LDM,   /* type */
1424          0,                     /* rightshift */
1425          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1426          16,                    /* bitsize */
1427          FALSE,                 /* pc_relative */
1428          0,                     /* bitpos */
1429          complain_overflow_signed, /* complain_on_overflow */
1430          _bfd_mips_elf_generic_reloc, /* special_function */
1431          "R_MICROMIPS_TLS_LDM", /* name */
1432          TRUE,                  /* partial_inplace */
1433          0x0000ffff,            /* src_mask */
1434          0x0000ffff,            /* dst_mask */
1435          FALSE),                /* pcrel_offset */
1436
1437   /* TLS local dynamic offset.  */
1438   HOWTO (R_MICROMIPS_TLS_DTPREL_HI16,   /* type */
1439          0,                     /* rightshift */
1440          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1441          16,                    /* bitsize */
1442          FALSE,                 /* pc_relative */
1443          0,                     /* bitpos */
1444          complain_overflow_signed, /* complain_on_overflow */
1445          _bfd_mips_elf_generic_reloc, /* special_function */
1446          "R_MICROMIPS_TLS_DTPREL_HI16", /* name */
1447          TRUE,                  /* partial_inplace */
1448          0x0000ffff,            /* src_mask */
1449          0x0000ffff,            /* dst_mask */
1450          FALSE),                /* pcrel_offset */
1451
1452   /* TLS local dynamic offset.  */
1453   HOWTO (R_MICROMIPS_TLS_DTPREL_LO16,   /* type */
1454          0,                     /* rightshift */
1455          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1456          16,                    /* bitsize */
1457          FALSE,                 /* pc_relative */
1458          0,                     /* bitpos */
1459          complain_overflow_signed, /* complain_on_overflow */
1460          _bfd_mips_elf_generic_reloc, /* special_function */
1461          "R_MICROMIPS_TLS_DTPREL_LO16", /* name */
1462          TRUE,                  /* partial_inplace */
1463          0x0000ffff,            /* src_mask */
1464          0x0000ffff,            /* dst_mask */
1465          FALSE),                /* pcrel_offset */
1466
1467   /* TLS thread pointer offset.  */
1468   HOWTO (R_MICROMIPS_TLS_GOTTPREL,      /* type */
1469          0,                     /* rightshift */
1470          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1471          16,                    /* bitsize */
1472          FALSE,                 /* pc_relative */
1473          0,                     /* bitpos */
1474          complain_overflow_signed, /* complain_on_overflow */
1475          _bfd_mips_elf_generic_reloc, /* special_function */
1476          "R_MICROMIPS_TLS_GOTTPREL",    /* name */
1477          TRUE,                  /* partial_inplace */
1478          0x0000ffff,            /* src_mask */
1479          0x0000ffff,            /* dst_mask */
1480          FALSE),                /* pcrel_offset */
1481
1482   EMPTY_HOWTO (167),
1483   EMPTY_HOWTO (168),
1484
1485   /* TLS thread pointer offset.  */
1486   HOWTO (R_MICROMIPS_TLS_TPREL_HI16,    /* type */
1487          0,                     /* rightshift */
1488          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1489          16,                    /* bitsize */
1490          FALSE,                 /* pc_relative */
1491          0,                     /* bitpos */
1492          complain_overflow_signed, /* complain_on_overflow */
1493          _bfd_mips_elf_generic_reloc, /* special_function */
1494          "R_MICROMIPS_TLS_TPREL_HI16", /* name */
1495          TRUE,                  /* partial_inplace */
1496          0x0000ffff,            /* src_mask */
1497          0x0000ffff,            /* dst_mask */
1498          FALSE),                /* pcrel_offset */
1499
1500   /* TLS thread pointer offset.  */
1501   HOWTO (R_MICROMIPS_TLS_TPREL_LO16,    /* type */
1502          0,                     /* rightshift */
1503          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1504          16,                    /* bitsize */
1505          FALSE,                 /* pc_relative */
1506          0,                     /* bitpos */
1507          complain_overflow_signed, /* complain_on_overflow */
1508          _bfd_mips_elf_generic_reloc, /* special_function */
1509          "R_MICROMIPS_TLS_TPREL_LO16", /* name */
1510          TRUE,                  /* partial_inplace */
1511          0x0000ffff,            /* src_mask */
1512          0x0000ffff,            /* dst_mask */
1513          FALSE),                /* pcrel_offset */
1514
1515   EMPTY_HOWTO (171),
1516
1517   /* GP- and PC-relative relocations.  */
1518   HOWTO (R_MICROMIPS_GPREL7_S2, /* type */
1519          2,                     /* rightshift */
1520          1,                     /* size (0 = byte, 1 = short, 2 = long) */
1521          7,                     /* bitsize */
1522          FALSE,                 /* pc_relative */
1523          0,                     /* bitpos */
1524          complain_overflow_signed, /* complain_on_overflow */
1525          _bfd_mips_elf32_gprel16_reloc, /* special_function */
1526          "R_MICROMIPS_GPREL7_S2",       /* name */
1527          TRUE,                  /* partial_inplace */
1528          0x0000007f,            /* src_mask */
1529          0x0000007f,            /* dst_mask */
1530          FALSE),                /* pcrel_offset */
1531
1532   HOWTO (R_MICROMIPS_PC23_S2,   /* type */
1533          2,                     /* rightshift */
1534          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1535          23,                    /* bitsize */
1536          TRUE,                  /* pc_relative */
1537          0,                     /* bitpos */
1538          complain_overflow_signed, /* complain_on_overflow */
1539          _bfd_mips_elf_generic_reloc, /* special_function */
1540          "R_MICROMIPS_PC23_S2", /* name */
1541          TRUE,                  /* partial_inplace */
1542          0x007fffff,            /* src_mask */
1543          0x007fffff,            /* dst_mask */
1544          TRUE),                 /* pcrel_offset */
1545 };
1546
1547 /* 16 bit offset for pc-relative branches.  */
1548 static reloc_howto_type elf_mips_gnu_rel16_s2 =
1549   HOWTO (R_MIPS_GNU_REL16_S2,   /* type */
1550          2,                     /* rightshift */
1551          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1552          16,                    /* bitsize */
1553          TRUE,                  /* pc_relative */
1554          0,                     /* bitpos */
1555          complain_overflow_signed, /* complain_on_overflow */
1556          _bfd_mips_elf_generic_reloc, /* special_function */
1557          "R_MIPS_GNU_REL16_S2", /* name */
1558          TRUE,                  /* partial_inplace */
1559          0xffff,                /* src_mask */
1560          0xffff,                /* dst_mask */
1561          TRUE);                 /* pcrel_offset */
1562
1563 /* 32 bit pc-relative.  This was a GNU extension used by embedded-PIC.
1564    It was co-opted by mips-linux for exception-handling data.  GCC stopped
1565    using it in May, 2004, then started using it again for compact unwind
1566    tables.  */
1567 static reloc_howto_type elf_mips_gnu_pcrel32 =
1568   HOWTO (R_MIPS_PC32,           /* type */
1569          0,                     /* rightshift */
1570          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1571          32,                    /* bitsize */
1572          TRUE,                  /* pc_relative */
1573          0,                     /* bitpos */
1574          complain_overflow_signed, /* complain_on_overflow */
1575          _bfd_mips_elf_generic_reloc, /* special_function */
1576          "R_MIPS_PC32",         /* name */
1577          TRUE,                  /* partial_inplace */
1578          0xffffffff,            /* src_mask */
1579          0xffffffff,            /* dst_mask */
1580          TRUE);                 /* pcrel_offset */
1581
1582 /* GNU extension to record C++ vtable hierarchy */
1583 static reloc_howto_type elf_mips_gnu_vtinherit_howto =
1584   HOWTO (R_MIPS_GNU_VTINHERIT,  /* type */
1585          0,                     /* rightshift */
1586          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1587          0,                     /* bitsize */
1588          FALSE,                 /* pc_relative */
1589          0,                     /* bitpos */
1590          complain_overflow_dont, /* complain_on_overflow */
1591          NULL,                  /* special_function */
1592          "R_MIPS_GNU_VTINHERIT", /* name */
1593          FALSE,                 /* partial_inplace */
1594          0,                     /* src_mask */
1595          0,                     /* dst_mask */
1596          FALSE);                /* pcrel_offset */
1597
1598 /* GNU extension to record C++ vtable member usage */
1599 static reloc_howto_type elf_mips_gnu_vtentry_howto =
1600   HOWTO (R_MIPS_GNU_VTENTRY,    /* type */
1601          0,                     /* rightshift */
1602          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1603          0,                     /* bitsize */
1604          FALSE,                 /* pc_relative */
1605          0,                     /* bitpos */
1606          complain_overflow_dont, /* complain_on_overflow */
1607          _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1608          "R_MIPS_GNU_VTENTRY",  /* name */
1609          FALSE,                 /* partial_inplace */
1610          0,                     /* src_mask */
1611          0,                     /* dst_mask */
1612          FALSE);                /* pcrel_offset */
1613
1614 /* Originally a VxWorks extension, but now used for other systems too.  */
1615 static reloc_howto_type elf_mips_copy_howto =
1616   HOWTO (R_MIPS_COPY,           /* type */
1617          0,                     /* rightshift */
1618          0,                     /* this one is variable size */
1619          0,                     /* bitsize */
1620          FALSE,                 /* pc_relative */
1621          0,                     /* bitpos */
1622          complain_overflow_bitfield, /* complain_on_overflow */
1623          _bfd_mips_elf_generic_reloc, /* special_function */
1624          "R_MIPS_COPY",         /* name */
1625          FALSE,                 /* partial_inplace */
1626          0x0,                   /* src_mask */
1627          0x0,                   /* dst_mask */
1628          FALSE);                /* pcrel_offset */
1629
1630 /* Originally a VxWorks extension, but now used for other systems too.  */
1631 static reloc_howto_type elf_mips_jump_slot_howto =
1632   HOWTO (R_MIPS_JUMP_SLOT,      /* type */
1633          0,                     /* rightshift */
1634          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1635          32,                    /* bitsize */
1636          FALSE,                 /* pc_relative */
1637          0,                     /* bitpos */
1638          complain_overflow_bitfield, /* complain_on_overflow */
1639          _bfd_mips_elf_generic_reloc, /* special_function */
1640          "R_MIPS_JUMP_SLOT",    /* name */
1641          FALSE,                 /* partial_inplace */
1642          0x0,                   /* src_mask */
1643          0x0,                   /* dst_mask */
1644          FALSE);                /* pcrel_offset */
1645
1646 /* Used in EH tables.  */
1647 static reloc_howto_type elf_mips_eh_howto =
1648   HOWTO (R_MIPS_EH,             /* type */
1649          0,                     /* rightshift */
1650          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1651          32,                    /* bitsize */
1652          FALSE,                 /* pc_relative */
1653          0,                     /* bitpos */
1654          complain_overflow_signed, /* complain_on_overflow */
1655          _bfd_mips_elf_generic_reloc, /* special_function */
1656          "R_MIPS_EH",           /* name */
1657          TRUE,                  /* partial_inplace */
1658          0xffffffff,            /* src_mask */
1659          0xffffffff,            /* dst_mask */
1660          FALSE);                /* pcrel_offset */
1661
1662 /* Set the GP value for OUTPUT_BFD.  Returns FALSE if this is a
1663    dangerous relocation.  */
1664
1665 static bfd_boolean
1666 mips_elf_assign_gp (bfd *output_bfd, bfd_vma *pgp)
1667 {
1668   unsigned int count;
1669   asymbol **sym;
1670   unsigned int i;
1671
1672   /* If we've already figured out what GP will be, just return it.  */
1673   *pgp = _bfd_get_gp_value (output_bfd);
1674   if (*pgp)
1675     return TRUE;
1676
1677   count = bfd_get_symcount (output_bfd);
1678   sym = bfd_get_outsymbols (output_bfd);
1679
1680   /* The linker script will have created a symbol named `_gp' with the
1681      appropriate value.  */
1682   if (sym == NULL)
1683     i = count;
1684   else
1685     {
1686       for (i = 0; i < count; i++, sym++)
1687         {
1688           register const char *name;
1689
1690           name = bfd_asymbol_name (*sym);
1691           if (*name == '_' && strcmp (name, "_gp") == 0)
1692             {
1693               *pgp = bfd_asymbol_value (*sym);
1694               _bfd_set_gp_value (output_bfd, *pgp);
1695               break;
1696             }
1697         }
1698     }
1699
1700   if (i >= count)
1701     {
1702       /* Only get the error once.  */
1703       *pgp = 4;
1704       _bfd_set_gp_value (output_bfd, *pgp);
1705       return FALSE;
1706     }
1707
1708   return TRUE;
1709 }
1710
1711 /* We have to figure out the gp value, so that we can adjust the
1712    symbol value correctly.  We look up the symbol _gp in the output
1713    BFD.  If we can't find it, we're stuck.  We cache it in the ELF
1714    target data.  We don't need to adjust the symbol value for an
1715    external symbol if we are producing relocatable output.  */
1716
1717 static bfd_reloc_status_type
1718 mips_elf_final_gp (bfd *output_bfd, asymbol *symbol, bfd_boolean relocatable,
1719                    char **error_message, bfd_vma *pgp)
1720 {
1721   if (bfd_is_und_section (symbol->section)
1722       && ! relocatable)
1723     {
1724       *pgp = 0;
1725       return bfd_reloc_undefined;
1726     }
1727
1728   *pgp = _bfd_get_gp_value (output_bfd);
1729   if (*pgp == 0
1730       && (! relocatable
1731           || (symbol->flags & BSF_SECTION_SYM) != 0))
1732     {
1733       if (relocatable)
1734         {
1735           /* Make up a value.  */
1736           *pgp = symbol->section->output_section->vma /*+ 0x4000*/;
1737           _bfd_set_gp_value (output_bfd, *pgp);
1738         }
1739       else if (!mips_elf_assign_gp (output_bfd, pgp))
1740         {
1741           *error_message =
1742             (char *) _("GP relative relocation when _gp not defined");
1743           return bfd_reloc_dangerous;
1744         }
1745     }
1746
1747   return bfd_reloc_ok;
1748 }
1749
1750 /* Do a R_MIPS_GPREL16 relocation.  This is a 16 bit value which must
1751    become the offset from the gp register.  This function also handles
1752    R_MIPS_LITERAL relocations, although those can be handled more
1753    cleverly because the entries in the .lit8 and .lit4 sections can be
1754    merged.  */
1755
1756 bfd_reloc_status_type
1757 _bfd_mips_elf32_gprel16_reloc (bfd *abfd, arelent *reloc_entry,
1758                                asymbol *symbol, void *data,
1759                                asection *input_section, bfd *output_bfd,
1760                                char **error_message)
1761 {
1762   bfd_boolean relocatable;
1763   bfd_reloc_status_type ret;
1764   bfd_byte *location;
1765   bfd_vma gp;
1766
1767   /* R_MIPS_LITERAL/R_MICROMIPS_LITERAL relocations are defined for local
1768      symbols only.  */
1769   if (literal_reloc_p (reloc_entry->howto->type)
1770       && output_bfd != NULL
1771       && (symbol->flags & BSF_SECTION_SYM) == 0
1772       && (symbol->flags & BSF_LOCAL) != 0)
1773     {
1774       *error_message = (char *)
1775         _("literal relocation occurs for an external symbol");
1776       return bfd_reloc_outofrange;
1777     }
1778
1779   if (output_bfd != NULL)
1780     relocatable = TRUE;
1781   else
1782     {
1783       relocatable = FALSE;
1784       output_bfd = symbol->section->output_section->owner;
1785     }
1786
1787   ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
1788                            &gp);
1789   if (ret != bfd_reloc_ok)
1790     return ret;
1791
1792   location = (bfd_byte *) data + reloc_entry->address;
1793   _bfd_mips_elf_reloc_unshuffle (abfd, reloc_entry->howto->type, FALSE,
1794                                  location);
1795   ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1796                                        input_section, relocatable,
1797                                        data, gp);
1798   _bfd_mips_elf_reloc_shuffle (abfd, reloc_entry->howto->type, !relocatable,
1799                                location);
1800
1801   return ret;
1802 }
1803
1804 /* Do a R_MIPS_GPREL32 relocation.  This is a 32 bit value which must
1805    become the offset from the gp register.  */
1806
1807 static bfd_reloc_status_type
1808 mips_elf_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1809                         void *data, asection *input_section, bfd *output_bfd,
1810                         char **error_message)
1811 {
1812   bfd_boolean relocatable;
1813   bfd_reloc_status_type ret;
1814   bfd_vma gp;
1815
1816   /* R_MIPS_GPREL32 relocations are defined for local symbols only.  */
1817   if (output_bfd != NULL
1818       && (symbol->flags & BSF_SECTION_SYM) == 0
1819       && (symbol->flags & BSF_LOCAL) != 0)
1820     {
1821       *error_message = (char *)
1822         _("32bits gp relative relocation occurs for an external symbol");
1823       return bfd_reloc_outofrange;
1824     }
1825
1826   if (output_bfd != NULL)
1827     relocatable = TRUE;
1828   else
1829     {
1830       relocatable = FALSE;
1831       output_bfd = symbol->section->output_section->owner;
1832     }
1833
1834   ret = mips_elf_final_gp (output_bfd, symbol, relocatable,
1835                            error_message, &gp);
1836   if (ret != bfd_reloc_ok)
1837     return ret;
1838
1839   return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
1840                           relocatable, data, gp);
1841 }
1842
1843 static bfd_reloc_status_type
1844 gprel32_with_gp (bfd *abfd, asymbol *symbol, arelent *reloc_entry,
1845                  asection *input_section, bfd_boolean relocatable,
1846                  void *data, bfd_vma gp)
1847 {
1848   bfd_vma relocation;
1849   bfd_vma val;
1850
1851   if (bfd_is_com_section (symbol->section))
1852     relocation = 0;
1853   else
1854     relocation = symbol->value;
1855
1856   relocation += symbol->section->output_section->vma;
1857   relocation += symbol->section->output_offset;
1858
1859   if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
1860     return bfd_reloc_outofrange;
1861
1862   /* Set val to the offset into the section or symbol.  */
1863   val = reloc_entry->addend;
1864
1865   if (reloc_entry->howto->partial_inplace)
1866     val += bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1867
1868   /* Adjust val for the final section location and GP value.  If we
1869      are producing relocatable output, we don't want to do this for
1870      an external symbol.  */
1871   if (! relocatable
1872       || (symbol->flags & BSF_SECTION_SYM) != 0)
1873     val += relocation - gp;
1874
1875   if (reloc_entry->howto->partial_inplace)
1876     bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
1877   else
1878     reloc_entry->addend = val;
1879
1880   if (relocatable)
1881     reloc_entry->address += input_section->output_offset;
1882
1883   return bfd_reloc_ok;
1884 }
1885
1886 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file.  These are
1887    generated when addresses are 64 bits.  The upper 32 bits are a simple
1888    sign extension.  */
1889
1890 static bfd_reloc_status_type
1891 mips32_64bit_reloc (bfd *abfd, arelent *reloc_entry,
1892                     asymbol *symbol ATTRIBUTE_UNUSED,
1893                     void *data, asection *input_section,
1894                     bfd *output_bfd, char **error_message)
1895 {
1896   bfd_reloc_status_type r;
1897   arelent reloc32;
1898   unsigned long val;
1899   bfd_size_type addr;
1900
1901   /* Do a normal 32 bit relocation on the lower 32 bits.  */
1902   reloc32 = *reloc_entry;
1903   if (bfd_big_endian (abfd))
1904     reloc32.address += 4;
1905   reloc32.howto = &elf_mips_howto_table_rel[R_MIPS_32];
1906   r = bfd_perform_relocation (abfd, &reloc32, data, input_section,
1907                               output_bfd, error_message);
1908
1909   /* Sign extend into the upper 32 bits.  */
1910   val = bfd_get_32 (abfd, (bfd_byte *) data + reloc32.address);
1911   if ((val & 0x80000000) != 0)
1912     val = 0xffffffff;
1913   else
1914     val = 0;
1915   addr = reloc_entry->address;
1916   if (bfd_little_endian (abfd))
1917     addr += 4;
1918   bfd_put_32 (abfd, val, (bfd_byte *) data + addr);
1919
1920   return r;
1921 }
1922
1923 /* Handle a mips16 GP relative reloc.  */
1924
1925 static bfd_reloc_status_type
1926 mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1927                     void *data, asection *input_section, bfd *output_bfd,
1928                     char **error_message)
1929 {
1930   bfd_boolean relocatable;
1931   bfd_reloc_status_type ret;
1932   bfd_byte *location;
1933   bfd_vma gp;
1934
1935   /* If we're relocating, and this is an external symbol, we don't want
1936      to change anything.  */
1937   if (output_bfd != NULL
1938       && (symbol->flags & BSF_SECTION_SYM) == 0
1939       && (symbol->flags & BSF_LOCAL) != 0)
1940     {
1941       reloc_entry->address += input_section->output_offset;
1942       return bfd_reloc_ok;
1943     }
1944
1945   if (output_bfd != NULL)
1946     relocatable = TRUE;
1947   else
1948     {
1949       relocatable = FALSE;
1950       output_bfd = symbol->section->output_section->owner;
1951     }
1952
1953   ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
1954                            &gp);
1955   if (ret != bfd_reloc_ok)
1956     return ret;
1957
1958   location = (bfd_byte *) data + reloc_entry->address;
1959   _bfd_mips_elf_reloc_unshuffle (abfd, reloc_entry->howto->type, FALSE,
1960                                  location);
1961   ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1962                                        input_section, relocatable,
1963                                        data, gp);
1964   _bfd_mips_elf_reloc_shuffle (abfd, reloc_entry->howto->type, !relocatable,
1965                                location);
1966
1967   return ret;
1968 }
1969
1970 /* A mapping from BFD reloc types to MIPS ELF reloc types.  */
1971
1972 struct elf_reloc_map {
1973   bfd_reloc_code_real_type bfd_val;
1974   enum elf_mips_reloc_type elf_val;
1975 };
1976
1977 static const struct elf_reloc_map mips_reloc_map[] =
1978 {
1979   { BFD_RELOC_NONE, R_MIPS_NONE },
1980   { BFD_RELOC_16, R_MIPS_16 },
1981   { BFD_RELOC_32, R_MIPS_32 },
1982   /* There is no BFD reloc for R_MIPS_REL32.  */
1983   { BFD_RELOC_64, R_MIPS_64 },
1984   { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
1985   { BFD_RELOC_HI16_S, R_MIPS_HI16 },
1986   { BFD_RELOC_LO16, R_MIPS_LO16 },
1987   { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
1988   { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
1989   { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
1990   { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
1991   { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
1992   { BFD_RELOC_GPREL32, R_MIPS_GPREL32 },
1993   { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
1994   { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
1995   { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
1996   { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
1997   { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
1998   { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
1999   { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
2000   { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP },
2001   { BFD_RELOC_MIPS_JALR, R_MIPS_JALR },
2002   { BFD_RELOC_MIPS_TLS_DTPMOD32, R_MIPS_TLS_DTPMOD32 },
2003   { BFD_RELOC_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL32 },
2004   { BFD_RELOC_MIPS_TLS_DTPMOD64, R_MIPS_TLS_DTPMOD64 },
2005   { BFD_RELOC_MIPS_TLS_DTPREL64, R_MIPS_TLS_DTPREL64 },
2006   { BFD_RELOC_MIPS_TLS_GD, R_MIPS_TLS_GD },
2007   { BFD_RELOC_MIPS_TLS_LDM, R_MIPS_TLS_LDM },
2008   { BFD_RELOC_MIPS_TLS_DTPREL_HI16, R_MIPS_TLS_DTPREL_HI16 },
2009   { BFD_RELOC_MIPS_TLS_DTPREL_LO16, R_MIPS_TLS_DTPREL_LO16 },
2010   { BFD_RELOC_MIPS_TLS_GOTTPREL, R_MIPS_TLS_GOTTPREL },
2011   { BFD_RELOC_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL32 },
2012   { BFD_RELOC_MIPS_TLS_TPREL64, R_MIPS_TLS_TPREL64 },
2013   { BFD_RELOC_MIPS_TLS_TPREL_HI16, R_MIPS_TLS_TPREL_HI16 },
2014   { BFD_RELOC_MIPS_TLS_TPREL_LO16, R_MIPS_TLS_TPREL_LO16 },
2015   { BFD_RELOC_MIPS_21_PCREL_S2, R_MIPS_PC21_S2 },
2016   { BFD_RELOC_MIPS_26_PCREL_S2, R_MIPS_PC26_S2 },
2017   { BFD_RELOC_MIPS_18_PCREL_S3, R_MIPS_PC18_S3 },
2018   { BFD_RELOC_MIPS_19_PCREL_S2, R_MIPS_PC19_S2 },
2019   { BFD_RELOC_HI16_S_PCREL, R_MIPS_PCHI16 },
2020   { BFD_RELOC_LO16_PCREL, R_MIPS_PCLO16 }
2021 };
2022
2023 static const struct elf_reloc_map mips16_reloc_map[] =
2024 {
2025   { BFD_RELOC_MIPS16_JMP, R_MIPS16_26 - R_MIPS16_min },
2026   { BFD_RELOC_MIPS16_GPREL, R_MIPS16_GPREL - R_MIPS16_min },
2027   { BFD_RELOC_MIPS16_GOT16, R_MIPS16_GOT16 - R_MIPS16_min },
2028   { BFD_RELOC_MIPS16_CALL16, R_MIPS16_CALL16 - R_MIPS16_min },
2029   { BFD_RELOC_MIPS16_HI16_S, R_MIPS16_HI16 - R_MIPS16_min },
2030   { BFD_RELOC_MIPS16_LO16, R_MIPS16_LO16 - R_MIPS16_min },
2031   { BFD_RELOC_MIPS16_TLS_GD, R_MIPS16_TLS_GD - R_MIPS16_min },
2032   { BFD_RELOC_MIPS16_TLS_LDM, R_MIPS16_TLS_LDM - R_MIPS16_min },
2033   { BFD_RELOC_MIPS16_TLS_DTPREL_HI16,
2034     R_MIPS16_TLS_DTPREL_HI16 - R_MIPS16_min },
2035   { BFD_RELOC_MIPS16_TLS_DTPREL_LO16,
2036     R_MIPS16_TLS_DTPREL_LO16 - R_MIPS16_min },
2037   { BFD_RELOC_MIPS16_TLS_GOTTPREL, R_MIPS16_TLS_GOTTPREL - R_MIPS16_min },
2038   { BFD_RELOC_MIPS16_TLS_TPREL_HI16, R_MIPS16_TLS_TPREL_HI16 - R_MIPS16_min },
2039   { BFD_RELOC_MIPS16_TLS_TPREL_LO16, R_MIPS16_TLS_TPREL_LO16 - R_MIPS16_min },
2040   { BFD_RELOC_MIPS16_16_PCREL_S1, R_MIPS16_PC16_S1 - R_MIPS16_min }
2041 };
2042
2043 static const struct elf_reloc_map micromips_reloc_map[] =
2044 {
2045   { BFD_RELOC_MICROMIPS_JMP, R_MICROMIPS_26_S1 - R_MICROMIPS_min },
2046   { BFD_RELOC_MICROMIPS_HI16_S, R_MICROMIPS_HI16 - R_MICROMIPS_min },
2047   { BFD_RELOC_MICROMIPS_LO16, R_MICROMIPS_LO16 - R_MICROMIPS_min },
2048   { BFD_RELOC_MICROMIPS_GPREL16, R_MICROMIPS_GPREL16 - R_MICROMIPS_min },
2049   { BFD_RELOC_MICROMIPS_LITERAL, R_MICROMIPS_LITERAL - R_MICROMIPS_min },
2050   { BFD_RELOC_MICROMIPS_GOT16, R_MICROMIPS_GOT16 - R_MICROMIPS_min },
2051   { BFD_RELOC_MICROMIPS_7_PCREL_S1, R_MICROMIPS_PC7_S1 - R_MICROMIPS_min },
2052   { BFD_RELOC_MICROMIPS_10_PCREL_S1, R_MICROMIPS_PC10_S1 - R_MICROMIPS_min },
2053   { BFD_RELOC_MICROMIPS_16_PCREL_S1, R_MICROMIPS_PC16_S1 - R_MICROMIPS_min },
2054   { BFD_RELOC_MICROMIPS_CALL16, R_MICROMIPS_CALL16 - R_MICROMIPS_min },
2055   { BFD_RELOC_MICROMIPS_GOT_DISP, R_MICROMIPS_GOT_DISP - R_MICROMIPS_min },
2056   { BFD_RELOC_MICROMIPS_GOT_PAGE, R_MICROMIPS_GOT_PAGE - R_MICROMIPS_min },
2057   { BFD_RELOC_MICROMIPS_GOT_OFST, R_MICROMIPS_GOT_OFST - R_MICROMIPS_min },
2058   { BFD_RELOC_MICROMIPS_GOT_HI16, R_MICROMIPS_GOT_HI16 - R_MICROMIPS_min },
2059   { BFD_RELOC_MICROMIPS_GOT_LO16, R_MICROMIPS_GOT_LO16 - R_MICROMIPS_min },
2060   { BFD_RELOC_MICROMIPS_SUB, R_MICROMIPS_SUB - R_MICROMIPS_min },
2061   { BFD_RELOC_MICROMIPS_HIGHER, R_MICROMIPS_HIGHER - R_MICROMIPS_min },
2062   { BFD_RELOC_MICROMIPS_HIGHEST, R_MICROMIPS_HIGHEST - R_MICROMIPS_min },
2063   { BFD_RELOC_MICROMIPS_CALL_HI16, R_MICROMIPS_CALL_HI16 - R_MICROMIPS_min },
2064   { BFD_RELOC_MICROMIPS_CALL_LO16, R_MICROMIPS_CALL_LO16 - R_MICROMIPS_min },
2065   { BFD_RELOC_MICROMIPS_SCN_DISP, R_MICROMIPS_SCN_DISP - R_MICROMIPS_min },
2066   { BFD_RELOC_MICROMIPS_JALR, R_MICROMIPS_JALR - R_MICROMIPS_min },
2067   /* There is no BFD reloc for R_MICROMIPS_HI0_LO16.  */
2068   { BFD_RELOC_MICROMIPS_TLS_GD, R_MICROMIPS_TLS_GD - R_MICROMIPS_min },
2069   { BFD_RELOC_MICROMIPS_TLS_LDM, R_MICROMIPS_TLS_LDM - R_MICROMIPS_min },
2070   { BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16,
2071     R_MICROMIPS_TLS_DTPREL_HI16 - R_MICROMIPS_min },
2072   { BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16,
2073     R_MICROMIPS_TLS_DTPREL_LO16 - R_MICROMIPS_min },
2074   { BFD_RELOC_MICROMIPS_TLS_GOTTPREL,
2075     R_MICROMIPS_TLS_GOTTPREL - R_MICROMIPS_min },
2076   { BFD_RELOC_MICROMIPS_TLS_TPREL_HI16,
2077     R_MICROMIPS_TLS_TPREL_HI16 - R_MICROMIPS_min },
2078   { BFD_RELOC_MICROMIPS_TLS_TPREL_LO16,
2079     R_MICROMIPS_TLS_TPREL_LO16 - R_MICROMIPS_min },
2080   /* There is no BFD reloc for R_MICROMIPS_GPREL7_S2.  */
2081   /* There is no BFD reloc for R_MICROMIPS_PC23_S2.  */
2082 };
2083
2084 /* Given a BFD reloc type, return a howto structure.  */
2085
2086 static reloc_howto_type *
2087 bfd_elf32_bfd_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code)
2088 {
2089   unsigned int i;
2090   reloc_howto_type *howto_table = elf_mips_howto_table_rel;
2091   reloc_howto_type *howto16_table = elf_mips16_howto_table_rel;
2092   reloc_howto_type *howto_micromips_table = elf_micromips_howto_table_rel;
2093
2094   for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map);
2095        i++)
2096     {
2097       if (mips_reloc_map[i].bfd_val == code)
2098         return &howto_table[(int) mips_reloc_map[i].elf_val];
2099     }
2100
2101   for (i = 0; i < sizeof (mips16_reloc_map) / sizeof (struct elf_reloc_map);
2102        i++)
2103     {
2104       if (mips16_reloc_map[i].bfd_val == code)
2105         return &howto16_table[(int) mips16_reloc_map[i].elf_val];
2106     }
2107
2108   for (i = 0; i < sizeof (micromips_reloc_map) / sizeof (struct elf_reloc_map);
2109        i++)
2110     {
2111       if (micromips_reloc_map[i].bfd_val == code)
2112         return &howto_micromips_table[(int) micromips_reloc_map[i].elf_val];
2113     }
2114
2115   switch (code)
2116     {
2117     default:
2118       bfd_set_error (bfd_error_bad_value);
2119       return NULL;
2120
2121     case BFD_RELOC_CTOR:
2122       /* We need to handle BFD_RELOC_CTOR specially.
2123          Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
2124          size of addresses of the ABI.  */
2125       if ((elf_elfheader (abfd)->e_flags & (E_MIPS_ABI_O64
2126                                             | E_MIPS_ABI_EABI64)) != 0)
2127         return &elf_mips_ctor64_howto;
2128       else
2129         return &howto_table[(int) R_MIPS_32];
2130
2131     case BFD_RELOC_VTABLE_INHERIT:
2132       return &elf_mips_gnu_vtinherit_howto;
2133     case BFD_RELOC_VTABLE_ENTRY:
2134       return &elf_mips_gnu_vtentry_howto;
2135     case BFD_RELOC_32_PCREL:
2136       return &elf_mips_gnu_pcrel32;
2137     case BFD_RELOC_MIPS_COPY:
2138       return &elf_mips_copy_howto;
2139     case BFD_RELOC_MIPS_JUMP_SLOT:
2140       return &elf_mips_jump_slot_howto;
2141     case BFD_RELOC_MIPS_EH:
2142       return &elf_mips_eh_howto;
2143     }
2144 }
2145
2146 static reloc_howto_type *
2147 bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2148                                  const char *r_name)
2149 {
2150   unsigned int i;
2151
2152   for (i = 0;
2153        i < (sizeof (elf_mips_howto_table_rel)
2154             / sizeof (elf_mips_howto_table_rel[0]));
2155        i++)
2156     if (elf_mips_howto_table_rel[i].name != NULL
2157         && strcasecmp (elf_mips_howto_table_rel[i].name, r_name) == 0)
2158       return &elf_mips_howto_table_rel[i];
2159
2160   for (i = 0;
2161        i < (sizeof (elf_mips16_howto_table_rel)
2162             / sizeof (elf_mips16_howto_table_rel[0]));
2163        i++)
2164     if (elf_mips16_howto_table_rel[i].name != NULL
2165         && strcasecmp (elf_mips16_howto_table_rel[i].name, r_name) == 0)
2166       return &elf_mips16_howto_table_rel[i];
2167
2168   for (i = 0;
2169        i < (sizeof (elf_micromips_howto_table_rel)
2170             / sizeof (elf_micromips_howto_table_rel[0]));
2171        i++)
2172     if (elf_micromips_howto_table_rel[i].name != NULL
2173         && strcasecmp (elf_micromips_howto_table_rel[i].name, r_name) == 0)
2174       return &elf_micromips_howto_table_rel[i];
2175
2176   if (strcasecmp (elf_mips_gnu_pcrel32.name, r_name) == 0)
2177     return &elf_mips_gnu_pcrel32;
2178   if (strcasecmp (elf_mips_gnu_rel16_s2.name, r_name) == 0)
2179     return &elf_mips_gnu_rel16_s2;
2180   if (strcasecmp (elf_mips_gnu_vtinherit_howto.name, r_name) == 0)
2181     return &elf_mips_gnu_vtinherit_howto;
2182   if (strcasecmp (elf_mips_gnu_vtentry_howto.name, r_name) == 0)
2183     return &elf_mips_gnu_vtentry_howto;
2184   if (strcasecmp (elf_mips_copy_howto.name, r_name) == 0)
2185     return &elf_mips_copy_howto;
2186   if (strcasecmp (elf_mips_jump_slot_howto.name, r_name) == 0)
2187     return &elf_mips_jump_slot_howto;
2188   if (strcasecmp (elf_mips_eh_howto.name, r_name) == 0)
2189     return &elf_mips_eh_howto;
2190
2191   return NULL;
2192 }
2193
2194 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure.  */
2195
2196 static reloc_howto_type *
2197 mips_elf32_rtype_to_howto (bfd *abfd,
2198                            unsigned int r_type,
2199                            bfd_boolean rela_p ATTRIBUTE_UNUSED)
2200 {
2201   switch (r_type)
2202     {
2203     case R_MIPS_GNU_VTINHERIT:
2204       return &elf_mips_gnu_vtinherit_howto;
2205     case R_MIPS_GNU_VTENTRY:
2206       return &elf_mips_gnu_vtentry_howto;
2207     case R_MIPS_GNU_REL16_S2:
2208       return &elf_mips_gnu_rel16_s2;
2209     case R_MIPS_PC32:
2210       return &elf_mips_gnu_pcrel32;
2211     case R_MIPS_COPY:
2212       return &elf_mips_copy_howto;
2213     case R_MIPS_JUMP_SLOT:
2214       return &elf_mips_jump_slot_howto;
2215     case R_MIPS_EH:
2216       return &elf_mips_eh_howto;
2217     default:
2218       if (r_type >= R_MICROMIPS_min && r_type < R_MICROMIPS_max)
2219         return &elf_micromips_howto_table_rel[r_type - R_MICROMIPS_min];
2220       if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max)
2221         return &elf_mips16_howto_table_rel[r_type - R_MIPS16_min];
2222       if (r_type >= (unsigned int) R_MIPS_max)
2223         {
2224           _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2225                               abfd, r_type);
2226           bfd_set_error (bfd_error_bad_value);
2227           return NULL;
2228         }
2229       return &elf_mips_howto_table_rel[r_type];
2230     }
2231 }
2232
2233 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure.  */
2234
2235 static bfd_boolean
2236 mips_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
2237 {
2238   const struct elf_backend_data *bed;
2239   unsigned int r_type;
2240
2241   r_type = ELF32_R_TYPE (dst->r_info);
2242   bed = get_elf_backend_data (abfd);
2243   cache_ptr->howto = bed->elf_backend_mips_rtype_to_howto (abfd, r_type, FALSE);
2244   if (cache_ptr->howto == NULL)
2245     {
2246       /* xgettext:c-format */
2247       _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type);
2248       bfd_set_error (bfd_error_bad_value);
2249       return FALSE;
2250     }
2251
2252   /* The addend for a GPREL16 or LITERAL relocation comes from the GP
2253      value for the object file.  We get the addend now, rather than
2254      when we do the relocation, because the symbol manipulations done
2255      by the linker may cause us to lose track of the input BFD.  */
2256   if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
2257       && (gprel16_reloc_p (r_type) || literal_reloc_p (r_type)))
2258     cache_ptr->addend = elf_gp (abfd);
2259
2260   return TRUE;
2261 }
2262
2263 /* Given a MIPS Elf_Internal_Rela, fill in an arelent structure.  */
2264
2265 static bfd_boolean
2266 mips_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
2267 {
2268   return mips_info_to_howto_rel (abfd, cache_ptr, dst);
2269
2270   /* If we ever need to do any extra processing with dst->r_addend
2271      (the field omitted in an Elf_Internal_Rel) we can do it here.  */
2272 }
2273 \f
2274 /* Determine whether a symbol is global for the purposes of splitting
2275    the symbol table into global symbols and local symbols.  At least
2276    on Irix 5, this split must be between section symbols and all other
2277    symbols.  On most ELF targets the split is between static symbols
2278    and externally visible symbols.  */
2279
2280 static bfd_boolean
2281 mips_elf_sym_is_global (bfd *abfd ATTRIBUTE_UNUSED, asymbol *sym)
2282 {
2283   if (SGI_COMPAT (abfd))
2284     return (sym->flags & BSF_SECTION_SYM) == 0;
2285   else
2286     return ((sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE)) != 0
2287             || bfd_is_und_section (bfd_get_section (sym))
2288             || bfd_is_com_section (bfd_get_section (sym)));
2289 }
2290 \f
2291 /* Set the right machine number for a MIPS ELF file.  */
2292
2293 static bfd_boolean
2294 mips_elf32_object_p (bfd *abfd)
2295 {
2296   unsigned long mach;
2297
2298   if (ABI_N32_P (abfd))
2299     return FALSE;
2300
2301   /* Irix 5 and 6 are broken.  Object file symbol tables are not always
2302      sorted correctly such that local symbols precede global symbols,
2303      and the sh_info field in the symbol table is not always right.  */
2304   if (SGI_COMPAT (abfd))
2305     elf_bad_symtab (abfd) = TRUE;
2306
2307   mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
2308   bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
2309   return TRUE;
2310 }
2311 \f
2312 /* MIPS ELF local labels start with '$', not 'L'.  */
2313
2314 static bfd_boolean
2315 mips_elf_is_local_label_name (bfd *abfd, const char *name)
2316 {
2317   if (name[0] == '$')
2318     return TRUE;
2319
2320   /* On Irix 6, the labels go back to starting with '.', so we accept
2321      the generic ELF local label syntax as well.  */
2322   return _bfd_elf_is_local_label_name (abfd, name);
2323 }
2324 \f
2325 /* Support for core dump NOTE sections.  */
2326 static bfd_boolean
2327 elf32_mips_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2328 {
2329   int offset;
2330   unsigned int size;
2331
2332   switch (note->descsz)
2333     {
2334       default:
2335         return FALSE;
2336
2337       case 256:         /* Linux/MIPS */
2338         /* pr_cursig */
2339         elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
2340
2341         /* pr_pid */
2342         elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
2343
2344         /* pr_reg */
2345         offset = 72;
2346         size = 180;
2347
2348         break;
2349     }
2350
2351   /* Make a ".reg/999" section.  */
2352   return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2353                                           size, note->descpos + offset);
2354 }
2355
2356 static bfd_boolean
2357 elf32_mips_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2358 {
2359   switch (note->descsz)
2360     {
2361       default:
2362         return FALSE;
2363
2364       case 128:         /* Linux/MIPS elf_prpsinfo */
2365         elf_tdata (abfd)->core->pid
2366          = bfd_get_32 (abfd, note->descdata + 16);
2367         elf_tdata (abfd)->core->program
2368          = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
2369         elf_tdata (abfd)->core->command
2370          = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
2371     }
2372
2373   /* Note that for some reason, a spurious space is tacked
2374      onto the end of the args in some (at least one anyway)
2375      implementations, so strip it off if it exists.  */
2376
2377   {
2378     char *command = elf_tdata (abfd)->core->command;
2379     int n = strlen (command);
2380
2381     if (0 < n && command[n - 1] == ' ')
2382       command[n - 1] = '\0';
2383   }
2384
2385   return TRUE;
2386 }
2387
2388 /* Write Linux core PRSTATUS note into core file.  */
2389
2390 static char *
2391 elf32_mips_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type,
2392                              ...)
2393 {
2394   switch (note_type)
2395     {
2396     default:
2397       return NULL;
2398
2399     case NT_PRPSINFO:
2400       BFD_FAIL ();
2401       return NULL;
2402
2403     case NT_PRSTATUS:
2404       {
2405         char data[256];
2406         va_list ap;
2407         long pid;
2408         int cursig;
2409         const void *greg;
2410
2411         va_start (ap, note_type);
2412         memset (data, 0, 72);
2413         pid = va_arg (ap, long);
2414         bfd_put_32 (abfd, pid, data + 24);
2415         cursig = va_arg (ap, int);
2416         bfd_put_16 (abfd, cursig, data + 12);
2417         greg = va_arg (ap, const void *);
2418         memcpy (data + 72, greg, 180);
2419         memset (data + 252, 0, 4);
2420         va_end (ap);
2421         return elfcore_write_note (abfd, buf, bufsiz,
2422                                    "CORE", note_type, data, sizeof (data));
2423       }
2424     }
2425 }
2426 \f
2427 /* Depending on the target vector we generate some version of Irix
2428    executables or "normal" MIPS ELF ABI executables.  */
2429 static irix_compat_t
2430 elf32_mips_irix_compat (bfd *abfd)
2431 {
2432   if ((abfd->xvec == &mips_elf32_be_vec)
2433       || (abfd->xvec == &mips_elf32_le_vec))
2434     return ict_irix5;
2435   else
2436     return ict_none;
2437 }
2438 \f
2439 /* ECOFF swapping routines.  These are used when dealing with the
2440    .mdebug section, which is in the ECOFF debugging format.  */
2441 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
2442   /* Symbol table magic number.  */
2443   magicSym,
2444   /* Alignment of debugging information.  E.g., 4.  */
2445   4,
2446   /* Sizes of external symbolic information.  */
2447   sizeof (struct hdr_ext),
2448   sizeof (struct dnr_ext),
2449   sizeof (struct pdr_ext),
2450   sizeof (struct sym_ext),
2451   sizeof (struct opt_ext),
2452   sizeof (struct fdr_ext),
2453   sizeof (struct rfd_ext),
2454   sizeof (struct ext_ext),
2455   /* Functions to swap in external symbolic data.  */
2456   ecoff_swap_hdr_in,
2457   ecoff_swap_dnr_in,
2458   ecoff_swap_pdr_in,
2459   ecoff_swap_sym_in,
2460   ecoff_swap_opt_in,
2461   ecoff_swap_fdr_in,
2462   ecoff_swap_rfd_in,
2463   ecoff_swap_ext_in,
2464   _bfd_ecoff_swap_tir_in,
2465   _bfd_ecoff_swap_rndx_in,
2466   /* Functions to swap out external symbolic data.  */
2467   ecoff_swap_hdr_out,
2468   ecoff_swap_dnr_out,
2469   ecoff_swap_pdr_out,
2470   ecoff_swap_sym_out,
2471   ecoff_swap_opt_out,
2472   ecoff_swap_fdr_out,
2473   ecoff_swap_rfd_out,
2474   ecoff_swap_ext_out,
2475   _bfd_ecoff_swap_tir_out,
2476   _bfd_ecoff_swap_rndx_out,
2477   /* Function to read in symbolic data.  */
2478   _bfd_mips_elf_read_ecoff_info
2479 };
2480 \f
2481 #define ELF_ARCH                        bfd_arch_mips
2482 #define ELF_TARGET_ID                   MIPS_ELF_DATA
2483 #define ELF_MACHINE_CODE                EM_MIPS
2484
2485 #define elf_backend_collect             TRUE
2486 #define elf_backend_type_change_ok      TRUE
2487 #define elf_backend_can_gc_sections     TRUE
2488 #define elf_backend_gc_mark_extra_sections \
2489                                         _bfd_mips_elf_gc_mark_extra_sections
2490 #define elf_info_to_howto               mips_info_to_howto_rela
2491 #define elf_info_to_howto_rel           mips_info_to_howto_rel
2492 #define elf_backend_sym_is_global       mips_elf_sym_is_global
2493 #define elf_backend_object_p            mips_elf32_object_p
2494 #define elf_backend_symbol_processing   _bfd_mips_elf_symbol_processing
2495 #define elf_backend_section_processing  _bfd_mips_elf_section_processing
2496 #define elf_backend_section_from_shdr   _bfd_mips_elf_section_from_shdr
2497 #define elf_backend_fake_sections       _bfd_mips_elf_fake_sections
2498 #define elf_backend_section_from_bfd_section \
2499                                         _bfd_mips_elf_section_from_bfd_section
2500 #define elf_backend_add_symbol_hook     _bfd_mips_elf_add_symbol_hook
2501 #define elf_backend_link_output_symbol_hook \
2502                                         _bfd_mips_elf_link_output_symbol_hook
2503 #define elf_backend_create_dynamic_sections \
2504                                         _bfd_mips_elf_create_dynamic_sections
2505 #define elf_backend_check_relocs        _bfd_mips_elf_check_relocs
2506 #define elf_backend_merge_symbol_attribute \
2507                                         _bfd_mips_elf_merge_symbol_attribute
2508 #define elf_backend_get_target_dtag     _bfd_mips_elf_get_target_dtag
2509 #define elf_backend_adjust_dynamic_symbol \
2510                                         _bfd_mips_elf_adjust_dynamic_symbol
2511 #define elf_backend_always_size_sections \
2512                                         _bfd_mips_elf_always_size_sections
2513 #define elf_backend_size_dynamic_sections \
2514                                         _bfd_mips_elf_size_dynamic_sections
2515 #define elf_backend_init_index_section  _bfd_elf_init_1_index_section
2516 #define elf_backend_relocate_section    _bfd_mips_elf_relocate_section
2517 #define elf_backend_finish_dynamic_symbol \
2518                                         _bfd_mips_elf_finish_dynamic_symbol
2519 #define elf_backend_finish_dynamic_sections \
2520                                         _bfd_mips_elf_finish_dynamic_sections
2521 #define elf_backend_final_write_processing \
2522                                         _bfd_mips_elf_final_write_processing
2523 #define elf_backend_additional_program_headers \
2524                                         _bfd_mips_elf_additional_program_headers
2525 #define elf_backend_modify_segment_map  _bfd_mips_elf_modify_segment_map
2526 #define elf_backend_gc_mark_hook        _bfd_mips_elf_gc_mark_hook
2527 #define elf_backend_copy_indirect_symbol \
2528                                         _bfd_mips_elf_copy_indirect_symbol
2529 #define elf_backend_grok_prstatus       elf32_mips_grok_prstatus
2530 #define elf_backend_grok_psinfo         elf32_mips_grok_psinfo
2531 #define elf_backend_ecoff_debug_swap    &mips_elf32_ecoff_debug_swap
2532
2533 #define elf_backend_got_header_size     (4 * MIPS_RESERVED_GOTNO)
2534 #define elf_backend_want_dynrelro       1
2535 #define elf_backend_may_use_rel_p       1
2536 #define elf_backend_may_use_rela_p      0
2537 #define elf_backend_default_use_rela_p  0
2538 #define elf_backend_sign_extend_vma     TRUE
2539 #define elf_backend_plt_readonly        1
2540
2541 #define elf_backend_discard_info        _bfd_mips_elf_discard_info
2542 #define elf_backend_ignore_discarded_relocs \
2543                                         _bfd_mips_elf_ignore_discarded_relocs
2544 #define elf_backend_write_section       _bfd_mips_elf_write_section
2545 #define elf_backend_mips_irix_compat    elf32_mips_irix_compat
2546 #define elf_backend_mips_rtype_to_howto mips_elf32_rtype_to_howto
2547 #define elf_backend_sort_relocs_p       _bfd_mips_elf_sort_relocs_p
2548
2549 #define bfd_elf32_bfd_is_local_label_name \
2550                                         mips_elf_is_local_label_name
2551 #define bfd_elf32_bfd_is_target_special_symbol \
2552                                         _bfd_mips_elf_is_target_special_symbol
2553 #define bfd_elf32_get_synthetic_symtab  _bfd_mips_elf_get_synthetic_symtab
2554 #define bfd_elf32_find_nearest_line     _bfd_mips_elf_find_nearest_line
2555 #define bfd_elf32_find_inliner_info     _bfd_mips_elf_find_inliner_info
2556 #define bfd_elf32_new_section_hook      _bfd_mips_elf_new_section_hook
2557 #define bfd_elf32_set_section_contents  _bfd_mips_elf_set_section_contents
2558 #define bfd_elf32_bfd_get_relocated_section_contents \
2559                                 _bfd_elf_mips_get_relocated_section_contents
2560 #define bfd_elf32_bfd_link_hash_table_create \
2561                                         _bfd_mips_elf_link_hash_table_create
2562 #define bfd_elf32_bfd_final_link        _bfd_mips_elf_final_link
2563 #define bfd_elf32_bfd_merge_private_bfd_data \
2564                                         _bfd_mips_elf_merge_private_bfd_data
2565 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
2566 #define bfd_elf32_bfd_print_private_bfd_data \
2567                                         _bfd_mips_elf_print_private_bfd_data
2568 #define bfd_elf32_bfd_relax_section     _bfd_mips_elf_relax_section
2569 #define bfd_elf32_mkobject              _bfd_mips_elf_mkobject
2570
2571 /* Support for SGI-ish mips targets.  */
2572 #define TARGET_LITTLE_SYM               mips_elf32_le_vec
2573 #define TARGET_LITTLE_NAME              "elf32-littlemips"
2574 #define TARGET_BIG_SYM                  mips_elf32_be_vec
2575 #define TARGET_BIG_NAME                 "elf32-bigmips"
2576
2577 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
2578    a value of 0x1000, and we are compatible.  */
2579 #define ELF_MAXPAGESIZE                 0x1000
2580 #define ELF_COMMONPAGESIZE              0x1000
2581
2582 #include "elf32-target.h"
2583
2584 /* Support for traditional mips targets.  */
2585 #undef TARGET_LITTLE_SYM
2586 #undef TARGET_LITTLE_NAME
2587 #undef TARGET_BIG_SYM
2588 #undef TARGET_BIG_NAME
2589
2590 #undef ELF_MAXPAGESIZE
2591 #undef ELF_COMMONPAGESIZE
2592
2593 #define TARGET_LITTLE_SYM               mips_elf32_trad_le_vec
2594 #define TARGET_LITTLE_NAME              "elf32-tradlittlemips"
2595 #define TARGET_BIG_SYM                  mips_elf32_trad_be_vec
2596 #define TARGET_BIG_NAME                 "elf32-tradbigmips"
2597
2598 /* The MIPS ABI says at Page 5-1:
2599    Virtual addresses and file offsets for MIPS segments are congruent
2600    modulo 64 KByte (0x10000) or larger powers of 2.  Because 64 KBytes
2601    is the maximum page size, the files are suitable for paging
2602    regardless of physical page size.  */
2603 #define ELF_MAXPAGESIZE                 0x10000
2604 #define ELF_COMMONPAGESIZE              0x1000
2605 #define elf32_bed                       elf32_tradbed
2606
2607 #undef elf_backend_write_core_note
2608 #define elf_backend_write_core_note     elf32_mips_write_core_note
2609
2610 /* Include the target file again for this target.  */
2611 #include "elf32-target.h"
2612
2613 /* FreeBSD support.  */
2614
2615 #undef TARGET_LITTLE_SYM
2616 #undef TARGET_LITTLE_NAME
2617 #undef TARGET_BIG_SYM
2618 #undef TARGET_BIG_NAME
2619
2620 #define TARGET_LITTLE_SYM               mips_elf32_tradfbsd_le_vec
2621 #define TARGET_LITTLE_NAME              "elf32-tradlittlemips-freebsd"
2622 #define TARGET_BIG_SYM                  mips_elf32_tradfbsd_be_vec
2623 #define TARGET_BIG_NAME                 "elf32-tradbigmips-freebsd"
2624
2625 #undef  ELF_OSABI
2626 #define ELF_OSABI                       ELFOSABI_FREEBSD
2627
2628 #undef  elf32_bed
2629 #define elf32_bed                               elf32_fbsd_tradbed
2630
2631 #undef elf_backend_write_core_note
2632
2633 #include "elf32-target.h"
2634 /* Implement elf_backend_final_write_processing for VxWorks.  */
2635
2636 static void
2637 mips_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
2638 {
2639   _bfd_mips_elf_final_write_processing (abfd, linker);
2640   elf_vxworks_final_write_processing (abfd, linker);
2641 }
2642
2643 #undef TARGET_LITTLE_SYM
2644 #undef TARGET_LITTLE_NAME
2645 #undef TARGET_BIG_SYM
2646 #undef TARGET_BIG_NAME
2647
2648 #undef ELF_MAXPAGESIZE
2649 #undef ELF_COMMONPAGESIZE
2650
2651 #define TARGET_LITTLE_SYM               mips_elf32_vxworks_le_vec
2652 #define TARGET_LITTLE_NAME              "elf32-littlemips-vxworks"
2653 #define TARGET_BIG_SYM                  mips_elf32_vxworks_be_vec
2654 #define TARGET_BIG_NAME                 "elf32-bigmips-vxworks"
2655 #undef  ELF_OSABI
2656
2657 #undef elf32_bed
2658 #define elf32_bed                       elf32_mips_vxworks_bed
2659
2660 #define ELF_MAXPAGESIZE                 0x1000
2661 #define ELF_COMMONPAGESIZE              0x1000
2662
2663 #undef elf_backend_want_got_plt
2664 #define elf_backend_want_got_plt                1
2665 #undef elf_backend_want_plt_sym
2666 #define elf_backend_want_plt_sym                1
2667 #undef elf_backend_may_use_rel_p
2668 #define elf_backend_may_use_rel_p               0
2669 #undef elf_backend_may_use_rela_p
2670 #define elf_backend_may_use_rela_p              1
2671 #undef elf_backend_default_use_rela_p
2672 #define elf_backend_default_use_rela_p          1
2673 #undef elf_backend_got_header_size
2674 #define elf_backend_got_header_size             (4 * 3)
2675 #undef elf_backend_dtrel_excludes_plt
2676 #define elf_backend_dtrel_excludes_plt          1
2677
2678 #undef elf_backend_finish_dynamic_symbol
2679 #define elf_backend_finish_dynamic_symbol \
2680   _bfd_mips_vxworks_finish_dynamic_symbol
2681 #undef bfd_elf32_bfd_link_hash_table_create
2682 #define bfd_elf32_bfd_link_hash_table_create \
2683   _bfd_mips_vxworks_link_hash_table_create
2684 #undef elf_backend_add_symbol_hook
2685 #define elf_backend_add_symbol_hook \
2686   elf_vxworks_add_symbol_hook
2687 #undef elf_backend_link_output_symbol_hook
2688 #define elf_backend_link_output_symbol_hook \
2689   elf_vxworks_link_output_symbol_hook
2690 #undef elf_backend_emit_relocs
2691 #define elf_backend_emit_relocs \
2692   elf_vxworks_emit_relocs
2693 #undef elf_backend_final_write_processing
2694 #define elf_backend_final_write_processing \
2695   mips_vxworks_final_write_processing
2696
2697 #undef elf_backend_additional_program_headers
2698 #undef elf_backend_modify_segment_map
2699 #undef elf_backend_symbol_processing
2700 /* NOTE: elf_backend_rela_normal is not defined for MIPS.  */
2701
2702 #undef bfd_elf32_get_synthetic_symtab
2703
2704 #include "elf32-target.h"