xref: /netbsd-src/external/gpl3/binutils/dist/bfd/elf64-mips.c (revision dd7241df2fae9da4ea2bd20a68f001fa86ecf909)
1 /* MIPS-specific support for 64-bit ELF
2    Copyright (C) 1996-2024 Free Software Foundation, Inc.
3    Ian Lance Taylor, Cygnus Support
4    Linker support added by Mark Mitchell, CodeSourcery, LLC.
5    <mark@codesourcery.com>
6 
7    This file is part of BFD, the Binary File Descriptor library.
8 
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22    MA 02110-1301, USA.  */
23 
24 
25 /* This file supports the 64-bit MIPS ELF ABI.
26 
27    The MIPS 64-bit ELF ABI uses an unusual reloc format.  This file
28    overrides the usual ELF reloc handling, and handles reading and
29    writing the relocations here.  */
30 
31 /* TODO: Many things are unsupported, even if there is some code for it
32  .       (which was mostly stolen from elf32-mips.c and slightly adapted).
33  .
34  .   - Relocation handling for REL relocs is wrong in many cases and
35  .     generally untested.
36  .   - Relocation handling for RELA relocs related to GOT support are
37  .     also likely to be wrong.
38  .   - Support for MIPS16 is untested.
39  .   - Combined relocs with RSS_* entries are unsupported.
40  .   - The whole GOT handling for NewABI is missing, some parts of
41  .     the OldABI version is still lying around and should be removed.
42  */
43 
44 #include "sysdep.h"
45 #include "bfd.h"
46 #include "libbfd.h"
47 #include "aout/ar.h"
48 #include "bfdlink.h"
49 #include "genlink.h"
50 #include "elf-bfd.h"
51 #include "elfxx-mips.h"
52 #include "elf/mips.h"
53 
54 /* Get the ECOFF swapping routines.  The 64-bit ABI is not supposed to
55    use ECOFF.  However, we support it anyhow for an easier changeover.  */
56 #include "coff/sym.h"
57 #include "coff/symconst.h"
58 #include "coff/internal.h"
59 #include "coff/ecoff.h"
60 /* The 64 bit versions of the mdebug data structures are in alpha.h.  */
61 #include "coff/alpha.h"
62 #define ECOFF_SIGNED_64
63 #include "ecoffswap.h"
64 
65 static void mips_elf64_swap_reloc_in
66   (bfd *, const Elf64_Mips_External_Rel *, Elf64_Mips_Internal_Rela *);
67 static void mips_elf64_swap_reloca_in
68   (bfd *, const Elf64_Mips_External_Rela *, Elf64_Mips_Internal_Rela *);
69 static void mips_elf64_swap_reloc_out
70   (bfd *, const Elf64_Mips_Internal_Rela *, Elf64_Mips_External_Rel *);
71 static void mips_elf64_swap_reloca_out
72   (bfd *, const Elf64_Mips_Internal_Rela *, Elf64_Mips_External_Rela *);
73 static void mips_elf64_be_swap_reloc_in
74   (bfd *, const bfd_byte *, Elf_Internal_Rela *);
75 static void mips_elf64_be_swap_reloc_out
76   (bfd *, const Elf_Internal_Rela *, bfd_byte *);
77 static void mips_elf64_be_swap_reloca_in
78   (bfd *, const bfd_byte *, Elf_Internal_Rela *);
79 static void mips_elf64_be_swap_reloca_out
80   (bfd *, const Elf_Internal_Rela *, bfd_byte *);
81 static reloc_howto_type *bfd_elf64_bfd_reloc_type_lookup
82   (bfd *, bfd_reloc_code_real_type);
83 static bool mips_elf64_info_to_howto_rela
84   (bfd *, arelent *, Elf_Internal_Rela *);
85 static long mips_elf64_get_dynamic_reloc_upper_bound
86   (bfd *);
87 static bool mips_elf64_slurp_one_reloc_table
88   (bfd *, asection *, Elf_Internal_Shdr *, bfd_size_type, arelent *,
89    asymbol **, bool);
90 static bool mips_elf64_slurp_reloc_table
91   (bfd *, asection *, asymbol **, bool);
92 static void mips_elf64_write_relocs
93   (bfd *, asection *, void *);
94 static void mips_elf64_write_rel
95   (bfd *, asection *, Elf_Internal_Shdr *, int *, void *);
96 static void mips_elf64_write_rela
97   (bfd *, asection *, Elf_Internal_Shdr *, int *, void *);
98 static bfd_reloc_status_type mips_elf64_gprel16_reloc
99   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
100 static bfd_reloc_status_type mips_elf64_literal_reloc
101   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
102 static bfd_reloc_status_type mips_elf64_gprel32_reloc
103   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
104 static bfd_reloc_status_type mips_elf64_shift6_reloc
105   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
106 static bfd_reloc_status_type mips16_gprel_reloc
107   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
108 static bool mips_elf64_assign_gp
109   (bfd *, bfd_vma *);
110 static bfd_reloc_status_type mips_elf64_final_gp
111   (bfd *, asymbol *, bool, char **, bfd_vma *);
112 static bool mips_elf64_object_p
113   (bfd *);
114 static bool mips_elf64_is_local_label_name
115   (bfd *, const char *);
116 static irix_compat_t elf64_mips_irix_compat
117   (bfd *);
118 static bool elf64_mips_grok_prstatus
119   (bfd *, Elf_Internal_Note *);
120 static bool elf64_mips_grok_psinfo
121   (bfd *, Elf_Internal_Note *);
122 
123 extern const bfd_target mips_elf64_be_vec;
124 extern const bfd_target mips_elf64_le_vec;
125 
126 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
127    from smaller values.  Start with zero, widen, *then* decrement.  */
128 #define MINUS_ONE	(((bfd_vma)0) - 1)
129 
130 /* The number of local .got entries we reserve.  */
131 #define MIPS_RESERVED_GOTNO (2)
132 
133 /* The relocation table used for SHT_REL sections.  */
134 
135 static reloc_howto_type mips_elf64_howto_table_rel[] =
136 {
137   /* No relocation.  */
138   HOWTO (R_MIPS_NONE,		/* type */
139 	 0,			/* rightshift */
140 	 0,			/* size */
141 	 0,			/* 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_NONE",		/* name */
147 	 false,			/* partial_inplace */
148 	 0,			/* src_mask */
149 	 0,			/* dst_mask */
150 	 false),		/* pcrel_offset */
151 
152   /* 16 bit relocation.  */
153   HOWTO (R_MIPS_16,		/* type */
154 	 0,			/* rightshift */
155 	 4,			/* size */
156 	 16,			/* bitsize */
157 	 false,			/* pc_relative */
158 	 0,			/* bitpos */
159 	 complain_overflow_signed, /* complain_on_overflow */
160 	 _bfd_mips_elf_generic_reloc,	/* special_function */
161 	 "R_MIPS_16",		/* name */
162 	 true,			/* partial_inplace */
163 	 0x0000ffff,		/* src_mask */
164 	 0x0000ffff,		/* dst_mask */
165 	 false),		/* pcrel_offset */
166 
167   /* 32 bit relocation.  */
168   HOWTO (R_MIPS_32,		/* type */
169 	 0,			/* rightshift */
170 	 4,			/* size */
171 	 32,			/* bitsize */
172 	 false,			/* pc_relative */
173 	 0,			/* bitpos */
174 	 complain_overflow_dont, /* complain_on_overflow */
175 	 _bfd_mips_elf_generic_reloc,	/* special_function */
176 	 "R_MIPS_32",		/* name */
177 	 true,			/* partial_inplace */
178 	 0xffffffff,		/* src_mask */
179 	 0xffffffff,		/* dst_mask */
180 	 false),		/* pcrel_offset */
181 
182   /* 32 bit symbol relative relocation.  */
183   HOWTO (R_MIPS_REL32,		/* type */
184 	 0,			/* rightshift */
185 	 4,			/* size */
186 	 32,			/* bitsize */
187 	 false,			/* pc_relative */
188 	 0,			/* bitpos */
189 	 complain_overflow_dont, /* complain_on_overflow */
190 	 _bfd_mips_elf_generic_reloc,	/* special_function */
191 	 "R_MIPS_REL32",	/* name */
192 	 true,			/* partial_inplace */
193 	 0xffffffff,		/* src_mask */
194 	 0xffffffff,		/* dst_mask */
195 	 false),		/* pcrel_offset */
196 
197   /* 26 bit jump address.  */
198   HOWTO (R_MIPS_26,		/* type */
199 	 2,			/* rightshift */
200 	 4,			/* size */
201 	 26,			/* bitsize */
202 	 false,			/* pc_relative */
203 	 0,			/* bitpos */
204 	 complain_overflow_dont, /* complain_on_overflow */
205 				/* This needs complex overflow
206 				   detection, because the upper 36
207 				   bits must match the PC + 4.  */
208 	 _bfd_mips_elf_generic_reloc,	/* special_function */
209 	 "R_MIPS_26",		/* name */
210 	 true,			/* partial_inplace */
211 	 0x03ffffff,		/* src_mask */
212 	 0x03ffffff,		/* dst_mask */
213 	 false),		/* pcrel_offset */
214 
215   /* R_MIPS_HI16 and R_MIPS_LO16 are unsupported for NewABI REL.
216      However, the native IRIX6 tools use them, so we try our best. */
217 
218   /* High 16 bits of symbol value.  */
219   HOWTO (R_MIPS_HI16,		/* type */
220 	 16,			/* rightshift */
221 	 4,			/* size */
222 	 16,			/* bitsize */
223 	 false,			/* pc_relative */
224 	 0,			/* bitpos */
225 	 complain_overflow_dont, /* complain_on_overflow */
226 	 _bfd_mips_elf_hi16_reloc, /* special_function */
227 	 "R_MIPS_HI16",		/* name */
228 	 true,			/* partial_inplace */
229 	 0x0000ffff,		/* src_mask */
230 	 0x0000ffff,		/* dst_mask */
231 	 false),		/* pcrel_offset */
232 
233   /* Low 16 bits of symbol value.  */
234   HOWTO (R_MIPS_LO16,		/* type */
235 	 0,			/* rightshift */
236 	 4,			/* size */
237 	 16,			/* bitsize */
238 	 false,			/* pc_relative */
239 	 0,			/* bitpos */
240 	 complain_overflow_dont, /* complain_on_overflow */
241 	 _bfd_mips_elf_lo16_reloc, /* special_function */
242 	 "R_MIPS_LO16",		/* name */
243 	 true,			/* partial_inplace */
244 	 0x0000ffff,		/* src_mask */
245 	 0x0000ffff,		/* dst_mask */
246 	 false),		/* pcrel_offset */
247 
248   /* GP relative reference.  */
249   HOWTO (R_MIPS_GPREL16,	/* type */
250 	 0,			/* rightshift */
251 	 4,			/* size */
252 	 16,			/* bitsize */
253 	 false,			/* pc_relative */
254 	 0,			/* bitpos */
255 	 complain_overflow_signed, /* complain_on_overflow */
256 	 mips_elf64_gprel16_reloc, /* special_function */
257 	 "R_MIPS_GPREL16",	/* name */
258 	 true,			/* partial_inplace */
259 	 0x0000ffff,		/* src_mask */
260 	 0x0000ffff,		/* dst_mask */
261 	 false),		/* pcrel_offset */
262 
263   /* Reference to literal section.  */
264   HOWTO (R_MIPS_LITERAL,	/* type */
265 	 0,			/* rightshift */
266 	 4,			/* size */
267 	 16,			/* bitsize */
268 	 false,			/* pc_relative */
269 	 0,			/* bitpos */
270 	 complain_overflow_signed, /* complain_on_overflow */
271 	 mips_elf64_literal_reloc, /* special_function */
272 	 "R_MIPS_LITERAL",	/* name */
273 	 true,			/* partial_inplace */
274 	 0x0000ffff,		/* src_mask */
275 	 0x0000ffff,		/* dst_mask */
276 	 false),		/* pcrel_offset */
277 
278   /* Reference to global offset table.  */
279   HOWTO (R_MIPS_GOT16,		/* type */
280 	 0,			/* rightshift */
281 	 4,			/* size */
282 	 16,			/* bitsize */
283 	 false,			/* pc_relative */
284 	 0,			/* bitpos */
285 	 complain_overflow_signed, /* complain_on_overflow */
286 	 _bfd_mips_elf_got16_reloc, /* special_function */
287 	 "R_MIPS_GOT16",	/* name */
288 	 true,			/* partial_inplace */
289 	 0x0000ffff,		/* src_mask */
290 	 0x0000ffff,		/* dst_mask */
291 	 false),		/* pcrel_offset */
292 
293   /* 16 bit PC relative reference.  Note that the ABI document has a typo
294      and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
295      We do the right thing here.  */
296   HOWTO (R_MIPS_PC16,		/* type */
297 	 2,			/* rightshift */
298 	 4,			/* size */
299 	 16,			/* bitsize */
300 	 true,			/* pc_relative */
301 	 0,			/* bitpos */
302 	 complain_overflow_signed, /* complain_on_overflow */
303 	 _bfd_mips_elf_generic_reloc,	/* special_function */
304 	 "R_MIPS_PC16",		/* name */
305 	 true,			/* partial_inplace */
306 	 0x0000ffff,		/* src_mask */
307 	 0x0000ffff,		/* dst_mask */
308 	 true),			/* pcrel_offset */
309 
310   /* 16 bit call through global offset table.  */
311   HOWTO (R_MIPS_CALL16,		/* type */
312 	 0,			/* rightshift */
313 	 4,			/* size */
314 	 16,			/* bitsize */
315 	 false,			/* pc_relative */
316 	 0,			/* bitpos */
317 	 complain_overflow_signed, /* complain_on_overflow */
318 	 _bfd_mips_elf_generic_reloc,	/* special_function */
319 	 "R_MIPS_CALL16",	/* name */
320 	 true,			/* partial_inplace */
321 	 0x0000ffff,		/* src_mask */
322 	 0x0000ffff,		/* dst_mask */
323 	 false),		/* pcrel_offset */
324 
325   /* 32 bit GP relative reference.  */
326   HOWTO (R_MIPS_GPREL32,	/* type */
327 	 0,			/* rightshift */
328 	 4,			/* size */
329 	 32,			/* bitsize */
330 	 false,			/* pc_relative */
331 	 0,			/* bitpos */
332 	 complain_overflow_dont, /* complain_on_overflow */
333 	 mips_elf64_gprel32_reloc, /* special_function */
334 	 "R_MIPS_GPREL32",	/* name */
335 	 true,			/* partial_inplace */
336 	 0xffffffff,		/* src_mask */
337 	 0xffffffff,		/* dst_mask */
338 	 false),		/* pcrel_offset */
339 
340   EMPTY_HOWTO (13),
341   EMPTY_HOWTO (14),
342   EMPTY_HOWTO (15),
343 
344   /* A 5 bit shift field.  */
345   HOWTO (R_MIPS_SHIFT5,		/* type */
346 	 0,			/* rightshift */
347 	 4,			/* size */
348 	 5,			/* bitsize */
349 	 false,			/* pc_relative */
350 	 6,			/* bitpos */
351 	 complain_overflow_bitfield, /* complain_on_overflow */
352 	 _bfd_mips_elf_generic_reloc,	/* special_function */
353 	 "R_MIPS_SHIFT5",	/* name */
354 	 true,			/* partial_inplace */
355 	 0x000007c0,		/* src_mask */
356 	 0x000007c0,		/* dst_mask */
357 	 false),		/* pcrel_offset */
358 
359   /* A 6 bit shift field.  */
360   HOWTO (R_MIPS_SHIFT6,		/* type */
361 	 0,			/* rightshift */
362 	 4,			/* size */
363 	 6,			/* bitsize */
364 	 false,			/* pc_relative */
365 	 6,			/* bitpos */
366 	 complain_overflow_bitfield, /* complain_on_overflow */
367 	 mips_elf64_shift6_reloc, /* special_function */
368 	 "R_MIPS_SHIFT6",	/* name */
369 	 true,			/* partial_inplace */
370 	 0x000007c4,		/* src_mask */
371 	 0x000007c4,		/* dst_mask */
372 	 false),		/* pcrel_offset */
373 
374   /* 64 bit relocation.  */
375   HOWTO (R_MIPS_64,		/* type */
376 	 0,			/* rightshift */
377 	 8,			/* size */
378 	 64,			/* bitsize */
379 	 false,			/* pc_relative */
380 	 0,			/* bitpos */
381 	 complain_overflow_dont, /* complain_on_overflow */
382 	 _bfd_mips_elf_generic_reloc,	/* special_function */
383 	 "R_MIPS_64",		/* name */
384 	 true,			/* partial_inplace */
385 	 MINUS_ONE,		/* src_mask */
386 	 MINUS_ONE,		/* dst_mask */
387 	 false),		/* pcrel_offset */
388 
389   /* Displacement in the global offset table.  */
390   HOWTO (R_MIPS_GOT_DISP,	/* type */
391 	 0,			/* rightshift */
392 	 4,			/* size */
393 	 16,			/* bitsize */
394 	 false,			/* pc_relative */
395 	 0,			/* bitpos */
396 	 complain_overflow_signed, /* complain_on_overflow */
397 	 _bfd_mips_elf_generic_reloc,	/* special_function */
398 	 "R_MIPS_GOT_DISP",	/* name */
399 	 true,			/* partial_inplace */
400 	 0x0000ffff,		/* src_mask */
401 	 0x0000ffff,		/* dst_mask */
402 	 false),		/* pcrel_offset */
403 
404   /* Displacement to page pointer in the global offset table.  */
405   HOWTO (R_MIPS_GOT_PAGE,	/* type */
406 	 0,			/* rightshift */
407 	 4,			/* size */
408 	 16,			/* bitsize */
409 	 false,			/* pc_relative */
410 	 0,			/* bitpos */
411 	 complain_overflow_signed, /* complain_on_overflow */
412 	 _bfd_mips_elf_generic_reloc,	/* special_function */
413 	 "R_MIPS_GOT_PAGE",	/* name */
414 	 true,			/* partial_inplace */
415 	 0x0000ffff,		/* src_mask */
416 	 0x0000ffff,		/* dst_mask */
417 	 false),		/* pcrel_offset */
418 
419   /* Offset from page pointer in the global offset table.  */
420   HOWTO (R_MIPS_GOT_OFST,	/* type */
421 	 0,			/* rightshift */
422 	 4,			/* size */
423 	 16,			/* bitsize */
424 	 false,			/* pc_relative */
425 	 0,			/* bitpos */
426 	 complain_overflow_signed, /* complain_on_overflow */
427 	 _bfd_mips_elf_generic_reloc,	/* special_function */
428 	 "R_MIPS_GOT_OFST",	/* name */
429 	 true,			/* partial_inplace */
430 	 0x0000ffff,		/* src_mask */
431 	 0x0000ffff,		/* dst_mask */
432 	 false),		/* pcrel_offset */
433 
434   /* High 16 bits of displacement in global offset table.  */
435   HOWTO (R_MIPS_GOT_HI16,	/* type */
436 	 0,			/* rightshift */
437 	 4,			/* size */
438 	 16,			/* bitsize */
439 	 false,			/* pc_relative */
440 	 0,			/* bitpos */
441 	 complain_overflow_dont, /* complain_on_overflow */
442 	 _bfd_mips_elf_generic_reloc,	/* special_function */
443 	 "R_MIPS_GOT_HI16",	/* name */
444 	 true,			/* partial_inplace */
445 	 0x0000ffff,		/* src_mask */
446 	 0x0000ffff,		/* dst_mask */
447 	 false),		/* pcrel_offset */
448 
449   /* Low 16 bits of displacement in global offset table.  */
450   HOWTO (R_MIPS_GOT_LO16,	/* type */
451 	 0,			/* rightshift */
452 	 4,			/* size */
453 	 16,			/* bitsize */
454 	 false,			/* pc_relative */
455 	 0,			/* bitpos */
456 	 complain_overflow_dont, /* complain_on_overflow */
457 	 _bfd_mips_elf_generic_reloc,	/* special_function */
458 	 "R_MIPS_GOT_LO16",	/* name */
459 	 true,			/* partial_inplace */
460 	 0x0000ffff,		/* src_mask */
461 	 0x0000ffff,		/* dst_mask */
462 	 false),		/* pcrel_offset */
463 
464   /* 64 bit subtraction.  */
465   HOWTO (R_MIPS_SUB,		/* type */
466 	 0,			/* rightshift */
467 	 8,			/* size */
468 	 64,			/* bitsize */
469 	 false,			/* pc_relative */
470 	 0,			/* bitpos */
471 	 complain_overflow_dont, /* complain_on_overflow */
472 	 _bfd_mips_elf_generic_reloc,	/* special_function */
473 	 "R_MIPS_SUB",		/* name */
474 	 true,			/* partial_inplace */
475 	 MINUS_ONE,		/* src_mask */
476 	 MINUS_ONE,		/* dst_mask */
477 	 false),		/* pcrel_offset */
478 
479   /* Insert the addend as an instruction.  */
480   /* FIXME: Not handled correctly.  */
481   HOWTO (R_MIPS_INSERT_A,	/* type */
482 	 0,			/* rightshift */
483 	 4,			/* size */
484 	 32,			/* bitsize */
485 	 false,			/* pc_relative */
486 	 0,			/* bitpos */
487 	 complain_overflow_dont, /* complain_on_overflow */
488 	 _bfd_mips_elf_generic_reloc,	/* special_function */
489 	 "R_MIPS_INSERT_A",	/* name */
490 	 true,			/* partial_inplace */
491 	 0xffffffff,		/* src_mask */
492 	 0xffffffff,		/* dst_mask */
493 	 false),		/* pcrel_offset */
494 
495   /* Insert the addend as an instruction, and change all relocations
496      to refer to the old instruction at the address.  */
497   /* FIXME: Not handled correctly.  */
498   HOWTO (R_MIPS_INSERT_B,	/* type */
499 	 0,			/* rightshift */
500 	 4,			/* size */
501 	 32,			/* bitsize */
502 	 false,			/* pc_relative */
503 	 0,			/* bitpos */
504 	 complain_overflow_dont, /* complain_on_overflow */
505 	 _bfd_mips_elf_generic_reloc,	/* special_function */
506 	 "R_MIPS_INSERT_B",	/* name */
507 	 true,			/* partial_inplace */
508 	 0xffffffff,		/* src_mask */
509 	 0xffffffff,		/* dst_mask */
510 	 false),		/* pcrel_offset */
511 
512   /* Delete a 32 bit instruction.  */
513   /* FIXME: Not handled correctly.  */
514   HOWTO (R_MIPS_DELETE,		/* type */
515 	 0,			/* rightshift */
516 	 4,			/* size */
517 	 32,			/* bitsize */
518 	 false,			/* pc_relative */
519 	 0,			/* bitpos */
520 	 complain_overflow_dont, /* complain_on_overflow */
521 	 _bfd_mips_elf_generic_reloc,	/* special_function */
522 	 "R_MIPS_DELETE",	/* name */
523 	 true,			/* partial_inplace */
524 	 0xffffffff,		/* src_mask */
525 	 0xffffffff,		/* dst_mask */
526 	 false),		/* pcrel_offset */
527 
528   /* The MIPS ELF64 ABI Draft wants us to support these for REL relocations.
529      We don't, because
530        a) It means building the addend from a R_MIPS_HIGHEST/R_MIPS_HIGHER/
531 	  R_MIPS_HI16/R_MIPS_LO16 sequence with varying ordering, using
532 	  fallable heuristics.
533        b) No other NewABI toolchain actually emits such relocations.  */
534   EMPTY_HOWTO (R_MIPS_HIGHER),
535   EMPTY_HOWTO (R_MIPS_HIGHEST),
536 
537   /* High 16 bits of displacement in global offset table.  */
538   HOWTO (R_MIPS_CALL_HI16,	/* type */
539 	 0,			/* rightshift */
540 	 4,			/* size */
541 	 16,			/* bitsize */
542 	 false,			/* pc_relative */
543 	 0,			/* bitpos */
544 	 complain_overflow_dont, /* complain_on_overflow */
545 	 _bfd_mips_elf_generic_reloc,	/* special_function */
546 	 "R_MIPS_CALL_HI16",	/* name */
547 	 true,			/* partial_inplace */
548 	 0x0000ffff,		/* src_mask */
549 	 0x0000ffff,		/* dst_mask */
550 	 false),		/* pcrel_offset */
551 
552   /* Low 16 bits of displacement in global offset table.  */
553   HOWTO (R_MIPS_CALL_LO16,	/* type */
554 	 0,			/* rightshift */
555 	 4,			/* size */
556 	 16,			/* bitsize */
557 	 false,			/* pc_relative */
558 	 0,			/* bitpos */
559 	 complain_overflow_dont, /* complain_on_overflow */
560 	 _bfd_mips_elf_generic_reloc,	/* special_function */
561 	 "R_MIPS_CALL_LO16",	/* name */
562 	 true,			/* partial_inplace */
563 	 0x0000ffff,		/* src_mask */
564 	 0x0000ffff,		/* dst_mask */
565 	 false),		/* pcrel_offset */
566 
567   /* Section displacement, used by an associated event location section.  */
568   HOWTO (R_MIPS_SCN_DISP,	/* type */
569 	 0,			/* rightshift */
570 	 4,			/* size */
571 	 32,			/* bitsize */
572 	 false,			/* pc_relative */
573 	 0,			/* bitpos */
574 	 complain_overflow_dont, /* complain_on_overflow */
575 	 _bfd_mips_elf_generic_reloc,	/* special_function */
576 	 "R_MIPS_SCN_DISP",	/* name */
577 	 true,			/* partial_inplace */
578 	 0xffffffff,		/* src_mask */
579 	 0xffffffff,		/* dst_mask */
580 	 false),		/* pcrel_offset */
581 
582   HOWTO (R_MIPS_REL16,		/* type */
583 	 0,			/* rightshift */
584 	 2,			/* size */
585 	 16,			/* bitsize */
586 	 false,			/* pc_relative */
587 	 0,			/* bitpos */
588 	 complain_overflow_signed, /* complain_on_overflow */
589 	 _bfd_mips_elf_generic_reloc,	/* special_function */
590 	 "R_MIPS_REL16",	/* name */
591 	 true,			/* partial_inplace */
592 	 0xffff,		/* src_mask */
593 	 0xffff,		/* dst_mask */
594 	 false),		/* pcrel_offset */
595 
596   /* These two are obsolete.  */
597   EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
598   EMPTY_HOWTO (R_MIPS_PJUMP),
599 
600   /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section.
601      It must be used for multigot GOT's (and only there).  */
602   HOWTO (R_MIPS_RELGOT,		/* type */
603 	 0,			/* rightshift */
604 	 4,			/* size */
605 	 32,			/* bitsize */
606 	 false,			/* pc_relative */
607 	 0,			/* bitpos */
608 	 complain_overflow_dont, /* complain_on_overflow */
609 	 _bfd_mips_elf_generic_reloc,	/* special_function */
610 	 "R_MIPS_RELGOT",	/* name */
611 	 true,			/* partial_inplace */
612 	 0xffffffff,		/* src_mask */
613 	 0xffffffff,		/* dst_mask */
614 	 false),		/* pcrel_offset */
615 
616   /* Protected jump conversion.  This is an optimization hint.  No
617      relocation is required for correctness.  */
618   HOWTO (R_MIPS_JALR,		/* type */
619 	 0,			/* rightshift */
620 	 4,			/* size */
621 	 32,			/* bitsize */
622 	 false,			/* pc_relative */
623 	 0,			/* bitpos */
624 	 complain_overflow_dont, /* complain_on_overflow */
625 	 _bfd_mips_elf_generic_reloc,	/* special_function */
626 	 "R_MIPS_JALR",		/* name */
627 	 false,			/* partial_inplace */
628 	 0,			/* src_mask */
629 	 0x00000000,		/* dst_mask */
630 	 false),		/* pcrel_offset */
631 
632   /* TLS relocations.  */
633   EMPTY_HOWTO (R_MIPS_TLS_DTPMOD32),
634   EMPTY_HOWTO (R_MIPS_TLS_DTPREL32),
635 
636   HOWTO (R_MIPS_TLS_DTPMOD64,	/* type */
637 	 0,			/* rightshift */
638 	 8,			/* size */
639 	 64,			/* bitsize */
640 	 false,			/* pc_relative */
641 	 0,			/* bitpos */
642 	 complain_overflow_dont, /* complain_on_overflow */
643 	 _bfd_mips_elf_generic_reloc, /* special_function */
644 	 "R_MIPS_TLS_DTPMOD64",	/* name */
645 	 true,			/* partial_inplace */
646 	 MINUS_ONE,		/* src_mask */
647 	 MINUS_ONE,		/* dst_mask */
648 	 false),		/* pcrel_offset */
649 
650   HOWTO (R_MIPS_TLS_DTPREL64,	/* type */
651 	 0,			/* rightshift */
652 	 8,			/* size */
653 	 64,			/* bitsize */
654 	 false,			/* pc_relative */
655 	 0,			/* bitpos */
656 	 complain_overflow_dont, /* complain_on_overflow */
657 	 _bfd_mips_elf_generic_reloc, /* special_function */
658 	 "R_MIPS_TLS_DTPREL64",	/* name */
659 	 true,			/* partial_inplace */
660 	 MINUS_ONE,		/* src_mask */
661 	 MINUS_ONE,		/* dst_mask */
662 	 false),		/* pcrel_offset */
663 
664   /* TLS general dynamic variable reference.  */
665   HOWTO (R_MIPS_TLS_GD,		/* type */
666 	 0,			/* rightshift */
667 	 4,			/* size */
668 	 16,			/* bitsize */
669 	 false,			/* pc_relative */
670 	 0,			/* bitpos */
671 	 complain_overflow_signed, /* complain_on_overflow */
672 	 _bfd_mips_elf_generic_reloc, /* special_function */
673 	 "R_MIPS_TLS_GD",	/* name */
674 	 true,			/* partial_inplace */
675 	 0x0000ffff,		/* src_mask */
676 	 0x0000ffff,		/* dst_mask */
677 	 false),		/* pcrel_offset */
678 
679   /* TLS local dynamic variable reference.  */
680   HOWTO (R_MIPS_TLS_LDM,	/* type */
681 	 0,			/* rightshift */
682 	 4,			/* size */
683 	 16,			/* bitsize */
684 	 false,			/* pc_relative */
685 	 0,			/* bitpos */
686 	 complain_overflow_signed, /* complain_on_overflow */
687 	 _bfd_mips_elf_generic_reloc, /* special_function */
688 	 "R_MIPS_TLS_LDM",	/* name */
689 	 true,			/* partial_inplace */
690 	 0x0000ffff,		/* src_mask */
691 	 0x0000ffff,		/* dst_mask */
692 	 false),		/* pcrel_offset */
693 
694   /* TLS local dynamic offset.  */
695   HOWTO (R_MIPS_TLS_DTPREL_HI16,	/* type */
696 	 0,			/* rightshift */
697 	 4,			/* size */
698 	 16,			/* bitsize */
699 	 false,			/* pc_relative */
700 	 0,			/* bitpos */
701 	 complain_overflow_signed, /* complain_on_overflow */
702 	 _bfd_mips_elf_generic_reloc, /* special_function */
703 	 "R_MIPS_TLS_DTPREL_HI16",	/* name */
704 	 true,			/* partial_inplace */
705 	 0x0000ffff,		/* src_mask */
706 	 0x0000ffff,		/* dst_mask */
707 	 false),		/* pcrel_offset */
708 
709   /* TLS local dynamic offset.  */
710   HOWTO (R_MIPS_TLS_DTPREL_LO16,	/* type */
711 	 0,			/* rightshift */
712 	 4,			/* size */
713 	 16,			/* bitsize */
714 	 false,			/* pc_relative */
715 	 0,			/* bitpos */
716 	 complain_overflow_signed, /* complain_on_overflow */
717 	 _bfd_mips_elf_generic_reloc, /* special_function */
718 	 "R_MIPS_TLS_DTPREL_LO16",	/* name */
719 	 true,			/* partial_inplace */
720 	 0x0000ffff,		/* src_mask */
721 	 0x0000ffff,		/* dst_mask */
722 	 false),		/* pcrel_offset */
723 
724   /* TLS thread pointer offset.  */
725   HOWTO (R_MIPS_TLS_GOTTPREL,	/* type */
726 	 0,			/* rightshift */
727 	 4,			/* size */
728 	 16,			/* bitsize */
729 	 false,			/* pc_relative */
730 	 0,			/* bitpos */
731 	 complain_overflow_signed, /* complain_on_overflow */
732 	 _bfd_mips_elf_generic_reloc, /* special_function */
733 	 "R_MIPS_TLS_GOTTPREL",	/* name */
734 	 true,			/* partial_inplace */
735 	 0x0000ffff,		/* src_mask */
736 	 0x0000ffff,		/* dst_mask */
737 	 false),		/* pcrel_offset */
738 
739   /* TLS IE dynamic relocations.  */
740   EMPTY_HOWTO (R_MIPS_TLS_TPREL32),
741 
742   HOWTO (R_MIPS_TLS_TPREL64,	/* type */
743 	 0,			/* rightshift */
744 	 8,			/* size */
745 	 64,			/* bitsize */
746 	 false,			/* pc_relative */
747 	 0,			/* bitpos */
748 	 complain_overflow_dont, /* complain_on_overflow */
749 	 _bfd_mips_elf_generic_reloc, /* special_function */
750 	 "R_MIPS_TLS_TPREL64",	/* name */
751 	 true,			/* partial_inplace */
752 	 MINUS_ONE,		/* src_mask */
753 	 MINUS_ONE,		/* dst_mask */
754 	 false),		/* pcrel_offset */
755 
756   /* TLS thread pointer offset.  */
757   HOWTO (R_MIPS_TLS_TPREL_HI16,	/* type */
758 	 0,			/* rightshift */
759 	 4,			/* size */
760 	 16,			/* bitsize */
761 	 false,			/* pc_relative */
762 	 0,			/* bitpos */
763 	 complain_overflow_signed, /* complain_on_overflow */
764 	 _bfd_mips_elf_generic_reloc, /* special_function */
765 	 "R_MIPS_TLS_TPREL_HI16", /* name */
766 	 true,			/* partial_inplace */
767 	 0x0000ffff,		/* src_mask */
768 	 0x0000ffff,		/* dst_mask */
769 	 false),		/* pcrel_offset */
770 
771   /* TLS thread pointer offset.  */
772   HOWTO (R_MIPS_TLS_TPREL_LO16,	/* type */
773 	 0,			/* rightshift */
774 	 4,			/* size */
775 	 16,			/* bitsize */
776 	 false,			/* pc_relative */
777 	 0,			/* bitpos */
778 	 complain_overflow_signed, /* complain_on_overflow */
779 	 _bfd_mips_elf_generic_reloc, /* special_function */
780 	 "R_MIPS_TLS_TPREL_LO16", /* name */
781 	 true,			/* partial_inplace */
782 	 0x0000ffff,		/* src_mask */
783 	 0x0000ffff,		/* dst_mask */
784 	 false),		/* pcrel_offset */
785 
786   /* 32 bit relocation with no addend.  */
787   HOWTO (R_MIPS_GLOB_DAT,	/* type */
788 	 0,			/* rightshift */
789 	 4,			/* size */
790 	 32,			/* bitsize */
791 	 false,			/* pc_relative */
792 	 0,			/* bitpos */
793 	 complain_overflow_dont, /* complain_on_overflow */
794 	 _bfd_mips_elf_generic_reloc, /* special_function */
795 	 "R_MIPS_GLOB_DAT",	/* name */
796 	 false,			/* partial_inplace */
797 	 0x0,			/* src_mask */
798 	 0xffffffff,		/* dst_mask */
799 	 false),		/* pcrel_offset */
800 
801   EMPTY_HOWTO (52),
802   EMPTY_HOWTO (53),
803   EMPTY_HOWTO (54),
804   EMPTY_HOWTO (55),
805   EMPTY_HOWTO (56),
806   EMPTY_HOWTO (57),
807   EMPTY_HOWTO (58),
808   EMPTY_HOWTO (59),
809 
810   HOWTO (R_MIPS_PC21_S2,	/* type */
811 	 2,			/* rightshift */
812 	 4,			/* size */
813 	 21,			/* bitsize */
814 	 true,			/* pc_relative */
815 	 0,			/* bitpos */
816 	 complain_overflow_signed, /* complain_on_overflow */
817 	 _bfd_mips_elf_generic_reloc, /* special_function */
818 	 "R_MIPS_PC21_S2",	/* name */
819 	 true,			/* partial_inplace */
820 	 0x001fffff,		/* src_mask */
821 	 0x001fffff,		/* dst_mask */
822 	 true),			/* pcrel_offset */
823 
824   HOWTO (R_MIPS_PC26_S2,	/* type */
825 	 2,			/* rightshift */
826 	 4,			/* size */
827 	 26,			/* bitsize */
828 	 true,			/* pc_relative */
829 	 0,			/* bitpos */
830 	 complain_overflow_signed, /* complain_on_overflow */
831 	 _bfd_mips_elf_generic_reloc, /* special_function */
832 	 "R_MIPS_PC26_S2",	/* name */
833 	 true,			/* partial_inplace */
834 	 0x03ffffff,		/* src_mask */
835 	 0x03ffffff,		/* dst_mask */
836 	 true),			/* pcrel_offset */
837 
838   HOWTO (R_MIPS_PC18_S3,	/* type */
839 	 3,			/* rightshift */
840 	 4,			/* size */
841 	 18,			/* bitsize */
842 	 true,			/* pc_relative */
843 	 0,			/* bitpos */
844 	 complain_overflow_signed, /* complain_on_overflow */
845 	 _bfd_mips_elf_generic_reloc,   /* special_function */
846 	 "R_MIPS_PC18_S3",	/* name */
847 	 true,			/* partial_inplace */
848 	 0x0003ffff,		/* src_mask */
849 	 0x0003ffff,		/* dst_mask */
850 	 true),			/* pcrel_offset */
851 
852   HOWTO (R_MIPS_PC19_S2,	/* type */
853 	 2,			/* rightshift */
854 	 4,			/* size */
855 	 19,			/* bitsize */
856 	 true,			/* pc_relative */
857 	 0,			/* bitpos */
858 	 complain_overflow_signed, /* complain_on_overflow */
859 	 _bfd_mips_elf_generic_reloc,   /* special_function */
860 	 "R_MIPS_PC19_S2",	/* name */
861 	 true,			/* partial_inplace */
862 	 0x0007ffff,		/* src_mask */
863 	 0x0007ffff,		/* dst_mask */
864 	 true),			/* pcrel_offset */
865 
866   HOWTO (R_MIPS_PCHI16,		/* type */
867 	 16,			/* rightshift */
868 	 4,			/* size */
869 	 16,			/* bitsize */
870 	 true,			/* pc_relative */
871 	 0,			/* bitpos */
872 	 complain_overflow_signed, /* complain_on_overflow */
873 	 _bfd_mips_elf_generic_reloc,   /* special_function */
874 	 "R_MIPS_PCHI16",	/* name */
875 	 true,			/* partial_inplace */
876 	 0x0000ffff,		/* src_mask */
877 	 0x0000ffff,		/* dst_mask */
878 	 true),			/* pcrel_offset */
879 
880   HOWTO (R_MIPS_PCLO16,		/* type */
881 	 0,			/* rightshift */
882 	 4,			/* size */
883 	 16,			/* bitsize */
884 	 true,			/* pc_relative */
885 	 0,			/* bitpos */
886 	 complain_overflow_dont, /* complain_on_overflow */
887 	 _bfd_mips_elf_generic_reloc,   /* special_function */
888 	 "R_MIPS_PCLO16",	/* name */
889 	 true,			/* partial_inplace */
890 	 0x0000ffff,		/* src_mask */
891 	 0x0000ffff,		/* dst_mask */
892 	 true),			/* pcrel_offset */
893 
894 };
895 
896 /* The relocation table used for SHT_RELA sections.  */
897 
898 static reloc_howto_type mips_elf64_howto_table_rela[] =
899 {
900   /* No relocation.  */
901   HOWTO (R_MIPS_NONE,		/* type */
902 	 0,			/* rightshift */
903 	 0,			/* size */
904 	 0,			/* bitsize */
905 	 false,			/* pc_relative */
906 	 0,			/* bitpos */
907 	 complain_overflow_dont, /* complain_on_overflow */
908 	 _bfd_mips_elf_generic_reloc,	/* special_function */
909 	 "R_MIPS_NONE",		/* name */
910 	 false,			/* partial_inplace */
911 	 0,			/* src_mask */
912 	 0,			/* dst_mask */
913 	 false),		/* pcrel_offset */
914 
915   /* 16 bit relocation.  */
916   HOWTO (R_MIPS_16,		/* type */
917 	 0,			/* rightshift */
918 	 4,			/* size */
919 	 16,			/* bitsize */
920 	 false,			/* pc_relative */
921 	 0,			/* bitpos */
922 	 complain_overflow_signed, /* complain_on_overflow */
923 	 _bfd_mips_elf_generic_reloc,	/* special_function */
924 	 "R_MIPS_16",		/* name */
925 	 false,			/* partial_inplace */
926 	 0,			/* src_mask */
927 	 0x0000ffff,		/* dst_mask */
928 	 false),		/* pcrel_offset */
929 
930   /* 32 bit relocation.  */
931   HOWTO (R_MIPS_32,		/* type */
932 	 0,			/* rightshift */
933 	 4,			/* size */
934 	 32,			/* bitsize */
935 	 false,			/* pc_relative */
936 	 0,			/* bitpos */
937 	 complain_overflow_dont, /* complain_on_overflow */
938 	 _bfd_mips_elf_generic_reloc,	/* special_function */
939 	 "R_MIPS_32",		/* name */
940 	 false,			/* partial_inplace */
941 	 0,			/* src_mask */
942 	 0xffffffff,		/* dst_mask */
943 	 false),		/* pcrel_offset */
944 
945   /* 32 bit symbol relative relocation.  */
946   HOWTO (R_MIPS_REL32,		/* type */
947 	 0,			/* rightshift */
948 	 4,			/* size */
949 	 32,			/* bitsize */
950 	 false,			/* pc_relative */
951 	 0,			/* bitpos */
952 	 complain_overflow_dont, /* complain_on_overflow */
953 	 _bfd_mips_elf_generic_reloc,	/* special_function */
954 	 "R_MIPS_REL32",	/* name */
955 	 false,			/* partial_inplace */
956 	 0,			/* src_mask */
957 	 0xffffffff,		/* dst_mask */
958 	 false),		/* pcrel_offset */
959 
960   /* 26 bit jump address.  */
961   HOWTO (R_MIPS_26,		/* type */
962 	 2,			/* rightshift */
963 	 4,			/* size */
964 	 26,			/* bitsize */
965 	 false,			/* pc_relative */
966 	 0,			/* bitpos */
967 	 complain_overflow_dont, /* complain_on_overflow */
968 				/* This needs complex overflow
969 				   detection, because the upper 36
970 				   bits must match the PC + 4.  */
971 	 _bfd_mips_elf_generic_reloc,	/* special_function */
972 	 "R_MIPS_26",		/* name */
973 	 false,			/* partial_inplace */
974 	 0,			/* src_mask */
975 	 0x03ffffff,		/* dst_mask */
976 	 false),		/* pcrel_offset */
977 
978   /* High 16 bits of symbol value.  */
979   HOWTO (R_MIPS_HI16,		/* type */
980 	 0,			/* rightshift */
981 	 4,			/* size */
982 	 16,			/* bitsize */
983 	 false,			/* pc_relative */
984 	 0,			/* bitpos */
985 	 complain_overflow_dont, /* complain_on_overflow */
986 	 _bfd_mips_elf_generic_reloc,	/* special_function */
987 	 "R_MIPS_HI16",		/* name */
988 	 false,			/* partial_inplace */
989 	 0,			/* src_mask */
990 	 0x0000ffff,		/* dst_mask */
991 	 false),		/* pcrel_offset */
992 
993   /* Low 16 bits of symbol value.  */
994   HOWTO (R_MIPS_LO16,		/* type */
995 	 0,			/* rightshift */
996 	 4,			/* size */
997 	 16,			/* bitsize */
998 	 false,			/* pc_relative */
999 	 0,			/* bitpos */
1000 	 complain_overflow_dont, /* complain_on_overflow */
1001 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1002 	 "R_MIPS_LO16",		/* name */
1003 	 false,			/* partial_inplace */
1004 	 0,			/* src_mask */
1005 	 0x0000ffff,		/* dst_mask */
1006 	 false),		/* pcrel_offset */
1007 
1008   /* GP relative reference.  */
1009   HOWTO (R_MIPS_GPREL16,	/* type */
1010 	 0,			/* rightshift */
1011 	 4,			/* size */
1012 	 16,			/* bitsize */
1013 	 false,			/* pc_relative */
1014 	 0,			/* bitpos */
1015 	 complain_overflow_signed, /* complain_on_overflow */
1016 	 mips_elf64_gprel16_reloc, /* special_function */
1017 	 "R_MIPS_GPREL16",	/* name */
1018 	 false,			/* partial_inplace */
1019 	 0,			/* src_mask */
1020 	 0x0000ffff,		/* dst_mask */
1021 	 false),		/* pcrel_offset */
1022 
1023   /* Reference to literal section.  */
1024   HOWTO (R_MIPS_LITERAL,	/* type */
1025 	 0,			/* rightshift */
1026 	 4,			/* size */
1027 	 16,			/* bitsize */
1028 	 false,			/* pc_relative */
1029 	 0,			/* bitpos */
1030 	 complain_overflow_signed, /* complain_on_overflow */
1031 	 mips_elf64_literal_reloc, /* special_function */
1032 	 "R_MIPS_LITERAL",	/* name */
1033 	 false,			/* partial_inplace */
1034 	 0,			/* src_mask */
1035 	 0x0000ffff,		/* dst_mask */
1036 	 false),		/* pcrel_offset */
1037 
1038   /* Reference to global offset table.  */
1039   HOWTO (R_MIPS_GOT16,		/* type */
1040 	 0,			/* rightshift */
1041 	 4,			/* size */
1042 	 16,			/* bitsize */
1043 	 false,			/* pc_relative */
1044 	 0,			/* bitpos */
1045 	 complain_overflow_signed, /* complain_on_overflow */
1046 	 _bfd_mips_elf_generic_reloc, /* special_function */
1047 	 "R_MIPS_GOT16",	/* name */
1048 	 false,			/* partial_inplace */
1049 	 0,			/* src_mask */
1050 	 0x0000ffff,		/* dst_mask */
1051 	 false),		/* pcrel_offset */
1052 
1053   /* 16 bit PC relative reference.  Note that the ABI document has a typo
1054      and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
1055      We do the right thing here.  */
1056   HOWTO (R_MIPS_PC16,		/* type */
1057 	 2,			/* rightshift */
1058 	 4,			/* size */
1059 	 16,			/* bitsize */
1060 	 true,			/* pc_relative */
1061 	 0,			/* bitpos */
1062 	 complain_overflow_signed, /* complain_on_overflow */
1063 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1064 	 "R_MIPS_PC16",		/* name */
1065 	 false,			/* partial_inplace */
1066 	 0,			/* src_mask */
1067 	 0x0000ffff,		/* dst_mask */
1068 	 true),			/* pcrel_offset */
1069 
1070   /* 16 bit call through global offset table.  */
1071   HOWTO (R_MIPS_CALL16,		/* type */
1072 	 0,			/* rightshift */
1073 	 4,			/* size */
1074 	 16,			/* bitsize */
1075 	 false,			/* pc_relative */
1076 	 0,			/* bitpos */
1077 	 complain_overflow_signed, /* complain_on_overflow */
1078 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1079 	 "R_MIPS_CALL16",	/* name */
1080 	 false,			/* partial_inplace */
1081 	 0,			/* src_mask */
1082 	 0x0000ffff,		/* dst_mask */
1083 	 false),		/* pcrel_offset */
1084 
1085   /* 32 bit GP relative reference.  */
1086   HOWTO (R_MIPS_GPREL32,	/* type */
1087 	 0,			/* rightshift */
1088 	 4,			/* size */
1089 	 32,			/* bitsize */
1090 	 false,			/* pc_relative */
1091 	 0,			/* bitpos */
1092 	 complain_overflow_dont, /* complain_on_overflow */
1093 	 mips_elf64_gprel32_reloc, /* special_function */
1094 	 "R_MIPS_GPREL32",	/* name */
1095 	 false,			/* partial_inplace */
1096 	 0,			/* src_mask */
1097 	 0xffffffff,		/* dst_mask */
1098 	 false),		/* pcrel_offset */
1099 
1100   EMPTY_HOWTO (13),
1101   EMPTY_HOWTO (14),
1102   EMPTY_HOWTO (15),
1103 
1104   /* A 5 bit shift field.  */
1105   HOWTO (R_MIPS_SHIFT5,		/* type */
1106 	 0,			/* rightshift */
1107 	 4,			/* size */
1108 	 5,			/* bitsize */
1109 	 false,			/* pc_relative */
1110 	 6,			/* bitpos */
1111 	 complain_overflow_bitfield, /* complain_on_overflow */
1112 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1113 	 "R_MIPS_SHIFT5",	/* name */
1114 	 false,			/* partial_inplace */
1115 	 0,			/* src_mask */
1116 	 0x000007c0,		/* dst_mask */
1117 	 false),		/* pcrel_offset */
1118 
1119   /* A 6 bit shift field.  */
1120   HOWTO (R_MIPS_SHIFT6,		/* type */
1121 	 0,			/* rightshift */
1122 	 4,			/* size */
1123 	 6,			/* bitsize */
1124 	 false,			/* pc_relative */
1125 	 6,			/* bitpos */
1126 	 complain_overflow_bitfield, /* complain_on_overflow */
1127 	 mips_elf64_shift6_reloc, /* special_function */
1128 	 "R_MIPS_SHIFT6",	/* name */
1129 	 false,			/* partial_inplace */
1130 	 0,			/* src_mask */
1131 	 0x000007c4,		/* dst_mask */
1132 	 false),		/* pcrel_offset */
1133 
1134   /* 64 bit relocation.  */
1135   HOWTO (R_MIPS_64,		/* type */
1136 	 0,			/* rightshift */
1137 	 8,			/* size */
1138 	 64,			/* bitsize */
1139 	 false,			/* pc_relative */
1140 	 0,			/* bitpos */
1141 	 complain_overflow_dont, /* complain_on_overflow */
1142 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1143 	 "R_MIPS_64",		/* name */
1144 	 false,			/* partial_inplace */
1145 	 0,			/* src_mask */
1146 	 MINUS_ONE,		/* dst_mask */
1147 	 false),		/* pcrel_offset */
1148 
1149   /* Displacement in the global offset table.  */
1150   HOWTO (R_MIPS_GOT_DISP,	/* type */
1151 	 0,			/* rightshift */
1152 	 4,			/* size */
1153 	 16,			/* bitsize */
1154 	 false,			/* pc_relative */
1155 	 0,			/* bitpos */
1156 	 complain_overflow_signed, /* complain_on_overflow */
1157 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1158 	 "R_MIPS_GOT_DISP",	/* name */
1159 	 false,			/* partial_inplace */
1160 	 0,			/* src_mask */
1161 	 0x0000ffff,		/* dst_mask */
1162 	 false),		/* pcrel_offset */
1163 
1164   /* Displacement to page pointer in the global offset table.  */
1165   HOWTO (R_MIPS_GOT_PAGE,	/* type */
1166 	 0,			/* rightshift */
1167 	 4,			/* size */
1168 	 16,			/* bitsize */
1169 	 false,			/* pc_relative */
1170 	 0,			/* bitpos */
1171 	 complain_overflow_signed, /* complain_on_overflow */
1172 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1173 	 "R_MIPS_GOT_PAGE",	/* name */
1174 	 false,			/* partial_inplace */
1175 	 0,			/* src_mask */
1176 	 0x0000ffff,		/* dst_mask */
1177 	 false),		/* pcrel_offset */
1178 
1179   /* Offset from page pointer in the global offset table.  */
1180   HOWTO (R_MIPS_GOT_OFST,	/* type */
1181 	 0,			/* rightshift */
1182 	 4,			/* size */
1183 	 16,			/* bitsize */
1184 	 false,			/* pc_relative */
1185 	 0,			/* bitpos */
1186 	 complain_overflow_signed, /* complain_on_overflow */
1187 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1188 	 "R_MIPS_GOT_OFST",	/* name */
1189 	 false,			/* partial_inplace */
1190 	 0,			/* src_mask */
1191 	 0x0000ffff,		/* dst_mask */
1192 	 false),		/* pcrel_offset */
1193 
1194   /* High 16 bits of displacement in global offset table.  */
1195   HOWTO (R_MIPS_GOT_HI16,	/* type */
1196 	 0,			/* rightshift */
1197 	 4,			/* size */
1198 	 16,			/* bitsize */
1199 	 false,			/* pc_relative */
1200 	 0,			/* bitpos */
1201 	 complain_overflow_dont, /* complain_on_overflow */
1202 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1203 	 "R_MIPS_GOT_HI16",	/* name */
1204 	 false,			/* partial_inplace */
1205 	 0,			/* src_mask */
1206 	 0x0000ffff,		/* dst_mask */
1207 	 false),		/* pcrel_offset */
1208 
1209   /* Low 16 bits of displacement in global offset table.  */
1210   HOWTO (R_MIPS_GOT_LO16,	/* type */
1211 	 0,			/* rightshift */
1212 	 4,			/* size */
1213 	 16,			/* bitsize */
1214 	 false,			/* pc_relative */
1215 	 0,			/* bitpos */
1216 	 complain_overflow_dont, /* complain_on_overflow */
1217 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1218 	 "R_MIPS_GOT_LO16",	/* name */
1219 	 false,			/* partial_inplace */
1220 	 0,			/* src_mask */
1221 	 0x0000ffff,		/* dst_mask */
1222 	 false),		/* pcrel_offset */
1223 
1224   /* 64 bit subtraction.  */
1225   HOWTO (R_MIPS_SUB,		/* type */
1226 	 0,			/* rightshift */
1227 	 8,			/* size */
1228 	 64,			/* bitsize */
1229 	 false,			/* pc_relative */
1230 	 0,			/* bitpos */
1231 	 complain_overflow_dont, /* complain_on_overflow */
1232 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1233 	 "R_MIPS_SUB",		/* name */
1234 	 false,			/* partial_inplace */
1235 	 0,			/* src_mask */
1236 	 MINUS_ONE,		/* dst_mask */
1237 	 false),		/* pcrel_offset */
1238 
1239   /* Insert the addend as an instruction.  */
1240   /* FIXME: Not handled correctly.  */
1241   HOWTO (R_MIPS_INSERT_A,	/* type */
1242 	 0,			/* rightshift */
1243 	 4,			/* size */
1244 	 32,			/* bitsize */
1245 	 false,			/* pc_relative */
1246 	 0,			/* bitpos */
1247 	 complain_overflow_dont, /* complain_on_overflow */
1248 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1249 	 "R_MIPS_INSERT_A",	/* name */
1250 	 false,			/* partial_inplace */
1251 	 0,			/* src_mask */
1252 	 0xffffffff,		/* dst_mask */
1253 	 false),		/* pcrel_offset */
1254 
1255   /* Insert the addend as an instruction, and change all relocations
1256      to refer to the old instruction at the address.  */
1257   /* FIXME: Not handled correctly.  */
1258   HOWTO (R_MIPS_INSERT_B,	/* type */
1259 	 0,			/* rightshift */
1260 	 4,			/* size */
1261 	 32,			/* bitsize */
1262 	 false,			/* pc_relative */
1263 	 0,			/* bitpos */
1264 	 complain_overflow_dont, /* complain_on_overflow */
1265 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1266 	 "R_MIPS_INSERT_B",	/* name */
1267 	 false,			/* partial_inplace */
1268 	 0,			/* src_mask */
1269 	 0xffffffff,		/* dst_mask */
1270 	 false),		/* pcrel_offset */
1271 
1272   /* Delete a 32 bit instruction.  */
1273   /* FIXME: Not handled correctly.  */
1274   HOWTO (R_MIPS_DELETE,		/* type */
1275 	 0,			/* rightshift */
1276 	 4,			/* size */
1277 	 32,			/* bitsize */
1278 	 false,			/* pc_relative */
1279 	 0,			/* bitpos */
1280 	 complain_overflow_dont, /* complain_on_overflow */
1281 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1282 	 "R_MIPS_DELETE",	/* name */
1283 	 false,			/* partial_inplace */
1284 	 0,			/* src_mask */
1285 	 0xffffffff,		/* dst_mask */
1286 	 false),		/* pcrel_offset */
1287 
1288   /* Get the higher value of a 64 bit addend.  */
1289   HOWTO (R_MIPS_HIGHER,		/* type */
1290 	 0,			/* rightshift */
1291 	 4,			/* size */
1292 	 16,			/* bitsize */
1293 	 false,			/* pc_relative */
1294 	 0,			/* bitpos */
1295 	 complain_overflow_dont, /* complain_on_overflow */
1296 	 _bfd_mips_elf_generic_reloc, /* special_function */
1297 	 "R_MIPS_HIGHER",	/* name */
1298 	 false,			/* partial_inplace */
1299 	 0,			/* src_mask */
1300 	 0x0000ffff,		/* dst_mask */
1301 	 false),		/* pcrel_offset */
1302 
1303   /* Get the highest value of a 64 bit addend.  */
1304   HOWTO (R_MIPS_HIGHEST,	/* type */
1305 	 0,			/* rightshift */
1306 	 4,			/* size */
1307 	 16,			/* bitsize */
1308 	 false,			/* pc_relative */
1309 	 0,			/* bitpos */
1310 	 complain_overflow_dont, /* complain_on_overflow */
1311 	 _bfd_mips_elf_generic_reloc, /* special_function */
1312 	 "R_MIPS_HIGHEST",	/* name */
1313 	 false,			/* partial_inplace */
1314 	 0,			/* src_mask */
1315 	 0x0000ffff,		/* dst_mask */
1316 	 false),		/* pcrel_offset */
1317 
1318   /* High 16 bits of displacement in global offset table.  */
1319   HOWTO (R_MIPS_CALL_HI16,	/* type */
1320 	 0,			/* rightshift */
1321 	 4,			/* size */
1322 	 16,			/* bitsize */
1323 	 false,			/* pc_relative */
1324 	 0,			/* bitpos */
1325 	 complain_overflow_dont, /* complain_on_overflow */
1326 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1327 	 "R_MIPS_CALL_HI16",	/* name */
1328 	 false,			/* partial_inplace */
1329 	 0,			/* src_mask */
1330 	 0x0000ffff,		/* dst_mask */
1331 	 false),		/* pcrel_offset */
1332 
1333   /* Low 16 bits of displacement in global offset table.  */
1334   HOWTO (R_MIPS_CALL_LO16,	/* type */
1335 	 0,			/* rightshift */
1336 	 4,			/* size */
1337 	 16,			/* bitsize */
1338 	 false,			/* pc_relative */
1339 	 0,			/* bitpos */
1340 	 complain_overflow_dont, /* complain_on_overflow */
1341 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1342 	 "R_MIPS_CALL_LO16",	/* name */
1343 	 false,			/* partial_inplace */
1344 	 0,			/* src_mask */
1345 	 0x0000ffff,		/* dst_mask */
1346 	 false),		/* pcrel_offset */
1347 
1348   /* Section displacement, used by an associated event location section.  */
1349   HOWTO (R_MIPS_SCN_DISP,	/* type */
1350 	 0,			/* rightshift */
1351 	 4,			/* size */
1352 	 32,			/* bitsize */
1353 	 false,			/* pc_relative */
1354 	 0,			/* bitpos */
1355 	 complain_overflow_dont, /* complain_on_overflow */
1356 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1357 	 "R_MIPS_SCN_DISP",	/* name */
1358 	 false,			/* partial_inplace */
1359 	 0,			/* src_mask */
1360 	 0xffffffff,		/* dst_mask */
1361 	 false),		/* pcrel_offset */
1362 
1363   HOWTO (R_MIPS_REL16,		/* type */
1364 	 0,			/* rightshift */
1365 	 2,			/* size */
1366 	 16,			/* bitsize */
1367 	 false,			/* pc_relative */
1368 	 0,			/* bitpos */
1369 	 complain_overflow_signed, /* complain_on_overflow */
1370 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1371 	 "R_MIPS_REL16",	/* name */
1372 	 false,			/* partial_inplace */
1373 	 0,			/* src_mask */
1374 	 0xffff,		/* dst_mask */
1375 	 false),		/* pcrel_offset */
1376 
1377   /* These two are obsolete.  */
1378   EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
1379   EMPTY_HOWTO (R_MIPS_PJUMP),
1380 
1381   /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section.
1382      It must be used for multigot GOT's (and only there).  */
1383   HOWTO (R_MIPS_RELGOT,		/* type */
1384 	 0,			/* rightshift */
1385 	 4,			/* size */
1386 	 32,			/* bitsize */
1387 	 false,			/* pc_relative */
1388 	 0,			/* bitpos */
1389 	 complain_overflow_dont, /* complain_on_overflow */
1390 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1391 	 "R_MIPS_RELGOT",	/* name */
1392 	 false,			/* partial_inplace */
1393 	 0,			/* src_mask */
1394 	 0xffffffff,		/* dst_mask */
1395 	 false),		/* pcrel_offset */
1396 
1397   /* Protected jump conversion.  This is an optimization hint.  No
1398      relocation is required for correctness.  */
1399   HOWTO (R_MIPS_JALR,		/* type */
1400 	 0,			/* rightshift */
1401 	 4,			/* size */
1402 	 32,			/* bitsize */
1403 	 false,			/* pc_relative */
1404 	 0,			/* bitpos */
1405 	 complain_overflow_dont, /* complain_on_overflow */
1406 	 _bfd_mips_elf_generic_reloc,	/* special_function */
1407 	 "R_MIPS_JALR",		/* name */
1408 	 false,			/* partial_inplace */
1409 	 0,			/* src_mask */
1410 	 0x00000000,		/* dst_mask */
1411 	 false),		/* pcrel_offset */
1412 
1413   /* TLS relocations.  */
1414   EMPTY_HOWTO (R_MIPS_TLS_DTPMOD32),
1415   EMPTY_HOWTO (R_MIPS_TLS_DTPREL32),
1416 
1417   HOWTO (R_MIPS_TLS_DTPMOD64,	/* type */
1418 	 0,			/* rightshift */
1419 	 8,			/* size */
1420 	 64,			/* bitsize */
1421 	 false,			/* pc_relative */
1422 	 0,			/* bitpos */
1423 	 complain_overflow_dont, /* complain_on_overflow */
1424 	 _bfd_mips_elf_generic_reloc, /* special_function */
1425 	 "R_MIPS_TLS_DTPMOD64", /* name */
1426 	 false,			/* partial_inplace */
1427 	 0,			/* src_mask */
1428 	 MINUS_ONE,		/* dst_mask */
1429 	 false),		/* pcrel_offset */
1430 
1431   HOWTO (R_MIPS_TLS_DTPREL64,	/* type */
1432 	 0,			/* rightshift */
1433 	 8,			/* size */
1434 	 64,			/* bitsize */
1435 	 false,			/* pc_relative */
1436 	 0,			/* bitpos */
1437 	 complain_overflow_dont, /* complain_on_overflow */
1438 	 _bfd_mips_elf_generic_reloc, /* special_function */
1439 	 "R_MIPS_TLS_DTPREL64",	/* name */
1440 	 false,			/* partial_inplace */
1441 	 0,			/* src_mask */
1442 	 MINUS_ONE,		/* dst_mask */
1443 	 false),		/* pcrel_offset */
1444 
1445   /* TLS general dynamic variable reference.  */
1446   HOWTO (R_MIPS_TLS_GD,		/* type */
1447 	 0,			/* rightshift */
1448 	 4,			/* size */
1449 	 16,			/* bitsize */
1450 	 false,			/* pc_relative */
1451 	 0,			/* bitpos */
1452 	 complain_overflow_signed, /* complain_on_overflow */
1453 	 _bfd_mips_elf_generic_reloc, /* special_function */
1454 	 "R_MIPS_TLS_GD",	/* name */
1455 	 false,			/* partial_inplace */
1456 	 0,			/* src_mask */
1457 	 0x0000ffff,		/* dst_mask */
1458 	 false),		/* pcrel_offset */
1459 
1460   /* TLS local dynamic variable reference.  */
1461   HOWTO (R_MIPS_TLS_LDM,	/* type */
1462 	 0,			/* rightshift */
1463 	 4,			/* size */
1464 	 16,			/* bitsize */
1465 	 false,			/* pc_relative */
1466 	 0,			/* bitpos */
1467 	 complain_overflow_signed, /* complain_on_overflow */
1468 	 _bfd_mips_elf_generic_reloc, /* special_function */
1469 	 "R_MIPS_TLS_LDM",	/* name */
1470 	 false,			/* partial_inplace */
1471 	 0,			/* src_mask */
1472 	 0x0000ffff,		/* dst_mask */
1473 	 false),		/* pcrel_offset */
1474 
1475   /* TLS local dynamic offset.  */
1476   HOWTO (R_MIPS_TLS_DTPREL_HI16,	/* type */
1477 	 0,			/* rightshift */
1478 	 4,			/* size */
1479 	 16,			/* bitsize */
1480 	 false,			/* pc_relative */
1481 	 0,			/* bitpos */
1482 	 complain_overflow_signed, /* complain_on_overflow */
1483 	 _bfd_mips_elf_generic_reloc, /* special_function */
1484 	 "R_MIPS_TLS_DTPREL_HI16",	/* name */
1485 	 false,			/* partial_inplace */
1486 	 0,			/* src_mask */
1487 	 0x0000ffff,		/* dst_mask */
1488 	 false),		/* pcrel_offset */
1489 
1490   /* TLS local dynamic offset.  */
1491   HOWTO (R_MIPS_TLS_DTPREL_LO16,	/* type */
1492 	 0,			/* rightshift */
1493 	 4,			/* size */
1494 	 16,			/* bitsize */
1495 	 false,			/* pc_relative */
1496 	 0,			/* bitpos */
1497 	 complain_overflow_signed, /* complain_on_overflow */
1498 	 _bfd_mips_elf_generic_reloc, /* special_function */
1499 	 "R_MIPS_TLS_DTPREL_LO16",	/* name */
1500 	 false,			/* partial_inplace */
1501 	 0,			/* src_mask */
1502 	 0x0000ffff,		/* dst_mask */
1503 	 false),		/* pcrel_offset */
1504 
1505   /* TLS thread pointer offset.  */
1506   HOWTO (R_MIPS_TLS_GOTTPREL,	/* type */
1507 	 0,			/* rightshift */
1508 	 4,			/* size */
1509 	 16,			/* bitsize */
1510 	 false,			/* pc_relative */
1511 	 0,			/* bitpos */
1512 	 complain_overflow_signed, /* complain_on_overflow */
1513 	 _bfd_mips_elf_generic_reloc, /* special_function */
1514 	 "R_MIPS_TLS_GOTTPREL",	/* name */
1515 	 false,			/* partial_inplace */
1516 	 0,			/* src_mask */
1517 	 0x0000ffff,		/* dst_mask */
1518 	 false),		/* pcrel_offset */
1519 
1520   /* TLS IE dynamic relocations.  */
1521   EMPTY_HOWTO (R_MIPS_TLS_TPREL32),
1522 
1523   HOWTO (R_MIPS_TLS_TPREL64,	/* type */
1524 	 0,			/* rightshift */
1525 	 8,			/* size */
1526 	 64,			/* bitsize */
1527 	 false,			/* pc_relative */
1528 	 0,			/* bitpos */
1529 	 complain_overflow_dont, /* complain_on_overflow */
1530 	 _bfd_mips_elf_generic_reloc, /* special_function */
1531 	 "R_MIPS_TLS_TPREL64",	/* name */
1532 	 false,			/* partial_inplace */
1533 	 0,			/* src_mask */
1534 	 MINUS_ONE,		/* dst_mask */
1535 	 false),		/* pcrel_offset */
1536 
1537   /* TLS thread pointer offset.  */
1538   HOWTO (R_MIPS_TLS_TPREL_HI16,	/* type */
1539 	 0,			/* rightshift */
1540 	 4,			/* size */
1541 	 16,			/* bitsize */
1542 	 false,			/* pc_relative */
1543 	 0,			/* bitpos */
1544 	 complain_overflow_signed, /* complain_on_overflow */
1545 	 _bfd_mips_elf_generic_reloc, /* special_function */
1546 	 "R_MIPS_TLS_TPREL_HI16", /* name */
1547 	 false,			/* partial_inplace */
1548 	 0,			/* src_mask */
1549 	 0x0000ffff,		/* dst_mask */
1550 	 false),		/* pcrel_offset */
1551 
1552   /* TLS thread pointer offset.  */
1553   HOWTO (R_MIPS_TLS_TPREL_LO16,	/* type */
1554 	 0,			/* rightshift */
1555 	 4,			/* size */
1556 	 16,			/* bitsize */
1557 	 false,			/* pc_relative */
1558 	 0,			/* bitpos */
1559 	 complain_overflow_signed, /* complain_on_overflow */
1560 	 _bfd_mips_elf_generic_reloc, /* special_function */
1561 	 "R_MIPS_TLS_TPREL_LO16", /* name */
1562 	 false,			/* partial_inplace */
1563 	 0,			/* src_mask */
1564 	 0x0000ffff,		/* dst_mask */
1565 	 false),		/* pcrel_offset */
1566 
1567   /* 32 bit relocation with no addend.  */
1568   HOWTO (R_MIPS_GLOB_DAT,	/* type */
1569 	 0,			/* rightshift */
1570 	 4,			/* size */
1571 	 32,			/* bitsize */
1572 	 false,			/* pc_relative */
1573 	 0,			/* bitpos */
1574 	 complain_overflow_dont, /* complain_on_overflow */
1575 	 _bfd_mips_elf_generic_reloc, /* special_function */
1576 	 "R_MIPS_GLOB_DAT",	/* name */
1577 	 false,			/* partial_inplace */
1578 	 0x0,			/* src_mask */
1579 	 0xffffffff,		/* dst_mask */
1580 	 false),		/* pcrel_offset */
1581 
1582   EMPTY_HOWTO (52),
1583   EMPTY_HOWTO (53),
1584   EMPTY_HOWTO (54),
1585   EMPTY_HOWTO (55),
1586   EMPTY_HOWTO (56),
1587   EMPTY_HOWTO (57),
1588   EMPTY_HOWTO (58),
1589   EMPTY_HOWTO (59),
1590 
1591   HOWTO (R_MIPS_PC21_S2,	/* type */
1592 	 2,			/* rightshift */
1593 	 4,			/* size */
1594 	 21,			/* bitsize */
1595 	 true,			/* pc_relative */
1596 	 0,			/* bitpos */
1597 	 complain_overflow_signed, /* complain_on_overflow */
1598 	 _bfd_mips_elf_generic_reloc, /* special_function */
1599 	 "R_MIPS_PC21_S2",	/* name */
1600 	 false,			/* partial_inplace */
1601 	 0,			/* src_mask */
1602 	 0x001fffff,		/* dst_mask */
1603 	 true),			/* pcrel_offset */
1604 
1605   HOWTO (R_MIPS_PC26_S2,	/* type */
1606 	 2,			/* rightshift */
1607 	 4,			/* size */
1608 	 26,			/* bitsize */
1609 	 true,			/* pc_relative */
1610 	 0,			/* bitpos */
1611 	 complain_overflow_signed, /* complain_on_overflow */
1612 	 _bfd_mips_elf_generic_reloc, /* special_function */
1613 	 "R_MIPS_PC26_S2",	/* name */
1614 	 false,			/* partial_inplace */
1615 	 0,			/* src_mask */
1616 	 0x03ffffff,		/* dst_mask */
1617 	 true),			/* pcrel_offset */
1618 
1619   HOWTO (R_MIPS_PC18_S3,	/* type */
1620 	 3,			/* rightshift */
1621 	 4,			/* size */
1622 	 18,			/* bitsize */
1623 	 true,			/* pc_relative */
1624 	 0,			/* bitpos */
1625 	 complain_overflow_signed, /* complain_on_overflow */
1626 	 _bfd_mips_elf_generic_reloc,   /* special_function */
1627 	 "R_MIPS_PC18_S3",	/* name */
1628 	 false,			/* partial_inplace */
1629 	 0,			/* src_mask */
1630 	 0x0003ffff,		/* dst_mask */
1631 	 true),			/* pcrel_offset */
1632 
1633   HOWTO (R_MIPS_PC19_S2,	/* type */
1634 	 2,			/* rightshift */
1635 	 4,			/* size */
1636 	 19,			/* bitsize */
1637 	 true,			/* pc_relative */
1638 	 0,			/* bitpos */
1639 	 complain_overflow_signed, /* complain_on_overflow */
1640 	 _bfd_mips_elf_generic_reloc,   /* special_function */
1641 	 "R_MIPS_PC19_S2",	/* name */
1642 	 false,			/* partial_inplace */
1643 	 0,			/* src_mask */
1644 	 0x0007ffff,		/* dst_mask */
1645 	 true),			/* pcrel_offset */
1646 
1647   HOWTO (R_MIPS_PCHI16,		/* type */
1648 	 16,			/* rightshift */
1649 	 4,			/* size */
1650 	 16,			/* bitsize */
1651 	 true,			/* pc_relative */
1652 	 0,			/* bitpos */
1653 	 complain_overflow_signed, /* complain_on_overflow */
1654 	 _bfd_mips_elf_generic_reloc,   /* special_function */
1655 	 "R_MIPS_PCHI16",	/* name */
1656 	 false,			/* partial_inplace */
1657 	 0,			/* src_mask */
1658 	 0x0000ffff,		/* dst_mask */
1659 	 true),			/* pcrel_offset */
1660 
1661   HOWTO (R_MIPS_PCLO16,		/* type */
1662 	 0,			/* rightshift */
1663 	 4,			/* size */
1664 	 16,			/* bitsize */
1665 	 true,			/* pc_relative */
1666 	 0,			/* bitpos */
1667 	 complain_overflow_dont, /* complain_on_overflow */
1668 	 _bfd_mips_elf_generic_reloc,   /* special_function */
1669 	 "R_MIPS_PCLO16",	/* name */
1670 	 false,			/* partial_inplace */
1671 	 0,			/* src_mask */
1672 	 0x0000ffff,		/* dst_mask */
1673 	 true),			/* pcrel_offset */
1674 
1675 };
1676 
1677 static reloc_howto_type mips16_elf64_howto_table_rel[] =
1678 {
1679   /* The reloc used for the mips16 jump instruction.  */
1680   HOWTO (R_MIPS16_26,		/* type */
1681 	 2,			/* rightshift */
1682 	 4,			/* size */
1683 	 26,			/* bitsize */
1684 	 false,			/* pc_relative */
1685 	 0,			/* bitpos */
1686 	 complain_overflow_dont, /* complain_on_overflow */
1687 				/* This needs complex overflow
1688 				   detection, because the upper four
1689 				   bits must match the PC.  */
1690 	 _bfd_mips_elf_generic_reloc, /* special_function */
1691 	 "R_MIPS16_26",		/* name */
1692 	 true,			/* partial_inplace */
1693 	 0x3ffffff,		/* src_mask */
1694 	 0x3ffffff,		/* dst_mask */
1695 	 false),		/* pcrel_offset */
1696 
1697   /* The reloc used for the mips16 gprel instruction.  */
1698   HOWTO (R_MIPS16_GPREL,	/* type */
1699 	 0,			/* rightshift */
1700 	 4,			/* size */
1701 	 16,			/* bitsize */
1702 	 false,			/* pc_relative */
1703 	 0,			/* bitpos */
1704 	 complain_overflow_signed, /* complain_on_overflow */
1705 	 mips16_gprel_reloc,	/* special_function */
1706 	 "R_MIPS16_GPREL",	/* name */
1707 	 true,			/* partial_inplace */
1708 	 0x0000ffff,		/* src_mask */
1709 	 0x0000ffff,		/* dst_mask */
1710 	 false),		/* pcrel_offset */
1711 
1712   /* A MIPS16 reference to the global offset table.  */
1713   HOWTO (R_MIPS16_GOT16,	/* type */
1714 	 0,			/* rightshift */
1715 	 4,			/* size */
1716 	 16,			/* bitsize */
1717 	 false,			/* pc_relative */
1718 	 0,			/* bitpos */
1719 	 complain_overflow_dont, /* complain_on_overflow */
1720 	 _bfd_mips_elf_got16_reloc, /* special_function */
1721 	 "R_MIPS16_GOT16",	/* name */
1722 	 true,			/* partial_inplace */
1723 	 0x0000ffff,		/* src_mask */
1724 	 0x0000ffff,		/* dst_mask */
1725 	 false),		/* pcrel_offset */
1726 
1727   /* A MIPS16 call through the global offset table.  */
1728   HOWTO (R_MIPS16_CALL16,	/* type */
1729 	 0,			/* rightshift */
1730 	 4,			/* size */
1731 	 16,			/* bitsize */
1732 	 false,			/* pc_relative */
1733 	 0,			/* bitpos */
1734 	 complain_overflow_dont, /* complain_on_overflow */
1735 	 _bfd_mips_elf_generic_reloc, /* special_function */
1736 	 "R_MIPS16_CALL16",	/* name */
1737 	 true,			/* partial_inplace */
1738 	 0x0000ffff,		/* src_mask */
1739 	 0x0000ffff,		/* dst_mask */
1740 	 false),		/* pcrel_offset */
1741 
1742   /* MIPS16 high 16 bits of symbol value.  */
1743   HOWTO (R_MIPS16_HI16,		/* type */
1744 	 16,			/* rightshift */
1745 	 4,			/* size */
1746 	 16,			/* bitsize */
1747 	 false,			/* pc_relative */
1748 	 0,			/* bitpos */
1749 	 complain_overflow_dont, /* complain_on_overflow */
1750 	 _bfd_mips_elf_hi16_reloc, /* special_function */
1751 	 "R_MIPS16_HI16",	/* name */
1752 	 true,			/* partial_inplace */
1753 	 0x0000ffff,		/* src_mask */
1754 	 0x0000ffff,		/* dst_mask */
1755 	 false),		/* pcrel_offset */
1756 
1757   /* MIPS16 low 16 bits of symbol value.  */
1758   HOWTO (R_MIPS16_LO16,		/* type */
1759 	 0,			/* rightshift */
1760 	 4,			/* size */
1761 	 16,			/* bitsize */
1762 	 false,			/* pc_relative */
1763 	 0,			/* bitpos */
1764 	 complain_overflow_dont, /* complain_on_overflow */
1765 	 _bfd_mips_elf_lo16_reloc, /* special_function */
1766 	 "R_MIPS16_LO16",	/* name */
1767 	 true,			/* partial_inplace */
1768 	 0x0000ffff,		/* src_mask */
1769 	 0x0000ffff,		/* dst_mask */
1770 	 false),		/* pcrel_offset */
1771 
1772   /* MIPS16 TLS general dynamic variable reference.  */
1773   HOWTO (R_MIPS16_TLS_GD,	/* type */
1774 	 0,			/* rightshift */
1775 	 4,			/* size */
1776 	 16,			/* bitsize */
1777 	 false,			/* pc_relative */
1778 	 0,			/* bitpos */
1779 	 complain_overflow_signed, /* complain_on_overflow */
1780 	 _bfd_mips_elf_generic_reloc, /* special_function */
1781 	 "R_MIPS16_TLS_GD",	/* name */
1782 	 true,			/* partial_inplace */
1783 	 0x0000ffff,		/* src_mask */
1784 	 0x0000ffff,		/* dst_mask */
1785 	 false),		/* pcrel_offset */
1786 
1787   /* MIPS16 TLS local dynamic variable reference.  */
1788   HOWTO (R_MIPS16_TLS_LDM,	/* type */
1789 	 0,			/* rightshift */
1790 	 4,			/* size */
1791 	 16,			/* bitsize */
1792 	 false,			/* pc_relative */
1793 	 0,			/* bitpos */
1794 	 complain_overflow_signed, /* complain_on_overflow */
1795 	 _bfd_mips_elf_generic_reloc, /* special_function */
1796 	 "R_MIPS16_TLS_LDM",	/* name */
1797 	 true,			/* partial_inplace */
1798 	 0x0000ffff,		/* src_mask */
1799 	 0x0000ffff,		/* dst_mask */
1800 	 false),		/* pcrel_offset */
1801 
1802   /* MIPS16 TLS local dynamic offset.  */
1803   HOWTO (R_MIPS16_TLS_DTPREL_HI16,	/* type */
1804 	 0,			/* rightshift */
1805 	 4,			/* size */
1806 	 16,			/* bitsize */
1807 	 false,			/* pc_relative */
1808 	 0,			/* bitpos */
1809 	 complain_overflow_signed, /* complain_on_overflow */
1810 	 _bfd_mips_elf_generic_reloc, /* special_function */
1811 	 "R_MIPS16_TLS_DTPREL_HI16",	/* name */
1812 	 true,			/* partial_inplace */
1813 	 0x0000ffff,		/* src_mask */
1814 	 0x0000ffff,		/* dst_mask */
1815 	 false),		/* pcrel_offset */
1816 
1817   /* MIPS16 TLS local dynamic offset.  */
1818   HOWTO (R_MIPS16_TLS_DTPREL_LO16,	/* type */
1819 	 0,			/* rightshift */
1820 	 4,			/* size */
1821 	 16,			/* bitsize */
1822 	 false,			/* pc_relative */
1823 	 0,			/* bitpos */
1824 	 complain_overflow_signed, /* complain_on_overflow */
1825 	 _bfd_mips_elf_generic_reloc, /* special_function */
1826 	 "R_MIPS16_TLS_DTPREL_LO16",	/* name */
1827 	 true,			/* partial_inplace */
1828 	 0x0000ffff,		/* src_mask */
1829 	 0x0000ffff,		/* dst_mask */
1830 	 false),		/* pcrel_offset */
1831 
1832   /* MIPS16 TLS thread pointer offset.  */
1833   HOWTO (R_MIPS16_TLS_GOTTPREL,	/* type */
1834 	 0,			/* rightshift */
1835 	 4,			/* size */
1836 	 16,			/* bitsize */
1837 	 false,			/* pc_relative */
1838 	 0,			/* bitpos */
1839 	 complain_overflow_signed, /* complain_on_overflow */
1840 	 _bfd_mips_elf_generic_reloc, /* special_function */
1841 	 "R_MIPS16_TLS_GOTTPREL",	/* name */
1842 	 true,			/* partial_inplace */
1843 	 0x0000ffff,		/* src_mask */
1844 	 0x0000ffff,		/* dst_mask */
1845 	 false),		/* pcrel_offset */
1846 
1847   /* MIPS16 TLS thread pointer offset.  */
1848   HOWTO (R_MIPS16_TLS_TPREL_HI16,	/* type */
1849 	 0,			/* rightshift */
1850 	 4,			/* size */
1851 	 16,			/* bitsize */
1852 	 false,			/* pc_relative */
1853 	 0,			/* bitpos */
1854 	 complain_overflow_signed, /* complain_on_overflow */
1855 	 _bfd_mips_elf_generic_reloc, /* special_function */
1856 	 "R_MIPS16_TLS_TPREL_HI16", /* name */
1857 	 true,			/* partial_inplace */
1858 	 0x0000ffff,		/* src_mask */
1859 	 0x0000ffff,		/* dst_mask */
1860 	 false),		/* pcrel_offset */
1861 
1862   /* MIPS16 TLS thread pointer offset.  */
1863   HOWTO (R_MIPS16_TLS_TPREL_LO16,	/* type */
1864 	 0,			/* rightshift */
1865 	 4,			/* size */
1866 	 16,			/* bitsize */
1867 	 false,			/* pc_relative */
1868 	 0,			/* bitpos */
1869 	 complain_overflow_signed, /* complain_on_overflow */
1870 	 _bfd_mips_elf_generic_reloc, /* special_function */
1871 	 "R_MIPS16_TLS_TPREL_LO16", /* name */
1872 	 true,			/* partial_inplace */
1873 	 0x0000ffff,		/* src_mask */
1874 	 0x0000ffff,		/* dst_mask */
1875 	 false),		/* pcrel_offset */
1876 
1877   /* MIPS16 16-bit PC-relative branch offset.  */
1878   HOWTO (R_MIPS16_PC16_S1,	/* type */
1879 	 1,			/* rightshift */
1880 	 4,			/* size */
1881 	 16,			/* bitsize */
1882 	 true,			/* pc_relative */
1883 	 0,			/* bitpos */
1884 	 complain_overflow_signed, /* complain_on_overflow */
1885 	 _bfd_mips_elf_generic_reloc, /* special_function */
1886 	 "R_MIPS16_PC16_S1",	/* name */
1887 	 true,			/* partial_inplace */
1888 	 0x0000ffff,		/* src_mask */
1889 	 0x0000ffff,		/* dst_mask */
1890 	 true),			/* pcrel_offset */
1891 };
1892 
1893 static reloc_howto_type mips16_elf64_howto_table_rela[] =
1894 {
1895   /* The reloc used for the mips16 jump instruction.  */
1896   HOWTO (R_MIPS16_26,		/* type */
1897 	 2,			/* rightshift */
1898 	 4,			/* size */
1899 	 26,			/* bitsize */
1900 	 false,			/* pc_relative */
1901 	 0,			/* bitpos */
1902 	 complain_overflow_dont, /* complain_on_overflow */
1903 				/* This needs complex overflow
1904 				   detection, because the upper four
1905 				   bits must match the PC.  */
1906 	 _bfd_mips_elf_generic_reloc, /* special_function */
1907 	 "R_MIPS16_26",		/* name */
1908 	 false,			/* partial_inplace */
1909 	 0,			/* src_mask */
1910 	 0x3ffffff,		/* dst_mask */
1911 	 false),		/* pcrel_offset */
1912 
1913   /* The reloc used for the mips16 gprel instruction.  */
1914   HOWTO (R_MIPS16_GPREL,	/* type */
1915 	 0,			/* rightshift */
1916 	 4,			/* size */
1917 	 16,			/* bitsize */
1918 	 false,			/* pc_relative */
1919 	 0,			/* bitpos */
1920 	 complain_overflow_signed, /* complain_on_overflow */
1921 	 mips16_gprel_reloc,	/* special_function */
1922 	 "R_MIPS16_GPREL",	/* name */
1923 	 false,			/* partial_inplace */
1924 	 0,			/* src_mask */
1925 	 0x0000ffff,		/* dst_mask */
1926 	 false),		/* pcrel_offset */
1927 
1928   /* A MIPS16 reference to the global offset table.  */
1929   HOWTO (R_MIPS16_GOT16,	/* type */
1930 	 0,			/* rightshift */
1931 	 4,			/* size */
1932 	 16,			/* bitsize */
1933 	 false,			/* pc_relative */
1934 	 0,			/* bitpos */
1935 	 complain_overflow_dont, /* complain_on_overflow */
1936 	 _bfd_mips_elf_got16_reloc, /* special_function */
1937 	 "R_MIPS16_GOT16",	/* name */
1938 	 false,			/* partial_inplace */
1939 	 0,			/* src_mask */
1940 	 0x0000ffff,		/* dst_mask */
1941 	 false),		/* pcrel_offset */
1942 
1943   /* A MIPS16 call through the global offset table.  */
1944   HOWTO (R_MIPS16_CALL16,	/* type */
1945 	 0,			/* rightshift */
1946 	 4,			/* size */
1947 	 16,			/* bitsize */
1948 	 false,			/* pc_relative */
1949 	 0,			/* bitpos */
1950 	 complain_overflow_dont, /* complain_on_overflow */
1951 	 _bfd_mips_elf_generic_reloc, /* special_function */
1952 	 "R_MIPS16_CALL16",	/* name */
1953 	 false,			/* partial_inplace */
1954 	 0,			/* src_mask */
1955 	 0x0000ffff,		/* dst_mask */
1956 	 false),		/* pcrel_offset */
1957 
1958   /* MIPS16 high 16 bits of symbol value.  */
1959   HOWTO (R_MIPS16_HI16,		/* type */
1960 	 16,			/* rightshift */
1961 	 4,			/* size */
1962 	 16,			/* bitsize */
1963 	 false,			/* pc_relative */
1964 	 0,			/* bitpos */
1965 	 complain_overflow_dont, /* complain_on_overflow */
1966 	 _bfd_mips_elf_hi16_reloc, /* special_function */
1967 	 "R_MIPS16_HI16",	/* name */
1968 	 false,			/* partial_inplace */
1969 	 0,			/* src_mask */
1970 	 0x0000ffff,		/* dst_mask */
1971 	 false),		/* pcrel_offset */
1972 
1973   /* MIPS16 low 16 bits of symbol value.  */
1974   HOWTO (R_MIPS16_LO16,		/* type */
1975 	 0,			/* rightshift */
1976 	 4,			/* size */
1977 	 16,			/* bitsize */
1978 	 false,			/* pc_relative */
1979 	 0,			/* bitpos */
1980 	 complain_overflow_dont, /* complain_on_overflow */
1981 	 _bfd_mips_elf_lo16_reloc, /* special_function */
1982 	 "R_MIPS16_LO16",	/* name */
1983 	 false,			/* partial_inplace */
1984 	 0,			/* src_mask */
1985 	 0x0000ffff,		/* dst_mask */
1986 	 false),		/* pcrel_offset */
1987 
1988   /* MIPS16 TLS general dynamic variable reference.  */
1989   HOWTO (R_MIPS16_TLS_GD,	/* type */
1990 	 0,			/* rightshift */
1991 	 4,			/* size */
1992 	 16,			/* bitsize */
1993 	 false,			/* pc_relative */
1994 	 0,			/* bitpos */
1995 	 complain_overflow_signed, /* complain_on_overflow */
1996 	 _bfd_mips_elf_generic_reloc, /* special_function */
1997 	 "R_MIPS16_TLS_GD",	/* name */
1998 	 false,			/* partial_inplace */
1999 	 0,			/* src_mask */
2000 	 0x0000ffff,		/* dst_mask */
2001 	 false),		/* pcrel_offset */
2002 
2003   /* MIPS16 TLS local dynamic variable reference.  */
2004   HOWTO (R_MIPS16_TLS_LDM,	/* type */
2005 	 0,			/* rightshift */
2006 	 4,			/* size */
2007 	 16,			/* bitsize */
2008 	 false,			/* pc_relative */
2009 	 0,			/* bitpos */
2010 	 complain_overflow_signed, /* complain_on_overflow */
2011 	 _bfd_mips_elf_generic_reloc, /* special_function */
2012 	 "R_MIPS16_TLS_LDM",	/* name */
2013 	 false,			/* partial_inplace */
2014 	 0,			/* src_mask */
2015 	 0x0000ffff,		/* dst_mask */
2016 	 false),		/* pcrel_offset */
2017 
2018   /* MIPS16 TLS local dynamic offset.  */
2019   HOWTO (R_MIPS16_TLS_DTPREL_HI16,	/* type */
2020 	 0,			/* rightshift */
2021 	 4,			/* size */
2022 	 16,			/* bitsize */
2023 	 false,			/* pc_relative */
2024 	 0,			/* bitpos */
2025 	 complain_overflow_signed, /* complain_on_overflow */
2026 	 _bfd_mips_elf_generic_reloc, /* special_function */
2027 	 "R_MIPS16_TLS_DTPREL_HI16",	/* name */
2028 	 false,			/* partial_inplace */
2029 	 0,			/* src_mask */
2030 	 0x0000ffff,		/* dst_mask */
2031 	 false),		/* pcrel_offset */
2032 
2033   /* MIPS16 TLS local dynamic offset.  */
2034   HOWTO (R_MIPS16_TLS_DTPREL_LO16,	/* type */
2035 	 0,			/* rightshift */
2036 	 4,			/* size */
2037 	 16,			/* bitsize */
2038 	 false,			/* pc_relative */
2039 	 0,			/* bitpos */
2040 	 complain_overflow_signed, /* complain_on_overflow */
2041 	 _bfd_mips_elf_generic_reloc, /* special_function */
2042 	 "R_MIPS16_TLS_DTPREL_LO16",	/* name */
2043 	 false,			/* partial_inplace */
2044 	 0,			/* src_mask */
2045 	 0x0000ffff,		/* dst_mask */
2046 	 false),		/* pcrel_offset */
2047 
2048   /* MIPS16 TLS thread pointer offset.  */
2049   HOWTO (R_MIPS16_TLS_GOTTPREL,	/* type */
2050 	 0,			/* rightshift */
2051 	 4,			/* size */
2052 	 16,			/* bitsize */
2053 	 false,			/* pc_relative */
2054 	 0,			/* bitpos */
2055 	 complain_overflow_signed, /* complain_on_overflow */
2056 	 _bfd_mips_elf_generic_reloc, /* special_function */
2057 	 "R_MIPS16_TLS_GOTTPREL",	/* name */
2058 	 false,			/* partial_inplace */
2059 	 0,			/* src_mask */
2060 	 0x0000ffff,		/* dst_mask */
2061 	 false),		/* pcrel_offset */
2062 
2063   /* MIPS16 TLS thread pointer offset.  */
2064   HOWTO (R_MIPS16_TLS_TPREL_HI16,	/* type */
2065 	 0,			/* rightshift */
2066 	 4,			/* size */
2067 	 16,			/* bitsize */
2068 	 false,			/* pc_relative */
2069 	 0,			/* bitpos */
2070 	 complain_overflow_signed, /* complain_on_overflow */
2071 	 _bfd_mips_elf_generic_reloc, /* special_function */
2072 	 "R_MIPS16_TLS_TPREL_HI16", /* name */
2073 	 false,			/* partial_inplace */
2074 	 0,			/* src_mask */
2075 	 0x0000ffff,		/* dst_mask */
2076 	 false),		/* pcrel_offset */
2077 
2078   /* MIPS16 TLS thread pointer offset.  */
2079   HOWTO (R_MIPS16_TLS_TPREL_LO16,	/* type */
2080 	 0,			/* rightshift */
2081 	 4,			/* size */
2082 	 16,			/* bitsize */
2083 	 false,			/* pc_relative */
2084 	 0,			/* bitpos */
2085 	 complain_overflow_signed, /* complain_on_overflow */
2086 	 _bfd_mips_elf_generic_reloc, /* special_function */
2087 	 "R_MIPS16_TLS_TPREL_LO16", /* name */
2088 	 false,			/* partial_inplace */
2089 	 0,			/* src_mask */
2090 	 0x0000ffff,		/* dst_mask */
2091 	 false),		/* pcrel_offset */
2092 
2093   /* MIPS16 16-bit PC-relative branch offset.  */
2094   HOWTO (R_MIPS16_PC16_S1,	/* type */
2095 	 1,			/* rightshift */
2096 	 4,			/* size */
2097 	 16,			/* bitsize */
2098 	 true,			/* pc_relative */
2099 	 0,			/* bitpos */
2100 	 complain_overflow_signed, /* complain_on_overflow */
2101 	 _bfd_mips_elf_generic_reloc, /* special_function */
2102 	 "R_MIPS16_PC16_S1",	/* name */
2103 	 false,			/* partial_inplace */
2104 	 0,			/* src_mask */
2105 	 0x0000ffff,		/* dst_mask */
2106 	 true),			/* pcrel_offset */
2107 };
2108 
2109 static reloc_howto_type micromips_elf64_howto_table_rel[] =
2110 {
2111   EMPTY_HOWTO (130),
2112   EMPTY_HOWTO (131),
2113   EMPTY_HOWTO (132),
2114 
2115   /* 26 bit jump address.  */
2116   HOWTO (R_MICROMIPS_26_S1,	/* type */
2117 	 1,			/* rightshift */
2118 	 4,			/* size */
2119 	 26,			/* bitsize */
2120 	 false,			/* pc_relative */
2121 	 0,			/* bitpos */
2122 	 complain_overflow_dont, /* complain_on_overflow */
2123 				/* This needs complex overflow
2124 				   detection, because the upper four
2125 				   bits must match the PC.  */
2126 	 _bfd_mips_elf_generic_reloc, /* special_function */
2127 	 "R_MICROMIPS_26_S1",	/* name */
2128 	 true,			/* partial_inplace */
2129 	 0x3ffffff,		/* src_mask */
2130 	 0x3ffffff,		/* dst_mask */
2131 	 false),		/* pcrel_offset */
2132 
2133   /* High 16 bits of symbol value.  */
2134   HOWTO (R_MICROMIPS_HI16,	/* type */
2135 	 16,			/* rightshift */
2136 	 4,			/* size */
2137 	 16,			/* bitsize */
2138 	 false,			/* pc_relative */
2139 	 0,			/* bitpos */
2140 	 complain_overflow_dont, /* complain_on_overflow */
2141 	 _bfd_mips_elf_hi16_reloc, /* special_function */
2142 	 "R_MICROMIPS_HI16",	/* name */
2143 	 true,			/* partial_inplace */
2144 	 0x0000ffff,		/* src_mask */
2145 	 0x0000ffff,		/* dst_mask */
2146 	 false),		/* pcrel_offset */
2147 
2148   /* Low 16 bits of symbol value.  */
2149   HOWTO (R_MICROMIPS_LO16,	/* type */
2150 	 0,			/* rightshift */
2151 	 4,			/* size */
2152 	 16,			/* bitsize */
2153 	 false,			/* pc_relative */
2154 	 0,			/* bitpos */
2155 	 complain_overflow_dont, /* complain_on_overflow */
2156 	 _bfd_mips_elf_lo16_reloc, /* special_function */
2157 	 "R_MICROMIPS_LO16",	/* name */
2158 	 true,			/* partial_inplace */
2159 	 0x0000ffff,		/* src_mask */
2160 	 0x0000ffff,		/* dst_mask */
2161 	 false),		/* pcrel_offset */
2162 
2163   /* GP relative reference.  */
2164   HOWTO (R_MICROMIPS_GPREL16,	/* type */
2165 	 0,			/* rightshift */
2166 	 4,			/* size */
2167 	 16,			/* bitsize */
2168 	 false,			/* pc_relative */
2169 	 0,			/* bitpos */
2170 	 complain_overflow_signed, /* complain_on_overflow */
2171 	 _bfd_mips_elf32_gprel16_reloc, /* special_function */
2172 	 "R_MICROMIPS_GPREL16",	/* name */
2173 	 true,			/* partial_inplace */
2174 	 0x0000ffff,		/* src_mask */
2175 	 0x0000ffff,		/* dst_mask */
2176 	 false),		/* pcrel_offset */
2177 
2178   /* Reference to literal section.  */
2179   HOWTO (R_MICROMIPS_LITERAL,	/* type */
2180 	 0,			/* rightshift */
2181 	 4,			/* size */
2182 	 16,			/* bitsize */
2183 	 false,			/* pc_relative */
2184 	 0,			/* bitpos */
2185 	 complain_overflow_signed, /* complain_on_overflow */
2186 	 _bfd_mips_elf32_gprel16_reloc, /* special_function */
2187 	 "R_MICROMIPS_LITERAL",	/* name */
2188 	 true,			/* partial_inplace */
2189 	 0x0000ffff,		/* src_mask */
2190 	 0x0000ffff,		/* dst_mask */
2191 	 false),		/* pcrel_offset */
2192 
2193   /* Reference to global offset table.  */
2194   HOWTO (R_MICROMIPS_GOT16,	/* type */
2195 	 0,			/* rightshift */
2196 	 4,			/* size */
2197 	 16,			/* bitsize */
2198 	 false,			/* pc_relative */
2199 	 0,			/* bitpos */
2200 	 complain_overflow_signed, /* complain_on_overflow */
2201 	 _bfd_mips_elf_got16_reloc, /* special_function */
2202 	 "R_MICROMIPS_GOT16",	/* name */
2203 	 true,			/* partial_inplace */
2204 	 0x0000ffff,		/* src_mask */
2205 	 0x0000ffff,		/* dst_mask */
2206 	 false),		/* pcrel_offset */
2207 
2208   /* This is for microMIPS branches.  */
2209   HOWTO (R_MICROMIPS_PC7_S1,	/* type */
2210 	 1,			/* rightshift */
2211 	 2,			/* size */
2212 	 7,			/* bitsize */
2213 	 true,			/* pc_relative */
2214 	 0,			/* bitpos */
2215 	 complain_overflow_signed, /* complain_on_overflow */
2216 	 _bfd_mips_elf_generic_reloc, /* special_function */
2217 	 "R_MICROMIPS_PC7_S1",	/* name */
2218 	 true,			/* partial_inplace */
2219 	 0x0000007f,		/* src_mask */
2220 	 0x0000007f,		/* dst_mask */
2221 	 true),			/* pcrel_offset */
2222 
2223   HOWTO (R_MICROMIPS_PC10_S1,	/* type */
2224 	 1,			/* rightshift */
2225 	 2,			/* size */
2226 	 10,			/* bitsize */
2227 	 true,			/* pc_relative */
2228 	 0,			/* bitpos */
2229 	 complain_overflow_signed, /* complain_on_overflow */
2230 	 _bfd_mips_elf_generic_reloc, /* special_function */
2231 	 "R_MICROMIPS_PC10_S1",	/* name */
2232 	 true,			/* partial_inplace */
2233 	 0x000003ff,		/* src_mask */
2234 	 0x000003ff,		/* dst_mask */
2235 	 true),			/* pcrel_offset */
2236 
2237   HOWTO (R_MICROMIPS_PC16_S1,	/* type */
2238 	 1,			/* rightshift */
2239 	 4,			/* size */
2240 	 16,			/* bitsize */
2241 	 true,			/* pc_relative */
2242 	 0,			/* bitpos */
2243 	 complain_overflow_signed, /* complain_on_overflow */
2244 	 _bfd_mips_elf_generic_reloc, /* special_function */
2245 	 "R_MICROMIPS_PC16_S1",	/* name */
2246 	 true,			/* partial_inplace */
2247 	 0x0000ffff,		/* src_mask */
2248 	 0x0000ffff,		/* dst_mask */
2249 	 true),			/* pcrel_offset */
2250 
2251   /* 16 bit call through global offset table.  */
2252   HOWTO (R_MICROMIPS_CALL16,	/* type */
2253 	 0,			/* rightshift */
2254 	 4,			/* size */
2255 	 16,			/* bitsize */
2256 	 false,			/* pc_relative */
2257 	 0,			/* bitpos */
2258 	 complain_overflow_signed, /* complain_on_overflow */
2259 	 _bfd_mips_elf_generic_reloc, /* special_function */
2260 	 "R_MICROMIPS_CALL16",	/* name */
2261 	 true,			/* partial_inplace */
2262 	 0x0000ffff,		/* src_mask */
2263 	 0x0000ffff,		/* dst_mask */
2264 	 false),		/* pcrel_offset */
2265 
2266   EMPTY_HOWTO (143),
2267   EMPTY_HOWTO (144),
2268 
2269   /* Displacement in the global offset table.  */
2270   HOWTO (R_MICROMIPS_GOT_DISP,	/* type */
2271 	 0,			/* rightshift */
2272 	 4,			/* size */
2273 	 16,			/* bitsize */
2274 	 false,			/* pc_relative */
2275 	 0,			/* bitpos */
2276 	 complain_overflow_signed, /* complain_on_overflow */
2277 	 _bfd_mips_elf_generic_reloc, /* special_function */
2278 	 "R_MICROMIPS_GOT_DISP",/* name */
2279 	 true,			/* partial_inplace */
2280 	 0x0000ffff,		/* src_mask */
2281 	 0x0000ffff,		/* dst_mask */
2282 	 false),		/* pcrel_offset */
2283 
2284   /* Displacement to page pointer in the global offset table.  */
2285   HOWTO (R_MICROMIPS_GOT_PAGE,	/* type */
2286 	 0,			/* rightshift */
2287 	 4,			/* size */
2288 	 16,			/* bitsize */
2289 	 false,			/* pc_relative */
2290 	 0,			/* bitpos */
2291 	 complain_overflow_signed, /* complain_on_overflow */
2292 	 _bfd_mips_elf_generic_reloc, /* special_function */
2293 	 "R_MICROMIPS_GOT_PAGE",/* name */
2294 	 true,			/* partial_inplace */
2295 	 0x0000ffff,		/* src_mask */
2296 	 0x0000ffff,		/* dst_mask */
2297 	 false),		/* pcrel_offset */
2298 
2299   /* Offset from page pointer in the global offset table.  */
2300   HOWTO (R_MICROMIPS_GOT_OFST,	/* type */
2301 	 0,			/* rightshift */
2302 	 4,			/* size */
2303 	 16,			/* bitsize */
2304 	 false,			/* pc_relative */
2305 	 0,			/* bitpos */
2306 	 complain_overflow_signed, /* complain_on_overflow */
2307 	 _bfd_mips_elf_generic_reloc, /* special_function */
2308 	 "R_MICROMIPS_GOT_OFST",/* name */
2309 	 true,			/* partial_inplace */
2310 	 0x0000ffff,		/* src_mask */
2311 	 0x0000ffff,		/* dst_mask */
2312 	 false),		/* pcrel_offset */
2313 
2314   /* High 16 bits of displacement in global offset table.  */
2315   HOWTO (R_MICROMIPS_GOT_HI16,	/* type */
2316 	 0,			/* rightshift */
2317 	 4,			/* size */
2318 	 16,			/* bitsize */
2319 	 false,			/* pc_relative */
2320 	 0,			/* bitpos */
2321 	 complain_overflow_dont, /* complain_on_overflow */
2322 	 _bfd_mips_elf_generic_reloc, /* special_function */
2323 	 "R_MICROMIPS_GOT_HI16",/* name */
2324 	 true,			/* partial_inplace */
2325 	 0x0000ffff,		/* src_mask */
2326 	 0x0000ffff,		/* dst_mask */
2327 	 false),		/* pcrel_offset */
2328 
2329   /* Low 16 bits of displacement in global offset table.  */
2330   HOWTO (R_MICROMIPS_GOT_LO16,	/* type */
2331 	 0,			/* rightshift */
2332 	 4,			/* size */
2333 	 16,			/* bitsize */
2334 	 false,			/* pc_relative */
2335 	 0,			/* bitpos */
2336 	 complain_overflow_dont, /* complain_on_overflow */
2337 	 _bfd_mips_elf_generic_reloc, /* special_function */
2338 	 "R_MICROMIPS_GOT_LO16",/* name */
2339 	 true,			/* partial_inplace */
2340 	 0x0000ffff,		/* src_mask */
2341 	 0x0000ffff,		/* dst_mask */
2342 	 false),		/* pcrel_offset */
2343 
2344   /* 64 bit subtraction.  Used in the N32 ABI.  */
2345   HOWTO (R_MICROMIPS_SUB,	/* type */
2346 	 0,			/* rightshift */
2347 	 8,			/* size */
2348 	 64,			/* bitsize */
2349 	 false,			/* pc_relative */
2350 	 0,			/* bitpos */
2351 	 complain_overflow_dont, /* complain_on_overflow */
2352 	 _bfd_mips_elf_generic_reloc, /* special_function */
2353 	 "R_MICROMIPS_SUB",	/* name */
2354 	 true,			/* partial_inplace */
2355 	 MINUS_ONE,		/* src_mask */
2356 	 MINUS_ONE,		/* dst_mask */
2357 	 false),		/* pcrel_offset */
2358 
2359   /* We don't support these for REL relocations, because it means building
2360      the addend from a R_MICROMIPS_HIGHEST/R_MICROMIPS_HIGHER/
2361      R_MICROMIPS_HI16/R_MICROMIPS_LO16 sequence with varying ordering,
2362      using fallable heuristics.  */
2363   EMPTY_HOWTO (R_MICROMIPS_HIGHER),
2364   EMPTY_HOWTO (R_MICROMIPS_HIGHEST),
2365 
2366   /* High 16 bits of displacement in global offset table.  */
2367   HOWTO (R_MICROMIPS_CALL_HI16,	/* type */
2368 	 0,			/* rightshift */
2369 	 4,			/* size */
2370 	 16,			/* bitsize */
2371 	 false,			/* pc_relative */
2372 	 0,			/* bitpos */
2373 	 complain_overflow_dont, /* complain_on_overflow */
2374 	 _bfd_mips_elf_generic_reloc, /* special_function */
2375 	 "R_MICROMIPS_CALL_HI16",/* name */
2376 	 true,			/* partial_inplace */
2377 	 0x0000ffff,		/* src_mask */
2378 	 0x0000ffff,		/* dst_mask */
2379 	 false),		/* pcrel_offset */
2380 
2381   /* Low 16 bits of displacement in global offset table.  */
2382   HOWTO (R_MICROMIPS_CALL_LO16,	/* type */
2383 	 0,			/* rightshift */
2384 	 4,			/* size */
2385 	 16,			/* bitsize */
2386 	 false,			/* pc_relative */
2387 	 0,			/* bitpos */
2388 	 complain_overflow_dont, /* complain_on_overflow */
2389 	 _bfd_mips_elf_generic_reloc, /* special_function */
2390 	 "R_MICROMIPS_CALL_LO16",/* name */
2391 	 true,			/* partial_inplace */
2392 	 0x0000ffff,		/* src_mask */
2393 	 0x0000ffff,		/* dst_mask */
2394 	 false),		/* pcrel_offset */
2395 
2396   /* Section displacement.  */
2397   HOWTO (R_MICROMIPS_SCN_DISP,  /* type */
2398 	 0,			/* rightshift */
2399 	 4,			/* size */
2400 	 32,			/* bitsize */
2401 	 false,			/* pc_relative */
2402 	 0,			/* bitpos */
2403 	 complain_overflow_dont, /* complain_on_overflow */
2404 	 _bfd_mips_elf_generic_reloc, /* special_function */
2405 	 "R_MICROMIPS_SCN_DISP", /* name */
2406 	 true,			/* partial_inplace */
2407 	 0xffffffff,		/* src_mask */
2408 	 0xffffffff,		/* dst_mask */
2409 	 false),		/* pcrel_offset */
2410 
2411   /* Protected jump conversion.  This is an optimization hint.  No
2412      relocation is required for correctness.  */
2413   HOWTO (R_MICROMIPS_JALR,	/* type */
2414 	 0,			/* rightshift */
2415 	 4,			/* size */
2416 	 32,			/* bitsize */
2417 	 false,			/* pc_relative */
2418 	 0,			/* bitpos */
2419 	 complain_overflow_dont, /* complain_on_overflow */
2420 	 _bfd_mips_elf_generic_reloc, /* special_function */
2421 	 "R_MICROMIPS_JALR",	/* name */
2422 	 false,			/* partial_inplace */
2423 	 0,			/* src_mask */
2424 	 0x00000000,		/* dst_mask */
2425 	 false),		/* pcrel_offset */
2426 
2427   /* Low 16 bits of symbol value.  Note that the high 16 bits of symbol values
2428      must be zero.  This is used for relaxation.  */
2429   HOWTO (R_MICROMIPS_HI0_LO16,	/* type */
2430 	 0,			/* rightshift */
2431 	 4,			/* size */
2432 	 16,			/* bitsize */
2433 	 false,			/* pc_relative */
2434 	 0,			/* bitpos */
2435 	 complain_overflow_dont, /* complain_on_overflow */
2436 	 _bfd_mips_elf_generic_reloc, /* special_function */
2437 	 "R_MICROMIPS_HI0_LO16",/* name */
2438 	 true,			/* partial_inplace */
2439 	 0x0000ffff,		/* src_mask */
2440 	 0x0000ffff,		/* dst_mask */
2441 	 false),		/* pcrel_offset */
2442 
2443   EMPTY_HOWTO (158),
2444   EMPTY_HOWTO (159),
2445   EMPTY_HOWTO (160),
2446   EMPTY_HOWTO (161),
2447 
2448   /* TLS general dynamic variable reference.  */
2449   HOWTO (R_MICROMIPS_TLS_GD,		/* type */
2450 	 0,			/* rightshift */
2451 	 4,			/* size */
2452 	 16,			/* bitsize */
2453 	 false,			/* pc_relative */
2454 	 0,			/* bitpos */
2455 	 complain_overflow_signed, /* complain_on_overflow */
2456 	 _bfd_mips_elf_generic_reloc, /* special_function */
2457 	 "R_MICROMIPS_TLS_GD",	/* name */
2458 	 true,			/* partial_inplace */
2459 	 0x0000ffff,		/* src_mask */
2460 	 0x0000ffff,		/* dst_mask */
2461 	 false),		/* pcrel_offset */
2462 
2463   /* TLS local dynamic variable reference.  */
2464   HOWTO (R_MICROMIPS_TLS_LDM,	/* type */
2465 	 0,			/* rightshift */
2466 	 4,			/* size */
2467 	 16,			/* bitsize */
2468 	 false,			/* pc_relative */
2469 	 0,			/* bitpos */
2470 	 complain_overflow_signed, /* complain_on_overflow */
2471 	 _bfd_mips_elf_generic_reloc, /* special_function */
2472 	 "R_MICROMIPS_TLS_LDM",	/* name */
2473 	 true,			/* partial_inplace */
2474 	 0x0000ffff,		/* src_mask */
2475 	 0x0000ffff,		/* dst_mask */
2476 	 false),		/* pcrel_offset */
2477 
2478   /* TLS local dynamic offset.  */
2479   HOWTO (R_MICROMIPS_TLS_DTPREL_HI16,	/* type */
2480 	 0,			/* rightshift */
2481 	 4,			/* size */
2482 	 16,			/* bitsize */
2483 	 false,			/* pc_relative */
2484 	 0,			/* bitpos */
2485 	 complain_overflow_signed, /* complain_on_overflow */
2486 	 _bfd_mips_elf_generic_reloc, /* special_function */
2487 	 "R_MICROMIPS_TLS_DTPREL_HI16",	/* name */
2488 	 true,			/* partial_inplace */
2489 	 0x0000ffff,		/* src_mask */
2490 	 0x0000ffff,		/* dst_mask */
2491 	 false),		/* pcrel_offset */
2492 
2493   /* TLS local dynamic offset.  */
2494   HOWTO (R_MICROMIPS_TLS_DTPREL_LO16,	/* type */
2495 	 0,			/* rightshift */
2496 	 4,			/* size */
2497 	 16,			/* bitsize */
2498 	 false,			/* pc_relative */
2499 	 0,			/* bitpos */
2500 	 complain_overflow_signed, /* complain_on_overflow */
2501 	 _bfd_mips_elf_generic_reloc, /* special_function */
2502 	 "R_MICROMIPS_TLS_DTPREL_LO16",	/* name */
2503 	 true,			/* partial_inplace */
2504 	 0x0000ffff,		/* src_mask */
2505 	 0x0000ffff,		/* dst_mask */
2506 	 false),		/* pcrel_offset */
2507 
2508   /* TLS thread pointer offset.  */
2509   HOWTO (R_MICROMIPS_TLS_GOTTPREL,	/* type */
2510 	 0,			/* rightshift */
2511 	 4,			/* size */
2512 	 16,			/* bitsize */
2513 	 false,			/* pc_relative */
2514 	 0,			/* bitpos */
2515 	 complain_overflow_signed, /* complain_on_overflow */
2516 	 _bfd_mips_elf_generic_reloc, /* special_function */
2517 	 "R_MICROMIPS_TLS_GOTTPREL",	/* name */
2518 	 true,			/* partial_inplace */
2519 	 0x0000ffff,		/* src_mask */
2520 	 0x0000ffff,		/* dst_mask */
2521 	 false),		/* pcrel_offset */
2522 
2523   EMPTY_HOWTO (167),
2524   EMPTY_HOWTO (168),
2525 
2526   /* TLS thread pointer offset.  */
2527   HOWTO (R_MICROMIPS_TLS_TPREL_HI16,	/* type */
2528 	 0,			/* rightshift */
2529 	 4,			/* size */
2530 	 16,			/* bitsize */
2531 	 false,			/* pc_relative */
2532 	 0,			/* bitpos */
2533 	 complain_overflow_signed, /* complain_on_overflow */
2534 	 _bfd_mips_elf_generic_reloc, /* special_function */
2535 	 "R_MICROMIPS_TLS_TPREL_HI16", /* name */
2536 	 true,			/* partial_inplace */
2537 	 0x0000ffff,		/* src_mask */
2538 	 0x0000ffff,		/* dst_mask */
2539 	 false),		/* pcrel_offset */
2540 
2541   /* TLS thread pointer offset.  */
2542   HOWTO (R_MICROMIPS_TLS_TPREL_LO16,	/* type */
2543 	 0,			/* rightshift */
2544 	 4,			/* size */
2545 	 16,			/* bitsize */
2546 	 false,			/* pc_relative */
2547 	 0,			/* bitpos */
2548 	 complain_overflow_signed, /* complain_on_overflow */
2549 	 _bfd_mips_elf_generic_reloc, /* special_function */
2550 	 "R_MICROMIPS_TLS_TPREL_LO16", /* name */
2551 	 true,			/* partial_inplace */
2552 	 0x0000ffff,		/* src_mask */
2553 	 0x0000ffff,		/* dst_mask */
2554 	 false),		/* pcrel_offset */
2555 
2556   EMPTY_HOWTO (171),
2557 
2558   /* GP- and PC-relative relocations.  */
2559   HOWTO (R_MICROMIPS_GPREL7_S2,	/* type */
2560 	 2,			/* rightshift */
2561 	 2,			/* size */
2562 	 7,			/* bitsize */
2563 	 false,			/* pc_relative */
2564 	 0,			/* bitpos */
2565 	 complain_overflow_signed, /* complain_on_overflow */
2566 	 _bfd_mips_elf32_gprel16_reloc, /* special_function */
2567 	 "R_MICROMIPS_GPREL7_S2",	/* name */
2568 	 true,			/* partial_inplace */
2569 	 0x0000007f,		/* src_mask */
2570 	 0x0000007f,		/* dst_mask */
2571 	 false),		/* pcrel_offset */
2572 
2573   HOWTO (R_MICROMIPS_PC23_S2,	/* type */
2574 	 2,			/* rightshift */
2575 	 4,			/* size */
2576 	 23,			/* bitsize */
2577 	 true,			/* pc_relative */
2578 	 0,			/* bitpos */
2579 	 complain_overflow_signed, /* complain_on_overflow */
2580 	 _bfd_mips_elf_generic_reloc, /* special_function */
2581 	 "R_MICROMIPS_PC23_S2",	/* name */
2582 	 true,			/* partial_inplace */
2583 	 0x007fffff,		/* src_mask */
2584 	 0x007fffff,		/* dst_mask */
2585 	 true),			/* pcrel_offset */
2586 };
2587 
2588 static reloc_howto_type micromips_elf64_howto_table_rela[] =
2589 {
2590   EMPTY_HOWTO (130),
2591   EMPTY_HOWTO (131),
2592   EMPTY_HOWTO (132),
2593 
2594   /* 26 bit jump address.  */
2595   HOWTO (R_MICROMIPS_26_S1,	/* type */
2596 	 1,			/* rightshift */
2597 	 4,			/* size */
2598 	 26,			/* bitsize */
2599 	 false,			/* pc_relative */
2600 	 0,			/* bitpos */
2601 	 complain_overflow_dont, /* complain_on_overflow */
2602 				/* This needs complex overflow
2603 				   detection, because the upper four
2604 				   bits must match the PC.  */
2605 	 _bfd_mips_elf_generic_reloc, /* special_function */
2606 	 "R_MICROMIPS_26_S1",	/* name */
2607 	 false,			/* partial_inplace */
2608 	 0,			/* src_mask */
2609 	 0x3ffffff,		/* dst_mask */
2610 	 false),		/* pcrel_offset */
2611 
2612   /* High 16 bits of symbol value.  */
2613   HOWTO (R_MICROMIPS_HI16,	/* type */
2614 	 16,			/* rightshift */
2615 	 4,			/* size */
2616 	 16,			/* bitsize */
2617 	 false,			/* pc_relative */
2618 	 0,			/* bitpos */
2619 	 complain_overflow_dont, /* complain_on_overflow */
2620 	 _bfd_mips_elf_hi16_reloc, /* special_function */
2621 	 "R_MICROMIPS_HI16",	/* name */
2622 	 false,			/* partial_inplace */
2623 	 0,			/* src_mask */
2624 	 0x0000ffff,		/* dst_mask */
2625 	 false),		/* pcrel_offset */
2626 
2627   /* Low 16 bits of symbol value.  */
2628   HOWTO (R_MICROMIPS_LO16,	/* type */
2629 	 0,			/* rightshift */
2630 	 4,			/* size */
2631 	 16,			/* bitsize */
2632 	 false,			/* pc_relative */
2633 	 0,			/* bitpos */
2634 	 complain_overflow_dont, /* complain_on_overflow */
2635 	 _bfd_mips_elf_lo16_reloc, /* special_function */
2636 	 "R_MICROMIPS_LO16",	/* name */
2637 	 false,			/* partial_inplace */
2638 	 0,			/* src_mask */
2639 	 0x0000ffff,		/* dst_mask */
2640 	 false),		/* pcrel_offset */
2641 
2642   /* GP relative reference.  */
2643   HOWTO (R_MICROMIPS_GPREL16,	/* type */
2644 	 0,			/* rightshift */
2645 	 4,			/* size */
2646 	 16,			/* bitsize */
2647 	 false,			/* pc_relative */
2648 	 0,			/* bitpos */
2649 	 complain_overflow_signed, /* complain_on_overflow */
2650 	 _bfd_mips_elf32_gprel16_reloc, /* special_function */
2651 	 "R_MICROMIPS_GPREL16",	/* name */
2652 	 false,			/* partial_inplace */
2653 	 0,			/* src_mask */
2654 	 0x0000ffff,		/* dst_mask */
2655 	 false),		/* pcrel_offset */
2656 
2657   /* Reference to literal section.  */
2658   HOWTO (R_MICROMIPS_LITERAL,	/* type */
2659 	 0,			/* rightshift */
2660 	 4,			/* size */
2661 	 16,			/* bitsize */
2662 	 false,			/* pc_relative */
2663 	 0,			/* bitpos */
2664 	 complain_overflow_signed, /* complain_on_overflow */
2665 	 _bfd_mips_elf32_gprel16_reloc, /* special_function */
2666 	 "R_MICROMIPS_LITERAL",	/* name */
2667 	 false,			/* partial_inplace */
2668 	 0,			/* src_mask */
2669 	 0x0000ffff,		/* dst_mask */
2670 	 false),		/* pcrel_offset */
2671 
2672   /* Reference to global offset table.  */
2673   HOWTO (R_MICROMIPS_GOT16,	/* type */
2674 	 0,			/* rightshift */
2675 	 4,			/* size */
2676 	 16,			/* bitsize */
2677 	 false,			/* pc_relative */
2678 	 0,			/* bitpos */
2679 	 complain_overflow_signed, /* complain_on_overflow */
2680 	 _bfd_mips_elf_got16_reloc, /* special_function */
2681 	 "R_MICROMIPS_GOT16",	/* name */
2682 	 false,			/* partial_inplace */
2683 	 0,			/* src_mask */
2684 	 0x0000ffff,		/* dst_mask */
2685 	 false),		/* pcrel_offset */
2686 
2687   /* This is for microMIPS branches.  */
2688   HOWTO (R_MICROMIPS_PC7_S1,	/* type */
2689 	 1,			/* rightshift */
2690 	 2,			/* size */
2691 	 7,			/* bitsize */
2692 	 true,			/* pc_relative */
2693 	 0,			/* bitpos */
2694 	 complain_overflow_signed, /* complain_on_overflow */
2695 	 _bfd_mips_elf_generic_reloc, /* special_function */
2696 	 "R_MICROMIPS_PC7_S1",	/* name */
2697 	 false,			/* partial_inplace */
2698 	 0,			/* src_mask */
2699 	 0x0000007f,		/* dst_mask */
2700 	 true),			/* pcrel_offset */
2701 
2702   HOWTO (R_MICROMIPS_PC10_S1,	/* type */
2703 	 1,			/* rightshift */
2704 	 2,			/* size */
2705 	 10,			/* bitsize */
2706 	 true,			/* pc_relative */
2707 	 0,			/* bitpos */
2708 	 complain_overflow_signed, /* complain_on_overflow */
2709 	 _bfd_mips_elf_generic_reloc, /* special_function */
2710 	 "R_MICROMIPS_PC10_S1",	/* name */
2711 	 false,			/* partial_inplace */
2712 	 0,			/* src_mask */
2713 	 0x000003ff,		/* dst_mask */
2714 	 true),			/* pcrel_offset */
2715 
2716   HOWTO (R_MICROMIPS_PC16_S1,	/* type */
2717 	 1,			/* rightshift */
2718 	 4,			/* size */
2719 	 16,			/* bitsize */
2720 	 true,			/* pc_relative */
2721 	 0,			/* bitpos */
2722 	 complain_overflow_signed, /* complain_on_overflow */
2723 	 _bfd_mips_elf_generic_reloc, /* special_function */
2724 	 "R_MICROMIPS_PC16_S1",	/* name */
2725 	 false,			/* partial_inplace */
2726 	 0,			/* src_mask */
2727 	 0x0000ffff,		/* dst_mask */
2728 	 true),			/* pcrel_offset */
2729 
2730   /* 16 bit call through global offset table.  */
2731   HOWTO (R_MICROMIPS_CALL16,	/* type */
2732 	 0,			/* rightshift */
2733 	 4,			/* size */
2734 	 16,			/* bitsize */
2735 	 false,			/* pc_relative */
2736 	 0,			/* bitpos */
2737 	 complain_overflow_signed, /* complain_on_overflow */
2738 	 _bfd_mips_elf_generic_reloc, /* special_function */
2739 	 "R_MICROMIPS_CALL16",	/* name */
2740 	 false,			/* partial_inplace */
2741 	 0,			/* src_mask */
2742 	 0x0000ffff,		/* dst_mask */
2743 	 false),		/* pcrel_offset */
2744 
2745   EMPTY_HOWTO (143),
2746   EMPTY_HOWTO (144),
2747 
2748   /* Displacement in the global offset table.  */
2749   HOWTO (R_MICROMIPS_GOT_DISP,	/* type */
2750 	 0,			/* rightshift */
2751 	 4,			/* size */
2752 	 16,			/* bitsize */
2753 	 false,			/* pc_relative */
2754 	 0,			/* bitpos */
2755 	 complain_overflow_signed, /* complain_on_overflow */
2756 	 _bfd_mips_elf_generic_reloc, /* special_function */
2757 	 "R_MICROMIPS_GOT_DISP",/* name */
2758 	 false,			/* partial_inplace */
2759 	 0,			/* src_mask */
2760 	 0x0000ffff,		/* dst_mask */
2761 	 false),		/* pcrel_offset */
2762 
2763   /* Displacement to page pointer in the global offset table.  */
2764   HOWTO (R_MICROMIPS_GOT_PAGE,	/* type */
2765 	 0,			/* rightshift */
2766 	 4,			/* size */
2767 	 16,			/* bitsize */
2768 	 false,			/* pc_relative */
2769 	 0,			/* bitpos */
2770 	 complain_overflow_signed, /* complain_on_overflow */
2771 	 _bfd_mips_elf_generic_reloc, /* special_function */
2772 	 "R_MICROMIPS_GOT_PAGE",/* name */
2773 	 false,			/* partial_inplace */
2774 	 0,			/* src_mask */
2775 	 0x0000ffff,		/* dst_mask */
2776 	 false),		/* pcrel_offset */
2777 
2778   /* Offset from page pointer in the global offset table.  */
2779   HOWTO (R_MICROMIPS_GOT_OFST,	/* type */
2780 	 0,			/* rightshift */
2781 	 4,			/* size */
2782 	 16,			/* bitsize */
2783 	 false,			/* pc_relative */
2784 	 0,			/* bitpos */
2785 	 complain_overflow_signed, /* complain_on_overflow */
2786 	 _bfd_mips_elf_generic_reloc, /* special_function */
2787 	 "R_MICROMIPS_GOT_OFST",/* name */
2788 	 false,			/* partial_inplace */
2789 	 0,			/* src_mask */
2790 	 0x0000ffff,		/* dst_mask */
2791 	 false),		/* pcrel_offset */
2792 
2793   /* High 16 bits of displacement in global offset table.  */
2794   HOWTO (R_MICROMIPS_GOT_HI16,	/* type */
2795 	 0,			/* rightshift */
2796 	 4,			/* size */
2797 	 16,			/* bitsize */
2798 	 false,			/* pc_relative */
2799 	 0,			/* bitpos */
2800 	 complain_overflow_dont, /* complain_on_overflow */
2801 	 _bfd_mips_elf_generic_reloc, /* special_function */
2802 	 "R_MICROMIPS_GOT_HI16",/* name */
2803 	 false,			/* partial_inplace */
2804 	 0,			/* src_mask */
2805 	 0x0000ffff,		/* dst_mask */
2806 	 false),		/* pcrel_offset */
2807 
2808   /* Low 16 bits of displacement in global offset table.  */
2809   HOWTO (R_MICROMIPS_GOT_LO16,	/* type */
2810 	 0,			/* rightshift */
2811 	 4,			/* size */
2812 	 16,			/* bitsize */
2813 	 false,			/* pc_relative */
2814 	 0,			/* bitpos */
2815 	 complain_overflow_dont, /* complain_on_overflow */
2816 	 _bfd_mips_elf_generic_reloc, /* special_function */
2817 	 "R_MICROMIPS_GOT_LO16",/* name */
2818 	 false,			/* partial_inplace */
2819 	 0,			/* src_mask */
2820 	 0x0000ffff,		/* dst_mask */
2821 	 false),		/* pcrel_offset */
2822 
2823   /* 64 bit subtraction.  Used in the N32 ABI.  */
2824   HOWTO (R_MICROMIPS_SUB,	/* type */
2825 	 0,			/* rightshift */
2826 	 8,			/* size */
2827 	 64,			/* bitsize */
2828 	 false,			/* pc_relative */
2829 	 0,			/* bitpos */
2830 	 complain_overflow_dont, /* complain_on_overflow */
2831 	 _bfd_mips_elf_generic_reloc, /* special_function */
2832 	 "R_MICROMIPS_SUB",	/* name */
2833 	 false,			/* partial_inplace */
2834 	 0,			/* src_mask */
2835 	 MINUS_ONE,		/* dst_mask */
2836 	 false),		/* pcrel_offset */
2837 
2838   /* Get the higher value of a 64 bit addend.  */
2839   HOWTO (R_MICROMIPS_HIGHER,	/* type */
2840 	 0,			/* rightshift */
2841 	 4,			/* size */
2842 	 16,			/* bitsize */
2843 	 false,			/* pc_relative */
2844 	 0,			/* bitpos */
2845 	 complain_overflow_dont, /* complain_on_overflow */
2846 	 _bfd_mips_elf_generic_reloc, /* special_function */
2847 	 "R_MICROMIPS_HIGHER",	/* name */
2848 	 false,			/* partial_inplace */
2849 	 0,			/* src_mask */
2850 	 0x0000ffff,		/* dst_mask */
2851 	 false),		/* pcrel_offset */
2852 
2853   /* Get the highest value of a 64 bit addend.  */
2854   HOWTO (R_MICROMIPS_HIGHEST,	/* type */
2855 	 0,			/* rightshift */
2856 	 4,			/* size */
2857 	 16,			/* bitsize */
2858 	 false,			/* pc_relative */
2859 	 0,			/* bitpos */
2860 	 complain_overflow_dont, /* complain_on_overflow */
2861 	 _bfd_mips_elf_generic_reloc, /* special_function */
2862 	 "R_MICROMIPS_HIGHEST",	/* name */
2863 	 false,			/* partial_inplace */
2864 	 0,			/* src_mask */
2865 	 0x0000ffff,		/* dst_mask */
2866 	 false),		/* pcrel_offset */
2867 
2868   /* High 16 bits of displacement in global offset table.  */
2869   HOWTO (R_MICROMIPS_CALL_HI16,	/* type */
2870 	 0,			/* rightshift */
2871 	 4,			/* size */
2872 	 16,			/* bitsize */
2873 	 false,			/* pc_relative */
2874 	 0,			/* bitpos */
2875 	 complain_overflow_dont, /* complain_on_overflow */
2876 	 _bfd_mips_elf_generic_reloc, /* special_function */
2877 	 "R_MICROMIPS_CALL_HI16",/* name */
2878 	 false,			/* partial_inplace */
2879 	 0,			/* src_mask */
2880 	 0x0000ffff,		/* dst_mask */
2881 	 false),		/* pcrel_offset */
2882 
2883   /* Low 16 bits of displacement in global offset table.  */
2884   HOWTO (R_MICROMIPS_CALL_LO16,	/* type */
2885 	 0,			/* rightshift */
2886 	 4,			/* size */
2887 	 16,			/* bitsize */
2888 	 false,			/* pc_relative */
2889 	 0,			/* bitpos */
2890 	 complain_overflow_dont, /* complain_on_overflow */
2891 	 _bfd_mips_elf_generic_reloc, /* special_function */
2892 	 "R_MICROMIPS_CALL_LO16",/* name */
2893 	 false,			/* partial_inplace */
2894 	 0,			/* src_mask */
2895 	 0x0000ffff,		/* dst_mask */
2896 	 false),		/* pcrel_offset */
2897 
2898   /* Section displacement.  */
2899   HOWTO (R_MICROMIPS_SCN_DISP,  /* type */
2900 	 0,			/* rightshift */
2901 	 4,			/* size */
2902 	 32,			/* bitsize */
2903 	 false,			/* pc_relative */
2904 	 0,			/* bitpos */
2905 	 complain_overflow_dont, /* complain_on_overflow */
2906 	 _bfd_mips_elf_generic_reloc, /* special_function */
2907 	 "R_MICROMIPS_SCN_DISP", /* name */
2908 	 false,			/* partial_inplace */
2909 	 0,			/* src_mask */
2910 	 0xffffffff,		/* dst_mask */
2911 	 false),		/* pcrel_offset */
2912 
2913   /* Protected jump conversion.  This is an optimization hint.  No
2914      relocation is required for correctness.  */
2915   HOWTO (R_MICROMIPS_JALR,	/* type */
2916 	 0,			/* rightshift */
2917 	 4,			/* size */
2918 	 32,			/* bitsize */
2919 	 false,			/* pc_relative */
2920 	 0,			/* bitpos */
2921 	 complain_overflow_dont, /* complain_on_overflow */
2922 	 _bfd_mips_elf_generic_reloc, /* special_function */
2923 	 "R_MICROMIPS_JALR",	/* name */
2924 	 false,			/* partial_inplace */
2925 	 0,			/* src_mask */
2926 	 0x00000000,		/* dst_mask */
2927 	 false),		/* pcrel_offset */
2928 
2929   /* Low 16 bits of symbol value.  Note that the high 16 bits of symbol values
2930      must be zero.  This is used for relaxation.  */
2931   HOWTO (R_MICROMIPS_HI0_LO16,	/* type */
2932 	 0,			/* rightshift */
2933 	 4,			/* size */
2934 	 16,			/* bitsize */
2935 	 false,			/* pc_relative */
2936 	 0,			/* bitpos */
2937 	 complain_overflow_dont, /* complain_on_overflow */
2938 	 _bfd_mips_elf_generic_reloc, /* special_function */
2939 	 "R_MICROMIPS_HI0_LO16",/* name */
2940 	 false,			/* partial_inplace */
2941 	 0,			/* src_mask */
2942 	 0x0000ffff,		/* dst_mask */
2943 	 false),		/* pcrel_offset */
2944 
2945   EMPTY_HOWTO (158),
2946   EMPTY_HOWTO (159),
2947   EMPTY_HOWTO (160),
2948   EMPTY_HOWTO (161),
2949 
2950   /* TLS general dynamic variable reference.  */
2951   HOWTO (R_MICROMIPS_TLS_GD,		/* type */
2952 	 0,			/* rightshift */
2953 	 4,			/* size */
2954 	 16,			/* bitsize */
2955 	 false,			/* pc_relative */
2956 	 0,			/* bitpos */
2957 	 complain_overflow_signed, /* complain_on_overflow */
2958 	 _bfd_mips_elf_generic_reloc, /* special_function */
2959 	 "R_MICROMIPS_TLS_GD",	/* name */
2960 	 false,			/* partial_inplace */
2961 	 0,			/* src_mask */
2962 	 0x0000ffff,		/* dst_mask */
2963 	 false),		/* pcrel_offset */
2964 
2965   /* TLS local dynamic variable reference.  */
2966   HOWTO (R_MICROMIPS_TLS_LDM,	/* type */
2967 	 0,			/* rightshift */
2968 	 4,			/* size */
2969 	 16,			/* bitsize */
2970 	 false,			/* pc_relative */
2971 	 0,			/* bitpos */
2972 	 complain_overflow_signed, /* complain_on_overflow */
2973 	 _bfd_mips_elf_generic_reloc, /* special_function */
2974 	 "R_MICROMIPS_TLS_LDM",	/* name */
2975 	 false,			/* partial_inplace */
2976 	 0,			/* src_mask */
2977 	 0x0000ffff,		/* dst_mask */
2978 	 false),		/* pcrel_offset */
2979 
2980   /* TLS local dynamic offset.  */
2981   HOWTO (R_MICROMIPS_TLS_DTPREL_HI16,	/* type */
2982 	 0,			/* rightshift */
2983 	 4,			/* size */
2984 	 16,			/* bitsize */
2985 	 false,			/* pc_relative */
2986 	 0,			/* bitpos */
2987 	 complain_overflow_signed, /* complain_on_overflow */
2988 	 _bfd_mips_elf_generic_reloc, /* special_function */
2989 	 "R_MICROMIPS_TLS_DTPREL_HI16",	/* name */
2990 	 false,			/* partial_inplace */
2991 	 0,			/* src_mask */
2992 	 0x0000ffff,		/* dst_mask */
2993 	 false),		/* pcrel_offset */
2994 
2995   /* TLS local dynamic offset.  */
2996   HOWTO (R_MICROMIPS_TLS_DTPREL_LO16,	/* type */
2997 	 0,			/* rightshift */
2998 	 4,			/* size */
2999 	 16,			/* bitsize */
3000 	 false,			/* pc_relative */
3001 	 0,			/* bitpos */
3002 	 complain_overflow_signed, /* complain_on_overflow */
3003 	 _bfd_mips_elf_generic_reloc, /* special_function */
3004 	 "R_MICROMIPS_TLS_DTPREL_LO16",	/* name */
3005 	 false,			/* partial_inplace */
3006 	 0,			/* src_mask */
3007 	 0x0000ffff,		/* dst_mask */
3008 	 false),		/* pcrel_offset */
3009 
3010   /* TLS thread pointer offset.  */
3011   HOWTO (R_MICROMIPS_TLS_GOTTPREL,	/* type */
3012 	 0,			/* rightshift */
3013 	 4,			/* size */
3014 	 16,			/* bitsize */
3015 	 false,			/* pc_relative */
3016 	 0,			/* bitpos */
3017 	 complain_overflow_signed, /* complain_on_overflow */
3018 	 _bfd_mips_elf_generic_reloc, /* special_function */
3019 	 "R_MICROMIPS_TLS_GOTTPREL",	/* name */
3020 	 false,			/* partial_inplace */
3021 	 0,			/* src_mask */
3022 	 0x0000ffff,		/* dst_mask */
3023 	 false),		/* pcrel_offset */
3024 
3025   EMPTY_HOWTO (167),
3026   EMPTY_HOWTO (168),
3027 
3028   /* TLS thread pointer offset.  */
3029   HOWTO (R_MICROMIPS_TLS_TPREL_HI16,	/* type */
3030 	 0,			/* rightshift */
3031 	 4,			/* size */
3032 	 16,			/* bitsize */
3033 	 false,			/* pc_relative */
3034 	 0,			/* bitpos */
3035 	 complain_overflow_signed, /* complain_on_overflow */
3036 	 _bfd_mips_elf_generic_reloc, /* special_function */
3037 	 "R_MICROMIPS_TLS_TPREL_HI16", /* name */
3038 	 false,			/* partial_inplace */
3039 	 0,			/* src_mask */
3040 	 0x0000ffff,		/* dst_mask */
3041 	 false),		/* pcrel_offset */
3042 
3043   /* TLS thread pointer offset.  */
3044   HOWTO (R_MICROMIPS_TLS_TPREL_LO16,	/* type */
3045 	 0,			/* rightshift */
3046 	 4,			/* size */
3047 	 16,			/* bitsize */
3048 	 false,			/* pc_relative */
3049 	 0,			/* bitpos */
3050 	 complain_overflow_signed, /* complain_on_overflow */
3051 	 _bfd_mips_elf_generic_reloc, /* special_function */
3052 	 "R_MICROMIPS_TLS_TPREL_LO16", /* name */
3053 	 false,			/* partial_inplace */
3054 	 0,			/* src_mask */
3055 	 0x0000ffff,		/* dst_mask */
3056 	 false),		/* pcrel_offset */
3057 
3058   EMPTY_HOWTO (171),
3059 
3060   /* GP- and PC-relative relocations.  */
3061   HOWTO (R_MICROMIPS_GPREL7_S2,	/* type */
3062 	 2,			/* rightshift */
3063 	 2,			/* size */
3064 	 7,			/* bitsize */
3065 	 false,			/* pc_relative */
3066 	 0,			/* bitpos */
3067 	 complain_overflow_signed, /* complain_on_overflow */
3068 	 _bfd_mips_elf32_gprel16_reloc, /* special_function */
3069 	 "R_MICROMIPS_GPREL7_S2",	/* name */
3070 	 false,			/* partial_inplace */
3071 	 0,			/* src_mask */
3072 	 0x0000007f,		/* dst_mask */
3073 	 false),		/* pcrel_offset */
3074 
3075   HOWTO (R_MICROMIPS_PC23_S2,	/* type */
3076 	 2,			/* rightshift */
3077 	 4,			/* size */
3078 	 23,			/* bitsize */
3079 	 true,			/* pc_relative */
3080 	 0,			/* bitpos */
3081 	 complain_overflow_signed, /* complain_on_overflow */
3082 	 _bfd_mips_elf_generic_reloc, /* special_function */
3083 	 "R_MICROMIPS_PC23_S2",	/* name */
3084 	 false,			/* partial_inplace */
3085 	 0,			/* src_mask */
3086 	 0x007fffff,		/* dst_mask */
3087 	 true),			/* pcrel_offset */
3088 };
3089 
3090 /* GNU extension to record C++ vtable hierarchy */
3091 static reloc_howto_type elf_mips_gnu_vtinherit_howto =
3092   HOWTO (R_MIPS_GNU_VTINHERIT,	/* type */
3093 	 0,			/* rightshift */
3094 	 4,			/* size */
3095 	 0,			/* bitsize */
3096 	 false,			/* pc_relative */
3097 	 0,			/* bitpos */
3098 	 complain_overflow_dont, /* complain_on_overflow */
3099 	 NULL,			/* special_function */
3100 	 "R_MIPS_GNU_VTINHERIT", /* name */
3101 	 false,			/* partial_inplace */
3102 	 0,			/* src_mask */
3103 	 0,			/* dst_mask */
3104 	 false);		/* pcrel_offset */
3105 
3106 /* GNU extension to record C++ vtable member usage */
3107 static reloc_howto_type elf_mips_gnu_vtentry_howto =
3108   HOWTO (R_MIPS_GNU_VTENTRY,	/* type */
3109 	 0,			/* rightshift */
3110 	 4,			/* size */
3111 	 0,			/* bitsize */
3112 	 false,			/* pc_relative */
3113 	 0,			/* bitpos */
3114 	 complain_overflow_dont, /* complain_on_overflow */
3115 	 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
3116 	 "R_MIPS_GNU_VTENTRY",	/* name */
3117 	 false,			/* partial_inplace */
3118 	 0,			/* src_mask */
3119 	 0,			/* dst_mask */
3120 	 false);		/* pcrel_offset */
3121 
3122 /* 16 bit offset for pc-relative branches.  */
3123 static reloc_howto_type elf_mips_gnu_rel16_s2 =
3124   HOWTO (R_MIPS_GNU_REL16_S2,	/* type */
3125 	 2,			/* rightshift */
3126 	 4,			/* size */
3127 	 16,			/* bitsize */
3128 	 true,			/* pc_relative */
3129 	 0,			/* bitpos */
3130 	 complain_overflow_signed, /* complain_on_overflow */
3131 	 _bfd_mips_elf_generic_reloc,	/* special_function */
3132 	 "R_MIPS_GNU_REL16_S2",	/* name */
3133 	 true,			/* partial_inplace */
3134 	 0x0000ffff,		/* src_mask */
3135 	 0x0000ffff,		/* dst_mask */
3136 	 true);			/* pcrel_offset */
3137 
3138 /* 16 bit offset for pc-relative branches.  */
3139 static reloc_howto_type elf_mips_gnu_rela16_s2 =
3140   HOWTO (R_MIPS_GNU_REL16_S2,	/* type */
3141 	 2,			/* rightshift */
3142 	 4,			/* size */
3143 	 16,			/* bitsize */
3144 	 true,			/* pc_relative */
3145 	 0,			/* bitpos */
3146 	 complain_overflow_signed, /* complain_on_overflow */
3147 	 _bfd_mips_elf_generic_reloc,	/* special_function */
3148 	 "R_MIPS_GNU_REL16_S2",	/* name */
3149 	 false,			/* partial_inplace */
3150 	 0,			/* src_mask */
3151 	 0x0000ffff,		/* dst_mask */
3152 	 true);			/* pcrel_offset */
3153 
3154 /* 32 bit pc-relative.  Used for compact EH tables.  */
3155 static reloc_howto_type elf_mips_gnu_pcrel32 =
3156   HOWTO (R_MIPS_PC32,		/* type */
3157 	 0,			/* rightshift */
3158 	 4,			/* size */
3159 	 32,			/* bitsize */
3160 	 true,			/* pc_relative */
3161 	 0,			/* bitpos */
3162 	 complain_overflow_signed, /* complain_on_overflow */
3163 	 _bfd_mips_elf_generic_reloc, /* special_function */
3164 	 "R_MIPS_PC32",		/* name */
3165 	 true,			/* partial_inplace */
3166 	 0xffffffff,		/* src_mask */
3167 	 0xffffffff,		/* dst_mask */
3168 	 true);			/* pcrel_offset */
3169 
3170 
3171 /* Originally a VxWorks extension, but now used for other systems too.  */
3172 static reloc_howto_type elf_mips_copy_howto =
3173   HOWTO (R_MIPS_COPY,		/* type */
3174 	 0,			/* rightshift */
3175 	 0,			/* this one is variable size */
3176 	 0,			/* bitsize */
3177 	 false,			/* pc_relative */
3178 	 0,			/* bitpos */
3179 	 complain_overflow_bitfield, /* complain_on_overflow */
3180 	 _bfd_mips_elf_generic_reloc, /* special_function */
3181 	 "R_MIPS_COPY",		/* name */
3182 	 false,			/* partial_inplace */
3183 	 0x0,			/* src_mask */
3184 	 0x0,			/* dst_mask */
3185 	 false);		/* pcrel_offset */
3186 
3187 /* Originally a VxWorks extension, but now used for other systems too.  */
3188 static reloc_howto_type elf_mips_jump_slot_howto =
3189   HOWTO (R_MIPS_JUMP_SLOT,	/* type */
3190 	 0,			/* rightshift */
3191 	 8,			/* size */
3192 	 64,			/* bitsize */
3193 	 false,			/* pc_relative */
3194 	 0,			/* bitpos */
3195 	 complain_overflow_bitfield, /* complain_on_overflow */
3196 	 _bfd_mips_elf_generic_reloc, /* special_function */
3197 	 "R_MIPS_JUMP_SLOT",	/* name */
3198 	 false,			/* partial_inplace */
3199 	 0x0,			/* src_mask */
3200 	 0x0,			/* dst_mask */
3201 	 false);		/* pcrel_offset */
3202 
3203 /* Used in EH tables.  */
3204 static reloc_howto_type elf_mips_eh_howto =
3205   HOWTO (R_MIPS_EH,		/* type */
3206 	 0,			/* rightshift */
3207 	 4,			/* size */
3208 	 32,			/* bitsize */
3209 	 false,			/* pc_relative */
3210 	 0,			/* bitpos */
3211 	 complain_overflow_signed, /* complain_on_overflow */
3212 	 _bfd_mips_elf_generic_reloc, /* special_function */
3213 	 "R_MIPS_EH",		/* name */
3214 	 true,			/* partial_inplace */
3215 	 0xffffffff,		/* src_mask */
3216 	 0xffffffff,		/* dst_mask */
3217 	 false);		/* pcrel_offset */
3218 
3219 
3220 /* Swap in a MIPS 64-bit Rel reloc.  */
3221 
3222 static void
mips_elf64_swap_reloc_in(bfd * abfd,const Elf64_Mips_External_Rel * src,Elf64_Mips_Internal_Rela * dst)3223 mips_elf64_swap_reloc_in (bfd *abfd, const Elf64_Mips_External_Rel *src,
3224 			  Elf64_Mips_Internal_Rela *dst)
3225 {
3226   dst->r_offset = H_GET_64 (abfd, src->r_offset);
3227   dst->r_sym = H_GET_32 (abfd, src->r_sym);
3228   dst->r_ssym = H_GET_8 (abfd, src->r_ssym);
3229   dst->r_type3 = H_GET_8 (abfd, src->r_type3);
3230   dst->r_type2 = H_GET_8 (abfd, src->r_type2);
3231   dst->r_type = H_GET_8 (abfd, src->r_type);
3232   dst->r_addend = 0;
3233 }
3234 
3235 /* Swap in a MIPS 64-bit Rela reloc.  */
3236 
3237 static void
mips_elf64_swap_reloca_in(bfd * abfd,const Elf64_Mips_External_Rela * src,Elf64_Mips_Internal_Rela * dst)3238 mips_elf64_swap_reloca_in (bfd *abfd, const Elf64_Mips_External_Rela *src,
3239 			   Elf64_Mips_Internal_Rela *dst)
3240 {
3241   dst->r_offset = H_GET_64 (abfd, src->r_offset);
3242   dst->r_sym = H_GET_32 (abfd, src->r_sym);
3243   dst->r_ssym = H_GET_8 (abfd, src->r_ssym);
3244   dst->r_type3 = H_GET_8 (abfd, src->r_type3);
3245   dst->r_type2 = H_GET_8 (abfd, src->r_type2);
3246   dst->r_type = H_GET_8 (abfd, src->r_type);
3247   dst->r_addend = H_GET_S64 (abfd, src->r_addend);
3248 }
3249 
3250 /* Swap out a MIPS 64-bit Rel reloc.  */
3251 
3252 static void
mips_elf64_swap_reloc_out(bfd * abfd,const Elf64_Mips_Internal_Rela * src,Elf64_Mips_External_Rel * dst)3253 mips_elf64_swap_reloc_out (bfd *abfd, const Elf64_Mips_Internal_Rela *src,
3254 			   Elf64_Mips_External_Rel *dst)
3255 {
3256   H_PUT_64 (abfd, src->r_offset, dst->r_offset);
3257   H_PUT_32 (abfd, src->r_sym, dst->r_sym);
3258   H_PUT_8 (abfd, src->r_ssym, dst->r_ssym);
3259   H_PUT_8 (abfd, src->r_type3, dst->r_type3);
3260   H_PUT_8 (abfd, src->r_type2, dst->r_type2);
3261   H_PUT_8 (abfd, src->r_type, dst->r_type);
3262 }
3263 
3264 /* Swap out a MIPS 64-bit Rela reloc.  */
3265 
3266 static void
mips_elf64_swap_reloca_out(bfd * abfd,const Elf64_Mips_Internal_Rela * src,Elf64_Mips_External_Rela * dst)3267 mips_elf64_swap_reloca_out (bfd *abfd, const Elf64_Mips_Internal_Rela *src,
3268 			    Elf64_Mips_External_Rela *dst)
3269 {
3270   H_PUT_64 (abfd, src->r_offset, dst->r_offset);
3271   H_PUT_32 (abfd, src->r_sym, dst->r_sym);
3272   H_PUT_8 (abfd, src->r_ssym, dst->r_ssym);
3273   H_PUT_8 (abfd, src->r_type3, dst->r_type3);
3274   H_PUT_8 (abfd, src->r_type2, dst->r_type2);
3275   H_PUT_8 (abfd, src->r_type, dst->r_type);
3276   H_PUT_S64 (abfd, src->r_addend, dst->r_addend);
3277 }
3278 
3279 /* Swap in a MIPS 64-bit Rel reloc.  */
3280 
3281 static void
mips_elf64_be_swap_reloc_in(bfd * abfd,const bfd_byte * src,Elf_Internal_Rela * dst)3282 mips_elf64_be_swap_reloc_in (bfd *abfd, const bfd_byte *src,
3283 			     Elf_Internal_Rela *dst)
3284 {
3285   Elf64_Mips_Internal_Rela mirel;
3286 
3287   mips_elf64_swap_reloc_in (abfd,
3288 			    (const Elf64_Mips_External_Rel *) src,
3289 			    &mirel);
3290 
3291   dst[0].r_offset = mirel.r_offset;
3292   dst[0].r_info = ELF64_R_INFO (mirel.r_sym, mirel.r_type);
3293   dst[0].r_addend = 0;
3294   dst[1].r_offset = mirel.r_offset;
3295   dst[1].r_info = ELF64_R_INFO (mirel.r_ssym, mirel.r_type2);
3296   dst[1].r_addend = 0;
3297   dst[2].r_offset = mirel.r_offset;
3298   dst[2].r_info = ELF64_R_INFO (STN_UNDEF, mirel.r_type3);
3299   dst[2].r_addend = 0;
3300 }
3301 
3302 /* Swap in a MIPS 64-bit Rela reloc.  */
3303 
3304 static void
mips_elf64_be_swap_reloca_in(bfd * abfd,const bfd_byte * src,Elf_Internal_Rela * dst)3305 mips_elf64_be_swap_reloca_in (bfd *abfd, const bfd_byte *src,
3306 			      Elf_Internal_Rela *dst)
3307 {
3308   Elf64_Mips_Internal_Rela mirela;
3309 
3310   mips_elf64_swap_reloca_in (abfd,
3311 			     (const Elf64_Mips_External_Rela *) src,
3312 			     &mirela);
3313 
3314   dst[0].r_offset = mirela.r_offset;
3315   dst[0].r_info = ELF64_R_INFO (mirela.r_sym, mirela.r_type);
3316   dst[0].r_addend = mirela.r_addend;
3317   dst[1].r_offset = mirela.r_offset;
3318   dst[1].r_info = ELF64_R_INFO (mirela.r_ssym, mirela.r_type2);
3319   dst[1].r_addend = 0;
3320   dst[2].r_offset = mirela.r_offset;
3321   dst[2].r_info = ELF64_R_INFO (STN_UNDEF, mirela.r_type3);
3322   dst[2].r_addend = 0;
3323 }
3324 
3325 /* Swap out a MIPS 64-bit Rel reloc.  */
3326 
3327 static void
mips_elf64_be_swap_reloc_out(bfd * abfd,const Elf_Internal_Rela * src,bfd_byte * dst)3328 mips_elf64_be_swap_reloc_out (bfd *abfd, const Elf_Internal_Rela *src,
3329 			      bfd_byte *dst)
3330 {
3331   Elf64_Mips_Internal_Rela mirel;
3332 
3333   mirel.r_offset = src[0].r_offset;
3334   BFD_ASSERT(src[0].r_offset == src[1].r_offset);
3335   BFD_ASSERT(src[0].r_offset == src[2].r_offset);
3336 
3337   mirel.r_type = ELF64_MIPS_R_TYPE (src[0].r_info);
3338   mirel.r_sym = ELF64_R_SYM (src[0].r_info);
3339   mirel.r_type2 = ELF64_MIPS_R_TYPE (src[1].r_info);
3340   mirel.r_ssym = ELF64_MIPS_R_SSYM (src[1].r_info);
3341   mirel.r_type3 = ELF64_MIPS_R_TYPE (src[2].r_info);
3342 
3343   mips_elf64_swap_reloc_out (abfd, &mirel,
3344 			     (Elf64_Mips_External_Rel *) dst);
3345 }
3346 
3347 /* Swap out a MIPS 64-bit Rela reloc.  */
3348 
3349 static void
mips_elf64_be_swap_reloca_out(bfd * abfd,const Elf_Internal_Rela * src,bfd_byte * dst)3350 mips_elf64_be_swap_reloca_out (bfd *abfd, const Elf_Internal_Rela *src,
3351 			       bfd_byte *dst)
3352 {
3353   Elf64_Mips_Internal_Rela mirela;
3354 
3355   mirela.r_offset = src[0].r_offset;
3356   BFD_ASSERT(src[0].r_offset == src[1].r_offset);
3357   BFD_ASSERT(src[0].r_offset == src[2].r_offset);
3358 
3359   mirela.r_type = ELF64_MIPS_R_TYPE (src[0].r_info);
3360   mirela.r_sym = ELF64_R_SYM (src[0].r_info);
3361   mirela.r_addend = src[0].r_addend;
3362   BFD_ASSERT(src[1].r_addend == 0);
3363   BFD_ASSERT(src[2].r_addend == 0);
3364 
3365   mirela.r_type2 = ELF64_MIPS_R_TYPE (src[1].r_info);
3366   mirela.r_ssym = ELF64_MIPS_R_SSYM (src[1].r_info);
3367   mirela.r_type3 = ELF64_MIPS_R_TYPE (src[2].r_info);
3368 
3369   mips_elf64_swap_reloca_out (abfd, &mirela,
3370 			      (Elf64_Mips_External_Rela *) dst);
3371 }
3372 
3373 /* Set the GP value for OUTPUT_BFD.  Returns false if this is a
3374    dangerous relocation.  */
3375 
3376 static bool
mips_elf64_assign_gp(bfd * output_bfd,bfd_vma * pgp)3377 mips_elf64_assign_gp (bfd *output_bfd, bfd_vma *pgp)
3378 {
3379   unsigned int count;
3380   asymbol **sym;
3381   unsigned int i;
3382 
3383   /* If we've already figured out what GP will be, just return it.  */
3384   *pgp = _bfd_get_gp_value (output_bfd);
3385   if (*pgp)
3386     return true;
3387 
3388   count = bfd_get_symcount (output_bfd);
3389   sym = bfd_get_outsymbols (output_bfd);
3390 
3391   /* The linker script will have created a symbol named `_gp' with the
3392      appropriate value.  */
3393   if (sym == NULL)
3394     i = count;
3395   else
3396     {
3397       for (i = 0; i < count; i++, sym++)
3398 	{
3399 	  register const char *name;
3400 
3401 	  name = bfd_asymbol_name (*sym);
3402 	  if (*name == '_' && strcmp (name, "_gp") == 0)
3403 	    {
3404 	      *pgp = bfd_asymbol_value (*sym);
3405 	      _bfd_set_gp_value (output_bfd, *pgp);
3406 	      break;
3407 	    }
3408 	}
3409     }
3410 
3411   if (i >= count)
3412     {
3413       /* Only get the error once.  */
3414       *pgp = 4;
3415       _bfd_set_gp_value (output_bfd, *pgp);
3416       return false;
3417     }
3418 
3419   return true;
3420 }
3421 
3422 /* We have to figure out the gp value, so that we can adjust the
3423    symbol value correctly.  We look up the symbol _gp in the output
3424    BFD.  If we can't find it, we're stuck.  We cache it in the ELF
3425    target data.  We don't need to adjust the symbol value for an
3426    external symbol if we are producing relocatable output.  */
3427 
3428 static bfd_reloc_status_type
mips_elf64_final_gp(bfd * output_bfd,asymbol * symbol,bool relocatable,char ** error_message,bfd_vma * pgp)3429 mips_elf64_final_gp (bfd *output_bfd, asymbol *symbol, bool relocatable,
3430 		     char **error_message, bfd_vma *pgp)
3431 {
3432   if (output_bfd == NULL)
3433     {
3434       *pgp = 0;
3435       return bfd_reloc_undefined;
3436     }
3437 
3438   *pgp = _bfd_get_gp_value (output_bfd);
3439   if (*pgp == 0
3440       && (! relocatable
3441 	  || (symbol->flags & BSF_SECTION_SYM) != 0))
3442     {
3443       if (relocatable)
3444 	{
3445 	  /* Make up a value.  */
3446 	  *pgp = symbol->section->output_section->vma /*+ 0x4000*/;
3447 	  _bfd_set_gp_value (output_bfd, *pgp);
3448 	}
3449       else if (!mips_elf64_assign_gp (output_bfd, pgp))
3450 	{
3451 	  *error_message =
3452 	    (char *) _("GP relative relocation when _gp not defined");
3453 	  return bfd_reloc_dangerous;
3454 	}
3455     }
3456 
3457   return bfd_reloc_ok;
3458 }
3459 
3460 /* Do a R_MIPS_GPREL16 relocation.  This is a 16 bit value which must
3461    become the offset from the gp register.  */
3462 
3463 static bfd_reloc_status_type
mips_elf64_gprel16_reloc(bfd * abfd,arelent * reloc_entry,asymbol * symbol,void * data,asection * input_section,bfd * output_bfd,char ** error_message)3464 mips_elf64_gprel16_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
3465 			  void *data, asection *input_section, bfd *output_bfd,
3466 			  char **error_message)
3467 {
3468   bool relocatable;
3469   bfd_reloc_status_type ret;
3470   bfd_vma gp;
3471 
3472   /* If we're relocating, and this is an external symbol, we don't want
3473      to change anything.  */
3474   if (output_bfd != NULL
3475       && (symbol->flags & BSF_SECTION_SYM) == 0
3476       && (symbol->flags & BSF_LOCAL) != 0)
3477     {
3478       reloc_entry->address += input_section->output_offset;
3479       return bfd_reloc_ok;
3480     }
3481 
3482   if (output_bfd != NULL)
3483     relocatable = true;
3484   else
3485     {
3486       relocatable = false;
3487       output_bfd = input_section->output_section->owner;
3488     }
3489 
3490   ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message,
3491 			     &gp);
3492   if (ret != bfd_reloc_ok)
3493     return ret;
3494 
3495   return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
3496 					input_section, relocatable,
3497 					data, gp);
3498 }
3499 
3500 /* Do a R_MIPS_LITERAL relocation.  */
3501 
3502 static bfd_reloc_status_type
mips_elf64_literal_reloc(bfd * abfd,arelent * reloc_entry,asymbol * symbol,void * data,asection * input_section,bfd * output_bfd,char ** error_message)3503 mips_elf64_literal_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
3504 			  void *data, asection *input_section, bfd *output_bfd,
3505 			  char **error_message)
3506 {
3507   bool relocatable;
3508   bfd_reloc_status_type ret;
3509   bfd_vma gp;
3510 
3511   /* R_MIPS_LITERAL relocations are defined for local symbols only.  */
3512   if (output_bfd != NULL
3513       && (symbol->flags & BSF_SECTION_SYM) == 0
3514       && (symbol->flags & BSF_LOCAL) != 0)
3515     {
3516       *error_message = (char *)
3517 	_("literal relocation occurs for an external symbol");
3518       return bfd_reloc_outofrange;
3519     }
3520 
3521   /* FIXME: The entries in the .lit8 and .lit4 sections should be merged.  */
3522   if (output_bfd != NULL)
3523     relocatable = true;
3524   else
3525     {
3526       relocatable = false;
3527       output_bfd = input_section->output_section->owner;
3528     }
3529 
3530   ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message,
3531 			     &gp);
3532   if (ret != bfd_reloc_ok)
3533     return ret;
3534 
3535   return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
3536 					input_section, relocatable,
3537 					data, gp);
3538 }
3539 
3540 /* Do a R_MIPS_GPREL32 relocation.  This is a 32 bit value which must
3541    become the offset from the gp register.  */
3542 
3543 static bfd_reloc_status_type
mips_elf64_gprel32_reloc(bfd * abfd,arelent * reloc_entry,asymbol * symbol,void * data,asection * input_section,bfd * output_bfd,char ** error_message)3544 mips_elf64_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
3545 			  void *data, asection *input_section, bfd *output_bfd,
3546 			  char **error_message)
3547 {
3548   bool relocatable;
3549   bfd_reloc_status_type ret;
3550   bfd_vma gp;
3551   bfd_vma relocation;
3552   bfd_vma val;
3553 
3554   /* R_MIPS_GPREL32 relocations are defined for local symbols only.  */
3555   if (output_bfd != NULL
3556       && (symbol->flags & BSF_SECTION_SYM) == 0
3557       && (symbol->flags & BSF_LOCAL) != 0)
3558     {
3559       *error_message = (char *)
3560 	_("32bits gp relative relocation occurs for an external symbol");
3561       return bfd_reloc_outofrange;
3562     }
3563 
3564   if (output_bfd != NULL)
3565     relocatable = true;
3566   else
3567     {
3568       relocatable = false;
3569       output_bfd = input_section->output_section->owner;
3570     }
3571 
3572   ret = mips_elf64_final_gp (output_bfd, symbol, relocatable,
3573 			     error_message, &gp);
3574   if (ret != bfd_reloc_ok)
3575     return ret;
3576 
3577   if (bfd_is_com_section (symbol->section))
3578     relocation = 0;
3579   else
3580     relocation = symbol->value;
3581 
3582   if (symbol->section->output_section != NULL)
3583     {
3584       relocation += symbol->section->output_section->vma;
3585       relocation += symbol->section->output_offset;
3586     }
3587 
3588   if (!_bfd_mips_reloc_offset_in_range (abfd, input_section, reloc_entry,
3589 					check_inplace))
3590     return bfd_reloc_outofrange;
3591 
3592   /* Set val to the offset into the section or symbol.  */
3593   val = reloc_entry->addend;
3594 
3595   if (reloc_entry->howto->partial_inplace)
3596     val += bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
3597 
3598   /* Adjust val for the final section location and GP value.  If we
3599      are producing relocatable output, we don't want to do this for
3600      an external symbol.  */
3601   if (! relocatable
3602       || (symbol->flags & BSF_SECTION_SYM) != 0)
3603     val += relocation - gp;
3604 
3605   if (reloc_entry->howto->partial_inplace)
3606     bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
3607   else
3608     reloc_entry->addend = val;
3609 
3610   if (relocatable)
3611     reloc_entry->address += input_section->output_offset;
3612 
3613   return bfd_reloc_ok;
3614 }
3615 
3616 /* Do a R_MIPS_SHIFT6 relocation. The MSB of the shift is stored at bit 2,
3617    the rest is at bits 6-10. The bitpos already got right by the howto.  */
3618 
3619 static bfd_reloc_status_type
mips_elf64_shift6_reloc(bfd * abfd,arelent * reloc_entry,asymbol * symbol,void * data,asection * input_section,bfd * output_bfd,char ** error_message)3620 mips_elf64_shift6_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
3621 			 void *data, asection *input_section, bfd *output_bfd,
3622 			 char **error_message)
3623 {
3624   if (reloc_entry->howto->partial_inplace)
3625     {
3626       reloc_entry->addend = ((reloc_entry->addend & 0x00007c0)
3627 			     | (reloc_entry->addend & 0x00000800) >> 9);
3628     }
3629 
3630   return _bfd_mips_elf_generic_reloc (abfd, reloc_entry, symbol, data,
3631 				      input_section, output_bfd,
3632 				      error_message);
3633 }
3634 
3635 /* Handle a mips16 GP relative reloc.  */
3636 
3637 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)3638 mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
3639 		    void *data, asection *input_section, bfd *output_bfd,
3640 		    char **error_message)
3641 {
3642   bool relocatable;
3643   bfd_reloc_status_type ret;
3644   bfd_byte *location;
3645   bfd_vma gp;
3646 
3647   /* If we're relocating, and this is an external symbol, we don't want
3648      to change anything.  */
3649   if (output_bfd != NULL
3650       && (symbol->flags & BSF_SECTION_SYM) == 0
3651       && (symbol->flags & BSF_LOCAL) != 0)
3652     {
3653       reloc_entry->address += input_section->output_offset;
3654       return bfd_reloc_ok;
3655     }
3656 
3657   if (output_bfd != NULL)
3658     relocatable = true;
3659   else
3660     {
3661       relocatable = false;
3662       output_bfd = input_section->output_section->owner;
3663     }
3664 
3665   ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message,
3666 			     &gp);
3667   if (ret != bfd_reloc_ok)
3668     return ret;
3669 
3670   if (!_bfd_mips_reloc_offset_in_range (abfd, input_section, reloc_entry,
3671 					check_shuffle))
3672     return bfd_reloc_outofrange;
3673 
3674   location = (bfd_byte *) data + reloc_entry->address;
3675   _bfd_mips_elf_reloc_unshuffle (abfd, reloc_entry->howto->type, false,
3676 				 location);
3677   ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
3678 				       input_section, relocatable,
3679 				       data, gp);
3680   _bfd_mips_elf_reloc_shuffle (abfd, reloc_entry->howto->type, !relocatable,
3681 			       location);
3682 
3683   return ret;
3684 }
3685 
3686 /* A mapping from BFD reloc types to MIPS ELF reloc types.  */
3687 
3688 struct elf_reloc_map {
3689   bfd_reloc_code_real_type bfd_val;
3690   enum elf_mips_reloc_type elf_val;
3691 };
3692 
3693 static const struct elf_reloc_map mips_reloc_map[] =
3694 {
3695   { BFD_RELOC_NONE, R_MIPS_NONE },
3696   { BFD_RELOC_MIPS_16, R_MIPS_16 },
3697   { BFD_RELOC_16, R_MIPS_REL16 },
3698   { BFD_RELOC_32, R_MIPS_32 },
3699   /* There is no BFD reloc for R_MIPS_REL32.  */
3700   { BFD_RELOC_64, R_MIPS_64 },
3701   { BFD_RELOC_CTOR, R_MIPS_64 },
3702   { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
3703   { BFD_RELOC_HI16_S, R_MIPS_HI16 },
3704   { BFD_RELOC_LO16, R_MIPS_LO16 },
3705   { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
3706   { BFD_RELOC_GPREL32, R_MIPS_GPREL32 },
3707   { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
3708   { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
3709   { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
3710   { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
3711   { BFD_RELOC_MIPS_SHIFT5, R_MIPS_SHIFT5 },
3712   { BFD_RELOC_MIPS_SHIFT6, R_MIPS_SHIFT6 },
3713   { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP },
3714   { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
3715   { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
3716   { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
3717   { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
3718   { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
3719   { BFD_RELOC_MIPS_INSERT_A, R_MIPS_INSERT_A },
3720   { BFD_RELOC_MIPS_INSERT_B, R_MIPS_INSERT_B },
3721   { BFD_RELOC_MIPS_DELETE, R_MIPS_DELETE },
3722   { BFD_RELOC_MIPS_HIGHEST, R_MIPS_HIGHEST },
3723   { BFD_RELOC_MIPS_HIGHER, R_MIPS_HIGHER },
3724   { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
3725   { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
3726   { BFD_RELOC_MIPS_SCN_DISP, R_MIPS_SCN_DISP },
3727   /* Use of R_MIPS_ADD_IMMEDIATE and R_MIPS_PJUMP is deprecated.  */
3728   { BFD_RELOC_MIPS_RELGOT, R_MIPS_RELGOT },
3729   { BFD_RELOC_MIPS_JALR, R_MIPS_JALR },
3730   { BFD_RELOC_MIPS_TLS_DTPMOD32, R_MIPS_TLS_DTPMOD32 },
3731   { BFD_RELOC_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL32 },
3732   { BFD_RELOC_MIPS_TLS_DTPMOD64, R_MIPS_TLS_DTPMOD64 },
3733   { BFD_RELOC_MIPS_TLS_DTPREL64, R_MIPS_TLS_DTPREL64 },
3734   { BFD_RELOC_MIPS_TLS_GD, R_MIPS_TLS_GD },
3735   { BFD_RELOC_MIPS_TLS_LDM, R_MIPS_TLS_LDM },
3736   { BFD_RELOC_MIPS_TLS_DTPREL_HI16, R_MIPS_TLS_DTPREL_HI16 },
3737   { BFD_RELOC_MIPS_TLS_DTPREL_LO16, R_MIPS_TLS_DTPREL_LO16 },
3738   { BFD_RELOC_MIPS_TLS_GOTTPREL, R_MIPS_TLS_GOTTPREL },
3739   { BFD_RELOC_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL32 },
3740   { BFD_RELOC_MIPS_TLS_TPREL64, R_MIPS_TLS_TPREL64 },
3741   { BFD_RELOC_MIPS_TLS_TPREL_HI16, R_MIPS_TLS_TPREL_HI16 },
3742   { BFD_RELOC_MIPS_TLS_TPREL_LO16, R_MIPS_TLS_TPREL_LO16 },
3743   { BFD_RELOC_MIPS_21_PCREL_S2, R_MIPS_PC21_S2 },
3744   { BFD_RELOC_MIPS_26_PCREL_S2, R_MIPS_PC26_S2 },
3745   { BFD_RELOC_MIPS_18_PCREL_S3, R_MIPS_PC18_S3 },
3746   { BFD_RELOC_MIPS_19_PCREL_S2, R_MIPS_PC19_S2 },
3747   { BFD_RELOC_HI16_S_PCREL, R_MIPS_PCHI16 },
3748   { BFD_RELOC_LO16_PCREL, R_MIPS_PCLO16 }
3749 };
3750 
3751 static const struct elf_reloc_map mips16_reloc_map[] =
3752 {
3753   { BFD_RELOC_MIPS16_JMP, R_MIPS16_26 - R_MIPS16_min },
3754   { BFD_RELOC_MIPS16_GPREL, R_MIPS16_GPREL - R_MIPS16_min },
3755   { BFD_RELOC_MIPS16_GOT16, R_MIPS16_GOT16 - R_MIPS16_min },
3756   { BFD_RELOC_MIPS16_CALL16, R_MIPS16_CALL16 - R_MIPS16_min },
3757   { BFD_RELOC_MIPS16_HI16_S, R_MIPS16_HI16 - R_MIPS16_min },
3758   { BFD_RELOC_MIPS16_LO16, R_MIPS16_LO16 - R_MIPS16_min },
3759   { BFD_RELOC_MIPS16_TLS_GD, R_MIPS16_TLS_GD - R_MIPS16_min },
3760   { BFD_RELOC_MIPS16_TLS_LDM, R_MIPS16_TLS_LDM - R_MIPS16_min },
3761   { BFD_RELOC_MIPS16_TLS_DTPREL_HI16,
3762     R_MIPS16_TLS_DTPREL_HI16 - R_MIPS16_min },
3763   { BFD_RELOC_MIPS16_TLS_DTPREL_LO16,
3764     R_MIPS16_TLS_DTPREL_LO16 - R_MIPS16_min },
3765   { BFD_RELOC_MIPS16_TLS_GOTTPREL, R_MIPS16_TLS_GOTTPREL - R_MIPS16_min },
3766   { BFD_RELOC_MIPS16_TLS_TPREL_HI16, R_MIPS16_TLS_TPREL_HI16 - R_MIPS16_min },
3767   { BFD_RELOC_MIPS16_TLS_TPREL_LO16, R_MIPS16_TLS_TPREL_LO16 - R_MIPS16_min },
3768   { BFD_RELOC_MIPS16_16_PCREL_S1, R_MIPS16_PC16_S1 - R_MIPS16_min }
3769 };
3770 
3771 static const struct elf_reloc_map micromips_reloc_map[] =
3772 {
3773   { BFD_RELOC_MICROMIPS_JMP, R_MICROMIPS_26_S1 - R_MICROMIPS_min },
3774   { BFD_RELOC_MICROMIPS_HI16_S, R_MICROMIPS_HI16 - R_MICROMIPS_min },
3775   { BFD_RELOC_MICROMIPS_LO16, R_MICROMIPS_LO16 - R_MICROMIPS_min },
3776   { BFD_RELOC_MICROMIPS_GPREL16, R_MICROMIPS_GPREL16 - R_MICROMIPS_min },
3777   { BFD_RELOC_MICROMIPS_LITERAL, R_MICROMIPS_LITERAL - R_MICROMIPS_min },
3778   { BFD_RELOC_MICROMIPS_GOT16, R_MICROMIPS_GOT16 - R_MICROMIPS_min },
3779   { BFD_RELOC_MICROMIPS_7_PCREL_S1, R_MICROMIPS_PC7_S1 - R_MICROMIPS_min },
3780   { BFD_RELOC_MICROMIPS_10_PCREL_S1, R_MICROMIPS_PC10_S1 - R_MICROMIPS_min },
3781   { BFD_RELOC_MICROMIPS_16_PCREL_S1, R_MICROMIPS_PC16_S1 - R_MICROMIPS_min },
3782   { BFD_RELOC_MICROMIPS_CALL16, R_MICROMIPS_CALL16 - R_MICROMIPS_min },
3783   { BFD_RELOC_MICROMIPS_GOT_DISP, R_MICROMIPS_GOT_DISP - R_MICROMIPS_min },
3784   { BFD_RELOC_MICROMIPS_GOT_PAGE, R_MICROMIPS_GOT_PAGE - R_MICROMIPS_min },
3785   { BFD_RELOC_MICROMIPS_GOT_OFST, R_MICROMIPS_GOT_OFST - R_MICROMIPS_min },
3786   { BFD_RELOC_MICROMIPS_GOT_HI16, R_MICROMIPS_GOT_HI16 - R_MICROMIPS_min },
3787   { BFD_RELOC_MICROMIPS_GOT_LO16, R_MICROMIPS_GOT_LO16 - R_MICROMIPS_min },
3788   { BFD_RELOC_MICROMIPS_SUB, R_MICROMIPS_SUB - R_MICROMIPS_min },
3789   { BFD_RELOC_MICROMIPS_HIGHER, R_MICROMIPS_HIGHER - R_MICROMIPS_min },
3790   { BFD_RELOC_MICROMIPS_HIGHEST, R_MICROMIPS_HIGHEST - R_MICROMIPS_min },
3791   { BFD_RELOC_MICROMIPS_CALL_HI16, R_MICROMIPS_CALL_HI16 - R_MICROMIPS_min },
3792   { BFD_RELOC_MICROMIPS_CALL_LO16, R_MICROMIPS_CALL_LO16 - R_MICROMIPS_min },
3793   { BFD_RELOC_MICROMIPS_SCN_DISP, R_MICROMIPS_SCN_DISP - R_MICROMIPS_min },
3794   { BFD_RELOC_MICROMIPS_JALR, R_MICROMIPS_JALR - R_MICROMIPS_min },
3795   /* There is no BFD reloc for R_MICROMIPS_HI0_LO16.  */
3796   { BFD_RELOC_MICROMIPS_TLS_GD, R_MICROMIPS_TLS_GD - R_MICROMIPS_min },
3797   { BFD_RELOC_MICROMIPS_TLS_LDM, R_MICROMIPS_TLS_LDM - R_MICROMIPS_min },
3798   { BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16,
3799     R_MICROMIPS_TLS_DTPREL_HI16 - R_MICROMIPS_min },
3800   { BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16,
3801     R_MICROMIPS_TLS_DTPREL_LO16 - R_MICROMIPS_min },
3802   { BFD_RELOC_MICROMIPS_TLS_GOTTPREL,
3803     R_MICROMIPS_TLS_GOTTPREL - R_MICROMIPS_min },
3804   { BFD_RELOC_MICROMIPS_TLS_TPREL_HI16,
3805     R_MICROMIPS_TLS_TPREL_HI16 - R_MICROMIPS_min },
3806   { BFD_RELOC_MICROMIPS_TLS_TPREL_LO16,
3807     R_MICROMIPS_TLS_TPREL_LO16 - R_MICROMIPS_min },
3808   /* There is no BFD reloc for R_MICROMIPS_GPREL7_S2.  */
3809   /* There is no BFD reloc for R_MICROMIPS_PC23_S2.  */
3810 };
3811 /* Given a BFD reloc type, return a howto structure.  */
3812 
3813 static reloc_howto_type *
bfd_elf64_bfd_reloc_type_lookup(bfd * abfd ATTRIBUTE_UNUSED,bfd_reloc_code_real_type code)3814 bfd_elf64_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
3815 				 bfd_reloc_code_real_type code)
3816 {
3817   unsigned int i;
3818   /* FIXME: We default to RELA here instead of choosing the right
3819      relocation variant.  */
3820   reloc_howto_type *howto_table = mips_elf64_howto_table_rela;
3821   reloc_howto_type *howto16_table = mips16_elf64_howto_table_rela;
3822   reloc_howto_type *howto_micromips_table = micromips_elf64_howto_table_rela;
3823 
3824   for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map);
3825        i++)
3826     {
3827       if (mips_reloc_map[i].bfd_val == code)
3828 	return &howto_table[(int) mips_reloc_map[i].elf_val];
3829     }
3830 
3831   for (i = 0; i < sizeof (mips16_reloc_map) / sizeof (struct elf_reloc_map);
3832        i++)
3833     {
3834       if (mips16_reloc_map[i].bfd_val == code)
3835 	return &howto16_table[(int) mips16_reloc_map[i].elf_val];
3836     }
3837 
3838   for (i = 0; i < sizeof (micromips_reloc_map) / sizeof (struct elf_reloc_map);
3839        i++)
3840     {
3841       if (micromips_reloc_map[i].bfd_val == code)
3842 	return &howto_micromips_table[(int) micromips_reloc_map[i].elf_val];
3843     }
3844 
3845   switch (code)
3846     {
3847     case BFD_RELOC_VTABLE_INHERIT:
3848       return &elf_mips_gnu_vtinherit_howto;
3849     case BFD_RELOC_VTABLE_ENTRY:
3850       return &elf_mips_gnu_vtentry_howto;
3851     case BFD_RELOC_32_PCREL:
3852       return &elf_mips_gnu_pcrel32;
3853     case BFD_RELOC_MIPS_EH:
3854       return &elf_mips_eh_howto;
3855     case BFD_RELOC_MIPS_COPY:
3856       return &elf_mips_copy_howto;
3857     case BFD_RELOC_MIPS_JUMP_SLOT:
3858       return &elf_mips_jump_slot_howto;
3859     default:
3860       bfd_set_error (bfd_error_bad_value);
3861       return NULL;
3862     }
3863 }
3864 
3865 static reloc_howto_type *
bfd_elf64_bfd_reloc_name_lookup(bfd * abfd ATTRIBUTE_UNUSED,const char * r_name)3866 bfd_elf64_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
3867 				 const char *r_name)
3868 {
3869   unsigned int i;
3870 
3871   for (i = 0;
3872        i < (sizeof (mips_elf64_howto_table_rela)
3873 	    / sizeof (mips_elf64_howto_table_rela[0])); i++)
3874     if (mips_elf64_howto_table_rela[i].name != NULL
3875 	&& strcasecmp (mips_elf64_howto_table_rela[i].name, r_name) == 0)
3876       return &mips_elf64_howto_table_rela[i];
3877 
3878   for (i = 0;
3879        i < (sizeof (mips16_elf64_howto_table_rela)
3880 	    / sizeof (mips16_elf64_howto_table_rela[0]));
3881        i++)
3882     if (mips16_elf64_howto_table_rela[i].name != NULL
3883 	&& strcasecmp (mips16_elf64_howto_table_rela[i].name, r_name) == 0)
3884       return &mips16_elf64_howto_table_rela[i];
3885 
3886   for (i = 0;
3887        i < (sizeof (micromips_elf64_howto_table_rela)
3888 	    / sizeof (micromips_elf64_howto_table_rela[0]));
3889        i++)
3890     if (micromips_elf64_howto_table_rela[i].name != NULL
3891 	&& strcasecmp (micromips_elf64_howto_table_rela[i].name, r_name) == 0)
3892       return &micromips_elf64_howto_table_rela[i];
3893 
3894   if (strcasecmp (elf_mips_gnu_vtinherit_howto.name, r_name) == 0)
3895     return &elf_mips_gnu_vtinherit_howto;
3896   if (strcasecmp (elf_mips_gnu_vtentry_howto.name, r_name) == 0)
3897     return &elf_mips_gnu_vtentry_howto;
3898   if (strcasecmp (elf_mips_gnu_rel16_s2.name, r_name) == 0)
3899     return &elf_mips_gnu_rel16_s2;
3900   if (strcasecmp (elf_mips_gnu_rela16_s2.name, r_name) == 0)
3901     return &elf_mips_gnu_rela16_s2;
3902   if (strcasecmp (elf_mips_gnu_pcrel32.name, r_name) == 0)
3903     return &elf_mips_gnu_pcrel32;
3904   if (strcasecmp (elf_mips_eh_howto.name, r_name) == 0)
3905     return &elf_mips_eh_howto;
3906   if (strcasecmp (elf_mips_copy_howto.name, r_name) == 0)
3907     return &elf_mips_copy_howto;
3908   if (strcasecmp (elf_mips_jump_slot_howto.name, r_name) == 0)
3909     return &elf_mips_jump_slot_howto;
3910 
3911   return NULL;
3912 }
3913 
3914 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure.  */
3915 
3916 static reloc_howto_type *
mips_elf64_rtype_to_howto(bfd * abfd,unsigned int r_type,bool rela_p)3917 mips_elf64_rtype_to_howto (bfd *abfd, unsigned int r_type, bool rela_p)
3918 {
3919   reloc_howto_type *howto = NULL;
3920 
3921   switch (r_type)
3922     {
3923     case R_MIPS_GNU_VTINHERIT:
3924       return &elf_mips_gnu_vtinherit_howto;
3925     case R_MIPS_GNU_VTENTRY:
3926       return &elf_mips_gnu_vtentry_howto;
3927     case R_MIPS_GNU_REL16_S2:
3928       if (rela_p)
3929 	return &elf_mips_gnu_rela16_s2;
3930       else
3931 	return &elf_mips_gnu_rel16_s2;
3932     case R_MIPS_PC32:
3933       return &elf_mips_gnu_pcrel32;
3934     case R_MIPS_EH:
3935       return &elf_mips_eh_howto;
3936     case R_MIPS_COPY:
3937       return &elf_mips_copy_howto;
3938     case R_MIPS_JUMP_SLOT:
3939       return &elf_mips_jump_slot_howto;
3940     default:
3941       if (r_type >= R_MICROMIPS_min && r_type < R_MICROMIPS_max)
3942 	{
3943 	  if (rela_p)
3944 	    howto
3945 	      = &micromips_elf64_howto_table_rela[r_type - R_MICROMIPS_min];
3946 	  else
3947 	    howto
3948 	      = &micromips_elf64_howto_table_rel[r_type - R_MICROMIPS_min];
3949 	}
3950       if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max)
3951 	{
3952 	  if (rela_p)
3953 	    howto = &mips16_elf64_howto_table_rela[r_type - R_MIPS16_min];
3954 	  else
3955 	    howto = &mips16_elf64_howto_table_rel[r_type - R_MIPS16_min];
3956 	}
3957       if (r_type < R_MIPS_max)
3958 	{
3959 	  if (rela_p)
3960 	    howto = &mips_elf64_howto_table_rela[r_type];
3961 	  else
3962 	    howto = &mips_elf64_howto_table_rel[r_type];
3963 	}
3964       if (howto != NULL && howto->name != NULL)
3965 	return howto;
3966 
3967       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
3968 			  abfd, r_type);
3969       bfd_set_error (bfd_error_bad_value);
3970       return NULL;
3971     }
3972 }
3973 
3974 /* Prevent relocation handling by bfd for MIPS ELF64.  */
3975 
3976 static bool
mips_elf64_info_to_howto_rela(bfd * abfd,arelent * cache_ptr ATTRIBUTE_UNUSED,Elf_Internal_Rela * dst)3977 mips_elf64_info_to_howto_rela (bfd *abfd,
3978 			       arelent *cache_ptr ATTRIBUTE_UNUSED,
3979 			       Elf_Internal_Rela *dst)
3980 {
3981   unsigned int r_type = ELF32_R_TYPE (dst->r_info);
3982   /* xgettext:c-format */
3983   _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
3984 		      abfd, r_type);
3985   bfd_set_error (bfd_error_bad_value);
3986   return false;
3987 }
3988 
3989 /* Since each entry in an SHT_REL or SHT_RELA section can represent up
3990    to three relocs, we must tell the user to allocate more space.  */
3991 
3992 static long
mips_elf64_get_dynamic_reloc_upper_bound(bfd * abfd)3993 mips_elf64_get_dynamic_reloc_upper_bound (bfd *abfd)
3994 {
3995   return _bfd_elf_get_dynamic_reloc_upper_bound (abfd) * 3;
3996 }
3997 
3998 /* Read the relocations from one reloc section.  This is mostly copied
3999    from elfcode.h, except for the changes to expand one external
4000    relocation to 3 internal ones.  To reduce processing effort we
4001    could discard those R_MIPS_NONE relocations that occupy the second
4002    and the third entry of a triplet, as `mips_elf64_write_rel' and
4003    `mips_elf64_write_rela' recreate them in output automagically,
4004    however that would also remove them from `objdump -r' output,
4005    breaking a long-established tradition and likely confusing people.  */
4006 
4007 static bool
mips_elf64_slurp_one_reloc_table(bfd * abfd,asection * asect,Elf_Internal_Shdr * rel_hdr,bfd_size_type reloc_count,arelent * relents,asymbol ** symbols,bool dynamic)4008 mips_elf64_slurp_one_reloc_table (bfd *abfd, asection *asect,
4009 				  Elf_Internal_Shdr *rel_hdr,
4010 				  bfd_size_type reloc_count,
4011 				  arelent *relents, asymbol **symbols,
4012 				  bool dynamic)
4013 {
4014   void *allocated;
4015   bfd_byte *native_relocs;
4016   unsigned int symcount;
4017   arelent *relent;
4018   bfd_vma i;
4019   int entsize;
4020   bool rela_p;
4021 
4022   if (bfd_seek (abfd, rel_hdr->sh_offset, SEEK_SET) != 0)
4023     return false;
4024   allocated = _bfd_malloc_and_read (abfd, rel_hdr->sh_size, rel_hdr->sh_size);
4025   if (allocated == NULL)
4026     return false;
4027 
4028   native_relocs = allocated;
4029 
4030   entsize = rel_hdr->sh_entsize;
4031   BFD_ASSERT (entsize == sizeof (Elf64_Mips_External_Rel)
4032 	      || entsize == sizeof (Elf64_Mips_External_Rela));
4033 
4034   if (entsize == sizeof (Elf64_Mips_External_Rel))
4035     rela_p = false;
4036   else
4037     rela_p = true;
4038 
4039   if (dynamic)
4040     symcount = bfd_get_dynamic_symcount (abfd);
4041   else
4042     symcount = bfd_get_symcount (abfd);
4043 
4044   for (i = 0, relent = relents;
4045        i < reloc_count;
4046        i++, native_relocs += entsize)
4047     {
4048       Elf64_Mips_Internal_Rela rela;
4049       bool used_sym, used_ssym;
4050       int ir;
4051 
4052       if (entsize == sizeof (Elf64_Mips_External_Rela))
4053 	mips_elf64_swap_reloca_in (abfd,
4054 				   (Elf64_Mips_External_Rela *) native_relocs,
4055 				   &rela);
4056       else
4057 	mips_elf64_swap_reloc_in (abfd,
4058 				  (Elf64_Mips_External_Rel *) native_relocs,
4059 				  &rela);
4060 
4061       /* Each entry represents exactly three actual relocations.  */
4062 
4063       used_sym = false;
4064       used_ssym = false;
4065       for (ir = 0; ir < 3; ir++)
4066 	{
4067 	  enum elf_mips_reloc_type type;
4068 
4069 	  switch (ir)
4070 	    {
4071 	    default:
4072 	      abort ();
4073 	    case 0:
4074 	      type = (enum elf_mips_reloc_type) rela.r_type;
4075 	      break;
4076 	    case 1:
4077 	      type = (enum elf_mips_reloc_type) rela.r_type2;
4078 	      break;
4079 	    case 2:
4080 	      type = (enum elf_mips_reloc_type) rela.r_type3;
4081 	      break;
4082 	    }
4083 
4084 	  /* Some types require symbols, whereas some do not.  */
4085 	  relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
4086 	  switch (type)
4087 	    {
4088 	    case R_MIPS_NONE:
4089 	    case R_MIPS_LITERAL:
4090 	    case R_MIPS_INSERT_A:
4091 	    case R_MIPS_INSERT_B:
4092 	    case R_MIPS_DELETE:
4093 	      break;
4094 
4095 	    default:
4096 	      if (! used_sym)
4097 		{
4098 		  if (rela.r_sym == STN_UNDEF)
4099 		    ;
4100 		  else if (rela.r_sym > symcount)
4101 		    {
4102 		      _bfd_error_handler
4103 			/* xgettext:c-format */
4104 			(_("%pB(%pA): relocation %" PRIu64
4105 			   " has invalid symbol index %ld"),
4106 			 abfd, asect, (uint64_t) i, rela.r_sym);
4107 		      bfd_set_error (bfd_error_bad_value);
4108 		    }
4109 		  else
4110 		    {
4111 		      asymbol **ps, *s;
4112 
4113 		      ps = symbols + rela.r_sym - 1;
4114 		      s = *ps;
4115 		      if ((s->flags & BSF_SECTION_SYM) == 0)
4116 			relent->sym_ptr_ptr = ps;
4117 		      else
4118 			relent->sym_ptr_ptr = s->section->symbol_ptr_ptr;
4119 		    }
4120 
4121 		  used_sym = true;
4122 		}
4123 	      else if (! used_ssym)
4124 		{
4125 		  switch (rela.r_ssym)
4126 		    {
4127 		    case RSS_UNDEF:
4128 		      break;
4129 
4130 		    case RSS_GP:
4131 		    case RSS_GP0:
4132 		    case RSS_LOC:
4133 		      /* FIXME: I think these need to be handled using
4134 			 special howto structures.  */
4135 		      BFD_ASSERT (0);
4136 		      break;
4137 
4138 		    default:
4139 		      BFD_ASSERT (0);
4140 		      break;
4141 		    }
4142 
4143 		  used_ssym = true;
4144 		}
4145 	      break;
4146 	    }
4147 
4148 	  /* The address of an ELF reloc is section relative for an
4149 	     object file, and absolute for an executable file or
4150 	     shared library.  The address of a BFD reloc is always
4151 	     section relative.  */
4152 	  if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0 || dynamic)
4153 	    relent->address = rela.r_offset;
4154 	  else
4155 	    relent->address = rela.r_offset - asect->vma;
4156 
4157 	  relent->addend = rela.r_addend;
4158 
4159 	  relent->howto = mips_elf64_rtype_to_howto (abfd, type, rela_p);
4160 	  if (relent->howto == NULL)
4161 	    goto error_return;
4162 
4163 	  ++relent;
4164 	}
4165     }
4166 
4167   free (allocated);
4168   return true;
4169 
4170  error_return:
4171   free (allocated);
4172   return false;
4173 }
4174 
4175 /* Read the relocations.  On Irix 6, there can be two reloc sections
4176    associated with a single data section.  This is copied from
4177    elfcode.h as well, with changes as small as accounting for 3
4178    internal relocs per external reloc.  */
4179 
4180 static bool
mips_elf64_slurp_reloc_table(bfd * abfd,asection * asect,asymbol ** symbols,bool dynamic)4181 mips_elf64_slurp_reloc_table (bfd *abfd, asection *asect,
4182 			      asymbol **symbols, bool dynamic)
4183 {
4184   struct bfd_elf_section_data * const d = elf_section_data (asect);
4185   Elf_Internal_Shdr *rel_hdr;
4186   Elf_Internal_Shdr *rel_hdr2;
4187   bfd_size_type reloc_count;
4188   bfd_size_type reloc_count2;
4189   arelent *relents;
4190   bfd_size_type amt;
4191 
4192   if (asect->relocation != NULL)
4193     return true;
4194 
4195   if (! dynamic)
4196     {
4197       if ((asect->flags & SEC_RELOC) == 0
4198 	  || asect->reloc_count == 0)
4199 	return true;
4200 
4201       rel_hdr = d->rel.hdr;
4202       reloc_count = rel_hdr ? NUM_SHDR_ENTRIES (rel_hdr) : 0;
4203       rel_hdr2 = d->rela.hdr;
4204       reloc_count2 = (rel_hdr2 ? NUM_SHDR_ENTRIES (rel_hdr2) : 0);
4205 
4206       BFD_ASSERT (asect->reloc_count == 3 * (reloc_count + reloc_count2));
4207       BFD_ASSERT ((rel_hdr && asect->rel_filepos == rel_hdr->sh_offset)
4208 		  || (rel_hdr2 && asect->rel_filepos == rel_hdr2->sh_offset));
4209 
4210     }
4211   else
4212     {
4213       /* Note that ASECT->RELOC_COUNT tends not to be accurate in this
4214 	 case because relocations against this section may use the
4215 	 dynamic symbol table, and in that case bfd_section_from_shdr
4216 	 in elf.c does not update the RELOC_COUNT.  */
4217       if (asect->size == 0)
4218 	return true;
4219 
4220       rel_hdr = &d->this_hdr;
4221       reloc_count = NUM_SHDR_ENTRIES (rel_hdr);
4222       rel_hdr2 = NULL;
4223       reloc_count2 = 0;
4224     }
4225 
4226   /* Allocate space for 3 arelent structures for each Rel structure.  */
4227   amt = (reloc_count + reloc_count2) * 3 * sizeof (arelent);
4228   relents = bfd_alloc (abfd, amt);
4229   if (relents == NULL)
4230     return false;
4231 
4232   if (rel_hdr != NULL
4233       && ! mips_elf64_slurp_one_reloc_table (abfd, asect,
4234 					     rel_hdr, reloc_count,
4235 					     relents,
4236 					     symbols, dynamic))
4237     return false;
4238   if (rel_hdr2 != NULL
4239       && ! mips_elf64_slurp_one_reloc_table (abfd, asect,
4240 					     rel_hdr2, reloc_count2,
4241 					     relents + reloc_count * 3,
4242 					     symbols, dynamic))
4243     return false;
4244 
4245   asect->relocation = relents;
4246   return true;
4247 }
4248 
4249 /* Write out the relocations.  */
4250 
4251 static void
mips_elf64_write_relocs(bfd * abfd,asection * sec,void * data)4252 mips_elf64_write_relocs (bfd *abfd, asection *sec, void *data)
4253 {
4254   bool *failedp = data;
4255   int count;
4256   Elf_Internal_Shdr *rel_hdr;
4257   unsigned int idx;
4258 
4259   /* If we have already failed, don't do anything.  */
4260   if (*failedp)
4261     return;
4262 
4263   if ((sec->flags & SEC_RELOC) == 0)
4264     return;
4265 
4266   /* The linker backend writes the relocs out itself, and sets the
4267      reloc_count field to zero to inhibit writing them here.  Also,
4268      sometimes the SEC_RELOC flag gets set even when there aren't any
4269      relocs.  */
4270   if (sec->reloc_count == 0)
4271     return;
4272 
4273   /* We can combine up to three relocs that refer to the same address
4274      if the latter relocs have no associated symbol.  */
4275   count = 0;
4276   for (idx = 0; idx < sec->reloc_count; idx++)
4277     {
4278       bfd_vma addr;
4279       unsigned int i;
4280 
4281       ++count;
4282 
4283       addr = sec->orelocation[idx]->address;
4284       for (i = 0; i < 2; i++)
4285 	{
4286 	  arelent *r;
4287 
4288 	  if (idx + 1 >= sec->reloc_count)
4289 	    break;
4290 	  r = sec->orelocation[idx + 1];
4291 	  if (r->address != addr
4292 	      || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
4293 	      || (*r->sym_ptr_ptr)->value != 0)
4294 	    break;
4295 
4296 	  /* We can merge the reloc at IDX + 1 with the reloc at IDX.  */
4297 
4298 	  ++idx;
4299 	}
4300     }
4301 
4302   rel_hdr = _bfd_elf_single_rel_hdr (sec);
4303 
4304   /* Do the actual relocation.  */
4305 
4306   if (rel_hdr->sh_entsize == sizeof(Elf64_Mips_External_Rel))
4307     mips_elf64_write_rel (abfd, sec, rel_hdr, &count, data);
4308   else if (rel_hdr->sh_entsize == sizeof(Elf64_Mips_External_Rela))
4309     mips_elf64_write_rela (abfd, sec, rel_hdr, &count, data);
4310   else
4311     BFD_ASSERT (0);
4312 }
4313 
4314 static void
mips_elf64_write_rel(bfd * abfd,asection * sec,Elf_Internal_Shdr * rel_hdr,int * count,void * data)4315 mips_elf64_write_rel (bfd *abfd, asection *sec,
4316 		      Elf_Internal_Shdr *rel_hdr,
4317 		      int *count, void *data)
4318 {
4319   bool *failedp = data;
4320   Elf64_Mips_External_Rel *ext_rel;
4321   unsigned int idx;
4322   asymbol *last_sym = 0;
4323   int last_sym_idx = 0;
4324 
4325   rel_hdr->sh_size = rel_hdr->sh_entsize * *count;
4326   rel_hdr->contents = bfd_alloc (abfd, rel_hdr->sh_size);
4327   if (rel_hdr->contents == NULL)
4328     {
4329       *failedp = true;
4330       return;
4331     }
4332 
4333   ext_rel = (Elf64_Mips_External_Rel *) rel_hdr->contents;
4334   for (idx = 0; idx < sec->reloc_count; idx++, ext_rel++)
4335     {
4336       arelent *ptr;
4337       Elf64_Mips_Internal_Rela int_rel;
4338       asymbol *sym;
4339       int n;
4340       unsigned int i;
4341 
4342       ptr = sec->orelocation[idx];
4343 
4344       /* The address of an ELF reloc is section relative for an object
4345 	 file, and absolute for an executable file or shared library.
4346 	 The address of a BFD reloc is always section relative.  */
4347       if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
4348 	int_rel.r_offset = ptr->address;
4349       else
4350 	int_rel.r_offset = ptr->address + sec->vma;
4351 
4352       sym = *ptr->sym_ptr_ptr;
4353       if (sym == last_sym)
4354 	n = last_sym_idx;
4355       else if (bfd_is_abs_section (sym->section) && sym->value == 0)
4356 	n = STN_UNDEF;
4357       else
4358 	{
4359 	  last_sym = sym;
4360 	  n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
4361 	  if (n < 0)
4362 	    {
4363 	      *failedp = true;
4364 	      return;
4365 	    }
4366 	  last_sym_idx = n;
4367 	}
4368 
4369       int_rel.r_sym = n;
4370       int_rel.r_ssym = RSS_UNDEF;
4371 
4372       if ((*ptr->sym_ptr_ptr)->the_bfd != NULL
4373 	  && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
4374 	  && ! _bfd_elf_validate_reloc (abfd, ptr))
4375 	{
4376 	  *failedp = true;
4377 	  return;
4378 	}
4379 
4380       int_rel.r_type = ptr->howto->type;
4381       int_rel.r_type2 = (int) R_MIPS_NONE;
4382       int_rel.r_type3 = (int) R_MIPS_NONE;
4383 
4384       for (i = 0; i < 2; i++)
4385 	{
4386 	  arelent *r;
4387 
4388 	  if (idx + 1 >= sec->reloc_count)
4389 	    break;
4390 	  r = sec->orelocation[idx + 1];
4391 	  if (r->address != ptr->address
4392 	      || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
4393 	      || (*r->sym_ptr_ptr)->value != 0)
4394 	    break;
4395 
4396 	  /* We can merge the reloc at IDX + 1 with the reloc at IDX.  */
4397 
4398 	  if (i == 0)
4399 	    int_rel.r_type2 = r->howto->type;
4400 	  else
4401 	    int_rel.r_type3 = r->howto->type;
4402 
4403 	  ++idx;
4404 	}
4405 
4406       mips_elf64_swap_reloc_out (abfd, &int_rel, ext_rel);
4407     }
4408 
4409   BFD_ASSERT (ext_rel - (Elf64_Mips_External_Rel *) rel_hdr->contents
4410 	      == *count);
4411 }
4412 
4413 static void
mips_elf64_write_rela(bfd * abfd,asection * sec,Elf_Internal_Shdr * rela_hdr,int * count,void * data)4414 mips_elf64_write_rela (bfd *abfd, asection *sec,
4415 		       Elf_Internal_Shdr *rela_hdr,
4416 		       int *count, void *data)
4417 {
4418   bool *failedp = data;
4419   Elf64_Mips_External_Rela *ext_rela;
4420   unsigned int idx;
4421   asymbol *last_sym = 0;
4422   int last_sym_idx = 0;
4423 
4424   rela_hdr->sh_size = rela_hdr->sh_entsize * *count;
4425   rela_hdr->contents = bfd_alloc (abfd, rela_hdr->sh_size);
4426   if (rela_hdr->contents == NULL)
4427     {
4428       *failedp = true;
4429       return;
4430     }
4431 
4432   ext_rela = (Elf64_Mips_External_Rela *) rela_hdr->contents;
4433   for (idx = 0; idx < sec->reloc_count; idx++, ext_rela++)
4434     {
4435       arelent *ptr;
4436       Elf64_Mips_Internal_Rela int_rela;
4437       asymbol *sym;
4438       int n;
4439       unsigned int i;
4440 
4441       ptr = sec->orelocation[idx];
4442 
4443       /* The address of an ELF reloc is section relative for an object
4444 	 file, and absolute for an executable file or shared library.
4445 	 The address of a BFD reloc is always section relative.  */
4446       if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
4447 	int_rela.r_offset = ptr->address;
4448       else
4449 	int_rela.r_offset = ptr->address + sec->vma;
4450 
4451       sym = *ptr->sym_ptr_ptr;
4452       if (sym == last_sym)
4453 	n = last_sym_idx;
4454       else if (bfd_is_abs_section (sym->section) && sym->value == 0)
4455 	n = STN_UNDEF;
4456       else
4457 	{
4458 	  last_sym = sym;
4459 	  n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
4460 	  if (n < 0)
4461 	    {
4462 	      *failedp = true;
4463 	      return;
4464 	    }
4465 	  last_sym_idx = n;
4466 	}
4467 
4468       int_rela.r_sym = n;
4469       int_rela.r_addend = ptr->addend;
4470       int_rela.r_ssym = RSS_UNDEF;
4471 
4472       if ((*ptr->sym_ptr_ptr)->the_bfd != NULL
4473 	  && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
4474 	  && ! _bfd_elf_validate_reloc (abfd, ptr))
4475 	{
4476 	  *failedp = true;
4477 	  return;
4478 	}
4479 
4480       int_rela.r_type = ptr->howto->type;
4481       int_rela.r_type2 = (int) R_MIPS_NONE;
4482       int_rela.r_type3 = (int) R_MIPS_NONE;
4483 
4484       for (i = 0; i < 2; i++)
4485 	{
4486 	  arelent *r;
4487 
4488 	  if (idx + 1 >= sec->reloc_count)
4489 	    break;
4490 	  r = sec->orelocation[idx + 1];
4491 	  if (r->address != ptr->address
4492 	      || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
4493 	      || (*r->sym_ptr_ptr)->value != 0)
4494 	    break;
4495 
4496 	  /* We can merge the reloc at IDX + 1 with the reloc at IDX.  */
4497 
4498 	  if (i == 0)
4499 	    int_rela.r_type2 = r->howto->type;
4500 	  else
4501 	    int_rela.r_type3 = r->howto->type;
4502 
4503 	  ++idx;
4504 	}
4505 
4506       mips_elf64_swap_reloca_out (abfd, &int_rela, ext_rela);
4507     }
4508 
4509   BFD_ASSERT (ext_rela - (Elf64_Mips_External_Rela *) rela_hdr->contents
4510 	      == *count);
4511 }
4512 
4513 /* Set the right machine number for a MIPS ELF file.  */
4514 
4515 static bool
mips_elf64_object_p(bfd * abfd)4516 mips_elf64_object_p (bfd *abfd)
4517 {
4518   unsigned long mach;
4519 
4520   /* Irix 6 is broken.  Object file symbol tables are not always
4521      sorted correctly such that local symbols precede global symbols,
4522      and the sh_info field in the symbol table is not always right.  */
4523   if (elf64_mips_irix_compat (abfd) != ict_none)
4524     elf_bad_symtab (abfd) = true;
4525 
4526   mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
4527   bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
4528   return true;
4529 }
4530 
4531 /* MIPS ELF local labels start with "$L".  */
4532 static bool
mips_elf64_is_local_label_name(bfd * abfd,const char * name)4533 mips_elf64_is_local_label_name (bfd *abfd, const char *name)
4534 {
4535   if (name[0] == '$' && name[1] == 'L')
4536     return true;
4537 
4538   /* We accept the generic ELF local label syntax as well.  */
4539   return _bfd_elf_is_local_label_name (abfd, name);
4540 }
4541 
4542 /* Depending on the target vector we generate some version of Irix
4543    executables or "normal" MIPS ELF ABI executables.  */
4544 static irix_compat_t
elf64_mips_irix_compat(bfd * abfd)4545 elf64_mips_irix_compat (bfd *abfd)
4546 {
4547   if ((abfd->xvec == &mips_elf64_be_vec)
4548       || (abfd->xvec == &mips_elf64_le_vec))
4549     return ict_irix6;
4550   else
4551     return ict_none;
4552 }
4553 
4554 /* Support for core dump NOTE sections.  */
4555 static bool
elf64_mips_grok_prstatus(bfd * abfd,Elf_Internal_Note * note)4556 elf64_mips_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
4557 {
4558   int offset;
4559   unsigned int size;
4560 
4561   switch (note->descsz)
4562     {
4563       default:
4564 	return false;
4565 
4566       case 480:		/* Linux/MIPS - N64 kernel */
4567 	/* pr_cursig */
4568 	elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
4569 
4570 	/* pr_pid */
4571 	elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32);
4572 
4573 	/* pr_reg */
4574 	offset = 112;
4575 	size = 360;
4576 
4577 	break;
4578     }
4579 
4580   /* Make a ".reg/999" section.  */
4581   return _bfd_elfcore_make_pseudosection (abfd, ".reg",
4582 					  size, note->descpos + offset);
4583 }
4584 
4585 static bool
elf64_mips_grok_psinfo(bfd * abfd,Elf_Internal_Note * note)4586 elf64_mips_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
4587 {
4588   switch (note->descsz)
4589     {
4590       default:
4591 	return false;
4592 
4593       case 136:		/* Linux/MIPS - N64 kernel elf_prpsinfo */
4594 	elf_tdata (abfd)->core->pid
4595 	 = bfd_get_32 (abfd, note->descdata + 24);
4596 	elf_tdata (abfd)->core->program
4597 	 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
4598 	elf_tdata (abfd)->core->command
4599 	 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
4600     }
4601 
4602   /* Note that for some reason, a spurious space is tacked
4603      onto the end of the args in some (at least one anyway)
4604      implementations, so strip it off if it exists.  */
4605 
4606   {
4607     char *command = elf_tdata (abfd)->core->command;
4608     int n = strlen (command);
4609 
4610     if (0 < n && command[n - 1] == ' ')
4611       command[n - 1] = '\0';
4612   }
4613 
4614   return true;
4615 }
4616 
4617 /* Write Linux core PRSTATUS note into core file.  */
4618 
4619 static char *
elf64_mips_write_core_note(bfd * abfd,char * buf,int * bufsiz,int note_type,...)4620 elf64_mips_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type,
4621 			     ...)
4622 {
4623   switch (note_type)
4624     {
4625     default:
4626       return NULL;
4627 
4628     case NT_PRPSINFO:
4629       BFD_FAIL ();
4630       return NULL;
4631 
4632     case NT_PRSTATUS:
4633       {
4634 	char data[480];
4635 	va_list ap;
4636 	long pid;
4637 	int cursig;
4638 	const void *greg;
4639 
4640 	va_start (ap, note_type);
4641 	memset (data, 0, 112);
4642 	pid = va_arg (ap, long);
4643 	bfd_put_32 (abfd, pid, data + 32);
4644 	cursig = va_arg (ap, int);
4645 	bfd_put_16 (abfd, cursig, data + 12);
4646 	greg = va_arg (ap, const void *);
4647 	memcpy (data + 112, greg, 360);
4648 	memset (data + 472, 0, 8);
4649 	va_end (ap);
4650 	return elfcore_write_note (abfd, buf, bufsiz,
4651 				   "CORE", note_type, data, sizeof (data));
4652       }
4653     }
4654 }
4655 
4656 /* ECOFF swapping routines.  These are used when dealing with the
4657    .mdebug section, which is in the ECOFF debugging format.  */
4658 static const struct ecoff_debug_swap mips_elf64_ecoff_debug_swap =
4659 {
4660   /* Symbol table magic number.  */
4661   magicSym2,
4662   /* Alignment of debugging information.  E.g., 4.  */
4663   8,
4664   /* Sizes of external symbolic information.  */
4665   sizeof (struct hdr_ext),
4666   sizeof (struct dnr_ext),
4667   sizeof (struct pdr_ext),
4668   sizeof (struct sym_ext),
4669   sizeof (struct opt_ext),
4670   sizeof (struct fdr_ext),
4671   sizeof (struct rfd_ext),
4672   sizeof (struct ext_ext),
4673   /* Functions to swap in external symbolic data.  */
4674   ecoff_swap_hdr_in,
4675   ecoff_swap_dnr_in,
4676   ecoff_swap_pdr_in,
4677   ecoff_swap_sym_in,
4678   ecoff_swap_opt_in,
4679   ecoff_swap_fdr_in,
4680   ecoff_swap_rfd_in,
4681   ecoff_swap_ext_in,
4682   _bfd_ecoff_swap_tir_in,
4683   _bfd_ecoff_swap_rndx_in,
4684   /* Functions to swap out external symbolic data.  */
4685   ecoff_swap_hdr_out,
4686   ecoff_swap_dnr_out,
4687   ecoff_swap_pdr_out,
4688   ecoff_swap_sym_out,
4689   ecoff_swap_opt_out,
4690   ecoff_swap_fdr_out,
4691   ecoff_swap_rfd_out,
4692   ecoff_swap_ext_out,
4693   _bfd_ecoff_swap_tir_out,
4694   _bfd_ecoff_swap_rndx_out,
4695   /* Function to read in symbolic data.  */
4696   _bfd_mips_elf_read_ecoff_info
4697 };
4698 
4699 /* Relocations in the 64 bit MIPS ELF ABI are more complex than in
4700    standard ELF.  This structure is used to redirect the relocation
4701    handling routines.  */
4702 
4703 const struct elf_size_info mips_elf64_size_info =
4704 {
4705   sizeof (Elf64_External_Ehdr),
4706   sizeof (Elf64_External_Phdr),
4707   sizeof (Elf64_External_Shdr),
4708   sizeof (Elf64_Mips_External_Rel),
4709   sizeof (Elf64_Mips_External_Rela),
4710   sizeof (Elf64_External_Sym),
4711   sizeof (Elf64_External_Dyn),
4712   sizeof (Elf_External_Note),
4713   4,		/* hash-table entry size */
4714   3,		/* internal relocations per external relocations */
4715   64,		/* arch_size */
4716   3,		/* log_file_align */
4717   ELFCLASS64,
4718   EV_CURRENT,
4719   bfd_elf64_write_out_phdrs,
4720   bfd_elf64_write_shdrs_and_ehdr,
4721   bfd_elf64_checksum_contents,
4722   mips_elf64_write_relocs,
4723   bfd_elf64_swap_symbol_in,
4724   bfd_elf64_swap_symbol_out,
4725   mips_elf64_slurp_reloc_table,
4726   bfd_elf64_slurp_symbol_table,
4727   bfd_elf64_swap_dyn_in,
4728   bfd_elf64_swap_dyn_out,
4729   mips_elf64_be_swap_reloc_in,
4730   mips_elf64_be_swap_reloc_out,
4731   mips_elf64_be_swap_reloca_in,
4732   mips_elf64_be_swap_reloca_out
4733 };
4734 
4735 #define ELF_ARCH			bfd_arch_mips
4736 #define ELF_TARGET_ID			MIPS_ELF_DATA
4737 #define ELF_MACHINE_CODE		EM_MIPS
4738 
4739 #define elf_backend_collect		true
4740 #define elf_backend_type_change_ok	true
4741 #define elf_backend_can_gc_sections	true
4742 #define elf_backend_gc_mark_extra_sections \
4743 					_bfd_mips_elf_gc_mark_extra_sections
4744 #define elf_info_to_howto		mips_elf64_info_to_howto_rela
4745 #define elf_info_to_howto_rel		mips_elf64_info_to_howto_rela
4746 #define elf_backend_object_p		mips_elf64_object_p
4747 #define elf_backend_symbol_processing	_bfd_mips_elf_symbol_processing
4748 #define elf_backend_section_processing	_bfd_mips_elf_section_processing
4749 #define elf_backend_section_from_shdr	_bfd_mips_elf_section_from_shdr
4750 #define elf_backend_fake_sections	_bfd_mips_elf_fake_sections
4751 #define elf_backend_section_from_bfd_section \
4752 				_bfd_mips_elf_section_from_bfd_section
4753 #define elf_backend_add_symbol_hook	_bfd_mips_elf_add_symbol_hook
4754 #define elf_backend_link_output_symbol_hook \
4755 				_bfd_mips_elf_link_output_symbol_hook
4756 #define elf_backend_create_dynamic_sections \
4757 				_bfd_mips_elf_create_dynamic_sections
4758 #define elf_backend_check_relocs	_bfd_mips_elf_check_relocs
4759 #define elf_backend_merge_symbol_attribute \
4760 				_bfd_mips_elf_merge_symbol_attribute
4761 #define elf_backend_get_target_dtag	_bfd_mips_elf_get_target_dtag
4762 #define elf_backend_adjust_dynamic_symbol \
4763 				_bfd_mips_elf_adjust_dynamic_symbol
4764 #define elf_backend_always_size_sections \
4765 				_bfd_mips_elf_always_size_sections
4766 #define elf_backend_size_dynamic_sections \
4767 				_bfd_mips_elf_size_dynamic_sections
4768 #define elf_backend_init_index_section	_bfd_elf_init_1_index_section
4769 #define elf_backend_relocate_section    _bfd_mips_elf_relocate_section
4770 #define elf_backend_finish_dynamic_symbol \
4771 				_bfd_mips_elf_finish_dynamic_symbol
4772 #define elf_backend_finish_dynamic_sections \
4773 				_bfd_mips_elf_finish_dynamic_sections
4774 #define elf_backend_final_write_processing \
4775 				_bfd_mips_elf_final_write_processing
4776 #define elf_backend_additional_program_headers \
4777 				_bfd_mips_elf_additional_program_headers
4778 #define elf_backend_modify_segment_map	_bfd_mips_elf_modify_segment_map
4779 #define elf_backend_gc_mark_hook	_bfd_mips_elf_gc_mark_hook
4780 #define elf_backend_copy_indirect_symbol \
4781 					_bfd_mips_elf_copy_indirect_symbol
4782 #define elf_backend_hide_symbol		_bfd_mips_elf_hide_symbol
4783 #define elf_backend_ignore_discarded_relocs \
4784 					_bfd_mips_elf_ignore_discarded_relocs
4785 #define elf_backend_mips_irix_compat	elf64_mips_irix_compat
4786 #define elf_backend_mips_rtype_to_howto	mips_elf64_rtype_to_howto
4787 #define elf_backend_ecoff_debug_swap	&mips_elf64_ecoff_debug_swap
4788 #define elf_backend_size_info		mips_elf64_size_info
4789 
4790 #define elf_backend_grok_prstatus	elf64_mips_grok_prstatus
4791 #define elf_backend_grok_psinfo		elf64_mips_grok_psinfo
4792 
4793 #define elf_backend_got_header_size	(8 * MIPS_RESERVED_GOTNO)
4794 #define elf_backend_want_dynrelro	1
4795 
4796 /* MIPS ELF64 can use a mixture of REL and RELA, but some Relocations
4797    work better/work only in RELA, so we default to this.  */
4798 #define elf_backend_may_use_rel_p	1
4799 #define elf_backend_may_use_rela_p	1
4800 #define elf_backend_default_use_rela_p	1
4801 #define elf_backend_rela_plts_and_copies_p 0
4802 #define elf_backend_plt_readonly	1
4803 #define elf_backend_plt_sym_val		_bfd_mips_elf_plt_sym_val
4804 
4805 #define elf_backend_sign_extend_vma	true
4806 
4807 #define elf_backend_write_section	_bfd_mips_elf_write_section
4808 #define elf_backend_sort_relocs_p	_bfd_mips_elf_sort_relocs_p
4809 
4810 #define bfd_elf64_bfd_is_local_label_name \
4811 					mips_elf64_is_local_label_name
4812 #define bfd_elf64_bfd_is_target_special_symbol \
4813 					_bfd_mips_elf_is_target_special_symbol
4814 #define bfd_elf64_find_nearest_line	_bfd_mips_elf_find_nearest_line
4815 #define bfd_elf64_find_nearest_line_with_alt \
4816 				_bfd_mips_elf_find_nearest_line_with_alt
4817 #define bfd_elf64_find_inliner_info	_bfd_mips_elf_find_inliner_info
4818 #define bfd_elf64_new_section_hook	_bfd_mips_elf_new_section_hook
4819 #define bfd_elf64_set_section_contents	_bfd_mips_elf_set_section_contents
4820 #define bfd_elf64_bfd_get_relocated_section_contents \
4821 				_bfd_elf_mips_get_relocated_section_contents
4822 #define bfd_elf64_bfd_link_hash_table_create \
4823 				_bfd_mips_elf_link_hash_table_create
4824 #define bfd_elf64_bfd_final_link	_bfd_mips_elf_final_link
4825 #define bfd_elf64_bfd_merge_private_bfd_data \
4826 				_bfd_mips_elf_merge_private_bfd_data
4827 #define bfd_elf64_bfd_set_private_flags	_bfd_mips_elf_set_private_flags
4828 #define bfd_elf64_bfd_print_private_bfd_data \
4829 				_bfd_mips_elf_print_private_bfd_data
4830 
4831 #define bfd_elf64_get_dynamic_reloc_upper_bound mips_elf64_get_dynamic_reloc_upper_bound
4832 #define bfd_elf64_mkobject		_bfd_mips_elf_mkobject
4833 #define bfd_elf64_bfd_free_cached_info	_bfd_mips_elf_free_cached_info
4834 
4835 /* The SGI style (n)64 NewABI.  */
4836 #define TARGET_LITTLE_SYM		mips_elf64_le_vec
4837 #define TARGET_LITTLE_NAME		"elf64-littlemips"
4838 #define TARGET_BIG_SYM			mips_elf64_be_vec
4839 #define TARGET_BIG_NAME			"elf64-bigmips"
4840 
4841 #define ELF_MAXPAGESIZE			0x10000
4842 #define ELF_COMMONPAGESIZE		0x1000
4843 
4844 #include "elf64-target.h"
4845 
4846 /* The SYSV-style 'traditional' (n)64 NewABI.  */
4847 #undef TARGET_LITTLE_SYM
4848 #undef TARGET_LITTLE_NAME
4849 #undef TARGET_BIG_SYM
4850 #undef TARGET_BIG_NAME
4851 
4852 #undef ELF_MAXPAGESIZE
4853 #undef ELF_COMMONPAGESIZE
4854 
4855 #define TARGET_LITTLE_SYM		mips_elf64_trad_le_vec
4856 #define TARGET_LITTLE_NAME		"elf64-tradlittlemips"
4857 #define TARGET_BIG_SYM			mips_elf64_trad_be_vec
4858 #define TARGET_BIG_NAME			"elf64-tradbigmips"
4859 
4860 #define ELF_MAXPAGESIZE			0x10000
4861 #define ELF_COMMONPAGESIZE		0x1000
4862 #define elf64_bed			elf64_tradbed
4863 
4864 #undef elf_backend_write_core_note
4865 #define elf_backend_write_core_note	elf64_mips_write_core_note
4866 
4867 /* Include the target file again for this target.  */
4868 #include "elf64-target.h"
4869 
4870 
4871 /* FreeBSD support.  */
4872 
4873 #undef TARGET_LITTLE_SYM
4874 #undef TARGET_LITTLE_NAME
4875 #undef TARGET_BIG_SYM
4876 #undef TARGET_BIG_NAME
4877 
4878 #define	TARGET_LITTLE_SYM		mips_elf64_tradfbsd_le_vec
4879 #define	TARGET_LITTLE_NAME		"elf64-tradlittlemips-freebsd"
4880 #define	TARGET_BIG_SYM			mips_elf64_tradfbsd_be_vec
4881 #define	TARGET_BIG_NAME			"elf64-tradbigmips-freebsd"
4882 
4883 #undef	ELF_OSABI
4884 #define	ELF_OSABI			ELFOSABI_FREEBSD
4885 
4886 #undef	elf64_bed
4887 #define elf64_bed				elf64_fbsd_tradbed
4888 
4889 #undef elf64_mips_write_core_note
4890 
4891 #include "elf64-target.h"
4892