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