1 /* MIPS-specific support for 32-bit ELF
2    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3    2003, 2004, 2005, 2007 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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, 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 "sysdep.h"
33 #include "bfd.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_gprel_reloc
65   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
66 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
67   (bfd *, bfd_reloc_code_real_type);
68 static reloc_howto_type *mips_elf_n32_rtype_to_howto
69   (unsigned int, bfd_boolean);
70 static void mips_info_to_howto_rel
71   (bfd *, arelent *, Elf_Internal_Rela *);
72 static void mips_info_to_howto_rela
73   (bfd *, arelent *, Elf_Internal_Rela *);
74 static bfd_boolean mips_elf_sym_is_global
75   (bfd *, asymbol *);
76 static bfd_boolean mips_elf_n32_object_p
77   (bfd *);
78 static bfd_boolean elf32_mips_grok_prstatus
79   (bfd *, Elf_Internal_Note *);
80 static bfd_boolean elf32_mips_grok_psinfo
81   (bfd *, Elf_Internal_Note *);
82 static irix_compat_t elf_n32_mips_irix_compat
83   (bfd *);
84 
85 extern const bfd_target bfd_elf32_nbigmips_vec;
86 extern const bfd_target bfd_elf32_nlittlemips_vec;
87 
88 /* Nonzero if ABFD is using the N32 ABI.  */
89 #define ABI_N32_P(abfd) \
90   ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
91 
92 /* Whether we are trying to be compatible with IRIX at all.  */
93 #define SGI_COMPAT(abfd) \
94   (elf_n32_mips_irix_compat (abfd) != ict_none)
95 
96 /* The number of local .got entries we reserve.  */
97 #define MIPS_RESERVED_GOTNO (2)
98 
99 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
100    from smaller values.  Start with zero, widen, *then* decrement.  */
101 #define MINUS_ONE	(((bfd_vma)0) - 1)
102 
103 /* The relocation table used for SHT_REL sections.  */
104 
105 static reloc_howto_type elf_mips_howto_table_rel[] =
106 {
107   /* No relocation.  */
108   HOWTO (R_MIPS_NONE,		/* type */
109 	 0,			/* rightshift */
110 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
111 	 0,			/* bitsize */
112 	 FALSE,			/* pc_relative */
113 	 0,			/* bitpos */
114 	 complain_overflow_dont, /* complain_on_overflow */
115 	 _bfd_mips_elf_generic_reloc, /* special_function */
116 	 "R_MIPS_NONE",		/* name */
117 	 FALSE,			/* partial_inplace */
118 	 0,			/* src_mask */
119 	 0,			/* dst_mask */
120 	 FALSE),		/* pcrel_offset */
121 
122   /* 16 bit relocation.  */
123   HOWTO (R_MIPS_16,		/* type */
124 	 0,			/* rightshift */
125 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
126 	 16,			/* bitsize */
127 	 FALSE,			/* pc_relative */
128 	 0,			/* bitpos */
129 	 complain_overflow_signed, /* complain_on_overflow */
130 	 _bfd_mips_elf_generic_reloc, /* special_function */
131 	 "R_MIPS_16",		/* name */
132 	 TRUE,			/* partial_inplace */
133 	 0x0000ffff,		/* src_mask */
134 	 0x0000ffff,		/* dst_mask */
135 	 FALSE),		/* pcrel_offset */
136 
137   /* 32 bit relocation.  */
138   HOWTO (R_MIPS_32,		/* type */
139 	 0,			/* rightshift */
140 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
141 	 32,			/* bitsize */
142 	 FALSE,			/* pc_relative */
143 	 0,			/* bitpos */
144 	 complain_overflow_dont, /* complain_on_overflow */
145 	 _bfd_mips_elf_generic_reloc, /* special_function */
146 	 "R_MIPS_32",		/* name */
147 	 TRUE,			/* partial_inplace */
148 	 0xffffffff,		/* src_mask */
149 	 0xffffffff,		/* dst_mask */
150 	 FALSE),		/* pcrel_offset */
151 
152   /* 32 bit symbol relative relocation.  */
153   HOWTO (R_MIPS_REL32,		/* type */
154 	 0,			/* rightshift */
155 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
156 	 32,			/* bitsize */
157 	 FALSE,			/* pc_relative */
158 	 0,			/* bitpos */
159 	 complain_overflow_dont, /* complain_on_overflow */
160 	 _bfd_mips_elf_generic_reloc, /* special_function */
161 	 "R_MIPS_REL32",	/* name */
162 	 TRUE,			/* partial_inplace */
163 	 0xffffffff,		/* src_mask */
164 	 0xffffffff,		/* dst_mask */
165 	 FALSE),		/* pcrel_offset */
166 
167   /* 26 bit jump address.  */
168   HOWTO (R_MIPS_26,		/* type */
169 	 2,			/* rightshift */
170 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
171 	 26,			/* bitsize */
172 	 FALSE,			/* pc_relative */
173 	 0,			/* bitpos */
174 	 complain_overflow_dont, /* complain_on_overflow */
175 	 			/* This needs complex overflow
176 				   detection, because the upper four
177 				   bits must match the PC + 4.  */
178 	 _bfd_mips_elf_generic_reloc, /* special_function */
179 	 "R_MIPS_26",		/* name */
180 	 TRUE,			/* partial_inplace */
181 	 0x03ffffff,		/* src_mask */
182 	 0x03ffffff,		/* dst_mask */
183 	 FALSE),		/* pcrel_offset */
184 
185   /* R_MIPS_HI16 and R_MIPS_LO16 are unsupported for NewABI REL.
186      However, the native IRIX6 tools use them, so we try our best. */
187 
188   /* High 16 bits of symbol value.  */
189   HOWTO (R_MIPS_HI16,		/* type */
190 	 16,			/* rightshift */
191 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
192 	 16,			/* bitsize */
193 	 FALSE,			/* pc_relative */
194 	 0,			/* bitpos */
195 	 complain_overflow_dont, /* complain_on_overflow */
196 	 _bfd_mips_elf_hi16_reloc, /* special_function */
197 	 "R_MIPS_HI16",		/* name */
198 	 TRUE,			/* partial_inplace */
199 	 0x0000ffff,		/* src_mask */
200 	 0x0000ffff,		/* dst_mask */
201 	 FALSE),		/* pcrel_offset */
202 
203   /* Low 16 bits of symbol value.  */
204   HOWTO (R_MIPS_LO16,		/* type */
205 	 0,			/* rightshift */
206 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
207 	 16,			/* bitsize */
208 	 FALSE,			/* pc_relative */
209 	 0,			/* bitpos */
210 	 complain_overflow_dont, /* complain_on_overflow */
211 	 _bfd_mips_elf_lo16_reloc, /* special_function */
212 	 "R_MIPS_LO16",		/* name */
213 	 TRUE,			/* partial_inplace */
214 	 0x0000ffff,		/* src_mask */
215 	 0x0000ffff,		/* dst_mask */
216 	 FALSE),		/* pcrel_offset */
217 
218   /* GP relative reference.  */
219   HOWTO (R_MIPS_GPREL16,	/* type */
220 	 0,			/* rightshift */
221 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
222 	 16,			/* bitsize */
223 	 FALSE,			/* pc_relative */
224 	 0,			/* bitpos */
225 	 complain_overflow_signed, /* complain_on_overflow */
226 	 mips_elf_gprel16_reloc, /* special_function */
227 	 "R_MIPS_GPREL16",	/* name */
228 	 TRUE,			/* partial_inplace */
229 	 0x0000ffff,		/* src_mask */
230 	 0x0000ffff,		/* dst_mask */
231 	 FALSE),		/* pcrel_offset */
232 
233   /* Reference to literal section.  */
234   HOWTO (R_MIPS_LITERAL,	/* type */
235 	 0,			/* rightshift */
236 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
237 	 16,			/* bitsize */
238 	 FALSE,			/* pc_relative */
239 	 0,			/* bitpos */
240 	 complain_overflow_signed, /* complain_on_overflow */
241 	 mips_elf_literal_reloc, /* special_function */
242 	 "R_MIPS_LITERAL",	/* name */
243 	 TRUE,			/* partial_inplace */
244 	 0x0000ffff,		/* src_mask */
245 	 0x0000ffff,		/* dst_mask */
246 	 FALSE),		/* pcrel_offset */
247 
248   /* Reference to global offset table.  */
249   HOWTO (R_MIPS_GOT16,		/* type */
250 	 0,			/* rightshift */
251 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
252 	 16,			/* bitsize */
253 	 FALSE,			/* pc_relative */
254 	 0,			/* bitpos */
255 	 complain_overflow_signed, /* complain_on_overflow */
256 	 _bfd_mips_elf_got16_reloc, /* special_function */
257 	 "R_MIPS_GOT16",	/* name */
258 	 TRUE,			/* partial_inplace */
259 	 0x0000ffff,		/* src_mask */
260 	 0x0000ffff,		/* dst_mask */
261 	 FALSE),		/* pcrel_offset */
262 
263   /* 16 bit PC relative reference.  Note that the ABI document has a typo
264      and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
265      We do the right thing here.  */
266   HOWTO (R_MIPS_PC16,		/* type */
267 	 2,			/* 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   /* 32 bit relocation with no addend.  */
759   HOWTO (R_MIPS_GLOB_DAT,	/* type */
760 	 0,			/* rightshift */
761 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
762 	 32,			/* bitsize */
763 	 FALSE,			/* pc_relative */
764 	 0,			/* bitpos */
765 	 complain_overflow_dont, /* complain_on_overflow */
766 	 _bfd_mips_elf_generic_reloc, /* special_function */
767 	 "R_MIPS_GLOB_DAT",	/* name */
768 	 FALSE,			/* partial_inplace */
769 	 0x0,			/* src_mask */
770 	 0xffffffff,		/* dst_mask */
771 	 FALSE),		/* pcrel_offset */
772 };
773 
774 /* The relocation table used for SHT_RELA sections.  */
775 
776 static reloc_howto_type elf_mips_howto_table_rela[] =
777 {
778   /* No relocation.  */
779   HOWTO (R_MIPS_NONE,		/* type */
780 	 0,			/* rightshift */
781 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
782 	 0,			/* bitsize */
783 	 FALSE,			/* pc_relative */
784 	 0,			/* bitpos */
785 	 complain_overflow_dont, /* complain_on_overflow */
786 	 _bfd_mips_elf_generic_reloc, /* special_function */
787 	 "R_MIPS_NONE",		/* name */
788 	 FALSE,			/* partial_inplace */
789 	 0,			/* src_mask */
790 	 0,			/* dst_mask */
791 	 FALSE),		/* pcrel_offset */
792 
793   /* 16 bit relocation.  */
794   HOWTO (R_MIPS_16,		/* type */
795 	 0,			/* rightshift */
796 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
797 	 16,			/* bitsize */
798 	 FALSE,			/* pc_relative */
799 	 0,			/* bitpos */
800 	 complain_overflow_signed, /* complain_on_overflow */
801 	 _bfd_mips_elf_generic_reloc, /* special_function */
802 	 "R_MIPS_16",		/* name */
803 	 FALSE,			/* partial_inplace */
804 	 0,			/* src_mask */
805 	 0x0000,		/* dst_mask */
806 	 FALSE),		/* pcrel_offset */
807 
808   /* 32 bit relocation.  */
809   HOWTO (R_MIPS_32,		/* 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_32",		/* name */
818 	 FALSE,			/* partial_inplace */
819 	 0,			/* src_mask */
820 	 0xffffffff,		/* dst_mask */
821 	 FALSE),		/* pcrel_offset */
822 
823   /* 32 bit symbol relative relocation.  */
824   HOWTO (R_MIPS_REL32,		/* type */
825 	 0,			/* rightshift */
826 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
827 	 32,			/* bitsize */
828 	 FALSE,			/* pc_relative */
829 	 0,			/* bitpos */
830 	 complain_overflow_dont, /* complain_on_overflow */
831 	 _bfd_mips_elf_generic_reloc, /* special_function */
832 	 "R_MIPS_REL32",	/* name */
833 	 FALSE,			/* partial_inplace */
834 	 0,			/* src_mask */
835 	 0xffffffff,		/* dst_mask */
836 	 FALSE),		/* pcrel_offset */
837 
838   /* 26 bit jump address.  */
839   HOWTO (R_MIPS_26,		/* type */
840 	 2,			/* rightshift */
841 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
842 	 26,			/* bitsize */
843 	 FALSE,			/* pc_relative */
844 	 0,			/* bitpos */
845 	 complain_overflow_dont, /* complain_on_overflow */
846 				/* This needs complex overflow
847 				   detection, because the upper 36
848 				   bits must match the PC + 4.  */
849 	 _bfd_mips_elf_generic_reloc, /* special_function */
850 	 "R_MIPS_26",		/* name */
851 	 FALSE,			/* partial_inplace */
852 	 0,			/* src_mask */
853 	 0x03ffffff,		/* dst_mask */
854 	 FALSE),		/* pcrel_offset */
855 
856   /* High 16 bits of symbol value.  */
857   HOWTO (R_MIPS_HI16,		/* 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_HI16",		/* name */
866 	 FALSE,			/* partial_inplace */
867 	 0,			/* src_mask */
868 	 0x0000ffff,		/* dst_mask */
869 	 FALSE),		/* pcrel_offset */
870 
871   /* Low 16 bits of symbol value.  */
872   HOWTO (R_MIPS_LO16,		/* 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_dont, /* complain_on_overflow */
879 	 _bfd_mips_elf_generic_reloc, /* special_function */
880 	 "R_MIPS_LO16",		/* name */
881 	 FALSE,			/* partial_inplace */
882 	 0,			/* src_mask */
883 	 0x0000ffff,		/* dst_mask */
884 	 FALSE),		/* pcrel_offset */
885 
886   /* GP relative reference.  */
887   HOWTO (R_MIPS_GPREL16,	/* 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_gprel16_reloc, /* special_function */
895 	 "R_MIPS_GPREL16",	/* name */
896 	 FALSE,			/* partial_inplace */
897 	 0,			/* src_mask */
898 	 0x0000ffff,		/* dst_mask */
899 	 FALSE),		/* pcrel_offset */
900 
901   /* Reference to literal section.  */
902   HOWTO (R_MIPS_LITERAL,	/* 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 	 mips_elf_literal_reloc, /* special_function */
910 	 "R_MIPS_LITERAL",	/* name */
911 	 FALSE,			/* partial_inplace */
912 	 0,			/* src_mask */
913 	 0x0000ffff,		/* dst_mask */
914 	 FALSE),		/* pcrel_offset */
915 
916   /* Reference to global offset table.  */
917   HOWTO (R_MIPS_GOT16,		/* type */
918 	 0,			/* rightshift */
919 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
920 	 16,			/* bitsize */
921 	 FALSE,			/* pc_relative */
922 	 0,			/* bitpos */
923 	 complain_overflow_signed, /* complain_on_overflow */
924 	 _bfd_mips_elf_generic_reloc, /* special_function */
925 	 "R_MIPS_GOT16",	/* name */
926 	 FALSE,			/* partial_inplace */
927 	 0,			/* src_mask */
928 	 0x0000ffff,		/* dst_mask */
929 	 FALSE),		/* pcrel_offset */
930 
931   /* 16 bit PC relative reference.  Note that the ABI document has a typo
932      and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
933      We do the right thing here.  */
934   HOWTO (R_MIPS_PC16,		/* type */
935 	 2,			/* rightshift */
936 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
937 	 16,			/* bitsize */
938 	 TRUE,			/* pc_relative */
939 	 0,			/* bitpos */
940 	 complain_overflow_signed, /* complain_on_overflow */
941 	 _bfd_mips_elf_generic_reloc, /* special_function */
942 	 "R_MIPS_PC16",		/* name */
943 	 FALSE,			/* partial_inplace */
944 	 0,			/* src_mask */
945 	 0x0000ffff,		/* dst_mask */
946 	 TRUE),			/* pcrel_offset */
947 
948   /* 16 bit call through global offset table.  */
949   HOWTO (R_MIPS_CALL16,		/* type */
950 	 0,			/* rightshift */
951 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
952 	 16,			/* bitsize */
953 	 FALSE,			/* pc_relative */
954 	 0,			/* bitpos */
955 	 complain_overflow_signed, /* complain_on_overflow */
956 	 _bfd_mips_elf_generic_reloc, /* special_function */
957 	 "R_MIPS_CALL16",	/* name */
958 	 FALSE,			/* partial_inplace */
959 	 0,			/* src_mask */
960 	 0x0000ffff,		/* dst_mask */
961 	 FALSE),		/* pcrel_offset */
962 
963   /* 32 bit GP relative reference.  */
964   HOWTO (R_MIPS_GPREL32,	/* type */
965 	 0,			/* rightshift */
966 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
967 	 32,			/* bitsize */
968 	 FALSE,			/* pc_relative */
969 	 0,			/* bitpos */
970 	 complain_overflow_dont, /* complain_on_overflow */
971 	 mips_elf_gprel32_reloc, /* special_function */
972 	 "R_MIPS_GPREL32",	/* name */
973 	 FALSE,			/* partial_inplace */
974 	 0,			/* src_mask */
975 	 0xffffffff,		/* dst_mask */
976 	 FALSE),		/* pcrel_offset */
977 
978   EMPTY_HOWTO (13),
979   EMPTY_HOWTO (14),
980   EMPTY_HOWTO (15),
981 
982   /* A 5 bit shift field.  */
983   HOWTO (R_MIPS_SHIFT5,		/* type */
984 	 0,			/* rightshift */
985 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
986 	 5,			/* bitsize */
987 	 FALSE,			/* pc_relative */
988 	 6,			/* bitpos */
989 	 complain_overflow_bitfield, /* complain_on_overflow */
990 	 _bfd_mips_elf_generic_reloc, /* special_function */
991 	 "R_MIPS_SHIFT5",	/* name */
992 	 FALSE,			/* partial_inplace */
993 	 0,			/* src_mask */
994 	 0x000007c0,		/* dst_mask */
995 	 FALSE),		/* pcrel_offset */
996 
997   /* A 6 bit shift field.  */
998   HOWTO (R_MIPS_SHIFT6,		/* type */
999 	 0,			/* rightshift */
1000 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1001 	 6,			/* bitsize */
1002 	 FALSE,			/* pc_relative */
1003 	 6,			/* bitpos */
1004 	 complain_overflow_bitfield, /* complain_on_overflow */
1005 	 mips_elf_shift6_reloc,	/* special_function */
1006 	 "R_MIPS_SHIFT6",	/* name */
1007 	 FALSE,			/* partial_inplace */
1008 	 0,			/* src_mask */
1009 	 0x000007c4,		/* dst_mask */
1010 	 FALSE),		/* pcrel_offset */
1011 
1012   /* 64 bit relocation.  */
1013   HOWTO (R_MIPS_64,		/* type */
1014 	 0,			/* rightshift */
1015 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
1016 	 64,			/* bitsize */
1017 	 FALSE,			/* pc_relative */
1018 	 0,			/* bitpos */
1019 	 complain_overflow_dont, /* complain_on_overflow */
1020 	 _bfd_mips_elf_generic_reloc, /* special_function */
1021 	 "R_MIPS_64",		/* name */
1022 	 FALSE,			/* partial_inplace */
1023 	 0,			/* src_mask */
1024 	 MINUS_ONE,		/* dst_mask */
1025 	 FALSE),		/* pcrel_offset */
1026 
1027   /* Displacement in the global offset table.  */
1028   HOWTO (R_MIPS_GOT_DISP,	/* type */
1029 	 0,			/* rightshift */
1030 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1031 	 16,			/* bitsize */
1032 	 FALSE,			/* pc_relative */
1033 	 0,			/* bitpos */
1034 	 complain_overflow_signed, /* complain_on_overflow */
1035 	 _bfd_mips_elf_generic_reloc, /* special_function */
1036 	 "R_MIPS_GOT_DISP",	/* name */
1037 	 FALSE,			/* partial_inplace */
1038 	 0,			/* src_mask */
1039 	 0x0000ffff,		/* dst_mask */
1040 	 FALSE),		/* pcrel_offset */
1041 
1042   /* Displacement to page pointer in the global offset table.  */
1043   HOWTO (R_MIPS_GOT_PAGE,	/* type */
1044 	 0,			/* rightshift */
1045 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1046 	 16,			/* bitsize */
1047 	 FALSE,			/* pc_relative */
1048 	 0,			/* bitpos */
1049 	 complain_overflow_signed, /* complain_on_overflow */
1050 	 _bfd_mips_elf_generic_reloc, /* special_function */
1051 	 "R_MIPS_GOT_PAGE",	/* name */
1052 	 FALSE,			/* partial_inplace */
1053 	 0,			/* src_mask */
1054 	 0x0000ffff,		/* dst_mask */
1055 	 FALSE),		/* pcrel_offset */
1056 
1057   /* Offset from page pointer in the global offset table.  */
1058   HOWTO (R_MIPS_GOT_OFST,	/* type */
1059 	 0,			/* rightshift */
1060 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1061 	 16,			/* bitsize */
1062 	 FALSE,			/* pc_relative */
1063 	 0,			/* bitpos */
1064 	 complain_overflow_signed, /* complain_on_overflow */
1065 	 _bfd_mips_elf_generic_reloc, /* special_function */
1066 	 "R_MIPS_GOT_OFST",	/* name */
1067 	 FALSE,			/* partial_inplace */
1068 	 0,			/* src_mask */
1069 	 0x0000ffff,		/* dst_mask */
1070 	 FALSE),		/* pcrel_offset */
1071 
1072   /* High 16 bits of displacement in global offset table.  */
1073   HOWTO (R_MIPS_GOT_HI16,	/* type */
1074 	 0,			/* rightshift */
1075 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1076 	 16,			/* bitsize */
1077 	 FALSE,			/* pc_relative */
1078 	 0,			/* bitpos */
1079 	 complain_overflow_dont, /* complain_on_overflow */
1080 	 _bfd_mips_elf_generic_reloc, /* special_function */
1081 	 "R_MIPS_GOT_HI16",	/* name */
1082 	 FALSE,			/* partial_inplace */
1083 	 0,			/* src_mask */
1084 	 0x0000ffff,		/* dst_mask */
1085 	 FALSE),		/* pcrel_offset */
1086 
1087   /* Low 16 bits of displacement in global offset table.  */
1088   HOWTO (R_MIPS_GOT_LO16,	/* type */
1089 	 0,			/* rightshift */
1090 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1091 	 16,			/* bitsize */
1092 	 FALSE,			/* pc_relative */
1093 	 0,			/* bitpos */
1094 	 complain_overflow_dont, /* complain_on_overflow */
1095 	 _bfd_mips_elf_generic_reloc, /* special_function */
1096 	 "R_MIPS_GOT_LO16",	/* name */
1097 	 FALSE,			/* partial_inplace */
1098 	 0,			/* src_mask */
1099 	 0x0000ffff,		/* dst_mask */
1100 	 FALSE),		/* pcrel_offset */
1101 
1102   /* 64 bit subtraction.  */
1103   HOWTO (R_MIPS_SUB,		/* type */
1104 	 0,			/* rightshift */
1105 	 4,			/* size (0 = byte, 1 = short, 2 = long) */
1106 	 64,			/* bitsize */
1107 	 FALSE,			/* pc_relative */
1108 	 0,			/* bitpos */
1109 	 complain_overflow_dont, /* complain_on_overflow */
1110 	 _bfd_mips_elf_generic_reloc, /* special_function */
1111 	 "R_MIPS_SUB",		/* name */
1112 	 FALSE,			/* partial_inplace */
1113 	 0,			/* src_mask */
1114 	 MINUS_ONE,		/* dst_mask */
1115 	 FALSE),		/* pcrel_offset */
1116 
1117   /* Insert the addend as an instruction.  */
1118   /* FIXME: Not handled correctly.  */
1119   HOWTO (R_MIPS_INSERT_A,	/* 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_A",	/* name */
1128 	 FALSE,			/* partial_inplace */
1129 	 0,			/* src_mask */
1130 	 0xffffffff,		/* dst_mask */
1131 	 FALSE),		/* pcrel_offset */
1132 
1133   /* Insert the addend as an instruction, and change all relocations
1134      to refer to the old instruction at the address.  */
1135   /* FIXME: Not handled correctly.  */
1136   HOWTO (R_MIPS_INSERT_B,	/* type */
1137 	 0,			/* rightshift */
1138 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1139 	 32,			/* bitsize */
1140 	 FALSE,			/* pc_relative */
1141 	 0,			/* bitpos */
1142 	 complain_overflow_dont, /* complain_on_overflow */
1143 	 _bfd_mips_elf_generic_reloc, /* special_function */
1144 	 "R_MIPS_INSERT_B",	/* name */
1145 	 FALSE,			/* partial_inplace */
1146 	 0,			/* src_mask */
1147 	 0xffffffff,		/* dst_mask */
1148 	 FALSE),		/* pcrel_offset */
1149 
1150   /* Delete a 32 bit instruction.  */
1151   /* FIXME: Not handled correctly.  */
1152   HOWTO (R_MIPS_DELETE,		/* type */
1153 	 0,			/* rightshift */
1154 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1155 	 32,			/* bitsize */
1156 	 FALSE,			/* pc_relative */
1157 	 0,			/* bitpos */
1158 	 complain_overflow_dont, /* complain_on_overflow */
1159 	 _bfd_mips_elf_generic_reloc, /* special_function */
1160 	 "R_MIPS_DELETE",	/* name */
1161 	 FALSE,			/* partial_inplace */
1162 	 0,			/* src_mask */
1163 	 0xffffffff,		/* dst_mask */
1164 	 FALSE),		/* pcrel_offset */
1165 
1166   /* Get the higher value of a 64 bit addend.  */
1167   HOWTO (R_MIPS_HIGHER,		/* type */
1168 	 0,			/* rightshift */
1169 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1170 	 16,			/* bitsize */
1171 	 FALSE,			/* pc_relative */
1172 	 0,			/* bitpos */
1173 	 complain_overflow_dont, /* complain_on_overflow */
1174 	 _bfd_mips_elf_generic_reloc, /* special_function */
1175 	 "R_MIPS_HIGHER",	/* name */
1176 	 FALSE,			/* partial_inplace */
1177 	 0,			/* src_mask */
1178 	 0x0000ffff,		/* dst_mask */
1179 	 FALSE),		/* pcrel_offset */
1180 
1181   /* Get the highest value of a 64 bit addend.  */
1182   HOWTO (R_MIPS_HIGHEST,	/* type */
1183 	 0,			/* rightshift */
1184 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1185 	 16,			/* bitsize */
1186 	 FALSE,			/* pc_relative */
1187 	 0,			/* bitpos */
1188 	 complain_overflow_dont, /* complain_on_overflow */
1189 	 _bfd_mips_elf_generic_reloc, /* special_function */
1190 	 "R_MIPS_HIGHEST",	/* name */
1191 	 FALSE,			/* partial_inplace */
1192 	 0,			/* src_mask */
1193 	 0x0000ffff,		/* dst_mask */
1194 	 FALSE),		/* pcrel_offset */
1195 
1196   /* High 16 bits of displacement in global offset table.  */
1197   HOWTO (R_MIPS_CALL_HI16,	/* type */
1198 	 0,			/* rightshift */
1199 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1200 	 16,			/* bitsize */
1201 	 FALSE,			/* pc_relative */
1202 	 0,			/* bitpos */
1203 	 complain_overflow_dont, /* complain_on_overflow */
1204 	 _bfd_mips_elf_generic_reloc, /* special_function */
1205 	 "R_MIPS_CALL_HI16",	/* name */
1206 	 FALSE,			/* partial_inplace */
1207 	 0,			/* src_mask */
1208 	 0x0000ffff,		/* dst_mask */
1209 	 FALSE),		/* pcrel_offset */
1210 
1211   /* Low 16 bits of displacement in global offset table.  */
1212   HOWTO (R_MIPS_CALL_LO16,	/* type */
1213 	 0,			/* rightshift */
1214 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1215 	 16,			/* bitsize */
1216 	 FALSE,			/* pc_relative */
1217 	 0,			/* bitpos */
1218 	 complain_overflow_dont, /* complain_on_overflow */
1219 	 _bfd_mips_elf_generic_reloc, /* special_function */
1220 	 "R_MIPS_CALL_LO16",	/* name */
1221 	 FALSE,			/* partial_inplace */
1222 	 0,			/* src_mask */
1223 	 0x0000ffff,		/* dst_mask */
1224 	 FALSE),		/* pcrel_offset */
1225 
1226   /* Section displacement, used by an associated event location section.  */
1227   HOWTO (R_MIPS_SCN_DISP,	/* type */
1228 	 0,			/* rightshift */
1229 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1230 	 32,			/* bitsize */
1231 	 FALSE,			/* pc_relative */
1232 	 0,			/* bitpos */
1233 	 complain_overflow_dont, /* complain_on_overflow */
1234 	 _bfd_mips_elf_generic_reloc, /* special_function */
1235 	 "R_MIPS_SCN_DISP",	/* name */
1236 	 FALSE,			/* partial_inplace */
1237 	 0,			/* src_mask */
1238 	 0xffffffff,		/* dst_mask */
1239 	 FALSE),		/* pcrel_offset */
1240 
1241   /* 16 bit relocation.  */
1242   HOWTO (R_MIPS_REL16,		/* type */
1243 	 0,			/* rightshift */
1244 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
1245 	 16,			/* bitsize */
1246 	 FALSE,			/* pc_relative */
1247 	 0,			/* bitpos */
1248 	 complain_overflow_signed, /* complain_on_overflow */
1249 	 _bfd_mips_elf_generic_reloc, /* special_function */
1250 	 "R_MIPS_REL16",	/* name */
1251 	 FALSE,			/* partial_inplace */
1252 	 0,			/* src_mask */
1253 	 0xffff,		/* dst_mask */
1254 	 FALSE),		/* pcrel_offset */
1255 
1256   /* These two are obsolete.  */
1257   EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
1258   EMPTY_HOWTO (R_MIPS_PJUMP),
1259 
1260   /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section.
1261      It must be used for multigot GOT's (and only there).  */
1262   HOWTO (R_MIPS_RELGOT,		/* type */
1263 	 0,			/* rightshift */
1264 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1265 	 32,			/* bitsize */
1266 	 FALSE,			/* pc_relative */
1267 	 0,			/* bitpos */
1268 	 complain_overflow_dont, /* complain_on_overflow */
1269 	 _bfd_mips_elf_generic_reloc, /* special_function */
1270 	 "R_MIPS_RELGOT",	/* name */
1271 	 FALSE,			/* partial_inplace */
1272 	 0,			/* src_mask */
1273 	 0xffffffff,		/* dst_mask */
1274 	 FALSE),		/* pcrel_offset */
1275 
1276   /* Protected jump conversion.  This is an optimization hint.  No
1277      relocation is required for correctness.  */
1278   HOWTO (R_MIPS_JALR,	        /* type */
1279 	 0,			/* rightshift */
1280 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1281 	 32,			/* bitsize */
1282 	 FALSE,			/* pc_relative */
1283 	 0,			/* bitpos */
1284 	 complain_overflow_dont, /* complain_on_overflow */
1285 	 _bfd_mips_elf_generic_reloc, /* special_function */
1286 	 "R_MIPS_JALR",	        /* name */
1287 	 FALSE,			/* partial_inplace */
1288 	 0,			/* src_mask */
1289 	 0,			/* dst_mask */
1290 	 FALSE),		/* pcrel_offset */
1291 
1292   /* TLS GD/LD dynamic relocations.  */
1293   HOWTO (R_MIPS_TLS_DTPMOD32,	/* type */
1294 	 0,			/* rightshift */
1295 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1296 	 32,			/* bitsize */
1297 	 FALSE,			/* pc_relative */
1298 	 0,			/* bitpos */
1299 	 complain_overflow_dont, /* complain_on_overflow */
1300 	 _bfd_mips_elf_generic_reloc, /* special_function */
1301 	 "R_MIPS_TLS_DTPMOD32",	/* name */
1302 	 TRUE,			/* partial_inplace */
1303 	 0xffffffff,		/* src_mask */
1304 	 0xffffffff,		/* dst_mask */
1305 	 FALSE),		/* pcrel_offset */
1306 
1307   HOWTO (R_MIPS_TLS_DTPREL32,	/* type */
1308 	 0,			/* rightshift */
1309 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1310 	 32,			/* bitsize */
1311 	 FALSE,			/* pc_relative */
1312 	 0,			/* bitpos */
1313 	 complain_overflow_dont, /* complain_on_overflow */
1314 	 _bfd_mips_elf_generic_reloc, /* special_function */
1315 	 "R_MIPS_TLS_DTPREL32",	/* name */
1316 	 TRUE,			/* partial_inplace */
1317 	 0xffffffff,		/* src_mask */
1318 	 0xffffffff,		/* dst_mask */
1319 	 FALSE),		/* pcrel_offset */
1320 
1321   EMPTY_HOWTO (R_MIPS_TLS_DTPMOD64),
1322   EMPTY_HOWTO (R_MIPS_TLS_DTPREL64),
1323 
1324   /* TLS general dynamic variable reference.  */
1325   HOWTO (R_MIPS_TLS_GD,		/* type */
1326 	 0,			/* rightshift */
1327 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1328 	 16,			/* bitsize */
1329 	 FALSE,			/* pc_relative */
1330 	 0,			/* bitpos */
1331 	 complain_overflow_signed, /* complain_on_overflow */
1332 	 _bfd_mips_elf_generic_reloc, /* special_function */
1333 	 "R_MIPS_TLS_GD",	/* name */
1334 	 TRUE,			/* partial_inplace */
1335 	 0x0000ffff,		/* src_mask */
1336 	 0x0000ffff,		/* dst_mask */
1337 	 FALSE),		/* pcrel_offset */
1338 
1339   /* TLS local dynamic variable reference.  */
1340   HOWTO (R_MIPS_TLS_LDM,	/* type */
1341 	 0,			/* rightshift */
1342 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1343 	 16,			/* bitsize */
1344 	 FALSE,			/* pc_relative */
1345 	 0,			/* bitpos */
1346 	 complain_overflow_signed, /* complain_on_overflow */
1347 	 _bfd_mips_elf_generic_reloc, /* special_function */
1348 	 "R_MIPS_TLS_LDM",	/* name */
1349 	 TRUE,			/* partial_inplace */
1350 	 0x0000ffff,		/* src_mask */
1351 	 0x0000ffff,		/* dst_mask */
1352 	 FALSE),		/* pcrel_offset */
1353 
1354   /* TLS local dynamic offset.  */
1355   HOWTO (R_MIPS_TLS_DTPREL_HI16,	/* type */
1356 	 0,			/* rightshift */
1357 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1358 	 16,			/* bitsize */
1359 	 FALSE,			/* pc_relative */
1360 	 0,			/* bitpos */
1361 	 complain_overflow_signed, /* complain_on_overflow */
1362 	 _bfd_mips_elf_generic_reloc, /* special_function */
1363 	 "R_MIPS_TLS_DTPREL_HI16",	/* name */
1364 	 TRUE,			/* partial_inplace */
1365 	 0x0000ffff,		/* src_mask */
1366 	 0x0000ffff,		/* dst_mask */
1367 	 FALSE),		/* pcrel_offset */
1368 
1369   /* TLS local dynamic offset.  */
1370   HOWTO (R_MIPS_TLS_DTPREL_LO16,	/* type */
1371 	 0,			/* rightshift */
1372 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1373 	 16,			/* bitsize */
1374 	 FALSE,			/* pc_relative */
1375 	 0,			/* bitpos */
1376 	 complain_overflow_signed, /* complain_on_overflow */
1377 	 _bfd_mips_elf_generic_reloc, /* special_function */
1378 	 "R_MIPS_TLS_DTPREL_LO16",	/* name */
1379 	 TRUE,			/* partial_inplace */
1380 	 0x0000ffff,		/* src_mask */
1381 	 0x0000ffff,		/* dst_mask */
1382 	 FALSE),		/* pcrel_offset */
1383 
1384   /* TLS thread pointer offset.  */
1385   HOWTO (R_MIPS_TLS_GOTTPREL,	/* type */
1386 	 0,			/* rightshift */
1387 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1388 	 16,			/* bitsize */
1389 	 FALSE,			/* pc_relative */
1390 	 0,			/* bitpos */
1391 	 complain_overflow_signed, /* complain_on_overflow */
1392 	 _bfd_mips_elf_generic_reloc, /* special_function */
1393 	 "R_MIPS_TLS_GOTTPREL",	/* name */
1394 	 TRUE,			/* partial_inplace */
1395 	 0x0000ffff,		/* src_mask */
1396 	 0x0000ffff,		/* dst_mask */
1397 	 FALSE),		/* pcrel_offset */
1398 
1399   /* TLS IE dynamic relocations.  */
1400   HOWTO (R_MIPS_TLS_TPREL32,	/* type */
1401 	 0,			/* rightshift */
1402 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1403 	 32,			/* bitsize */
1404 	 FALSE,			/* pc_relative */
1405 	 0,			/* bitpos */
1406 	 complain_overflow_dont, /* complain_on_overflow */
1407 	 _bfd_mips_elf_generic_reloc, /* special_function */
1408 	 "R_MIPS_TLS_TPREL32",	/* name */
1409 	 TRUE,			/* partial_inplace */
1410 	 0xffffffff,		/* src_mask */
1411 	 0xffffffff,		/* dst_mask */
1412 	 FALSE),		/* pcrel_offset */
1413 
1414   EMPTY_HOWTO (R_MIPS_TLS_TPREL64),
1415 
1416   /* TLS thread pointer offset.  */
1417   HOWTO (R_MIPS_TLS_TPREL_HI16,	/* type */
1418 	 0,			/* rightshift */
1419 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1420 	 16,			/* bitsize */
1421 	 FALSE,			/* pc_relative */
1422 	 0,			/* bitpos */
1423 	 complain_overflow_signed, /* complain_on_overflow */
1424 	 _bfd_mips_elf_generic_reloc, /* special_function */
1425 	 "R_MIPS_TLS_TPREL_HI16", /* name */
1426 	 TRUE,			/* partial_inplace */
1427 	 0x0000ffff,		/* src_mask */
1428 	 0x0000ffff,		/* dst_mask */
1429 	 FALSE),		/* pcrel_offset */
1430 
1431   /* TLS thread pointer offset.  */
1432   HOWTO (R_MIPS_TLS_TPREL_LO16,	/* type */
1433 	 0,			/* rightshift */
1434 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1435 	 16,			/* bitsize */
1436 	 FALSE,			/* pc_relative */
1437 	 0,			/* bitpos */
1438 	 complain_overflow_signed, /* complain_on_overflow */
1439 	 _bfd_mips_elf_generic_reloc, /* special_function */
1440 	 "R_MIPS_TLS_TPREL_LO16", /* name */
1441 	 TRUE,			/* partial_inplace */
1442 	 0x0000ffff,		/* src_mask */
1443 	 0x0000ffff,		/* dst_mask */
1444 	 FALSE),		/* pcrel_offset */
1445 
1446   /* 32 bit relocation with no addend.  */
1447   HOWTO (R_MIPS_GLOB_DAT,	/* type */
1448 	 0,			/* rightshift */
1449 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1450 	 32,			/* bitsize */
1451 	 FALSE,			/* pc_relative */
1452 	 0,			/* bitpos */
1453 	 complain_overflow_dont, /* complain_on_overflow */
1454 	 _bfd_mips_elf_generic_reloc, /* special_function */
1455 	 "R_MIPS_GLOB_DAT",	/* name */
1456 	 FALSE,			/* partial_inplace */
1457 	 0x0,			/* src_mask */
1458 	 0xffffffff,		/* dst_mask */
1459 	 FALSE),		/* pcrel_offset */
1460 };
1461 
1462 static reloc_howto_type elf_mips16_howto_table_rel[] =
1463 {
1464   /* The reloc used for the mips16 jump instruction.  */
1465   HOWTO (R_MIPS16_26,		/* type */
1466 	 2,			/* rightshift */
1467 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1468 	 26,			/* bitsize */
1469 	 FALSE,			/* pc_relative */
1470 	 0,			/* bitpos */
1471 	 complain_overflow_dont, /* complain_on_overflow */
1472 	 			/* This needs complex overflow
1473 				   detection, because the upper four
1474 				   bits must match the PC.  */
1475 	 _bfd_mips_elf_generic_reloc, /* special_function */
1476 	 "R_MIPS16_26",		/* name */
1477 	 TRUE,			/* partial_inplace */
1478 	 0x3ffffff,		/* src_mask */
1479 	 0x3ffffff,		/* dst_mask */
1480 	 FALSE),		/* pcrel_offset */
1481 
1482   /* The reloc used for the mips16 gprel instruction.  */
1483   HOWTO (R_MIPS16_GPREL,	/* type */
1484 	 0,			/* rightshift */
1485 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1486 	 16,			/* bitsize */
1487 	 FALSE,			/* pc_relative */
1488 	 0,			/* bitpos */
1489 	 complain_overflow_signed, /* complain_on_overflow */
1490 	 mips16_gprel_reloc,	/* special_function */
1491 	 "R_MIPS16_GPREL",	/* name */
1492 	 TRUE,			/* partial_inplace */
1493 	 0x0000ffff,		/* src_mask */
1494 	 0x0000ffff,	        /* dst_mask */
1495 	 FALSE),		/* pcrel_offset */
1496 
1497   /* A placeholder for MIPS16 reference to global offset table.  */
1498   EMPTY_HOWTO (R_MIPS16_GOT16),
1499 
1500   /* A placeholder for MIPS16 16 bit call through global offset table.  */
1501   EMPTY_HOWTO (R_MIPS16_CALL16),
1502 
1503   /* MIPS16 high 16 bits of symbol value.  */
1504   HOWTO (R_MIPS16_HI16,		/* type */
1505 	 16,			/* rightshift */
1506 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1507 	 16,			/* bitsize */
1508 	 FALSE,			/* pc_relative */
1509 	 0,			/* bitpos */
1510 	 complain_overflow_dont, /* complain_on_overflow */
1511 	 _bfd_mips_elf_hi16_reloc, /* special_function */
1512 	 "R_MIPS16_HI16",	/* name */
1513 	 TRUE,			/* partial_inplace */
1514 	 0x0000ffff,		/* src_mask */
1515 	 0x0000ffff,		/* dst_mask */
1516 	 FALSE),		/* pcrel_offset */
1517 
1518   /* MIPS16 low 16 bits of symbol value.  */
1519   HOWTO (R_MIPS16_LO16,		/* type */
1520 	 0,			/* rightshift */
1521 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1522 	 16,			/* bitsize */
1523 	 FALSE,			/* pc_relative */
1524 	 0,			/* bitpos */
1525 	 complain_overflow_dont, /* complain_on_overflow */
1526 	 _bfd_mips_elf_lo16_reloc, /* special_function */
1527 	 "R_MIPS16_LO16",	/* name */
1528 	 TRUE,			/* partial_inplace */
1529 	 0x0000ffff,		/* src_mask */
1530 	 0x0000ffff,		/* dst_mask */
1531 	 FALSE),		/* pcrel_offset */
1532 };
1533 
1534 static reloc_howto_type elf_mips16_howto_table_rela[] =
1535 {
1536   /* The reloc used for the mips16 jump instruction.  */
1537   HOWTO (R_MIPS16_26,		/* type */
1538 	 2,			/* rightshift */
1539 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1540 	 26,			/* bitsize */
1541 	 FALSE,			/* pc_relative */
1542 	 0,			/* bitpos */
1543 	 complain_overflow_dont, /* complain_on_overflow */
1544 	 			/* This needs complex overflow
1545 				   detection, because the upper four
1546 				   bits must match the PC.  */
1547 	 _bfd_mips_elf_generic_reloc, /* special_function */
1548 	 "R_MIPS16_26",		/* name */
1549 	 FALSE,			/* partial_inplace */
1550 	 0x3ffffff,		/* src_mask */
1551 	 0x3ffffff,		/* dst_mask */
1552 	 FALSE),		/* pcrel_offset */
1553 
1554   /* The reloc used for the mips16 gprel instruction.  */
1555   HOWTO (R_MIPS16_GPREL,	/* type */
1556 	 0,			/* rightshift */
1557 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1558 	 16,			/* bitsize */
1559 	 FALSE,			/* pc_relative */
1560 	 0,			/* bitpos */
1561 	 complain_overflow_signed, /* complain_on_overflow */
1562 	 mips16_gprel_reloc,	/* special_function */
1563 	 "R_MIPS16_GPREL",	/* name */
1564 	 FALSE,			/* partial_inplace */
1565 	 0x0000ffff,		/* src_mask */
1566 	 0x0000ffff,	        /* dst_mask */
1567 	 FALSE),		/* pcrel_offset */
1568 
1569   /* A placeholder for MIPS16 reference to global offset table.  */
1570   EMPTY_HOWTO (R_MIPS16_GOT16),
1571 
1572   /* A placeholder for MIPS16 16 bit call through global offset table.  */
1573   EMPTY_HOWTO (R_MIPS16_CALL16),
1574 
1575   /* MIPS16 high 16 bits of symbol value.  */
1576   HOWTO (R_MIPS16_HI16,		/* type */
1577 	 16,			/* rightshift */
1578 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1579 	 16,			/* bitsize */
1580 	 FALSE,			/* pc_relative */
1581 	 0,			/* bitpos */
1582 	 complain_overflow_dont, /* complain_on_overflow */
1583 	 _bfd_mips_elf_hi16_reloc, /* special_function */
1584 	 "R_MIPS16_HI16",	/* name */
1585 	 FALSE,			/* partial_inplace */
1586 	 0x0000ffff,		/* src_mask */
1587 	 0x0000ffff,		/* dst_mask */
1588 	 FALSE),		/* pcrel_offset */
1589 
1590   /* MIPS16 low 16 bits of symbol value.  */
1591   HOWTO (R_MIPS16_LO16,		/* type */
1592 	 0,			/* rightshift */
1593 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1594 	 16,			/* bitsize */
1595 	 FALSE,			/* pc_relative */
1596 	 0,			/* bitpos */
1597 	 complain_overflow_dont, /* complain_on_overflow */
1598 	 _bfd_mips_elf_lo16_reloc, /* special_function */
1599 	 "R_MIPS16_LO16",	/* name */
1600 	 FALSE,			/* partial_inplace */
1601 	 0x0000ffff,		/* src_mask */
1602 	 0x0000ffff,		/* dst_mask */
1603 	 FALSE),		/* pcrel_offset */
1604 };
1605 
1606 /* GNU extension to record C++ vtable hierarchy */
1607 static reloc_howto_type elf_mips_gnu_vtinherit_howto =
1608   HOWTO (R_MIPS_GNU_VTINHERIT,	/* type */
1609 	 0,			/* rightshift */
1610 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1611 	 0,			/* bitsize */
1612 	 FALSE,			/* pc_relative */
1613 	 0,			/* bitpos */
1614 	 complain_overflow_dont, /* complain_on_overflow */
1615 	 NULL,			/* special_function */
1616 	 "R_MIPS_GNU_VTINHERIT", /* name */
1617 	 FALSE,			/* partial_inplace */
1618 	 0,			/* src_mask */
1619 	 0,			/* dst_mask */
1620 	 FALSE);		/* pcrel_offset */
1621 
1622 /* GNU extension to record C++ vtable member usage */
1623 static reloc_howto_type elf_mips_gnu_vtentry_howto =
1624   HOWTO (R_MIPS_GNU_VTENTRY,	/* type */
1625 	 0,			/* rightshift */
1626 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1627 	 0,			/* bitsize */
1628 	 FALSE,			/* pc_relative */
1629 	 0,			/* bitpos */
1630 	 complain_overflow_dont, /* complain_on_overflow */
1631 	 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1632 	 "R_MIPS_GNU_VTENTRY",	/* name */
1633 	 FALSE,			/* partial_inplace */
1634 	 0,			/* src_mask */
1635 	 0,			/* dst_mask */
1636 	 FALSE);		/* pcrel_offset */
1637 
1638 /* 16 bit offset for pc-relative branches.  */
1639 static reloc_howto_type elf_mips_gnu_rel16_s2 =
1640   HOWTO (R_MIPS_GNU_REL16_S2,	/* type */
1641 	 2,			/* rightshift */
1642 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1643 	 16,			/* bitsize */
1644 	 TRUE,			/* pc_relative */
1645 	 0,			/* bitpos */
1646 	 complain_overflow_signed, /* complain_on_overflow */
1647 	 _bfd_mips_elf_generic_reloc, /* special_function */
1648 	 "R_MIPS_GNU_REL16_S2",	/* name */
1649 	 TRUE,			/* partial_inplace */
1650 	 0x0000ffff,		/* src_mask */
1651 	 0x0000ffff,		/* dst_mask */
1652 	 TRUE);			/* pcrel_offset */
1653 
1654 /* 16 bit offset for pc-relative branches.  */
1655 static reloc_howto_type elf_mips_gnu_rela16_s2 =
1656   HOWTO (R_MIPS_GNU_REL16_S2,	/* type */
1657 	 2,			/* rightshift */
1658 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1659 	 16,			/* bitsize */
1660 	 TRUE,			/* pc_relative */
1661 	 0,			/* bitpos */
1662 	 complain_overflow_signed, /* complain_on_overflow */
1663 	 _bfd_mips_elf_generic_reloc, /* special_function */
1664 	 "R_MIPS_GNU_REL16_S2",	/* name */
1665 	 FALSE,			/* partial_inplace */
1666 	 0,			/* src_mask */
1667 	 0x0000ffff,		/* dst_mask */
1668 	 TRUE);			/* pcrel_offset */
1669 
1670 /* Set the GP value for OUTPUT_BFD.  Returns FALSE if this is a
1671    dangerous relocation.  */
1672 
1673 static bfd_boolean
mips_elf_assign_gp(bfd * output_bfd,bfd_vma * pgp)1674 mips_elf_assign_gp (bfd *output_bfd, bfd_vma *pgp)
1675 {
1676   unsigned int count;
1677   asymbol **sym;
1678   unsigned int i;
1679 
1680   /* If we've already figured out what GP will be, just return it.  */
1681   *pgp = _bfd_get_gp_value (output_bfd);
1682   if (*pgp)
1683     return TRUE;
1684 
1685   count = bfd_get_symcount (output_bfd);
1686   sym = bfd_get_outsymbols (output_bfd);
1687 
1688   /* The linker script will have created a symbol named `_gp' with the
1689      appropriate value.  */
1690   if (sym == NULL)
1691     i = count;
1692   else
1693     {
1694       for (i = 0; i < count; i++, sym++)
1695 	{
1696 	  register const char *name;
1697 
1698 	  name = bfd_asymbol_name (*sym);
1699 	  if (*name == '_' && strcmp (name, "_gp") == 0)
1700 	    {
1701 	      *pgp = bfd_asymbol_value (*sym);
1702 	      _bfd_set_gp_value (output_bfd, *pgp);
1703 	      break;
1704 	    }
1705 	}
1706     }
1707 
1708   if (i >= count)
1709     {
1710       /* Only get the error once.  */
1711       *pgp = 4;
1712       _bfd_set_gp_value (output_bfd, *pgp);
1713       return FALSE;
1714     }
1715 
1716   return TRUE;
1717 }
1718 
1719 /* We have to figure out the gp value, so that we can adjust the
1720    symbol value correctly.  We look up the symbol _gp in the output
1721    BFD.  If we can't find it, we're stuck.  We cache it in the ELF
1722    target data.  We don't need to adjust the symbol value for an
1723    external symbol if we are producing relocatable output.  */
1724 
1725 static bfd_reloc_status_type
mips_elf_final_gp(bfd * output_bfd,asymbol * symbol,bfd_boolean relocatable,char ** error_message,bfd_vma * pgp)1726 mips_elf_final_gp (bfd *output_bfd, asymbol *symbol, bfd_boolean relocatable,
1727 		   char **error_message, bfd_vma *pgp)
1728 {
1729   if (bfd_is_und_section (symbol->section)
1730       && ! relocatable)
1731     {
1732       *pgp = 0;
1733       return bfd_reloc_undefined;
1734     }
1735 
1736   *pgp = _bfd_get_gp_value (output_bfd);
1737   if (*pgp == 0
1738       && (! relocatable
1739 	  || (symbol->flags & BSF_SECTION_SYM) != 0))
1740     {
1741       if (relocatable)
1742 	{
1743 	  /* Make up a value.  */
1744 	  *pgp = symbol->section->output_section->vma /*+ 0x4000*/;
1745 	  _bfd_set_gp_value (output_bfd, *pgp);
1746 	}
1747       else if (!mips_elf_assign_gp (output_bfd, pgp))
1748 	{
1749 	  *error_message =
1750 	    (char *) _("GP relative relocation when _gp not defined");
1751 	  return bfd_reloc_dangerous;
1752 	}
1753     }
1754 
1755   return bfd_reloc_ok;
1756 }
1757 
1758 /* Do a R_MIPS_GPREL16 relocation.  This is a 16 bit value which must
1759    become the offset from the gp register.  */
1760 
1761 static bfd_reloc_status_type
mips_elf_gprel16_reloc(bfd * abfd ATTRIBUTE_UNUSED,arelent * reloc_entry,asymbol * symbol,void * data ATTRIBUTE_UNUSED,asection * input_section,bfd * output_bfd,char ** error_message ATTRIBUTE_UNUSED)1762 mips_elf_gprel16_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
1763 			asymbol *symbol, void *data ATTRIBUTE_UNUSED,
1764 			asection *input_section, bfd *output_bfd,
1765 			char **error_message ATTRIBUTE_UNUSED)
1766 {
1767   bfd_boolean relocatable;
1768   bfd_reloc_status_type ret;
1769   bfd_vma gp;
1770 
1771   if (output_bfd != NULL)
1772     relocatable = TRUE;
1773   else
1774     {
1775       relocatable = FALSE;
1776       output_bfd = symbol->section->output_section->owner;
1777     }
1778 
1779   ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
1780 			   &gp);
1781   if (ret != bfd_reloc_ok)
1782     return ret;
1783 
1784   return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1785 					input_section, relocatable,
1786 					data, gp);
1787 }
1788 
1789 /* Do a R_MIPS_LITERAL relocation.  */
1790 
1791 static bfd_reloc_status_type
mips_elf_literal_reloc(bfd * abfd,arelent * reloc_entry,asymbol * symbol,void * data,asection * input_section,bfd * output_bfd,char ** error_message)1792 mips_elf_literal_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1793 			void *data, asection *input_section, bfd *output_bfd,
1794 			char **error_message)
1795 {
1796   bfd_boolean relocatable;
1797   bfd_reloc_status_type ret;
1798   bfd_vma gp;
1799 
1800   /* R_MIPS_LITERAL relocations are defined for local symbols only.  */
1801   if (output_bfd != NULL
1802       && (symbol->flags & BSF_SECTION_SYM) == 0
1803       && (symbol->flags & BSF_LOCAL) != 0)
1804     {
1805       *error_message = (char *)
1806 	_("literal relocation occurs for an external symbol");
1807       return bfd_reloc_outofrange;
1808     }
1809 
1810   /* FIXME: The entries in the .lit8 and .lit4 sections should be merged.  */
1811   if (output_bfd != NULL)
1812     relocatable = TRUE;
1813   else
1814     {
1815       relocatable = FALSE;
1816       output_bfd = symbol->section->output_section->owner;
1817     }
1818 
1819   ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
1820 			   &gp);
1821   if (ret != bfd_reloc_ok)
1822     return ret;
1823 
1824   return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1825 					input_section, relocatable,
1826 					data, gp);
1827 }
1828 
1829 /* Do a R_MIPS_GPREL32 relocation.  This is a 32 bit value which must
1830    become the offset from the gp register.  */
1831 
1832 static bfd_reloc_status_type
mips_elf_gprel32_reloc(bfd * abfd,arelent * reloc_entry,asymbol * symbol,void * data,asection * input_section,bfd * output_bfd,char ** error_message)1833 mips_elf_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1834 			void *data, asection *input_section, bfd *output_bfd,
1835 			char **error_message)
1836 {
1837   bfd_boolean relocatable;
1838   bfd_reloc_status_type ret;
1839   bfd_vma gp;
1840 
1841   /* R_MIPS_GPREL32 relocations are defined for local symbols only.  */
1842   if (output_bfd != NULL
1843       && (symbol->flags & BSF_SECTION_SYM) == 0
1844       && (symbol->flags & BSF_LOCAL) != 0)
1845     {
1846       *error_message = (char *)
1847 	_("32bits gp relative relocation occurs for an external symbol");
1848       return bfd_reloc_outofrange;
1849     }
1850 
1851   if (output_bfd != NULL)
1852     {
1853       relocatable = TRUE;
1854       gp = _bfd_get_gp_value (output_bfd);
1855     }
1856   else
1857     {
1858       relocatable = FALSE;
1859       output_bfd = symbol->section->output_section->owner;
1860 
1861       ret = mips_elf_final_gp (output_bfd, symbol, relocatable,
1862 			       error_message, &gp);
1863       if (ret != bfd_reloc_ok)
1864 	return ret;
1865     }
1866 
1867   return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
1868 			  relocatable, data, gp);
1869 }
1870 
1871 static bfd_reloc_status_type
gprel32_with_gp(bfd * abfd,asymbol * symbol,arelent * reloc_entry,asection * input_section,bfd_boolean relocatable,void * data,bfd_vma gp)1872 gprel32_with_gp (bfd *abfd, asymbol *symbol, arelent *reloc_entry,
1873 		 asection *input_section, bfd_boolean relocatable,
1874 		 void *data, bfd_vma gp)
1875 {
1876   bfd_vma relocation;
1877   unsigned long val;
1878 
1879   if (bfd_is_com_section (symbol->section))
1880     relocation = 0;
1881   else
1882     relocation = symbol->value;
1883 
1884   relocation += symbol->section->output_section->vma;
1885   relocation += symbol->section->output_offset;
1886 
1887   if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
1888     return bfd_reloc_outofrange;
1889 
1890   if (reloc_entry->howto->src_mask == 0)
1891     val = 0;
1892   else
1893     val = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1894 
1895   /* Set val to the offset into the section or symbol.  */
1896   val += reloc_entry->addend;
1897 
1898   /* Adjust val for the final section location and GP value.  If we
1899      are producing relocatable output, we don't want to do this for
1900      an external symbol.  */
1901   if (! relocatable
1902       || (symbol->flags & BSF_SECTION_SYM) != 0)
1903     val += relocation - gp;
1904 
1905   bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
1906 
1907   if (relocatable)
1908     reloc_entry->address += input_section->output_offset;
1909 
1910   return bfd_reloc_ok;
1911 }
1912 
1913 /* Do a R_MIPS_SHIFT6 relocation. The MSB of the shift is stored at bit 2,
1914    the rest is at bits 6-10. The bitpos already got right by the howto.  */
1915 
1916 static bfd_reloc_status_type
mips_elf_shift6_reloc(bfd * abfd,arelent * reloc_entry,asymbol * symbol,void * data,asection * input_section,bfd * output_bfd,char ** error_message)1917 mips_elf_shift6_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1918 		       void *data, asection *input_section, bfd *output_bfd,
1919 		       char **error_message)
1920 {
1921   if (reloc_entry->howto->partial_inplace)
1922     {
1923       reloc_entry->addend = ((reloc_entry->addend & 0x00007c0)
1924 			     | (reloc_entry->addend & 0x00000800) >> 9);
1925     }
1926 
1927   return _bfd_mips_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1928 				      input_section, output_bfd,
1929 				      error_message);
1930 }
1931 
1932 /* Handle a mips16 GP relative reloc.  */
1933 
1934 static bfd_reloc_status_type
mips16_gprel_reloc(bfd * abfd,arelent * reloc_entry,asymbol * symbol,void * data,asection * input_section,bfd * output_bfd,char ** error_message)1935 mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1936 		    void *data, asection *input_section, bfd *output_bfd,
1937 		    char **error_message)
1938 {
1939   bfd_boolean relocatable;
1940   bfd_reloc_status_type ret;
1941   bfd_byte *location;
1942   bfd_vma gp;
1943 
1944   /* If we're relocating, and this is an external symbol, we don't want
1945      to change anything.  */
1946   if (output_bfd != NULL
1947       && (symbol->flags & BSF_SECTION_SYM) == 0
1948       && (symbol->flags & BSF_LOCAL) != 0)
1949     {
1950       reloc_entry->address += input_section->output_offset;
1951       return bfd_reloc_ok;
1952     }
1953 
1954   if (output_bfd != NULL)
1955     relocatable = TRUE;
1956   else
1957     {
1958       relocatable = FALSE;
1959       output_bfd = symbol->section->output_section->owner;
1960     }
1961 
1962   ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
1963 			   &gp);
1964   if (ret != bfd_reloc_ok)
1965     return ret;
1966 
1967   location = (bfd_byte *) data + reloc_entry->address;
1968   _bfd_mips16_elf_reloc_unshuffle (abfd, reloc_entry->howto->type, FALSE,
1969 				   location);
1970   ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1971 				       input_section, relocatable,
1972 				       data, gp);
1973   _bfd_mips16_elf_reloc_shuffle (abfd, reloc_entry->howto->type, !relocatable,
1974 				 location);
1975 
1976   return ret;
1977 }
1978 
1979 /* A mapping from BFD reloc types to MIPS ELF reloc types.  */
1980 
1981 struct elf_reloc_map {
1982   bfd_reloc_code_real_type bfd_val;
1983   enum elf_mips_reloc_type elf_val;
1984 };
1985 
1986 static const struct elf_reloc_map mips_reloc_map[] =
1987 {
1988   { BFD_RELOC_NONE, R_MIPS_NONE },
1989   { BFD_RELOC_16, R_MIPS_16 },
1990   { BFD_RELOC_32, R_MIPS_32 },
1991   /* There is no BFD reloc for R_MIPS_REL32.  */
1992   { BFD_RELOC_CTOR, R_MIPS_32 },
1993   { BFD_RELOC_64, R_MIPS_64 },
1994   { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
1995   { BFD_RELOC_HI16_S, R_MIPS_HI16 },
1996   { BFD_RELOC_LO16, R_MIPS_LO16 },
1997   { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
1998   { BFD_RELOC_GPREL32, R_MIPS_GPREL32 },
1999   { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
2000   { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
2001   { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
2002   { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
2003   { BFD_RELOC_MIPS_SHIFT5, R_MIPS_SHIFT5 },
2004   { BFD_RELOC_MIPS_SHIFT6, R_MIPS_SHIFT6 },
2005   { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP },
2006   { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
2007   { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
2008   { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
2009   { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
2010   { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
2011   { BFD_RELOC_MIPS_INSERT_A, R_MIPS_INSERT_A },
2012   { BFD_RELOC_MIPS_INSERT_B, R_MIPS_INSERT_B },
2013   { BFD_RELOC_MIPS_DELETE, R_MIPS_DELETE },
2014   { BFD_RELOC_MIPS_HIGHEST, R_MIPS_HIGHEST },
2015   { BFD_RELOC_MIPS_HIGHER, R_MIPS_HIGHER },
2016   { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
2017   { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
2018   { BFD_RELOC_MIPS_SCN_DISP, R_MIPS_SCN_DISP },
2019   { BFD_RELOC_MIPS_REL16, R_MIPS_REL16 },
2020   /* Use of R_MIPS_ADD_IMMEDIATE and R_MIPS_PJUMP is deprecated.  */
2021   { BFD_RELOC_MIPS_RELGOT, R_MIPS_RELGOT },
2022   { BFD_RELOC_MIPS_JALR, R_MIPS_JALR },
2023   { BFD_RELOC_MIPS_TLS_DTPMOD32, R_MIPS_TLS_DTPMOD32 },
2024   { BFD_RELOC_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL32 },
2025   { BFD_RELOC_MIPS_TLS_DTPMOD64, R_MIPS_TLS_DTPMOD64 },
2026   { BFD_RELOC_MIPS_TLS_DTPREL64, R_MIPS_TLS_DTPREL64 },
2027   { BFD_RELOC_MIPS_TLS_GD, R_MIPS_TLS_GD },
2028   { BFD_RELOC_MIPS_TLS_LDM, R_MIPS_TLS_LDM },
2029   { BFD_RELOC_MIPS_TLS_DTPREL_HI16, R_MIPS_TLS_DTPREL_HI16 },
2030   { BFD_RELOC_MIPS_TLS_DTPREL_LO16, R_MIPS_TLS_DTPREL_LO16 },
2031   { BFD_RELOC_MIPS_TLS_GOTTPREL, R_MIPS_TLS_GOTTPREL },
2032   { BFD_RELOC_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL32 },
2033   { BFD_RELOC_MIPS_TLS_TPREL64, R_MIPS_TLS_TPREL64 },
2034   { BFD_RELOC_MIPS_TLS_TPREL_HI16, R_MIPS_TLS_TPREL_HI16 },
2035   { BFD_RELOC_MIPS_TLS_TPREL_LO16, R_MIPS_TLS_TPREL_LO16 }
2036 };
2037 
2038 static const struct elf_reloc_map mips16_reloc_map[] =
2039 {
2040   { BFD_RELOC_MIPS16_JMP, R_MIPS16_26 - R_MIPS16_min },
2041   { BFD_RELOC_MIPS16_GPREL, R_MIPS16_GPREL - R_MIPS16_min },
2042   { BFD_RELOC_MIPS16_HI16_S, R_MIPS16_HI16 - R_MIPS16_min },
2043   { BFD_RELOC_MIPS16_LO16, R_MIPS16_LO16 - R_MIPS16_min },
2044 };
2045 
2046 /* Given a BFD reloc type, return a howto structure.  */
2047 
2048 static reloc_howto_type *
bfd_elf32_bfd_reloc_type_lookup(bfd * abfd ATTRIBUTE_UNUSED,bfd_reloc_code_real_type code)2049 bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2050 				 bfd_reloc_code_real_type code)
2051 {
2052   unsigned int i;
2053   /* FIXME: We default to RELA here instead of choosing the right
2054      relocation variant.  */
2055   reloc_howto_type *howto_table = elf_mips_howto_table_rela;
2056   reloc_howto_type *howto16_table = elf_mips16_howto_table_rela;
2057 
2058   for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map);
2059        i++)
2060     {
2061       if (mips_reloc_map[i].bfd_val == code)
2062 	return &howto_table[(int) mips_reloc_map[i].elf_val];
2063     }
2064 
2065   for (i = 0; i < sizeof (mips16_reloc_map) / sizeof (struct elf_reloc_map);
2066        i++)
2067     {
2068       if (mips16_reloc_map[i].bfd_val == code)
2069 	return &howto16_table[(int) mips16_reloc_map[i].elf_val];
2070     }
2071 
2072   switch (code)
2073     {
2074     case BFD_RELOC_VTABLE_INHERIT:
2075       return &elf_mips_gnu_vtinherit_howto;
2076     case BFD_RELOC_VTABLE_ENTRY:
2077       return &elf_mips_gnu_vtentry_howto;
2078     default:
2079       bfd_set_error (bfd_error_bad_value);
2080       return NULL;
2081     }
2082 }
2083 
2084 static reloc_howto_type *
bfd_elf32_bfd_reloc_name_lookup(bfd * abfd ATTRIBUTE_UNUSED,const char * r_name)2085 bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2086 				 const char *r_name)
2087 {
2088   unsigned int i;
2089 
2090   for (i = 0;
2091        i < (sizeof (elf_mips_howto_table_rela)
2092 	    / sizeof (elf_mips_howto_table_rela[0]));
2093        i++)
2094     if (elf_mips_howto_table_rela[i].name != NULL
2095 	&& strcasecmp (elf_mips_howto_table_rela[i].name, r_name) == 0)
2096       return &elf_mips_howto_table_rela[i];
2097 
2098   for (i = 0;
2099        i < (sizeof (elf_mips16_howto_table_rela)
2100 	    / sizeof (elf_mips16_howto_table_rela[0]));
2101        i++)
2102     if (elf_mips16_howto_table_rela[i].name != NULL
2103 	&& strcasecmp (elf_mips16_howto_table_rela[i].name, r_name) == 0)
2104       return &elf_mips16_howto_table_rela[i];
2105 
2106   if (strcasecmp (elf_mips_gnu_vtinherit_howto.name, r_name) == 0)
2107     return &elf_mips_gnu_vtinherit_howto;
2108   if (strcasecmp (elf_mips_gnu_vtentry_howto.name, r_name) == 0)
2109     return &elf_mips_gnu_vtentry_howto;
2110   if (strcasecmp (elf_mips_gnu_rel16_s2.name, r_name) == 0)
2111     return &elf_mips_gnu_rel16_s2;
2112   if (strcasecmp (elf_mips_gnu_rela16_s2.name, r_name) == 0)
2113     return &elf_mips_gnu_rela16_s2;
2114 
2115   return NULL;
2116 }
2117 
2118 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure.  */
2119 
2120 static reloc_howto_type *
mips_elf_n32_rtype_to_howto(unsigned int r_type,bfd_boolean rela_p)2121 mips_elf_n32_rtype_to_howto (unsigned int r_type, bfd_boolean rela_p)
2122 {
2123   switch (r_type)
2124     {
2125     case R_MIPS_GNU_VTINHERIT:
2126       return &elf_mips_gnu_vtinherit_howto;
2127     case R_MIPS_GNU_VTENTRY:
2128       return &elf_mips_gnu_vtentry_howto;
2129     case R_MIPS_GNU_REL16_S2:
2130       if (rela_p)
2131 	return &elf_mips_gnu_rela16_s2;
2132       else
2133 	return &elf_mips_gnu_rel16_s2;
2134     default:
2135       if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max)
2136 	{
2137 	  if (rela_p)
2138 	    return &elf_mips16_howto_table_rela[r_type - R_MIPS16_min];
2139 	  else
2140 	    return &elf_mips16_howto_table_rel[r_type - R_MIPS16_min];
2141 	}
2142       BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
2143       if (rela_p)
2144 	return &elf_mips_howto_table_rela[r_type];
2145       else
2146 	return &elf_mips_howto_table_rel[r_type];
2147       break;
2148     }
2149 }
2150 
2151 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure.  */
2152 
2153 static void
mips_info_to_howto_rel(bfd * abfd,arelent * cache_ptr,Elf_Internal_Rela * dst)2154 mips_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
2155 {
2156   unsigned int r_type;
2157 
2158   r_type = ELF32_R_TYPE (dst->r_info);
2159   cache_ptr->howto = mips_elf_n32_rtype_to_howto (r_type, FALSE);
2160 
2161   /* The addend for a GPREL16 or LITERAL relocation comes from the GP
2162      value for the object file.  We get the addend now, rather than
2163      when we do the relocation, because the symbol manipulations done
2164      by the linker may cause us to lose track of the input BFD.  */
2165   if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
2166       && (r_type == (unsigned int) R_MIPS_GPREL16
2167 	  || r_type == (unsigned int) R_MIPS_LITERAL))
2168     cache_ptr->addend = elf_gp (abfd);
2169 }
2170 
2171 /* Given a MIPS Elf_Internal_Rela, fill in an arelent structure.  */
2172 
2173 static void
mips_info_to_howto_rela(bfd * abfd ATTRIBUTE_UNUSED,arelent * cache_ptr,Elf_Internal_Rela * dst)2174 mips_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
2175 			 arelent *cache_ptr, Elf_Internal_Rela *dst)
2176 {
2177   unsigned int r_type;
2178 
2179   r_type = ELF32_R_TYPE (dst->r_info);
2180   cache_ptr->howto = mips_elf_n32_rtype_to_howto (r_type, TRUE);
2181   cache_ptr->addend = dst->r_addend;
2182 }
2183 
2184 /* Determine whether a symbol is global for the purposes of splitting
2185    the symbol table into global symbols and local symbols.  At least
2186    on Irix 5, this split must be between section symbols and all other
2187    symbols.  On most ELF targets the split is between static symbols
2188    and externally visible symbols.  */
2189 
2190 static bfd_boolean
mips_elf_sym_is_global(bfd * abfd ATTRIBUTE_UNUSED,asymbol * sym)2191 mips_elf_sym_is_global (bfd *abfd ATTRIBUTE_UNUSED, asymbol *sym)
2192 {
2193   if (SGI_COMPAT (abfd))
2194     return (sym->flags & BSF_SECTION_SYM) == 0;
2195   else
2196     return ((sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0
2197 	    || bfd_is_und_section (bfd_get_section (sym))
2198 	    || bfd_is_com_section (bfd_get_section (sym)));
2199 }
2200 
2201 /* Set the right machine number for a MIPS ELF file.  */
2202 
2203 static bfd_boolean
mips_elf_n32_object_p(bfd * abfd)2204 mips_elf_n32_object_p (bfd *abfd)
2205 {
2206   unsigned long mach;
2207 
2208   /* Irix 5 and 6 are broken.  Object file symbol tables are not always
2209      sorted correctly such that local symbols precede global symbols,
2210      and the sh_info field in the symbol table is not always right.  */
2211   if (SGI_COMPAT (abfd))
2212     elf_bad_symtab (abfd) = TRUE;
2213 
2214   mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
2215   bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
2216 
2217   if (! ABI_N32_P(abfd))
2218     return FALSE;
2219 
2220   return TRUE;
2221 }
2222 
2223 /* Support for core dump NOTE sections.  */
2224 static bfd_boolean
elf32_mips_grok_prstatus(bfd * abfd,Elf_Internal_Note * note)2225 elf32_mips_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2226 {
2227   int offset;
2228   unsigned int size;
2229 
2230   switch (note->descsz)
2231     {
2232       default:
2233 	return FALSE;
2234 
2235       case 440:		/* Linux/MIPS N32 */
2236 	/* pr_cursig */
2237 	elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
2238 
2239 	/* pr_pid */
2240 	elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
2241 
2242 	/* pr_reg */
2243 	offset = 72;
2244 	size = 360;
2245 
2246 	break;
2247     }
2248 
2249   /* Make a ".reg/999" section.  */
2250   return _bfd_elfcore_make_pseudosection (abfd, ".reg", size,
2251 					  note->descpos + offset);
2252 }
2253 
2254 static bfd_boolean
elf32_mips_grok_psinfo(bfd * abfd,Elf_Internal_Note * note)2255 elf32_mips_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2256 {
2257   switch (note->descsz)
2258     {
2259       default:
2260 	return FALSE;
2261 
2262       case 128:		/* Linux/MIPS elf_prpsinfo */
2263 	elf_tdata (abfd)->core_program
2264 	 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
2265 	elf_tdata (abfd)->core_command
2266 	 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
2267     }
2268 
2269   /* Note that for some reason, a spurious space is tacked
2270      onto the end of the args in some (at least one anyway)
2271      implementations, so strip it off if it exists.  */
2272 
2273   {
2274     char *command = elf_tdata (abfd)->core_command;
2275     int n = strlen (command);
2276 
2277     if (0 < n && command[n - 1] == ' ')
2278       command[n - 1] = '\0';
2279   }
2280 
2281   return TRUE;
2282 }
2283 
2284 /* Depending on the target vector we generate some version of Irix
2285    executables or "normal" MIPS ELF ABI executables.  */
2286 static irix_compat_t
elf_n32_mips_irix_compat(bfd * abfd)2287 elf_n32_mips_irix_compat (bfd *abfd)
2288 {
2289   if ((abfd->xvec == &bfd_elf32_nbigmips_vec)
2290       || (abfd->xvec == &bfd_elf32_nlittlemips_vec))
2291     return ict_irix6;
2292   else
2293     return ict_none;
2294 }
2295 
2296 /* ECOFF swapping routines.  These are used when dealing with the
2297    .mdebug section, which is in the ECOFF debugging format.  */
2298 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
2299   /* Symbol table magic number.  */
2300   magicSym,
2301   /* Alignment of debugging information.  E.g., 4.  */
2302   4,
2303   /* Sizes of external symbolic information.  */
2304   sizeof (struct hdr_ext),
2305   sizeof (struct dnr_ext),
2306   sizeof (struct pdr_ext),
2307   sizeof (struct sym_ext),
2308   sizeof (struct opt_ext),
2309   sizeof (struct fdr_ext),
2310   sizeof (struct rfd_ext),
2311   sizeof (struct ext_ext),
2312   /* Functions to swap in external symbolic data.  */
2313   ecoff_swap_hdr_in,
2314   ecoff_swap_dnr_in,
2315   ecoff_swap_pdr_in,
2316   ecoff_swap_sym_in,
2317   ecoff_swap_opt_in,
2318   ecoff_swap_fdr_in,
2319   ecoff_swap_rfd_in,
2320   ecoff_swap_ext_in,
2321   _bfd_ecoff_swap_tir_in,
2322   _bfd_ecoff_swap_rndx_in,
2323   /* Functions to swap out external symbolic data.  */
2324   ecoff_swap_hdr_out,
2325   ecoff_swap_dnr_out,
2326   ecoff_swap_pdr_out,
2327   ecoff_swap_sym_out,
2328   ecoff_swap_opt_out,
2329   ecoff_swap_fdr_out,
2330   ecoff_swap_rfd_out,
2331   ecoff_swap_ext_out,
2332   _bfd_ecoff_swap_tir_out,
2333   _bfd_ecoff_swap_rndx_out,
2334   /* Function to read in symbolic data.  */
2335   _bfd_mips_elf_read_ecoff_info
2336 };
2337 
2338 #define ELF_ARCH			bfd_arch_mips
2339 #define ELF_MACHINE_CODE		EM_MIPS
2340 
2341 #define elf_backend_collect		TRUE
2342 #define elf_backend_type_change_ok	TRUE
2343 #define elf_backend_can_gc_sections	TRUE
2344 #define elf_info_to_howto		mips_info_to_howto_rela
2345 #define elf_info_to_howto_rel		mips_info_to_howto_rel
2346 #define elf_backend_sym_is_global	mips_elf_sym_is_global
2347 #define elf_backend_object_p		mips_elf_n32_object_p
2348 #define elf_backend_symbol_processing	_bfd_mips_elf_symbol_processing
2349 #define elf_backend_section_processing	_bfd_mips_elf_section_processing
2350 #define elf_backend_section_from_shdr	_bfd_mips_elf_section_from_shdr
2351 #define elf_backend_fake_sections	_bfd_mips_elf_fake_sections
2352 #define elf_backend_section_from_bfd_section \
2353 					_bfd_mips_elf_section_from_bfd_section
2354 #define elf_backend_add_symbol_hook	_bfd_mips_elf_add_symbol_hook
2355 #define elf_backend_link_output_symbol_hook \
2356 					_bfd_mips_elf_link_output_symbol_hook
2357 #define elf_backend_create_dynamic_sections \
2358 					_bfd_mips_elf_create_dynamic_sections
2359 #define elf_backend_check_relocs	_bfd_mips_elf_check_relocs
2360 #define elf_backend_merge_symbol_attribute \
2361 					_bfd_mips_elf_merge_symbol_attribute
2362 #define elf_backend_adjust_dynamic_symbol \
2363 					_bfd_mips_elf_adjust_dynamic_symbol
2364 #define elf_backend_always_size_sections \
2365 					_bfd_mips_elf_always_size_sections
2366 #define elf_backend_size_dynamic_sections \
2367 					_bfd_mips_elf_size_dynamic_sections
2368 #define elf_backend_init_index_section	_bfd_elf_init_1_index_section
2369 #define elf_backend_relocate_section	_bfd_mips_elf_relocate_section
2370 #define elf_backend_finish_dynamic_symbol \
2371 					_bfd_mips_elf_finish_dynamic_symbol
2372 #define elf_backend_finish_dynamic_sections \
2373 					_bfd_mips_elf_finish_dynamic_sections
2374 #define elf_backend_final_write_processing \
2375 					_bfd_mips_elf_final_write_processing
2376 #define elf_backend_additional_program_headers \
2377 					_bfd_mips_elf_additional_program_headers
2378 #define elf_backend_modify_segment_map	_bfd_mips_elf_modify_segment_map
2379 #define elf_backend_gc_mark_hook	_bfd_mips_elf_gc_mark_hook
2380 #define elf_backend_gc_sweep_hook	_bfd_mips_elf_gc_sweep_hook
2381 #define elf_backend_copy_indirect_symbol \
2382 					_bfd_mips_elf_copy_indirect_symbol
2383 #define elf_backend_hide_symbol		_bfd_mips_elf_hide_symbol
2384 #define elf_backend_grok_prstatus	elf32_mips_grok_prstatus
2385 #define elf_backend_grok_psinfo		elf32_mips_grok_psinfo
2386 #define elf_backend_ecoff_debug_swap	&mips_elf32_ecoff_debug_swap
2387 
2388 #define elf_backend_got_header_size	(4 * MIPS_RESERVED_GOTNO)
2389 
2390 /* MIPS n32 ELF can use a mixture of REL and RELA, but some Relocations
2391    work better/work only in RELA, so we default to this.  */
2392 #define elf_backend_may_use_rel_p	1
2393 #define elf_backend_may_use_rela_p	1
2394 #define elf_backend_default_use_rela_p	1
2395 #define elf_backend_sign_extend_vma	TRUE
2396 
2397 #define elf_backend_discard_info	_bfd_mips_elf_discard_info
2398 #define elf_backend_ignore_discarded_relocs \
2399 					_bfd_mips_elf_ignore_discarded_relocs
2400 #define elf_backend_write_section	_bfd_mips_elf_write_section
2401 #define elf_backend_mips_irix_compat	elf_n32_mips_irix_compat
2402 #define elf_backend_mips_rtype_to_howto	mips_elf_n32_rtype_to_howto
2403 #define bfd_elf32_find_nearest_line	_bfd_mips_elf_find_nearest_line
2404 #define bfd_elf32_find_inliner_info	_bfd_mips_elf_find_inliner_info
2405 #define bfd_elf32_new_section_hook	_bfd_mips_elf_new_section_hook
2406 #define bfd_elf32_set_section_contents	_bfd_mips_elf_set_section_contents
2407 #define bfd_elf32_bfd_get_relocated_section_contents \
2408 				_bfd_elf_mips_get_relocated_section_contents
2409 #define bfd_elf32_bfd_link_hash_table_create \
2410 					_bfd_mips_elf_link_hash_table_create
2411 #define bfd_elf32_bfd_final_link	_bfd_mips_elf_final_link
2412 #define bfd_elf32_bfd_merge_private_bfd_data \
2413 					_bfd_mips_elf_merge_private_bfd_data
2414 #define bfd_elf32_bfd_set_private_flags	_bfd_mips_elf_set_private_flags
2415 #define bfd_elf32_bfd_print_private_bfd_data \
2416 					_bfd_mips_elf_print_private_bfd_data
2417 #define bfd_elf32_bfd_relax_section     _bfd_mips_relax_section
2418 
2419 /* Support for SGI-ish mips targets using n32 ABI.  */
2420 
2421 #define TARGET_LITTLE_SYM               bfd_elf32_nlittlemips_vec
2422 #define TARGET_LITTLE_NAME              "elf32-nlittlemips"
2423 #define TARGET_BIG_SYM                  bfd_elf32_nbigmips_vec
2424 #define TARGET_BIG_NAME                 "elf32-nbigmips"
2425 
2426 #define ELF_MAXPAGESIZE			0x10000
2427 #define ELF_COMMONPAGESIZE		0x1000
2428 
2429 #include "elf32-target.h"
2430 
2431 /* Support for traditional mips targets using n32 ABI.  */
2432 #undef TARGET_LITTLE_SYM
2433 #undef TARGET_LITTLE_NAME
2434 #undef TARGET_BIG_SYM
2435 #undef TARGET_BIG_NAME
2436 
2437 #undef ELF_MAXPAGESIZE
2438 #undef ELF_COMMONPAGESIZE
2439 
2440 #define TARGET_LITTLE_SYM               bfd_elf32_ntradlittlemips_vec
2441 #define TARGET_LITTLE_NAME              "elf32-ntradlittlemips"
2442 #define TARGET_BIG_SYM                  bfd_elf32_ntradbigmips_vec
2443 #define TARGET_BIG_NAME                 "elf32-ntradbigmips"
2444 
2445 #define ELF_MAXPAGESIZE			0x10000
2446 #define ELF_COMMONPAGESIZE		0x1000
2447 #define elf32_bed			elf32_tradbed
2448 
2449 /* Include the target file again for this target.  */
2450 #include "elf32-target.h"
2451