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