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