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