1/* MIPS-specific support for 64-bit ELF
2   Copyright (C) 1996-2020 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
65static void mips_elf64_swap_reloc_in
66  (bfd *, const Elf64_Mips_External_Rel *, Elf64_Mips_Internal_Rela *);
67static void mips_elf64_swap_reloca_in
68  (bfd *, const Elf64_Mips_External_Rela *, Elf64_Mips_Internal_Rela *);
69static void mips_elf64_swap_reloc_out
70  (bfd *, const Elf64_Mips_Internal_Rela *, Elf64_Mips_External_Rel *);
71static void mips_elf64_swap_reloca_out
72  (bfd *, const Elf64_Mips_Internal_Rela *, Elf64_Mips_External_Rela *);
73static void mips_elf64_be_swap_reloc_in
74  (bfd *, const bfd_byte *, Elf_Internal_Rela *);
75static void mips_elf64_be_swap_reloc_out
76  (bfd *, const Elf_Internal_Rela *, bfd_byte *);
77static void mips_elf64_be_swap_reloca_in
78  (bfd *, const bfd_byte *, Elf_Internal_Rela *);
79static void mips_elf64_be_swap_reloca_out
80  (bfd *, const Elf_Internal_Rela *, bfd_byte *);
81static reloc_howto_type *bfd_elf64_bfd_reloc_type_lookup
82  (bfd *, bfd_reloc_code_real_type);
83static bfd_boolean mips_elf64_info_to_howto_rela
84  (bfd *, arelent *, Elf_Internal_Rela *);
85static long mips_elf64_get_dynamic_reloc_upper_bound
86  (bfd *);
87static bfd_boolean mips_elf64_slurp_one_reloc_table
88  (bfd *, asection *, Elf_Internal_Shdr *, bfd_size_type, arelent *,
89   asymbol **, bfd_boolean);
90static bfd_boolean mips_elf64_slurp_reloc_table
91  (bfd *, asection *, asymbol **, bfd_boolean);
92static void mips_elf64_write_relocs
93  (bfd *, asection *, void *);
94static void mips_elf64_write_rel
95  (bfd *, asection *, Elf_Internal_Shdr *, int *, void *);
96static void mips_elf64_write_rela
97  (bfd *, asection *, Elf_Internal_Shdr *, int *, void *);
98static bfd_reloc_status_type mips_elf64_gprel16_reloc
99  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
100static bfd_reloc_status_type mips_elf64_literal_reloc
101  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
102static bfd_reloc_status_type mips_elf64_gprel32_reloc
103  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
104static bfd_reloc_status_type mips_elf64_shift6_reloc
105  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
106static bfd_reloc_status_type mips16_gprel_reloc
107  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
108static bfd_boolean mips_elf64_assign_gp
109  (bfd *, bfd_vma *);
110static bfd_reloc_status_type mips_elf64_final_gp
111  (bfd *, asymbol *, bfd_boolean, char **, bfd_vma *);
112static bfd_boolean mips_elf64_object_p
113  (bfd *);
114static bfd_boolean mips_elf64_is_local_label_name
115  (bfd *, const char *);
116static irix_compat_t elf64_mips_irix_compat
117  (bfd *);
118static bfd_boolean elf64_mips_grok_prstatus
119  (bfd *, Elf_Internal_Note *);
120static bfd_boolean elf64_mips_grok_psinfo
121  (bfd *, Elf_Internal_Note *);
122
123extern const bfd_target mips_elf64_be_vec;
124extern 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
135static reloc_howto_type mips_elf64_howto_table_rel[] =
136{
137  /* No relocation.  */
138  HOWTO (R_MIPS_NONE,		/* type */
139	 0,			/* rightshift */
140	 3,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
252	 16,			/* bitsize */
253	 FALSE,			/* pc_relative */
254	 0,			/* bitpos */
255	 complain_overflow_signed, /* complain_on_overflow */
256	 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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 4,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 4,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
517	 32,			/* bitsize */
518	 FALSE,			/* pc_relative */
519	 0,			/* bitpos */
520	 complain_overflow_dont, /* complain_on_overflow */
521	 _bfd_mips_elf_generic_reloc,	/* special_function */
522	 "R_MIPS_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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 1,			/* size (0 = byte, 1 = short, 2 = long) */
585	 16,			/* bitsize */
586	 FALSE,			/* pc_relative */
587	 0,			/* bitpos */
588	 complain_overflow_signed, /* complain_on_overflow */
589	 _bfd_mips_elf_generic_reloc,	/* special_function */
590	 "R_MIPS_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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 4,			/* size (0 = byte, 1 = short, 2 = long) */
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	 4,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 4,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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
898static reloc_howto_type mips_elf64_howto_table_rela[] =
899{
900  /* No relocation.  */
901  HOWTO (R_MIPS_NONE,		/* type */
902	 0,			/* rightshift */
903	 3,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 4,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1198	 16,			/* bitsize */
1199	 FALSE,			/* pc_relative */
1200	 0,			/* bitpos */
1201	 complain_overflow_dont, /* complain_on_overflow */
1202	 _bfd_mips_elf_generic_reloc,	/* special_function */
1203	 "R_MIPS_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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 4,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 1,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
1386	 32,			/* bitsize */
1387	 FALSE,			/* pc_relative */
1388	 0,			/* bitpos */
1389	 complain_overflow_dont, /* complain_on_overflow */
1390	 _bfd_mips_elf_generic_reloc,	/* special_function */
1391	 "R_MIPS_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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 4,			/* size (0 = byte, 1 = short, 2 = long) */
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	 4,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 4,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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
1677static 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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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
1893static 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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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
2109static 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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 1,			/* size (0 = byte, 1 = short, 2 = long) */
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	 1,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 4,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 1,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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
2588static 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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 1,			/* size (0 = byte, 1 = short, 2 = long) */
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	 1,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 4,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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	 1,			/* size (0 = byte, 1 = short, 2 = long) */
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	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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 */
3091static reloc_howto_type elf_mips_gnu_vtinherit_howto =
3092  HOWTO (R_MIPS_GNU_VTINHERIT,	/* type */
3093	 0,			/* rightshift */
3094	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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 */
3107static reloc_howto_type elf_mips_gnu_vtentry_howto =
3108  HOWTO (R_MIPS_GNU_VTENTRY,	/* type */
3109	 0,			/* rightshift */
3110	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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.  */
3123static reloc_howto_type elf_mips_gnu_rel16_s2 =
3124  HOWTO (R_MIPS_GNU_REL16_S2,	/* type */
3125	 2,			/* rightshift */
3126	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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.  */
3139static reloc_howto_type elf_mips_gnu_rela16_s2 =
3140  HOWTO (R_MIPS_GNU_REL16_S2,	/* type */
3141	 2,			/* rightshift */
3142	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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.  */
3155static reloc_howto_type elf_mips_gnu_pcrel32 =
3156  HOWTO (R_MIPS_PC32,		/* type */
3157	 0,			/* rightshift */
3158	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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.  */
3172static 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.  */
3188static reloc_howto_type elf_mips_jump_slot_howto =
3189  HOWTO (R_MIPS_JUMP_SLOT,	/* type */
3190	 0,			/* rightshift */
3191	 4,			/* size (0 = byte, 1 = short, 2 = long) */
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.  */
3204static reloc_howto_type elf_mips_eh_howto =
3205  HOWTO (R_MIPS_EH,		/* type */
3206	 0,			/* rightshift */
3207	 2,			/* size (0 = byte, 1 = short, 2 = long) */
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
3222static void
3223mips_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
3237static void
3238mips_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
3252static void
3253mips_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
3266static void
3267mips_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
3281static void
3282mips_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
3304static void
3305mips_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
3327static void
3328mips_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
3349static void
3350mips_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
3376static bfd_boolean
3377mips_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
3428static bfd_reloc_status_type
3429mips_elf64_final_gp (bfd *output_bfd, asymbol *symbol, bfd_boolean relocatable,
3430		     char **error_message, bfd_vma *pgp)
3431{
3432  if (bfd_is_und_section (symbol->section)
3433      && ! relocatable)
3434    {
3435      *pgp = 0;
3436      return bfd_reloc_undefined;
3437    }
3438
3439  *pgp = _bfd_get_gp_value (output_bfd);
3440  if (*pgp == 0
3441      && (! relocatable
3442	  || (symbol->flags & BSF_SECTION_SYM) != 0))
3443    {
3444      if (relocatable)
3445	{
3446	  /* Make up a value.  */
3447	  *pgp = symbol->section->output_section->vma /*+ 0x4000*/;
3448	  _bfd_set_gp_value (output_bfd, *pgp);
3449	}
3450      else if (!mips_elf64_assign_gp (output_bfd, pgp))
3451	{
3452	  *error_message =
3453	    (char *) _("GP relative relocation when _gp not defined");
3454	  return bfd_reloc_dangerous;
3455	}
3456    }
3457
3458  return bfd_reloc_ok;
3459}
3460
3461/* Do a R_MIPS_GPREL16 relocation.  This is a 16 bit value which must
3462   become the offset from the gp register.  */
3463
3464static bfd_reloc_status_type
3465mips_elf64_gprel16_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
3466			  void *data, asection *input_section, bfd *output_bfd,
3467			  char **error_message)
3468{
3469  bfd_boolean relocatable;
3470  bfd_reloc_status_type ret;
3471  bfd_vma gp;
3472
3473  /* If we're relocating, and this is an external symbol, we don't want
3474     to change anything.  */
3475  if (output_bfd != NULL
3476      && (symbol->flags & BSF_SECTION_SYM) == 0
3477      && (symbol->flags & BSF_LOCAL) != 0)
3478    {
3479      reloc_entry->address += input_section->output_offset;
3480      return bfd_reloc_ok;
3481    }
3482
3483  if (output_bfd != NULL)
3484    relocatable = TRUE;
3485  else
3486    {
3487      relocatable = FALSE;
3488      output_bfd = symbol->section->output_section->owner;
3489    }
3490
3491  ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message,
3492			     &gp);
3493  if (ret != bfd_reloc_ok)
3494    return ret;
3495
3496  return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
3497					input_section, relocatable,
3498					data, gp);
3499}
3500
3501/* Do a R_MIPS_LITERAL relocation.  */
3502
3503static bfd_reloc_status_type
3504mips_elf64_literal_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
3505			  void *data, asection *input_section, bfd *output_bfd,
3506			  char **error_message)
3507{
3508  bfd_boolean relocatable;
3509  bfd_reloc_status_type ret;
3510  bfd_vma gp;
3511
3512  /* R_MIPS_LITERAL relocations are defined for local symbols only.  */
3513  if (output_bfd != NULL
3514      && (symbol->flags & BSF_SECTION_SYM) == 0
3515      && (symbol->flags & BSF_LOCAL) != 0)
3516    {
3517      *error_message = (char *)
3518	_("literal relocation occurs for an external symbol");
3519      return bfd_reloc_outofrange;
3520    }
3521
3522  /* FIXME: The entries in the .lit8 and .lit4 sections should be merged.  */
3523  if (output_bfd != NULL)
3524    relocatable = TRUE;
3525  else
3526    {
3527      relocatable = FALSE;
3528      output_bfd = symbol->section->output_section->owner;
3529    }
3530
3531  ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message,
3532			     &gp);
3533  if (ret != bfd_reloc_ok)
3534    return ret;
3535
3536  return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
3537					input_section, relocatable,
3538					data, gp);
3539}
3540
3541/* Do a R_MIPS_GPREL32 relocation.  This is a 32 bit value which must
3542   become the offset from the gp register.  */
3543
3544static bfd_reloc_status_type
3545mips_elf64_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
3546			  void *data, asection *input_section, bfd *output_bfd,
3547			  char **error_message)
3548{
3549  bfd_boolean relocatable;
3550  bfd_reloc_status_type ret;
3551  bfd_vma gp;
3552  bfd_vma relocation;
3553  bfd_vma val;
3554
3555  /* R_MIPS_GPREL32 relocations are defined for local symbols only.  */
3556  if (output_bfd != NULL
3557      && (symbol->flags & BSF_SECTION_SYM) == 0
3558      && (symbol->flags & BSF_LOCAL) != 0)
3559    {
3560      *error_message = (char *)
3561	_("32bits gp relative relocation occurs for an external symbol");
3562      return bfd_reloc_outofrange;
3563    }
3564
3565  if (output_bfd != NULL)
3566    relocatable = TRUE;
3567  else
3568    {
3569      relocatable = FALSE;
3570      output_bfd = symbol->section->output_section->owner;
3571    }
3572
3573  ret = mips_elf64_final_gp (output_bfd, symbol, relocatable,
3574			     error_message, &gp);
3575  if (ret != bfd_reloc_ok)
3576    return ret;
3577
3578  if (bfd_is_com_section (symbol->section))
3579    relocation = 0;
3580  else
3581    relocation = symbol->value;
3582
3583  relocation += symbol->section->output_section->vma;
3584  relocation += symbol->section->output_offset;
3585
3586  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
3587    return bfd_reloc_outofrange;
3588
3589  /* Set val to the offset into the section or symbol.  */
3590  val = reloc_entry->addend;
3591
3592  if (reloc_entry->howto->partial_inplace)
3593    val += bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
3594
3595  /* Adjust val for the final section location and GP value.  If we
3596     are producing relocatable output, we don't want to do this for
3597     an external symbol.  */
3598  if (! relocatable
3599      || (symbol->flags & BSF_SECTION_SYM) != 0)
3600    val += relocation - gp;
3601
3602  if (reloc_entry->howto->partial_inplace)
3603    bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
3604  else
3605    reloc_entry->addend = val;
3606
3607  if (relocatable)
3608    reloc_entry->address += input_section->output_offset;
3609
3610  return bfd_reloc_ok;
3611}
3612
3613/* Do a R_MIPS_SHIFT6 relocation. The MSB of the shift is stored at bit 2,
3614   the rest is at bits 6-10. The bitpos already got right by the howto.  */
3615
3616static bfd_reloc_status_type
3617mips_elf64_shift6_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
3618			 void *data, asection *input_section, bfd *output_bfd,
3619			 char **error_message)
3620{
3621  if (reloc_entry->howto->partial_inplace)
3622    {
3623      reloc_entry->addend = ((reloc_entry->addend & 0x00007c0)
3624			     | (reloc_entry->addend & 0x00000800) >> 9);
3625    }
3626
3627  return _bfd_mips_elf_generic_reloc (abfd, reloc_entry, symbol, data,
3628				      input_section, output_bfd,
3629				      error_message);
3630}
3631
3632/* Handle a mips16 GP relative reloc.  */
3633
3634static bfd_reloc_status_type
3635mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
3636		    void *data, asection *input_section, bfd *output_bfd,
3637		    char **error_message)
3638{
3639  bfd_boolean relocatable;
3640  bfd_reloc_status_type ret;
3641  bfd_byte *location;
3642  bfd_vma gp;
3643
3644  /* If we're relocating, and this is an external symbol, we don't want
3645     to change anything.  */
3646  if (output_bfd != NULL
3647      && (symbol->flags & BSF_SECTION_SYM) == 0
3648      && (symbol->flags & BSF_LOCAL) != 0)
3649    {
3650      reloc_entry->address += input_section->output_offset;
3651      return bfd_reloc_ok;
3652    }
3653
3654  if (output_bfd != NULL)
3655    relocatable = TRUE;
3656  else
3657    {
3658      relocatable = FALSE;
3659      output_bfd = symbol->section->output_section->owner;
3660    }
3661
3662  ret = mips_elf64_final_gp (output_bfd, symbol, relocatable, error_message,
3663			     &gp);
3664  if (ret != bfd_reloc_ok)
3665    return ret;
3666
3667  location = (bfd_byte *) data + reloc_entry->address;
3668  _bfd_mips_elf_reloc_unshuffle (abfd, reloc_entry->howto->type, FALSE,
3669				 location);
3670  ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
3671				       input_section, relocatable,
3672				       data, gp);
3673  _bfd_mips_elf_reloc_shuffle (abfd, reloc_entry->howto->type, !relocatable,
3674			       location);
3675
3676  return ret;
3677}
3678
3679/* A mapping from BFD reloc types to MIPS ELF reloc types.  */
3680
3681struct elf_reloc_map {
3682  bfd_reloc_code_real_type bfd_val;
3683  enum elf_mips_reloc_type elf_val;
3684};
3685
3686static const struct elf_reloc_map mips_reloc_map[] =
3687{
3688  { BFD_RELOC_NONE, R_MIPS_NONE },
3689  { BFD_RELOC_16, R_MIPS_16 },
3690  { BFD_RELOC_32, R_MIPS_32 },
3691  /* There is no BFD reloc for R_MIPS_REL32.  */
3692  { BFD_RELOC_64, R_MIPS_64 },
3693  { BFD_RELOC_CTOR, R_MIPS_64 },
3694  { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
3695  { BFD_RELOC_HI16_S, R_MIPS_HI16 },
3696  { BFD_RELOC_LO16, R_MIPS_LO16 },
3697  { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
3698  { BFD_RELOC_GPREL32, R_MIPS_GPREL32 },
3699  { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
3700  { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
3701  { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
3702  { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
3703  { BFD_RELOC_MIPS_SHIFT5, R_MIPS_SHIFT5 },
3704  { BFD_RELOC_MIPS_SHIFT6, R_MIPS_SHIFT6 },
3705  { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP },
3706  { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
3707  { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
3708  { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
3709  { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
3710  { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
3711  { BFD_RELOC_MIPS_INSERT_A, R_MIPS_INSERT_A },
3712  { BFD_RELOC_MIPS_INSERT_B, R_MIPS_INSERT_B },
3713  { BFD_RELOC_MIPS_DELETE, R_MIPS_DELETE },
3714  { BFD_RELOC_MIPS_HIGHEST, R_MIPS_HIGHEST },
3715  { BFD_RELOC_MIPS_HIGHER, R_MIPS_HIGHER },
3716  { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
3717  { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
3718  { BFD_RELOC_MIPS_SCN_DISP, R_MIPS_SCN_DISP },
3719  { BFD_RELOC_MIPS_REL16, R_MIPS_REL16 },
3720  /* Use of R_MIPS_ADD_IMMEDIATE and R_MIPS_PJUMP is deprecated.  */
3721  { BFD_RELOC_MIPS_RELGOT, R_MIPS_RELGOT },
3722  { BFD_RELOC_MIPS_JALR, R_MIPS_JALR },
3723  { BFD_RELOC_MIPS_TLS_DTPMOD32, R_MIPS_TLS_DTPMOD32 },
3724  { BFD_RELOC_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL32 },
3725  { BFD_RELOC_MIPS_TLS_DTPMOD64, R_MIPS_TLS_DTPMOD64 },
3726  { BFD_RELOC_MIPS_TLS_DTPREL64, R_MIPS_TLS_DTPREL64 },
3727  { BFD_RELOC_MIPS_TLS_GD, R_MIPS_TLS_GD },
3728  { BFD_RELOC_MIPS_TLS_LDM, R_MIPS_TLS_LDM },
3729  { BFD_RELOC_MIPS_TLS_DTPREL_HI16, R_MIPS_TLS_DTPREL_HI16 },
3730  { BFD_RELOC_MIPS_TLS_DTPREL_LO16, R_MIPS_TLS_DTPREL_LO16 },
3731  { BFD_RELOC_MIPS_TLS_GOTTPREL, R_MIPS_TLS_GOTTPREL },
3732  { BFD_RELOC_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL32 },
3733  { BFD_RELOC_MIPS_TLS_TPREL64, R_MIPS_TLS_TPREL64 },
3734  { BFD_RELOC_MIPS_TLS_TPREL_HI16, R_MIPS_TLS_TPREL_HI16 },
3735  { BFD_RELOC_MIPS_TLS_TPREL_LO16, R_MIPS_TLS_TPREL_LO16 },
3736  { BFD_RELOC_MIPS_21_PCREL_S2, R_MIPS_PC21_S2 },
3737  { BFD_RELOC_MIPS_26_PCREL_S2, R_MIPS_PC26_S2 },
3738  { BFD_RELOC_MIPS_18_PCREL_S3, R_MIPS_PC18_S3 },
3739  { BFD_RELOC_MIPS_19_PCREL_S2, R_MIPS_PC19_S2 },
3740  { BFD_RELOC_HI16_S_PCREL, R_MIPS_PCHI16 },
3741  { BFD_RELOC_LO16_PCREL, R_MIPS_PCLO16 }
3742};
3743
3744static const struct elf_reloc_map mips16_reloc_map[] =
3745{
3746  { BFD_RELOC_MIPS16_JMP, R_MIPS16_26 - R_MIPS16_min },
3747  { BFD_RELOC_MIPS16_GPREL, R_MIPS16_GPREL - R_MIPS16_min },
3748  { BFD_RELOC_MIPS16_GOT16, R_MIPS16_GOT16 - R_MIPS16_min },
3749  { BFD_RELOC_MIPS16_CALL16, R_MIPS16_CALL16 - R_MIPS16_min },
3750  { BFD_RELOC_MIPS16_HI16_S, R_MIPS16_HI16 - R_MIPS16_min },
3751  { BFD_RELOC_MIPS16_LO16, R_MIPS16_LO16 - R_MIPS16_min },
3752  { BFD_RELOC_MIPS16_TLS_GD, R_MIPS16_TLS_GD - R_MIPS16_min },
3753  { BFD_RELOC_MIPS16_TLS_LDM, R_MIPS16_TLS_LDM - R_MIPS16_min },
3754  { BFD_RELOC_MIPS16_TLS_DTPREL_HI16,
3755    R_MIPS16_TLS_DTPREL_HI16 - R_MIPS16_min },
3756  { BFD_RELOC_MIPS16_TLS_DTPREL_LO16,
3757    R_MIPS16_TLS_DTPREL_LO16 - R_MIPS16_min },
3758  { BFD_RELOC_MIPS16_TLS_GOTTPREL, R_MIPS16_TLS_GOTTPREL - R_MIPS16_min },
3759  { BFD_RELOC_MIPS16_TLS_TPREL_HI16, R_MIPS16_TLS_TPREL_HI16 - R_MIPS16_min },
3760  { BFD_RELOC_MIPS16_TLS_TPREL_LO16, R_MIPS16_TLS_TPREL_LO16 - R_MIPS16_min },
3761  { BFD_RELOC_MIPS16_16_PCREL_S1, R_MIPS16_PC16_S1 - R_MIPS16_min }
3762};
3763
3764static const struct elf_reloc_map micromips_reloc_map[] =
3765{
3766  { BFD_RELOC_MICROMIPS_JMP, R_MICROMIPS_26_S1 - R_MICROMIPS_min },
3767  { BFD_RELOC_MICROMIPS_HI16_S, R_MICROMIPS_HI16 - R_MICROMIPS_min },
3768  { BFD_RELOC_MICROMIPS_LO16, R_MICROMIPS_LO16 - R_MICROMIPS_min },
3769  { BFD_RELOC_MICROMIPS_GPREL16, R_MICROMIPS_GPREL16 - R_MICROMIPS_min },
3770  { BFD_RELOC_MICROMIPS_LITERAL, R_MICROMIPS_LITERAL - R_MICROMIPS_min },
3771  { BFD_RELOC_MICROMIPS_GOT16, R_MICROMIPS_GOT16 - R_MICROMIPS_min },
3772  { BFD_RELOC_MICROMIPS_7_PCREL_S1, R_MICROMIPS_PC7_S1 - R_MICROMIPS_min },
3773  { BFD_RELOC_MICROMIPS_10_PCREL_S1, R_MICROMIPS_PC10_S1 - R_MICROMIPS_min },
3774  { BFD_RELOC_MICROMIPS_16_PCREL_S1, R_MICROMIPS_PC16_S1 - R_MICROMIPS_min },
3775  { BFD_RELOC_MICROMIPS_CALL16, R_MICROMIPS_CALL16 - R_MICROMIPS_min },
3776  { BFD_RELOC_MICROMIPS_GOT_DISP, R_MICROMIPS_GOT_DISP - R_MICROMIPS_min },
3777  { BFD_RELOC_MICROMIPS_GOT_PAGE, R_MICROMIPS_GOT_PAGE - R_MICROMIPS_min },
3778  { BFD_RELOC_MICROMIPS_GOT_OFST, R_MICROMIPS_GOT_OFST - R_MICROMIPS_min },
3779  { BFD_RELOC_MICROMIPS_GOT_HI16, R_MICROMIPS_GOT_HI16 - R_MICROMIPS_min },
3780  { BFD_RELOC_MICROMIPS_GOT_LO16, R_MICROMIPS_GOT_LO16 - R_MICROMIPS_min },
3781  { BFD_RELOC_MICROMIPS_SUB, R_MICROMIPS_SUB - R_MICROMIPS_min },
3782  { BFD_RELOC_MICROMIPS_HIGHER, R_MICROMIPS_HIGHER - R_MICROMIPS_min },
3783  { BFD_RELOC_MICROMIPS_HIGHEST, R_MICROMIPS_HIGHEST - R_MICROMIPS_min },
3784  { BFD_RELOC_MICROMIPS_CALL_HI16, R_MICROMIPS_CALL_HI16 - R_MICROMIPS_min },
3785  { BFD_RELOC_MICROMIPS_CALL_LO16, R_MICROMIPS_CALL_LO16 - R_MICROMIPS_min },
3786  { BFD_RELOC_MICROMIPS_SCN_DISP, R_MICROMIPS_SCN_DISP - R_MICROMIPS_min },
3787  { BFD_RELOC_MICROMIPS_JALR, R_MICROMIPS_JALR - R_MICROMIPS_min },
3788  /* There is no BFD reloc for R_MICROMIPS_HI0_LO16.  */
3789  { BFD_RELOC_MICROMIPS_TLS_GD, R_MICROMIPS_TLS_GD - R_MICROMIPS_min },
3790  { BFD_RELOC_MICROMIPS_TLS_LDM, R_MICROMIPS_TLS_LDM - R_MICROMIPS_min },
3791  { BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16,
3792    R_MICROMIPS_TLS_DTPREL_HI16 - R_MICROMIPS_min },
3793  { BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16,
3794    R_MICROMIPS_TLS_DTPREL_LO16 - R_MICROMIPS_min },
3795  { BFD_RELOC_MICROMIPS_TLS_GOTTPREL,
3796    R_MICROMIPS_TLS_GOTTPREL - R_MICROMIPS_min },
3797  { BFD_RELOC_MICROMIPS_TLS_TPREL_HI16,
3798    R_MICROMIPS_TLS_TPREL_HI16 - R_MICROMIPS_min },
3799  { BFD_RELOC_MICROMIPS_TLS_TPREL_LO16,
3800    R_MICROMIPS_TLS_TPREL_LO16 - R_MICROMIPS_min },
3801  /* There is no BFD reloc for R_MICROMIPS_GPREL7_S2.  */
3802  /* There is no BFD reloc for R_MICROMIPS_PC23_S2.  */
3803};
3804/* Given a BFD reloc type, return a howto structure.  */
3805
3806static reloc_howto_type *
3807bfd_elf64_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
3808				 bfd_reloc_code_real_type code)
3809{
3810  unsigned int i;
3811  /* FIXME: We default to RELA here instead of choosing the right
3812     relocation variant.  */
3813  reloc_howto_type *howto_table = mips_elf64_howto_table_rela;
3814  reloc_howto_type *howto16_table = mips16_elf64_howto_table_rela;
3815  reloc_howto_type *howto_micromips_table = micromips_elf64_howto_table_rela;
3816
3817  for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map);
3818       i++)
3819    {
3820      if (mips_reloc_map[i].bfd_val == code)
3821	return &howto_table[(int) mips_reloc_map[i].elf_val];
3822    }
3823
3824  for (i = 0; i < sizeof (mips16_reloc_map) / sizeof (struct elf_reloc_map);
3825       i++)
3826    {
3827      if (mips16_reloc_map[i].bfd_val == code)
3828	return &howto16_table[(int) mips16_reloc_map[i].elf_val];
3829    }
3830
3831  for (i = 0; i < sizeof (micromips_reloc_map) / sizeof (struct elf_reloc_map);
3832       i++)
3833    {
3834      if (micromips_reloc_map[i].bfd_val == code)
3835	return &howto_micromips_table[(int) micromips_reloc_map[i].elf_val];
3836    }
3837
3838  switch (code)
3839    {
3840    case BFD_RELOC_VTABLE_INHERIT:
3841      return &elf_mips_gnu_vtinherit_howto;
3842    case BFD_RELOC_VTABLE_ENTRY:
3843      return &elf_mips_gnu_vtentry_howto;
3844    case BFD_RELOC_32_PCREL:
3845      return &elf_mips_gnu_pcrel32;
3846    case BFD_RELOC_MIPS_EH:
3847      return &elf_mips_eh_howto;
3848    case BFD_RELOC_MIPS_COPY:
3849      return &elf_mips_copy_howto;
3850    case BFD_RELOC_MIPS_JUMP_SLOT:
3851      return &elf_mips_jump_slot_howto;
3852    default:
3853      bfd_set_error (bfd_error_bad_value);
3854      return NULL;
3855    }
3856}
3857
3858static reloc_howto_type *
3859bfd_elf64_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
3860				 const char *r_name)
3861{
3862  unsigned int i;
3863
3864  for (i = 0;
3865       i < (sizeof (mips_elf64_howto_table_rela)
3866	    / sizeof (mips_elf64_howto_table_rela[0])); i++)
3867    if (mips_elf64_howto_table_rela[i].name != NULL
3868	&& strcasecmp (mips_elf64_howto_table_rela[i].name, r_name) == 0)
3869      return &mips_elf64_howto_table_rela[i];
3870
3871  for (i = 0;
3872       i < (sizeof (mips16_elf64_howto_table_rela)
3873	    / sizeof (mips16_elf64_howto_table_rela[0]));
3874       i++)
3875    if (mips16_elf64_howto_table_rela[i].name != NULL
3876	&& strcasecmp (mips16_elf64_howto_table_rela[i].name, r_name) == 0)
3877      return &mips16_elf64_howto_table_rela[i];
3878
3879  for (i = 0;
3880       i < (sizeof (micromips_elf64_howto_table_rela)
3881	    / sizeof (micromips_elf64_howto_table_rela[0]));
3882       i++)
3883    if (micromips_elf64_howto_table_rela[i].name != NULL
3884	&& strcasecmp (micromips_elf64_howto_table_rela[i].name, r_name) == 0)
3885      return &micromips_elf64_howto_table_rela[i];
3886
3887  if (strcasecmp (elf_mips_gnu_vtinherit_howto.name, r_name) == 0)
3888    return &elf_mips_gnu_vtinherit_howto;
3889  if (strcasecmp (elf_mips_gnu_vtentry_howto.name, r_name) == 0)
3890    return &elf_mips_gnu_vtentry_howto;
3891  if (strcasecmp (elf_mips_gnu_rel16_s2.name, r_name) == 0)
3892    return &elf_mips_gnu_rel16_s2;
3893  if (strcasecmp (elf_mips_gnu_rela16_s2.name, r_name) == 0)
3894    return &elf_mips_gnu_rela16_s2;
3895  if (strcasecmp (elf_mips_gnu_pcrel32.name, r_name) == 0)
3896    return &elf_mips_gnu_pcrel32;
3897  if (strcasecmp (elf_mips_eh_howto.name, r_name) == 0)
3898    return &elf_mips_eh_howto;
3899  if (strcasecmp (elf_mips_copy_howto.name, r_name) == 0)
3900    return &elf_mips_copy_howto;
3901  if (strcasecmp (elf_mips_jump_slot_howto.name, r_name) == 0)
3902    return &elf_mips_jump_slot_howto;
3903
3904  return NULL;
3905}
3906
3907/* Given a MIPS Elf_Internal_Rel, fill in an arelent structure.  */
3908
3909static reloc_howto_type *
3910mips_elf64_rtype_to_howto (bfd *abfd, unsigned int r_type, bfd_boolean rela_p)
3911{
3912  reloc_howto_type *howto = NULL;
3913
3914  switch (r_type)
3915    {
3916    case R_MIPS_GNU_VTINHERIT:
3917      return &elf_mips_gnu_vtinherit_howto;
3918    case R_MIPS_GNU_VTENTRY:
3919      return &elf_mips_gnu_vtentry_howto;
3920    case R_MIPS_GNU_REL16_S2:
3921      if (rela_p)
3922	return &elf_mips_gnu_rela16_s2;
3923      else
3924	return &elf_mips_gnu_rel16_s2;
3925    case R_MIPS_PC32:
3926      return &elf_mips_gnu_pcrel32;
3927    case R_MIPS_EH:
3928      return &elf_mips_eh_howto;
3929    case R_MIPS_COPY:
3930      return &elf_mips_copy_howto;
3931    case R_MIPS_JUMP_SLOT:
3932      return &elf_mips_jump_slot_howto;
3933    default:
3934      if (r_type >= R_MICROMIPS_min && r_type < R_MICROMIPS_max)
3935	{
3936	  if (rela_p)
3937	    howto
3938	      = &micromips_elf64_howto_table_rela[r_type - R_MICROMIPS_min];
3939	  else
3940	    howto
3941	      = &micromips_elf64_howto_table_rel[r_type - R_MICROMIPS_min];
3942	}
3943      if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max)
3944	{
3945	  if (rela_p)
3946	    howto = &mips16_elf64_howto_table_rela[r_type - R_MIPS16_min];
3947	  else
3948	    howto = &mips16_elf64_howto_table_rel[r_type - R_MIPS16_min];
3949	}
3950      if (r_type < R_MIPS_max)
3951	{
3952	  if (rela_p)
3953	    howto = &mips_elf64_howto_table_rela[r_type];
3954	  else
3955	    howto = &mips_elf64_howto_table_rel[r_type];
3956	}
3957      if (howto != NULL && howto->name != NULL)
3958	return howto;
3959
3960      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
3961			  abfd, r_type);
3962      bfd_set_error (bfd_error_bad_value);
3963      return NULL;
3964    }
3965}
3966
3967/* Prevent relocation handling by bfd for MIPS ELF64.  */
3968
3969static bfd_boolean
3970mips_elf64_info_to_howto_rela (bfd *abfd,
3971			       arelent *cache_ptr ATTRIBUTE_UNUSED,
3972			       Elf_Internal_Rela *dst)
3973{
3974  unsigned int r_type = ELF32_R_TYPE (dst->r_info);
3975  /* xgettext:c-format */
3976  _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
3977		      abfd, r_type);
3978  bfd_set_error (bfd_error_bad_value);
3979  return FALSE;
3980}
3981
3982/* Since each entry in an SHT_REL or SHT_RELA section can represent up
3983   to three relocs, we must tell the user to allocate more space.  */
3984
3985static long
3986mips_elf64_get_dynamic_reloc_upper_bound (bfd *abfd)
3987{
3988  return _bfd_elf_get_dynamic_reloc_upper_bound (abfd) * 3;
3989}
3990
3991/* Read the relocations from one reloc section.  This is mostly copied
3992   from elfcode.h, except for the changes to expand one external
3993   relocation to 3 internal ones.  To reduce processing effort we
3994   could discard those R_MIPS_NONE relocations that occupy the second
3995   and the third entry of a triplet, as `mips_elf64_write_rel' and
3996   `mips_elf64_write_rela' recreate them in output automagically,
3997   however that would also remove them from `objdump -r' output,
3998   breaking a long-established tradition and likely confusing people.  */
3999
4000static bfd_boolean
4001mips_elf64_slurp_one_reloc_table (bfd *abfd, asection *asect,
4002				  Elf_Internal_Shdr *rel_hdr,
4003				  bfd_size_type reloc_count,
4004				  arelent *relents, asymbol **symbols,
4005				  bfd_boolean dynamic)
4006{
4007  void *allocated;
4008  bfd_byte *native_relocs;
4009  unsigned int symcount;
4010  arelent *relent;
4011  bfd_vma i;
4012  int entsize;
4013  bfd_boolean rela_p;
4014
4015  allocated = bfd_malloc (rel_hdr->sh_size);
4016  if (allocated == NULL)
4017    return FALSE;
4018
4019  if (bfd_seek (abfd, rel_hdr->sh_offset, SEEK_SET) != 0
4020      || (bfd_bread (allocated, rel_hdr->sh_size, abfd)
4021	  != rel_hdr->sh_size))
4022    goto error_return;
4023
4024  native_relocs = allocated;
4025
4026  entsize = rel_hdr->sh_entsize;
4027  BFD_ASSERT (entsize == sizeof (Elf64_Mips_External_Rel)
4028	      || entsize == sizeof (Elf64_Mips_External_Rela));
4029
4030  if (entsize == sizeof (Elf64_Mips_External_Rel))
4031    rela_p = FALSE;
4032  else
4033    rela_p = TRUE;
4034
4035  if (dynamic)
4036    symcount = bfd_get_dynamic_symcount (abfd);
4037  else
4038    symcount = bfd_get_symcount (abfd);
4039
4040  for (i = 0, relent = relents;
4041       i < reloc_count;
4042       i++, native_relocs += entsize)
4043    {
4044      Elf64_Mips_Internal_Rela rela;
4045      bfd_boolean used_sym, used_ssym;
4046      int ir;
4047
4048      if (entsize == sizeof (Elf64_Mips_External_Rela))
4049	mips_elf64_swap_reloca_in (abfd,
4050				   (Elf64_Mips_External_Rela *) native_relocs,
4051				   &rela);
4052      else
4053	mips_elf64_swap_reloc_in (abfd,
4054				  (Elf64_Mips_External_Rel *) native_relocs,
4055				  &rela);
4056
4057      /* Each entry represents exactly three actual relocations.  */
4058
4059      used_sym = FALSE;
4060      used_ssym = FALSE;
4061      for (ir = 0; ir < 3; ir++)
4062	{
4063	  enum elf_mips_reloc_type type;
4064
4065	  switch (ir)
4066	    {
4067	    default:
4068	      abort ();
4069	    case 0:
4070	      type = (enum elf_mips_reloc_type) rela.r_type;
4071	      break;
4072	    case 1:
4073	      type = (enum elf_mips_reloc_type) rela.r_type2;
4074	      break;
4075	    case 2:
4076	      type = (enum elf_mips_reloc_type) rela.r_type3;
4077	      break;
4078	    }
4079
4080	  /* Some types require symbols, whereas some do not.  */
4081	  switch (type)
4082	    {
4083	    case R_MIPS_NONE:
4084	    case R_MIPS_LITERAL:
4085	    case R_MIPS_INSERT_A:
4086	    case R_MIPS_INSERT_B:
4087	    case R_MIPS_DELETE:
4088	      relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
4089	      break;
4090
4091	    default:
4092	      if (! used_sym)
4093		{
4094		  if (rela.r_sym == STN_UNDEF)
4095		    relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
4096		  else if (rela.r_sym > symcount)
4097		    {
4098		      _bfd_error_handler
4099			/* xgettext:c-format */
4100			(_("%pB(%pA): relocation %" PRIu64
4101			   " has invalid symbol index %ld"),
4102			 abfd, asect, (uint64_t) i, rela.r_sym);
4103		      bfd_set_error (bfd_error_bad_value);
4104		      relent->sym_ptr_ptr
4105			= bfd_abs_section_ptr->symbol_ptr_ptr;
4106		    }
4107		  else
4108		    {
4109		      asymbol **ps, *s;
4110
4111		      ps = symbols + rela.r_sym - 1;
4112		      s = *ps;
4113		      if ((s->flags & BSF_SECTION_SYM) == 0)
4114			relent->sym_ptr_ptr = ps;
4115		      else
4116			relent->sym_ptr_ptr = s->section->symbol_ptr_ptr;
4117		    }
4118
4119		  used_sym = TRUE;
4120		}
4121	      else if (! used_ssym)
4122		{
4123		  switch (rela.r_ssym)
4124		    {
4125		    case RSS_UNDEF:
4126		      relent->sym_ptr_ptr =
4127			bfd_abs_section_ptr->symbol_ptr_ptr;
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	      else
4146		relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
4147
4148	      break;
4149	    }
4150
4151	  /* The address of an ELF reloc is section relative for an
4152	     object file, and absolute for an executable file or
4153	     shared library.  The address of a BFD reloc is always
4154	     section relative.  */
4155	  if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0 || dynamic)
4156	    relent->address = rela.r_offset;
4157	  else
4158	    relent->address = rela.r_offset - asect->vma;
4159
4160	  relent->addend = rela.r_addend;
4161
4162	  relent->howto = mips_elf64_rtype_to_howto (abfd, type, rela_p);
4163	  if (relent->howto == NULL)
4164	    goto error_return;
4165
4166	  ++relent;
4167	}
4168    }
4169
4170  if (allocated != NULL)
4171    free (allocated);
4172
4173  return TRUE;
4174
4175 error_return:
4176  if (allocated != NULL)
4177    free (allocated);
4178  return FALSE;
4179}
4180
4181/* Read the relocations.  On Irix 6, there can be two reloc sections
4182   associated with a single data section.  This is copied from
4183   elfcode.h as well, with changes as small as accounting for 3
4184   internal relocs per external reloc.  */
4185
4186static bfd_boolean
4187mips_elf64_slurp_reloc_table (bfd *abfd, asection *asect,
4188			      asymbol **symbols, bfd_boolean dynamic)
4189{
4190  struct bfd_elf_section_data * const d = elf_section_data (asect);
4191  Elf_Internal_Shdr *rel_hdr;
4192  Elf_Internal_Shdr *rel_hdr2;
4193  bfd_size_type reloc_count;
4194  bfd_size_type reloc_count2;
4195  arelent *relents;
4196  bfd_size_type amt;
4197
4198  if (asect->relocation != NULL)
4199    return TRUE;
4200
4201  if (! dynamic)
4202    {
4203      if ((asect->flags & SEC_RELOC) == 0
4204	  || asect->reloc_count == 0)
4205	return TRUE;
4206
4207      rel_hdr = d->rel.hdr;
4208      reloc_count = rel_hdr ? NUM_SHDR_ENTRIES (rel_hdr) : 0;
4209      rel_hdr2 = d->rela.hdr;
4210      reloc_count2 = (rel_hdr2 ? NUM_SHDR_ENTRIES (rel_hdr2) : 0);
4211
4212      BFD_ASSERT (asect->reloc_count == 3 * (reloc_count + reloc_count2));
4213      BFD_ASSERT ((rel_hdr && asect->rel_filepos == rel_hdr->sh_offset)
4214		  || (rel_hdr2 && asect->rel_filepos == rel_hdr2->sh_offset));
4215
4216    }
4217  else
4218    {
4219      /* Note that ASECT->RELOC_COUNT tends not to be accurate in this
4220	 case because relocations against this section may use the
4221	 dynamic symbol table, and in that case bfd_section_from_shdr
4222	 in elf.c does not update the RELOC_COUNT.  */
4223      if (asect->size == 0)
4224	return TRUE;
4225
4226      rel_hdr = &d->this_hdr;
4227      reloc_count = NUM_SHDR_ENTRIES (rel_hdr);
4228      rel_hdr2 = NULL;
4229      reloc_count2 = 0;
4230    }
4231
4232  /* Allocate space for 3 arelent structures for each Rel structure.  */
4233  amt = (reloc_count + reloc_count2) * 3 * sizeof (arelent);
4234  relents = bfd_alloc (abfd, amt);
4235  if (relents == NULL)
4236    return FALSE;
4237
4238  if (rel_hdr != NULL
4239      && ! mips_elf64_slurp_one_reloc_table (abfd, asect,
4240					     rel_hdr, reloc_count,
4241					     relents,
4242					     symbols, dynamic))
4243    return FALSE;
4244  if (rel_hdr2 != NULL
4245      && ! mips_elf64_slurp_one_reloc_table (abfd, asect,
4246					     rel_hdr2, reloc_count2,
4247					     relents + reloc_count * 3,
4248					     symbols, dynamic))
4249    return FALSE;
4250
4251  asect->relocation = relents;
4252  return TRUE;
4253}
4254
4255/* Write out the relocations.  */
4256
4257static void
4258mips_elf64_write_relocs (bfd *abfd, asection *sec, void *data)
4259{
4260  bfd_boolean *failedp = data;
4261  int count;
4262  Elf_Internal_Shdr *rel_hdr;
4263  unsigned int idx;
4264
4265  /* If we have already failed, don't do anything.  */
4266  if (*failedp)
4267    return;
4268
4269  if ((sec->flags & SEC_RELOC) == 0)
4270    return;
4271
4272  /* The linker backend writes the relocs out itself, and sets the
4273     reloc_count field to zero to inhibit writing them here.  Also,
4274     sometimes the SEC_RELOC flag gets set even when there aren't any
4275     relocs.  */
4276  if (sec->reloc_count == 0)
4277    return;
4278
4279  /* We can combine up to three relocs that refer to the same address
4280     if the latter relocs have no associated symbol.  */
4281  count = 0;
4282  for (idx = 0; idx < sec->reloc_count; idx++)
4283    {
4284      bfd_vma addr;
4285      unsigned int i;
4286
4287      ++count;
4288
4289      addr = sec->orelocation[idx]->address;
4290      for (i = 0; i < 2; i++)
4291	{
4292	  arelent *r;
4293
4294	  if (idx + 1 >= sec->reloc_count)
4295	    break;
4296	  r = sec->orelocation[idx + 1];
4297	  if (r->address != addr
4298	      || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
4299	      || (*r->sym_ptr_ptr)->value != 0)
4300	    break;
4301
4302	  /* We can merge the reloc at IDX + 1 with the reloc at IDX.  */
4303
4304	  ++idx;
4305	}
4306    }
4307
4308  rel_hdr = _bfd_elf_single_rel_hdr (sec);
4309
4310  /* Do the actual relocation.  */
4311
4312  if (rel_hdr->sh_entsize == sizeof(Elf64_Mips_External_Rel))
4313    mips_elf64_write_rel (abfd, sec, rel_hdr, &count, data);
4314  else if (rel_hdr->sh_entsize == sizeof(Elf64_Mips_External_Rela))
4315    mips_elf64_write_rela (abfd, sec, rel_hdr, &count, data);
4316  else
4317    BFD_ASSERT (0);
4318}
4319
4320static void
4321mips_elf64_write_rel (bfd *abfd, asection *sec,
4322		      Elf_Internal_Shdr *rel_hdr,
4323		      int *count, void *data)
4324{
4325  bfd_boolean *failedp = data;
4326  Elf64_Mips_External_Rel *ext_rel;
4327  unsigned int idx;
4328  asymbol *last_sym = 0;
4329  int last_sym_idx = 0;
4330
4331  rel_hdr->sh_size = rel_hdr->sh_entsize * *count;
4332  rel_hdr->contents = bfd_alloc (abfd, rel_hdr->sh_size);
4333  if (rel_hdr->contents == NULL)
4334    {
4335      *failedp = TRUE;
4336      return;
4337    }
4338
4339  ext_rel = (Elf64_Mips_External_Rel *) rel_hdr->contents;
4340  for (idx = 0; idx < sec->reloc_count; idx++, ext_rel++)
4341    {
4342      arelent *ptr;
4343      Elf64_Mips_Internal_Rela int_rel;
4344      asymbol *sym;
4345      int n;
4346      unsigned int i;
4347
4348      ptr = sec->orelocation[idx];
4349
4350      /* The address of an ELF reloc is section relative for an object
4351	 file, and absolute for an executable file or shared library.
4352	 The address of a BFD reloc is always section relative.  */
4353      if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
4354	int_rel.r_offset = ptr->address;
4355      else
4356	int_rel.r_offset = ptr->address + sec->vma;
4357
4358      sym = *ptr->sym_ptr_ptr;
4359      if (sym == last_sym)
4360	n = last_sym_idx;
4361      else if (bfd_is_abs_section (sym->section) && sym->value == 0)
4362	n = STN_UNDEF;
4363      else
4364	{
4365	  last_sym = sym;
4366	  n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
4367	  if (n < 0)
4368	    {
4369	      *failedp = TRUE;
4370	      return;
4371	    }
4372	  last_sym_idx = n;
4373	}
4374
4375      int_rel.r_sym = n;
4376      int_rel.r_ssym = RSS_UNDEF;
4377
4378      if ((*ptr->sym_ptr_ptr)->the_bfd != NULL
4379	  && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
4380	  && ! _bfd_elf_validate_reloc (abfd, ptr))
4381	{
4382	  *failedp = TRUE;
4383	  return;
4384	}
4385
4386      int_rel.r_type = ptr->howto->type;
4387      int_rel.r_type2 = (int) R_MIPS_NONE;
4388      int_rel.r_type3 = (int) R_MIPS_NONE;
4389
4390      for (i = 0; i < 2; i++)
4391	{
4392	  arelent *r;
4393
4394	  if (idx + 1 >= sec->reloc_count)
4395	    break;
4396	  r = sec->orelocation[idx + 1];
4397	  if (r->address != ptr->address
4398	      || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
4399	      || (*r->sym_ptr_ptr)->value != 0)
4400	    break;
4401
4402	  /* We can merge the reloc at IDX + 1 with the reloc at IDX.  */
4403
4404	  if (i == 0)
4405	    int_rel.r_type2 = r->howto->type;
4406	  else
4407	    int_rel.r_type3 = r->howto->type;
4408
4409	  ++idx;
4410	}
4411
4412      mips_elf64_swap_reloc_out (abfd, &int_rel, ext_rel);
4413    }
4414
4415  BFD_ASSERT (ext_rel - (Elf64_Mips_External_Rel *) rel_hdr->contents
4416	      == *count);
4417}
4418
4419static void
4420mips_elf64_write_rela (bfd *abfd, asection *sec,
4421		       Elf_Internal_Shdr *rela_hdr,
4422		       int *count, void *data)
4423{
4424  bfd_boolean *failedp = data;
4425  Elf64_Mips_External_Rela *ext_rela;
4426  unsigned int idx;
4427  asymbol *last_sym = 0;
4428  int last_sym_idx = 0;
4429
4430  rela_hdr->sh_size = rela_hdr->sh_entsize * *count;
4431  rela_hdr->contents = bfd_alloc (abfd, rela_hdr->sh_size);
4432  if (rela_hdr->contents == NULL)
4433    {
4434      *failedp = TRUE;
4435      return;
4436    }
4437
4438  ext_rela = (Elf64_Mips_External_Rela *) rela_hdr->contents;
4439  for (idx = 0; idx < sec->reloc_count; idx++, ext_rela++)
4440    {
4441      arelent *ptr;
4442      Elf64_Mips_Internal_Rela int_rela;
4443      asymbol *sym;
4444      int n;
4445      unsigned int i;
4446
4447      ptr = sec->orelocation[idx];
4448
4449      /* The address of an ELF reloc is section relative for an object
4450	 file, and absolute for an executable file or shared library.
4451	 The address of a BFD reloc is always section relative.  */
4452      if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
4453	int_rela.r_offset = ptr->address;
4454      else
4455	int_rela.r_offset = ptr->address + sec->vma;
4456
4457      sym = *ptr->sym_ptr_ptr;
4458      if (sym == last_sym)
4459	n = last_sym_idx;
4460      else if (bfd_is_abs_section (sym->section) && sym->value == 0)
4461	n = STN_UNDEF;
4462      else
4463	{
4464	  last_sym = sym;
4465	  n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
4466	  if (n < 0)
4467	    {
4468	      *failedp = TRUE;
4469	      return;
4470	    }
4471	  last_sym_idx = n;
4472	}
4473
4474      int_rela.r_sym = n;
4475      int_rela.r_addend = ptr->addend;
4476      int_rela.r_ssym = RSS_UNDEF;
4477
4478      if ((*ptr->sym_ptr_ptr)->the_bfd != NULL
4479	  && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
4480	  && ! _bfd_elf_validate_reloc (abfd, ptr))
4481	{
4482	  *failedp = TRUE;
4483	  return;
4484	}
4485
4486      int_rela.r_type = ptr->howto->type;
4487      int_rela.r_type2 = (int) R_MIPS_NONE;
4488      int_rela.r_type3 = (int) R_MIPS_NONE;
4489
4490      for (i = 0; i < 2; i++)
4491	{
4492	  arelent *r;
4493
4494	  if (idx + 1 >= sec->reloc_count)
4495	    break;
4496	  r = sec->orelocation[idx + 1];
4497	  if (r->address != ptr->address
4498	      || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
4499	      || (*r->sym_ptr_ptr)->value != 0)
4500	    break;
4501
4502	  /* We can merge the reloc at IDX + 1 with the reloc at IDX.  */
4503
4504	  if (i == 0)
4505	    int_rela.r_type2 = r->howto->type;
4506	  else
4507	    int_rela.r_type3 = r->howto->type;
4508
4509	  ++idx;
4510	}
4511
4512      mips_elf64_swap_reloca_out (abfd, &int_rela, ext_rela);
4513    }
4514
4515  BFD_ASSERT (ext_rela - (Elf64_Mips_External_Rela *) rela_hdr->contents
4516	      == *count);
4517}
4518
4519/* Set the right machine number for a MIPS ELF file.  */
4520
4521static bfd_boolean
4522mips_elf64_object_p (bfd *abfd)
4523{
4524  unsigned long mach;
4525
4526  /* Irix 6 is broken.  Object file symbol tables are not always
4527     sorted correctly such that local symbols precede global symbols,
4528     and the sh_info field in the symbol table is not always right.  */
4529  if (elf64_mips_irix_compat (abfd) != ict_none)
4530    elf_bad_symtab (abfd) = TRUE;
4531
4532  mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
4533  bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
4534  return TRUE;
4535}
4536
4537/* MIPS ELF local labels start with "$L".  */
4538static bfd_boolean
4539mips_elf64_is_local_label_name (bfd *abfd, const char *name)
4540{
4541  if (name[0] == '$' && name[1] == 'L')
4542    return TRUE;
4543
4544  /* We accept the generic ELF local label syntax as well.  */
4545  return _bfd_elf_is_local_label_name (abfd, name);
4546}
4547
4548/* Depending on the target vector we generate some version of Irix
4549   executables or "normal" MIPS ELF ABI executables.  */
4550static irix_compat_t
4551elf64_mips_irix_compat (bfd *abfd)
4552{
4553  if ((abfd->xvec == &mips_elf64_be_vec)
4554      || (abfd->xvec == &mips_elf64_le_vec))
4555    return ict_irix6;
4556  else
4557    return ict_none;
4558}
4559
4560/* Support for core dump NOTE sections.  */
4561static bfd_boolean
4562elf64_mips_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
4563{
4564  int offset;
4565  unsigned int size;
4566
4567  switch (note->descsz)
4568    {
4569      default:
4570	return FALSE;
4571
4572      case 480:		/* Linux/MIPS - N64 kernel */
4573	/* pr_cursig */
4574	elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
4575
4576	/* pr_pid */
4577	elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32);
4578
4579	/* pr_reg */
4580	offset = 112;
4581	size = 360;
4582
4583	break;
4584    }
4585
4586  /* Make a ".reg/999" section.  */
4587  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
4588					  size, note->descpos + offset);
4589}
4590
4591static bfd_boolean
4592elf64_mips_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
4593{
4594  switch (note->descsz)
4595    {
4596      default:
4597	return FALSE;
4598
4599      case 136:		/* Linux/MIPS - N64 kernel elf_prpsinfo */
4600	elf_tdata (abfd)->core->pid
4601	 = bfd_get_32 (abfd, note->descdata + 24);
4602	elf_tdata (abfd)->core->program
4603	 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
4604	elf_tdata (abfd)->core->command
4605	 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
4606    }
4607
4608  /* Note that for some reason, a spurious space is tacked
4609     onto the end of the args in some (at least one anyway)
4610     implementations, so strip it off if it exists.  */
4611
4612  {
4613    char *command = elf_tdata (abfd)->core->command;
4614    int n = strlen (command);
4615
4616    if (0 < n && command[n - 1] == ' ')
4617      command[n - 1] = '\0';
4618  }
4619
4620  return TRUE;
4621}
4622
4623/* Write Linux core PRSTATUS note into core file.  */
4624
4625static char *
4626elf64_mips_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type,
4627			     ...)
4628{
4629  switch (note_type)
4630    {
4631    default:
4632      return NULL;
4633
4634    case NT_PRPSINFO:
4635      BFD_FAIL ();
4636      return NULL;
4637
4638    case NT_PRSTATUS:
4639      {
4640	char data[480];
4641	va_list ap;
4642	long pid;
4643	int cursig;
4644	const void *greg;
4645
4646	va_start (ap, note_type);
4647	memset (data, 0, 112);
4648	pid = va_arg (ap, long);
4649	bfd_put_32 (abfd, pid, data + 32);
4650	cursig = va_arg (ap, int);
4651	bfd_put_16 (abfd, cursig, data + 12);
4652	greg = va_arg (ap, const void *);
4653	memcpy (data + 112, greg, 360);
4654	memset (data + 472, 0, 8);
4655	va_end (ap);
4656	return elfcore_write_note (abfd, buf, bufsiz,
4657				   "CORE", note_type, data, sizeof (data));
4658      }
4659    }
4660}
4661
4662/* ECOFF swapping routines.  These are used when dealing with the
4663   .mdebug section, which is in the ECOFF debugging format.  */
4664static const struct ecoff_debug_swap mips_elf64_ecoff_debug_swap =
4665{
4666  /* Symbol table magic number.  */
4667  magicSym2,
4668  /* Alignment of debugging information.  E.g., 4.  */
4669  8,
4670  /* Sizes of external symbolic information.  */
4671  sizeof (struct hdr_ext),
4672  sizeof (struct dnr_ext),
4673  sizeof (struct pdr_ext),
4674  sizeof (struct sym_ext),
4675  sizeof (struct opt_ext),
4676  sizeof (struct fdr_ext),
4677  sizeof (struct rfd_ext),
4678  sizeof (struct ext_ext),
4679  /* Functions to swap in external symbolic data.  */
4680  ecoff_swap_hdr_in,
4681  ecoff_swap_dnr_in,
4682  ecoff_swap_pdr_in,
4683  ecoff_swap_sym_in,
4684  ecoff_swap_opt_in,
4685  ecoff_swap_fdr_in,
4686  ecoff_swap_rfd_in,
4687  ecoff_swap_ext_in,
4688  _bfd_ecoff_swap_tir_in,
4689  _bfd_ecoff_swap_rndx_in,
4690  /* Functions to swap out external symbolic data.  */
4691  ecoff_swap_hdr_out,
4692  ecoff_swap_dnr_out,
4693  ecoff_swap_pdr_out,
4694  ecoff_swap_sym_out,
4695  ecoff_swap_opt_out,
4696  ecoff_swap_fdr_out,
4697  ecoff_swap_rfd_out,
4698  ecoff_swap_ext_out,
4699  _bfd_ecoff_swap_tir_out,
4700  _bfd_ecoff_swap_rndx_out,
4701  /* Function to read in symbolic data.  */
4702  _bfd_mips_elf_read_ecoff_info
4703};
4704
4705/* Relocations in the 64 bit MIPS ELF ABI are more complex than in
4706   standard ELF.  This structure is used to redirect the relocation
4707   handling routines.  */
4708
4709const struct elf_size_info mips_elf64_size_info =
4710{
4711  sizeof (Elf64_External_Ehdr),
4712  sizeof (Elf64_External_Phdr),
4713  sizeof (Elf64_External_Shdr),
4714  sizeof (Elf64_Mips_External_Rel),
4715  sizeof (Elf64_Mips_External_Rela),
4716  sizeof (Elf64_External_Sym),
4717  sizeof (Elf64_External_Dyn),
4718  sizeof (Elf_External_Note),
4719  4,		/* hash-table entry size */
4720  3,		/* internal relocations per external relocations */
4721  64,		/* arch_size */
4722  3,		/* log_file_align */
4723  ELFCLASS64,
4724  EV_CURRENT,
4725  bfd_elf64_write_out_phdrs,
4726  bfd_elf64_write_shdrs_and_ehdr,
4727  bfd_elf64_checksum_contents,
4728  mips_elf64_write_relocs,
4729  bfd_elf64_swap_symbol_in,
4730  bfd_elf64_swap_symbol_out,
4731  mips_elf64_slurp_reloc_table,
4732  bfd_elf64_slurp_symbol_table,
4733  bfd_elf64_swap_dyn_in,
4734  bfd_elf64_swap_dyn_out,
4735  mips_elf64_be_swap_reloc_in,
4736  mips_elf64_be_swap_reloc_out,
4737  mips_elf64_be_swap_reloca_in,
4738  mips_elf64_be_swap_reloca_out
4739};
4740
4741#define ELF_ARCH			bfd_arch_mips
4742#define ELF_TARGET_ID			MIPS_ELF_DATA
4743#define ELF_MACHINE_CODE		EM_MIPS
4744
4745#define elf_backend_collect		TRUE
4746#define elf_backend_type_change_ok	TRUE
4747#define elf_backend_can_gc_sections	TRUE
4748#define elf_backend_gc_mark_extra_sections \
4749					_bfd_mips_elf_gc_mark_extra_sections
4750#define elf_info_to_howto		mips_elf64_info_to_howto_rela
4751#define elf_info_to_howto_rel		mips_elf64_info_to_howto_rela
4752#define elf_backend_object_p		mips_elf64_object_p
4753#define elf_backend_symbol_processing	_bfd_mips_elf_symbol_processing
4754#define elf_backend_section_processing	_bfd_mips_elf_section_processing
4755#define elf_backend_section_from_shdr	_bfd_mips_elf_section_from_shdr
4756#define elf_backend_fake_sections	_bfd_mips_elf_fake_sections
4757#define elf_backend_section_from_bfd_section \
4758				_bfd_mips_elf_section_from_bfd_section
4759#define elf_backend_add_symbol_hook	_bfd_mips_elf_add_symbol_hook
4760#define elf_backend_link_output_symbol_hook \
4761				_bfd_mips_elf_link_output_symbol_hook
4762#define elf_backend_create_dynamic_sections \
4763				_bfd_mips_elf_create_dynamic_sections
4764#define elf_backend_check_relocs	_bfd_mips_elf_check_relocs
4765#define elf_backend_merge_symbol_attribute \
4766				_bfd_mips_elf_merge_symbol_attribute
4767#define elf_backend_get_target_dtag	_bfd_mips_elf_get_target_dtag
4768#define elf_backend_adjust_dynamic_symbol \
4769				_bfd_mips_elf_adjust_dynamic_symbol
4770#define elf_backend_always_size_sections \
4771				_bfd_mips_elf_always_size_sections
4772#define elf_backend_size_dynamic_sections \
4773				_bfd_mips_elf_size_dynamic_sections
4774#define elf_backend_init_index_section	_bfd_elf_init_1_index_section
4775#define elf_backend_relocate_section    _bfd_mips_elf_relocate_section
4776#define elf_backend_finish_dynamic_symbol \
4777				_bfd_mips_elf_finish_dynamic_symbol
4778#define elf_backend_finish_dynamic_sections \
4779				_bfd_mips_elf_finish_dynamic_sections
4780#define elf_backend_final_write_processing \
4781				_bfd_mips_elf_final_write_processing
4782#define elf_backend_additional_program_headers \
4783				_bfd_mips_elf_additional_program_headers
4784#define elf_backend_modify_segment_map	_bfd_mips_elf_modify_segment_map
4785#define elf_backend_gc_mark_hook	_bfd_mips_elf_gc_mark_hook
4786#define elf_backend_copy_indirect_symbol \
4787					_bfd_mips_elf_copy_indirect_symbol
4788#define elf_backend_hide_symbol		_bfd_mips_elf_hide_symbol
4789#define elf_backend_ignore_discarded_relocs \
4790					_bfd_mips_elf_ignore_discarded_relocs
4791#define elf_backend_mips_irix_compat	elf64_mips_irix_compat
4792#define elf_backend_mips_rtype_to_howto	mips_elf64_rtype_to_howto
4793#define elf_backend_ecoff_debug_swap	&mips_elf64_ecoff_debug_swap
4794#define elf_backend_size_info		mips_elf64_size_info
4795
4796#define elf_backend_grok_prstatus	elf64_mips_grok_prstatus
4797#define elf_backend_grok_psinfo		elf64_mips_grok_psinfo
4798
4799#define elf_backend_got_header_size	(8 * MIPS_RESERVED_GOTNO)
4800#define elf_backend_want_dynrelro	1
4801
4802/* MIPS ELF64 can use a mixture of REL and RELA, but some Relocations
4803   work better/work only in RELA, so we default to this.  */
4804#define elf_backend_may_use_rel_p	1
4805#define elf_backend_may_use_rela_p	1
4806#define elf_backend_default_use_rela_p	1
4807#define elf_backend_rela_plts_and_copies_p 0
4808#define elf_backend_plt_readonly	1
4809#define elf_backend_plt_sym_val		_bfd_mips_elf_plt_sym_val
4810
4811#define elf_backend_sign_extend_vma	TRUE
4812
4813#define elf_backend_write_section	_bfd_mips_elf_write_section
4814#define elf_backend_sort_relocs_p	_bfd_mips_elf_sort_relocs_p
4815
4816#define bfd_elf64_bfd_is_local_label_name \
4817					mips_elf64_is_local_label_name
4818#define bfd_elf64_bfd_is_target_special_symbol \
4819					_bfd_mips_elf_is_target_special_symbol
4820#define bfd_elf64_find_nearest_line	_bfd_mips_elf_find_nearest_line
4821#define bfd_elf64_find_inliner_info	_bfd_mips_elf_find_inliner_info
4822#define bfd_elf64_new_section_hook	_bfd_mips_elf_new_section_hook
4823#define bfd_elf64_set_section_contents	_bfd_mips_elf_set_section_contents
4824#define bfd_elf64_bfd_get_relocated_section_contents \
4825				_bfd_elf_mips_get_relocated_section_contents
4826#define bfd_elf64_bfd_link_hash_table_create \
4827				_bfd_mips_elf_link_hash_table_create
4828#define bfd_elf64_bfd_final_link	_bfd_mips_elf_final_link
4829#define bfd_elf64_bfd_merge_private_bfd_data \
4830				_bfd_mips_elf_merge_private_bfd_data
4831#define bfd_elf64_bfd_set_private_flags	_bfd_mips_elf_set_private_flags
4832#define bfd_elf64_bfd_print_private_bfd_data \
4833				_bfd_mips_elf_print_private_bfd_data
4834
4835#define bfd_elf64_get_dynamic_reloc_upper_bound mips_elf64_get_dynamic_reloc_upper_bound
4836#define bfd_elf64_mkobject		_bfd_mips_elf_mkobject
4837
4838/* The SGI style (n)64 NewABI.  */
4839#define TARGET_LITTLE_SYM		mips_elf64_le_vec
4840#define TARGET_LITTLE_NAME		"elf64-littlemips"
4841#define TARGET_BIG_SYM			mips_elf64_be_vec
4842#define TARGET_BIG_NAME			"elf64-bigmips"
4843
4844#define ELF_MAXPAGESIZE			0x10000
4845#define ELF_COMMONPAGESIZE		0x1000
4846
4847#include "elf64-target.h"
4848
4849/* The SYSV-style 'traditional' (n)64 NewABI.  */
4850#undef TARGET_LITTLE_SYM
4851#undef TARGET_LITTLE_NAME
4852#undef TARGET_BIG_SYM
4853#undef TARGET_BIG_NAME
4854
4855#undef ELF_MAXPAGESIZE
4856#undef ELF_COMMONPAGESIZE
4857
4858#define TARGET_LITTLE_SYM		mips_elf64_trad_le_vec
4859#define TARGET_LITTLE_NAME		"elf64-tradlittlemips"
4860#define TARGET_BIG_SYM			mips_elf64_trad_be_vec
4861#define TARGET_BIG_NAME			"elf64-tradbigmips"
4862
4863#define ELF_MAXPAGESIZE			0x10000
4864#define ELF_COMMONPAGESIZE		0x1000
4865#define elf64_bed			elf64_tradbed
4866
4867#undef elf_backend_write_core_note
4868#define elf_backend_write_core_note	elf64_mips_write_core_note
4869
4870/* Include the target file again for this target.  */
4871#include "elf64-target.h"
4872
4873
4874/* FreeBSD support.  */
4875
4876#undef TARGET_LITTLE_SYM
4877#undef TARGET_LITTLE_NAME
4878#undef TARGET_BIG_SYM
4879#undef TARGET_BIG_NAME
4880
4881#define	TARGET_LITTLE_SYM		mips_elf64_tradfbsd_le_vec
4882#define	TARGET_LITTLE_NAME		"elf64-tradlittlemips-freebsd"
4883#define	TARGET_BIG_SYM			mips_elf64_tradfbsd_be_vec
4884#define	TARGET_BIG_NAME			"elf64-tradbigmips-freebsd"
4885
4886#undef	ELF_OSABI
4887#define	ELF_OSABI			ELFOSABI_FREEBSD
4888
4889#undef	elf64_bed
4890#define elf64_bed				elf64_fbsd_tradbed
4891
4892#undef elf64_mips_write_core_note
4893
4894#include "elf64-target.h"
4895