]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - bfd/elf32-mips.c
gnu-nat: Move local functions inside gnu_nat_target class
[thirdparty/binutils-gdb.git] / bfd / elf32-mips.c
CommitLineData
efcbd82c 1/* MIPS-specific support for 32-bit ELF
b3adc24a 2 Copyright (C) 1993-2020 Free Software Foundation, Inc.
252b5132
RH
3
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
5 <ian@cygnus.com>.
103186c6
MM
6 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
7 <mark@codesourcery.com>
f7cb7d68
UC
8 Traditional MIPS targets support added by Koundinya.K, Dansk Data
9 Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
252b5132 10
cd123cb7 11 This file is part of BFD, the Binary File Descriptor library.
252b5132 12
cd123cb7
NC
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3 of the License, or
16 (at your option) any later version.
252b5132 17
cd123cb7
NC
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
26 MA 02110-1301, USA. */
252b5132 27
252b5132
RH
28
29/* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
30 different MIPS ELF from other targets. This matters when linking.
31 This file supports both, switching at runtime. */
32
252b5132 33#include "sysdep.h"
3db64b00 34#include "bfd.h"
252b5132
RH
35#include "libbfd.h"
36#include "bfdlink.h"
37#include "genlink.h"
38#include "elf-bfd.h"
c6e90b02 39#include "elfxx-mips.h"
252b5132 40#include "elf/mips.h"
0a44bf69 41#include "elf-vxworks.h"
252b5132
RH
42
43/* Get the ECOFF swapping routines. */
44#include "coff/sym.h"
45#include "coff/symconst.h"
46#include "coff/internal.h"
47#include "coff/ecoff.h"
48#include "coff/mips.h"
23e2c83b 49#define ECOFF_SIGNED_32
252b5132
RH
50#include "ecoffswap.h"
51
a7ebbfdf 52static bfd_reloc_status_type gprel32_with_gp
11a2be4d 53 (bfd *, asymbol *, arelent *, asection *, bfd_boolean, void *, bfd_vma);
c6e90b02 54static bfd_reloc_status_type mips_elf_gprel32_reloc
11a2be4d 55 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
252b5132 56static bfd_reloc_status_type mips32_64bit_reloc
11a2be4d 57 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
252b5132 58static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
11a2be4d 59 (bfd *, bfd_reloc_code_real_type);
f3185997 60static bfd_boolean mips_info_to_howto_rel
11a2be4d 61 (bfd *, arelent *, Elf_Internal_Rela *);
f3185997 62static bfd_boolean mips_info_to_howto_rela
11a2be4d 63 (bfd *, arelent *, Elf_Internal_Rela *);
b34976b6 64static bfd_boolean mips_elf_sym_is_global
11a2be4d 65 (bfd *, asymbol *);
b34976b6 66static bfd_boolean mips_elf32_object_p
11a2be4d 67 (bfd *);
b34976b6 68static bfd_boolean mips_elf_is_local_label_name
11a2be4d 69 (bfd *, const char *);
252b5132 70static bfd_reloc_status_type mips16_gprel_reloc
11a2be4d 71 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
252b5132 72static bfd_reloc_status_type mips_elf_final_gp
11a2be4d 73 (bfd *, asymbol *, bfd_boolean, char **, bfd_vma *);
b34976b6 74static bfd_boolean mips_elf_assign_gp
11a2be4d 75 (bfd *, bfd_vma *);
b34976b6 76static bfd_boolean elf32_mips_grok_prstatus
11a2be4d 77 (bfd *, Elf_Internal_Note *);
b34976b6 78static bfd_boolean elf32_mips_grok_psinfo
11a2be4d 79 (bfd *, Elf_Internal_Note *);
c6e90b02 80static irix_compat_t elf32_mips_irix_compat
11a2be4d 81 (bfd *);
252b5132 82
6d00b590
AM
83extern const bfd_target mips_elf32_be_vec;
84extern const bfd_target mips_elf32_le_vec;
adb76a3e 85
a94a7c1c 86/* Nonzero if ABFD is using the N32 ABI. */
a94a7c1c
MM
87#define ABI_N32_P(abfd) \
88 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
89
4e8a9624 90/* Whether we are trying to be compatible with IRIX at all. */
a94a7c1c 91#define SGI_COMPAT(abfd) \
c6e90b02 92 (elf32_mips_irix_compat (abfd) != ict_none)
103186c6 93
252b5132
RH
94/* The number of local .got entries we reserve. */
95#define MIPS_RESERVED_GOTNO (2)
96
3f830999
MM
97/* In case we're on a 32-bit machine, construct a 64-bit "-1" value
98 from smaller values. Start with zero, widen, *then* decrement. */
99#define MINUS_ONE (((bfd_vma)0) - 1)
100
d75bc93d
TS
101/* The relocation table used for SHT_REL sections. */
102
103static reloc_howto_type elf_mips_howto_table_rel[] =
104{
105 /* No relocation. */
106 HOWTO (R_MIPS_NONE, /* type */
107 0, /* rightshift */
6346d5ca 108 3, /* size (0 = byte, 1 = short, 2 = long) */
d75bc93d 109 0, /* bitsize */
b34976b6 110 FALSE, /* pc_relative */
d75bc93d
TS
111 0, /* bitpos */
112 complain_overflow_dont, /* complain_on_overflow */
30ac9238 113 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 114 "R_MIPS_NONE", /* name */
b34976b6 115 FALSE, /* partial_inplace */
d75bc93d
TS
116 0, /* src_mask */
117 0, /* dst_mask */
b34976b6 118 FALSE), /* pcrel_offset */
d75bc93d
TS
119
120 /* 16 bit relocation. */
121 HOWTO (R_MIPS_16, /* type */
122 0, /* rightshift */
123 2, /* size (0 = byte, 1 = short, 2 = long) */
124 16, /* bitsize */
b34976b6 125 FALSE, /* pc_relative */
d75bc93d
TS
126 0, /* bitpos */
127 complain_overflow_signed, /* complain_on_overflow */
30ac9238 128 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 129 "R_MIPS_16", /* name */
b34976b6 130 TRUE, /* partial_inplace */
d75bc93d
TS
131 0x0000ffff, /* src_mask */
132 0x0000ffff, /* dst_mask */
b34976b6 133 FALSE), /* pcrel_offset */
d75bc93d
TS
134
135 /* 32 bit relocation. */
136 HOWTO (R_MIPS_32, /* type */
137 0, /* rightshift */
138 2, /* size (0 = byte, 1 = short, 2 = long) */
139 32, /* bitsize */
b34976b6 140 FALSE, /* pc_relative */
d75bc93d
TS
141 0, /* bitpos */
142 complain_overflow_dont, /* complain_on_overflow */
30ac9238 143 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 144 "R_MIPS_32", /* name */
b34976b6 145 TRUE, /* partial_inplace */
d75bc93d
TS
146 0xffffffff, /* src_mask */
147 0xffffffff, /* dst_mask */
b34976b6 148 FALSE), /* pcrel_offset */
d75bc93d
TS
149
150 /* 32 bit symbol relative relocation. */
151 HOWTO (R_MIPS_REL32, /* type */
152 0, /* rightshift */
153 2, /* size (0 = byte, 1 = short, 2 = long) */
154 32, /* bitsize */
b34976b6 155 FALSE, /* pc_relative */
d75bc93d
TS
156 0, /* bitpos */
157 complain_overflow_dont, /* complain_on_overflow */
30ac9238 158 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 159 "R_MIPS_REL32", /* name */
b34976b6 160 TRUE, /* partial_inplace */
d75bc93d
TS
161 0xffffffff, /* src_mask */
162 0xffffffff, /* dst_mask */
b34976b6 163 FALSE), /* pcrel_offset */
d75bc93d
TS
164
165 /* 26 bit jump address. */
166 HOWTO (R_MIPS_26, /* type */
167 2, /* rightshift */
168 2, /* size (0 = byte, 1 = short, 2 = long) */
169 26, /* bitsize */
b34976b6 170 FALSE, /* pc_relative */
d75bc93d
TS
171 0, /* bitpos */
172 complain_overflow_dont, /* complain_on_overflow */
07d6d2b8 173 /* This needs complex overflow
d75bc93d
TS
174 detection, because the upper four
175 bits must match the PC + 4. */
30ac9238 176 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 177 "R_MIPS_26", /* name */
b34976b6 178 TRUE, /* partial_inplace */
d75bc93d
TS
179 0x03ffffff, /* src_mask */
180 0x03ffffff, /* dst_mask */
b34976b6 181 FALSE), /* pcrel_offset */
d75bc93d
TS
182
183 /* High 16 bits of symbol value. */
184 HOWTO (R_MIPS_HI16, /* type */
30ac9238 185 16, /* rightshift */
d75bc93d
TS
186 2, /* size (0 = byte, 1 = short, 2 = long) */
187 16, /* bitsize */
b34976b6 188 FALSE, /* pc_relative */
d75bc93d
TS
189 0, /* bitpos */
190 complain_overflow_dont, /* complain_on_overflow */
30ac9238 191 _bfd_mips_elf_hi16_reloc, /* special_function */
d75bc93d 192 "R_MIPS_HI16", /* name */
b34976b6 193 TRUE, /* partial_inplace */
d75bc93d
TS
194 0x0000ffff, /* src_mask */
195 0x0000ffff, /* dst_mask */
b34976b6 196 FALSE), /* pcrel_offset */
d75bc93d
TS
197
198 /* Low 16 bits of symbol value. */
199 HOWTO (R_MIPS_LO16, /* type */
200 0, /* rightshift */
201 2, /* size (0 = byte, 1 = short, 2 = long) */
202 16, /* bitsize */
b34976b6 203 FALSE, /* pc_relative */
d75bc93d
TS
204 0, /* bitpos */
205 complain_overflow_dont, /* complain_on_overflow */
30ac9238 206 _bfd_mips_elf_lo16_reloc, /* special_function */
d75bc93d 207 "R_MIPS_LO16", /* name */
b34976b6 208 TRUE, /* partial_inplace */
d75bc93d
TS
209 0x0000ffff, /* src_mask */
210 0x0000ffff, /* dst_mask */
b34976b6 211 FALSE), /* pcrel_offset */
d75bc93d
TS
212
213 /* GP relative reference. */
214 HOWTO (R_MIPS_GPREL16, /* type */
215 0, /* rightshift */
216 2, /* size (0 = byte, 1 = short, 2 = long) */
217 16, /* bitsize */
b34976b6 218 FALSE, /* pc_relative */
d75bc93d
TS
219 0, /* bitpos */
220 complain_overflow_signed, /* complain_on_overflow */
c6e90b02 221 _bfd_mips_elf32_gprel16_reloc, /* special_function */
d75bc93d 222 "R_MIPS_GPREL16", /* name */
b34976b6 223 TRUE, /* partial_inplace */
d75bc93d
TS
224 0x0000ffff, /* src_mask */
225 0x0000ffff, /* dst_mask */
b34976b6 226 FALSE), /* pcrel_offset */
d75bc93d
TS
227
228 /* Reference to literal section. */
229 HOWTO (R_MIPS_LITERAL, /* type */
230 0, /* rightshift */
231 2, /* size (0 = byte, 1 = short, 2 = long) */
232 16, /* bitsize */
b34976b6 233 FALSE, /* pc_relative */
d75bc93d
TS
234 0, /* bitpos */
235 complain_overflow_signed, /* complain_on_overflow */
c6e90b02 236 _bfd_mips_elf32_gprel16_reloc, /* special_function */
d75bc93d 237 "R_MIPS_LITERAL", /* name */
b34976b6 238 TRUE, /* partial_inplace */
d75bc93d
TS
239 0x0000ffff, /* src_mask */
240 0x0000ffff, /* dst_mask */
b34976b6 241 FALSE), /* pcrel_offset */
d75bc93d
TS
242
243 /* Reference to global offset table. */
244 HOWTO (R_MIPS_GOT16, /* type */
245 0, /* rightshift */
246 2, /* size (0 = byte, 1 = short, 2 = long) */
247 16, /* bitsize */
b34976b6 248 FALSE, /* pc_relative */
d75bc93d
TS
249 0, /* bitpos */
250 complain_overflow_signed, /* complain_on_overflow */
30ac9238 251 _bfd_mips_elf_got16_reloc, /* special_function */
d75bc93d 252 "R_MIPS_GOT16", /* name */
b34976b6 253 TRUE, /* partial_inplace */
d75bc93d
TS
254 0x0000ffff, /* src_mask */
255 0x0000ffff, /* dst_mask */
b34976b6 256 FALSE), /* pcrel_offset */
d75bc93d 257
bad36eac
DJ
258 /* 16 bit PC relative reference. Note that the ABI document has a typo
259 and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
260 We do the right thing here. */
d75bc93d 261 HOWTO (R_MIPS_PC16, /* type */
bad36eac 262 2, /* rightshift */
d75bc93d
TS
263 2, /* size (0 = byte, 1 = short, 2 = long) */
264 16, /* bitsize */
b34976b6 265 TRUE, /* pc_relative */
d75bc93d
TS
266 0, /* bitpos */
267 complain_overflow_signed, /* complain_on_overflow */
30ac9238 268 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 269 "R_MIPS_PC16", /* name */
b34976b6 270 TRUE, /* partial_inplace */
d75bc93d
TS
271 0x0000ffff, /* src_mask */
272 0x0000ffff, /* dst_mask */
b34976b6 273 TRUE), /* pcrel_offset */
d75bc93d
TS
274
275 /* 16 bit call through global offset table. */
276 HOWTO (R_MIPS_CALL16, /* type */
277 0, /* rightshift */
278 2, /* size (0 = byte, 1 = short, 2 = long) */
279 16, /* bitsize */
b34976b6 280 FALSE, /* pc_relative */
d75bc93d
TS
281 0, /* bitpos */
282 complain_overflow_signed, /* complain_on_overflow */
30ac9238 283 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 284 "R_MIPS_CALL16", /* name */
b34976b6 285 TRUE, /* partial_inplace */
d75bc93d
TS
286 0x0000ffff, /* src_mask */
287 0x0000ffff, /* dst_mask */
b34976b6 288 FALSE), /* pcrel_offset */
d75bc93d
TS
289
290 /* 32 bit GP relative reference. */
291 HOWTO (R_MIPS_GPREL32, /* type */
292 0, /* rightshift */
293 2, /* size (0 = byte, 1 = short, 2 = long) */
294 32, /* bitsize */
b34976b6 295 FALSE, /* pc_relative */
d75bc93d
TS
296 0, /* bitpos */
297 complain_overflow_dont, /* complain_on_overflow */
c6e90b02 298 mips_elf_gprel32_reloc, /* special_function */
d75bc93d 299 "R_MIPS_GPREL32", /* name */
b34976b6 300 TRUE, /* partial_inplace */
d75bc93d
TS
301 0xffffffff, /* src_mask */
302 0xffffffff, /* dst_mask */
b34976b6 303 FALSE), /* pcrel_offset */
d75bc93d
TS
304
305 /* The remaining relocs are defined on Irix 5, although they are
306 not defined by the ABI. */
307 EMPTY_HOWTO (13),
308 EMPTY_HOWTO (14),
309 EMPTY_HOWTO (15),
310
311 /* A 5 bit shift field. */
312 HOWTO (R_MIPS_SHIFT5, /* type */
313 0, /* rightshift */
314 2, /* size (0 = byte, 1 = short, 2 = long) */
315 5, /* bitsize */
b34976b6 316 FALSE, /* pc_relative */
d75bc93d
TS
317 6, /* bitpos */
318 complain_overflow_bitfield, /* complain_on_overflow */
30ac9238 319 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 320 "R_MIPS_SHIFT5", /* name */
b34976b6 321 TRUE, /* partial_inplace */
d75bc93d
TS
322 0x000007c0, /* src_mask */
323 0x000007c0, /* dst_mask */
b34976b6 324 FALSE), /* pcrel_offset */
d75bc93d
TS
325
326 /* A 6 bit shift field. */
327 /* FIXME: This is not handled correctly; a special function is
328 needed to put the most significant bit in the right place. */
329 HOWTO (R_MIPS_SHIFT6, /* type */
330 0, /* rightshift */
331 2, /* size (0 = byte, 1 = short, 2 = long) */
332 6, /* bitsize */
b34976b6 333 FALSE, /* pc_relative */
d75bc93d
TS
334 6, /* bitpos */
335 complain_overflow_bitfield, /* complain_on_overflow */
30ac9238 336 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 337 "R_MIPS_SHIFT6", /* name */
b34976b6 338 TRUE, /* partial_inplace */
d75bc93d
TS
339 0x000007c4, /* src_mask */
340 0x000007c4, /* dst_mask */
b34976b6 341 FALSE), /* pcrel_offset */
d75bc93d
TS
342
343 /* A 64 bit relocation. */
344 HOWTO (R_MIPS_64, /* type */
345 0, /* rightshift */
346 4, /* size (0 = byte, 1 = short, 2 = long) */
347 64, /* bitsize */
b34976b6 348 FALSE, /* pc_relative */
d75bc93d
TS
349 0, /* bitpos */
350 complain_overflow_dont, /* complain_on_overflow */
351 mips32_64bit_reloc, /* special_function */
352 "R_MIPS_64", /* name */
b34976b6 353 TRUE, /* partial_inplace */
d75bc93d
TS
354 MINUS_ONE, /* src_mask */
355 MINUS_ONE, /* dst_mask */
b34976b6 356 FALSE), /* pcrel_offset */
d75bc93d
TS
357
358 /* Displacement in the global offset table. */
359 HOWTO (R_MIPS_GOT_DISP, /* type */
360 0, /* rightshift */
361 2, /* size (0 = byte, 1 = short, 2 = long) */
362 16, /* bitsize */
b34976b6 363 FALSE, /* pc_relative */
d75bc93d
TS
364 0, /* bitpos */
365 complain_overflow_signed, /* complain_on_overflow */
30ac9238 366 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 367 "R_MIPS_GOT_DISP", /* name */
b34976b6 368 TRUE, /* partial_inplace */
d75bc93d
TS
369 0x0000ffff, /* src_mask */
370 0x0000ffff, /* dst_mask */
b34976b6 371 FALSE), /* pcrel_offset */
d75bc93d
TS
372
373 /* Displacement to page pointer in the global offset table. */
374 HOWTO (R_MIPS_GOT_PAGE, /* type */
375 0, /* rightshift */
376 2, /* size (0 = byte, 1 = short, 2 = long) */
377 16, /* bitsize */
b34976b6 378 FALSE, /* pc_relative */
d75bc93d
TS
379 0, /* bitpos */
380 complain_overflow_signed, /* complain_on_overflow */
30ac9238 381 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 382 "R_MIPS_GOT_PAGE", /* name */
b34976b6 383 TRUE, /* partial_inplace */
d75bc93d
TS
384 0x0000ffff, /* src_mask */
385 0x0000ffff, /* dst_mask */
b34976b6 386 FALSE), /* pcrel_offset */
d75bc93d
TS
387
388 /* Offset from page pointer in the global offset table. */
389 HOWTO (R_MIPS_GOT_OFST, /* type */
390 0, /* rightshift */
391 2, /* size (0 = byte, 1 = short, 2 = long) */
392 16, /* bitsize */
b34976b6 393 FALSE, /* pc_relative */
d75bc93d
TS
394 0, /* bitpos */
395 complain_overflow_signed, /* complain_on_overflow */
30ac9238 396 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 397 "R_MIPS_GOT_OFST", /* name */
b34976b6 398 TRUE, /* partial_inplace */
d75bc93d
TS
399 0x0000ffff, /* src_mask */
400 0x0000ffff, /* dst_mask */
b34976b6 401 FALSE), /* pcrel_offset */
d75bc93d
TS
402
403 /* High 16 bits of displacement in global offset table. */
404 HOWTO (R_MIPS_GOT_HI16, /* type */
405 0, /* rightshift */
406 2, /* size (0 = byte, 1 = short, 2 = long) */
407 16, /* bitsize */
b34976b6 408 FALSE, /* pc_relative */
d75bc93d
TS
409 0, /* bitpos */
410 complain_overflow_dont, /* complain_on_overflow */
30ac9238 411 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 412 "R_MIPS_GOT_HI16", /* name */
b34976b6 413 TRUE, /* partial_inplace */
d75bc93d
TS
414 0x0000ffff, /* src_mask */
415 0x0000ffff, /* dst_mask */
b34976b6 416 FALSE), /* pcrel_offset */
d75bc93d
TS
417
418 /* Low 16 bits of displacement in global offset table. */
419 HOWTO (R_MIPS_GOT_LO16, /* type */
420 0, /* rightshift */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
422 16, /* bitsize */
b34976b6 423 FALSE, /* pc_relative */
d75bc93d
TS
424 0, /* bitpos */
425 complain_overflow_dont, /* complain_on_overflow */
30ac9238 426 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 427 "R_MIPS_GOT_LO16", /* name */
b34976b6 428 TRUE, /* partial_inplace */
d75bc93d
TS
429 0x0000ffff, /* src_mask */
430 0x0000ffff, /* dst_mask */
b34976b6 431 FALSE), /* pcrel_offset */
d75bc93d
TS
432
433 /* 64 bit subtraction. Used in the N32 ABI. */
434 HOWTO (R_MIPS_SUB, /* type */
435 0, /* rightshift */
436 4, /* size (0 = byte, 1 = short, 2 = long) */
437 64, /* bitsize */
b34976b6 438 FALSE, /* pc_relative */
d75bc93d
TS
439 0, /* bitpos */
440 complain_overflow_dont, /* complain_on_overflow */
30ac9238 441 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 442 "R_MIPS_SUB", /* name */
b34976b6 443 TRUE, /* partial_inplace */
d75bc93d
TS
444 MINUS_ONE, /* src_mask */
445 MINUS_ONE, /* dst_mask */
b34976b6 446 FALSE), /* pcrel_offset */
d75bc93d
TS
447
448 /* Used to cause the linker to insert and delete instructions? */
449 EMPTY_HOWTO (R_MIPS_INSERT_A),
450 EMPTY_HOWTO (R_MIPS_INSERT_B),
451 EMPTY_HOWTO (R_MIPS_DELETE),
452
453 /* Get the higher value of a 64 bit addend. */
454 HOWTO (R_MIPS_HIGHER, /* type */
455 0, /* rightshift */
456 2, /* size (0 = byte, 1 = short, 2 = long) */
457 16, /* bitsize */
b34976b6 458 FALSE, /* pc_relative */
d75bc93d
TS
459 0, /* bitpos */
460 complain_overflow_dont, /* complain_on_overflow */
30ac9238 461 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 462 "R_MIPS_HIGHER", /* name */
b34976b6 463 TRUE, /* partial_inplace */
d75bc93d
TS
464 0x0000ffff, /* src_mask */
465 0x0000ffff, /* dst_mask */
b34976b6 466 FALSE), /* pcrel_offset */
d75bc93d
TS
467
468 /* Get the highest value of a 64 bit addend. */
469 HOWTO (R_MIPS_HIGHEST, /* type */
470 0, /* rightshift */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
472 16, /* bitsize */
b34976b6 473 FALSE, /* pc_relative */
d75bc93d
TS
474 0, /* bitpos */
475 complain_overflow_dont, /* complain_on_overflow */
30ac9238 476 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 477 "R_MIPS_HIGHEST", /* name */
b34976b6 478 TRUE, /* partial_inplace */
d75bc93d
TS
479 0x0000ffff, /* src_mask */
480 0x0000ffff, /* dst_mask */
b34976b6 481 FALSE), /* pcrel_offset */
d75bc93d
TS
482
483 /* High 16 bits of displacement in global offset table. */
484 HOWTO (R_MIPS_CALL_HI16, /* type */
485 0, /* rightshift */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
487 16, /* bitsize */
b34976b6 488 FALSE, /* pc_relative */
d75bc93d
TS
489 0, /* bitpos */
490 complain_overflow_dont, /* complain_on_overflow */
30ac9238 491 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 492 "R_MIPS_CALL_HI16", /* name */
b34976b6 493 TRUE, /* partial_inplace */
d75bc93d
TS
494 0x0000ffff, /* src_mask */
495 0x0000ffff, /* dst_mask */
b34976b6 496 FALSE), /* pcrel_offset */
d75bc93d
TS
497
498 /* Low 16 bits of displacement in global offset table. */
499 HOWTO (R_MIPS_CALL_LO16, /* type */
500 0, /* rightshift */
501 2, /* size (0 = byte, 1 = short, 2 = long) */
502 16, /* bitsize */
b34976b6 503 FALSE, /* pc_relative */
d75bc93d
TS
504 0, /* bitpos */
505 complain_overflow_dont, /* complain_on_overflow */
30ac9238 506 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 507 "R_MIPS_CALL_LO16", /* name */
b34976b6 508 TRUE, /* partial_inplace */
d75bc93d
TS
509 0x0000ffff, /* src_mask */
510 0x0000ffff, /* dst_mask */
b34976b6 511 FALSE), /* pcrel_offset */
d75bc93d
TS
512
513 /* Section displacement. */
514 HOWTO (R_MIPS_SCN_DISP, /* type */
515 0, /* rightshift */
516 2, /* size (0 = byte, 1 = short, 2 = long) */
517 32, /* bitsize */
b34976b6 518 FALSE, /* pc_relative */
d75bc93d
TS
519 0, /* bitpos */
520 complain_overflow_dont, /* complain_on_overflow */
30ac9238 521 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 522 "R_MIPS_SCN_DISP", /* name */
b34976b6 523 TRUE, /* partial_inplace */
d75bc93d
TS
524 0xffffffff, /* src_mask */
525 0xffffffff, /* dst_mask */
b34976b6 526 FALSE), /* pcrel_offset */
d75bc93d
TS
527
528 EMPTY_HOWTO (R_MIPS_REL16),
529 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
530 EMPTY_HOWTO (R_MIPS_PJUMP),
531 EMPTY_HOWTO (R_MIPS_RELGOT),
532
533 /* Protected jump conversion. This is an optimization hint. No
534 relocation is required for correctness. */
07d6d2b8 535 HOWTO (R_MIPS_JALR, /* type */
d75bc93d
TS
536 0, /* rightshift */
537 2, /* size (0 = byte, 1 = short, 2 = long) */
538 32, /* bitsize */
b34976b6 539 FALSE, /* pc_relative */
d75bc93d
TS
540 0, /* bitpos */
541 complain_overflow_dont, /* complain_on_overflow */
30ac9238 542 _bfd_mips_elf_generic_reloc, /* special_function */
07d6d2b8 543 "R_MIPS_JALR", /* name */
b34976b6 544 FALSE, /* partial_inplace */
d75bc93d
TS
545 0x00000000, /* src_mask */
546 0x00000000, /* dst_mask */
b34976b6 547 FALSE), /* pcrel_offset */
0f20cc35
DJ
548
549 /* TLS GD/LD dynamic relocations. */
550 HOWTO (R_MIPS_TLS_DTPMOD32, /* type */
551 0, /* rightshift */
552 2, /* size (0 = byte, 1 = short, 2 = long) */
553 32, /* bitsize */
554 FALSE, /* pc_relative */
555 0, /* bitpos */
556 complain_overflow_dont, /* complain_on_overflow */
557 _bfd_mips_elf_generic_reloc, /* special_function */
558 "R_MIPS_TLS_DTPMOD32", /* name */
559 TRUE, /* partial_inplace */
560 0xffffffff, /* src_mask */
561 0xffffffff, /* dst_mask */
562 FALSE), /* pcrel_offset */
563
564 HOWTO (R_MIPS_TLS_DTPREL32, /* type */
565 0, /* rightshift */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
567 32, /* bitsize */
568 FALSE, /* pc_relative */
569 0, /* bitpos */
570 complain_overflow_dont, /* complain_on_overflow */
571 _bfd_mips_elf_generic_reloc, /* special_function */
572 "R_MIPS_TLS_DTPREL32", /* name */
573 TRUE, /* partial_inplace */
574 0xffffffff, /* src_mask */
575 0xffffffff, /* dst_mask */
576 FALSE), /* pcrel_offset */
577
578 EMPTY_HOWTO (R_MIPS_TLS_DTPMOD64),
579 EMPTY_HOWTO (R_MIPS_TLS_DTPREL64),
580
581 /* TLS general dynamic variable reference. */
582 HOWTO (R_MIPS_TLS_GD, /* type */
583 0, /* rightshift */
584 2, /* size (0 = byte, 1 = short, 2 = long) */
585 16, /* bitsize */
586 FALSE, /* pc_relative */
587 0, /* bitpos */
588 complain_overflow_signed, /* complain_on_overflow */
589 _bfd_mips_elf_generic_reloc, /* special_function */
590 "R_MIPS_TLS_GD", /* name */
591 TRUE, /* partial_inplace */
592 0x0000ffff, /* src_mask */
593 0x0000ffff, /* dst_mask */
594 FALSE), /* pcrel_offset */
595
596 /* TLS local dynamic variable reference. */
597 HOWTO (R_MIPS_TLS_LDM, /* type */
598 0, /* rightshift */
599 2, /* size (0 = byte, 1 = short, 2 = long) */
600 16, /* bitsize */
601 FALSE, /* pc_relative */
602 0, /* bitpos */
603 complain_overflow_signed, /* complain_on_overflow */
604 _bfd_mips_elf_generic_reloc, /* special_function */
605 "R_MIPS_TLS_LDM", /* name */
606 TRUE, /* partial_inplace */
607 0x0000ffff, /* src_mask */
608 0x0000ffff, /* dst_mask */
609 FALSE), /* pcrel_offset */
610
611 /* TLS local dynamic offset. */
612 HOWTO (R_MIPS_TLS_DTPREL_HI16, /* type */
613 0, /* rightshift */
614 2, /* size (0 = byte, 1 = short, 2 = long) */
615 16, /* bitsize */
616 FALSE, /* pc_relative */
617 0, /* bitpos */
618 complain_overflow_signed, /* complain_on_overflow */
619 _bfd_mips_elf_generic_reloc, /* special_function */
620 "R_MIPS_TLS_DTPREL_HI16", /* name */
621 TRUE, /* partial_inplace */
622 0x0000ffff, /* src_mask */
623 0x0000ffff, /* dst_mask */
624 FALSE), /* pcrel_offset */
625
626 /* TLS local dynamic offset. */
627 HOWTO (R_MIPS_TLS_DTPREL_LO16, /* type */
628 0, /* rightshift */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
630 16, /* bitsize */
631 FALSE, /* pc_relative */
632 0, /* bitpos */
633 complain_overflow_signed, /* complain_on_overflow */
634 _bfd_mips_elf_generic_reloc, /* special_function */
635 "R_MIPS_TLS_DTPREL_LO16", /* name */
636 TRUE, /* partial_inplace */
637 0x0000ffff, /* src_mask */
638 0x0000ffff, /* dst_mask */
639 FALSE), /* pcrel_offset */
640
641 /* TLS thread pointer offset. */
642 HOWTO (R_MIPS_TLS_GOTTPREL, /* type */
643 0, /* rightshift */
644 2, /* size (0 = byte, 1 = short, 2 = long) */
645 16, /* bitsize */
646 FALSE, /* pc_relative */
647 0, /* bitpos */
648 complain_overflow_signed, /* complain_on_overflow */
649 _bfd_mips_elf_generic_reloc, /* special_function */
650 "R_MIPS_TLS_GOTTPREL", /* name */
651 TRUE, /* partial_inplace */
652 0x0000ffff, /* src_mask */
653 0x0000ffff, /* dst_mask */
654 FALSE), /* pcrel_offset */
655
656 /* TLS IE dynamic relocations. */
657 HOWTO (R_MIPS_TLS_TPREL32, /* type */
658 0, /* rightshift */
659 2, /* size (0 = byte, 1 = short, 2 = long) */
660 32, /* bitsize */
661 FALSE, /* pc_relative */
662 0, /* bitpos */
663 complain_overflow_dont, /* complain_on_overflow */
664 _bfd_mips_elf_generic_reloc, /* special_function */
665 "R_MIPS_TLS_TPREL32", /* name */
666 TRUE, /* partial_inplace */
667 0xffffffff, /* src_mask */
668 0xffffffff, /* dst_mask */
669 FALSE), /* pcrel_offset */
670
671 EMPTY_HOWTO (R_MIPS_TLS_TPREL64),
672
673 /* TLS thread pointer offset. */
674 HOWTO (R_MIPS_TLS_TPREL_HI16, /* type */
675 0, /* rightshift */
676 2, /* size (0 = byte, 1 = short, 2 = long) */
677 16, /* bitsize */
678 FALSE, /* pc_relative */
679 0, /* bitpos */
680 complain_overflow_signed, /* complain_on_overflow */
681 _bfd_mips_elf_generic_reloc, /* special_function */
682 "R_MIPS_TLS_TPREL_HI16", /* name */
683 TRUE, /* partial_inplace */
684 0x0000ffff, /* src_mask */
685 0x0000ffff, /* dst_mask */
686 FALSE), /* pcrel_offset */
687
688 /* TLS thread pointer offset. */
689 HOWTO (R_MIPS_TLS_TPREL_LO16, /* type */
690 0, /* rightshift */
691 2, /* size (0 = byte, 1 = short, 2 = long) */
692 16, /* bitsize */
693 FALSE, /* pc_relative */
694 0, /* bitpos */
695 complain_overflow_signed, /* complain_on_overflow */
696 _bfd_mips_elf_generic_reloc, /* special_function */
697 "R_MIPS_TLS_TPREL_LO16", /* name */
698 TRUE, /* partial_inplace */
699 0x0000ffff, /* src_mask */
700 0x0000ffff, /* dst_mask */
701 FALSE), /* pcrel_offset */
165b93e7
RS
702
703 /* 32 bit relocation with no addend. */
704 HOWTO (R_MIPS_GLOB_DAT, /* type */
705 0, /* rightshift */
706 2, /* size (0 = byte, 1 = short, 2 = long) */
707 32, /* bitsize */
708 FALSE, /* pc_relative */
709 0, /* bitpos */
710 complain_overflow_dont, /* complain_on_overflow */
711 _bfd_mips_elf_generic_reloc, /* special_function */
712 "R_MIPS_GLOB_DAT", /* name */
713 FALSE, /* partial_inplace */
714 0x0, /* src_mask */
715 0xffffffff, /* dst_mask */
716 FALSE), /* pcrel_offset */
7361da2c
AB
717
718 EMPTY_HOWTO (52),
719 EMPTY_HOWTO (53),
720 EMPTY_HOWTO (54),
721 EMPTY_HOWTO (55),
722 EMPTY_HOWTO (56),
723 EMPTY_HOWTO (57),
724 EMPTY_HOWTO (58),
725 EMPTY_HOWTO (59),
726
727 HOWTO (R_MIPS_PC21_S2, /* type */
728 2, /* rightshift */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
730 21, /* bitsize */
731 TRUE, /* pc_relative */
732 0, /* bitpos */
733 complain_overflow_signed, /* complain_on_overflow */
734 _bfd_mips_elf_generic_reloc, /* special_function */
735 "R_MIPS_PC21_S2", /* name */
736 TRUE, /* partial_inplace */
737 0x001fffff, /* src_mask */
738 0x001fffff, /* dst_mask */
739 TRUE), /* pcrel_offset */
740
741 HOWTO (R_MIPS_PC26_S2, /* type */
742 2, /* rightshift */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
744 26, /* bitsize */
745 TRUE, /* pc_relative */
746 0, /* bitpos */
747 complain_overflow_signed, /* complain_on_overflow */
748 _bfd_mips_elf_generic_reloc, /* special_function */
749 "R_MIPS_PC26_S2", /* name */
750 TRUE, /* partial_inplace */
751 0x03ffffff, /* src_mask */
752 0x03ffffff, /* dst_mask */
753 TRUE), /* pcrel_offset */
754
755 HOWTO (R_MIPS_PC18_S3, /* type */
756 3, /* rightshift */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
758 18, /* bitsize */
759 TRUE, /* pc_relative */
760 0, /* bitpos */
761 complain_overflow_signed, /* complain_on_overflow */
762 _bfd_mips_elf_generic_reloc, /* special_function */
763 "R_MIPS_PC18_S3", /* name */
764 TRUE, /* partial_inplace */
765 0x0003ffff, /* src_mask */
766 0x0003ffff, /* dst_mask */
767 TRUE), /* pcrel_offset */
768
769 HOWTO (R_MIPS_PC19_S2, /* type */
770 2, /* rightshift */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
772 19, /* bitsize */
773 TRUE, /* pc_relative */
774 0, /* bitpos */
775 complain_overflow_signed, /* complain_on_overflow */
776 _bfd_mips_elf_generic_reloc, /* special_function */
777 "R_MIPS_PC19_S2", /* name */
778 TRUE, /* partial_inplace */
779 0x0007ffff, /* src_mask */
780 0x0007ffff, /* dst_mask */
781 TRUE), /* pcrel_offset */
782
783 HOWTO (R_MIPS_PCHI16, /* type */
784 16, /* rightshift */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
786 16, /* bitsize */
787 TRUE, /* pc_relative */
788 0, /* bitpos */
789 complain_overflow_signed, /* complain_on_overflow */
790 _bfd_mips_elf_generic_reloc, /* special_function */
791 "R_MIPS_PCHI16", /* name */
792 TRUE, /* partial_inplace */
793 0x0000ffff, /* src_mask */
794 0x0000ffff, /* dst_mask */
795 TRUE), /* pcrel_offset */
796
797 HOWTO (R_MIPS_PCLO16, /* type */
798 0, /* rightshift */
799 2, /* size (0 = byte, 1 = short, 2 = long) */
800 16, /* bitsize */
801 TRUE, /* pc_relative */
802 0, /* bitpos */
803 complain_overflow_dont, /* complain_on_overflow */
804 _bfd_mips_elf_generic_reloc, /* special_function */
805 "R_MIPS_PCLO16", /* name */
806 TRUE, /* partial_inplace */
807 0x0000ffff, /* src_mask */
808 0x0000ffff, /* dst_mask */
809 TRUE), /* pcrel_offset */
d75bc93d
TS
810};
811
c6e90b02
TS
812/* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
813 is a hack to make the linker think that we need 64 bit values. */
814static reloc_howto_type elf_mips_ctor64_howto =
815 HOWTO (R_MIPS_64, /* type */
252b5132 816 0, /* rightshift */
c6e90b02 817 4, /* size (0 = byte, 1 = short, 2 = long) */
252b5132 818 32, /* bitsize */
b34976b6 819 FALSE, /* pc_relative */
252b5132 820 0, /* bitpos */
c6e90b02
TS
821 complain_overflow_signed, /* complain_on_overflow */
822 mips32_64bit_reloc, /* special_function */
823 "R_MIPS_64", /* name */
b34976b6 824 TRUE, /* partial_inplace */
c6e90b02 825 0xffffffff, /* src_mask */
252b5132 826 0xffffffff, /* dst_mask */
b34976b6 827 FALSE); /* pcrel_offset */
252b5132 828
d6f16593
MR
829static reloc_howto_type elf_mips16_howto_table_rel[] =
830{
831 /* The reloc used for the mips16 jump instruction. */
c6e90b02 832 HOWTO (R_MIPS16_26, /* type */
252b5132
RH
833 2, /* rightshift */
834 2, /* size (0 = byte, 1 = short, 2 = long) */
835 26, /* bitsize */
b34976b6 836 FALSE, /* pc_relative */
252b5132
RH
837 0, /* bitpos */
838 complain_overflow_dont, /* complain_on_overflow */
07d6d2b8 839 /* This needs complex overflow
c6e90b02
TS
840 detection, because the upper four
841 bits must match the PC. */
35d3d567 842 _bfd_mips_elf_generic_reloc, /* special_function */
c6e90b02 843 "R_MIPS16_26", /* name */
b34976b6 844 TRUE, /* partial_inplace */
c6e90b02
TS
845 0x3ffffff, /* src_mask */
846 0x3ffffff, /* dst_mask */
d6f16593 847 FALSE), /* pcrel_offset */
252b5132 848
d6f16593 849 /* The reloc used for the mips16 gprel instruction. */
c6e90b02 850 HOWTO (R_MIPS16_GPREL, /* type */
252b5132
RH
851 0, /* rightshift */
852 2, /* size (0 = byte, 1 = short, 2 = long) */
853 16, /* bitsize */
b34976b6 854 FALSE, /* pc_relative */
252b5132 855 0, /* bitpos */
c6e90b02
TS
856 complain_overflow_signed, /* complain_on_overflow */
857 mips16_gprel_reloc, /* special_function */
858 "R_MIPS16_GPREL", /* name */
b34976b6 859 TRUE, /* partial_inplace */
d6f16593 860 0x0000ffff, /* src_mask */
07d6d2b8 861 0x0000ffff, /* dst_mask */
d6f16593
MR
862 FALSE), /* pcrel_offset */
863
738e5348
RS
864 /* A MIPS16 reference to the global offset table. */
865 HOWTO (R_MIPS16_GOT16, /* type */
866 0, /* rightshift */
867 2, /* size (0 = byte, 1 = short, 2 = long) */
868 16, /* bitsize */
869 FALSE, /* pc_relative */
870 0, /* bitpos */
871 complain_overflow_dont, /* complain_on_overflow */
872 _bfd_mips_elf_got16_reloc, /* special_function */
873 "R_MIPS16_GOT16", /* name */
874 TRUE, /* partial_inplace */
875 0x0000ffff, /* src_mask */
07d6d2b8 876 0x0000ffff, /* dst_mask */
738e5348 877 FALSE), /* pcrel_offset */
d6f16593 878
738e5348
RS
879 /* A MIPS16 call through the global offset table. */
880 HOWTO (R_MIPS16_CALL16, /* type */
881 0, /* rightshift */
882 2, /* size (0 = byte, 1 = short, 2 = long) */
883 16, /* bitsize */
884 FALSE, /* pc_relative */
885 0, /* bitpos */
886 complain_overflow_dont, /* complain_on_overflow */
887 _bfd_mips_elf_generic_reloc, /* special_function */
888 "R_MIPS16_CALL16", /* name */
889 TRUE, /* partial_inplace */
890 0x0000ffff, /* src_mask */
07d6d2b8 891 0x0000ffff, /* dst_mask */
738e5348 892 FALSE), /* pcrel_offset */
d6f16593
MR
893
894 /* MIPS16 high 16 bits of symbol value. */
895 HOWTO (R_MIPS16_HI16, /* type */
896 16, /* rightshift */
897 2, /* size (0 = byte, 1 = short, 2 = long) */
898 16, /* bitsize */
899 FALSE, /* pc_relative */
900 0, /* bitpos */
901 complain_overflow_dont, /* complain_on_overflow */
902 _bfd_mips_elf_hi16_reloc, /* special_function */
903 "R_MIPS16_HI16", /* name */
904 TRUE, /* partial_inplace */
905 0x0000ffff, /* src_mask */
07d6d2b8 906 0x0000ffff, /* dst_mask */
d6f16593
MR
907 FALSE), /* pcrel_offset */
908
909 /* MIPS16 low 16 bits of symbol value. */
910 HOWTO (R_MIPS16_LO16, /* type */
911 0, /* rightshift */
912 2, /* size (0 = byte, 1 = short, 2 = long) */
913 16, /* bitsize */
914 FALSE, /* pc_relative */
915 0, /* bitpos */
916 complain_overflow_dont, /* complain_on_overflow */
917 _bfd_mips_elf_lo16_reloc, /* special_function */
918 "R_MIPS16_LO16", /* name */
919 TRUE, /* partial_inplace */
920 0x0000ffff, /* src_mask */
07d6d2b8 921 0x0000ffff, /* dst_mask */
d6f16593 922 FALSE), /* pcrel_offset */
d0f13682
CLT
923
924 /* MIPS16 TLS general dynamic variable reference. */
925 HOWTO (R_MIPS16_TLS_GD, /* type */
926 0, /* rightshift */
927 2, /* size (0 = byte, 1 = short, 2 = long) */
928 16, /* bitsize */
929 FALSE, /* pc_relative */
930 0, /* bitpos */
931 complain_overflow_signed, /* complain_on_overflow */
932 _bfd_mips_elf_generic_reloc, /* special_function */
933 "R_MIPS16_TLS_GD", /* name */
934 TRUE, /* partial_inplace */
935 0x0000ffff, /* src_mask */
936 0x0000ffff, /* dst_mask */
937 FALSE), /* pcrel_offset */
938
939 /* MIPS16 TLS local dynamic variable reference. */
940 HOWTO (R_MIPS16_TLS_LDM, /* type */
941 0, /* rightshift */
942 2, /* size (0 = byte, 1 = short, 2 = long) */
943 16, /* bitsize */
944 FALSE, /* pc_relative */
945 0, /* bitpos */
946 complain_overflow_signed, /* complain_on_overflow */
947 _bfd_mips_elf_generic_reloc, /* special_function */
948 "R_MIPS16_TLS_LDM", /* name */
949 TRUE, /* partial_inplace */
950 0x0000ffff, /* src_mask */
951 0x0000ffff, /* dst_mask */
952 FALSE), /* pcrel_offset */
953
954 /* MIPS16 TLS local dynamic offset. */
955 HOWTO (R_MIPS16_TLS_DTPREL_HI16, /* type */
956 0, /* rightshift */
957 2, /* size (0 = byte, 1 = short, 2 = long) */
958 16, /* bitsize */
959 FALSE, /* pc_relative */
960 0, /* bitpos */
961 complain_overflow_signed, /* complain_on_overflow */
962 _bfd_mips_elf_generic_reloc, /* special_function */
963 "R_MIPS16_TLS_DTPREL_HI16", /* name */
964 TRUE, /* partial_inplace */
965 0x0000ffff, /* src_mask */
966 0x0000ffff, /* dst_mask */
967 FALSE), /* pcrel_offset */
968
969 /* MIPS16 TLS local dynamic offset. */
970 HOWTO (R_MIPS16_TLS_DTPREL_LO16, /* type */
971 0, /* rightshift */
972 2, /* size (0 = byte, 1 = short, 2 = long) */
973 16, /* bitsize */
974 FALSE, /* pc_relative */
975 0, /* bitpos */
976 complain_overflow_signed, /* complain_on_overflow */
977 _bfd_mips_elf_generic_reloc, /* special_function */
978 "R_MIPS16_TLS_DTPREL_LO16", /* name */
979 TRUE, /* partial_inplace */
980 0x0000ffff, /* src_mask */
981 0x0000ffff, /* dst_mask */
982 FALSE), /* pcrel_offset */
983
984 /* MIPS16 TLS thread pointer offset. */
985 HOWTO (R_MIPS16_TLS_GOTTPREL, /* type */
986 0, /* rightshift */
987 2, /* size (0 = byte, 1 = short, 2 = long) */
988 16, /* bitsize */
989 FALSE, /* pc_relative */
990 0, /* bitpos */
991 complain_overflow_signed, /* complain_on_overflow */
992 _bfd_mips_elf_generic_reloc, /* special_function */
993 "R_MIPS16_TLS_GOTTPREL", /* name */
994 TRUE, /* partial_inplace */
995 0x0000ffff, /* src_mask */
996 0x0000ffff, /* dst_mask */
997 FALSE), /* pcrel_offset */
998
999 /* MIPS16 TLS thread pointer offset. */
1000 HOWTO (R_MIPS16_TLS_TPREL_HI16, /* type */
1001 0, /* rightshift */
1002 2, /* size (0 = byte, 1 = short, 2 = long) */
1003 16, /* bitsize */
1004 FALSE, /* pc_relative */
1005 0, /* bitpos */
1006 complain_overflow_signed, /* complain_on_overflow */
1007 _bfd_mips_elf_generic_reloc, /* special_function */
1008 "R_MIPS16_TLS_TPREL_HI16", /* name */
1009 TRUE, /* partial_inplace */
1010 0x0000ffff, /* src_mask */
1011 0x0000ffff, /* dst_mask */
1012 FALSE), /* pcrel_offset */
1013
1014 /* MIPS16 TLS thread pointer offset. */
1015 HOWTO (R_MIPS16_TLS_TPREL_LO16, /* type */
1016 0, /* rightshift */
1017 2, /* size (0 = byte, 1 = short, 2 = long) */
1018 16, /* bitsize */
1019 FALSE, /* pc_relative */
1020 0, /* bitpos */
1021 complain_overflow_signed, /* complain_on_overflow */
1022 _bfd_mips_elf_generic_reloc, /* special_function */
1023 "R_MIPS16_TLS_TPREL_LO16", /* name */
1024 TRUE, /* partial_inplace */
1025 0x0000ffff, /* src_mask */
1026 0x0000ffff, /* dst_mask */
1027 FALSE), /* pcrel_offset */
c9775dde
MR
1028
1029 /* MIPS16 16-bit PC-relative branch offset. */
1030 HOWTO (R_MIPS16_PC16_S1, /* type */
1031 1, /* rightshift */
1032 2, /* size (0 = byte, 1 = short, 2 = long) */
1033 16, /* bitsize */
1034 TRUE, /* pc_relative */
1035 0, /* bitpos */
1036 complain_overflow_signed, /* complain_on_overflow */
1037 _bfd_mips_elf_generic_reloc, /* special_function */
1038 "R_MIPS16_PC16_S1", /* name */
1039 TRUE, /* partial_inplace */
1040 0x0000ffff, /* src_mask */
1041 0x0000ffff, /* dst_mask */
1042 TRUE), /* pcrel_offset */
d6f16593 1043};
252b5132 1044
df58fc94
RS
1045static reloc_howto_type elf_micromips_howto_table_rel[] =
1046{
1047 EMPTY_HOWTO (130),
1048 EMPTY_HOWTO (131),
1049 EMPTY_HOWTO (132),
1050
1051 /* 26 bit jump address. */
1052 HOWTO (R_MICROMIPS_26_S1, /* type */
1053 1, /* rightshift */
1054 2, /* size (0 = byte, 1 = short, 2 = long) */
1055 26, /* bitsize */
1056 FALSE, /* pc_relative */
1057 0, /* bitpos */
1058 complain_overflow_dont, /* complain_on_overflow */
07d6d2b8 1059 /* This needs complex overflow
df58fc94
RS
1060 detection, because the upper four
1061 bits must match the PC. */
1062 _bfd_mips_elf_generic_reloc, /* special_function */
1063 "R_MICROMIPS_26_S1", /* name */
1064 TRUE, /* partial_inplace */
1065 0x3ffffff, /* src_mask */
1066 0x3ffffff, /* dst_mask */
1067 FALSE), /* pcrel_offset */
1068
1069 /* High 16 bits of symbol value. */
1070 HOWTO (R_MICROMIPS_HI16, /* type */
1071 16, /* rightshift */
1072 2, /* size (0 = byte, 1 = short, 2 = long) */
1073 16, /* bitsize */
1074 FALSE, /* pc_relative */
1075 0, /* bitpos */
1076 complain_overflow_dont, /* complain_on_overflow */
1077 _bfd_mips_elf_hi16_reloc, /* special_function */
1078 "R_MICROMIPS_HI16", /* name */
1079 TRUE, /* partial_inplace */
1080 0x0000ffff, /* src_mask */
1081 0x0000ffff, /* dst_mask */
1082 FALSE), /* pcrel_offset */
1083
1084 /* Low 16 bits of symbol value. */
1085 HOWTO (R_MICROMIPS_LO16, /* type */
1086 0, /* rightshift */
1087 2, /* size (0 = byte, 1 = short, 2 = long) */
1088 16, /* bitsize */
1089 FALSE, /* pc_relative */
1090 0, /* bitpos */
1091 complain_overflow_dont, /* complain_on_overflow */
1092 _bfd_mips_elf_lo16_reloc, /* special_function */
1093 "R_MICROMIPS_LO16", /* name */
1094 TRUE, /* partial_inplace */
1095 0x0000ffff, /* src_mask */
1096 0x0000ffff, /* dst_mask */
1097 FALSE), /* pcrel_offset */
1098
1099 /* GP relative reference. */
1100 HOWTO (R_MICROMIPS_GPREL16, /* type */
1101 0, /* rightshift */
1102 2, /* size (0 = byte, 1 = short, 2 = long) */
1103 16, /* bitsize */
1104 FALSE, /* pc_relative */
1105 0, /* bitpos */
1106 complain_overflow_signed, /* complain_on_overflow */
1107 _bfd_mips_elf32_gprel16_reloc, /* special_function */
1108 "R_MICROMIPS_GPREL16", /* name */
1109 TRUE, /* partial_inplace */
1110 0x0000ffff, /* src_mask */
1111 0x0000ffff, /* dst_mask */
1112 FALSE), /* pcrel_offset */
1113
1114 /* Reference to literal section. */
1115 HOWTO (R_MICROMIPS_LITERAL, /* type */
1116 0, /* rightshift */
1117 2, /* size (0 = byte, 1 = short, 2 = long) */
1118 16, /* bitsize */
1119 FALSE, /* pc_relative */
1120 0, /* bitpos */
1121 complain_overflow_signed, /* complain_on_overflow */
1122 _bfd_mips_elf32_gprel16_reloc, /* special_function */
1123 "R_MICROMIPS_LITERAL", /* name */
1124 TRUE, /* partial_inplace */
1125 0x0000ffff, /* src_mask */
1126 0x0000ffff, /* dst_mask */
1127 FALSE), /* pcrel_offset */
1128
1129 /* Reference to global offset table. */
1130 HOWTO (R_MICROMIPS_GOT16, /* type */
1131 0, /* rightshift */
1132 2, /* size (0 = byte, 1 = short, 2 = long) */
1133 16, /* bitsize */
1134 FALSE, /* pc_relative */
1135 0, /* bitpos */
1136 complain_overflow_signed, /* complain_on_overflow */
1137 _bfd_mips_elf_got16_reloc, /* special_function */
1138 "R_MICROMIPS_GOT16", /* name */
1139 TRUE, /* partial_inplace */
1140 0x0000ffff, /* src_mask */
1141 0x0000ffff, /* dst_mask */
1142 FALSE), /* pcrel_offset */
1143
1144 /* This is for microMIPS branches. */
1145 HOWTO (R_MICROMIPS_PC7_S1, /* type */
1146 1, /* rightshift */
1147 1, /* size (0 = byte, 1 = short, 2 = long) */
1148 7, /* bitsize */
1149 TRUE, /* pc_relative */
1150 0, /* bitpos */
1151 complain_overflow_signed, /* complain_on_overflow */
1152 _bfd_mips_elf_generic_reloc, /* special_function */
1153 "R_MICROMIPS_PC7_S1", /* name */
1154 TRUE, /* partial_inplace */
1155 0x0000007f, /* src_mask */
1156 0x0000007f, /* dst_mask */
1157 TRUE), /* pcrel_offset */
1158
1159 HOWTO (R_MICROMIPS_PC10_S1, /* type */
1160 1, /* rightshift */
1161 1, /* size (0 = byte, 1 = short, 2 = long) */
1162 10, /* bitsize */
1163 TRUE, /* pc_relative */
1164 0, /* bitpos */
1165 complain_overflow_signed, /* complain_on_overflow */
1166 _bfd_mips_elf_generic_reloc, /* special_function */
1167 "R_MICROMIPS_PC10_S1", /* name */
1168 TRUE, /* partial_inplace */
1169 0x000003ff, /* src_mask */
1170 0x000003ff, /* dst_mask */
1171 TRUE), /* pcrel_offset */
1172
1173 HOWTO (R_MICROMIPS_PC16_S1, /* type */
1174 1, /* rightshift */
1175 2, /* size (0 = byte, 1 = short, 2 = long) */
1176 16, /* bitsize */
1177 TRUE, /* pc_relative */
1178 0, /* bitpos */
1179 complain_overflow_signed, /* complain_on_overflow */
1180 _bfd_mips_elf_generic_reloc, /* special_function */
1181 "R_MICROMIPS_PC16_S1", /* name */
1182 TRUE, /* partial_inplace */
1183 0x0000ffff, /* src_mask */
1184 0x0000ffff, /* dst_mask */
1185 TRUE), /* pcrel_offset */
1186
1187 /* 16 bit call through global offset table. */
1188 HOWTO (R_MICROMIPS_CALL16, /* type */
1189 0, /* rightshift */
1190 2, /* size (0 = byte, 1 = short, 2 = long) */
1191 16, /* bitsize */
1192 FALSE, /* pc_relative */
1193 0, /* bitpos */
1194 complain_overflow_signed, /* complain_on_overflow */
1195 _bfd_mips_elf_generic_reloc, /* special_function */
1196 "R_MICROMIPS_CALL16", /* name */
1197 TRUE, /* partial_inplace */
1198 0x0000ffff, /* src_mask */
1199 0x0000ffff, /* dst_mask */
1200 FALSE), /* pcrel_offset */
1201
1202 EMPTY_HOWTO (143),
1203 EMPTY_HOWTO (144),
1204
1205 /* Displacement in the global offset table. */
1206 HOWTO (R_MICROMIPS_GOT_DISP, /* type */
1207 0, /* rightshift */
1208 2, /* size (0 = byte, 1 = short, 2 = long) */
1209 16, /* bitsize */
1210 FALSE, /* pc_relative */
1211 0, /* bitpos */
1212 complain_overflow_signed, /* complain_on_overflow */
1213 _bfd_mips_elf_generic_reloc, /* special_function */
1214 "R_MICROMIPS_GOT_DISP",/* name */
1215 TRUE, /* partial_inplace */
1216 0x0000ffff, /* src_mask */
1217 0x0000ffff, /* dst_mask */
1218 FALSE), /* pcrel_offset */
1219
1220 /* Displacement to page pointer in the global offset table. */
1221 HOWTO (R_MICROMIPS_GOT_PAGE, /* type */
1222 0, /* rightshift */
1223 2, /* size (0 = byte, 1 = short, 2 = long) */
1224 16, /* bitsize */
1225 FALSE, /* pc_relative */
1226 0, /* bitpos */
1227 complain_overflow_signed, /* complain_on_overflow */
1228 _bfd_mips_elf_generic_reloc, /* special_function */
1229 "R_MICROMIPS_GOT_PAGE",/* name */
1230 TRUE, /* partial_inplace */
1231 0x0000ffff, /* src_mask */
1232 0x0000ffff, /* dst_mask */
1233 FALSE), /* pcrel_offset */
1234
1235 /* Offset from page pointer in the global offset table. */
1236 HOWTO (R_MICROMIPS_GOT_OFST, /* type */
1237 0, /* rightshift */
1238 2, /* size (0 = byte, 1 = short, 2 = long) */
1239 16, /* bitsize */
1240 FALSE, /* pc_relative */
1241 0, /* bitpos */
1242 complain_overflow_signed, /* complain_on_overflow */
1243 _bfd_mips_elf_generic_reloc, /* special_function */
1244 "R_MICROMIPS_GOT_OFST",/* name */
1245 TRUE, /* partial_inplace */
1246 0x0000ffff, /* src_mask */
1247 0x0000ffff, /* dst_mask */
1248 FALSE), /* pcrel_offset */
1249
1250 /* High 16 bits of displacement in global offset table. */
1251 HOWTO (R_MICROMIPS_GOT_HI16, /* type */
1252 0, /* rightshift */
1253 2, /* size (0 = byte, 1 = short, 2 = long) */
1254 16, /* bitsize */
1255 FALSE, /* pc_relative */
1256 0, /* bitpos */
1257 complain_overflow_dont, /* complain_on_overflow */
1258 _bfd_mips_elf_generic_reloc, /* special_function */
1259 "R_MICROMIPS_GOT_HI16",/* name */
1260 TRUE, /* partial_inplace */
1261 0x0000ffff, /* src_mask */
1262 0x0000ffff, /* dst_mask */
1263 FALSE), /* pcrel_offset */
1264
1265 /* Low 16 bits of displacement in global offset table. */
1266 HOWTO (R_MICROMIPS_GOT_LO16, /* type */
1267 0, /* rightshift */
1268 2, /* size (0 = byte, 1 = short, 2 = long) */
1269 16, /* bitsize */
1270 FALSE, /* pc_relative */
1271 0, /* bitpos */
1272 complain_overflow_dont, /* complain_on_overflow */
1273 _bfd_mips_elf_generic_reloc, /* special_function */
1274 "R_MICROMIPS_GOT_LO16",/* name */
1275 TRUE, /* partial_inplace */
1276 0x0000ffff, /* src_mask */
1277 0x0000ffff, /* dst_mask */
1278 FALSE), /* pcrel_offset */
1279
1280 /* 64 bit subtraction. Used in the N32 ABI. */
1281 HOWTO (R_MICROMIPS_SUB, /* type */
1282 0, /* rightshift */
1283 4, /* size (0 = byte, 1 = short, 2 = long) */
1284 64, /* bitsize */
1285 FALSE, /* pc_relative */
1286 0, /* bitpos */
1287 complain_overflow_dont, /* complain_on_overflow */
1288 _bfd_mips_elf_generic_reloc, /* special_function */
1289 "R_MICROMIPS_SUB", /* name */
1290 TRUE, /* partial_inplace */
1291 MINUS_ONE, /* src_mask */
1292 MINUS_ONE, /* dst_mask */
1293 FALSE), /* pcrel_offset */
1294
1295 /* Get the higher value of a 64 bit addend. */
1296 HOWTO (R_MICROMIPS_HIGHER, /* type */
1297 0, /* rightshift */
1298 2, /* size (0 = byte, 1 = short, 2 = long) */
1299 16, /* bitsize */
1300 FALSE, /* pc_relative */
1301 0, /* bitpos */
1302 complain_overflow_dont, /* complain_on_overflow */
1303 _bfd_mips_elf_generic_reloc, /* special_function */
1304 "R_MICROMIPS_HIGHER", /* name */
1305 TRUE, /* partial_inplace */
1306 0x0000ffff, /* src_mask */
1307 0x0000ffff, /* dst_mask */
1308 FALSE), /* pcrel_offset */
1309
1310 /* Get the highest value of a 64 bit addend. */
1311 HOWTO (R_MICROMIPS_HIGHEST, /* type */
1312 0, /* rightshift */
1313 2, /* size (0 = byte, 1 = short, 2 = long) */
1314 16, /* bitsize */
1315 FALSE, /* pc_relative */
1316 0, /* bitpos */
1317 complain_overflow_dont, /* complain_on_overflow */
1318 _bfd_mips_elf_generic_reloc, /* special_function */
1319 "R_MICROMIPS_HIGHEST", /* name */
1320 TRUE, /* partial_inplace */
1321 0x0000ffff, /* src_mask */
1322 0x0000ffff, /* dst_mask */
1323 FALSE), /* pcrel_offset */
1324
1325 /* High 16 bits of displacement in global offset table. */
1326 HOWTO (R_MICROMIPS_CALL_HI16, /* type */
1327 0, /* rightshift */
1328 2, /* size (0 = byte, 1 = short, 2 = long) */
1329 16, /* bitsize */
1330 FALSE, /* pc_relative */
1331 0, /* bitpos */
1332 complain_overflow_dont, /* complain_on_overflow */
1333 _bfd_mips_elf_generic_reloc, /* special_function */
1334 "R_MICROMIPS_CALL_HI16",/* name */
1335 TRUE, /* partial_inplace */
1336 0x0000ffff, /* src_mask */
1337 0x0000ffff, /* dst_mask */
1338 FALSE), /* pcrel_offset */
1339
1340 /* Low 16 bits of displacement in global offset table. */
1341 HOWTO (R_MICROMIPS_CALL_LO16, /* type */
1342 0, /* rightshift */
1343 2, /* size (0 = byte, 1 = short, 2 = long) */
1344 16, /* bitsize */
1345 FALSE, /* pc_relative */
1346 0, /* bitpos */
1347 complain_overflow_dont, /* complain_on_overflow */
1348 _bfd_mips_elf_generic_reloc, /* special_function */
1349 "R_MICROMIPS_CALL_LO16",/* name */
1350 TRUE, /* partial_inplace */
1351 0x0000ffff, /* src_mask */
1352 0x0000ffff, /* dst_mask */
1353 FALSE), /* pcrel_offset */
1354
1355 /* Section displacement. */
1356 HOWTO (R_MICROMIPS_SCN_DISP, /* type */
1357 0, /* rightshift */
1358 2, /* size (0 = byte, 1 = short, 2 = long) */
1359 32, /* bitsize */
1360 FALSE, /* pc_relative */
1361 0, /* bitpos */
1362 complain_overflow_dont, /* complain_on_overflow */
1363 _bfd_mips_elf_generic_reloc, /* special_function */
1364 "R_MICROMIPS_SCN_DISP",/* name */
1365 TRUE, /* partial_inplace */
1366 0xffffffff, /* src_mask */
1367 0xffffffff, /* dst_mask */
1368 FALSE), /* pcrel_offset */
1369
1370 /* Protected jump conversion. This is an optimization hint. No
1371 relocation is required for correctness. */
1372 HOWTO (R_MICROMIPS_JALR, /* type */
1373 0, /* rightshift */
1374 2, /* size (0 = byte, 1 = short, 2 = long) */
1375 32, /* bitsize */
1376 FALSE, /* pc_relative */
1377 0, /* bitpos */
1378 complain_overflow_dont, /* complain_on_overflow */
1379 _bfd_mips_elf_generic_reloc, /* special_function */
1380 "R_MICROMIPS_JALR", /* name */
1381 FALSE, /* partial_inplace */
1382 0x00000000, /* src_mask */
1383 0x00000000, /* dst_mask */
1384 FALSE), /* pcrel_offset */
1385
1386 /* Low 16 bits of symbol value. Note that the high 16 bits of symbol values
1387 must be zero. This is used for relaxation. */
1388 HOWTO (R_MICROMIPS_HI0_LO16, /* type */
1389 0, /* rightshift */
1390 2, /* size (0 = byte, 1 = short, 2 = long) */
1391 16, /* bitsize */
1392 FALSE, /* pc_relative */
1393 0, /* bitpos */
1394 complain_overflow_dont, /* complain_on_overflow */
1395 _bfd_mips_elf_generic_reloc, /* special_function */
1396 "R_MICROMIPS_HI0_LO16",/* name */
1397 TRUE, /* partial_inplace */
1398 0x0000ffff, /* src_mask */
1399 0x0000ffff, /* dst_mask */
1400 FALSE), /* pcrel_offset */
1401
1402 EMPTY_HOWTO (158),
1403 EMPTY_HOWTO (159),
1404 EMPTY_HOWTO (160),
1405 EMPTY_HOWTO (161),
1406
1407 /* TLS general dynamic variable reference. */
1408 HOWTO (R_MICROMIPS_TLS_GD, /* type */
1409 0, /* rightshift */
1410 2, /* size (0 = byte, 1 = short, 2 = long) */
1411 16, /* bitsize */
1412 FALSE, /* pc_relative */
1413 0, /* bitpos */
1414 complain_overflow_signed, /* complain_on_overflow */
1415 _bfd_mips_elf_generic_reloc, /* special_function */
1416 "R_MICROMIPS_TLS_GD", /* name */
1417 TRUE, /* partial_inplace */
1418 0x0000ffff, /* src_mask */
1419 0x0000ffff, /* dst_mask */
1420 FALSE), /* pcrel_offset */
1421
1422 /* TLS local dynamic variable reference. */
1423 HOWTO (R_MICROMIPS_TLS_LDM, /* type */
1424 0, /* rightshift */
1425 2, /* size (0 = byte, 1 = short, 2 = long) */
1426 16, /* bitsize */
1427 FALSE, /* pc_relative */
1428 0, /* bitpos */
1429 complain_overflow_signed, /* complain_on_overflow */
1430 _bfd_mips_elf_generic_reloc, /* special_function */
1431 "R_MICROMIPS_TLS_LDM", /* name */
1432 TRUE, /* partial_inplace */
1433 0x0000ffff, /* src_mask */
1434 0x0000ffff, /* dst_mask */
1435 FALSE), /* pcrel_offset */
1436
1437 /* TLS local dynamic offset. */
1438 HOWTO (R_MICROMIPS_TLS_DTPREL_HI16, /* type */
1439 0, /* rightshift */
1440 2, /* size (0 = byte, 1 = short, 2 = long) */
1441 16, /* bitsize */
1442 FALSE, /* pc_relative */
1443 0, /* bitpos */
1444 complain_overflow_signed, /* complain_on_overflow */
1445 _bfd_mips_elf_generic_reloc, /* special_function */
1446 "R_MICROMIPS_TLS_DTPREL_HI16", /* name */
1447 TRUE, /* partial_inplace */
1448 0x0000ffff, /* src_mask */
1449 0x0000ffff, /* dst_mask */
1450 FALSE), /* pcrel_offset */
1451
1452 /* TLS local dynamic offset. */
1453 HOWTO (R_MICROMIPS_TLS_DTPREL_LO16, /* type */
1454 0, /* rightshift */
1455 2, /* size (0 = byte, 1 = short, 2 = long) */
1456 16, /* bitsize */
1457 FALSE, /* pc_relative */
1458 0, /* bitpos */
1459 complain_overflow_signed, /* complain_on_overflow */
1460 _bfd_mips_elf_generic_reloc, /* special_function */
1461 "R_MICROMIPS_TLS_DTPREL_LO16", /* name */
1462 TRUE, /* partial_inplace */
1463 0x0000ffff, /* src_mask */
1464 0x0000ffff, /* dst_mask */
1465 FALSE), /* pcrel_offset */
1466
1467 /* TLS thread pointer offset. */
1468 HOWTO (R_MICROMIPS_TLS_GOTTPREL, /* type */
1469 0, /* rightshift */
1470 2, /* size (0 = byte, 1 = short, 2 = long) */
1471 16, /* bitsize */
1472 FALSE, /* pc_relative */
1473 0, /* bitpos */
1474 complain_overflow_signed, /* complain_on_overflow */
1475 _bfd_mips_elf_generic_reloc, /* special_function */
1476 "R_MICROMIPS_TLS_GOTTPREL", /* name */
1477 TRUE, /* partial_inplace */
1478 0x0000ffff, /* src_mask */
1479 0x0000ffff, /* dst_mask */
1480 FALSE), /* pcrel_offset */
1481
1482 EMPTY_HOWTO (167),
1483 EMPTY_HOWTO (168),
1484
1485 /* TLS thread pointer offset. */
1486 HOWTO (R_MICROMIPS_TLS_TPREL_HI16, /* type */
1487 0, /* rightshift */
1488 2, /* size (0 = byte, 1 = short, 2 = long) */
1489 16, /* bitsize */
1490 FALSE, /* pc_relative */
1491 0, /* bitpos */
1492 complain_overflow_signed, /* complain_on_overflow */
1493 _bfd_mips_elf_generic_reloc, /* special_function */
1494 "R_MICROMIPS_TLS_TPREL_HI16", /* name */
1495 TRUE, /* partial_inplace */
1496 0x0000ffff, /* src_mask */
1497 0x0000ffff, /* dst_mask */
1498 FALSE), /* pcrel_offset */
1499
1500 /* TLS thread pointer offset. */
1501 HOWTO (R_MICROMIPS_TLS_TPREL_LO16, /* type */
1502 0, /* rightshift */
1503 2, /* size (0 = byte, 1 = short, 2 = long) */
1504 16, /* bitsize */
1505 FALSE, /* pc_relative */
1506 0, /* bitpos */
1507 complain_overflow_signed, /* complain_on_overflow */
1508 _bfd_mips_elf_generic_reloc, /* special_function */
1509 "R_MICROMIPS_TLS_TPREL_LO16", /* name */
1510 TRUE, /* partial_inplace */
1511 0x0000ffff, /* src_mask */
1512 0x0000ffff, /* dst_mask */
1513 FALSE), /* pcrel_offset */
1514
1515 EMPTY_HOWTO (171),
1516
1517 /* GP- and PC-relative relocations. */
1518 HOWTO (R_MICROMIPS_GPREL7_S2, /* type */
1519 2, /* rightshift */
1520 1, /* size (0 = byte, 1 = short, 2 = long) */
1521 7, /* bitsize */
1522 FALSE, /* pc_relative */
1523 0, /* bitpos */
1524 complain_overflow_signed, /* complain_on_overflow */
1525 _bfd_mips_elf32_gprel16_reloc, /* special_function */
1526 "R_MICROMIPS_GPREL7_S2", /* name */
1527 TRUE, /* partial_inplace */
1528 0x0000007f, /* src_mask */
1529 0x0000007f, /* dst_mask */
1530 FALSE), /* pcrel_offset */
1531
1532 HOWTO (R_MICROMIPS_PC23_S2, /* type */
1533 2, /* rightshift */
1534 2, /* size (0 = byte, 1 = short, 2 = long) */
1535 23, /* bitsize */
1536 TRUE, /* pc_relative */
1537 0, /* bitpos */
1538 complain_overflow_signed, /* complain_on_overflow */
1539 _bfd_mips_elf_generic_reloc, /* special_function */
1540 "R_MICROMIPS_PC23_S2", /* name */
1541 TRUE, /* partial_inplace */
1542 0x007fffff, /* src_mask */
1543 0x007fffff, /* dst_mask */
1544 TRUE), /* pcrel_offset */
1545};
1546
c6e90b02
TS
1547/* 16 bit offset for pc-relative branches. */
1548static reloc_howto_type elf_mips_gnu_rel16_s2 =
1549 HOWTO (R_MIPS_GNU_REL16_S2, /* type */
1550 2, /* rightshift */
252b5132
RH
1551 2, /* size (0 = byte, 1 = short, 2 = long) */
1552 16, /* bitsize */
b34976b6 1553 TRUE, /* pc_relative */
252b5132
RH
1554 0, /* bitpos */
1555 complain_overflow_signed, /* complain_on_overflow */
30ac9238 1556 _bfd_mips_elf_generic_reloc, /* special_function */
c6e90b02 1557 "R_MIPS_GNU_REL16_S2", /* name */
b34976b6 1558 TRUE, /* partial_inplace */
c6e90b02
TS
1559 0xffff, /* src_mask */
1560 0xffff, /* dst_mask */
b34976b6 1561 TRUE); /* pcrel_offset */
252b5132 1562
092dcd75 1563/* 32 bit pc-relative. This was a GNU extension used by embedded-PIC.
0c9663cb
MR
1564 It was co-opted by mips-linux for exception-handling data. GCC stopped
1565 using it in May, 2004, then started using it again for compact unwind
1566 tables. */
092dcd75
CD
1567static reloc_howto_type elf_mips_gnu_pcrel32 =
1568 HOWTO (R_MIPS_PC32, /* type */
1569 0, /* rightshift */
1570 2, /* size (0 = byte, 1 = short, 2 = long) */
1571 32, /* bitsize */
1572 TRUE, /* pc_relative */
1573 0, /* bitpos */
1574 complain_overflow_signed, /* complain_on_overflow */
1575 _bfd_mips_elf_generic_reloc, /* special_function */
1576 "R_MIPS_PC32", /* name */
1577 TRUE, /* partial_inplace */
1578 0xffffffff, /* src_mask */
1579 0xffffffff, /* dst_mask */
1580 TRUE); /* pcrel_offset */
1581
c6e90b02
TS
1582/* GNU extension to record C++ vtable hierarchy */
1583static reloc_howto_type elf_mips_gnu_vtinherit_howto =
1584 HOWTO (R_MIPS_GNU_VTINHERIT, /* type */
252b5132
RH
1585 0, /* rightshift */
1586 2, /* size (0 = byte, 1 = short, 2 = long) */
c6e90b02 1587 0, /* bitsize */
b34976b6 1588 FALSE, /* pc_relative */
252b5132 1589 0, /* bitpos */
c6e90b02
TS
1590 complain_overflow_dont, /* complain_on_overflow */
1591 NULL, /* special_function */
1592 "R_MIPS_GNU_VTINHERIT", /* name */
b34976b6 1593 FALSE, /* partial_inplace */
d75bc93d 1594 0, /* src_mask */
c6e90b02 1595 0, /* dst_mask */
b34976b6 1596 FALSE); /* pcrel_offset */
252b5132 1597
c6e90b02
TS
1598/* GNU extension to record C++ vtable member usage */
1599static reloc_howto_type elf_mips_gnu_vtentry_howto =
1600 HOWTO (R_MIPS_GNU_VTENTRY, /* type */
252b5132
RH
1601 0, /* rightshift */
1602 2, /* size (0 = byte, 1 = short, 2 = long) */
c6e90b02 1603 0, /* bitsize */
b34976b6 1604 FALSE, /* pc_relative */
252b5132
RH
1605 0, /* bitpos */
1606 complain_overflow_dont, /* complain_on_overflow */
c6e90b02
TS
1607 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1608 "R_MIPS_GNU_VTENTRY", /* name */
b34976b6 1609 FALSE, /* partial_inplace */
d75bc93d 1610 0, /* src_mask */
c6e90b02 1611 0, /* dst_mask */
b34976b6 1612 FALSE); /* pcrel_offset */
252b5132 1613
861fb55a
DJ
1614/* Originally a VxWorks extension, but now used for other systems too. */
1615static reloc_howto_type elf_mips_copy_howto =
1616 HOWTO (R_MIPS_COPY, /* type */
1617 0, /* rightshift */
1618 0, /* this one is variable size */
1619 0, /* bitsize */
1620 FALSE, /* pc_relative */
1621 0, /* bitpos */
1622 complain_overflow_bitfield, /* complain_on_overflow */
d150b1a2 1623 _bfd_mips_elf_generic_reloc, /* special_function */
861fb55a
DJ
1624 "R_MIPS_COPY", /* name */
1625 FALSE, /* partial_inplace */
07d6d2b8
AM
1626 0x0, /* src_mask */
1627 0x0, /* dst_mask */
861fb55a
DJ
1628 FALSE); /* pcrel_offset */
1629
1630/* Originally a VxWorks extension, but now used for other systems too. */
1631static reloc_howto_type elf_mips_jump_slot_howto =
1632 HOWTO (R_MIPS_JUMP_SLOT, /* type */
1633 0, /* rightshift */
1634 2, /* size (0 = byte, 1 = short, 2 = long) */
1635 32, /* bitsize */
1636 FALSE, /* pc_relative */
1637 0, /* bitpos */
1638 complain_overflow_bitfield, /* complain_on_overflow */
d150b1a2 1639 _bfd_mips_elf_generic_reloc, /* special_function */
861fb55a
DJ
1640 "R_MIPS_JUMP_SLOT", /* name */
1641 FALSE, /* partial_inplace */
07d6d2b8
AM
1642 0x0, /* src_mask */
1643 0x0, /* dst_mask */
861fb55a
DJ
1644 FALSE); /* pcrel_offset */
1645
067ec077
CM
1646/* Used in EH tables. */
1647static reloc_howto_type elf_mips_eh_howto =
1648 HOWTO (R_MIPS_EH, /* type */
1649 0, /* rightshift */
1650 2, /* size (0 = byte, 1 = short, 2 = long) */
1651 32, /* bitsize */
1652 FALSE, /* pc_relative */
1653 0, /* bitpos */
1654 complain_overflow_signed, /* complain_on_overflow */
1655 _bfd_mips_elf_generic_reloc, /* special_function */
1656 "R_MIPS_EH", /* name */
1657 TRUE, /* partial_inplace */
1658 0xffffffff, /* src_mask */
07d6d2b8 1659 0xffffffff, /* dst_mask */
067ec077
CM
1660 FALSE); /* pcrel_offset */
1661
b34976b6 1662/* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a
c6e90b02 1663 dangerous relocation. */
252b5132 1664
b34976b6 1665static bfd_boolean
11a2be4d 1666mips_elf_assign_gp (bfd *output_bfd, bfd_vma *pgp)
252b5132 1667{
c6e90b02
TS
1668 unsigned int count;
1669 asymbol **sym;
1670 unsigned int i;
e92d460e 1671
c6e90b02
TS
1672 /* If we've already figured out what GP will be, just return it. */
1673 *pgp = _bfd_get_gp_value (output_bfd);
1674 if (*pgp)
b34976b6 1675 return TRUE;
c6e90b02
TS
1676
1677 count = bfd_get_symcount (output_bfd);
1678 sym = bfd_get_outsymbols (output_bfd);
252b5132 1679
c6e90b02
TS
1680 /* The linker script will have created a symbol named `_gp' with the
1681 appropriate value. */
11a2be4d 1682 if (sym == NULL)
c6e90b02
TS
1683 i = count;
1684 else
252b5132 1685 {
c6e90b02
TS
1686 for (i = 0; i < count; i++, sym++)
1687 {
1688 register const char *name;
1689
1690 name = bfd_asymbol_name (*sym);
1691 if (*name == '_' && strcmp (name, "_gp") == 0)
1692 {
1693 *pgp = bfd_asymbol_value (*sym);
1694 _bfd_set_gp_value (output_bfd, *pgp);
1695 break;
1696 }
1697 }
252b5132
RH
1698 }
1699
c6e90b02 1700 if (i >= count)
252b5132 1701 {
c6e90b02
TS
1702 /* Only get the error once. */
1703 *pgp = 4;
1704 _bfd_set_gp_value (output_bfd, *pgp);
b34976b6 1705 return FALSE;
252b5132
RH
1706 }
1707
b34976b6 1708 return TRUE;
252b5132
RH
1709}
1710
c6e90b02
TS
1711/* We have to figure out the gp value, so that we can adjust the
1712 symbol value correctly. We look up the symbol _gp in the output
1713 BFD. If we can't find it, we're stuck. We cache it in the ELF
1714 target data. We don't need to adjust the symbol value for an
1049f94e 1715 external symbol if we are producing relocatable output. */
252b5132 1716
c6e90b02 1717static bfd_reloc_status_type
11a2be4d
RS
1718mips_elf_final_gp (bfd *output_bfd, asymbol *symbol, bfd_boolean relocatable,
1719 char **error_message, bfd_vma *pgp)
252b5132 1720{
c6e90b02 1721 if (bfd_is_und_section (symbol->section)
1049f94e 1722 && ! relocatable)
252b5132 1723 {
c6e90b02
TS
1724 *pgp = 0;
1725 return bfd_reloc_undefined;
252b5132
RH
1726 }
1727
c6e90b02
TS
1728 *pgp = _bfd_get_gp_value (output_bfd);
1729 if (*pgp == 0
1049f94e 1730 && (! relocatable
c6e90b02 1731 || (symbol->flags & BSF_SECTION_SYM) != 0))
252b5132 1732 {
1049f94e 1733 if (relocatable)
252b5132 1734 {
c6e90b02 1735 /* Make up a value. */
453f5985 1736 *pgp = symbol->section->output_section->vma /*+ 0x4000*/;
c6e90b02 1737 _bfd_set_gp_value (output_bfd, *pgp);
252b5132 1738 }
c6e90b02 1739 else if (!mips_elf_assign_gp (output_bfd, pgp))
252b5132 1740 {
c6e90b02
TS
1741 *error_message =
1742 (char *) _("GP relative relocation when _gp not defined");
1743 return bfd_reloc_dangerous;
252b5132 1744 }
252b5132
RH
1745 }
1746
c6e90b02
TS
1747 return bfd_reloc_ok;
1748}
252b5132 1749
c6e90b02
TS
1750/* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1751 become the offset from the gp register. This function also handles
1752 R_MIPS_LITERAL relocations, although those can be handled more
1753 cleverly because the entries in the .lit8 and .lit4 sections can be
1754 merged. */
252b5132 1755
c6e90b02 1756bfd_reloc_status_type
11a2be4d
RS
1757_bfd_mips_elf32_gprel16_reloc (bfd *abfd, arelent *reloc_entry,
1758 asymbol *symbol, void *data,
1759 asection *input_section, bfd *output_bfd,
1760 char **error_message)
c6e90b02 1761{
1049f94e 1762 bfd_boolean relocatable;
c6e90b02 1763 bfd_reloc_status_type ret;
df58fc94 1764 bfd_byte *location;
c6e90b02 1765 bfd_vma gp;
252b5132 1766
df58fc94
RS
1767 /* R_MIPS_LITERAL/R_MICROMIPS_LITERAL relocations are defined for local
1768 symbols only. */
1769 if (literal_reloc_p (reloc_entry->howto->type)
254f0426
MR
1770 && output_bfd != NULL
1771 && (symbol->flags & BSF_SECTION_SYM) == 0
1772 && (symbol->flags & BSF_LOCAL) != 0)
1773 {
1774 *error_message = (char *)
1775 _("literal relocation occurs for an external symbol");
1776 return bfd_reloc_outofrange;
1777 }
1778
11a2be4d 1779 if (output_bfd != NULL)
1049f94e 1780 relocatable = TRUE;
c6e90b02
TS
1781 else
1782 {
1049f94e 1783 relocatable = FALSE;
c6e90b02
TS
1784 output_bfd = symbol->section->output_section->owner;
1785 }
252b5132 1786
1049f94e 1787 ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
c6e90b02
TS
1788 &gp);
1789 if (ret != bfd_reloc_ok)
1790 return ret;
252b5132 1791
df58fc94
RS
1792 location = (bfd_byte *) data + reloc_entry->address;
1793 _bfd_mips_elf_reloc_unshuffle (abfd, reloc_entry->howto->type, FALSE,
1794 location);
1795 ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1796 input_section, relocatable,
1797 data, gp);
1798 _bfd_mips_elf_reloc_shuffle (abfd, reloc_entry->howto->type, !relocatable,
1799 location);
1800
1801 return ret;
c6e90b02 1802}
252b5132 1803
cb7394f2
TS
1804/* Do a R_MIPS_GPREL32 relocation. This is a 32 bit value which must
1805 become the offset from the gp register. */
252b5132 1806
c6e90b02 1807static bfd_reloc_status_type
11a2be4d
RS
1808mips_elf_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1809 void *data, asection *input_section, bfd *output_bfd,
1810 char **error_message)
c6e90b02 1811{
1049f94e 1812 bfd_boolean relocatable;
c6e90b02
TS
1813 bfd_reloc_status_type ret;
1814 bfd_vma gp;
252b5132 1815
765f2ef6
MR
1816 /* R_MIPS_GPREL32 relocations are defined for local symbols only. */
1817 if (output_bfd != NULL
1818 && (symbol->flags & BSF_SECTION_SYM) == 0
1819 && (symbol->flags & BSF_LOCAL) != 0)
1820 {
1821 *error_message = (char *)
1822 _("32bits gp relative relocation occurs for an external symbol");
1823 return bfd_reloc_outofrange;
1824 }
1825
11a2be4d 1826 if (output_bfd != NULL)
1049f94e 1827 relocatable = TRUE;
c6e90b02
TS
1828 else
1829 {
1049f94e 1830 relocatable = FALSE;
c6e90b02 1831 output_bfd = symbol->section->output_section->owner;
c6e90b02 1832 }
252b5132 1833
1049f94e 1834 ret = mips_elf_final_gp (output_bfd, symbol, relocatable,
a7ebbfdf
TS
1835 error_message, &gp);
1836 if (ret != bfd_reloc_ok)
1837 return ret;
1838
c6e90b02 1839 return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
1049f94e 1840 relocatable, data, gp);
c6e90b02 1841}
252b5132 1842
c6e90b02 1843static bfd_reloc_status_type
11a2be4d
RS
1844gprel32_with_gp (bfd *abfd, asymbol *symbol, arelent *reloc_entry,
1845 asection *input_section, bfd_boolean relocatable,
1846 void *data, bfd_vma gp)
c6e90b02
TS
1847{
1848 bfd_vma relocation;
a7ebbfdf 1849 bfd_vma val;
252b5132 1850
c6e90b02
TS
1851 if (bfd_is_com_section (symbol->section))
1852 relocation = 0;
1853 else
1854 relocation = symbol->value;
252b5132 1855
c6e90b02
TS
1856 relocation += symbol->section->output_section->vma;
1857 relocation += symbol->section->output_offset;
252b5132 1858
07515404 1859 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
c6e90b02 1860 return bfd_reloc_outofrange;
252b5132 1861
c6e90b02 1862 /* Set val to the offset into the section or symbol. */
a7ebbfdf
TS
1863 val = reloc_entry->addend;
1864
1865 if (reloc_entry->howto->partial_inplace)
1866 val += bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
252b5132 1867
c6e90b02 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
c6e90b02 1870 an external symbol. */
1049f94e 1871 if (! relocatable
c6e90b02
TS
1872 || (symbol->flags & BSF_SECTION_SYM) != 0)
1873 val += relocation - gp;
252b5132 1874
a7ebbfdf
TS
1875 if (reloc_entry->howto->partial_inplace)
1876 bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
1877 else
1878 reloc_entry->addend = val;
c6142e5d 1879
1049f94e 1880 if (relocatable)
c6e90b02 1881 reloc_entry->address += input_section->output_offset;
252b5132 1882
c6e90b02 1883 return bfd_reloc_ok;
252b5132
RH
1884}
1885
c6e90b02
TS
1886/* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1887 generated when addresses are 64 bits. The upper 32 bits are a simple
1888 sign extension. */
7403cb63 1889
c6e90b02 1890static bfd_reloc_status_type
30ac9238
RS
1891mips32_64bit_reloc (bfd *abfd, arelent *reloc_entry,
1892 asymbol *symbol ATTRIBUTE_UNUSED,
1893 void *data, asection *input_section,
1894 bfd *output_bfd, char **error_message)
7403cb63 1895{
c6e90b02
TS
1896 bfd_reloc_status_type r;
1897 arelent reloc32;
1898 unsigned long val;
1899 bfd_size_type addr;
7403cb63 1900
c6e90b02
TS
1901 /* Do a normal 32 bit relocation on the lower 32 bits. */
1902 reloc32 = *reloc_entry;
1903 if (bfd_big_endian (abfd))
1904 reloc32.address += 4;
1905 reloc32.howto = &elf_mips_howto_table_rel[R_MIPS_32];
1906 r = bfd_perform_relocation (abfd, &reloc32, data, input_section,
1907 output_bfd, error_message);
be3ccd9c 1908
c6e90b02
TS
1909 /* Sign extend into the upper 32 bits. */
1910 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc32.address);
1911 if ((val & 0x80000000) != 0)
1912 val = 0xffffffff;
1913 else
1914 val = 0;
1915 addr = reloc_entry->address;
1916 if (bfd_little_endian (abfd))
1917 addr += 4;
11a2be4d 1918 bfd_put_32 (abfd, val, (bfd_byte *) data + addr);
c6e90b02
TS
1919
1920 return r;
7403cb63
MM
1921}
1922
c6e90b02 1923/* Handle a mips16 GP relative reloc. */
252b5132 1924
c6e90b02 1925static bfd_reloc_status_type
11a2be4d
RS
1926mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1927 void *data, asection *input_section, bfd *output_bfd,
1928 char **error_message)
c6e90b02 1929{
1049f94e 1930 bfd_boolean relocatable;
c6e90b02 1931 bfd_reloc_status_type ret;
d6f16593 1932 bfd_byte *location;
c6e90b02 1933 bfd_vma gp;
252b5132 1934
a7ebbfdf
TS
1935 /* If we're relocating, and this is an external symbol, we don't want
1936 to change anything. */
c6e90b02
TS
1937 if (output_bfd != NULL
1938 && (symbol->flags & BSF_SECTION_SYM) == 0
a7ebbfdf 1939 && (symbol->flags & BSF_LOCAL) != 0)
c6e90b02
TS
1940 {
1941 reloc_entry->address += input_section->output_offset;
1942 return bfd_reloc_ok;
1943 }
252b5132 1944
c6e90b02 1945 if (output_bfd != NULL)
1049f94e 1946 relocatable = TRUE;
c6e90b02
TS
1947 else
1948 {
1049f94e 1949 relocatable = FALSE;
c6e90b02 1950 output_bfd = symbol->section->output_section->owner;
252b5132
RH
1951 }
1952
1049f94e 1953 ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
c6e90b02
TS
1954 &gp);
1955 if (ret != bfd_reloc_ok)
1956 return ret;
252b5132 1957
d6f16593 1958 location = (bfd_byte *) data + reloc_entry->address;
df58fc94
RS
1959 _bfd_mips_elf_reloc_unshuffle (abfd, reloc_entry->howto->type, FALSE,
1960 location);
d6f16593
MR
1961 ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1962 input_section, relocatable,
1963 data, gp);
df58fc94
RS
1964 _bfd_mips_elf_reloc_shuffle (abfd, reloc_entry->howto->type, !relocatable,
1965 location);
a7ebbfdf 1966
d6f16593 1967 return ret;
c6e90b02 1968}
7403cb63 1969
c6e90b02 1970/* A mapping from BFD reloc types to MIPS ELF reloc types. */
252b5132 1971
c6e90b02 1972struct elf_reloc_map {
cb7394f2
TS
1973 bfd_reloc_code_real_type bfd_val;
1974 enum elf_mips_reloc_type elf_val;
c6e90b02 1975};
252b5132 1976
c6e90b02
TS
1977static const struct elf_reloc_map mips_reloc_map[] =
1978{
28458e7e 1979 { BFD_RELOC_NONE, R_MIPS_NONE },
c6e90b02
TS
1980 { BFD_RELOC_16, R_MIPS_16 },
1981 { BFD_RELOC_32, R_MIPS_32 },
cb7394f2 1982 /* There is no BFD reloc for R_MIPS_REL32. */
c6e90b02
TS
1983 { BFD_RELOC_64, R_MIPS_64 },
1984 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
1985 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
1986 { BFD_RELOC_LO16, R_MIPS_LO16 },
1987 { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
1988 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
1989 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
bad36eac 1990 { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
c6e90b02
TS
1991 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
1992 { BFD_RELOC_GPREL32, R_MIPS_GPREL32 },
1993 { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
1994 { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
1995 { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
1996 { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
1997 { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
1998 { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
1999 { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
0f20cc35 2000 { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP },
cd8d5a82 2001 { BFD_RELOC_MIPS_JALR, R_MIPS_JALR },
0f20cc35
DJ
2002 { BFD_RELOC_MIPS_TLS_DTPMOD32, R_MIPS_TLS_DTPMOD32 },
2003 { BFD_RELOC_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL32 },
2004 { BFD_RELOC_MIPS_TLS_DTPMOD64, R_MIPS_TLS_DTPMOD64 },
2005 { BFD_RELOC_MIPS_TLS_DTPREL64, R_MIPS_TLS_DTPREL64 },
2006 { BFD_RELOC_MIPS_TLS_GD, R_MIPS_TLS_GD },
2007 { BFD_RELOC_MIPS_TLS_LDM, R_MIPS_TLS_LDM },
2008 { BFD_RELOC_MIPS_TLS_DTPREL_HI16, R_MIPS_TLS_DTPREL_HI16 },
2009 { BFD_RELOC_MIPS_TLS_DTPREL_LO16, R_MIPS_TLS_DTPREL_LO16 },
2010 { BFD_RELOC_MIPS_TLS_GOTTPREL, R_MIPS_TLS_GOTTPREL },
2011 { BFD_RELOC_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL32 },
2012 { BFD_RELOC_MIPS_TLS_TPREL64, R_MIPS_TLS_TPREL64 },
2013 { BFD_RELOC_MIPS_TLS_TPREL_HI16, R_MIPS_TLS_TPREL_HI16 },
7361da2c
AB
2014 { BFD_RELOC_MIPS_TLS_TPREL_LO16, R_MIPS_TLS_TPREL_LO16 },
2015 { BFD_RELOC_MIPS_21_PCREL_S2, R_MIPS_PC21_S2 },
2016 { BFD_RELOC_MIPS_26_PCREL_S2, R_MIPS_PC26_S2 },
2017 { BFD_RELOC_MIPS_18_PCREL_S3, R_MIPS_PC18_S3 },
2018 { BFD_RELOC_MIPS_19_PCREL_S2, R_MIPS_PC19_S2 },
2019 { BFD_RELOC_HI16_S_PCREL, R_MIPS_PCHI16 },
2020 { BFD_RELOC_LO16_PCREL, R_MIPS_PCLO16 }
c6e90b02 2021};
252b5132 2022
d6f16593
MR
2023static const struct elf_reloc_map mips16_reloc_map[] =
2024{
2025 { BFD_RELOC_MIPS16_JMP, R_MIPS16_26 - R_MIPS16_min },
2026 { BFD_RELOC_MIPS16_GPREL, R_MIPS16_GPREL - R_MIPS16_min },
738e5348
RS
2027 { BFD_RELOC_MIPS16_GOT16, R_MIPS16_GOT16 - R_MIPS16_min },
2028 { BFD_RELOC_MIPS16_CALL16, R_MIPS16_CALL16 - R_MIPS16_min },
d6f16593
MR
2029 { BFD_RELOC_MIPS16_HI16_S, R_MIPS16_HI16 - R_MIPS16_min },
2030 { BFD_RELOC_MIPS16_LO16, R_MIPS16_LO16 - R_MIPS16_min },
d0f13682
CLT
2031 { BFD_RELOC_MIPS16_TLS_GD, R_MIPS16_TLS_GD - R_MIPS16_min },
2032 { BFD_RELOC_MIPS16_TLS_LDM, R_MIPS16_TLS_LDM - R_MIPS16_min },
2033 { BFD_RELOC_MIPS16_TLS_DTPREL_HI16,
2034 R_MIPS16_TLS_DTPREL_HI16 - R_MIPS16_min },
2035 { BFD_RELOC_MIPS16_TLS_DTPREL_LO16,
2036 R_MIPS16_TLS_DTPREL_LO16 - R_MIPS16_min },
2037 { BFD_RELOC_MIPS16_TLS_GOTTPREL, R_MIPS16_TLS_GOTTPREL - R_MIPS16_min },
2038 { BFD_RELOC_MIPS16_TLS_TPREL_HI16, R_MIPS16_TLS_TPREL_HI16 - R_MIPS16_min },
c9775dde
MR
2039 { BFD_RELOC_MIPS16_TLS_TPREL_LO16, R_MIPS16_TLS_TPREL_LO16 - R_MIPS16_min },
2040 { BFD_RELOC_MIPS16_16_PCREL_S1, R_MIPS16_PC16_S1 - R_MIPS16_min }
d6f16593
MR
2041};
2042
df58fc94
RS
2043static const struct elf_reloc_map micromips_reloc_map[] =
2044{
2045 { BFD_RELOC_MICROMIPS_JMP, R_MICROMIPS_26_S1 - R_MICROMIPS_min },
2046 { BFD_RELOC_MICROMIPS_HI16_S, R_MICROMIPS_HI16 - R_MICROMIPS_min },
2047 { BFD_RELOC_MICROMIPS_LO16, R_MICROMIPS_LO16 - R_MICROMIPS_min },
2048 { BFD_RELOC_MICROMIPS_GPREL16, R_MICROMIPS_GPREL16 - R_MICROMIPS_min },
2049 { BFD_RELOC_MICROMIPS_LITERAL, R_MICROMIPS_LITERAL - R_MICROMIPS_min },
2050 { BFD_RELOC_MICROMIPS_GOT16, R_MICROMIPS_GOT16 - R_MICROMIPS_min },
2051 { BFD_RELOC_MICROMIPS_7_PCREL_S1, R_MICROMIPS_PC7_S1 - R_MICROMIPS_min },
2052 { BFD_RELOC_MICROMIPS_10_PCREL_S1, R_MICROMIPS_PC10_S1 - R_MICROMIPS_min },
2053 { BFD_RELOC_MICROMIPS_16_PCREL_S1, R_MICROMIPS_PC16_S1 - R_MICROMIPS_min },
2054 { BFD_RELOC_MICROMIPS_CALL16, R_MICROMIPS_CALL16 - R_MICROMIPS_min },
2055 { BFD_RELOC_MICROMIPS_GOT_DISP, R_MICROMIPS_GOT_DISP - R_MICROMIPS_min },
2056 { BFD_RELOC_MICROMIPS_GOT_PAGE, R_MICROMIPS_GOT_PAGE - R_MICROMIPS_min },
2057 { BFD_RELOC_MICROMIPS_GOT_OFST, R_MICROMIPS_GOT_OFST - R_MICROMIPS_min },
2058 { BFD_RELOC_MICROMIPS_GOT_HI16, R_MICROMIPS_GOT_HI16 - R_MICROMIPS_min },
2059 { BFD_RELOC_MICROMIPS_GOT_LO16, R_MICROMIPS_GOT_LO16 - R_MICROMIPS_min },
2060 { BFD_RELOC_MICROMIPS_SUB, R_MICROMIPS_SUB - R_MICROMIPS_min },
2061 { BFD_RELOC_MICROMIPS_HIGHER, R_MICROMIPS_HIGHER - R_MICROMIPS_min },
2062 { BFD_RELOC_MICROMIPS_HIGHEST, R_MICROMIPS_HIGHEST - R_MICROMIPS_min },
2063 { BFD_RELOC_MICROMIPS_CALL_HI16, R_MICROMIPS_CALL_HI16 - R_MICROMIPS_min },
2064 { BFD_RELOC_MICROMIPS_CALL_LO16, R_MICROMIPS_CALL_LO16 - R_MICROMIPS_min },
2065 { BFD_RELOC_MICROMIPS_SCN_DISP, R_MICROMIPS_SCN_DISP - R_MICROMIPS_min },
2066 { BFD_RELOC_MICROMIPS_JALR, R_MICROMIPS_JALR - R_MICROMIPS_min },
2067 /* There is no BFD reloc for R_MICROMIPS_HI0_LO16. */
2068 { BFD_RELOC_MICROMIPS_TLS_GD, R_MICROMIPS_TLS_GD - R_MICROMIPS_min },
2069 { BFD_RELOC_MICROMIPS_TLS_LDM, R_MICROMIPS_TLS_LDM - R_MICROMIPS_min },
2070 { BFD_RELOC_MICROMIPS_TLS_DTPREL_HI16,
2071 R_MICROMIPS_TLS_DTPREL_HI16 - R_MICROMIPS_min },
2072 { BFD_RELOC_MICROMIPS_TLS_DTPREL_LO16,
2073 R_MICROMIPS_TLS_DTPREL_LO16 - R_MICROMIPS_min },
2074 { BFD_RELOC_MICROMIPS_TLS_GOTTPREL,
2075 R_MICROMIPS_TLS_GOTTPREL - R_MICROMIPS_min },
2076 { BFD_RELOC_MICROMIPS_TLS_TPREL_HI16,
2077 R_MICROMIPS_TLS_TPREL_HI16 - R_MICROMIPS_min },
2078 { BFD_RELOC_MICROMIPS_TLS_TPREL_LO16,
2079 R_MICROMIPS_TLS_TPREL_LO16 - R_MICROMIPS_min },
2080 /* There is no BFD reloc for R_MICROMIPS_GPREL7_S2. */
2081 /* There is no BFD reloc for R_MICROMIPS_PC23_S2. */
2082};
2083
c6e90b02 2084/* Given a BFD reloc type, return a howto structure. */
252b5132 2085
c6e90b02 2086static reloc_howto_type *
11a2be4d 2087bfd_elf32_bfd_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code)
252b5132 2088{
c6e90b02 2089 unsigned int i;
cb7394f2 2090 reloc_howto_type *howto_table = elf_mips_howto_table_rel;
d6f16593 2091 reloc_howto_type *howto16_table = elf_mips16_howto_table_rel;
df58fc94 2092 reloc_howto_type *howto_micromips_table = elf_micromips_howto_table_rel;
252b5132 2093
cb7394f2
TS
2094 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map);
2095 i++)
252b5132 2096 {
cb7394f2
TS
2097 if (mips_reloc_map[i].bfd_val == code)
2098 return &howto_table[(int) mips_reloc_map[i].elf_val];
252b5132
RH
2099 }
2100
d6f16593
MR
2101 for (i = 0; i < sizeof (mips16_reloc_map) / sizeof (struct elf_reloc_map);
2102 i++)
2103 {
2104 if (mips16_reloc_map[i].bfd_val == code)
2105 return &howto16_table[(int) mips16_reloc_map[i].elf_val];
2106 }
2107
df58fc94
RS
2108 for (i = 0; i < sizeof (micromips_reloc_map) / sizeof (struct elf_reloc_map);
2109 i++)
2110 {
2111 if (micromips_reloc_map[i].bfd_val == code)
2112 return &howto_micromips_table[(int) micromips_reloc_map[i].elf_val];
2113 }
2114
c6e90b02 2115 switch (code)
252b5132 2116 {
c6e90b02
TS
2117 default:
2118 bfd_set_error (bfd_error_bad_value);
2119 return NULL;
252b5132 2120
c6e90b02
TS
2121 case BFD_RELOC_CTOR:
2122 /* We need to handle BFD_RELOC_CTOR specially.
2123 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
69931e60
AO
2124 size of addresses of the ABI. */
2125 if ((elf_elfheader (abfd)->e_flags & (E_MIPS_ABI_O64
2126 | E_MIPS_ABI_EABI64)) != 0)
c6e90b02 2127 return &elf_mips_ctor64_howto;
69931e60
AO
2128 else
2129 return &howto_table[(int) R_MIPS_32];
252b5132 2130
c6e90b02
TS
2131 case BFD_RELOC_VTABLE_INHERIT:
2132 return &elf_mips_gnu_vtinherit_howto;
2133 case BFD_RELOC_VTABLE_ENTRY:
2134 return &elf_mips_gnu_vtentry_howto;
092dcd75
CD
2135 case BFD_RELOC_32_PCREL:
2136 return &elf_mips_gnu_pcrel32;
861fb55a
DJ
2137 case BFD_RELOC_MIPS_COPY:
2138 return &elf_mips_copy_howto;
2139 case BFD_RELOC_MIPS_JUMP_SLOT:
2140 return &elf_mips_jump_slot_howto;
067ec077
CM
2141 case BFD_RELOC_MIPS_EH:
2142 return &elf_mips_eh_howto;
c6e90b02
TS
2143 }
2144}
252b5132 2145
157090f7
AM
2146static reloc_howto_type *
2147bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2148 const char *r_name)
2149{
2150 unsigned int i;
2151
2152 for (i = 0;
2153 i < (sizeof (elf_mips_howto_table_rel)
2154 / sizeof (elf_mips_howto_table_rel[0]));
2155 i++)
2156 if (elf_mips_howto_table_rel[i].name != NULL
2157 && strcasecmp (elf_mips_howto_table_rel[i].name, r_name) == 0)
2158 return &elf_mips_howto_table_rel[i];
2159
2160 for (i = 0;
2161 i < (sizeof (elf_mips16_howto_table_rel)
2162 / sizeof (elf_mips16_howto_table_rel[0]));
2163 i++)
2164 if (elf_mips16_howto_table_rel[i].name != NULL
2165 && strcasecmp (elf_mips16_howto_table_rel[i].name, r_name) == 0)
2166 return &elf_mips16_howto_table_rel[i];
2167
df58fc94
RS
2168 for (i = 0;
2169 i < (sizeof (elf_micromips_howto_table_rel)
2170 / sizeof (elf_micromips_howto_table_rel[0]));
2171 i++)
2172 if (elf_micromips_howto_table_rel[i].name != NULL
2173 && strcasecmp (elf_micromips_howto_table_rel[i].name, r_name) == 0)
2174 return &elf_micromips_howto_table_rel[i];
2175
157090f7
AM
2176 if (strcasecmp (elf_mips_gnu_pcrel32.name, r_name) == 0)
2177 return &elf_mips_gnu_pcrel32;
2178 if (strcasecmp (elf_mips_gnu_rel16_s2.name, r_name) == 0)
2179 return &elf_mips_gnu_rel16_s2;
2180 if (strcasecmp (elf_mips_gnu_vtinherit_howto.name, r_name) == 0)
2181 return &elf_mips_gnu_vtinherit_howto;
2182 if (strcasecmp (elf_mips_gnu_vtentry_howto.name, r_name) == 0)
2183 return &elf_mips_gnu_vtentry_howto;
861fb55a
DJ
2184 if (strcasecmp (elf_mips_copy_howto.name, r_name) == 0)
2185 return &elf_mips_copy_howto;
2186 if (strcasecmp (elf_mips_jump_slot_howto.name, r_name) == 0)
2187 return &elf_mips_jump_slot_howto;
067ec077
CM
2188 if (strcasecmp (elf_mips_eh_howto.name, r_name) == 0)
2189 return &elf_mips_eh_howto;
157090f7
AM
2190
2191 return NULL;
2192}
2193
947216bf 2194/* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
252b5132 2195
c6e90b02 2196static reloc_howto_type *
0aa13fee
AM
2197mips_elf32_rtype_to_howto (bfd *abfd,
2198 unsigned int r_type,
11a2be4d 2199 bfd_boolean rela_p ATTRIBUTE_UNUSED)
c6e90b02 2200{
7ed6f92a
MR
2201 reloc_howto_type *howto = NULL;
2202
c6e90b02
TS
2203 switch (r_type)
2204 {
c6e90b02
TS
2205 case R_MIPS_GNU_VTINHERIT:
2206 return &elf_mips_gnu_vtinherit_howto;
c6e90b02
TS
2207 case R_MIPS_GNU_VTENTRY:
2208 return &elf_mips_gnu_vtentry_howto;
c6e90b02
TS
2209 case R_MIPS_GNU_REL16_S2:
2210 return &elf_mips_gnu_rel16_s2;
092dcd75
CD
2211 case R_MIPS_PC32:
2212 return &elf_mips_gnu_pcrel32;
861fb55a
DJ
2213 case R_MIPS_COPY:
2214 return &elf_mips_copy_howto;
2215 case R_MIPS_JUMP_SLOT:
2216 return &elf_mips_jump_slot_howto;
067ec077
CM
2217 case R_MIPS_EH:
2218 return &elf_mips_eh_howto;
c6e90b02 2219 default:
df58fc94 2220 if (r_type >= R_MICROMIPS_min && r_type < R_MICROMIPS_max)
7ed6f92a 2221 howto = &elf_micromips_howto_table_rel[r_type - R_MICROMIPS_min];
d6f16593 2222 if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max)
7ed6f92a
MR
2223 howto = &elf_mips16_howto_table_rel[r_type - R_MIPS16_min];
2224 if (r_type < R_MIPS_max)
2225 howto = &elf_mips_howto_table_rel[r_type];
2226 if (howto != NULL && howto->name != NULL)
2227 return howto;
2228
2229 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2230 abfd, r_type);
2231 bfd_set_error (bfd_error_bad_value);
2232 return NULL;
c6e90b02
TS
2233 }
2234}
252b5132 2235
947216bf 2236/* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
252b5132 2237
f3185997 2238static bfd_boolean
11a2be4d 2239mips_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
c6e90b02
TS
2240{
2241 unsigned int r_type;
252b5132 2242
c6e90b02 2243 r_type = ELF32_R_TYPE (dst->r_info);
8205a328 2244 cache_ptr->howto = mips_elf32_rtype_to_howto (abfd, r_type, FALSE);
75def2ab 2245
f3185997 2246 if (cache_ptr->howto == NULL)
75def2ab 2247 return FALSE;
252b5132 2248
c6e90b02
TS
2249 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
2250 value for the object file. We get the addend now, rather than
2251 when we do the relocation, because the symbol manipulations done
2252 by the linker may cause us to lose track of the input BFD. */
2253 if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
df58fc94 2254 && (gprel16_reloc_p (r_type) || literal_reloc_p (r_type)))
c6e90b02 2255 cache_ptr->addend = elf_gp (abfd);
f3185997
NC
2256
2257 return TRUE;
c6e90b02 2258}
5499724a 2259
947216bf 2260/* Given a MIPS Elf_Internal_Rela, fill in an arelent structure. */
252b5132 2261
f3185997 2262static bfd_boolean
11a2be4d 2263mips_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
c6e90b02 2264{
f3185997 2265 return mips_info_to_howto_rel (abfd, cache_ptr, dst);
252b5132 2266
c6e90b02 2267 /* If we ever need to do any extra processing with dst->r_addend
947216bf 2268 (the field omitted in an Elf_Internal_Rel) we can do it here. */
c6e90b02
TS
2269}
2270\f
2271/* Determine whether a symbol is global for the purposes of splitting
2272 the symbol table into global symbols and local symbols. At least
2273 on Irix 5, this split must be between section symbols and all other
2274 symbols. On most ELF targets the split is between static symbols
2275 and externally visible symbols. */
252b5132 2276
b34976b6 2277static bfd_boolean
11a2be4d 2278mips_elf_sym_is_global (bfd *abfd ATTRIBUTE_UNUSED, asymbol *sym)
c6e90b02
TS
2279{
2280 if (SGI_COMPAT (abfd))
2281 return (sym->flags & BSF_SECTION_SYM) == 0;
2282 else
e47bf690 2283 return ((sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE)) != 0
e6f7f6d1
AM
2284 || bfd_is_und_section (bfd_asymbol_section (sym))
2285 || bfd_is_com_section (bfd_asymbol_section (sym)));
c6e90b02
TS
2286}
2287\f
2288/* Set the right machine number for a MIPS ELF file. */
7403cb63 2289
b34976b6 2290static bfd_boolean
11a2be4d 2291mips_elf32_object_p (bfd *abfd)
c6e90b02
TS
2292{
2293 unsigned long mach;
103186c6 2294
dd2bed3a
MR
2295 if (ABI_N32_P (abfd))
2296 return FALSE;
2297
c6e90b02
TS
2298 /* Irix 5 and 6 are broken. Object file symbol tables are not always
2299 sorted correctly such that local symbols precede global symbols,
2300 and the sh_info field in the symbol table is not always right. */
2301 if (SGI_COMPAT (abfd))
b34976b6 2302 elf_bad_symtab (abfd) = TRUE;
103186c6 2303
c6e90b02
TS
2304 mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
2305 bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
b34976b6 2306 return TRUE;
c6e90b02
TS
2307}
2308\f
2309/* MIPS ELF local labels start with '$', not 'L'. */
252b5132 2310
b34976b6 2311static bfd_boolean
11a2be4d 2312mips_elf_is_local_label_name (bfd *abfd, const char *name)
c6e90b02
TS
2313{
2314 if (name[0] == '$')
b34976b6 2315 return TRUE;
252b5132 2316
c6e90b02
TS
2317 /* On Irix 6, the labels go back to starting with '.', so we accept
2318 the generic ELF local label syntax as well. */
2319 return _bfd_elf_is_local_label_name (abfd, name);
252b5132
RH
2320}
2321\f
c6e90b02 2322/* Support for core dump NOTE sections. */
b34976b6 2323static bfd_boolean
11a2be4d 2324elf32_mips_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
bb0082d6
AM
2325{
2326 int offset;
eea6121a 2327 unsigned int size;
bb0082d6
AM
2328
2329 switch (note->descsz)
2330 {
2331 default:
b34976b6 2332 return FALSE;
bb0082d6
AM
2333
2334 case 256: /* Linux/MIPS */
2335 /* pr_cursig */
228e534f 2336 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
bb0082d6
AM
2337
2338 /* pr_pid */
228e534f 2339 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
bb0082d6
AM
2340
2341 /* pr_reg */
2342 offset = 72;
eea6121a 2343 size = 180;
bb0082d6
AM
2344
2345 break;
2346 }
2347
2348 /* Make a ".reg/999" section. */
936e320b 2349 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
eea6121a 2350 size, note->descpos + offset);
bb0082d6
AM
2351}
2352
b34976b6 2353static bfd_boolean
11a2be4d 2354elf32_mips_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
bb0082d6
AM
2355{
2356 switch (note->descsz)
2357 {
2358 default:
b34976b6 2359 return FALSE;
bb0082d6
AM
2360
2361 case 128: /* Linux/MIPS elf_prpsinfo */
c9ec0e89
DT
2362 elf_tdata (abfd)->core->pid
2363 = bfd_get_32 (abfd, note->descdata + 16);
228e534f 2364 elf_tdata (abfd)->core->program
bb0082d6 2365 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
228e534f 2366 elf_tdata (abfd)->core->command
bb0082d6
AM
2367 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
2368 }
2369
2370 /* Note that for some reason, a spurious space is tacked
2371 onto the end of the args in some (at least one anyway)
2372 implementations, so strip it off if it exists. */
2373
2374 {
228e534f 2375 char *command = elf_tdata (abfd)->core->command;
bb0082d6
AM
2376 int n = strlen (command);
2377
2378 if (0 < n && command[n - 1] == ' ')
2379 command[n - 1] = '\0';
2380 }
2381
b34976b6 2382 return TRUE;
bb0082d6 2383}
9031cb4a
DT
2384
2385/* Write Linux core PRSTATUS note into core file. */
2386
2387static char *
2388elf32_mips_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type,
2389 ...)
2390{
2391 switch (note_type)
2392 {
2393 default:
2394 return NULL;
2395
2396 case NT_PRPSINFO:
2397 BFD_FAIL ();
2398 return NULL;
2399
2400 case NT_PRSTATUS:
2401 {
2402 char data[256];
2403 va_list ap;
2404 long pid;
2405 int cursig;
2406 const void *greg;
2407
2408 va_start (ap, note_type);
2409 memset (data, 0, 72);
2410 pid = va_arg (ap, long);
2411 bfd_put_32 (abfd, pid, data + 24);
2412 cursig = va_arg (ap, int);
2413 bfd_put_16 (abfd, cursig, data + 12);
2414 greg = va_arg (ap, const void *);
2415 memcpy (data + 72, greg, 180);
2416 memset (data + 252, 0, 4);
2417 va_end (ap);
2418 return elfcore_write_note (abfd, buf, bufsiz,
2419 "CORE", note_type, data, sizeof (data));
2420 }
2421 }
2422}
3be08ea4
SA
2423
2424/* Remove the magic _gp_disp symbol from the symbol tables. */
2425
2426static bfd_boolean
2427elf32_mips_fixup_symbol (struct bfd_link_info *info,
2428 struct elf_link_hash_entry *h)
2429{
2430 if (strcmp (h->root.root.string, "_gp_disp") == 0)
2431 _bfd_elf_link_hash_hide_symbol (info, h, TRUE);
2432 return TRUE;
2433}
bb0082d6 2434\f
c6e90b02
TS
2435/* Depending on the target vector we generate some version of Irix
2436 executables or "normal" MIPS ELF ABI executables. */
2437static irix_compat_t
11a2be4d 2438elf32_mips_irix_compat (bfd *abfd)
c6e90b02 2439{
6d00b590
AM
2440 if ((abfd->xvec == &mips_elf32_be_vec)
2441 || (abfd->xvec == &mips_elf32_le_vec))
c6e90b02 2442 return ict_irix5;
cb7394f2
TS
2443 else
2444 return ict_none;
c6e90b02 2445}
73d074b4 2446\f
252b5132
RH
2447/* ECOFF swapping routines. These are used when dealing with the
2448 .mdebug section, which is in the ECOFF debugging format. */
be3ccd9c 2449static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
252b5132
RH
2450 /* Symbol table magic number. */
2451 magicSym,
2452 /* Alignment of debugging information. E.g., 4. */
2453 4,
2454 /* Sizes of external symbolic information. */
2455 sizeof (struct hdr_ext),
2456 sizeof (struct dnr_ext),
2457 sizeof (struct pdr_ext),
2458 sizeof (struct sym_ext),
2459 sizeof (struct opt_ext),
2460 sizeof (struct fdr_ext),
2461 sizeof (struct rfd_ext),
2462 sizeof (struct ext_ext),
2463 /* Functions to swap in external symbolic data. */
2464 ecoff_swap_hdr_in,
2465 ecoff_swap_dnr_in,
2466 ecoff_swap_pdr_in,
2467 ecoff_swap_sym_in,
2468 ecoff_swap_opt_in,
2469 ecoff_swap_fdr_in,
2470 ecoff_swap_rfd_in,
2471 ecoff_swap_ext_in,
2472 _bfd_ecoff_swap_tir_in,
2473 _bfd_ecoff_swap_rndx_in,
2474 /* Functions to swap out external symbolic data. */
2475 ecoff_swap_hdr_out,
2476 ecoff_swap_dnr_out,
2477 ecoff_swap_pdr_out,
2478 ecoff_swap_sym_out,
2479 ecoff_swap_opt_out,
2480 ecoff_swap_fdr_out,
2481 ecoff_swap_rfd_out,
2482 ecoff_swap_ext_out,
2483 _bfd_ecoff_swap_tir_out,
2484 _bfd_ecoff_swap_rndx_out,
2485 /* Function to read in symbolic data. */
2486 _bfd_mips_elf_read_ecoff_info
2487};
2488\f
252b5132 2489#define ELF_ARCH bfd_arch_mips
ae95ffa6 2490#define ELF_TARGET_ID MIPS_ELF_DATA
252b5132
RH
2491#define ELF_MACHINE_CODE EM_MIPS
2492
b34976b6
AM
2493#define elf_backend_collect TRUE
2494#define elf_backend_type_change_ok TRUE
2495#define elf_backend_can_gc_sections TRUE
351cdf24
MF
2496#define elf_backend_gc_mark_extra_sections \
2497 _bfd_mips_elf_gc_mark_extra_sections
3f830999 2498#define elf_info_to_howto mips_info_to_howto_rela
252b5132
RH
2499#define elf_info_to_howto_rel mips_info_to_howto_rel
2500#define elf_backend_sym_is_global mips_elf_sym_is_global
c6e90b02 2501#define elf_backend_object_p mips_elf32_object_p
d75bc93d
TS
2502#define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
2503#define elf_backend_section_processing _bfd_mips_elf_section_processing
103186c6 2504#define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
252b5132
RH
2505#define elf_backend_fake_sections _bfd_mips_elf_fake_sections
2506#define elf_backend_section_from_bfd_section \
2507 _bfd_mips_elf_section_from_bfd_section
103186c6 2508#define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
d75bc93d
TS
2509#define elf_backend_link_output_symbol_hook \
2510 _bfd_mips_elf_link_output_symbol_hook
103186c6
MM
2511#define elf_backend_create_dynamic_sections \
2512 _bfd_mips_elf_create_dynamic_sections
2513#define elf_backend_check_relocs _bfd_mips_elf_check_relocs
8992f0d7
TS
2514#define elf_backend_merge_symbol_attribute \
2515 _bfd_mips_elf_merge_symbol_attribute
ad9563d6 2516#define elf_backend_get_target_dtag _bfd_mips_elf_get_target_dtag
103186c6
MM
2517#define elf_backend_adjust_dynamic_symbol \
2518 _bfd_mips_elf_adjust_dynamic_symbol
2519#define elf_backend_always_size_sections \
2520 _bfd_mips_elf_always_size_sections
2521#define elf_backend_size_dynamic_sections \
2522 _bfd_mips_elf_size_dynamic_sections
74541ad4 2523#define elf_backend_init_index_section _bfd_elf_init_1_index_section
103186c6 2524#define elf_backend_relocate_section _bfd_mips_elf_relocate_section
103186c6
MM
2525#define elf_backend_finish_dynamic_symbol \
2526 _bfd_mips_elf_finish_dynamic_symbol
2527#define elf_backend_finish_dynamic_sections \
2528 _bfd_mips_elf_finish_dynamic_sections
d75bc93d
TS
2529#define elf_backend_final_write_processing \
2530 _bfd_mips_elf_final_write_processing
2531#define elf_backend_additional_program_headers \
2532 _bfd_mips_elf_additional_program_headers
2533#define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
103186c6 2534#define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
8a20f077
UC
2535#define elf_backend_copy_indirect_symbol \
2536 _bfd_mips_elf_copy_indirect_symbol
47275900 2537#define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
3be08ea4 2538#define elf_backend_fixup_symbol elf32_mips_fixup_symbol
c6e90b02
TS
2539#define elf_backend_grok_prstatus elf32_mips_grok_prstatus
2540#define elf_backend_grok_psinfo elf32_mips_grok_psinfo
d75bc93d
TS
2541#define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
2542
2543#define elf_backend_got_header_size (4 * MIPS_RESERVED_GOTNO)
5474d94f 2544#define elf_backend_want_dynrelro 1
d75bc93d
TS
2545#define elf_backend_may_use_rel_p 1
2546#define elf_backend_may_use_rela_p 0
2547#define elf_backend_default_use_rela_p 0
b34976b6 2548#define elf_backend_sign_extend_vma TRUE
861fb55a 2549#define elf_backend_plt_readonly 1
b305ef96 2550
d01414a5 2551#define elf_backend_discard_info _bfd_mips_elf_discard_info
73d074b4 2552#define elf_backend_ignore_discarded_relocs \
53bfd6b4 2553 _bfd_mips_elf_ignore_discarded_relocs
20163277 2554#define elf_backend_write_section _bfd_mips_elf_write_section
c6e90b02
TS
2555#define elf_backend_mips_irix_compat elf32_mips_irix_compat
2556#define elf_backend_mips_rtype_to_howto mips_elf32_rtype_to_howto
28dbcedc
AM
2557#define elf_backend_sort_relocs_p _bfd_mips_elf_sort_relocs_p
2558
252b5132
RH
2559#define bfd_elf32_bfd_is_local_label_name \
2560 mips_elf_is_local_label_name
df58fc94
RS
2561#define bfd_elf32_bfd_is_target_special_symbol \
2562 _bfd_mips_elf_is_target_special_symbol
1bbce132 2563#define bfd_elf32_get_synthetic_symtab _bfd_mips_elf_get_synthetic_symtab
252b5132 2564#define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
4ab527b0 2565#define bfd_elf32_find_inliner_info _bfd_mips_elf_find_inliner_info
f0abc2a1 2566#define bfd_elf32_new_section_hook _bfd_mips_elf_new_section_hook
252b5132 2567#define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
c6e90b02
TS
2568#define bfd_elf32_bfd_get_relocated_section_contents \
2569 _bfd_elf_mips_get_relocated_section_contents
252b5132 2570#define bfd_elf32_bfd_link_hash_table_create \
103186c6
MM
2571 _bfd_mips_elf_link_hash_table_create
2572#define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
252b5132
RH
2573#define bfd_elf32_bfd_merge_private_bfd_data \
2574 _bfd_mips_elf_merge_private_bfd_data
2575#define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
2576#define bfd_elf32_bfd_print_private_bfd_data \
2577 _bfd_mips_elf_print_private_bfd_data
df58fc94 2578#define bfd_elf32_bfd_relax_section _bfd_mips_elf_relax_section
6ae68ba3 2579#define bfd_elf32_mkobject _bfd_mips_elf_mkobject
e364195d 2580
d75bc93d 2581/* Support for SGI-ish mips targets. */
6d00b590 2582#define TARGET_LITTLE_SYM mips_elf32_le_vec
d75bc93d 2583#define TARGET_LITTLE_NAME "elf32-littlemips"
6d00b590 2584#define TARGET_BIG_SYM mips_elf32_be_vec
d75bc93d
TS
2585#define TARGET_BIG_NAME "elf32-bigmips"
2586
4301eeb1
MR
2587/* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
2588 a value of 0x1000, and we are compatible. */
2589#define ELF_MAXPAGESIZE 0x1000
24718e3b 2590#define ELF_COMMONPAGESIZE 0x1000
4301eeb1 2591
d75bc93d 2592#include "elf32-target.h"
e364195d 2593
d75bc93d 2594/* Support for traditional mips targets. */
e364195d
UC
2595#undef TARGET_LITTLE_SYM
2596#undef TARGET_LITTLE_NAME
2597#undef TARGET_BIG_SYM
2598#undef TARGET_BIG_NAME
2599
4301eeb1 2600#undef ELF_MAXPAGESIZE
7fd91fe0 2601#undef ELF_COMMONPAGESIZE
4301eeb1 2602
07d6d2b8
AM
2603#define TARGET_LITTLE_SYM mips_elf32_trad_le_vec
2604#define TARGET_LITTLE_NAME "elf32-tradlittlemips"
2605#define TARGET_BIG_SYM mips_elf32_trad_be_vec
2606#define TARGET_BIG_NAME "elf32-tradbigmips"
e364195d 2607
7fd91fe0
TS
2608/* The MIPS ABI says at Page 5-1:
2609 Virtual addresses and file offsets for MIPS segments are congruent
2610 modulo 64 KByte (0x10000) or larger powers of 2. Because 64 KBytes
2611 is the maximum page size, the files are suitable for paging
2612 regardless of physical page size. */
4301eeb1 2613#define ELF_MAXPAGESIZE 0x10000
7fd91fe0 2614#define ELF_COMMONPAGESIZE 0x1000
4301eeb1
MR
2615#define elf32_bed elf32_tradbed
2616
9031cb4a
DT
2617#undef elf_backend_write_core_note
2618#define elf_backend_write_core_note elf32_mips_write_core_note
2619
c6e90b02 2620/* Include the target file again for this target. */
e364195d 2621#include "elf32-target.h"
0a44bf69 2622
aeffff67
RS
2623/* FreeBSD support. */
2624
2625#undef TARGET_LITTLE_SYM
2626#undef TARGET_LITTLE_NAME
2627#undef TARGET_BIG_SYM
2628#undef TARGET_BIG_NAME
2629
6d00b590 2630#define TARGET_LITTLE_SYM mips_elf32_tradfbsd_le_vec
aeffff67 2631#define TARGET_LITTLE_NAME "elf32-tradlittlemips-freebsd"
6d00b590 2632#define TARGET_BIG_SYM mips_elf32_tradfbsd_be_vec
aeffff67
RS
2633#define TARGET_BIG_NAME "elf32-tradbigmips-freebsd"
2634
2635#undef ELF_OSABI
2636#define ELF_OSABI ELFOSABI_FREEBSD
2637
aeffff67
RS
2638#undef elf32_bed
2639#define elf32_bed elf32_fbsd_tradbed
2640
9031cb4a
DT
2641#undef elf_backend_write_core_note
2642
aeffff67 2643#include "elf32-target.h"
0a44bf69
RS
2644/* Implement elf_backend_final_write_processing for VxWorks. */
2645
cc364be6
AM
2646static bfd_boolean
2647mips_vxworks_final_write_processing (bfd *abfd)
0a44bf69 2648{
cc364be6
AM
2649 _bfd_mips_final_write_processing (abfd);
2650 return elf_vxworks_final_write_processing (abfd);
0a44bf69
RS
2651}
2652
2653#undef TARGET_LITTLE_SYM
2654#undef TARGET_LITTLE_NAME
2655#undef TARGET_BIG_SYM
2656#undef TARGET_BIG_NAME
2657
7fd91fe0
TS
2658#undef ELF_MAXPAGESIZE
2659#undef ELF_COMMONPAGESIZE
2660
07d6d2b8
AM
2661#define TARGET_LITTLE_SYM mips_elf32_vxworks_le_vec
2662#define TARGET_LITTLE_NAME "elf32-littlemips-vxworks"
2663#define TARGET_BIG_SYM mips_elf32_vxworks_be_vec
2664#define TARGET_BIG_NAME "elf32-bigmips-vxworks"
91ea67ca 2665#undef ELF_OSABI
0a44bf69
RS
2666
2667#undef elf32_bed
2668#define elf32_bed elf32_mips_vxworks_bed
2669
0a44bf69 2670#define ELF_MAXPAGESIZE 0x1000
7fd91fe0 2671#define ELF_COMMONPAGESIZE 0x1000
0a44bf69
RS
2672
2673#undef elf_backend_want_got_plt
2674#define elf_backend_want_got_plt 1
2675#undef elf_backend_want_plt_sym
2676#define elf_backend_want_plt_sym 1
0a44bf69
RS
2677#undef elf_backend_may_use_rel_p
2678#define elf_backend_may_use_rel_p 0
2679#undef elf_backend_may_use_rela_p
2680#define elf_backend_may_use_rela_p 1
2681#undef elf_backend_default_use_rela_p
2682#define elf_backend_default_use_rela_p 1
2683#undef elf_backend_got_header_size
2684#define elf_backend_got_header_size (4 * 3)
64f52338
AM
2685#undef elf_backend_dtrel_excludes_plt
2686#define elf_backend_dtrel_excludes_plt 1
861fb55a 2687
0a44bf69
RS
2688#undef elf_backend_finish_dynamic_symbol
2689#define elf_backend_finish_dynamic_symbol \
2690 _bfd_mips_vxworks_finish_dynamic_symbol
2691#undef bfd_elf32_bfd_link_hash_table_create
2692#define bfd_elf32_bfd_link_hash_table_create \
2693 _bfd_mips_vxworks_link_hash_table_create
2694#undef elf_backend_add_symbol_hook
2695#define elf_backend_add_symbol_hook \
2696 elf_vxworks_add_symbol_hook
2697#undef elf_backend_link_output_symbol_hook
2698#define elf_backend_link_output_symbol_hook \
2699 elf_vxworks_link_output_symbol_hook
2700#undef elf_backend_emit_relocs
2701#define elf_backend_emit_relocs \
2702 elf_vxworks_emit_relocs
2703#undef elf_backend_final_write_processing
2704#define elf_backend_final_write_processing \
2705 mips_vxworks_final_write_processing
2706
2707#undef elf_backend_additional_program_headers
2708#undef elf_backend_modify_segment_map
2709#undef elf_backend_symbol_processing
2710/* NOTE: elf_backend_rela_normal is not defined for MIPS. */
2711
1bbce132
MR
2712#undef bfd_elf32_get_synthetic_symtab
2713
0a44bf69 2714#include "elf32-target.h"