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