1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 Most of the information added by Ian Lance Taylor, Cygnus Support,
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>
12 This file is part of BFD, the Binary File Descriptor library.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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. */
38 #include "elfxx-mips.h"
41 /* Get the ECOFF swapping routines. */
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"
50 static bfd_reloc_status_type mips_elf_hi16_reloc
51 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
52 static bfd_reloc_status_type mips_elf_lo16_reloc
53 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
54 static bfd_reloc_status_type mips_elf_got16_reloc
55 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
56 static bfd_reloc_status_type mips_elf_gprel32_reloc
57 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
58 static bfd_reloc_status_type mips32_64bit_reloc
59 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
60 static reloc_howto_type
*bfd_elf32_bfd_reloc_type_lookup
61 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
62 static reloc_howto_type
*mips_elf32_rtype_to_howto
63 PARAMS ((unsigned int, boolean
));
64 static void mips_info_to_howto_rel
65 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
66 static void mips_info_to_howto_rela
67 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
68 static boolean mips_elf_sym_is_global
PARAMS ((bfd
*, asymbol
*));
69 static boolean mips_elf32_object_p
PARAMS ((bfd
*));
70 static boolean mips_elf_is_local_label_name
71 PARAMS ((bfd
*, const char *));
72 static bfd_reloc_status_type mips16_jump_reloc
73 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
74 static bfd_reloc_status_type mips16_gprel_reloc
75 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
76 static bfd_reloc_status_type mips_elf_final_gp
77 PARAMS ((bfd
*, asymbol
*, boolean
, char **, bfd_vma
*));
78 static boolean mips_elf_assign_gp
PARAMS ((bfd
*, bfd_vma
*));
79 static boolean elf32_mips_grok_prstatus
80 PARAMS ((bfd
*, Elf_Internal_Note
*));
81 static boolean elf32_mips_grok_psinfo
82 PARAMS ((bfd
*, Elf_Internal_Note
*));
83 static irix_compat_t elf32_mips_irix_compat
86 extern const bfd_target bfd_elf32_bigmips_vec
;
87 extern const bfd_target bfd_elf32_littlemips_vec
;
89 /* Nonzero if ABFD is using the N32 ABI. */
90 #define ABI_N32_P(abfd) \
91 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
93 /* Whether we are trying to be compatible with IRIX at all. */
94 #define SGI_COMPAT(abfd) \
95 (elf32_mips_irix_compat (abfd) != ict_none)
97 /* The number of local .got entries we reserve. */
98 #define MIPS_RESERVED_GOTNO (2)
100 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
101 from smaller values. Start with zero, widen, *then* decrement. */
102 #define MINUS_ONE (((bfd_vma)0) - 1)
104 /* The relocation table used for SHT_REL sections. */
106 static reloc_howto_type elf_mips_howto_table_rel
[] =
109 HOWTO (R_MIPS_NONE
, /* type */
111 0, /* size (0 = byte, 1 = short, 2 = long) */
113 false, /* pc_relative */
115 complain_overflow_dont
, /* complain_on_overflow */
116 bfd_elf_generic_reloc
, /* special_function */
117 "R_MIPS_NONE", /* name */
118 false, /* partial_inplace */
121 false), /* pcrel_offset */
123 /* 16 bit relocation. */
124 HOWTO (R_MIPS_16
, /* type */
126 2, /* size (0 = byte, 1 = short, 2 = long) */
128 false, /* pc_relative */
130 complain_overflow_signed
, /* complain_on_overflow */
131 bfd_elf_generic_reloc
, /* special_function */
132 "R_MIPS_16", /* name */
133 true, /* partial_inplace */
134 0x0000ffff, /* src_mask */
135 0x0000ffff, /* dst_mask */
136 false), /* pcrel_offset */
138 /* 32 bit relocation. */
139 HOWTO (R_MIPS_32
, /* type */
141 2, /* size (0 = byte, 1 = short, 2 = long) */
143 false, /* pc_relative */
145 complain_overflow_dont
, /* complain_on_overflow */
146 bfd_elf_generic_reloc
, /* special_function */
147 "R_MIPS_32", /* name */
148 true, /* partial_inplace */
149 0xffffffff, /* src_mask */
150 0xffffffff, /* dst_mask */
151 false), /* pcrel_offset */
153 /* 32 bit symbol relative relocation. */
154 HOWTO (R_MIPS_REL32
, /* type */
156 2, /* size (0 = byte, 1 = short, 2 = long) */
158 false, /* pc_relative */
160 complain_overflow_dont
, /* complain_on_overflow */
161 bfd_elf_generic_reloc
, /* special_function */
162 "R_MIPS_REL32", /* name */
163 true, /* partial_inplace */
164 0xffffffff, /* src_mask */
165 0xffffffff, /* dst_mask */
166 false), /* pcrel_offset */
168 /* 26 bit jump address. */
169 HOWTO (R_MIPS_26
, /* type */
171 2, /* size (0 = byte, 1 = short, 2 = long) */
173 false, /* pc_relative */
175 complain_overflow_dont
, /* complain_on_overflow */
176 /* This needs complex overflow
177 detection, because the upper four
178 bits must match the PC + 4. */
179 bfd_elf_generic_reloc
, /* special_function */
180 "R_MIPS_26", /* name */
181 true, /* partial_inplace */
182 0x03ffffff, /* src_mask */
183 0x03ffffff, /* dst_mask */
184 false), /* pcrel_offset */
186 /* High 16 bits of symbol value. */
187 HOWTO (R_MIPS_HI16
, /* type */
189 2, /* size (0 = byte, 1 = short, 2 = long) */
191 false, /* pc_relative */
193 complain_overflow_dont
, /* complain_on_overflow */
194 mips_elf_hi16_reloc
, /* special_function */
195 "R_MIPS_HI16", /* name */
196 true, /* partial_inplace */
197 0x0000ffff, /* src_mask */
198 0x0000ffff, /* dst_mask */
199 false), /* pcrel_offset */
201 /* Low 16 bits of symbol value. */
202 HOWTO (R_MIPS_LO16
, /* type */
204 2, /* size (0 = byte, 1 = short, 2 = long) */
206 false, /* pc_relative */
208 complain_overflow_dont
, /* complain_on_overflow */
209 mips_elf_lo16_reloc
, /* special_function */
210 "R_MIPS_LO16", /* name */
211 true, /* partial_inplace */
212 0x0000ffff, /* src_mask */
213 0x0000ffff, /* dst_mask */
214 false), /* pcrel_offset */
216 /* GP relative reference. */
217 HOWTO (R_MIPS_GPREL16
, /* type */
219 2, /* size (0 = byte, 1 = short, 2 = long) */
221 false, /* pc_relative */
223 complain_overflow_signed
, /* complain_on_overflow */
224 _bfd_mips_elf32_gprel16_reloc
, /* special_function */
225 "R_MIPS_GPREL16", /* name */
226 true, /* partial_inplace */
227 0x0000ffff, /* src_mask */
228 0x0000ffff, /* dst_mask */
229 false), /* pcrel_offset */
231 /* Reference to literal section. */
232 HOWTO (R_MIPS_LITERAL
, /* type */
234 2, /* size (0 = byte, 1 = short, 2 = long) */
236 false, /* pc_relative */
238 complain_overflow_signed
, /* complain_on_overflow */
239 _bfd_mips_elf32_gprel16_reloc
, /* special_function */
240 "R_MIPS_LITERAL", /* name */
241 true, /* partial_inplace */
242 0x0000ffff, /* src_mask */
243 0x0000ffff, /* dst_mask */
244 false), /* pcrel_offset */
246 /* Reference to global offset table. */
247 HOWTO (R_MIPS_GOT16
, /* type */
249 2, /* size (0 = byte, 1 = short, 2 = long) */
251 false, /* pc_relative */
253 complain_overflow_signed
, /* complain_on_overflow */
254 mips_elf_got16_reloc
, /* special_function */
255 "R_MIPS_GOT16", /* name */
256 true, /* partial_inplace */
257 0x0000ffff, /* src_mask */
258 0x0000ffff, /* dst_mask */
259 false), /* pcrel_offset */
261 /* 16 bit PC relative reference. */
262 HOWTO (R_MIPS_PC16
, /* type */
264 2, /* size (0 = byte, 1 = short, 2 = long) */
266 true, /* pc_relative */
268 complain_overflow_signed
, /* complain_on_overflow */
269 bfd_elf_generic_reloc
, /* special_function */
270 "R_MIPS_PC16", /* name */
271 true, /* partial_inplace */
272 0x0000ffff, /* src_mask */
273 0x0000ffff, /* dst_mask */
274 true), /* pcrel_offset */
276 /* 16 bit call through global offset table. */
277 HOWTO (R_MIPS_CALL16
, /* type */
279 2, /* size (0 = byte, 1 = short, 2 = long) */
281 false, /* pc_relative */
283 complain_overflow_signed
, /* complain_on_overflow */
284 bfd_elf_generic_reloc
, /* special_function */
285 "R_MIPS_CALL16", /* name */
286 true, /* partial_inplace */
287 0x0000ffff, /* src_mask */
288 0x0000ffff, /* dst_mask */
289 false), /* pcrel_offset */
291 /* 32 bit GP relative reference. */
292 HOWTO (R_MIPS_GPREL32
, /* type */
294 2, /* size (0 = byte, 1 = short, 2 = long) */
296 false, /* pc_relative */
298 complain_overflow_dont
, /* complain_on_overflow */
299 mips_elf_gprel32_reloc
, /* special_function */
300 "R_MIPS_GPREL32", /* name */
301 true, /* partial_inplace */
302 0xffffffff, /* src_mask */
303 0xffffffff, /* dst_mask */
304 false), /* pcrel_offset */
306 /* The remaining relocs are defined on Irix 5, although they are
307 not defined by the ABI. */
312 /* A 5 bit shift field. */
313 HOWTO (R_MIPS_SHIFT5
, /* type */
315 2, /* size (0 = byte, 1 = short, 2 = long) */
317 false, /* pc_relative */
319 complain_overflow_bitfield
, /* complain_on_overflow */
320 bfd_elf_generic_reloc
, /* special_function */
321 "R_MIPS_SHIFT5", /* name */
322 true, /* partial_inplace */
323 0x000007c0, /* src_mask */
324 0x000007c0, /* dst_mask */
325 false), /* pcrel_offset */
327 /* A 6 bit shift field. */
328 /* FIXME: This is not handled correctly; a special function is
329 needed to put the most significant bit in the right place. */
330 HOWTO (R_MIPS_SHIFT6
, /* type */
332 2, /* size (0 = byte, 1 = short, 2 = long) */
334 false, /* pc_relative */
336 complain_overflow_bitfield
, /* complain_on_overflow */
337 bfd_elf_generic_reloc
, /* special_function */
338 "R_MIPS_SHIFT6", /* name */
339 true, /* partial_inplace */
340 0x000007c4, /* src_mask */
341 0x000007c4, /* dst_mask */
342 false), /* pcrel_offset */
344 /* A 64 bit relocation. */
345 HOWTO (R_MIPS_64
, /* type */
347 4, /* size (0 = byte, 1 = short, 2 = long) */
349 false, /* pc_relative */
351 complain_overflow_dont
, /* complain_on_overflow */
352 mips32_64bit_reloc
, /* special_function */
353 "R_MIPS_64", /* name */
354 true, /* partial_inplace */
355 MINUS_ONE
, /* src_mask */
356 MINUS_ONE
, /* dst_mask */
357 false), /* pcrel_offset */
359 /* Displacement in the global offset table. */
360 HOWTO (R_MIPS_GOT_DISP
, /* type */
362 2, /* size (0 = byte, 1 = short, 2 = long) */
364 false, /* pc_relative */
366 complain_overflow_signed
, /* complain_on_overflow */
367 bfd_elf_generic_reloc
, /* special_function */
368 "R_MIPS_GOT_DISP", /* name */
369 true, /* partial_inplace */
370 0x0000ffff, /* src_mask */
371 0x0000ffff, /* dst_mask */
372 false), /* pcrel_offset */
374 /* Displacement to page pointer in the global offset table. */
375 HOWTO (R_MIPS_GOT_PAGE
, /* type */
377 2, /* size (0 = byte, 1 = short, 2 = long) */
379 false, /* pc_relative */
381 complain_overflow_signed
, /* complain_on_overflow */
382 bfd_elf_generic_reloc
, /* special_function */
383 "R_MIPS_GOT_PAGE", /* name */
384 true, /* partial_inplace */
385 0x0000ffff, /* src_mask */
386 0x0000ffff, /* dst_mask */
387 false), /* pcrel_offset */
389 /* Offset from page pointer in the global offset table. */
390 HOWTO (R_MIPS_GOT_OFST
, /* type */
392 2, /* size (0 = byte, 1 = short, 2 = long) */
394 false, /* pc_relative */
396 complain_overflow_signed
, /* complain_on_overflow */
397 bfd_elf_generic_reloc
, /* special_function */
398 "R_MIPS_GOT_OFST", /* name */
399 true, /* partial_inplace */
400 0x0000ffff, /* src_mask */
401 0x0000ffff, /* dst_mask */
402 false), /* pcrel_offset */
404 /* High 16 bits of displacement in global offset table. */
405 HOWTO (R_MIPS_GOT_HI16
, /* type */
407 2, /* size (0 = byte, 1 = short, 2 = long) */
409 false, /* pc_relative */
411 complain_overflow_dont
, /* complain_on_overflow */
412 bfd_elf_generic_reloc
, /* special_function */
413 "R_MIPS_GOT_HI16", /* name */
414 true, /* partial_inplace */
415 0x0000ffff, /* src_mask */
416 0x0000ffff, /* dst_mask */
417 false), /* pcrel_offset */
419 /* Low 16 bits of displacement in global offset table. */
420 HOWTO (R_MIPS_GOT_LO16
, /* type */
422 2, /* size (0 = byte, 1 = short, 2 = long) */
424 false, /* pc_relative */
426 complain_overflow_dont
, /* complain_on_overflow */
427 bfd_elf_generic_reloc
, /* special_function */
428 "R_MIPS_GOT_LO16", /* name */
429 true, /* partial_inplace */
430 0x0000ffff, /* src_mask */
431 0x0000ffff, /* dst_mask */
432 false), /* pcrel_offset */
434 /* 64 bit subtraction. Used in the N32 ABI. */
435 HOWTO (R_MIPS_SUB
, /* type */
437 4, /* size (0 = byte, 1 = short, 2 = long) */
439 false, /* pc_relative */
441 complain_overflow_dont
, /* complain_on_overflow */
442 bfd_elf_generic_reloc
, /* special_function */
443 "R_MIPS_SUB", /* name */
444 true, /* partial_inplace */
445 MINUS_ONE
, /* src_mask */
446 MINUS_ONE
, /* dst_mask */
447 false), /* pcrel_offset */
449 /* Used to cause the linker to insert and delete instructions? */
450 EMPTY_HOWTO (R_MIPS_INSERT_A
),
451 EMPTY_HOWTO (R_MIPS_INSERT_B
),
452 EMPTY_HOWTO (R_MIPS_DELETE
),
454 /* Get the higher value of a 64 bit addend. */
455 HOWTO (R_MIPS_HIGHER
, /* type */
457 2, /* size (0 = byte, 1 = short, 2 = long) */
459 false, /* pc_relative */
461 complain_overflow_dont
, /* complain_on_overflow */
462 bfd_elf_generic_reloc
, /* special_function */
463 "R_MIPS_HIGHER", /* name */
464 true, /* partial_inplace */
465 0x0000ffff, /* src_mask */
466 0x0000ffff, /* dst_mask */
467 false), /* pcrel_offset */
469 /* Get the highest value of a 64 bit addend. */
470 HOWTO (R_MIPS_HIGHEST
, /* type */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
474 false, /* pc_relative */
476 complain_overflow_dont
, /* complain_on_overflow */
477 bfd_elf_generic_reloc
, /* special_function */
478 "R_MIPS_HIGHEST", /* name */
479 true, /* partial_inplace */
480 0x0000ffff, /* src_mask */
481 0x0000ffff, /* dst_mask */
482 false), /* pcrel_offset */
484 /* High 16 bits of displacement in global offset table. */
485 HOWTO (R_MIPS_CALL_HI16
, /* type */
487 2, /* size (0 = byte, 1 = short, 2 = long) */
489 false, /* pc_relative */
491 complain_overflow_dont
, /* complain_on_overflow */
492 bfd_elf_generic_reloc
, /* special_function */
493 "R_MIPS_CALL_HI16", /* name */
494 true, /* partial_inplace */
495 0x0000ffff, /* src_mask */
496 0x0000ffff, /* dst_mask */
497 false), /* pcrel_offset */
499 /* Low 16 bits of displacement in global offset table. */
500 HOWTO (R_MIPS_CALL_LO16
, /* type */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
504 false, /* pc_relative */
506 complain_overflow_dont
, /* complain_on_overflow */
507 bfd_elf_generic_reloc
, /* special_function */
508 "R_MIPS_CALL_LO16", /* name */
509 true, /* partial_inplace */
510 0x0000ffff, /* src_mask */
511 0x0000ffff, /* dst_mask */
512 false), /* pcrel_offset */
514 /* Section displacement. */
515 HOWTO (R_MIPS_SCN_DISP
, /* type */
517 2, /* size (0 = byte, 1 = short, 2 = long) */
519 false, /* pc_relative */
521 complain_overflow_dont
, /* complain_on_overflow */
522 bfd_elf_generic_reloc
, /* special_function */
523 "R_MIPS_SCN_DISP", /* name */
524 true, /* partial_inplace */
525 0xffffffff, /* src_mask */
526 0xffffffff, /* dst_mask */
527 false), /* pcrel_offset */
529 EMPTY_HOWTO (R_MIPS_REL16
),
530 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE
),
531 EMPTY_HOWTO (R_MIPS_PJUMP
),
532 EMPTY_HOWTO (R_MIPS_RELGOT
),
534 /* Protected jump conversion. This is an optimization hint. No
535 relocation is required for correctness. */
536 HOWTO (R_MIPS_JALR
, /* type */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
540 false, /* pc_relative */
542 complain_overflow_dont
, /* complain_on_overflow */
543 bfd_elf_generic_reloc
, /* special_function */
544 "R_MIPS_JALR", /* name */
545 false, /* partial_inplace */
546 0x00000000, /* src_mask */
547 0x00000000, /* dst_mask */
548 false), /* pcrel_offset */
551 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
552 is a hack to make the linker think that we need 64 bit values. */
553 static reloc_howto_type elf_mips_ctor64_howto
=
554 HOWTO (R_MIPS_64
, /* type */
556 4, /* size (0 = byte, 1 = short, 2 = long) */
558 false, /* pc_relative */
560 complain_overflow_signed
, /* complain_on_overflow */
561 mips32_64bit_reloc
, /* special_function */
562 "R_MIPS_64", /* name */
563 true, /* partial_inplace */
564 0xffffffff, /* src_mask */
565 0xffffffff, /* dst_mask */
566 false); /* pcrel_offset */
568 /* The reloc used for the mips16 jump instruction. */
569 static reloc_howto_type elf_mips16_jump_howto
=
570 HOWTO (R_MIPS16_26
, /* type */
572 2, /* size (0 = byte, 1 = short, 2 = long) */
574 false, /* pc_relative */
576 complain_overflow_dont
, /* complain_on_overflow */
577 /* This needs complex overflow
578 detection, because the upper four
579 bits must match the PC. */
580 mips16_jump_reloc
, /* special_function */
581 "R_MIPS16_26", /* name */
582 true, /* partial_inplace */
583 0x3ffffff, /* src_mask */
584 0x3ffffff, /* dst_mask */
585 false); /* pcrel_offset */
587 /* The reloc used for the mips16 gprel instruction. */
588 static reloc_howto_type elf_mips16_gprel_howto
=
589 HOWTO (R_MIPS16_GPREL
, /* type */
591 2, /* size (0 = byte, 1 = short, 2 = long) */
593 false, /* pc_relative */
595 complain_overflow_signed
, /* complain_on_overflow */
596 mips16_gprel_reloc
, /* special_function */
597 "R_MIPS16_GPREL", /* name */
598 true, /* partial_inplace */
599 0x07ff001f, /* src_mask */
600 0x07ff001f, /* dst_mask */
601 false); /* pcrel_offset */
603 /* GNU extensions for embedded-pic. */
604 /* High 16 bits of symbol value, pc-relative. */
605 static reloc_howto_type elf_mips_gnu_rel_hi16
=
606 HOWTO (R_MIPS_GNU_REL_HI16
, /* type */
608 2, /* size (0 = byte, 1 = short, 2 = long) */
610 true, /* pc_relative */
612 complain_overflow_dont
, /* complain_on_overflow */
613 mips_elf_hi16_reloc
, /* special_function */
614 "R_MIPS_GNU_REL_HI16", /* name */
615 true, /* partial_inplace */
616 0xffff, /* src_mask */
617 0xffff, /* dst_mask */
618 true); /* pcrel_offset */
620 /* Low 16 bits of symbol value, pc-relative. */
621 static reloc_howto_type elf_mips_gnu_rel_lo16
=
622 HOWTO (R_MIPS_GNU_REL_LO16
, /* type */
624 2, /* size (0 = byte, 1 = short, 2 = long) */
626 true, /* pc_relative */
628 complain_overflow_dont
, /* complain_on_overflow */
629 mips_elf_lo16_reloc
, /* special_function */
630 "R_MIPS_GNU_REL_LO16", /* name */
631 true, /* partial_inplace */
632 0xffff, /* src_mask */
633 0xffff, /* dst_mask */
634 true); /* pcrel_offset */
636 /* 16 bit offset for pc-relative branches. */
637 static reloc_howto_type elf_mips_gnu_rel16_s2
=
638 HOWTO (R_MIPS_GNU_REL16_S2
, /* type */
640 2, /* size (0 = byte, 1 = short, 2 = long) */
642 true, /* pc_relative */
644 complain_overflow_signed
, /* complain_on_overflow */
645 bfd_elf_generic_reloc
, /* special_function */
646 "R_MIPS_GNU_REL16_S2", /* name */
647 true, /* partial_inplace */
648 0xffff, /* src_mask */
649 0xffff, /* dst_mask */
650 true); /* pcrel_offset */
652 /* 64 bit pc-relative. */
653 static reloc_howto_type elf_mips_gnu_pcrel64
=
654 HOWTO (R_MIPS_PC64
, /* type */
656 4, /* size (0 = byte, 1 = short, 2 = long) */
658 true, /* pc_relative */
660 complain_overflow_signed
, /* complain_on_overflow */
661 bfd_elf_generic_reloc
, /* special_function */
662 "R_MIPS_PC64", /* name */
663 true, /* partial_inplace */
664 MINUS_ONE
, /* src_mask */
665 MINUS_ONE
, /* dst_mask */
666 true); /* pcrel_offset */
668 /* 32 bit pc-relative. */
669 static reloc_howto_type elf_mips_gnu_pcrel32
=
670 HOWTO (R_MIPS_PC32
, /* type */
672 2, /* size (0 = byte, 1 = short, 2 = long) */
674 true, /* pc_relative */
676 complain_overflow_signed
, /* complain_on_overflow */
677 bfd_elf_generic_reloc
, /* special_function */
678 "R_MIPS_PC32", /* name */
679 true, /* partial_inplace */
680 0xffffffff, /* src_mask */
681 0xffffffff, /* dst_mask */
682 true); /* pcrel_offset */
684 /* GNU extension to record C++ vtable hierarchy */
685 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
686 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
688 2, /* size (0 = byte, 1 = short, 2 = long) */
690 false, /* pc_relative */
692 complain_overflow_dont
, /* complain_on_overflow */
693 NULL
, /* special_function */
694 "R_MIPS_GNU_VTINHERIT", /* name */
695 false, /* partial_inplace */
698 false); /* pcrel_offset */
700 /* GNU extension to record C++ vtable member usage */
701 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
702 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
704 2, /* size (0 = byte, 1 = short, 2 = long) */
706 false, /* pc_relative */
708 complain_overflow_dont
, /* complain_on_overflow */
709 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
710 "R_MIPS_GNU_VTENTRY", /* name */
711 false, /* partial_inplace */
714 false); /* pcrel_offset */
716 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
717 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
718 the HI16. Here we just save the information we need; we do the
719 actual relocation when we see the LO16.
721 MIPS ELF requires that the LO16 immediately follow the HI16. As a
722 GNU extension, for non-pc-relative relocations, we permit an
723 arbitrary number of HI16 relocs to be associated with a single LO16
724 reloc. This extension permits gcc to output the HI and LO relocs
727 This cannot be done for PC-relative relocations because both the HI16
728 and LO16 parts of the relocations must be done relative to the LO16
729 part, and there can be carry to or borrow from the HI16 part. */
733 struct mips_hi16
*next
;
738 /* FIXME: This should not be a static variable. */
740 static struct mips_hi16
*mips_hi16_list
;
742 static bfd_reloc_status_type
743 mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
744 output_bfd
, error_message
)
745 bfd
*abfd ATTRIBUTE_UNUSED
;
746 arelent
*reloc_entry
;
749 asection
*input_section
;
751 char **error_message
;
753 bfd_reloc_status_type ret
;
757 /* If we're relocating, and this is an external symbol, we don't want
758 to change anything. */
759 if (output_bfd
!= (bfd
*) NULL
760 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
761 && reloc_entry
->addend
== 0)
763 reloc_entry
->address
+= input_section
->output_offset
;
769 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
771 boolean relocateable
;
774 if (ret
== bfd_reloc_undefined
)
777 if (output_bfd
!= NULL
)
781 relocateable
= false;
782 output_bfd
= symbol
->section
->output_section
->owner
;
785 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
787 if (ret
!= bfd_reloc_ok
)
790 relocation
= gp
- reloc_entry
->address
;
794 if (bfd_is_und_section (symbol
->section
)
795 && output_bfd
== (bfd
*) NULL
)
796 ret
= bfd_reloc_undefined
;
798 if (bfd_is_com_section (symbol
->section
))
801 relocation
= symbol
->value
;
804 relocation
+= symbol
->section
->output_section
->vma
;
805 relocation
+= symbol
->section
->output_offset
;
806 relocation
+= reloc_entry
->addend
;
808 if (reloc_entry
->address
> input_section
->_cooked_size
)
809 return bfd_reloc_outofrange
;
811 /* Save the information, and let LO16 do the actual relocation. */
812 n
= (struct mips_hi16
*) bfd_malloc ((bfd_size_type
) sizeof *n
);
814 return bfd_reloc_outofrange
;
815 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
816 n
->addend
= relocation
;
817 n
->next
= mips_hi16_list
;
820 if (output_bfd
!= (bfd
*) NULL
)
821 reloc_entry
->address
+= input_section
->output_offset
;
826 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
827 inplace relocation; this function exists in order to do the
828 R_MIPS_HI16 relocation described above. */
830 static bfd_reloc_status_type
831 mips_elf_lo16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
832 output_bfd
, error_message
)
834 arelent
*reloc_entry
;
837 asection
*input_section
;
839 char **error_message
;
841 arelent gp_disp_relent
;
843 if (mips_hi16_list
!= NULL
)
853 struct mips_hi16
*next
;
855 /* Do the HI16 relocation. Note that we actually don't need
856 to know anything about the LO16 itself, except where to
857 find the low 16 bits of the addend needed by the LO16. */
858 insn
= bfd_get_32 (abfd
, l
->addr
);
859 vallo
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
861 /* The low order 16 bits are always treated as a signed
863 vallo
= ((vallo
& 0xffff) ^ 0x8000) - 0x8000;
864 val
= ((insn
& 0xffff) << 16) + vallo
;
867 /* If PC-relative, we need to subtract out the address of the LO
868 half of the HI/LO. (The actual relocation is relative
869 to that instruction.) */
870 if (reloc_entry
->howto
->pc_relative
)
871 val
-= reloc_entry
->address
;
873 /* At this point, "val" has the value of the combined HI/LO
874 pair. If the low order 16 bits (which will be used for
875 the LO16 insn) are negative, then we will need an
876 adjustment for the high order 16 bits. */
878 val
= (val
>> 16) & 0xffff;
880 insn
&= ~ (bfd_vma
) 0xffff;
882 bfd_put_32 (abfd
, (bfd_vma
) insn
, l
->addr
);
884 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
886 gp_disp_relent
= *reloc_entry
;
887 reloc_entry
= &gp_disp_relent
;
888 reloc_entry
->addend
= l
->addend
;
896 mips_hi16_list
= NULL
;
898 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
900 bfd_reloc_status_type ret
;
901 bfd_vma gp
, relocation
;
903 /* FIXME: Does this case ever occur? */
905 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
906 if (ret
!= bfd_reloc_ok
)
909 relocation
= gp
- reloc_entry
->address
;
910 relocation
+= symbol
->section
->output_section
->vma
;
911 relocation
+= symbol
->section
->output_offset
;
912 relocation
+= reloc_entry
->addend
;
914 if (reloc_entry
->address
> input_section
->_cooked_size
)
915 return bfd_reloc_outofrange
;
917 gp_disp_relent
= *reloc_entry
;
918 reloc_entry
= &gp_disp_relent
;
919 reloc_entry
->addend
= relocation
- 4;
922 /* Now do the LO16 reloc in the usual way. */
923 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
924 input_section
, output_bfd
, error_message
);
927 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
928 table used for PIC code. If the symbol is an external symbol, the
929 instruction is modified to contain the offset of the appropriate
930 entry in the global offset table. If the symbol is a section
931 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
932 addends are combined to form the real addend against the section
933 symbol; the GOT16 is modified to contain the offset of an entry in
934 the global offset table, and the LO16 is modified to offset it
935 appropriately. Thus an offset larger than 16 bits requires a
936 modified value in the global offset table.
938 This implementation suffices for the assembler, but the linker does
939 not yet know how to create global offset tables. */
941 static bfd_reloc_status_type
942 mips_elf_got16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
943 output_bfd
, error_message
)
945 arelent
*reloc_entry
;
948 asection
*input_section
;
950 char **error_message
;
952 /* If we're relocating, and this is an external symbol, we don't want
953 to change anything. */
954 if (output_bfd
!= (bfd
*) NULL
955 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
956 && reloc_entry
->addend
== 0)
958 reloc_entry
->address
+= input_section
->output_offset
;
962 /* If we're relocating, and this is a local symbol, we can handle it
964 if (output_bfd
!= (bfd
*) NULL
965 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
966 return mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
967 input_section
, output_bfd
, error_message
);
972 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
973 dangerous relocation. */
976 mips_elf_assign_gp (output_bfd
, pgp
)
984 /* If we've already figured out what GP will be, just return it. */
985 *pgp
= _bfd_get_gp_value (output_bfd
);
989 count
= bfd_get_symcount (output_bfd
);
990 sym
= bfd_get_outsymbols (output_bfd
);
992 /* The linker script will have created a symbol named `_gp' with the
993 appropriate value. */
994 if (sym
== (asymbol
**) NULL
)
998 for (i
= 0; i
< count
; i
++, sym
++)
1000 register const char *name
;
1002 name
= bfd_asymbol_name (*sym
);
1003 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1005 *pgp
= bfd_asymbol_value (*sym
);
1006 _bfd_set_gp_value (output_bfd
, *pgp
);
1014 /* Only get the error once. */
1016 _bfd_set_gp_value (output_bfd
, *pgp
);
1023 /* We have to figure out the gp value, so that we can adjust the
1024 symbol value correctly. We look up the symbol _gp in the output
1025 BFD. If we can't find it, we're stuck. We cache it in the ELF
1026 target data. We don't need to adjust the symbol value for an
1027 external symbol if we are producing relocateable output. */
1029 static bfd_reloc_status_type
1030 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1033 boolean relocateable
;
1034 char **error_message
;
1037 if (bfd_is_und_section (symbol
->section
)
1041 return bfd_reloc_undefined
;
1044 *pgp
= _bfd_get_gp_value (output_bfd
);
1047 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1051 /* Make up a value. */
1052 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1053 _bfd_set_gp_value (output_bfd
, *pgp
);
1055 else if (!mips_elf_assign_gp (output_bfd
, pgp
))
1058 (char *) _("GP relative relocation when _gp not defined");
1059 return bfd_reloc_dangerous
;
1063 return bfd_reloc_ok
;
1066 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1067 become the offset from the gp register. This function also handles
1068 R_MIPS_LITERAL relocations, although those can be handled more
1069 cleverly because the entries in the .lit8 and .lit4 sections can be
1072 bfd_reloc_status_type
1073 _bfd_mips_elf32_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1074 output_bfd
, error_message
)
1076 arelent
*reloc_entry
;
1079 asection
*input_section
;
1081 char **error_message
;
1083 boolean relocateable
;
1084 bfd_reloc_status_type ret
;
1087 /* If we're relocating, and this is an external symbol with no
1088 addend, we don't want to change anything. We will only have an
1089 addend if this is a newly created reloc, not read from an ELF
1091 if (output_bfd
!= (bfd
*) NULL
1092 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1093 && reloc_entry
->addend
== 0)
1095 reloc_entry
->address
+= input_section
->output_offset
;
1096 return bfd_reloc_ok
;
1099 if (output_bfd
!= (bfd
*) NULL
)
1100 relocateable
= true;
1103 relocateable
= false;
1104 output_bfd
= symbol
->section
->output_section
->owner
;
1107 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1109 if (ret
!= bfd_reloc_ok
)
1112 return _bfd_mips_elf_gprel16_with_gp (abfd
, symbol
, reloc_entry
,
1113 input_section
, relocateable
,
1117 /* Do a R_MIPS_GPREL32 relocation. This is a 32 bit value which must
1118 become the offset from the gp register. */
1120 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1121 arelent
*, asection
*,
1122 boolean
, PTR
, bfd_vma
));
1124 static bfd_reloc_status_type
1125 mips_elf_gprel32_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1126 output_bfd
, error_message
)
1128 arelent
*reloc_entry
;
1131 asection
*input_section
;
1133 char **error_message
;
1135 boolean relocateable
;
1136 bfd_reloc_status_type ret
;
1139 /* If we're relocating, and this is an external symbol with no
1140 addend, we don't want to change anything. We will only have an
1141 addend if this is a newly created reloc, not read from an ELF
1143 if (output_bfd
!= (bfd
*) NULL
1144 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1145 && reloc_entry
->addend
== 0)
1147 *error_message
= (char *)
1148 _("32bits gp relative relocation occurs for an external symbol");
1149 return bfd_reloc_outofrange
;
1152 if (output_bfd
!= (bfd
*) NULL
)
1154 relocateable
= true;
1155 gp
= _bfd_get_gp_value (output_bfd
);
1159 relocateable
= false;
1160 output_bfd
= symbol
->section
->output_section
->owner
;
1162 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1163 error_message
, &gp
);
1164 if (ret
!= bfd_reloc_ok
)
1168 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1169 relocateable
, data
, gp
);
1172 static bfd_reloc_status_type
1173 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1177 arelent
*reloc_entry
;
1178 asection
*input_section
;
1179 boolean relocateable
;
1186 if (bfd_is_com_section (symbol
->section
))
1189 relocation
= symbol
->value
;
1191 relocation
+= symbol
->section
->output_section
->vma
;
1192 relocation
+= symbol
->section
->output_offset
;
1194 if (reloc_entry
->address
> input_section
->_cooked_size
)
1195 return bfd_reloc_outofrange
;
1197 if (reloc_entry
->howto
->src_mask
== 0)
1199 /* This case arises with the 64-bit MIPS ELF ABI. */
1203 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1205 /* Set val to the offset into the section or symbol. */
1206 val
+= reloc_entry
->addend
;
1208 /* Adjust val for the final section location and GP value. If we
1209 are producing relocateable output, we don't want to do this for
1210 an external symbol. */
1212 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1213 val
+= relocation
- gp
;
1215 bfd_put_32 (abfd
, (bfd_vma
) val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1218 reloc_entry
->address
+= input_section
->output_offset
;
1220 return bfd_reloc_ok
;
1223 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1224 generated when addresses are 64 bits. The upper 32 bits are a simple
1227 static bfd_reloc_status_type
1228 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1229 output_bfd
, error_message
)
1231 arelent
*reloc_entry
;
1234 asection
*input_section
;
1236 char **error_message
;
1238 bfd_reloc_status_type r
;
1243 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1244 input_section
, output_bfd
, error_message
);
1245 if (r
!= bfd_reloc_continue
)
1248 /* Do a normal 32 bit relocation on the lower 32 bits. */
1249 reloc32
= *reloc_entry
;
1250 if (bfd_big_endian (abfd
))
1251 reloc32
.address
+= 4;
1252 reloc32
.howto
= &elf_mips_howto_table_rel
[R_MIPS_32
];
1253 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1254 output_bfd
, error_message
);
1256 /* Sign extend into the upper 32 bits. */
1257 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1258 if ((val
& 0x80000000) != 0)
1262 addr
= reloc_entry
->address
;
1263 if (bfd_little_endian (abfd
))
1265 bfd_put_32 (abfd
, (bfd_vma
) val
, (bfd_byte
*) data
+ addr
);
1270 /* Handle a mips16 jump. */
1272 static bfd_reloc_status_type
1273 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1274 output_bfd
, error_message
)
1275 bfd
*abfd ATTRIBUTE_UNUSED
;
1276 arelent
*reloc_entry
;
1278 PTR data ATTRIBUTE_UNUSED
;
1279 asection
*input_section
;
1281 char **error_message ATTRIBUTE_UNUSED
;
1283 if (output_bfd
!= (bfd
*) NULL
1284 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1285 && reloc_entry
->addend
== 0)
1287 reloc_entry
->address
+= input_section
->output_offset
;
1288 return bfd_reloc_ok
;
1293 static boolean warned
;
1296 (*_bfd_error_handler
)
1297 (_("Linking mips16 objects into %s format is not supported"),
1298 bfd_get_target (input_section
->output_section
->owner
));
1302 return bfd_reloc_undefined
;
1305 /* Handle a mips16 GP relative reloc. */
1307 static bfd_reloc_status_type
1308 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1309 output_bfd
, error_message
)
1311 arelent
*reloc_entry
;
1314 asection
*input_section
;
1316 char **error_message
;
1318 boolean relocateable
;
1319 bfd_reloc_status_type ret
;
1321 unsigned short extend
, insn
;
1322 unsigned long final
;
1324 /* If we're relocating, and this is an external symbol with no
1325 addend, we don't want to change anything. We will only have an
1326 addend if this is a newly created reloc, not read from an ELF
1328 if (output_bfd
!= NULL
1329 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1330 && reloc_entry
->addend
== 0)
1332 reloc_entry
->address
+= input_section
->output_offset
;
1333 return bfd_reloc_ok
;
1336 if (output_bfd
!= NULL
)
1337 relocateable
= true;
1340 relocateable
= false;
1341 output_bfd
= symbol
->section
->output_section
->owner
;
1344 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1346 if (ret
!= bfd_reloc_ok
)
1349 if (reloc_entry
->address
> input_section
->_cooked_size
)
1350 return bfd_reloc_outofrange
;
1352 /* Pick up the mips16 extend instruction and the real instruction. */
1353 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1354 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1356 /* Stuff the current addend back as a 32 bit value, do the usual
1357 relocation, and then clean up. */
1359 (bfd_vma
) (((extend
& 0x1f) << 11)
1362 (bfd_byte
*) data
+ reloc_entry
->address
);
1364 ret
= _bfd_mips_elf_gprel16_with_gp (abfd
, symbol
, reloc_entry
,
1365 input_section
, relocateable
, data
, gp
);
1367 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1369 (bfd_vma
) ((extend
& 0xf800)
1370 | ((final
>> 11) & 0x1f)
1372 (bfd_byte
*) data
+ reloc_entry
->address
);
1374 (bfd_vma
) ((insn
& 0xffe0)
1376 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1381 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1383 struct elf_reloc_map
{
1384 bfd_reloc_code_real_type bfd_val
;
1385 enum elf_mips_reloc_type elf_val
;
1388 static const struct elf_reloc_map mips_reloc_map
[] =
1390 { BFD_RELOC_NONE
, R_MIPS_NONE
},
1391 { BFD_RELOC_16
, R_MIPS_16
},
1392 { BFD_RELOC_32
, R_MIPS_32
},
1393 /* There is no BFD reloc for R_MIPS_REL32. */
1394 { BFD_RELOC_64
, R_MIPS_64
},
1395 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1396 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1397 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1398 { BFD_RELOC_GPREL16
, R_MIPS_GPREL16
},
1399 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1400 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1401 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1402 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1403 { BFD_RELOC_GPREL32
, R_MIPS_GPREL32
},
1404 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1405 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1406 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1407 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1408 { BFD_RELOC_MIPS_SUB
, R_MIPS_SUB
},
1409 { BFD_RELOC_MIPS_GOT_PAGE
, R_MIPS_GOT_PAGE
},
1410 { BFD_RELOC_MIPS_GOT_OFST
, R_MIPS_GOT_OFST
},
1411 { BFD_RELOC_MIPS_GOT_DISP
, R_MIPS_GOT_DISP
}
1414 /* Given a BFD reloc type, return a howto structure. */
1416 static reloc_howto_type
*
1417 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1419 bfd_reloc_code_real_type code
;
1422 reloc_howto_type
*howto_table
= elf_mips_howto_table_rel
;
1424 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
);
1427 if (mips_reloc_map
[i
].bfd_val
== code
)
1428 return &howto_table
[(int) mips_reloc_map
[i
].elf_val
];
1434 bfd_set_error (bfd_error_bad_value
);
1437 case BFD_RELOC_CTOR
:
1438 /* We need to handle BFD_RELOC_CTOR specially.
1439 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1440 size of addresses on this architecture. */
1441 if (bfd_arch_bits_per_address (abfd
) == 32)
1442 return &howto_table
[(int) R_MIPS_32
];
1444 return &elf_mips_ctor64_howto
;
1446 case BFD_RELOC_MIPS16_JMP
:
1447 return &elf_mips16_jump_howto
;
1448 case BFD_RELOC_MIPS16_GPREL
:
1449 return &elf_mips16_gprel_howto
;
1450 case BFD_RELOC_VTABLE_INHERIT
:
1451 return &elf_mips_gnu_vtinherit_howto
;
1452 case BFD_RELOC_VTABLE_ENTRY
:
1453 return &elf_mips_gnu_vtentry_howto
;
1454 case BFD_RELOC_PCREL_HI16_S
:
1455 return &elf_mips_gnu_rel_hi16
;
1456 case BFD_RELOC_PCREL_LO16
:
1457 return &elf_mips_gnu_rel_lo16
;
1458 case BFD_RELOC_16_PCREL_S2
:
1459 return &elf_mips_gnu_rel16_s2
;
1460 case BFD_RELOC_64_PCREL
:
1461 return &elf_mips_gnu_pcrel64
;
1462 case BFD_RELOC_32_PCREL
:
1463 return &elf_mips_gnu_pcrel32
;
1467 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
1469 static reloc_howto_type
*
1470 mips_elf32_rtype_to_howto (r_type
, rela_p
)
1471 unsigned int r_type
;
1472 boolean rela_p ATTRIBUTE_UNUSED
;
1477 return &elf_mips16_jump_howto
;
1478 case R_MIPS16_GPREL
:
1479 return &elf_mips16_gprel_howto
;
1480 case R_MIPS_GNU_VTINHERIT
:
1481 return &elf_mips_gnu_vtinherit_howto
;
1482 case R_MIPS_GNU_VTENTRY
:
1483 return &elf_mips_gnu_vtentry_howto
;
1484 case R_MIPS_GNU_REL_HI16
:
1485 return &elf_mips_gnu_rel_hi16
;
1486 case R_MIPS_GNU_REL_LO16
:
1487 return &elf_mips_gnu_rel_lo16
;
1488 case R_MIPS_GNU_REL16_S2
:
1489 return &elf_mips_gnu_rel16_s2
;
1491 return &elf_mips_gnu_pcrel64
;
1493 return &elf_mips_gnu_pcrel32
;
1495 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1496 return &elf_mips_howto_table_rel
[r_type
];
1500 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
1503 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1506 Elf32_Internal_Rel
*dst
;
1508 unsigned int r_type
;
1510 r_type
= ELF32_R_TYPE (dst
->r_info
);
1511 cache_ptr
->howto
= mips_elf32_rtype_to_howto (r_type
, false);
1513 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1514 value for the object file. We get the addend now, rather than
1515 when we do the relocation, because the symbol manipulations done
1516 by the linker may cause us to lose track of the input BFD. */
1517 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1518 && (r_type
== (unsigned int) R_MIPS_GPREL16
1519 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1520 cache_ptr
->addend
= elf_gp (abfd
);
1523 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
1526 mips_info_to_howto_rela (abfd
, cache_ptr
, dst
)
1529 Elf32_Internal_Rela
*dst
;
1531 /* Since an Elf32_Internal_Rel is an initial prefix of an
1532 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
1534 mips_info_to_howto_rel (abfd
, cache_ptr
, (Elf32_Internal_Rel
*) dst
);
1536 /* If we ever need to do any extra processing with dst->r_addend
1537 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
1540 /* Determine whether a symbol is global for the purposes of splitting
1541 the symbol table into global symbols and local symbols. At least
1542 on Irix 5, this split must be between section symbols and all other
1543 symbols. On most ELF targets the split is between static symbols
1544 and externally visible symbols. */
1547 mips_elf_sym_is_global (abfd
, sym
)
1548 bfd
*abfd ATTRIBUTE_UNUSED
;
1551 if (SGI_COMPAT (abfd
))
1552 return (sym
->flags
& BSF_SECTION_SYM
) == 0;
1554 return ((sym
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
1555 || bfd_is_und_section (bfd_get_section (sym
))
1556 || bfd_is_com_section (bfd_get_section (sym
)));
1559 /* Set the right machine number for a MIPS ELF file. */
1562 mips_elf32_object_p (abfd
)
1567 /* Irix 5 and 6 are broken. Object file symbol tables are not always
1568 sorted correctly such that local symbols precede global symbols,
1569 and the sh_info field in the symbol table is not always right. */
1570 if (SGI_COMPAT (abfd
))
1571 elf_bad_symtab (abfd
) = true;
1573 if (ABI_N32_P (abfd
))
1576 mach
= _bfd_elf_mips_mach (elf_elfheader (abfd
)->e_flags
);
1577 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, mach
);
1582 /* MIPS ELF local labels start with '$', not 'L'. */
1585 mips_elf_is_local_label_name (abfd
, name
)
1592 /* On Irix 6, the labels go back to starting with '.', so we accept
1593 the generic ELF local label syntax as well. */
1594 return _bfd_elf_is_local_label_name (abfd
, name
);
1597 /* Support for core dump NOTE sections. */
1599 elf32_mips_grok_prstatus (abfd
, note
)
1601 Elf_Internal_Note
*note
;
1604 unsigned int raw_size
;
1606 switch (note
->descsz
)
1611 case 256: /* Linux/MIPS */
1613 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1616 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1625 /* Make a ".reg/999" section. */
1626 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1627 raw_size
, note
->descpos
+ offset
);
1631 elf32_mips_grok_psinfo (abfd
, note
)
1633 Elf_Internal_Note
*note
;
1635 switch (note
->descsz
)
1640 case 128: /* Linux/MIPS elf_prpsinfo */
1641 elf_tdata (abfd
)->core_program
1642 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
1643 elf_tdata (abfd
)->core_command
1644 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
1647 /* Note that for some reason, a spurious space is tacked
1648 onto the end of the args in some (at least one anyway)
1649 implementations, so strip it off if it exists. */
1652 char *command
= elf_tdata (abfd
)->core_command
;
1653 int n
= strlen (command
);
1655 if (0 < n
&& command
[n
- 1] == ' ')
1656 command
[n
- 1] = '\0';
1662 /* Depending on the target vector we generate some version of Irix
1663 executables or "normal" MIPS ELF ABI executables. */
1664 static irix_compat_t
1665 elf32_mips_irix_compat (abfd
)
1668 if ((abfd
->xvec
== &bfd_elf32_bigmips_vec
)
1669 || (abfd
->xvec
== &bfd_elf32_littlemips_vec
))
1675 /* Given a data section and an in-memory embedded reloc section, store
1676 relocation information into the embedded reloc section which can be
1677 used at runtime to relocate the data section. This is called by the
1678 linker when the --embedded-relocs switch is used. This is called
1679 after the add_symbols entry point has been called for all the
1680 objects, and before the final_link entry point is called. */
1683 bfd_mips_elf32_create_embedded_relocs (abfd
, info
, datasec
, relsec
, errmsg
)
1685 struct bfd_link_info
*info
;
1690 Elf_Internal_Shdr
*symtab_hdr
;
1691 Elf_Internal_Sym
*isymbuf
= NULL
;
1692 Elf_Internal_Rela
*internal_relocs
= NULL
;
1693 Elf_Internal_Rela
*irel
, *irelend
;
1696 BFD_ASSERT (! info
->relocateable
);
1700 if (datasec
->reloc_count
== 0)
1703 /* Read this BFD's symbols if we haven't done so already, or get the cached
1704 copy if it exists. */
1705 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1706 if (symtab_hdr
->sh_info
!= 0)
1708 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1709 if (isymbuf
== NULL
)
1710 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
1711 symtab_hdr
->sh_info
, 0,
1713 if (isymbuf
== NULL
)
1717 /* Get a copy of the native relocations. */
1718 internal_relocs
= (_bfd_elf32_link_read_relocs
1719 (abfd
, datasec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
1720 info
->keep_memory
));
1721 if (internal_relocs
== NULL
)
1724 relsec
->contents
= (bfd_byte
*) bfd_alloc (abfd
, datasec
->reloc_count
* 12);
1725 if (relsec
->contents
== NULL
)
1728 p
= relsec
->contents
;
1730 irelend
= internal_relocs
+ datasec
->reloc_count
;
1732 for (irel
= internal_relocs
; irel
< irelend
; irel
++, p
+= 12)
1734 asection
*targetsec
;
1736 /* We are going to write a four byte longword into the runtime
1737 reloc section. The longword will be the address in the data
1738 section which must be relocated. It is followed by the name
1739 of the target section NUL-padded or truncated to 8
1742 /* We can only relocate absolute longword relocs at run time. */
1743 if ((ELF32_R_TYPE (irel
->r_info
) != (int) R_MIPS_32
) &&
1744 (ELF32_R_TYPE (irel
->r_info
) != (int) R_MIPS_64
))
1746 *errmsg
= _("unsupported reloc type");
1747 bfd_set_error (bfd_error_bad_value
);
1750 /* Get the target section referred to by the reloc. */
1751 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
1753 Elf_Internal_Sym
*isym
;
1755 /* A local symbol. */
1756 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
1757 targetsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1762 struct elf_link_hash_entry
*h
;
1764 /* An external symbol. */
1765 indx
= ELF32_R_SYM (irel
->r_info
);
1766 h
= elf_sym_hashes (abfd
)[indx
];
1769 For some reason, in certain programs, the symbol will
1770 not be in the hash table. It seems to happen when you
1771 declare a static table of pointers to const external structures.
1772 In this case, the relocs are relative to data, not
1773 text, so just treating it like an undefined link
1774 should be sufficient. */
1775 BFD_ASSERT(h
!= NULL
);
1776 if (h
->root
.type
== bfd_link_hash_defined
1777 || h
->root
.type
== bfd_link_hash_defweak
)
1778 targetsec
= h
->root
.u
.def
.section
;
1783 Set the low bit of the relocation offset if it's a MIPS64 reloc.
1784 Relocations will always be on (at least) 32-bit boundaries. */
1786 bfd_put_32 (abfd
, ((irel
->r_offset
+ datasec
->output_offset
) +
1787 ((ELF32_R_TYPE (irel
->r_info
) == (int) R_MIPS_64
) ? 1 : 0)),
1789 memset (p
+ 4, 0, 8);
1790 if (targetsec
!= NULL
)
1791 strncpy (p
+ 4, targetsec
->output_section
->name
, 8);
1794 if (internal_relocs
!= NULL
1795 && elf_section_data (datasec
)->relocs
!= internal_relocs
)
1796 free (internal_relocs
);
1798 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
1803 if (internal_relocs
!= NULL
1804 && elf_section_data (datasec
)->relocs
!= internal_relocs
)
1805 free (internal_relocs
);
1807 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
1812 /* ECOFF swapping routines. These are used when dealing with the
1813 .mdebug section, which is in the ECOFF debugging format. */
1814 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
= {
1815 /* Symbol table magic number. */
1817 /* Alignment of debugging information. E.g., 4. */
1819 /* Sizes of external symbolic information. */
1820 sizeof (struct hdr_ext
),
1821 sizeof (struct dnr_ext
),
1822 sizeof (struct pdr_ext
),
1823 sizeof (struct sym_ext
),
1824 sizeof (struct opt_ext
),
1825 sizeof (struct fdr_ext
),
1826 sizeof (struct rfd_ext
),
1827 sizeof (struct ext_ext
),
1828 /* Functions to swap in external symbolic data. */
1837 _bfd_ecoff_swap_tir_in
,
1838 _bfd_ecoff_swap_rndx_in
,
1839 /* Functions to swap out external symbolic data. */
1848 _bfd_ecoff_swap_tir_out
,
1849 _bfd_ecoff_swap_rndx_out
,
1850 /* Function to read in symbolic data. */
1851 _bfd_mips_elf_read_ecoff_info
1854 #define ELF_ARCH bfd_arch_mips
1855 #define ELF_MACHINE_CODE EM_MIPS
1857 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
1858 a value of 0x1000, and we are compatible. */
1859 #define ELF_MAXPAGESIZE 0x1000
1861 #define elf_backend_collect true
1862 #define elf_backend_type_change_ok true
1863 #define elf_backend_can_gc_sections true
1864 #define elf_info_to_howto mips_info_to_howto_rela
1865 #define elf_info_to_howto_rel mips_info_to_howto_rel
1866 #define elf_backend_sym_is_global mips_elf_sym_is_global
1867 #define elf_backend_object_p mips_elf32_object_p
1868 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
1869 #define elf_backend_section_processing _bfd_mips_elf_section_processing
1870 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
1871 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
1872 #define elf_backend_section_from_bfd_section \
1873 _bfd_mips_elf_section_from_bfd_section
1874 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
1875 #define elf_backend_link_output_symbol_hook \
1876 _bfd_mips_elf_link_output_symbol_hook
1877 #define elf_backend_create_dynamic_sections \
1878 _bfd_mips_elf_create_dynamic_sections
1879 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
1880 #define elf_backend_adjust_dynamic_symbol \
1881 _bfd_mips_elf_adjust_dynamic_symbol
1882 #define elf_backend_always_size_sections \
1883 _bfd_mips_elf_always_size_sections
1884 #define elf_backend_size_dynamic_sections \
1885 _bfd_mips_elf_size_dynamic_sections
1886 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
1887 #define elf_backend_finish_dynamic_symbol \
1888 _bfd_mips_elf_finish_dynamic_symbol
1889 #define elf_backend_finish_dynamic_sections \
1890 _bfd_mips_elf_finish_dynamic_sections
1891 #define elf_backend_final_write_processing \
1892 _bfd_mips_elf_final_write_processing
1893 #define elf_backend_additional_program_headers \
1894 _bfd_mips_elf_additional_program_headers
1895 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
1896 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
1897 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
1898 #define elf_backend_copy_indirect_symbol \
1899 _bfd_mips_elf_copy_indirect_symbol
1900 #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
1901 #define elf_backend_grok_prstatus elf32_mips_grok_prstatus
1902 #define elf_backend_grok_psinfo elf32_mips_grok_psinfo
1903 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
1905 #define elf_backend_got_header_size (4 * MIPS_RESERVED_GOTNO)
1906 #define elf_backend_plt_header_size 0
1907 #define elf_backend_may_use_rel_p 1
1908 #define elf_backend_may_use_rela_p 0
1909 #define elf_backend_default_use_rela_p 0
1910 #define elf_backend_sign_extend_vma true
1912 #define elf_backend_discard_info _bfd_mips_elf_discard_info
1913 #define elf_backend_ignore_discarded_relocs \
1914 _bfd_mips_elf_ignore_discarded_relocs
1915 #define elf_backend_mips_irix_compat elf32_mips_irix_compat
1916 #define elf_backend_mips_rtype_to_howto mips_elf32_rtype_to_howto
1917 #define bfd_elf32_bfd_is_local_label_name \
1918 mips_elf_is_local_label_name
1919 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
1920 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
1921 #define bfd_elf32_bfd_get_relocated_section_contents \
1922 _bfd_elf_mips_get_relocated_section_contents
1923 #define bfd_elf32_bfd_link_hash_table_create \
1924 _bfd_mips_elf_link_hash_table_create
1925 #define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
1926 #define bfd_elf32_bfd_merge_private_bfd_data \
1927 _bfd_mips_elf_merge_private_bfd_data
1928 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
1929 #define bfd_elf32_bfd_print_private_bfd_data \
1930 _bfd_mips_elf_print_private_bfd_data
1932 /* Support for SGI-ish mips targets. */
1933 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
1934 #define TARGET_LITTLE_NAME "elf32-littlemips"
1935 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
1936 #define TARGET_BIG_NAME "elf32-bigmips"
1938 #include "elf32-target.h"
1940 /* Support for traditional mips targets. */
1941 #define INCLUDED_TARGET_FILE /* More a type of flag. */
1943 #undef TARGET_LITTLE_SYM
1944 #undef TARGET_LITTLE_NAME
1945 #undef TARGET_BIG_SYM
1946 #undef TARGET_BIG_NAME
1948 #define TARGET_LITTLE_SYM bfd_elf32_tradlittlemips_vec
1949 #define TARGET_LITTLE_NAME "elf32-tradlittlemips"
1950 #define TARGET_BIG_SYM bfd_elf32_tradbigmips_vec
1951 #define TARGET_BIG_NAME "elf32-tradbigmips"
1953 /* Include the target file again for this target. */
1954 #include "elf32-target.h"