* corefile.c (core_init): Report that the executable is not in the
[deliverable/binutils-gdb.git] / bfd / elf32-mips.c
CommitLineData
efcbd82c 1/* MIPS-specific support for 32-bit ELF
f0abc2a1 2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
0f20cc35 3 2003, 2004, 2005 Free Software Foundation, Inc.
252b5132
RH
4
5 Most of the information added by Ian Lance Taylor, Cygnus Support,
6 <ian@cygnus.com>.
103186c6
MM
7 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
8 <mark@codesourcery.com>
f7cb7d68
UC
9 Traditional MIPS targets support added by Koundinya.K, Dansk Data
10 Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
252b5132
RH
11
12This file is part of BFD, the Binary File Descriptor library.
13
14This program is free software; you can redistribute it and/or modify
15it under the terms of the GNU General Public License as published by
16the Free Software Foundation; either version 2 of the License, or
17(at your option) any later version.
18
19This program is distributed in the hope that it will be useful,
20but WITHOUT ANY WARRANTY; without even the implied warranty of
21MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22GNU General Public License for more details.
23
24You should have received a copy of the GNU General Public License
25along with this program; if not, write to the Free Software
3e110533 26Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
252b5132
RH
27
28/* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly
29 different MIPS ELF from other targets. This matters when linking.
30 This file supports both, switching at runtime. */
31
32#include "bfd.h"
33#include "sysdep.h"
34#include "libbfd.h"
35#include "bfdlink.h"
36#include "genlink.h"
37#include "elf-bfd.h"
c6e90b02 38#include "elfxx-mips.h"
252b5132
RH
39#include "elf/mips.h"
40
41/* Get the ECOFF swapping routines. */
42#include "coff/sym.h"
43#include "coff/symconst.h"
44#include "coff/internal.h"
45#include "coff/ecoff.h"
46#include "coff/mips.h"
23e2c83b 47#define ECOFF_SIGNED_32
252b5132
RH
48#include "ecoffswap.h"
49
a7ebbfdf 50static bfd_reloc_status_type gprel32_with_gp
11a2be4d 51 (bfd *, asymbol *, arelent *, asection *, bfd_boolean, void *, bfd_vma);
c6e90b02 52static bfd_reloc_status_type mips_elf_gprel32_reloc
11a2be4d 53 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
252b5132 54static bfd_reloc_status_type mips32_64bit_reloc
11a2be4d 55 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
252b5132 56static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
11a2be4d 57 (bfd *, bfd_reloc_code_real_type);
c6e90b02 58static reloc_howto_type *mips_elf32_rtype_to_howto
11a2be4d 59 (unsigned int, bfd_boolean);
252b5132 60static void mips_info_to_howto_rel
11a2be4d 61 (bfd *, arelent *, Elf_Internal_Rela *);
3f830999 62static void 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_jump_reloc
11a2be4d 71 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
252b5132 72static bfd_reloc_status_type mips16_gprel_reloc
11a2be4d 73 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
252b5132 74static bfd_reloc_status_type mips_elf_final_gp
11a2be4d 75 (bfd *, asymbol *, bfd_boolean, char **, bfd_vma *);
b34976b6 76static bfd_boolean mips_elf_assign_gp
11a2be4d 77 (bfd *, bfd_vma *);
b34976b6 78static bfd_boolean elf32_mips_grok_prstatus
11a2be4d 79 (bfd *, Elf_Internal_Note *);
b34976b6 80static bfd_boolean elf32_mips_grok_psinfo
11a2be4d 81 (bfd *, Elf_Internal_Note *);
c6e90b02 82static irix_compat_t elf32_mips_irix_compat
11a2be4d 83 (bfd *);
252b5132 84
cb7394f2
TS
85extern const bfd_target bfd_elf32_bigmips_vec;
86extern const bfd_target bfd_elf32_littlemips_vec;
adb76a3e 87
a94a7c1c 88/* Nonzero if ABFD is using the N32 ABI. */
a94a7c1c
MM
89#define ABI_N32_P(abfd) \
90 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
91
4e8a9624 92/* Whether we are trying to be compatible with IRIX at all. */
a94a7c1c 93#define SGI_COMPAT(abfd) \
c6e90b02 94 (elf32_mips_irix_compat (abfd) != ict_none)
103186c6 95
252b5132
RH
96/* The number of local .got entries we reserve. */
97#define MIPS_RESERVED_GOTNO (2)
98
3f830999
MM
99/* In case we're on a 32-bit machine, construct a 64-bit "-1" value
100 from smaller values. Start with zero, widen, *then* decrement. */
101#define MINUS_ONE (((bfd_vma)0) - 1)
102
d75bc93d
TS
103/* The relocation table used for SHT_REL sections. */
104
105static reloc_howto_type elf_mips_howto_table_rel[] =
106{
107 /* No relocation. */
108 HOWTO (R_MIPS_NONE, /* type */
109 0, /* rightshift */
110 0, /* size (0 = byte, 1 = short, 2 = long) */
111 0, /* bitsize */
b34976b6 112 FALSE, /* pc_relative */
d75bc93d
TS
113 0, /* bitpos */
114 complain_overflow_dont, /* complain_on_overflow */
30ac9238 115 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 116 "R_MIPS_NONE", /* name */
b34976b6 117 FALSE, /* partial_inplace */
d75bc93d
TS
118 0, /* src_mask */
119 0, /* dst_mask */
b34976b6 120 FALSE), /* pcrel_offset */
d75bc93d
TS
121
122 /* 16 bit relocation. */
123 HOWTO (R_MIPS_16, /* type */
124 0, /* rightshift */
125 2, /* size (0 = byte, 1 = short, 2 = long) */
126 16, /* bitsize */
b34976b6 127 FALSE, /* pc_relative */
d75bc93d
TS
128 0, /* bitpos */
129 complain_overflow_signed, /* complain_on_overflow */
30ac9238 130 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 131 "R_MIPS_16", /* name */
b34976b6 132 TRUE, /* partial_inplace */
d75bc93d
TS
133 0x0000ffff, /* src_mask */
134 0x0000ffff, /* dst_mask */
b34976b6 135 FALSE), /* pcrel_offset */
d75bc93d
TS
136
137 /* 32 bit relocation. */
138 HOWTO (R_MIPS_32, /* type */
139 0, /* rightshift */
140 2, /* size (0 = byte, 1 = short, 2 = long) */
141 32, /* bitsize */
b34976b6 142 FALSE, /* pc_relative */
d75bc93d
TS
143 0, /* bitpos */
144 complain_overflow_dont, /* complain_on_overflow */
30ac9238 145 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 146 "R_MIPS_32", /* name */
b34976b6 147 TRUE, /* partial_inplace */
d75bc93d
TS
148 0xffffffff, /* src_mask */
149 0xffffffff, /* dst_mask */
b34976b6 150 FALSE), /* pcrel_offset */
d75bc93d
TS
151
152 /* 32 bit symbol relative relocation. */
153 HOWTO (R_MIPS_REL32, /* type */
154 0, /* rightshift */
155 2, /* size (0 = byte, 1 = short, 2 = long) */
156 32, /* bitsize */
b34976b6 157 FALSE, /* pc_relative */
d75bc93d
TS
158 0, /* bitpos */
159 complain_overflow_dont, /* complain_on_overflow */
30ac9238 160 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 161 "R_MIPS_REL32", /* name */
b34976b6 162 TRUE, /* partial_inplace */
d75bc93d
TS
163 0xffffffff, /* src_mask */
164 0xffffffff, /* dst_mask */
b34976b6 165 FALSE), /* pcrel_offset */
d75bc93d
TS
166
167 /* 26 bit jump address. */
168 HOWTO (R_MIPS_26, /* type */
169 2, /* rightshift */
170 2, /* size (0 = byte, 1 = short, 2 = long) */
171 26, /* bitsize */
b34976b6 172 FALSE, /* pc_relative */
d75bc93d
TS
173 0, /* bitpos */
174 complain_overflow_dont, /* complain_on_overflow */
175 /* This needs complex overflow
176 detection, because the upper four
177 bits must match the PC + 4. */
30ac9238 178 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 179 "R_MIPS_26", /* name */
b34976b6 180 TRUE, /* partial_inplace */
d75bc93d
TS
181 0x03ffffff, /* src_mask */
182 0x03ffffff, /* dst_mask */
b34976b6 183 FALSE), /* pcrel_offset */
d75bc93d
TS
184
185 /* High 16 bits of symbol value. */
186 HOWTO (R_MIPS_HI16, /* type */
30ac9238 187 16, /* rightshift */
d75bc93d
TS
188 2, /* size (0 = byte, 1 = short, 2 = long) */
189 16, /* bitsize */
b34976b6 190 FALSE, /* pc_relative */
d75bc93d
TS
191 0, /* bitpos */
192 complain_overflow_dont, /* complain_on_overflow */
30ac9238 193 _bfd_mips_elf_hi16_reloc, /* special_function */
d75bc93d 194 "R_MIPS_HI16", /* name */
b34976b6 195 TRUE, /* partial_inplace */
d75bc93d
TS
196 0x0000ffff, /* src_mask */
197 0x0000ffff, /* dst_mask */
b34976b6 198 FALSE), /* pcrel_offset */
d75bc93d
TS
199
200 /* Low 16 bits of symbol value. */
201 HOWTO (R_MIPS_LO16, /* type */
202 0, /* rightshift */
203 2, /* size (0 = byte, 1 = short, 2 = long) */
204 16, /* bitsize */
b34976b6 205 FALSE, /* pc_relative */
d75bc93d
TS
206 0, /* bitpos */
207 complain_overflow_dont, /* complain_on_overflow */
30ac9238 208 _bfd_mips_elf_lo16_reloc, /* special_function */
d75bc93d 209 "R_MIPS_LO16", /* name */
b34976b6 210 TRUE, /* partial_inplace */
d75bc93d
TS
211 0x0000ffff, /* src_mask */
212 0x0000ffff, /* dst_mask */
b34976b6 213 FALSE), /* pcrel_offset */
d75bc93d
TS
214
215 /* GP relative reference. */
216 HOWTO (R_MIPS_GPREL16, /* type */
217 0, /* rightshift */
218 2, /* size (0 = byte, 1 = short, 2 = long) */
219 16, /* bitsize */
b34976b6 220 FALSE, /* pc_relative */
d75bc93d
TS
221 0, /* bitpos */
222 complain_overflow_signed, /* complain_on_overflow */
c6e90b02 223 _bfd_mips_elf32_gprel16_reloc, /* special_function */
d75bc93d 224 "R_MIPS_GPREL16", /* name */
b34976b6 225 TRUE, /* partial_inplace */
d75bc93d
TS
226 0x0000ffff, /* src_mask */
227 0x0000ffff, /* dst_mask */
b34976b6 228 FALSE), /* pcrel_offset */
d75bc93d
TS
229
230 /* Reference to literal section. */
231 HOWTO (R_MIPS_LITERAL, /* type */
232 0, /* rightshift */
233 2, /* size (0 = byte, 1 = short, 2 = long) */
234 16, /* bitsize */
b34976b6 235 FALSE, /* pc_relative */
d75bc93d
TS
236 0, /* bitpos */
237 complain_overflow_signed, /* complain_on_overflow */
c6e90b02 238 _bfd_mips_elf32_gprel16_reloc, /* special_function */
d75bc93d 239 "R_MIPS_LITERAL", /* name */
b34976b6 240 TRUE, /* partial_inplace */
d75bc93d
TS
241 0x0000ffff, /* src_mask */
242 0x0000ffff, /* dst_mask */
b34976b6 243 FALSE), /* pcrel_offset */
d75bc93d
TS
244
245 /* Reference to global offset table. */
246 HOWTO (R_MIPS_GOT16, /* type */
247 0, /* rightshift */
248 2, /* size (0 = byte, 1 = short, 2 = long) */
249 16, /* bitsize */
b34976b6 250 FALSE, /* pc_relative */
d75bc93d
TS
251 0, /* bitpos */
252 complain_overflow_signed, /* complain_on_overflow */
30ac9238 253 _bfd_mips_elf_got16_reloc, /* special_function */
d75bc93d 254 "R_MIPS_GOT16", /* name */
b34976b6 255 TRUE, /* partial_inplace */
d75bc93d
TS
256 0x0000ffff, /* src_mask */
257 0x0000ffff, /* dst_mask */
b34976b6 258 FALSE), /* pcrel_offset */
d75bc93d 259
bad36eac
DJ
260 /* 16 bit PC relative reference. Note that the ABI document has a typo
261 and claims R_MIPS_PC16 to be not rightshifted, rendering it useless.
262 We do the right thing here. */
d75bc93d 263 HOWTO (R_MIPS_PC16, /* type */
bad36eac 264 2, /* rightshift */
d75bc93d
TS
265 2, /* size (0 = byte, 1 = short, 2 = long) */
266 16, /* bitsize */
b34976b6 267 TRUE, /* pc_relative */
d75bc93d
TS
268 0, /* bitpos */
269 complain_overflow_signed, /* complain_on_overflow */
30ac9238 270 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 271 "R_MIPS_PC16", /* name */
b34976b6 272 TRUE, /* partial_inplace */
d75bc93d
TS
273 0x0000ffff, /* src_mask */
274 0x0000ffff, /* dst_mask */
b34976b6 275 TRUE), /* pcrel_offset */
d75bc93d
TS
276
277 /* 16 bit call through global offset table. */
278 HOWTO (R_MIPS_CALL16, /* type */
279 0, /* rightshift */
280 2, /* size (0 = byte, 1 = short, 2 = long) */
281 16, /* bitsize */
b34976b6 282 FALSE, /* pc_relative */
d75bc93d
TS
283 0, /* bitpos */
284 complain_overflow_signed, /* complain_on_overflow */
30ac9238 285 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 286 "R_MIPS_CALL16", /* name */
b34976b6 287 TRUE, /* partial_inplace */
d75bc93d
TS
288 0x0000ffff, /* src_mask */
289 0x0000ffff, /* dst_mask */
b34976b6 290 FALSE), /* pcrel_offset */
d75bc93d
TS
291
292 /* 32 bit GP relative reference. */
293 HOWTO (R_MIPS_GPREL32, /* type */
294 0, /* rightshift */
295 2, /* size (0 = byte, 1 = short, 2 = long) */
296 32, /* bitsize */
b34976b6 297 FALSE, /* pc_relative */
d75bc93d
TS
298 0, /* bitpos */
299 complain_overflow_dont, /* complain_on_overflow */
c6e90b02 300 mips_elf_gprel32_reloc, /* special_function */
d75bc93d 301 "R_MIPS_GPREL32", /* name */
b34976b6 302 TRUE, /* partial_inplace */
d75bc93d
TS
303 0xffffffff, /* src_mask */
304 0xffffffff, /* dst_mask */
b34976b6 305 FALSE), /* pcrel_offset */
d75bc93d
TS
306
307 /* The remaining relocs are defined on Irix 5, although they are
308 not defined by the ABI. */
309 EMPTY_HOWTO (13),
310 EMPTY_HOWTO (14),
311 EMPTY_HOWTO (15),
312
313 /* A 5 bit shift field. */
314 HOWTO (R_MIPS_SHIFT5, /* type */
315 0, /* rightshift */
316 2, /* size (0 = byte, 1 = short, 2 = long) */
317 5, /* bitsize */
b34976b6 318 FALSE, /* pc_relative */
d75bc93d
TS
319 6, /* bitpos */
320 complain_overflow_bitfield, /* complain_on_overflow */
30ac9238 321 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 322 "R_MIPS_SHIFT5", /* name */
b34976b6 323 TRUE, /* partial_inplace */
d75bc93d
TS
324 0x000007c0, /* src_mask */
325 0x000007c0, /* dst_mask */
b34976b6 326 FALSE), /* pcrel_offset */
d75bc93d
TS
327
328 /* A 6 bit shift field. */
329 /* FIXME: This is not handled correctly; a special function is
330 needed to put the most significant bit in the right place. */
331 HOWTO (R_MIPS_SHIFT6, /* type */
332 0, /* rightshift */
333 2, /* size (0 = byte, 1 = short, 2 = long) */
334 6, /* bitsize */
b34976b6 335 FALSE, /* pc_relative */
d75bc93d
TS
336 6, /* bitpos */
337 complain_overflow_bitfield, /* complain_on_overflow */
30ac9238 338 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 339 "R_MIPS_SHIFT6", /* name */
b34976b6 340 TRUE, /* partial_inplace */
d75bc93d
TS
341 0x000007c4, /* src_mask */
342 0x000007c4, /* dst_mask */
b34976b6 343 FALSE), /* pcrel_offset */
d75bc93d
TS
344
345 /* A 64 bit relocation. */
346 HOWTO (R_MIPS_64, /* type */
347 0, /* rightshift */
348 4, /* size (0 = byte, 1 = short, 2 = long) */
349 64, /* bitsize */
b34976b6 350 FALSE, /* pc_relative */
d75bc93d
TS
351 0, /* bitpos */
352 complain_overflow_dont, /* complain_on_overflow */
353 mips32_64bit_reloc, /* special_function */
354 "R_MIPS_64", /* name */
b34976b6 355 TRUE, /* partial_inplace */
d75bc93d
TS
356 MINUS_ONE, /* src_mask */
357 MINUS_ONE, /* dst_mask */
b34976b6 358 FALSE), /* pcrel_offset */
d75bc93d
TS
359
360 /* Displacement in the global offset table. */
361 HOWTO (R_MIPS_GOT_DISP, /* type */
362 0, /* rightshift */
363 2, /* size (0 = byte, 1 = short, 2 = long) */
364 16, /* bitsize */
b34976b6 365 FALSE, /* pc_relative */
d75bc93d
TS
366 0, /* bitpos */
367 complain_overflow_signed, /* complain_on_overflow */
30ac9238 368 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 369 "R_MIPS_GOT_DISP", /* name */
b34976b6 370 TRUE, /* partial_inplace */
d75bc93d
TS
371 0x0000ffff, /* src_mask */
372 0x0000ffff, /* dst_mask */
b34976b6 373 FALSE), /* pcrel_offset */
d75bc93d
TS
374
375 /* Displacement to page pointer in the global offset table. */
376 HOWTO (R_MIPS_GOT_PAGE, /* type */
377 0, /* rightshift */
378 2, /* size (0 = byte, 1 = short, 2 = long) */
379 16, /* bitsize */
b34976b6 380 FALSE, /* pc_relative */
d75bc93d
TS
381 0, /* bitpos */
382 complain_overflow_signed, /* complain_on_overflow */
30ac9238 383 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 384 "R_MIPS_GOT_PAGE", /* name */
b34976b6 385 TRUE, /* partial_inplace */
d75bc93d
TS
386 0x0000ffff, /* src_mask */
387 0x0000ffff, /* dst_mask */
b34976b6 388 FALSE), /* pcrel_offset */
d75bc93d
TS
389
390 /* Offset from page pointer in the global offset table. */
391 HOWTO (R_MIPS_GOT_OFST, /* type */
392 0, /* rightshift */
393 2, /* size (0 = byte, 1 = short, 2 = long) */
394 16, /* bitsize */
b34976b6 395 FALSE, /* pc_relative */
d75bc93d
TS
396 0, /* bitpos */
397 complain_overflow_signed, /* complain_on_overflow */
30ac9238 398 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 399 "R_MIPS_GOT_OFST", /* name */
b34976b6 400 TRUE, /* partial_inplace */
d75bc93d
TS
401 0x0000ffff, /* src_mask */
402 0x0000ffff, /* dst_mask */
b34976b6 403 FALSE), /* pcrel_offset */
d75bc93d
TS
404
405 /* High 16 bits of displacement in global offset table. */
406 HOWTO (R_MIPS_GOT_HI16, /* type */
407 0, /* rightshift */
408 2, /* size (0 = byte, 1 = short, 2 = long) */
409 16, /* bitsize */
b34976b6 410 FALSE, /* pc_relative */
d75bc93d
TS
411 0, /* bitpos */
412 complain_overflow_dont, /* complain_on_overflow */
30ac9238 413 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 414 "R_MIPS_GOT_HI16", /* name */
b34976b6 415 TRUE, /* partial_inplace */
d75bc93d
TS
416 0x0000ffff, /* src_mask */
417 0x0000ffff, /* dst_mask */
b34976b6 418 FALSE), /* pcrel_offset */
d75bc93d
TS
419
420 /* Low 16 bits of displacement in global offset table. */
421 HOWTO (R_MIPS_GOT_LO16, /* type */
422 0, /* rightshift */
423 2, /* size (0 = byte, 1 = short, 2 = long) */
424 16, /* bitsize */
b34976b6 425 FALSE, /* pc_relative */
d75bc93d
TS
426 0, /* bitpos */
427 complain_overflow_dont, /* complain_on_overflow */
30ac9238 428 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 429 "R_MIPS_GOT_LO16", /* name */
b34976b6 430 TRUE, /* partial_inplace */
d75bc93d
TS
431 0x0000ffff, /* src_mask */
432 0x0000ffff, /* dst_mask */
b34976b6 433 FALSE), /* pcrel_offset */
d75bc93d
TS
434
435 /* 64 bit subtraction. Used in the N32 ABI. */
436 HOWTO (R_MIPS_SUB, /* type */
437 0, /* rightshift */
438 4, /* size (0 = byte, 1 = short, 2 = long) */
439 64, /* bitsize */
b34976b6 440 FALSE, /* pc_relative */
d75bc93d
TS
441 0, /* bitpos */
442 complain_overflow_dont, /* complain_on_overflow */
30ac9238 443 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 444 "R_MIPS_SUB", /* name */
b34976b6 445 TRUE, /* partial_inplace */
d75bc93d
TS
446 MINUS_ONE, /* src_mask */
447 MINUS_ONE, /* dst_mask */
b34976b6 448 FALSE), /* pcrel_offset */
d75bc93d
TS
449
450 /* Used to cause the linker to insert and delete instructions? */
451 EMPTY_HOWTO (R_MIPS_INSERT_A),
452 EMPTY_HOWTO (R_MIPS_INSERT_B),
453 EMPTY_HOWTO (R_MIPS_DELETE),
454
455 /* Get the higher value of a 64 bit addend. */
456 HOWTO (R_MIPS_HIGHER, /* type */
457 0, /* rightshift */
458 2, /* size (0 = byte, 1 = short, 2 = long) */
459 16, /* bitsize */
b34976b6 460 FALSE, /* pc_relative */
d75bc93d
TS
461 0, /* bitpos */
462 complain_overflow_dont, /* complain_on_overflow */
30ac9238 463 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 464 "R_MIPS_HIGHER", /* name */
b34976b6 465 TRUE, /* partial_inplace */
d75bc93d
TS
466 0x0000ffff, /* src_mask */
467 0x0000ffff, /* dst_mask */
b34976b6 468 FALSE), /* pcrel_offset */
d75bc93d
TS
469
470 /* Get the highest value of a 64 bit addend. */
471 HOWTO (R_MIPS_HIGHEST, /* type */
472 0, /* rightshift */
473 2, /* size (0 = byte, 1 = short, 2 = long) */
474 16, /* bitsize */
b34976b6 475 FALSE, /* pc_relative */
d75bc93d
TS
476 0, /* bitpos */
477 complain_overflow_dont, /* complain_on_overflow */
30ac9238 478 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 479 "R_MIPS_HIGHEST", /* name */
b34976b6 480 TRUE, /* partial_inplace */
d75bc93d
TS
481 0x0000ffff, /* src_mask */
482 0x0000ffff, /* dst_mask */
b34976b6 483 FALSE), /* pcrel_offset */
d75bc93d
TS
484
485 /* High 16 bits of displacement in global offset table. */
486 HOWTO (R_MIPS_CALL_HI16, /* type */
487 0, /* rightshift */
488 2, /* size (0 = byte, 1 = short, 2 = long) */
489 16, /* bitsize */
b34976b6 490 FALSE, /* pc_relative */
d75bc93d
TS
491 0, /* bitpos */
492 complain_overflow_dont, /* complain_on_overflow */
30ac9238 493 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 494 "R_MIPS_CALL_HI16", /* name */
b34976b6 495 TRUE, /* partial_inplace */
d75bc93d
TS
496 0x0000ffff, /* src_mask */
497 0x0000ffff, /* dst_mask */
b34976b6 498 FALSE), /* pcrel_offset */
d75bc93d
TS
499
500 /* Low 16 bits of displacement in global offset table. */
501 HOWTO (R_MIPS_CALL_LO16, /* type */
502 0, /* rightshift */
503 2, /* size (0 = byte, 1 = short, 2 = long) */
504 16, /* bitsize */
b34976b6 505 FALSE, /* pc_relative */
d75bc93d
TS
506 0, /* bitpos */
507 complain_overflow_dont, /* complain_on_overflow */
30ac9238 508 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 509 "R_MIPS_CALL_LO16", /* name */
b34976b6 510 TRUE, /* partial_inplace */
d75bc93d
TS
511 0x0000ffff, /* src_mask */
512 0x0000ffff, /* dst_mask */
b34976b6 513 FALSE), /* pcrel_offset */
d75bc93d
TS
514
515 /* Section displacement. */
516 HOWTO (R_MIPS_SCN_DISP, /* type */
517 0, /* rightshift */
518 2, /* size (0 = byte, 1 = short, 2 = long) */
519 32, /* bitsize */
b34976b6 520 FALSE, /* pc_relative */
d75bc93d
TS
521 0, /* bitpos */
522 complain_overflow_dont, /* complain_on_overflow */
30ac9238 523 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 524 "R_MIPS_SCN_DISP", /* name */
b34976b6 525 TRUE, /* partial_inplace */
d75bc93d
TS
526 0xffffffff, /* src_mask */
527 0xffffffff, /* dst_mask */
b34976b6 528 FALSE), /* pcrel_offset */
d75bc93d
TS
529
530 EMPTY_HOWTO (R_MIPS_REL16),
531 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
532 EMPTY_HOWTO (R_MIPS_PJUMP),
533 EMPTY_HOWTO (R_MIPS_RELGOT),
534
535 /* Protected jump conversion. This is an optimization hint. No
536 relocation is required for correctness. */
537 HOWTO (R_MIPS_JALR, /* type */
538 0, /* rightshift */
539 2, /* size (0 = byte, 1 = short, 2 = long) */
540 32, /* bitsize */
b34976b6 541 FALSE, /* pc_relative */
d75bc93d
TS
542 0, /* bitpos */
543 complain_overflow_dont, /* complain_on_overflow */
30ac9238 544 _bfd_mips_elf_generic_reloc, /* special_function */
d75bc93d 545 "R_MIPS_JALR", /* name */
b34976b6 546 FALSE, /* partial_inplace */
d75bc93d
TS
547 0x00000000, /* src_mask */
548 0x00000000, /* dst_mask */
b34976b6 549 FALSE), /* pcrel_offset */
0f20cc35
DJ
550
551 /* TLS GD/LD dynamic relocations. */
552 HOWTO (R_MIPS_TLS_DTPMOD32, /* type */
553 0, /* rightshift */
554 2, /* size (0 = byte, 1 = short, 2 = long) */
555 32, /* bitsize */
556 FALSE, /* pc_relative */
557 0, /* bitpos */
558 complain_overflow_dont, /* complain_on_overflow */
559 _bfd_mips_elf_generic_reloc, /* special_function */
560 "R_MIPS_TLS_DTPMOD32", /* name */
561 TRUE, /* partial_inplace */
562 0xffffffff, /* src_mask */
563 0xffffffff, /* dst_mask */
564 FALSE), /* pcrel_offset */
565
566 HOWTO (R_MIPS_TLS_DTPREL32, /* type */
567 0, /* rightshift */
568 2, /* size (0 = byte, 1 = short, 2 = long) */
569 32, /* bitsize */
570 FALSE, /* pc_relative */
571 0, /* bitpos */
572 complain_overflow_dont, /* complain_on_overflow */
573 _bfd_mips_elf_generic_reloc, /* special_function */
574 "R_MIPS_TLS_DTPREL32", /* name */
575 TRUE, /* partial_inplace */
576 0xffffffff, /* src_mask */
577 0xffffffff, /* dst_mask */
578 FALSE), /* pcrel_offset */
579
580 EMPTY_HOWTO (R_MIPS_TLS_DTPMOD64),
581 EMPTY_HOWTO (R_MIPS_TLS_DTPREL64),
582
583 /* TLS general dynamic variable reference. */
584 HOWTO (R_MIPS_TLS_GD, /* type */
585 0, /* rightshift */
586 2, /* size (0 = byte, 1 = short, 2 = long) */
587 16, /* bitsize */
588 FALSE, /* pc_relative */
589 0, /* bitpos */
590 complain_overflow_signed, /* complain_on_overflow */
591 _bfd_mips_elf_generic_reloc, /* special_function */
592 "R_MIPS_TLS_GD", /* name */
593 TRUE, /* partial_inplace */
594 0x0000ffff, /* src_mask */
595 0x0000ffff, /* dst_mask */
596 FALSE), /* pcrel_offset */
597
598 /* TLS local dynamic variable reference. */
599 HOWTO (R_MIPS_TLS_LDM, /* type */
600 0, /* rightshift */
601 2, /* size (0 = byte, 1 = short, 2 = long) */
602 16, /* bitsize */
603 FALSE, /* pc_relative */
604 0, /* bitpos */
605 complain_overflow_signed, /* complain_on_overflow */
606 _bfd_mips_elf_generic_reloc, /* special_function */
607 "R_MIPS_TLS_LDM", /* name */
608 TRUE, /* partial_inplace */
609 0x0000ffff, /* src_mask */
610 0x0000ffff, /* dst_mask */
611 FALSE), /* pcrel_offset */
612
613 /* TLS local dynamic offset. */
614 HOWTO (R_MIPS_TLS_DTPREL_HI16, /* type */
615 0, /* rightshift */
616 2, /* size (0 = byte, 1 = short, 2 = long) */
617 16, /* bitsize */
618 FALSE, /* pc_relative */
619 0, /* bitpos */
620 complain_overflow_signed, /* complain_on_overflow */
621 _bfd_mips_elf_generic_reloc, /* special_function */
622 "R_MIPS_TLS_DTPREL_HI16", /* name */
623 TRUE, /* partial_inplace */
624 0x0000ffff, /* src_mask */
625 0x0000ffff, /* dst_mask */
626 FALSE), /* pcrel_offset */
627
628 /* TLS local dynamic offset. */
629 HOWTO (R_MIPS_TLS_DTPREL_LO16, /* type */
630 0, /* rightshift */
631 2, /* size (0 = byte, 1 = short, 2 = long) */
632 16, /* bitsize */
633 FALSE, /* pc_relative */
634 0, /* bitpos */
635 complain_overflow_signed, /* complain_on_overflow */
636 _bfd_mips_elf_generic_reloc, /* special_function */
637 "R_MIPS_TLS_DTPREL_LO16", /* name */
638 TRUE, /* partial_inplace */
639 0x0000ffff, /* src_mask */
640 0x0000ffff, /* dst_mask */
641 FALSE), /* pcrel_offset */
642
643 /* TLS thread pointer offset. */
644 HOWTO (R_MIPS_TLS_GOTTPREL, /* type */
645 0, /* rightshift */
646 2, /* size (0 = byte, 1 = short, 2 = long) */
647 16, /* bitsize */
648 FALSE, /* pc_relative */
649 0, /* bitpos */
650 complain_overflow_signed, /* complain_on_overflow */
651 _bfd_mips_elf_generic_reloc, /* special_function */
652 "R_MIPS_TLS_GOTTPREL", /* name */
653 TRUE, /* partial_inplace */
654 0x0000ffff, /* src_mask */
655 0x0000ffff, /* dst_mask */
656 FALSE), /* pcrel_offset */
657
658 /* TLS IE dynamic relocations. */
659 HOWTO (R_MIPS_TLS_TPREL32, /* type */
660 0, /* rightshift */
661 2, /* size (0 = byte, 1 = short, 2 = long) */
662 32, /* bitsize */
663 FALSE, /* pc_relative */
664 0, /* bitpos */
665 complain_overflow_dont, /* complain_on_overflow */
666 _bfd_mips_elf_generic_reloc, /* special_function */
667 "R_MIPS_TLS_TPREL32", /* name */
668 TRUE, /* partial_inplace */
669 0xffffffff, /* src_mask */
670 0xffffffff, /* dst_mask */
671 FALSE), /* pcrel_offset */
672
673 EMPTY_HOWTO (R_MIPS_TLS_TPREL64),
674
675 /* TLS thread pointer offset. */
676 HOWTO (R_MIPS_TLS_TPREL_HI16, /* type */
677 0, /* rightshift */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
679 16, /* bitsize */
680 FALSE, /* pc_relative */
681 0, /* bitpos */
682 complain_overflow_signed, /* complain_on_overflow */
683 _bfd_mips_elf_generic_reloc, /* special_function */
684 "R_MIPS_TLS_TPREL_HI16", /* name */
685 TRUE, /* partial_inplace */
686 0x0000ffff, /* src_mask */
687 0x0000ffff, /* dst_mask */
688 FALSE), /* pcrel_offset */
689
690 /* TLS thread pointer offset. */
691 HOWTO (R_MIPS_TLS_TPREL_LO16, /* type */
692 0, /* rightshift */
693 2, /* size (0 = byte, 1 = short, 2 = long) */
694 16, /* bitsize */
695 FALSE, /* pc_relative */
696 0, /* bitpos */
697 complain_overflow_signed, /* complain_on_overflow */
698 _bfd_mips_elf_generic_reloc, /* special_function */
699 "R_MIPS_TLS_TPREL_LO16", /* name */
700 TRUE, /* partial_inplace */
701 0x0000ffff, /* src_mask */
702 0x0000ffff, /* dst_mask */
703 FALSE), /* pcrel_offset */
d75bc93d
TS
704};
705
c6e90b02
TS
706/* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
707 is a hack to make the linker think that we need 64 bit values. */
708static reloc_howto_type elf_mips_ctor64_howto =
709 HOWTO (R_MIPS_64, /* type */
252b5132 710 0, /* rightshift */
c6e90b02 711 4, /* size (0 = byte, 1 = short, 2 = long) */
252b5132 712 32, /* bitsize */
b34976b6 713 FALSE, /* pc_relative */
252b5132 714 0, /* bitpos */
c6e90b02
TS
715 complain_overflow_signed, /* complain_on_overflow */
716 mips32_64bit_reloc, /* special_function */
717 "R_MIPS_64", /* name */
b34976b6 718 TRUE, /* partial_inplace */
c6e90b02 719 0xffffffff, /* src_mask */
252b5132 720 0xffffffff, /* dst_mask */
b34976b6 721 FALSE); /* pcrel_offset */
252b5132 722
d6f16593
MR
723static reloc_howto_type elf_mips16_howto_table_rel[] =
724{
725 /* The reloc used for the mips16 jump instruction. */
c6e90b02 726 HOWTO (R_MIPS16_26, /* type */
252b5132
RH
727 2, /* rightshift */
728 2, /* size (0 = byte, 1 = short, 2 = long) */
729 26, /* bitsize */
b34976b6 730 FALSE, /* pc_relative */
252b5132
RH
731 0, /* bitpos */
732 complain_overflow_dont, /* complain_on_overflow */
c6e90b02
TS
733 /* This needs complex overflow
734 detection, because the upper four
735 bits must match the PC. */
736 mips16_jump_reloc, /* special_function */
737 "R_MIPS16_26", /* name */
b34976b6 738 TRUE, /* partial_inplace */
c6e90b02
TS
739 0x3ffffff, /* src_mask */
740 0x3ffffff, /* dst_mask */
d6f16593 741 FALSE), /* pcrel_offset */
252b5132 742
d6f16593 743 /* The reloc used for the mips16 gprel instruction. */
c6e90b02 744 HOWTO (R_MIPS16_GPREL, /* type */
252b5132
RH
745 0, /* rightshift */
746 2, /* size (0 = byte, 1 = short, 2 = long) */
747 16, /* bitsize */
b34976b6 748 FALSE, /* pc_relative */
252b5132 749 0, /* bitpos */
c6e90b02
TS
750 complain_overflow_signed, /* complain_on_overflow */
751 mips16_gprel_reloc, /* special_function */
752 "R_MIPS16_GPREL", /* name */
b34976b6 753 TRUE, /* partial_inplace */
d6f16593
MR
754 0x0000ffff, /* src_mask */
755 0x0000ffff, /* dst_mask */
756 FALSE), /* pcrel_offset */
757
758 /* A placeholder for MIPS16 reference to global offset table. */
759 EMPTY_HOWTO (R_MIPS16_GOT16),
760
761 /* A placeholder for MIPS16 16 bit call through global offset table. */
762 EMPTY_HOWTO (R_MIPS16_CALL16),
763
764 /* MIPS16 high 16 bits of symbol value. */
765 HOWTO (R_MIPS16_HI16, /* type */
766 16, /* rightshift */
767 2, /* size (0 = byte, 1 = short, 2 = long) */
768 16, /* bitsize */
769 FALSE, /* pc_relative */
770 0, /* bitpos */
771 complain_overflow_dont, /* complain_on_overflow */
772 _bfd_mips_elf_hi16_reloc, /* special_function */
773 "R_MIPS16_HI16", /* name */
774 TRUE, /* partial_inplace */
775 0x0000ffff, /* src_mask */
776 0x0000ffff, /* dst_mask */
777 FALSE), /* pcrel_offset */
778
779 /* MIPS16 low 16 bits of symbol value. */
780 HOWTO (R_MIPS16_LO16, /* type */
781 0, /* rightshift */
782 2, /* size (0 = byte, 1 = short, 2 = long) */
783 16, /* bitsize */
784 FALSE, /* pc_relative */
785 0, /* bitpos */
786 complain_overflow_dont, /* complain_on_overflow */
787 _bfd_mips_elf_lo16_reloc, /* special_function */
788 "R_MIPS16_LO16", /* name */
789 TRUE, /* partial_inplace */
790 0x0000ffff, /* src_mask */
791 0x0000ffff, /* dst_mask */
792 FALSE), /* pcrel_offset */
793};
252b5132 794
c6e90b02
TS
795/* 16 bit offset for pc-relative branches. */
796static reloc_howto_type elf_mips_gnu_rel16_s2 =
797 HOWTO (R_MIPS_GNU_REL16_S2, /* type */
798 2, /* rightshift */
252b5132
RH
799 2, /* size (0 = byte, 1 = short, 2 = long) */
800 16, /* bitsize */
b34976b6 801 TRUE, /* pc_relative */
252b5132
RH
802 0, /* bitpos */
803 complain_overflow_signed, /* complain_on_overflow */
30ac9238 804 _bfd_mips_elf_generic_reloc, /* special_function */
c6e90b02 805 "R_MIPS_GNU_REL16_S2", /* name */
b34976b6 806 TRUE, /* partial_inplace */
c6e90b02
TS
807 0xffff, /* src_mask */
808 0xffff, /* dst_mask */
b34976b6 809 TRUE); /* pcrel_offset */
252b5132 810
092dcd75
CD
811/* 32 bit pc-relative. This was a GNU extension used by embedded-PIC.
812 It was co-opted by mips-linux for exception-handling data. It is no
813 longer used, but should continue to be supported by the linker for
814 backward compatibility. (GCC stopped using it in May, 2004.) */
815static reloc_howto_type elf_mips_gnu_pcrel32 =
816 HOWTO (R_MIPS_PC32, /* type */
817 0, /* rightshift */
818 2, /* size (0 = byte, 1 = short, 2 = long) */
819 32, /* bitsize */
820 TRUE, /* pc_relative */
821 0, /* bitpos */
822 complain_overflow_signed, /* complain_on_overflow */
823 _bfd_mips_elf_generic_reloc, /* special_function */
824 "R_MIPS_PC32", /* name */
825 TRUE, /* partial_inplace */
826 0xffffffff, /* src_mask */
827 0xffffffff, /* dst_mask */
828 TRUE); /* pcrel_offset */
829
c6e90b02
TS
830/* GNU extension to record C++ vtable hierarchy */
831static reloc_howto_type elf_mips_gnu_vtinherit_howto =
832 HOWTO (R_MIPS_GNU_VTINHERIT, /* type */
252b5132
RH
833 0, /* rightshift */
834 2, /* size (0 = byte, 1 = short, 2 = long) */
c6e90b02 835 0, /* bitsize */
b34976b6 836 FALSE, /* pc_relative */
252b5132 837 0, /* bitpos */
c6e90b02
TS
838 complain_overflow_dont, /* complain_on_overflow */
839 NULL, /* special_function */
840 "R_MIPS_GNU_VTINHERIT", /* name */
b34976b6 841 FALSE, /* partial_inplace */
d75bc93d 842 0, /* src_mask */
c6e90b02 843 0, /* dst_mask */
b34976b6 844 FALSE); /* pcrel_offset */
252b5132 845
c6e90b02
TS
846/* GNU extension to record C++ vtable member usage */
847static reloc_howto_type elf_mips_gnu_vtentry_howto =
848 HOWTO (R_MIPS_GNU_VTENTRY, /* type */
252b5132
RH
849 0, /* rightshift */
850 2, /* size (0 = byte, 1 = short, 2 = long) */
c6e90b02 851 0, /* bitsize */
b34976b6 852 FALSE, /* pc_relative */
252b5132
RH
853 0, /* bitpos */
854 complain_overflow_dont, /* complain_on_overflow */
c6e90b02
TS
855 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
856 "R_MIPS_GNU_VTENTRY", /* name */
b34976b6 857 FALSE, /* partial_inplace */
d75bc93d 858 0, /* src_mask */
c6e90b02 859 0, /* dst_mask */
b34976b6 860 FALSE); /* pcrel_offset */
252b5132 861
b34976b6 862/* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a
c6e90b02 863 dangerous relocation. */
252b5132 864
b34976b6 865static bfd_boolean
11a2be4d 866mips_elf_assign_gp (bfd *output_bfd, bfd_vma *pgp)
252b5132 867{
c6e90b02
TS
868 unsigned int count;
869 asymbol **sym;
870 unsigned int i;
e92d460e 871
c6e90b02
TS
872 /* If we've already figured out what GP will be, just return it. */
873 *pgp = _bfd_get_gp_value (output_bfd);
874 if (*pgp)
b34976b6 875 return TRUE;
c6e90b02
TS
876
877 count = bfd_get_symcount (output_bfd);
878 sym = bfd_get_outsymbols (output_bfd);
252b5132 879
c6e90b02
TS
880 /* The linker script will have created a symbol named `_gp' with the
881 appropriate value. */
11a2be4d 882 if (sym == NULL)
c6e90b02
TS
883 i = count;
884 else
252b5132 885 {
c6e90b02
TS
886 for (i = 0; i < count; i++, sym++)
887 {
888 register const char *name;
889
890 name = bfd_asymbol_name (*sym);
891 if (*name == '_' && strcmp (name, "_gp") == 0)
892 {
893 *pgp = bfd_asymbol_value (*sym);
894 _bfd_set_gp_value (output_bfd, *pgp);
895 break;
896 }
897 }
252b5132
RH
898 }
899
c6e90b02 900 if (i >= count)
252b5132 901 {
c6e90b02
TS
902 /* Only get the error once. */
903 *pgp = 4;
904 _bfd_set_gp_value (output_bfd, *pgp);
b34976b6 905 return FALSE;
252b5132
RH
906 }
907
b34976b6 908 return TRUE;
252b5132
RH
909}
910
c6e90b02
TS
911/* We have to figure out the gp value, so that we can adjust the
912 symbol value correctly. We look up the symbol _gp in the output
913 BFD. If we can't find it, we're stuck. We cache it in the ELF
914 target data. We don't need to adjust the symbol value for an
1049f94e 915 external symbol if we are producing relocatable output. */
252b5132 916
c6e90b02 917static bfd_reloc_status_type
11a2be4d
RS
918mips_elf_final_gp (bfd *output_bfd, asymbol *symbol, bfd_boolean relocatable,
919 char **error_message, bfd_vma *pgp)
252b5132 920{
c6e90b02 921 if (bfd_is_und_section (symbol->section)
1049f94e 922 && ! relocatable)
252b5132 923 {
c6e90b02
TS
924 *pgp = 0;
925 return bfd_reloc_undefined;
252b5132
RH
926 }
927
c6e90b02
TS
928 *pgp = _bfd_get_gp_value (output_bfd);
929 if (*pgp == 0
1049f94e 930 && (! relocatable
c6e90b02 931 || (symbol->flags & BSF_SECTION_SYM) != 0))
252b5132 932 {
1049f94e 933 if (relocatable)
252b5132 934 {
c6e90b02
TS
935 /* Make up a value. */
936 *pgp = symbol->section->output_section->vma + 0x4000;
937 _bfd_set_gp_value (output_bfd, *pgp);
252b5132 938 }
c6e90b02 939 else if (!mips_elf_assign_gp (output_bfd, pgp))
252b5132 940 {
c6e90b02
TS
941 *error_message =
942 (char *) _("GP relative relocation when _gp not defined");
943 return bfd_reloc_dangerous;
252b5132 944 }
252b5132
RH
945 }
946
c6e90b02
TS
947 return bfd_reloc_ok;
948}
252b5132 949
c6e90b02
TS
950/* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
951 become the offset from the gp register. This function also handles
952 R_MIPS_LITERAL relocations, although those can be handled more
953 cleverly because the entries in the .lit8 and .lit4 sections can be
954 merged. */
252b5132 955
c6e90b02 956bfd_reloc_status_type
11a2be4d
RS
957_bfd_mips_elf32_gprel16_reloc (bfd *abfd, arelent *reloc_entry,
958 asymbol *symbol, void *data,
959 asection *input_section, bfd *output_bfd,
960 char **error_message)
c6e90b02 961{
1049f94e 962 bfd_boolean relocatable;
c6e90b02
TS
963 bfd_reloc_status_type ret;
964 bfd_vma gp;
252b5132 965
254f0426
MR
966 /* R_MIPS_LITERAL relocations are defined for local symbols only. */
967 if (reloc_entry->howto->type == R_MIPS_LITERAL
968 && output_bfd != NULL
969 && (symbol->flags & BSF_SECTION_SYM) == 0
970 && (symbol->flags & BSF_LOCAL) != 0)
971 {
972 *error_message = (char *)
973 _("literal relocation occurs for an external symbol");
974 return bfd_reloc_outofrange;
975 }
976
11a2be4d 977 if (output_bfd != NULL)
1049f94e 978 relocatable = TRUE;
c6e90b02
TS
979 else
980 {
1049f94e 981 relocatable = FALSE;
c6e90b02
TS
982 output_bfd = symbol->section->output_section->owner;
983 }
252b5132 984
1049f94e 985 ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
c6e90b02
TS
986 &gp);
987 if (ret != bfd_reloc_ok)
988 return ret;
252b5132 989
c6e90b02 990 return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1049f94e 991 input_section, relocatable,
c6e90b02
TS
992 data, gp);
993}
252b5132 994
cb7394f2
TS
995/* Do a R_MIPS_GPREL32 relocation. This is a 32 bit value which must
996 become the offset from the gp register. */
252b5132 997
c6e90b02 998static bfd_reloc_status_type
11a2be4d
RS
999mips_elf_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1000 void *data, asection *input_section, bfd *output_bfd,
1001 char **error_message)
c6e90b02 1002{
1049f94e 1003 bfd_boolean relocatable;
c6e90b02
TS
1004 bfd_reloc_status_type ret;
1005 bfd_vma gp;
252b5132 1006
765f2ef6
MR
1007 /* R_MIPS_GPREL32 relocations are defined for local symbols only. */
1008 if (output_bfd != NULL
1009 && (symbol->flags & BSF_SECTION_SYM) == 0
1010 && (symbol->flags & BSF_LOCAL) != 0)
1011 {
1012 *error_message = (char *)
1013 _("32bits gp relative relocation occurs for an external symbol");
1014 return bfd_reloc_outofrange;
1015 }
1016
11a2be4d 1017 if (output_bfd != NULL)
1049f94e 1018 relocatable = TRUE;
c6e90b02
TS
1019 else
1020 {
1049f94e 1021 relocatable = FALSE;
c6e90b02 1022 output_bfd = symbol->section->output_section->owner;
c6e90b02 1023 }
252b5132 1024
1049f94e 1025 ret = mips_elf_final_gp (output_bfd, symbol, relocatable,
a7ebbfdf
TS
1026 error_message, &gp);
1027 if (ret != bfd_reloc_ok)
1028 return ret;
1029
c6e90b02 1030 return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
1049f94e 1031 relocatable, data, gp);
c6e90b02 1032}
252b5132 1033
c6e90b02 1034static bfd_reloc_status_type
11a2be4d
RS
1035gprel32_with_gp (bfd *abfd, asymbol *symbol, arelent *reloc_entry,
1036 asection *input_section, bfd_boolean relocatable,
1037 void *data, bfd_vma gp)
c6e90b02
TS
1038{
1039 bfd_vma relocation;
a7ebbfdf 1040 bfd_vma val;
252b5132 1041
c6e90b02
TS
1042 if (bfd_is_com_section (symbol->section))
1043 relocation = 0;
1044 else
1045 relocation = symbol->value;
252b5132 1046
c6e90b02
TS
1047 relocation += symbol->section->output_section->vma;
1048 relocation += symbol->section->output_offset;
252b5132 1049
07515404 1050 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
c6e90b02 1051 return bfd_reloc_outofrange;
252b5132 1052
c6e90b02 1053 /* Set val to the offset into the section or symbol. */
a7ebbfdf
TS
1054 val = reloc_entry->addend;
1055
1056 if (reloc_entry->howto->partial_inplace)
1057 val += bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
252b5132 1058
c6e90b02 1059 /* Adjust val for the final section location and GP value. If we
1049f94e 1060 are producing relocatable output, we don't want to do this for
c6e90b02 1061 an external symbol. */
1049f94e 1062 if (! relocatable
c6e90b02
TS
1063 || (symbol->flags & BSF_SECTION_SYM) != 0)
1064 val += relocation - gp;
252b5132 1065
a7ebbfdf
TS
1066 if (reloc_entry->howto->partial_inplace)
1067 bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
1068 else
1069 reloc_entry->addend = val;
c6142e5d 1070
1049f94e 1071 if (relocatable)
c6e90b02 1072 reloc_entry->address += input_section->output_offset;
252b5132 1073
c6e90b02 1074 return bfd_reloc_ok;
252b5132
RH
1075}
1076
c6e90b02
TS
1077/* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1078 generated when addresses are 64 bits. The upper 32 bits are a simple
1079 sign extension. */
7403cb63 1080
c6e90b02 1081static bfd_reloc_status_type
30ac9238
RS
1082mips32_64bit_reloc (bfd *abfd, arelent *reloc_entry,
1083 asymbol *symbol ATTRIBUTE_UNUSED,
1084 void *data, asection *input_section,
1085 bfd *output_bfd, char **error_message)
7403cb63 1086{
c6e90b02
TS
1087 bfd_reloc_status_type r;
1088 arelent reloc32;
1089 unsigned long val;
1090 bfd_size_type addr;
7403cb63 1091
c6e90b02
TS
1092 /* Do a normal 32 bit relocation on the lower 32 bits. */
1093 reloc32 = *reloc_entry;
1094 if (bfd_big_endian (abfd))
1095 reloc32.address += 4;
1096 reloc32.howto = &elf_mips_howto_table_rel[R_MIPS_32];
1097 r = bfd_perform_relocation (abfd, &reloc32, data, input_section,
1098 output_bfd, error_message);
be3ccd9c 1099
c6e90b02
TS
1100 /* Sign extend into the upper 32 bits. */
1101 val = bfd_get_32 (abfd, (bfd_byte *) data + reloc32.address);
1102 if ((val & 0x80000000) != 0)
1103 val = 0xffffffff;
1104 else
1105 val = 0;
1106 addr = reloc_entry->address;
1107 if (bfd_little_endian (abfd))
1108 addr += 4;
11a2be4d 1109 bfd_put_32 (abfd, val, (bfd_byte *) data + addr);
c6e90b02
TS
1110
1111 return r;
7403cb63
MM
1112}
1113
c6e90b02 1114/* Handle a mips16 jump. */
252b5132 1115
c6e90b02 1116static bfd_reloc_status_type
11a2be4d
RS
1117mips16_jump_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
1118 asymbol *symbol, void *data ATTRIBUTE_UNUSED,
1119 asection *input_section, bfd *output_bfd,
1120 char **error_message ATTRIBUTE_UNUSED)
252b5132 1121{
11a2be4d 1122 if (output_bfd != NULL
c6e90b02
TS
1123 && (symbol->flags & BSF_SECTION_SYM) == 0
1124 && reloc_entry->addend == 0)
252b5132 1125 {
c6e90b02
TS
1126 reloc_entry->address += input_section->output_offset;
1127 return bfd_reloc_ok;
1128 }
252b5132 1129
c6e90b02
TS
1130 /* FIXME. */
1131 {
b34976b6 1132 static bfd_boolean warned;
252b5132 1133
c6e90b02
TS
1134 if (! warned)
1135 (*_bfd_error_handler)
1136 (_("Linking mips16 objects into %s format is not supported"),
1137 bfd_get_target (input_section->output_section->owner));
b34976b6 1138 warned = TRUE;
c6e90b02 1139 }
252b5132 1140
c6e90b02
TS
1141 return bfd_reloc_undefined;
1142}
252b5132 1143
c6e90b02 1144/* Handle a mips16 GP relative reloc. */
252b5132 1145
c6e90b02 1146static bfd_reloc_status_type
11a2be4d
RS
1147mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
1148 void *data, asection *input_section, bfd *output_bfd,
1149 char **error_message)
c6e90b02 1150{
1049f94e 1151 bfd_boolean relocatable;
c6e90b02 1152 bfd_reloc_status_type ret;
d6f16593 1153 bfd_byte *location;
c6e90b02 1154 bfd_vma gp;
252b5132 1155
a7ebbfdf
TS
1156 /* If we're relocating, and this is an external symbol, we don't want
1157 to change anything. */
c6e90b02
TS
1158 if (output_bfd != NULL
1159 && (symbol->flags & BSF_SECTION_SYM) == 0
a7ebbfdf 1160 && (symbol->flags & BSF_LOCAL) != 0)
c6e90b02
TS
1161 {
1162 reloc_entry->address += input_section->output_offset;
1163 return bfd_reloc_ok;
1164 }
252b5132 1165
c6e90b02 1166 if (output_bfd != NULL)
1049f94e 1167 relocatable = TRUE;
c6e90b02
TS
1168 else
1169 {
1049f94e 1170 relocatable = FALSE;
c6e90b02 1171 output_bfd = symbol->section->output_section->owner;
252b5132
RH
1172 }
1173
1049f94e 1174 ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
c6e90b02
TS
1175 &gp);
1176 if (ret != bfd_reloc_ok)
1177 return ret;
252b5132 1178
d6f16593
MR
1179 location = (bfd_byte *) data + reloc_entry->address;
1180 _bfd_mips16_elf_reloc_unshuffle (abfd, reloc_entry->howto->type, FALSE,
1181 location);
1182 ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry,
1183 input_section, relocatable,
1184 data, gp);
1185 _bfd_mips16_elf_reloc_shuffle (abfd, reloc_entry->howto->type, !relocatable,
1186 location);
a7ebbfdf 1187
d6f16593 1188 return ret;
c6e90b02 1189}
7403cb63 1190
c6e90b02 1191/* A mapping from BFD reloc types to MIPS ELF reloc types. */
252b5132 1192
c6e90b02 1193struct elf_reloc_map {
cb7394f2
TS
1194 bfd_reloc_code_real_type bfd_val;
1195 enum elf_mips_reloc_type elf_val;
c6e90b02 1196};
252b5132 1197
c6e90b02
TS
1198static const struct elf_reloc_map mips_reloc_map[] =
1199{
28458e7e 1200 { BFD_RELOC_NONE, R_MIPS_NONE },
c6e90b02
TS
1201 { BFD_RELOC_16, R_MIPS_16 },
1202 { BFD_RELOC_32, R_MIPS_32 },
cb7394f2 1203 /* There is no BFD reloc for R_MIPS_REL32. */
c6e90b02
TS
1204 { BFD_RELOC_64, R_MIPS_64 },
1205 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
1206 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
1207 { BFD_RELOC_LO16, R_MIPS_LO16 },
1208 { BFD_RELOC_GPREL16, R_MIPS_GPREL16 },
1209 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
1210 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
bad36eac 1211 { BFD_RELOC_16_PCREL_S2, R_MIPS_PC16 },
c6e90b02
TS
1212 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
1213 { BFD_RELOC_GPREL32, R_MIPS_GPREL32 },
1214 { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
1215 { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
1216 { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
1217 { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
1218 { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
1219 { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
1220 { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
0f20cc35
DJ
1221 { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP },
1222 { BFD_RELOC_MIPS_TLS_DTPMOD32, R_MIPS_TLS_DTPMOD32 },
1223 { BFD_RELOC_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL32 },
1224 { BFD_RELOC_MIPS_TLS_DTPMOD64, R_MIPS_TLS_DTPMOD64 },
1225 { BFD_RELOC_MIPS_TLS_DTPREL64, R_MIPS_TLS_DTPREL64 },
1226 { BFD_RELOC_MIPS_TLS_GD, R_MIPS_TLS_GD },
1227 { BFD_RELOC_MIPS_TLS_LDM, R_MIPS_TLS_LDM },
1228 { BFD_RELOC_MIPS_TLS_DTPREL_HI16, R_MIPS_TLS_DTPREL_HI16 },
1229 { BFD_RELOC_MIPS_TLS_DTPREL_LO16, R_MIPS_TLS_DTPREL_LO16 },
1230 { BFD_RELOC_MIPS_TLS_GOTTPREL, R_MIPS_TLS_GOTTPREL },
1231 { BFD_RELOC_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL32 },
1232 { BFD_RELOC_MIPS_TLS_TPREL64, R_MIPS_TLS_TPREL64 },
1233 { BFD_RELOC_MIPS_TLS_TPREL_HI16, R_MIPS_TLS_TPREL_HI16 },
1234 { BFD_RELOC_MIPS_TLS_TPREL_LO16, R_MIPS_TLS_TPREL_LO16 }
c6e90b02 1235};
252b5132 1236
d6f16593
MR
1237static const struct elf_reloc_map mips16_reloc_map[] =
1238{
1239 { BFD_RELOC_MIPS16_JMP, R_MIPS16_26 - R_MIPS16_min },
1240 { BFD_RELOC_MIPS16_GPREL, R_MIPS16_GPREL - R_MIPS16_min },
1241 { BFD_RELOC_MIPS16_HI16_S, R_MIPS16_HI16 - R_MIPS16_min },
1242 { BFD_RELOC_MIPS16_LO16, R_MIPS16_LO16 - R_MIPS16_min },
1243};
1244
c6e90b02 1245/* Given a BFD reloc type, return a howto structure. */
252b5132 1246
c6e90b02 1247static reloc_howto_type *
11a2be4d 1248bfd_elf32_bfd_reloc_type_lookup (bfd *abfd, bfd_reloc_code_real_type code)
252b5132 1249{
c6e90b02 1250 unsigned int i;
cb7394f2 1251 reloc_howto_type *howto_table = elf_mips_howto_table_rel;
d6f16593 1252 reloc_howto_type *howto16_table = elf_mips16_howto_table_rel;
252b5132 1253
cb7394f2
TS
1254 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map);
1255 i++)
252b5132 1256 {
cb7394f2
TS
1257 if (mips_reloc_map[i].bfd_val == code)
1258 return &howto_table[(int) mips_reloc_map[i].elf_val];
252b5132
RH
1259 }
1260
d6f16593
MR
1261 for (i = 0; i < sizeof (mips16_reloc_map) / sizeof (struct elf_reloc_map);
1262 i++)
1263 {
1264 if (mips16_reloc_map[i].bfd_val == code)
1265 return &howto16_table[(int) mips16_reloc_map[i].elf_val];
1266 }
1267
c6e90b02 1268 switch (code)
252b5132 1269 {
c6e90b02
TS
1270 default:
1271 bfd_set_error (bfd_error_bad_value);
1272 return NULL;
252b5132 1273
c6e90b02
TS
1274 case BFD_RELOC_CTOR:
1275 /* We need to handle BFD_RELOC_CTOR specially.
1276 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
69931e60
AO
1277 size of addresses of the ABI. */
1278 if ((elf_elfheader (abfd)->e_flags & (E_MIPS_ABI_O64
1279 | E_MIPS_ABI_EABI64)) != 0)
c6e90b02 1280 return &elf_mips_ctor64_howto;
69931e60
AO
1281 else
1282 return &howto_table[(int) R_MIPS_32];
252b5132 1283
c6e90b02
TS
1284 case BFD_RELOC_VTABLE_INHERIT:
1285 return &elf_mips_gnu_vtinherit_howto;
1286 case BFD_RELOC_VTABLE_ENTRY:
1287 return &elf_mips_gnu_vtentry_howto;
092dcd75
CD
1288 case BFD_RELOC_32_PCREL:
1289 return &elf_mips_gnu_pcrel32;
c6e90b02
TS
1290 }
1291}
252b5132 1292
947216bf 1293/* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
252b5132 1294
c6e90b02 1295static reloc_howto_type *
11a2be4d
RS
1296mips_elf32_rtype_to_howto (unsigned int r_type,
1297 bfd_boolean rela_p ATTRIBUTE_UNUSED)
c6e90b02
TS
1298{
1299 switch (r_type)
1300 {
c6e90b02
TS
1301 case R_MIPS_GNU_VTINHERIT:
1302 return &elf_mips_gnu_vtinherit_howto;
c6e90b02
TS
1303 case R_MIPS_GNU_VTENTRY:
1304 return &elf_mips_gnu_vtentry_howto;
c6e90b02
TS
1305 case R_MIPS_GNU_REL16_S2:
1306 return &elf_mips_gnu_rel16_s2;
092dcd75
CD
1307 case R_MIPS_PC32:
1308 return &elf_mips_gnu_pcrel32;
c6e90b02 1309 default:
d6f16593
MR
1310 if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max)
1311 return &elf_mips16_howto_table_rel[r_type - R_MIPS16_min];
c6e90b02
TS
1312 BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
1313 return &elf_mips_howto_table_rel[r_type];
1314 }
1315}
252b5132 1316
947216bf 1317/* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
252b5132 1318
c6e90b02 1319static void
11a2be4d 1320mips_info_to_howto_rel (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
c6e90b02
TS
1321{
1322 unsigned int r_type;
252b5132 1323
c6e90b02 1324 r_type = ELF32_R_TYPE (dst->r_info);
b34976b6 1325 cache_ptr->howto = mips_elf32_rtype_to_howto (r_type, FALSE);
252b5132 1326
c6e90b02
TS
1327 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1328 value for the object file. We get the addend now, rather than
1329 when we do the relocation, because the symbol manipulations done
1330 by the linker may cause us to lose track of the input BFD. */
1331 if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
1332 && (r_type == (unsigned int) R_MIPS_GPREL16
1333 || r_type == (unsigned int) R_MIPS_LITERAL))
1334 cache_ptr->addend = elf_gp (abfd);
1335}
5499724a 1336
947216bf 1337/* Given a MIPS Elf_Internal_Rela, fill in an arelent structure. */
252b5132 1338
c6e90b02 1339static void
11a2be4d 1340mips_info_to_howto_rela (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
c6e90b02 1341{
947216bf 1342 mips_info_to_howto_rel (abfd, cache_ptr, dst);
252b5132 1343
c6e90b02 1344 /* If we ever need to do any extra processing with dst->r_addend
947216bf 1345 (the field omitted in an Elf_Internal_Rel) we can do it here. */
c6e90b02
TS
1346}
1347\f
1348/* Determine whether a symbol is global for the purposes of splitting
1349 the symbol table into global symbols and local symbols. At least
1350 on Irix 5, this split must be between section symbols and all other
1351 symbols. On most ELF targets the split is between static symbols
1352 and externally visible symbols. */
252b5132 1353
b34976b6 1354static bfd_boolean
11a2be4d 1355mips_elf_sym_is_global (bfd *abfd ATTRIBUTE_UNUSED, asymbol *sym)
c6e90b02
TS
1356{
1357 if (SGI_COMPAT (abfd))
1358 return (sym->flags & BSF_SECTION_SYM) == 0;
1359 else
1360 return ((sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0
1361 || bfd_is_und_section (bfd_get_section (sym))
1362 || bfd_is_com_section (bfd_get_section (sym)));
1363}
1364\f
1365/* Set the right machine number for a MIPS ELF file. */
7403cb63 1366
b34976b6 1367static bfd_boolean
11a2be4d 1368mips_elf32_object_p (bfd *abfd)
c6e90b02
TS
1369{
1370 unsigned long mach;
103186c6 1371
c6e90b02
TS
1372 /* Irix 5 and 6 are broken. Object file symbol tables are not always
1373 sorted correctly such that local symbols precede global symbols,
1374 and the sh_info field in the symbol table is not always right. */
1375 if (SGI_COMPAT (abfd))
b34976b6 1376 elf_bad_symtab (abfd) = TRUE;
103186c6 1377
8a397dad 1378 if (ABI_N32_P (abfd))
b34976b6 1379 return FALSE;
8a397dad 1380
c6e90b02
TS
1381 mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
1382 bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
252b5132 1383
b34976b6 1384 return TRUE;
c6e90b02
TS
1385}
1386\f
1387/* MIPS ELF local labels start with '$', not 'L'. */
252b5132 1388
b34976b6 1389static bfd_boolean
11a2be4d 1390mips_elf_is_local_label_name (bfd *abfd, const char *name)
c6e90b02
TS
1391{
1392 if (name[0] == '$')
b34976b6 1393 return TRUE;
252b5132 1394
c6e90b02
TS
1395 /* On Irix 6, the labels go back to starting with '.', so we accept
1396 the generic ELF local label syntax as well. */
1397 return _bfd_elf_is_local_label_name (abfd, name);
252b5132
RH
1398}
1399\f
c6e90b02 1400/* Support for core dump NOTE sections. */
b34976b6 1401static bfd_boolean
11a2be4d 1402elf32_mips_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
bb0082d6
AM
1403{
1404 int offset;
eea6121a 1405 unsigned int size;
bb0082d6
AM
1406
1407 switch (note->descsz)
1408 {
1409 default:
b34976b6 1410 return FALSE;
bb0082d6
AM
1411
1412 case 256: /* Linux/MIPS */
1413 /* pr_cursig */
1414 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1415
1416 /* pr_pid */
1417 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1418
1419 /* pr_reg */
1420 offset = 72;
eea6121a 1421 size = 180;
bb0082d6
AM
1422
1423 break;
1424 }
1425
1426 /* Make a ".reg/999" section. */
936e320b 1427 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
eea6121a 1428 size, note->descpos + offset);
bb0082d6
AM
1429}
1430
b34976b6 1431static bfd_boolean
11a2be4d 1432elf32_mips_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
bb0082d6
AM
1433{
1434 switch (note->descsz)
1435 {
1436 default:
b34976b6 1437 return FALSE;
bb0082d6
AM
1438
1439 case 128: /* Linux/MIPS elf_prpsinfo */
1440 elf_tdata (abfd)->core_program
1441 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
1442 elf_tdata (abfd)->core_command
1443 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
1444 }
1445
1446 /* Note that for some reason, a spurious space is tacked
1447 onto the end of the args in some (at least one anyway)
1448 implementations, so strip it off if it exists. */
1449
1450 {
1451 char *command = elf_tdata (abfd)->core_command;
1452 int n = strlen (command);
1453
1454 if (0 < n && command[n - 1] == ' ')
1455 command[n - 1] = '\0';
1456 }
1457
b34976b6 1458 return TRUE;
bb0082d6
AM
1459}
1460\f
c6e90b02
TS
1461/* Depending on the target vector we generate some version of Irix
1462 executables or "normal" MIPS ELF ABI executables. */
1463static irix_compat_t
11a2be4d 1464elf32_mips_irix_compat (bfd *abfd)
c6e90b02 1465{
cb7394f2
TS
1466 if ((abfd->xvec == &bfd_elf32_bigmips_vec)
1467 || (abfd->xvec == &bfd_elf32_littlemips_vec))
c6e90b02 1468 return ict_irix5;
cb7394f2
TS
1469 else
1470 return ict_none;
c6e90b02 1471}
73d074b4 1472\f
252b5132
RH
1473/* ECOFF swapping routines. These are used when dealing with the
1474 .mdebug section, which is in the ECOFF debugging format. */
be3ccd9c 1475static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
252b5132
RH
1476 /* Symbol table magic number. */
1477 magicSym,
1478 /* Alignment of debugging information. E.g., 4. */
1479 4,
1480 /* Sizes of external symbolic information. */
1481 sizeof (struct hdr_ext),
1482 sizeof (struct dnr_ext),
1483 sizeof (struct pdr_ext),
1484 sizeof (struct sym_ext),
1485 sizeof (struct opt_ext),
1486 sizeof (struct fdr_ext),
1487 sizeof (struct rfd_ext),
1488 sizeof (struct ext_ext),
1489 /* Functions to swap in external symbolic data. */
1490 ecoff_swap_hdr_in,
1491 ecoff_swap_dnr_in,
1492 ecoff_swap_pdr_in,
1493 ecoff_swap_sym_in,
1494 ecoff_swap_opt_in,
1495 ecoff_swap_fdr_in,
1496 ecoff_swap_rfd_in,
1497 ecoff_swap_ext_in,
1498 _bfd_ecoff_swap_tir_in,
1499 _bfd_ecoff_swap_rndx_in,
1500 /* Functions to swap out external symbolic data. */
1501 ecoff_swap_hdr_out,
1502 ecoff_swap_dnr_out,
1503 ecoff_swap_pdr_out,
1504 ecoff_swap_sym_out,
1505 ecoff_swap_opt_out,
1506 ecoff_swap_fdr_out,
1507 ecoff_swap_rfd_out,
1508 ecoff_swap_ext_out,
1509 _bfd_ecoff_swap_tir_out,
1510 _bfd_ecoff_swap_rndx_out,
1511 /* Function to read in symbolic data. */
1512 _bfd_mips_elf_read_ecoff_info
1513};
1514\f
252b5132
RH
1515#define ELF_ARCH bfd_arch_mips
1516#define ELF_MACHINE_CODE EM_MIPS
1517
b34976b6
AM
1518#define elf_backend_collect TRUE
1519#define elf_backend_type_change_ok TRUE
1520#define elf_backend_can_gc_sections TRUE
3f830999 1521#define elf_info_to_howto mips_info_to_howto_rela
252b5132
RH
1522#define elf_info_to_howto_rel mips_info_to_howto_rel
1523#define elf_backend_sym_is_global mips_elf_sym_is_global
c6e90b02 1524#define elf_backend_object_p mips_elf32_object_p
d75bc93d
TS
1525#define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
1526#define elf_backend_section_processing _bfd_mips_elf_section_processing
103186c6 1527#define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
252b5132
RH
1528#define elf_backend_fake_sections _bfd_mips_elf_fake_sections
1529#define elf_backend_section_from_bfd_section \
1530 _bfd_mips_elf_section_from_bfd_section
103186c6 1531#define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
d75bc93d
TS
1532#define elf_backend_link_output_symbol_hook \
1533 _bfd_mips_elf_link_output_symbol_hook
103186c6
MM
1534#define elf_backend_create_dynamic_sections \
1535 _bfd_mips_elf_create_dynamic_sections
1536#define elf_backend_check_relocs _bfd_mips_elf_check_relocs
1537#define elf_backend_adjust_dynamic_symbol \
1538 _bfd_mips_elf_adjust_dynamic_symbol
1539#define elf_backend_always_size_sections \
1540 _bfd_mips_elf_always_size_sections
1541#define elf_backend_size_dynamic_sections \
1542 _bfd_mips_elf_size_dynamic_sections
1543#define elf_backend_relocate_section _bfd_mips_elf_relocate_section
103186c6
MM
1544#define elf_backend_finish_dynamic_symbol \
1545 _bfd_mips_elf_finish_dynamic_symbol
1546#define elf_backend_finish_dynamic_sections \
1547 _bfd_mips_elf_finish_dynamic_sections
d75bc93d
TS
1548#define elf_backend_final_write_processing \
1549 _bfd_mips_elf_final_write_processing
1550#define elf_backend_additional_program_headers \
1551 _bfd_mips_elf_additional_program_headers
1552#define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
103186c6
MM
1553#define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
1554#define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
8a20f077
UC
1555#define elf_backend_copy_indirect_symbol \
1556 _bfd_mips_elf_copy_indirect_symbol
b305ef96 1557#define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
c6e90b02
TS
1558#define elf_backend_grok_prstatus elf32_mips_grok_prstatus
1559#define elf_backend_grok_psinfo elf32_mips_grok_psinfo
d75bc93d
TS
1560#define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
1561
1562#define elf_backend_got_header_size (4 * MIPS_RESERVED_GOTNO)
d75bc93d
TS
1563#define elf_backend_may_use_rel_p 1
1564#define elf_backend_may_use_rela_p 0
1565#define elf_backend_default_use_rela_p 0
b34976b6 1566#define elf_backend_sign_extend_vma TRUE
b305ef96 1567
d01414a5 1568#define elf_backend_discard_info _bfd_mips_elf_discard_info
73d074b4 1569#define elf_backend_ignore_discarded_relocs \
53bfd6b4 1570 _bfd_mips_elf_ignore_discarded_relocs
c6e90b02
TS
1571#define elf_backend_mips_irix_compat elf32_mips_irix_compat
1572#define elf_backend_mips_rtype_to_howto mips_elf32_rtype_to_howto
252b5132
RH
1573#define bfd_elf32_bfd_is_local_label_name \
1574 mips_elf_is_local_label_name
1575#define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
4ab527b0 1576#define bfd_elf32_find_inliner_info _bfd_mips_elf_find_inliner_info
f0abc2a1 1577#define bfd_elf32_new_section_hook _bfd_mips_elf_new_section_hook
252b5132 1578#define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
c6e90b02
TS
1579#define bfd_elf32_bfd_get_relocated_section_contents \
1580 _bfd_elf_mips_get_relocated_section_contents
252b5132 1581#define bfd_elf32_bfd_link_hash_table_create \
103186c6
MM
1582 _bfd_mips_elf_link_hash_table_create
1583#define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
252b5132
RH
1584#define bfd_elf32_bfd_merge_private_bfd_data \
1585 _bfd_mips_elf_merge_private_bfd_data
1586#define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
1587#define bfd_elf32_bfd_print_private_bfd_data \
1588 _bfd_mips_elf_print_private_bfd_data
e364195d 1589
d75bc93d
TS
1590/* Support for SGI-ish mips targets. */
1591#define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
1592#define TARGET_LITTLE_NAME "elf32-littlemips"
1593#define TARGET_BIG_SYM bfd_elf32_bigmips_vec
1594#define TARGET_BIG_NAME "elf32-bigmips"
1595
4301eeb1
MR
1596/* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
1597 a value of 0x1000, and we are compatible. */
1598#define ELF_MAXPAGESIZE 0x1000
1599
d75bc93d 1600#include "elf32-target.h"
e364195d 1601
d75bc93d 1602/* Support for traditional mips targets. */
e364195d
UC
1603#undef TARGET_LITTLE_SYM
1604#undef TARGET_LITTLE_NAME
1605#undef TARGET_BIG_SYM
1606#undef TARGET_BIG_NAME
1607
4301eeb1
MR
1608#undef ELF_MAXPAGESIZE
1609
e364195d
UC
1610#define TARGET_LITTLE_SYM bfd_elf32_tradlittlemips_vec
1611#define TARGET_LITTLE_NAME "elf32-tradlittlemips"
1612#define TARGET_BIG_SYM bfd_elf32_tradbigmips_vec
1613#define TARGET_BIG_NAME "elf32-tradbigmips"
1614
4301eeb1
MR
1615/* The SVR4 MIPS ABI says that this should be 0x10000, and Linux uses
1616 page sizes of up to that limit, so we need to respect it. */
1617#define ELF_MAXPAGESIZE 0x10000
1618#define elf32_bed elf32_tradbed
1619
c6e90b02 1620/* Include the target file again for this target. */
e364195d 1621#include "elf32-target.h"
This page took 0.556917 seconds and 4 git commands to generate.