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