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