bfd/
[deliverable/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 */
8a397dad
TS
757};
758
759/* The relocation table used for SHT_RELA sections. */
760
761static reloc_howto_type elf_mips_howto_table_rela[] =
762{
763 /* No relocation. */
764 HOWTO (R_MIPS_NONE, /* type */
765 0, /* rightshift */
766 0, /* size (0 = byte, 1 = short, 2 = long) */
767 0, /* bitsize */
b34976b6 768 FALSE, /* pc_relative */
8a397dad
TS
769 0, /* bitpos */
770 complain_overflow_dont, /* complain_on_overflow */
30ac9238 771 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 772 "R_MIPS_NONE", /* name */
b34976b6 773 FALSE, /* partial_inplace */
8a397dad
TS
774 0, /* src_mask */
775 0, /* dst_mask */
b34976b6 776 FALSE), /* pcrel_offset */
8a397dad
TS
777
778 /* 16 bit relocation. */
779 HOWTO (R_MIPS_16, /* type */
780 0, /* rightshift */
781 2, /* size (0 = byte, 1 = short, 2 = long) */
782 16, /* bitsize */
b34976b6 783 FALSE, /* pc_relative */
8a397dad
TS
784 0, /* bitpos */
785 complain_overflow_signed, /* complain_on_overflow */
30ac9238 786 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 787 "R_MIPS_16", /* name */
b34976b6 788 FALSE, /* partial_inplace */
8a397dad
TS
789 0, /* src_mask */
790 0x0000, /* dst_mask */
b34976b6 791 FALSE), /* pcrel_offset */
8a397dad
TS
792
793 /* 32 bit relocation. */
794 HOWTO (R_MIPS_32, /* type */
795 0, /* rightshift */
796 2, /* size (0 = byte, 1 = short, 2 = long) */
797 32, /* bitsize */
b34976b6 798 FALSE, /* pc_relative */
8a397dad
TS
799 0, /* bitpos */
800 complain_overflow_dont, /* complain_on_overflow */
30ac9238 801 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 802 "R_MIPS_32", /* name */
b34976b6 803 FALSE, /* partial_inplace */
8a397dad
TS
804 0, /* src_mask */
805 0xffffffff, /* dst_mask */
b34976b6 806 FALSE), /* pcrel_offset */
8a397dad
TS
807
808 /* 32 bit symbol relative relocation. */
809 HOWTO (R_MIPS_REL32, /* 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_REL32", /* 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 /* 26 bit jump address. */
824 HOWTO (R_MIPS_26, /* type */
825 2, /* rightshift */
826 2, /* size (0 = byte, 1 = short, 2 = long) */
827 26, /* bitsize */
b34976b6 828 FALSE, /* pc_relative */
8a397dad
TS
829 0, /* bitpos */
830 complain_overflow_dont, /* complain_on_overflow */
831 /* This needs complex overflow
832 detection, because the upper 36
833 bits must match the PC + 4. */
30ac9238 834 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 835 "R_MIPS_26", /* name */
b34976b6 836 FALSE, /* partial_inplace */
8a397dad
TS
837 0, /* src_mask */
838 0x03ffffff, /* dst_mask */
b34976b6 839 FALSE), /* pcrel_offset */
8a397dad
TS
840
841 /* High 16 bits of symbol value. */
842 HOWTO (R_MIPS_HI16, /* type */
843 0, /* rightshift */
844 2, /* size (0 = byte, 1 = short, 2 = long) */
845 16, /* bitsize */
b34976b6 846 FALSE, /* pc_relative */
8a397dad
TS
847 0, /* bitpos */
848 complain_overflow_dont, /* complain_on_overflow */
30ac9238 849 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 850 "R_MIPS_HI16", /* name */
b34976b6 851 FALSE, /* partial_inplace */
8a397dad
TS
852 0, /* src_mask */
853 0x0000ffff, /* dst_mask */
b34976b6 854 FALSE), /* pcrel_offset */
8a397dad
TS
855
856 /* Low 16 bits of symbol value. */
857 HOWTO (R_MIPS_LO16, /* 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_LO16", /* 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 /* GP relative reference. */
872 HOWTO (R_MIPS_GPREL16, /* 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_signed, /* complain_on_overflow */
879 mips_elf_gprel16_reloc, /* special_function */
880 "R_MIPS_GPREL16", /* 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 /* Reference to literal section. */
887 HOWTO (R_MIPS_LITERAL, /* 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_literal_reloc, /* special_function */
895 "R_MIPS_LITERAL", /* 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 global offset table. */
902 HOWTO (R_MIPS_GOT16, /* 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 */
30ac9238 909 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 910 "R_MIPS_GOT16", /* name */
b34976b6 911 FALSE, /* partial_inplace */
8a397dad
TS
912 0, /* src_mask */
913 0x0000ffff, /* dst_mask */
b34976b6 914 FALSE), /* pcrel_offset */
8a397dad 915
bad36eac
DJ
916 /* 16 bit PC relative reference. Note that the ABI document has a typo
917 and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
918 We do the right thing here. */
8a397dad 919 HOWTO (R_MIPS_PC16, /* type */
bad36eac 920 2, /* rightshift */
8a397dad
TS
921 2, /* size (0 = byte, 1 = short, 2 = long) */
922 16, /* bitsize */
b34976b6 923 TRUE, /* pc_relative */
8a397dad
TS
924 0, /* bitpos */
925 complain_overflow_signed, /* complain_on_overflow */
30ac9238 926 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 927 "R_MIPS_PC16", /* name */
b34976b6 928 FALSE, /* partial_inplace */
8a397dad
TS
929 0, /* src_mask */
930 0x0000ffff, /* dst_mask */
b34976b6 931 TRUE), /* pcrel_offset */
8a397dad
TS
932
933 /* 16 bit call through global offset table. */
934 HOWTO (R_MIPS_CALL16, /* type */
935 0, /* rightshift */
936 2, /* size (0 = byte, 1 = short, 2 = long) */
937 16, /* bitsize */
b34976b6 938 FALSE, /* 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_CALL16", /* name */
b34976b6 943 FALSE, /* partial_inplace */
8a397dad
TS
944 0, /* src_mask */
945 0x0000ffff, /* dst_mask */
b34976b6 946 FALSE), /* pcrel_offset */
8a397dad
TS
947
948 /* 32 bit GP relative reference. */
949 HOWTO (R_MIPS_GPREL32, /* type */
950 0, /* rightshift */
951 2, /* size (0 = byte, 1 = short, 2 = long) */
952 32, /* bitsize */
b34976b6 953 FALSE, /* pc_relative */
8a397dad
TS
954 0, /* bitpos */
955 complain_overflow_dont, /* complain_on_overflow */
956 mips_elf_gprel32_reloc, /* special_function */
957 "R_MIPS_GPREL32", /* name */
b34976b6 958 FALSE, /* partial_inplace */
8a397dad
TS
959 0, /* src_mask */
960 0xffffffff, /* dst_mask */
b34976b6 961 FALSE), /* pcrel_offset */
8a397dad
TS
962
963 EMPTY_HOWTO (13),
964 EMPTY_HOWTO (14),
965 EMPTY_HOWTO (15),
966
967 /* A 5 bit shift field. */
968 HOWTO (R_MIPS_SHIFT5, /* type */
969 0, /* rightshift */
970 2, /* size (0 = byte, 1 = short, 2 = long) */
971 5, /* bitsize */
b34976b6 972 FALSE, /* pc_relative */
8a397dad
TS
973 6, /* bitpos */
974 complain_overflow_bitfield, /* complain_on_overflow */
30ac9238 975 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 976 "R_MIPS_SHIFT5", /* name */
b34976b6 977 FALSE, /* partial_inplace */
8a397dad
TS
978 0, /* src_mask */
979 0x000007c0, /* dst_mask */
b34976b6 980 FALSE), /* pcrel_offset */
8a397dad
TS
981
982 /* A 6 bit shift field. */
983 HOWTO (R_MIPS_SHIFT6, /* type */
984 0, /* rightshift */
985 2, /* size (0 = byte, 1 = short, 2 = long) */
986 6, /* bitsize */
b34976b6 987 FALSE, /* pc_relative */
8a397dad
TS
988 6, /* bitpos */
989 complain_overflow_bitfield, /* complain_on_overflow */
990 mips_elf_shift6_reloc, /* special_function */
991 "R_MIPS_SHIFT6", /* name */
b34976b6 992 FALSE, /* partial_inplace */
8a397dad
TS
993 0, /* src_mask */
994 0x000007c4, /* dst_mask */
b34976b6 995 FALSE), /* pcrel_offset */
8a397dad
TS
996
997 /* 64 bit relocation. */
998 HOWTO (R_MIPS_64, /* type */
999 0, /* rightshift */
1000 4, /* size (0 = byte, 1 = short, 2 = long) */
1001 64, /* bitsize */
b34976b6 1002 FALSE, /* pc_relative */
8a397dad
TS
1003 0, /* bitpos */
1004 complain_overflow_dont, /* complain_on_overflow */
30ac9238 1005 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 1006 "R_MIPS_64", /* name */
b34976b6 1007 FALSE, /* partial_inplace */
8a397dad
TS
1008 0, /* src_mask */
1009 MINUS_ONE, /* dst_mask */
b34976b6 1010 FALSE), /* pcrel_offset */
8a397dad
TS
1011
1012 /* Displacement in the global offset table. */
1013 HOWTO (R_MIPS_GOT_DISP, /* type */
1014 0, /* rightshift */
1015 2, /* size (0 = byte, 1 = short, 2 = long) */
1016 16, /* bitsize */
b34976b6 1017 FALSE, /* pc_relative */
8a397dad
TS
1018 0, /* bitpos */
1019 complain_overflow_signed, /* complain_on_overflow */
30ac9238 1020 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 1021 "R_MIPS_GOT_DISP", /* name */
b34976b6 1022 FALSE, /* partial_inplace */
8a397dad
TS
1023 0, /* src_mask */
1024 0x0000ffff, /* dst_mask */
b34976b6 1025 FALSE), /* pcrel_offset */
8a397dad
TS
1026
1027 /* Displacement to page pointer in the global offset table. */
1028 HOWTO (R_MIPS_GOT_PAGE, /* 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_PAGE", /* 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 /* Offset from page pointer in the global offset table. */
1043 HOWTO (R_MIPS_GOT_OFST, /* 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_OFST", /* 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 /* High 16 bits of displacement in global offset table. */
1058 HOWTO (R_MIPS_GOT_HI16, /* 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_dont, /* complain_on_overflow */
30ac9238 1065 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 1066 "R_MIPS_GOT_HI16", /* 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 /* Low 16 bits of displacement in global offset table. */
1073 HOWTO (R_MIPS_GOT_LO16, /* 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_LO16", /* name */
b34976b6 1082 FALSE, /* partial_inplace */
8a397dad
TS
1083 0, /* src_mask */
1084 0x0000ffff, /* dst_mask */
b34976b6 1085 FALSE), /* pcrel_offset */
8a397dad 1086
4cc11e76 1087 /* 64 bit subtraction. */
8a397dad
TS
1088 HOWTO (R_MIPS_SUB, /* type */
1089 0, /* rightshift */
1090 4, /* size (0 = byte, 1 = short, 2 = long) */
1091 64, /* 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_SUB", /* name */
b34976b6 1097 FALSE, /* partial_inplace */
8a397dad
TS
1098 0, /* src_mask */
1099 MINUS_ONE, /* dst_mask */
b34976b6 1100 FALSE), /* pcrel_offset */
8a397dad
TS
1101
1102 /* Insert the addend as an instruction. */
1103 /* FIXME: Not handled correctly. */
1104 HOWTO (R_MIPS_INSERT_A, /* type */
1105 0, /* rightshift */
1106 2, /* size (0 = byte, 1 = short, 2 = long) */
1107 32, /* bitsize */
b34976b6 1108 FALSE, /* pc_relative */
8a397dad
TS
1109 0, /* bitpos */
1110 complain_overflow_dont, /* complain_on_overflow */
30ac9238 1111 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 1112 "R_MIPS_INSERT_A", /* name */
b34976b6 1113 FALSE, /* partial_inplace */
8a397dad
TS
1114 0, /* src_mask */
1115 0xffffffff, /* dst_mask */
b34976b6 1116 FALSE), /* pcrel_offset */
8a397dad
TS
1117
1118 /* Insert the addend as an instruction, and change all relocations
1119 to refer to the old instruction at the address. */
1120 /* FIXME: Not handled correctly. */
1121 HOWTO (R_MIPS_INSERT_B, /* type */
1122 0, /* rightshift */
1123 2, /* size (0 = byte, 1 = short, 2 = long) */
1124 32, /* bitsize */
b34976b6 1125 FALSE, /* pc_relative */
8a397dad
TS
1126 0, /* bitpos */
1127 complain_overflow_dont, /* complain_on_overflow */
30ac9238 1128 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 1129 "R_MIPS_INSERT_B", /* name */
b34976b6 1130 FALSE, /* partial_inplace */
8a397dad
TS
1131 0, /* src_mask */
1132 0xffffffff, /* dst_mask */
b34976b6 1133 FALSE), /* pcrel_offset */
8a397dad
TS
1134
1135 /* Delete a 32 bit instruction. */
1136 /* FIXME: Not handled correctly. */
1137 HOWTO (R_MIPS_DELETE, /* type */
1138 0, /* rightshift */
1139 2, /* size (0 = byte, 1 = short, 2 = long) */
1140 32, /* bitsize */
b34976b6 1141 FALSE, /* pc_relative */
8a397dad
TS
1142 0, /* bitpos */
1143 complain_overflow_dont, /* complain_on_overflow */
30ac9238 1144 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 1145 "R_MIPS_DELETE", /* name */
b34976b6 1146 FALSE, /* partial_inplace */
8a397dad
TS
1147 0, /* src_mask */
1148 0xffffffff, /* dst_mask */
b34976b6 1149 FALSE), /* pcrel_offset */
8a397dad
TS
1150
1151 /* Get the higher value of a 64 bit addend. */
1152 HOWTO (R_MIPS_HIGHER, /* type */
1153 0, /* rightshift */
1154 2, /* size (0 = byte, 1 = short, 2 = long) */
1155 16, /* 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_HIGHER", /* name */
b34976b6 1161 FALSE, /* partial_inplace */
8a397dad
TS
1162 0, /* src_mask */
1163 0x0000ffff, /* dst_mask */
b34976b6 1164 FALSE), /* pcrel_offset */
8a397dad
TS
1165
1166 /* Get the highest value of a 64 bit addend. */
1167 HOWTO (R_MIPS_HIGHEST, /* 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_HIGHEST", /* 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 /* High 16 bits of displacement in global offset table. */
1182 HOWTO (R_MIPS_CALL_HI16, /* 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_CALL_HI16", /* 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 /* Low 16 bits of displacement in global offset table. */
1197 HOWTO (R_MIPS_CALL_LO16, /* 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_LO16", /* 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 /* Section displacement, used by an associated event location section. */
1212 HOWTO (R_MIPS_SCN_DISP, /* type */
1213 0, /* rightshift */
1214 2, /* size (0 = byte, 1 = short, 2 = long) */
1215 32, /* 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_SCN_DISP", /* name */
b34976b6 1221 FALSE, /* partial_inplace */
8a397dad
TS
1222 0, /* src_mask */
1223 0xffffffff, /* dst_mask */
b34976b6 1224 FALSE), /* pcrel_offset */
8a397dad
TS
1225
1226 /* 16 bit relocation. */
1227 HOWTO (R_MIPS_REL16, /* type */
1228 0, /* rightshift */
1229 1, /* size (0 = byte, 1 = short, 2 = long) */
1230 16, /* bitsize */
b34976b6 1231 FALSE, /* pc_relative */
8a397dad
TS
1232 0, /* bitpos */
1233 complain_overflow_signed, /* complain_on_overflow */
30ac9238 1234 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 1235 "R_MIPS_REL16", /* name */
b34976b6 1236 FALSE, /* partial_inplace */
8a397dad
TS
1237 0, /* src_mask */
1238 0xffff, /* dst_mask */
b34976b6 1239 FALSE), /* pcrel_offset */
8a397dad
TS
1240
1241 /* These two are obsolete. */
1242 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
1243 EMPTY_HOWTO (R_MIPS_PJUMP),
1244
1245 /* Similiar to R_MIPS_REL32, but used for relocations in a GOT section.
1246 It must be used for multigot GOT's (and only there). */
1247 HOWTO (R_MIPS_RELGOT, /* type */
1248 0, /* rightshift */
1249 2, /* size (0 = byte, 1 = short, 2 = long) */
1250 32, /* bitsize */
b34976b6 1251 FALSE, /* pc_relative */
8a397dad
TS
1252 0, /* bitpos */
1253 complain_overflow_dont, /* complain_on_overflow */
30ac9238 1254 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 1255 "R_MIPS_RELGOT", /* name */
b34976b6 1256 FALSE, /* partial_inplace */
8a397dad
TS
1257 0, /* src_mask */
1258 0xffffffff, /* dst_mask */
b34976b6 1259 FALSE), /* pcrel_offset */
8a397dad
TS
1260
1261 /* Protected jump conversion. This is an optimization hint. No
1262 relocation is required for correctness. */
1263 HOWTO (R_MIPS_JALR, /* type */
1264 0, /* rightshift */
1265 2, /* size (0 = byte, 1 = short, 2 = long) */
1266 32, /* bitsize */
b34976b6 1267 FALSE, /* pc_relative */
8a397dad
TS
1268 0, /* bitpos */
1269 complain_overflow_dont, /* complain_on_overflow */
30ac9238 1270 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 1271 "R_MIPS_JALR", /* name */
b34976b6 1272 FALSE, /* partial_inplace */
8a397dad 1273 0, /* src_mask */
74f79d8d 1274 0, /* dst_mask */
b34976b6 1275 FALSE), /* pcrel_offset */
0f20cc35
DJ
1276
1277 /* TLS GD/LD dynamic relocations. */
1278 HOWTO (R_MIPS_TLS_DTPMOD32, /* type */
1279 0, /* rightshift */
1280 2, /* size (0 = byte, 1 = short, 2 = long) */
1281 32, /* bitsize */
1282 FALSE, /* pc_relative */
1283 0, /* bitpos */
1284 complain_overflow_dont, /* complain_on_overflow */
1285 _bfd_mips_elf_generic_reloc, /* special_function */
1286 "R_MIPS_TLS_DTPMOD32", /* name */
1287 TRUE, /* partial_inplace */
1288 0xffffffff, /* src_mask */
1289 0xffffffff, /* dst_mask */
1290 FALSE), /* pcrel_offset */
1291
1292 HOWTO (R_MIPS_TLS_DTPREL32, /* type */
1293 0, /* rightshift */
1294 2, /* size (0 = byte, 1 = short, 2 = long) */
1295 32, /* bitsize */
1296 FALSE, /* pc_relative */
1297 0, /* bitpos */
1298 complain_overflow_dont, /* complain_on_overflow */
1299 _bfd_mips_elf_generic_reloc, /* special_function */
1300 "R_MIPS_TLS_DTPREL32", /* name */
1301 TRUE, /* partial_inplace */
1302 0xffffffff, /* src_mask */
1303 0xffffffff, /* dst_mask */
1304 FALSE), /* pcrel_offset */
1305
1306 EMPTY_HOWTO (R_MIPS_TLS_DTPMOD64),
1307 EMPTY_HOWTO (R_MIPS_TLS_DTPREL64),
1308
1309 /* TLS general dynamic variable reference. */
1310 HOWTO (R_MIPS_TLS_GD, /* type */
1311 0, /* rightshift */
1312 2, /* size (0 = byte, 1 = short, 2 = long) */
1313 16, /* bitsize */
1314 FALSE, /* pc_relative */
1315 0, /* bitpos */
1316 complain_overflow_signed, /* complain_on_overflow */
1317 _bfd_mips_elf_generic_reloc, /* special_function */
1318 "R_MIPS_TLS_GD", /* name */
1319 TRUE, /* partial_inplace */
1320 0x0000ffff, /* src_mask */
1321 0x0000ffff, /* dst_mask */
1322 FALSE), /* pcrel_offset */
1323
1324 /* TLS local dynamic variable reference. */
1325 HOWTO (R_MIPS_TLS_LDM, /* 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_LDM", /* name */
1334 TRUE, /* partial_inplace */
1335 0x0000ffff, /* src_mask */
1336 0x0000ffff, /* dst_mask */
1337 FALSE), /* pcrel_offset */
1338
1339 /* TLS local dynamic offset. */
1340 HOWTO (R_MIPS_TLS_DTPREL_HI16, /* 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_DTPREL_HI16", /* 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_LO16, /* 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_LO16", /* name */
1364 TRUE, /* partial_inplace */
1365 0x0000ffff, /* src_mask */
1366 0x0000ffff, /* dst_mask */
1367 FALSE), /* pcrel_offset */
1368
1369 /* TLS thread pointer offset. */
1370 HOWTO (R_MIPS_TLS_GOTTPREL, /* 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_GOTTPREL", /* name */
1379 TRUE, /* partial_inplace */
1380 0x0000ffff, /* src_mask */
1381 0x0000ffff, /* dst_mask */
1382 FALSE), /* pcrel_offset */
1383
1384 /* TLS IE dynamic relocations. */
1385 HOWTO (R_MIPS_TLS_TPREL32, /* type */
1386 0, /* rightshift */
1387 2, /* size (0 = byte, 1 = short, 2 = long) */
1388 32, /* bitsize */
1389 FALSE, /* pc_relative */
1390 0, /* bitpos */
1391 complain_overflow_dont, /* complain_on_overflow */
1392 _bfd_mips_elf_generic_reloc, /* special_function */
1393 "R_MIPS_TLS_TPREL32", /* name */
1394 TRUE, /* partial_inplace */
1395 0xffffffff, /* src_mask */
1396 0xffffffff, /* dst_mask */
1397 FALSE), /* pcrel_offset */
1398
1399 EMPTY_HOWTO (R_MIPS_TLS_TPREL64),
1400
1401 /* TLS thread pointer offset. */
1402 HOWTO (R_MIPS_TLS_TPREL_HI16, /* type */
1403 0, /* rightshift */
1404 2, /* size (0 = byte, 1 = short, 2 = long) */
1405 16, /* bitsize */
1406 FALSE, /* pc_relative */
1407 0, /* bitpos */
1408 complain_overflow_signed, /* complain_on_overflow */
1409 _bfd_mips_elf_generic_reloc, /* special_function */
1410 "R_MIPS_TLS_TPREL_HI16", /* name */
1411 TRUE, /* partial_inplace */
1412 0x0000ffff, /* src_mask */
1413 0x0000ffff, /* dst_mask */
1414 FALSE), /* pcrel_offset */
1415
1416 /* TLS thread pointer offset. */
1417 HOWTO (R_MIPS_TLS_TPREL_LO16, /* 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_LO16", /* name */
1426 TRUE, /* partial_inplace */
1427 0x0000ffff, /* src_mask */
1428 0x0000ffff, /* dst_mask */
1429 FALSE), /* pcrel_offset */
8a397dad
TS
1430};
1431
d6f16593
MR
1432static reloc_howto_type elf_mips16_howto_table_rel[] =
1433{
1434 /* The reloc used for the mips16 jump instruction. */
8a397dad
TS
1435 HOWTO (R_MIPS16_26, /* type */
1436 2, /* rightshift */
1437 2, /* size (0 = byte, 1 = short, 2 = long) */
1438 26, /* bitsize */
b34976b6 1439 FALSE, /* pc_relative */
8a397dad
TS
1440 0, /* bitpos */
1441 complain_overflow_dont, /* complain_on_overflow */
1442 /* This needs complex overflow
1443 detection, because the upper four
1444 bits must match the PC. */
35d3d567 1445 _bfd_mips_elf_generic_reloc, /* special_function */
8a397dad 1446 "R_MIPS16_26", /* name */
b34976b6 1447 TRUE, /* partial_inplace */
8a397dad
TS
1448 0x3ffffff, /* src_mask */
1449 0x3ffffff, /* dst_mask */
d6f16593 1450 FALSE), /* pcrel_offset */
8a397dad 1451
d6f16593 1452 /* The reloc used for the mips16 gprel instruction. */
8a397dad
TS
1453 HOWTO (R_MIPS16_GPREL, /* type */
1454 0, /* rightshift */
1455 2, /* size (0 = byte, 1 = short, 2 = long) */
1456 16, /* bitsize */
b34976b6 1457 FALSE, /* pc_relative */
8a397dad
TS
1458 0, /* bitpos */
1459 complain_overflow_signed, /* complain_on_overflow */
1460 mips16_gprel_reloc, /* special_function */
1461 "R_MIPS16_GPREL", /* name */
b34976b6 1462 TRUE, /* partial_inplace */
d6f16593
MR
1463 0x0000ffff, /* src_mask */
1464 0x0000ffff, /* dst_mask */
1465 FALSE), /* pcrel_offset */
1466
1467 /* A placeholder for MIPS16 reference to global offset table. */
1468 EMPTY_HOWTO (R_MIPS16_GOT16),
1469
1470 /* A placeholder for MIPS16 16 bit call through global offset table. */
1471 EMPTY_HOWTO (R_MIPS16_CALL16),
1472
1473 /* MIPS16 high 16 bits of symbol value. */
1474 HOWTO (R_MIPS16_HI16, /* type */
1475 16, /* rightshift */
1476 2, /* size (0 = byte, 1 = short, 2 = long) */
1477 16, /* bitsize */
1478 FALSE, /* pc_relative */
1479 0, /* bitpos */
1480 complain_overflow_dont, /* complain_on_overflow */
1481 _bfd_mips_elf_hi16_reloc, /* special_function */
1482 "R_MIPS16_HI16", /* name */
1483 TRUE, /* partial_inplace */
1484 0x0000ffff, /* src_mask */
1485 0x0000ffff, /* dst_mask */
1486 FALSE), /* pcrel_offset */
1487
1488 /* MIPS16 low 16 bits of symbol value. */
1489 HOWTO (R_MIPS16_LO16, /* type */
1490 0, /* rightshift */
1491 2, /* size (0 = byte, 1 = short, 2 = long) */
1492 16, /* bitsize */
1493 FALSE, /* pc_relative */
1494 0, /* bitpos */
1495 complain_overflow_dont, /* complain_on_overflow */
1496 _bfd_mips_elf_lo16_reloc, /* special_function */
1497 "R_MIPS16_LO16", /* name */
1498 TRUE, /* partial_inplace */
1499 0x0000ffff, /* src_mask */
1500 0x0000ffff, /* dst_mask */
1501 FALSE), /* pcrel_offset */
1502};
1503
1504static reloc_howto_type elf_mips16_howto_table_rela[] =
1505{
1506 /* The reloc used for the mips16 jump instruction. */
1507 HOWTO (R_MIPS16_26, /* type */
1508 2, /* rightshift */
1509 2, /* size (0 = byte, 1 = short, 2 = long) */
1510 26, /* bitsize */
1511 FALSE, /* pc_relative */
1512 0, /* bitpos */
1513 complain_overflow_dont, /* complain_on_overflow */
1514 /* This needs complex overflow
1515 detection, because the upper four
1516 bits must match the PC. */
35d3d567 1517 _bfd_mips_elf_generic_reloc, /* special_function */
d6f16593
MR
1518 "R_MIPS16_26", /* name */
1519 FALSE, /* partial_inplace */
1520 0x3ffffff, /* src_mask */
1521 0x3ffffff, /* dst_mask */
1522 FALSE), /* pcrel_offset */
1523
1524 /* The reloc used for the mips16 gprel instruction. */
1525 HOWTO (R_MIPS16_GPREL, /* type */
1526 0, /* rightshift */
1527 2, /* size (0 = byte, 1 = short, 2 = long) */
1528 16, /* bitsize */
1529 FALSE, /* pc_relative */
1530 0, /* bitpos */
1531 complain_overflow_signed, /* complain_on_overflow */
1532 mips16_gprel_reloc, /* special_function */
1533 "R_MIPS16_GPREL", /* name */
1534 FALSE, /* partial_inplace */
1535 0x0000ffff, /* src_mask */
1536 0x0000ffff, /* dst_mask */
1537 FALSE), /* pcrel_offset */
1538
1539 /* A placeholder for MIPS16 reference to global offset table. */
1540 EMPTY_HOWTO (R_MIPS16_GOT16),
1541
1542 /* A placeholder for MIPS16 16 bit call through global offset table. */
1543 EMPTY_HOWTO (R_MIPS16_CALL16),
1544
1545 /* MIPS16 high 16 bits of symbol value. */
1546 HOWTO (R_MIPS16_HI16, /* type */
1547 16, /* rightshift */
1548 2, /* size (0 = byte, 1 = short, 2 = long) */
1549 16, /* bitsize */
1550 FALSE, /* pc_relative */
1551 0, /* bitpos */
1552 complain_overflow_dont, /* complain_on_overflow */
1553 _bfd_mips_elf_hi16_reloc, /* special_function */
1554 "R_MIPS16_HI16", /* name */
1555 FALSE, /* partial_inplace */
1556 0x0000ffff, /* src_mask */
1557 0x0000ffff, /* dst_mask */
1558 FALSE), /* pcrel_offset */
1559
1560 /* MIPS16 low 16 bits of symbol value. */
1561 HOWTO (R_MIPS16_LO16, /* type */
1562 0, /* rightshift */
1563 2, /* size (0 = byte, 1 = short, 2 = long) */
1564 16, /* bitsize */
1565 FALSE, /* pc_relative */
1566 0, /* bitpos */
1567 complain_overflow_dont, /* complain_on_overflow */
1568 _bfd_mips_elf_lo16_reloc, /* special_function */
1569 "R_MIPS16_LO16", /* name */
1570 FALSE, /* partial_inplace */
1571 0x0000ffff, /* src_mask */
1572 0x0000ffff, /* dst_mask */
1573 FALSE), /* pcrel_offset */
1574};
8a397dad
TS
1575
1576/* GNU extension to record C++ vtable hierarchy */
1577static reloc_howto_type elf_mips_gnu_vtinherit_howto =
1578 HOWTO (R_MIPS_GNU_VTINHERIT, /* type */
1579 0, /* rightshift */
1580 2, /* size (0 = byte, 1 = short, 2 = long) */
1581 0, /* bitsize */
b34976b6 1582 FALSE, /* pc_relative */
8a397dad
TS
1583 0, /* bitpos */
1584 complain_overflow_dont, /* complain_on_overflow */
1585 NULL, /* special_function */
1586 "R_MIPS_GNU_VTINHERIT", /* name */
b34976b6 1587 FALSE, /* partial_inplace */
8a397dad
TS
1588 0, /* src_mask */
1589 0, /* dst_mask */
b34976b6 1590 FALSE); /* pcrel_offset */
8a397dad
TS
1591
1592/* GNU extension to record C++ vtable member usage */
1593static reloc_howto_type elf_mips_gnu_vtentry_howto =
1594 HOWTO (R_MIPS_GNU_VTENTRY, /* type */
1595 0, /* rightshift */
1596 2, /* size (0 = byte, 1 = short, 2 = long) */
1597 0, /* bitsize */
b34976b6 1598 FALSE, /* pc_relative */
8a397dad
TS
1599 0, /* bitpos */
1600 complain_overflow_dont, /* complain_on_overflow */
1601 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1602 "R_MIPS_GNU_VTENTRY", /* name */
b34976b6 1603 FALSE, /* partial_inplace */
8a397dad
TS
1604 0, /* src_mask */
1605 0, /* dst_mask */
b34976b6 1606 FALSE); /* pcrel_offset */
8a397dad 1607\f
d0c728db
TS
1608/* 16 bit offset for pc-relative branches. */
1609static reloc_howto_type elf_mips_gnu_rel16_s2 =
1610 HOWTO (R_MIPS_GNU_REL16_S2, /* type */
1611 2, /* rightshift */
1612 2, /* size (0 = byte, 1 = short, 2 = long) */
1613 16, /* bitsize */
1614 TRUE, /* pc_relative */
1615 0, /* bitpos */
1616 complain_overflow_signed, /* complain_on_overflow */
30ac9238 1617 _bfd_mips_elf_generic_reloc, /* special_function */
d0c728db
TS
1618 "R_MIPS_GNU_REL16_S2", /* name */
1619 TRUE, /* partial_inplace */
1620 0x0000ffff, /* src_mask */
1621 0x0000ffff, /* dst_mask */
1622 TRUE); /* pcrel_offset */
1623
1624/* 16 bit offset for pc-relative branches. */
1625static reloc_howto_type elf_mips_gnu_rela16_s2 =
1626 HOWTO (R_MIPS_GNU_REL16_S2, /* type */
1627 2, /* rightshift */
1628 2, /* size (0 = byte, 1 = short, 2 = long) */
1629 16, /* bitsize */
1630 TRUE, /* pc_relative */
1631 0, /* bitpos */
1632 complain_overflow_signed, /* complain_on_overflow */
30ac9238 1633 _bfd_mips_elf_generic_reloc, /* special_function */
d0c728db
TS
1634 "R_MIPS_GNU_REL16_S2", /* name */
1635 FALSE, /* partial_inplace */
1636 0, /* src_mask */
1637 0x0000ffff, /* dst_mask */
1638 TRUE); /* pcrel_offset */
1639\f
b34976b6 1640/* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a
8a397dad
TS
1641 dangerous relocation. */
1642
b34976b6 1643static bfd_boolean
11a2be4d 1644mips_elf_assign_gp (bfd *output_bfd, bfd_vma *pgp)
8a397dad
TS
1645{
1646 unsigned int count;
1647 asymbol **sym;
1648 unsigned int i;
1649
1650 /* If we've already figured out what GP will be, just return it. */
1651 *pgp = _bfd_get_gp_value (output_bfd);
1652 if (*pgp)
b34976b6 1653 return TRUE;
8a397dad
TS
1654
1655 count = bfd_get_symcount (output_bfd);
1656 sym = bfd_get_outsymbols (output_bfd);
1657
1658 /* The linker script will have created a symbol named `_gp' with the
1659 appropriate value. */
11a2be4d 1660 if (sym == NULL)
8a397dad
TS
1661 i = count;
1662 else
1663 {
1664 for (i = 0; i < count; i++, sym++)
1665 {
1666 register const char *name;
1667
1668 name = bfd_asymbol_name (*sym);
1669 if (*name == '_' && strcmp (name, "_gp") == 0)
1670 {
1671 *pgp = bfd_asymbol_value (*sym);
1672 _bfd_set_gp_value (output_bfd, *pgp);
1673 break;
1674 }
1675 }
1676 }
1677
1678 if (i >= count)
1679 {
1680 /* Only get the error once. */
1681 *pgp = 4;
1682 _bfd_set_gp_value (output_bfd, *pgp);
b34976b6 1683 return FALSE;
8a397dad
TS
1684 }
1685
b34976b6 1686 return TRUE;
8a397dad
TS
1687}
1688
1689/* We have to figure out the gp value, so that we can adjust the
1690 symbol value correctly. We look up the symbol _gp in the output
1691 BFD. If we can't find it, we're stuck. We cache it in the ELF
1692 target data. We don't need to adjust the symbol value for an
1049f94e 1693 external symbol if we are producing relocatable output. */
8a397dad
TS
1694
1695static bfd_reloc_status_type
11a2be4d
RS
1696mips_elf_final_gp (bfd *output_bfd, asymbol *symbol, bfd_boolean relocatable,
1697 char **error_message, bfd_vma *pgp)
8a397dad
TS
1698{
1699 if (bfd_is_und_section (symbol->section)
1049f94e 1700 && ! relocatable)
8a397dad
TS
1701 {
1702 *pgp = 0;
1703 return bfd_reloc_undefined;
1704 }
1705
1706 *pgp = _bfd_get_gp_value (output_bfd);
1707 if (*pgp == 0
1049f94e 1708 && (! relocatable
8a397dad
TS
1709 || (symbol->flags & BSF_SECTION_SYM) != 0))
1710 {
1049f94e 1711 if (relocatable)
8a397dad
TS
1712 {
1713 /* Make up a value. */
a902ee94 1714 *pgp = symbol->section->output_section->vma /*+ 0x4000*/;
8a397dad
TS
1715 _bfd_set_gp_value (output_bfd, *pgp);
1716 }
1717 else if (!mips_elf_assign_gp (output_bfd, pgp))
1718 {
1719 *error_message =
1720 (char *) _("GP relative relocation when _gp not defined");
1721 return bfd_reloc_dangerous;
1722 }
1723 }
1724
1725 return bfd_reloc_ok;
1726}
1727
1728/* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1729 become the offset from the gp register. */
1730
1731static bfd_reloc_status_type
11a2be4d
RS
1732mips_elf_gprel16_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
1733 asymbol *symbol, void *data ATTRIBUTE_UNUSED,
1734 asection *input_section, bfd *output_bfd,
1735 char **error_message ATTRIBUTE_UNUSED)
8a397dad 1736{
1049f94e 1737 bfd_boolean relocatable;
8a397dad
TS
1738 bfd_reloc_status_type ret;
1739 bfd_vma gp;
1740
11a2be4d 1741 if (output_bfd != NULL)
1049f94e 1742 relocatable = TRUE;
8a397dad
TS
1743 else
1744 {
1049f94e 1745 relocatable = FALSE;
8a397dad
TS
1746 output_bfd = symbol->section->output_section->owner;
1747 }
1748
1049f94e 1749 ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
8a397dad
TS
1750 &gp);
1751 if (ret != bfd_reloc_ok)
1752 return ret;
1753
1754 return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1049f94e 1755 input_section, relocatable,
8a397dad
TS
1756 data, gp);
1757}
1758
1759/* Do a R_MIPS_LITERAL relocation. */
1760
1761static bfd_reloc_status_type
11a2be4d
RS
1762mips_elf_literal_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1763 void *data, asection *input_section, bfd *output_bfd,
1764 char **error_message)
8a397dad 1765{
1049f94e 1766 bfd_boolean relocatable;
8a397dad
TS
1767 bfd_reloc_status_type ret;
1768 bfd_vma gp;
1769
254f0426
MR
1770 /* R_MIPS_LITERAL relocations are defined for local symbols only. */
1771 if (output_bfd != NULL
1772 && (symbol->flags & BSF_SECTION_SYM) == 0
1773 && (symbol->flags & BSF_LOCAL) != 0)
1774 {
1775 *error_message = (char *)
1776 _("literal relocation occurs for an external symbol");
1777 return bfd_reloc_outofrange;
1778 }
1779
8a397dad 1780 /* FIXME: The entries in the .lit8 and .lit4 sections should be merged. */
11a2be4d 1781 if (output_bfd != NULL)
1049f94e 1782 relocatable = TRUE;
8a397dad
TS
1783 else
1784 {
1049f94e 1785 relocatable = FALSE;
8a397dad
TS
1786 output_bfd = symbol->section->output_section->owner;
1787 }
1788
1049f94e 1789 ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
8a397dad
TS
1790 &gp);
1791 if (ret != bfd_reloc_ok)
1792 return ret;
1793
1794 return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1049f94e 1795 input_section, relocatable,
8a397dad
TS
1796 data, gp);
1797}
1798
1799/* Do a R_MIPS_GPREL32 relocation. This is a 32 bit value which must
1800 become the offset from the gp register. */
1801
1802static bfd_reloc_status_type
11a2be4d
RS
1803mips_elf_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1804 void *data, asection *input_section, bfd *output_bfd,
1805 char **error_message)
8a397dad 1806{
1049f94e 1807 bfd_boolean relocatable;
8a397dad
TS
1808 bfd_reloc_status_type ret;
1809 bfd_vma gp;
1810
a7ebbfdf 1811 /* R_MIPS_GPREL32 relocations are defined for local symbols only. */
11a2be4d 1812 if (output_bfd != NULL
8a397dad 1813 && (symbol->flags & BSF_SECTION_SYM) == 0
a7ebbfdf 1814 && (symbol->flags & BSF_LOCAL) != 0)
8a397dad
TS
1815 {
1816 *error_message = (char *)
1817 _("32bits gp relative relocation occurs for an external symbol");
1818 return bfd_reloc_outofrange;
1819 }
1820
11a2be4d 1821 if (output_bfd != NULL)
8a397dad 1822 {
1049f94e 1823 relocatable = TRUE;
8a397dad
TS
1824 gp = _bfd_get_gp_value (output_bfd);
1825 }
1826 else
1827 {
1049f94e 1828 relocatable = FALSE;
8a397dad
TS
1829 output_bfd = symbol->section->output_section->owner;
1830
1049f94e 1831 ret = mips_elf_final_gp (output_bfd, symbol, relocatable,
8a397dad
TS
1832 error_message, &gp);
1833 if (ret != bfd_reloc_ok)
1834 return ret;
1835 }
1836
1837 return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
1049f94e 1838 relocatable, data, gp);
8a397dad
TS
1839}
1840
1841static bfd_reloc_status_type
11a2be4d
RS
1842gprel32_with_gp (bfd *abfd, asymbol *symbol, arelent *reloc_entry,
1843 asection *input_section, bfd_boolean relocatable,
1844 void *data, bfd_vma gp)
8a397dad
TS
1845{
1846 bfd_vma relocation;
1847 unsigned long val;
1848
1849 if (bfd_is_com_section (symbol->section))
1850 relocation = 0;
1851 else
1852 relocation = symbol->value;
1853
1854 relocation += symbol->section->output_section->vma;
1855 relocation += symbol->section->output_offset;
1856
07515404 1857 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
8a397dad
TS
1858 return bfd_reloc_outofrange;
1859
1860 if (reloc_entry->howto->src_mask == 0)
1861 val = 0;
1862 else
1863 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1864
1865 /* Set val to the offset into the section or symbol. */
1866 val += reloc_entry->addend;
1867
1868 /* Adjust val for the final section location and GP value. If we
1049f94e 1869 are producing relocatable output, we don't want to do this for
8a397dad 1870 an external symbol. */
1049f94e 1871 if (! relocatable
8a397dad
TS
1872 || (symbol->flags & BSF_SECTION_SYM) != 0)
1873 val += relocation - gp;
1874
11a2be4d 1875 bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
8a397dad 1876
1049f94e 1877 if (relocatable)
8a397dad
TS
1878 reloc_entry->address += input_section->output_offset;
1879
1880 return bfd_reloc_ok;
1881}
1882
1883/* Do a R_MIPS_SHIFT6 relocation. The MSB of the shift is stored at bit 2,
1884 the rest is at bits 6-10. The bitpos already got right by the howto. */
1885
1886static bfd_reloc_status_type
30ac9238
RS
1887mips_elf_shift6_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1888 void *data, asection *input_section, bfd *output_bfd,
1889 char **error_message)
8a397dad 1890{
a7ebbfdf
TS
1891 if (reloc_entry->howto->partial_inplace)
1892 {
1893 reloc_entry->addend = ((reloc_entry->addend & 0x00007c0)
1894 | (reloc_entry->addend & 0x00000800) >> 9);
1895 }
8a397dad 1896
30ac9238
RS
1897 return _bfd_mips_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1898 input_section, output_bfd,
1899 error_message);
8a397dad
TS
1900}
1901\f
8a397dad
TS
1902/* Handle a mips16 GP relative reloc. */
1903
1904static bfd_reloc_status_type
11a2be4d
RS
1905mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1906 void *data, asection *input_section, bfd *output_bfd,
1907 char **error_message)
8a397dad 1908{
1049f94e 1909 bfd_boolean relocatable;
8a397dad 1910 bfd_reloc_status_type ret;
d6f16593 1911 bfd_byte *location;
8a397dad 1912 bfd_vma gp;
8a397dad 1913
7f05722e
MR
1914 /* If we're relocating, and this is an external symbol, we don't want
1915 to change anything. */
1916 if (output_bfd != NULL
1917 && (symbol->flags & BSF_SECTION_SYM) == 0
1918 && (symbol->flags & BSF_LOCAL) != 0)
1919 {
1920 reloc_entry->address += input_section->output_offset;
1921 return bfd_reloc_ok;
1922 }
1923
8a397dad 1924 if (output_bfd != NULL)
1049f94e 1925 relocatable = TRUE;
8a397dad
TS
1926 else
1927 {
1049f94e 1928 relocatable = FALSE;
8a397dad
TS
1929 output_bfd = symbol->section->output_section->owner;
1930 }
1931
1049f94e 1932 ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
8a397dad
TS
1933 &gp);
1934 if (ret != bfd_reloc_ok)
1935 return ret;
1936
d6f16593
MR
1937 location = (bfd_byte *) data + reloc_entry->address;
1938 _bfd_mips16_elf_reloc_unshuffle (abfd, reloc_entry->howto->type, FALSE,
1939 location);
1940 ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1941 input_section, relocatable,
1942 data, gp);
1943 _bfd_mips16_elf_reloc_shuffle (abfd, reloc_entry->howto->type, !relocatable,
1944 location);
8a397dad 1945
d6f16593 1946 return ret;
8a397dad 1947}
8a397dad
TS
1948\f
1949/* A mapping from BFD reloc types to MIPS ELF reloc types. */
1950
1951struct elf_reloc_map {
1952 bfd_reloc_code_real_type bfd_val;
1953 enum elf_mips_reloc_type elf_val;
1954};
1955
1956static const struct elf_reloc_map mips_reloc_map[] =
1957{
1958 { BFD_RELOC_NONE, R_MIPS_NONE },
1959 { BFD_RELOC_16, R_MIPS_16 },
1960 { BFD_RELOC_32, R_MIPS_32 },
1961 /* There is no BFD reloc for R_MIPS_REL32. */
1962 { BFD_RELOC_CTOR, R_MIPS_32 },
1963 { BFD_RELOC_64, R_MIPS_64 },
bad36eac 1964 { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
8a397dad
TS
1965 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
1966 { BFD_RELOC_LO16, R_MIPS_LO16 },
1967 { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
1968 { BFD_RELOC_GPREL32, R_MIPS_GPREL32 },
1969 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
1970 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
1971 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
1972 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
1973 { BFD_RELOC_MIPS_SHIFT5, R_MIPS_SHIFT5 },
1974 { BFD_RELOC_MIPS_SHIFT6, R_MIPS_SHIFT6 },
1975 { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP },
1976 { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
1977 { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
1978 { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
1979 { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
1980 { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
1981 { BFD_RELOC_MIPS_INSERT_A, R_MIPS_INSERT_A },
1982 { BFD_RELOC_MIPS_INSERT_B, R_MIPS_INSERT_B },
1983 { BFD_RELOC_MIPS_DELETE, R_MIPS_DELETE },
1984 { BFD_RELOC_MIPS_HIGHEST, R_MIPS_HIGHEST },
1985 { BFD_RELOC_MIPS_HIGHER, R_MIPS_HIGHER },
1986 { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
1987 { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
1988 { BFD_RELOC_MIPS_SCN_DISP, R_MIPS_SCN_DISP },
1989 { BFD_RELOC_MIPS_REL16, R_MIPS_REL16 },
1990 /* Use of R_MIPS_ADD_IMMEDIATE and R_MIPS_PJUMP is deprecated. */
1991 { BFD_RELOC_MIPS_RELGOT, R_MIPS_RELGOT },
0f20cc35
DJ
1992 { BFD_RELOC_MIPS_JALR, R_MIPS_JALR },
1993 { BFD_RELOC_MIPS_TLS_DTPMOD32, R_MIPS_TLS_DTPMOD32 },
1994 { BFD_RELOC_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL32 },
1995 { BFD_RELOC_MIPS_TLS_DTPMOD64, R_MIPS_TLS_DTPMOD64 },
1996 { BFD_RELOC_MIPS_TLS_DTPREL64, R_MIPS_TLS_DTPREL64 },
1997 { BFD_RELOC_MIPS_TLS_GD, R_MIPS_TLS_GD },
1998 { BFD_RELOC_MIPS_TLS_LDM, R_MIPS_TLS_LDM },
1999 { BFD_RELOC_MIPS_TLS_DTPREL_HI16, R_MIPS_TLS_DTPREL_HI16 },
2000 { BFD_RELOC_MIPS_TLS_DTPREL_LO16, R_MIPS_TLS_DTPREL_LO16 },
2001 { BFD_RELOC_MIPS_TLS_GOTTPREL, R_MIPS_TLS_GOTTPREL },
2002 { BFD_RELOC_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL32 },
2003 { BFD_RELOC_MIPS_TLS_TPREL64, R_MIPS_TLS_TPREL64 },
2004 { BFD_RELOC_MIPS_TLS_TPREL_HI16, R_MIPS_TLS_TPREL_HI16 },
2005 { BFD_RELOC_MIPS_TLS_TPREL_LO16, R_MIPS_TLS_TPREL_LO16 }
8a397dad
TS
2006};
2007
d6f16593
MR
2008static const struct elf_reloc_map mips16_reloc_map[] =
2009{
2010 { BFD_RELOC_MIPS16_JMP, R_MIPS16_26 - R_MIPS16_min },
2011 { BFD_RELOC_MIPS16_GPREL, R_MIPS16_GPREL - R_MIPS16_min },
2012 { BFD_RELOC_MIPS16_HI16_S, R_MIPS16_HI16 - R_MIPS16_min },
2013 { BFD_RELOC_MIPS16_LO16, R_MIPS16_LO16 - R_MIPS16_min },
2014};
2015
8a397dad
TS
2016/* Given a BFD reloc type, return a howto structure. */
2017
2018static reloc_howto_type *
11a2be4d
RS
2019bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2020 bfd_reloc_code_real_type code)
8a397dad
TS
2021{
2022 unsigned int i;
2023 /* FIXME: We default to RELA here instead of choosing the right
2024 relocation variant. */
2025 reloc_howto_type *howto_table = elf_mips_howto_table_rela;
d6f16593 2026 reloc_howto_type *howto16_table = elf_mips16_howto_table_rela;
8a397dad
TS
2027
2028 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map);
2029 i++)
2030 {
2031 if (mips_reloc_map[i].bfd_val == code)
2032 return &howto_table[(int) mips_reloc_map[i].elf_val];
2033 }
2034
d6f16593
MR
2035 for (i = 0; i < sizeof (mips16_reloc_map) / sizeof (struct elf_reloc_map);
2036 i++)
2037 {
2038 if (mips16_reloc_map[i].bfd_val == code)
2039 return &howto16_table[(int) mips16_reloc_map[i].elf_val];
2040 }
2041
8a397dad
TS
2042 switch (code)
2043 {
8a397dad
TS
2044 case BFD_RELOC_VTABLE_INHERIT:
2045 return &elf_mips_gnu_vtinherit_howto;
2046 case BFD_RELOC_VTABLE_ENTRY:
2047 return &elf_mips_gnu_vtentry_howto;
2048 default:
2049 bfd_set_error (bfd_error_bad_value);
2050 return NULL;
2051 }
2052}
2053
947216bf 2054/* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
8a397dad
TS
2055
2056static reloc_howto_type *
11a2be4d 2057mips_elf_n32_rtype_to_howto (unsigned int r_type, bfd_boolean rela_p)
8a397dad
TS
2058{
2059 switch (r_type)
2060 {
8a397dad
TS
2061 case R_MIPS_GNU_VTINHERIT:
2062 return &elf_mips_gnu_vtinherit_howto;
2063 case R_MIPS_GNU_VTENTRY:
2064 return &elf_mips_gnu_vtentry_howto;
d0c728db
TS
2065 case R_MIPS_GNU_REL16_S2:
2066 if (rela_p)
2067 return &elf_mips_gnu_rela16_s2;
2068 else
2069 return &elf_mips_gnu_rel16_s2;
8a397dad 2070 default:
d6f16593
MR
2071 if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max)
2072 {
2073 if (rela_p)
2074 return &elf_mips16_howto_table_rela[r_type - R_MIPS16_min];
2075 else
2076 return &elf_mips16_howto_table_rel[r_type - R_MIPS16_min];
2077 }
8a397dad
TS
2078 BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
2079 if (rela_p)
2080 return &elf_mips_howto_table_rela[r_type];
2081 else
2082 return &elf_mips_howto_table_rel[r_type];
2083 break;
2084 }
2085}
2086
947216bf 2087/* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
8a397dad
TS
2088
2089static void
11a2be4d 2090mips_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
8a397dad
TS
2091{
2092 unsigned int r_type;
2093
2094 r_type = ELF32_R_TYPE (dst->r_info);
b34976b6 2095 cache_ptr->howto = mips_elf_n32_rtype_to_howto (r_type, FALSE);
8a397dad
TS
2096
2097 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
2098 value for the object file. We get the addend now, rather than
2099 when we do the relocation, because the symbol manipulations done
2100 by the linker may cause us to lose track of the input BFD. */
2101 if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
2102 && (r_type == (unsigned int) R_MIPS_GPREL16
2103 || r_type == (unsigned int) R_MIPS_LITERAL))
2104 cache_ptr->addend = elf_gp (abfd);
2105}
2106
947216bf 2107/* Given a MIPS Elf_Internal_Rela, fill in an arelent structure. */
8a397dad
TS
2108
2109static void
11a2be4d
RS
2110mips_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
2111 arelent *cache_ptr, Elf_Internal_Rela *dst)
8a397dad
TS
2112{
2113 unsigned int r_type;
2114
2115 r_type = ELF32_R_TYPE (dst->r_info);
b34976b6 2116 cache_ptr->howto = mips_elf_n32_rtype_to_howto (r_type, TRUE);
8a397dad
TS
2117 cache_ptr->addend = dst->r_addend;
2118}
2119\f
2120/* Determine whether a symbol is global for the purposes of splitting
2121 the symbol table into global symbols and local symbols. At least
2122 on Irix 5, this split must be between section symbols and all other
2123 symbols. On most ELF targets the split is between static symbols
2124 and externally visible symbols. */
2125
b34976b6 2126static bfd_boolean
11a2be4d 2127mips_elf_sym_is_global (bfd *abfd ATTRIBUTE_UNUSED, asymbol *sym)
8a397dad
TS
2128{
2129 if (SGI_COMPAT (abfd))
2130 return (sym->flags & BSF_SECTION_SYM) == 0;
2131 else
2132 return ((sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0
2133 || bfd_is_und_section (bfd_get_section (sym))
2134 || bfd_is_com_section (bfd_get_section (sym)));
2135}
2136\f
2137/* Set the right machine number for a MIPS ELF file. */
2138
b34976b6 2139static bfd_boolean
11a2be4d 2140mips_elf_n32_object_p (bfd *abfd)
8a397dad
TS
2141{
2142 unsigned long mach;
2143
2144 /* Irix 5 and 6 are broken. Object file symbol tables are not always
2145 sorted correctly such that local symbols precede global symbols,
2146 and the sh_info field in the symbol table is not always right. */
2147 if (SGI_COMPAT (abfd))
b34976b6 2148 elf_bad_symtab (abfd) = TRUE;
8a397dad
TS
2149
2150 mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
2151 bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
2152
2153 if (! ABI_N32_P(abfd))
b34976b6 2154 return FALSE;
8a397dad 2155
b34976b6 2156 return TRUE;
8a397dad
TS
2157}
2158\f
2159/* Support for core dump NOTE sections. */
b34976b6 2160static bfd_boolean
11a2be4d 2161elf32_mips_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
8a397dad
TS
2162{
2163 int offset;
eea6121a 2164 unsigned int size;
8a397dad
TS
2165
2166 switch (note->descsz)
2167 {
2168 default:
b34976b6 2169 return FALSE;
8a397dad 2170
59a8c196 2171 case 440: /* Linux/MIPS N32 */
8a397dad
TS
2172 /* pr_cursig */
2173 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
2174
2175 /* pr_pid */
2176 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
2177
2178 /* pr_reg */
2179 offset = 72;
eea6121a 2180 size = 360;
8a397dad
TS
2181
2182 break;
2183 }
2184
2185 /* Make a ".reg/999" section. */
eea6121a 2186 return _bfd_elfcore_make_pseudosection (abfd, ".reg", size,
8a397dad
TS
2187 note->descpos + offset);
2188}
2189
b34976b6 2190static bfd_boolean
11a2be4d 2191elf32_mips_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
8a397dad
TS
2192{
2193 switch (note->descsz)
2194 {
2195 default:
b34976b6 2196 return FALSE;
8a397dad
TS
2197
2198 case 128: /* Linux/MIPS elf_prpsinfo */
2199 elf_tdata (abfd)->core_program
2200 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
2201 elf_tdata (abfd)->core_command
2202 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
2203 }
2204
2205 /* Note that for some reason, a spurious space is tacked
2206 onto the end of the args in some (at least one anyway)
2207 implementations, so strip it off if it exists. */
2208
2209 {
2210 char *command = elf_tdata (abfd)->core_command;
2211 int n = strlen (command);
2212
2213 if (0 < n && command[n - 1] == ' ')
2214 command[n - 1] = '\0';
2215 }
2216
b34976b6 2217 return TRUE;
8a397dad
TS
2218}
2219\f
2220/* Depending on the target vector we generate some version of Irix
2221 executables or "normal" MIPS ELF ABI executables. */
2222static irix_compat_t
11a2be4d 2223elf_n32_mips_irix_compat (bfd *abfd)
8a397dad
TS
2224{
2225 if ((abfd->xvec == &bfd_elf32_nbigmips_vec)
2226 || (abfd->xvec == &bfd_elf32_nlittlemips_vec))
2227 return ict_irix6;
2228 else
2229 return ict_none;
2230}
2231\f
2232/* ECOFF swapping routines. These are used when dealing with the
2233 .mdebug section, which is in the ECOFF debugging format. */
2234static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
2235 /* Symbol table magic number. */
2236 magicSym,
2237 /* Alignment of debugging information. E.g., 4. */
2238 4,
2239 /* Sizes of external symbolic information. */
2240 sizeof (struct hdr_ext),
2241 sizeof (struct dnr_ext),
2242 sizeof (struct pdr_ext),
2243 sizeof (struct sym_ext),
2244 sizeof (struct opt_ext),
2245 sizeof (struct fdr_ext),
2246 sizeof (struct rfd_ext),
2247 sizeof (struct ext_ext),
2248 /* Functions to swap in external symbolic data. */
2249 ecoff_swap_hdr_in,
2250 ecoff_swap_dnr_in,
2251 ecoff_swap_pdr_in,
2252 ecoff_swap_sym_in,
2253 ecoff_swap_opt_in,
2254 ecoff_swap_fdr_in,
2255 ecoff_swap_rfd_in,
2256 ecoff_swap_ext_in,
2257 _bfd_ecoff_swap_tir_in,
2258 _bfd_ecoff_swap_rndx_in,
2259 /* Functions to swap out external symbolic data. */
2260 ecoff_swap_hdr_out,
2261 ecoff_swap_dnr_out,
2262 ecoff_swap_pdr_out,
2263 ecoff_swap_sym_out,
2264 ecoff_swap_opt_out,
2265 ecoff_swap_fdr_out,
2266 ecoff_swap_rfd_out,
2267 ecoff_swap_ext_out,
2268 _bfd_ecoff_swap_tir_out,
2269 _bfd_ecoff_swap_rndx_out,
2270 /* Function to read in symbolic data. */
2271 _bfd_mips_elf_read_ecoff_info
2272};
2273\f
2274#define ELF_ARCH bfd_arch_mips
2275#define ELF_MACHINE_CODE EM_MIPS
2276
b34976b6
AM
2277#define elf_backend_collect TRUE
2278#define elf_backend_type_change_ok TRUE
2279#define elf_backend_can_gc_sections TRUE
8a397dad
TS
2280#define elf_info_to_howto mips_info_to_howto_rela
2281#define elf_info_to_howto_rel mips_info_to_howto_rel
2282#define elf_backend_sym_is_global mips_elf_sym_is_global
2283#define elf_backend_object_p mips_elf_n32_object_p
2284#define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
2285#define elf_backend_section_processing _bfd_mips_elf_section_processing
2286#define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
2287#define elf_backend_fake_sections _bfd_mips_elf_fake_sections
2288#define elf_backend_section_from_bfd_section \
2289 _bfd_mips_elf_section_from_bfd_section
2290#define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
2291#define elf_backend_link_output_symbol_hook \
2292 _bfd_mips_elf_link_output_symbol_hook
2293#define elf_backend_create_dynamic_sections \
2294 _bfd_mips_elf_create_dynamic_sections
2295#define elf_backend_check_relocs _bfd_mips_elf_check_relocs
8992f0d7
TS
2296#define elf_backend_merge_symbol_attribute \
2297 _bfd_mips_elf_merge_symbol_attribute
8a397dad
TS
2298#define elf_backend_adjust_dynamic_symbol \
2299 _bfd_mips_elf_adjust_dynamic_symbol
2300#define elf_backend_always_size_sections \
2301 _bfd_mips_elf_always_size_sections
2302#define elf_backend_size_dynamic_sections \
2303 _bfd_mips_elf_size_dynamic_sections
74541ad4 2304#define elf_backend_init_index_section _bfd_elf_init_1_index_section
8a397dad
TS
2305#define elf_backend_relocate_section _bfd_mips_elf_relocate_section
2306#define elf_backend_finish_dynamic_symbol \
2307 _bfd_mips_elf_finish_dynamic_symbol
2308#define elf_backend_finish_dynamic_sections \
2309 _bfd_mips_elf_finish_dynamic_sections
2310#define elf_backend_final_write_processing \
2311 _bfd_mips_elf_final_write_processing
2312#define elf_backend_additional_program_headers \
2313 _bfd_mips_elf_additional_program_headers
2314#define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
2315#define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
2316#define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
2317#define elf_backend_copy_indirect_symbol \
2318 _bfd_mips_elf_copy_indirect_symbol
2319#define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
2320#define elf_backend_grok_prstatus elf32_mips_grok_prstatus
2321#define elf_backend_grok_psinfo elf32_mips_grok_psinfo
2322#define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
2323
2324#define elf_backend_got_header_size (4 * MIPS_RESERVED_GOTNO)
8a397dad
TS
2325
2326/* MIPS n32 ELF can use a mixture of REL and RELA, but some Relocations
2327 work better/work only in RELA, so we default to this. */
2328#define elf_backend_may_use_rel_p 1
2329#define elf_backend_may_use_rela_p 1
2330#define elf_backend_default_use_rela_p 1
b34976b6 2331#define elf_backend_sign_extend_vma TRUE
8a397dad
TS
2332
2333#define elf_backend_discard_info _bfd_mips_elf_discard_info
2334#define elf_backend_ignore_discarded_relocs \
2335 _bfd_mips_elf_ignore_discarded_relocs
2336#define elf_backend_write_section _bfd_mips_elf_write_section
2337#define elf_backend_mips_irix_compat elf_n32_mips_irix_compat
2338#define elf_backend_mips_rtype_to_howto mips_elf_n32_rtype_to_howto
2339#define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
4ab527b0 2340#define bfd_elf32_find_inliner_info _bfd_mips_elf_find_inliner_info
f0abc2a1 2341#define bfd_elf32_new_section_hook _bfd_mips_elf_new_section_hook
8a397dad
TS
2342#define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
2343#define bfd_elf32_bfd_get_relocated_section_contents \
2344 _bfd_elf_mips_get_relocated_section_contents
2345#define bfd_elf32_bfd_link_hash_table_create \
2346 _bfd_mips_elf_link_hash_table_create
2347#define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
2348#define bfd_elf32_bfd_merge_private_bfd_data \
2349 _bfd_mips_elf_merge_private_bfd_data
2350#define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
2351#define bfd_elf32_bfd_print_private_bfd_data \
2352 _bfd_mips_elf_print_private_bfd_data
d0647110 2353#define bfd_elf32_bfd_relax_section _bfd_mips_relax_section
8a397dad
TS
2354
2355/* Support for SGI-ish mips targets using n32 ABI. */
2356
2357#define TARGET_LITTLE_SYM bfd_elf32_nlittlemips_vec
2358#define TARGET_LITTLE_NAME "elf32-nlittlemips"
2359#define TARGET_BIG_SYM bfd_elf32_nbigmips_vec
2360#define TARGET_BIG_NAME "elf32-nbigmips"
2361
7fd91fe0 2362#define ELF_MAXPAGESIZE 0x10000
24718e3b 2363#define ELF_COMMONPAGESIZE 0x1000
4301eeb1 2364
8a397dad
TS
2365#include "elf32-target.h"
2366
2367/* Support for traditional mips targets using n32 ABI. */
8a397dad
TS
2368#undef TARGET_LITTLE_SYM
2369#undef TARGET_LITTLE_NAME
2370#undef TARGET_BIG_SYM
2371#undef TARGET_BIG_NAME
2372
4301eeb1 2373#undef ELF_MAXPAGESIZE
7fd91fe0 2374#undef ELF_COMMONPAGESIZE
4301eeb1 2375
8a397dad
TS
2376#define TARGET_LITTLE_SYM bfd_elf32_ntradlittlemips_vec
2377#define TARGET_LITTLE_NAME "elf32-ntradlittlemips"
2378#define TARGET_BIG_SYM bfd_elf32_ntradbigmips_vec
2379#define TARGET_BIG_NAME "elf32-ntradbigmips"
2380
4301eeb1 2381#define ELF_MAXPAGESIZE 0x10000
7fd91fe0 2382#define ELF_COMMONPAGESIZE 0x1000
4301eeb1
MR
2383#define elf32_bed elf32_tradbed
2384
8a397dad
TS
2385/* Include the target file again for this target. */
2386#include "elf32-target.h"
This page took 0.411289 seconds and 4 git commands to generate.