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 boolean elf32_mips_discard_info
84 PARAMS ((bfd
*, struct elf_reloc_cookie
*, struct bfd_link_info
*));
85 static boolean elf32_mips_write_section
86 PARAMS ((bfd
*, asection
*, bfd_byte
*));
87 static irix_compat_t elf32_mips_irix_compat
90 extern const bfd_target bfd_elf32_bigmips_vec
;
91 extern const bfd_target bfd_elf32_littlemips_vec
;
93 /* Nonzero if ABFD is using the N32 ABI. */
94 #define ABI_N32_P(abfd) \
95 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
97 /* Whether we are trying to be compatible with IRIX at all. */
98 #define SGI_COMPAT(abfd) \
99 (elf32_mips_irix_compat (abfd) != ict_none)
101 /* The number of local .got entries we reserve. */
102 #define MIPS_RESERVED_GOTNO (2)
104 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
105 from smaller values. Start with zero, widen, *then* decrement. */
106 #define MINUS_ONE (((bfd_vma)0) - 1)
108 /* The relocation table used for SHT_REL sections. */
110 static reloc_howto_type elf_mips_howto_table_rel
[] =
113 HOWTO (R_MIPS_NONE
, /* type */
115 0, /* size (0 = byte, 1 = short, 2 = long) */
117 false, /* pc_relative */
119 complain_overflow_dont
, /* complain_on_overflow */
120 bfd_elf_generic_reloc
, /* special_function */
121 "R_MIPS_NONE", /* name */
122 false, /* partial_inplace */
125 false), /* pcrel_offset */
127 /* 16 bit relocation. */
128 HOWTO (R_MIPS_16
, /* type */
130 2, /* size (0 = byte, 1 = short, 2 = long) */
132 false, /* pc_relative */
134 complain_overflow_signed
, /* complain_on_overflow */
135 bfd_elf_generic_reloc
, /* special_function */
136 "R_MIPS_16", /* name */
137 true, /* partial_inplace */
138 0x0000ffff, /* src_mask */
139 0x0000ffff, /* dst_mask */
140 false), /* pcrel_offset */
142 /* 32 bit relocation. */
143 HOWTO (R_MIPS_32
, /* type */
145 2, /* size (0 = byte, 1 = short, 2 = long) */
147 false, /* pc_relative */
149 complain_overflow_dont
, /* complain_on_overflow */
150 bfd_elf_generic_reloc
, /* special_function */
151 "R_MIPS_32", /* name */
152 true, /* partial_inplace */
153 0xffffffff, /* src_mask */
154 0xffffffff, /* dst_mask */
155 false), /* pcrel_offset */
157 /* 32 bit symbol relative relocation. */
158 HOWTO (R_MIPS_REL32
, /* type */
160 2, /* size (0 = byte, 1 = short, 2 = long) */
162 false, /* pc_relative */
164 complain_overflow_dont
, /* complain_on_overflow */
165 bfd_elf_generic_reloc
, /* special_function */
166 "R_MIPS_REL32", /* name */
167 true, /* partial_inplace */
168 0xffffffff, /* src_mask */
169 0xffffffff, /* dst_mask */
170 false), /* pcrel_offset */
172 /* 26 bit jump address. */
173 HOWTO (R_MIPS_26
, /* type */
175 2, /* size (0 = byte, 1 = short, 2 = long) */
177 false, /* pc_relative */
179 complain_overflow_dont
, /* complain_on_overflow */
180 /* This needs complex overflow
181 detection, because the upper four
182 bits must match the PC + 4. */
183 bfd_elf_generic_reloc
, /* special_function */
184 "R_MIPS_26", /* name */
185 true, /* partial_inplace */
186 0x03ffffff, /* src_mask */
187 0x03ffffff, /* dst_mask */
188 false), /* pcrel_offset */
190 /* High 16 bits of symbol value. */
191 HOWTO (R_MIPS_HI16
, /* type */
193 2, /* size (0 = byte, 1 = short, 2 = long) */
195 false, /* pc_relative */
197 complain_overflow_dont
, /* complain_on_overflow */
198 mips_elf_hi16_reloc
, /* special_function */
199 "R_MIPS_HI16", /* name */
200 true, /* partial_inplace */
201 0x0000ffff, /* src_mask */
202 0x0000ffff, /* dst_mask */
203 false), /* pcrel_offset */
205 /* Low 16 bits of symbol value. */
206 HOWTO (R_MIPS_LO16
, /* type */
208 2, /* size (0 = byte, 1 = short, 2 = long) */
210 false, /* pc_relative */
212 complain_overflow_dont
, /* complain_on_overflow */
213 mips_elf_lo16_reloc
, /* special_function */
214 "R_MIPS_LO16", /* name */
215 true, /* partial_inplace */
216 0x0000ffff, /* src_mask */
217 0x0000ffff, /* dst_mask */
218 false), /* pcrel_offset */
220 /* GP relative reference. */
221 HOWTO (R_MIPS_GPREL16
, /* type */
223 2, /* size (0 = byte, 1 = short, 2 = long) */
225 false, /* pc_relative */
227 complain_overflow_signed
, /* complain_on_overflow */
228 _bfd_mips_elf32_gprel16_reloc
, /* special_function */
229 "R_MIPS_GPREL16", /* name */
230 true, /* partial_inplace */
231 0x0000ffff, /* src_mask */
232 0x0000ffff, /* dst_mask */
233 false), /* pcrel_offset */
235 /* Reference to literal section. */
236 HOWTO (R_MIPS_LITERAL
, /* type */
238 2, /* size (0 = byte, 1 = short, 2 = long) */
240 false, /* pc_relative */
242 complain_overflow_signed
, /* complain_on_overflow */
243 _bfd_mips_elf32_gprel16_reloc
, /* special_function */
244 "R_MIPS_LITERAL", /* name */
245 true, /* partial_inplace */
246 0x0000ffff, /* src_mask */
247 0x0000ffff, /* dst_mask */
248 false), /* pcrel_offset */
250 /* Reference to global offset table. */
251 HOWTO (R_MIPS_GOT16
, /* type */
253 2, /* size (0 = byte, 1 = short, 2 = long) */
255 false, /* pc_relative */
257 complain_overflow_signed
, /* complain_on_overflow */
258 mips_elf_got16_reloc
, /* special_function */
259 "R_MIPS_GOT16", /* name */
260 true, /* partial_inplace */
261 0x0000ffff, /* src_mask */
262 0x0000ffff, /* dst_mask */
263 false), /* pcrel_offset */
265 /* 16 bit PC relative reference. */
266 HOWTO (R_MIPS_PC16
, /* type */
268 2, /* size (0 = byte, 1 = short, 2 = long) */
270 true, /* pc_relative */
272 complain_overflow_signed
, /* complain_on_overflow */
273 bfd_elf_generic_reloc
, /* special_function */
274 "R_MIPS_PC16", /* name */
275 true, /* partial_inplace */
276 0x0000ffff, /* src_mask */
277 0x0000ffff, /* dst_mask */
278 true), /* pcrel_offset */
280 /* 16 bit call through global offset table. */
281 HOWTO (R_MIPS_CALL16
, /* type */
283 2, /* size (0 = byte, 1 = short, 2 = long) */
285 false, /* pc_relative */
287 complain_overflow_signed
, /* complain_on_overflow */
288 bfd_elf_generic_reloc
, /* special_function */
289 "R_MIPS_CALL16", /* name */
290 true, /* partial_inplace */
291 0x0000ffff, /* src_mask */
292 0x0000ffff, /* dst_mask */
293 false), /* pcrel_offset */
295 /* 32 bit GP relative reference. */
296 HOWTO (R_MIPS_GPREL32
, /* type */
298 2, /* size (0 = byte, 1 = short, 2 = long) */
300 false, /* pc_relative */
302 complain_overflow_dont
, /* complain_on_overflow */
303 mips_elf_gprel32_reloc
, /* special_function */
304 "R_MIPS_GPREL32", /* name */
305 true, /* partial_inplace */
306 0xffffffff, /* src_mask */
307 0xffffffff, /* dst_mask */
308 false), /* pcrel_offset */
310 /* The remaining relocs are defined on Irix 5, although they are
311 not defined by the ABI. */
316 /* A 5 bit shift field. */
317 HOWTO (R_MIPS_SHIFT5
, /* type */
319 2, /* size (0 = byte, 1 = short, 2 = long) */
321 false, /* pc_relative */
323 complain_overflow_bitfield
, /* complain_on_overflow */
324 bfd_elf_generic_reloc
, /* special_function */
325 "R_MIPS_SHIFT5", /* name */
326 true, /* partial_inplace */
327 0x000007c0, /* src_mask */
328 0x000007c0, /* dst_mask */
329 false), /* pcrel_offset */
331 /* A 6 bit shift field. */
332 /* FIXME: This is not handled correctly; a special function is
333 needed to put the most significant bit in the right place. */
334 HOWTO (R_MIPS_SHIFT6
, /* type */
336 2, /* size (0 = byte, 1 = short, 2 = long) */
338 false, /* pc_relative */
340 complain_overflow_bitfield
, /* complain_on_overflow */
341 bfd_elf_generic_reloc
, /* special_function */
342 "R_MIPS_SHIFT6", /* name */
343 true, /* partial_inplace */
344 0x000007c4, /* src_mask */
345 0x000007c4, /* dst_mask */
346 false), /* pcrel_offset */
348 /* A 64 bit relocation. */
349 HOWTO (R_MIPS_64
, /* type */
351 4, /* size (0 = byte, 1 = short, 2 = long) */
353 false, /* pc_relative */
355 complain_overflow_dont
, /* complain_on_overflow */
356 mips32_64bit_reloc
, /* special_function */
357 "R_MIPS_64", /* name */
358 true, /* partial_inplace */
359 MINUS_ONE
, /* src_mask */
360 MINUS_ONE
, /* dst_mask */
361 false), /* pcrel_offset */
363 /* Displacement in the global offset table. */
364 HOWTO (R_MIPS_GOT_DISP
, /* type */
366 2, /* size (0 = byte, 1 = short, 2 = long) */
368 false, /* pc_relative */
370 complain_overflow_signed
, /* complain_on_overflow */
371 bfd_elf_generic_reloc
, /* special_function */
372 "R_MIPS_GOT_DISP", /* name */
373 true, /* partial_inplace */
374 0x0000ffff, /* src_mask */
375 0x0000ffff, /* dst_mask */
376 false), /* pcrel_offset */
378 /* Displacement to page pointer in the global offset table. */
379 HOWTO (R_MIPS_GOT_PAGE
, /* type */
381 2, /* size (0 = byte, 1 = short, 2 = long) */
383 false, /* pc_relative */
385 complain_overflow_signed
, /* complain_on_overflow */
386 bfd_elf_generic_reloc
, /* special_function */
387 "R_MIPS_GOT_PAGE", /* name */
388 true, /* partial_inplace */
389 0x0000ffff, /* src_mask */
390 0x0000ffff, /* dst_mask */
391 false), /* pcrel_offset */
393 /* Offset from page pointer in the global offset table. */
394 HOWTO (R_MIPS_GOT_OFST
, /* type */
396 2, /* size (0 = byte, 1 = short, 2 = long) */
398 false, /* pc_relative */
400 complain_overflow_signed
, /* complain_on_overflow */
401 bfd_elf_generic_reloc
, /* special_function */
402 "R_MIPS_GOT_OFST", /* name */
403 true, /* partial_inplace */
404 0x0000ffff, /* src_mask */
405 0x0000ffff, /* dst_mask */
406 false), /* pcrel_offset */
408 /* High 16 bits of displacement in global offset table. */
409 HOWTO (R_MIPS_GOT_HI16
, /* type */
411 2, /* size (0 = byte, 1 = short, 2 = long) */
413 false, /* pc_relative */
415 complain_overflow_dont
, /* complain_on_overflow */
416 bfd_elf_generic_reloc
, /* special_function */
417 "R_MIPS_GOT_HI16", /* name */
418 true, /* partial_inplace */
419 0x0000ffff, /* src_mask */
420 0x0000ffff, /* dst_mask */
421 false), /* pcrel_offset */
423 /* Low 16 bits of displacement in global offset table. */
424 HOWTO (R_MIPS_GOT_LO16
, /* type */
426 2, /* size (0 = byte, 1 = short, 2 = long) */
428 false, /* pc_relative */
430 complain_overflow_dont
, /* complain_on_overflow */
431 bfd_elf_generic_reloc
, /* special_function */
432 "R_MIPS_GOT_LO16", /* name */
433 true, /* partial_inplace */
434 0x0000ffff, /* src_mask */
435 0x0000ffff, /* dst_mask */
436 false), /* pcrel_offset */
438 /* 64 bit subtraction. Used in the N32 ABI. */
439 HOWTO (R_MIPS_SUB
, /* type */
441 4, /* size (0 = byte, 1 = short, 2 = long) */
443 false, /* pc_relative */
445 complain_overflow_dont
, /* complain_on_overflow */
446 bfd_elf_generic_reloc
, /* special_function */
447 "R_MIPS_SUB", /* name */
448 true, /* partial_inplace */
449 MINUS_ONE
, /* src_mask */
450 MINUS_ONE
, /* dst_mask */
451 false), /* pcrel_offset */
453 /* Used to cause the linker to insert and delete instructions? */
454 EMPTY_HOWTO (R_MIPS_INSERT_A
),
455 EMPTY_HOWTO (R_MIPS_INSERT_B
),
456 EMPTY_HOWTO (R_MIPS_DELETE
),
458 /* Get the higher value of a 64 bit addend. */
459 HOWTO (R_MIPS_HIGHER
, /* type */
461 2, /* size (0 = byte, 1 = short, 2 = long) */
463 false, /* pc_relative */
465 complain_overflow_dont
, /* complain_on_overflow */
466 bfd_elf_generic_reloc
, /* special_function */
467 "R_MIPS_HIGHER", /* name */
468 true, /* partial_inplace */
469 0x0000ffff, /* src_mask */
470 0x0000ffff, /* dst_mask */
471 false), /* pcrel_offset */
473 /* Get the highest value of a 64 bit addend. */
474 HOWTO (R_MIPS_HIGHEST
, /* type */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
478 false, /* pc_relative */
480 complain_overflow_dont
, /* complain_on_overflow */
481 bfd_elf_generic_reloc
, /* special_function */
482 "R_MIPS_HIGHEST", /* name */
483 true, /* partial_inplace */
484 0x0000ffff, /* src_mask */
485 0x0000ffff, /* dst_mask */
486 false), /* pcrel_offset */
488 /* High 16 bits of displacement in global offset table. */
489 HOWTO (R_MIPS_CALL_HI16
, /* type */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
493 false, /* pc_relative */
495 complain_overflow_dont
, /* complain_on_overflow */
496 bfd_elf_generic_reloc
, /* special_function */
497 "R_MIPS_CALL_HI16", /* name */
498 true, /* partial_inplace */
499 0x0000ffff, /* src_mask */
500 0x0000ffff, /* dst_mask */
501 false), /* pcrel_offset */
503 /* Low 16 bits of displacement in global offset table. */
504 HOWTO (R_MIPS_CALL_LO16
, /* type */
506 2, /* size (0 = byte, 1 = short, 2 = long) */
508 false, /* pc_relative */
510 complain_overflow_dont
, /* complain_on_overflow */
511 bfd_elf_generic_reloc
, /* special_function */
512 "R_MIPS_CALL_LO16", /* name */
513 true, /* partial_inplace */
514 0x0000ffff, /* src_mask */
515 0x0000ffff, /* dst_mask */
516 false), /* pcrel_offset */
518 /* Section displacement. */
519 HOWTO (R_MIPS_SCN_DISP
, /* type */
521 2, /* size (0 = byte, 1 = short, 2 = long) */
523 false, /* pc_relative */
525 complain_overflow_dont
, /* complain_on_overflow */
526 bfd_elf_generic_reloc
, /* special_function */
527 "R_MIPS_SCN_DISP", /* name */
528 true, /* partial_inplace */
529 0xffffffff, /* src_mask */
530 0xffffffff, /* dst_mask */
531 false), /* pcrel_offset */
533 EMPTY_HOWTO (R_MIPS_REL16
),
534 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE
),
535 EMPTY_HOWTO (R_MIPS_PJUMP
),
536 EMPTY_HOWTO (R_MIPS_RELGOT
),
538 /* Protected jump conversion. This is an optimization hint. No
539 relocation is required for correctness. */
540 HOWTO (R_MIPS_JALR
, /* type */
542 2, /* size (0 = byte, 1 = short, 2 = long) */
544 false, /* pc_relative */
546 complain_overflow_dont
, /* complain_on_overflow */
547 bfd_elf_generic_reloc
, /* special_function */
548 "R_MIPS_JALR", /* name */
549 false, /* partial_inplace */
550 0x00000000, /* src_mask */
551 0x00000000, /* dst_mask */
552 false), /* pcrel_offset */
555 /* The reloc used for BFD_RELOC_CTOR when doing a 64 bit link. This
556 is a hack to make the linker think that we need 64 bit values. */
557 static reloc_howto_type elf_mips_ctor64_howto
=
558 HOWTO (R_MIPS_64
, /* type */
560 4, /* size (0 = byte, 1 = short, 2 = long) */
562 false, /* pc_relative */
564 complain_overflow_signed
, /* complain_on_overflow */
565 mips32_64bit_reloc
, /* special_function */
566 "R_MIPS_64", /* name */
567 true, /* partial_inplace */
568 0xffffffff, /* src_mask */
569 0xffffffff, /* dst_mask */
570 false); /* pcrel_offset */
572 /* The reloc used for the mips16 jump instruction. */
573 static reloc_howto_type elf_mips16_jump_howto
=
574 HOWTO (R_MIPS16_26
, /* type */
576 2, /* size (0 = byte, 1 = short, 2 = long) */
578 false, /* pc_relative */
580 complain_overflow_dont
, /* complain_on_overflow */
581 /* This needs complex overflow
582 detection, because the upper four
583 bits must match the PC. */
584 mips16_jump_reloc
, /* special_function */
585 "R_MIPS16_26", /* name */
586 true, /* partial_inplace */
587 0x3ffffff, /* src_mask */
588 0x3ffffff, /* dst_mask */
589 false); /* pcrel_offset */
591 /* The reloc used for the mips16 gprel instruction. */
592 static reloc_howto_type elf_mips16_gprel_howto
=
593 HOWTO (R_MIPS16_GPREL
, /* type */
595 2, /* size (0 = byte, 1 = short, 2 = long) */
597 false, /* pc_relative */
599 complain_overflow_signed
, /* complain_on_overflow */
600 mips16_gprel_reloc
, /* special_function */
601 "R_MIPS16_GPREL", /* name */
602 true, /* partial_inplace */
603 0x07ff001f, /* src_mask */
604 0x07ff001f, /* dst_mask */
605 false); /* pcrel_offset */
607 /* GNU extensions for embedded-pic. */
608 /* High 16 bits of symbol value, pc-relative. */
609 static reloc_howto_type elf_mips_gnu_rel_hi16
=
610 HOWTO (R_MIPS_GNU_REL_HI16
, /* type */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
614 true, /* pc_relative */
616 complain_overflow_dont
, /* complain_on_overflow */
617 mips_elf_hi16_reloc
, /* special_function */
618 "R_MIPS_GNU_REL_HI16", /* name */
619 true, /* partial_inplace */
620 0xffff, /* src_mask */
621 0xffff, /* dst_mask */
622 true); /* pcrel_offset */
624 /* Low 16 bits of symbol value, pc-relative. */
625 static reloc_howto_type elf_mips_gnu_rel_lo16
=
626 HOWTO (R_MIPS_GNU_REL_LO16
, /* type */
628 2, /* size (0 = byte, 1 = short, 2 = long) */
630 true, /* pc_relative */
632 complain_overflow_dont
, /* complain_on_overflow */
633 mips_elf_lo16_reloc
, /* special_function */
634 "R_MIPS_GNU_REL_LO16", /* name */
635 true, /* partial_inplace */
636 0xffff, /* src_mask */
637 0xffff, /* dst_mask */
638 true); /* pcrel_offset */
640 /* 16 bit offset for pc-relative branches. */
641 static reloc_howto_type elf_mips_gnu_rel16_s2
=
642 HOWTO (R_MIPS_GNU_REL16_S2
, /* type */
644 2, /* size (0 = byte, 1 = short, 2 = long) */
646 true, /* pc_relative */
648 complain_overflow_signed
, /* complain_on_overflow */
649 bfd_elf_generic_reloc
, /* special_function */
650 "R_MIPS_GNU_REL16_S2", /* name */
651 true, /* partial_inplace */
652 0xffff, /* src_mask */
653 0xffff, /* dst_mask */
654 true); /* pcrel_offset */
656 /* 64 bit pc-relative. */
657 static reloc_howto_type elf_mips_gnu_pcrel64
=
658 HOWTO (R_MIPS_PC64
, /* type */
660 4, /* size (0 = byte, 1 = short, 2 = long) */
662 true, /* pc_relative */
664 complain_overflow_signed
, /* complain_on_overflow */
665 bfd_elf_generic_reloc
, /* special_function */
666 "R_MIPS_PC64", /* name */
667 true, /* partial_inplace */
668 MINUS_ONE
, /* src_mask */
669 MINUS_ONE
, /* dst_mask */
670 true); /* pcrel_offset */
672 /* 32 bit pc-relative. */
673 static reloc_howto_type elf_mips_gnu_pcrel32
=
674 HOWTO (R_MIPS_PC32
, /* type */
676 2, /* size (0 = byte, 1 = short, 2 = long) */
678 true, /* pc_relative */
680 complain_overflow_signed
, /* complain_on_overflow */
681 bfd_elf_generic_reloc
, /* special_function */
682 "R_MIPS_PC32", /* name */
683 true, /* partial_inplace */
684 0xffffffff, /* src_mask */
685 0xffffffff, /* dst_mask */
686 true); /* pcrel_offset */
688 /* GNU extension to record C++ vtable hierarchy */
689 static reloc_howto_type elf_mips_gnu_vtinherit_howto
=
690 HOWTO (R_MIPS_GNU_VTINHERIT
, /* type */
692 2, /* size (0 = byte, 1 = short, 2 = long) */
694 false, /* pc_relative */
696 complain_overflow_dont
, /* complain_on_overflow */
697 NULL
, /* special_function */
698 "R_MIPS_GNU_VTINHERIT", /* name */
699 false, /* partial_inplace */
702 false); /* pcrel_offset */
704 /* GNU extension to record C++ vtable member usage */
705 static reloc_howto_type elf_mips_gnu_vtentry_howto
=
706 HOWTO (R_MIPS_GNU_VTENTRY
, /* type */
708 2, /* size (0 = byte, 1 = short, 2 = long) */
710 false, /* pc_relative */
712 complain_overflow_dont
, /* complain_on_overflow */
713 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
714 "R_MIPS_GNU_VTENTRY", /* name */
715 false, /* partial_inplace */
718 false); /* pcrel_offset */
720 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
721 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
722 the HI16. Here we just save the information we need; we do the
723 actual relocation when we see the LO16.
725 MIPS ELF requires that the LO16 immediately follow the HI16. As a
726 GNU extension, for non-pc-relative relocations, we permit an
727 arbitrary number of HI16 relocs to be associated with a single LO16
728 reloc. This extension permits gcc to output the HI and LO relocs
731 This cannot be done for PC-relative relocations because both the HI16
732 and LO16 parts of the relocations must be done relative to the LO16
733 part, and there can be carry to or borrow from the HI16 part. */
737 struct mips_hi16
*next
;
742 /* FIXME: This should not be a static variable. */
744 static struct mips_hi16
*mips_hi16_list
;
746 static bfd_reloc_status_type
747 mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
748 output_bfd
, error_message
)
749 bfd
*abfd ATTRIBUTE_UNUSED
;
750 arelent
*reloc_entry
;
753 asection
*input_section
;
755 char **error_message
;
757 bfd_reloc_status_type ret
;
761 /* If we're relocating, and this is an external symbol, we don't want
762 to change anything. */
763 if (output_bfd
!= (bfd
*) NULL
764 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
765 && reloc_entry
->addend
== 0)
767 reloc_entry
->address
+= input_section
->output_offset
;
773 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
775 boolean relocateable
;
778 if (ret
== bfd_reloc_undefined
)
781 if (output_bfd
!= NULL
)
785 relocateable
= false;
786 output_bfd
= symbol
->section
->output_section
->owner
;
789 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
791 if (ret
!= bfd_reloc_ok
)
794 relocation
= gp
- reloc_entry
->address
;
798 if (bfd_is_und_section (symbol
->section
)
799 && output_bfd
== (bfd
*) NULL
)
800 ret
= bfd_reloc_undefined
;
802 if (bfd_is_com_section (symbol
->section
))
805 relocation
= symbol
->value
;
808 relocation
+= symbol
->section
->output_section
->vma
;
809 relocation
+= symbol
->section
->output_offset
;
810 relocation
+= reloc_entry
->addend
;
812 if (reloc_entry
->address
> input_section
->_cooked_size
)
813 return bfd_reloc_outofrange
;
815 /* Save the information, and let LO16 do the actual relocation. */
816 n
= (struct mips_hi16
*) bfd_malloc ((bfd_size_type
) sizeof *n
);
818 return bfd_reloc_outofrange
;
819 n
->addr
= (bfd_byte
*) data
+ reloc_entry
->address
;
820 n
->addend
= relocation
;
821 n
->next
= mips_hi16_list
;
824 if (output_bfd
!= (bfd
*) NULL
)
825 reloc_entry
->address
+= input_section
->output_offset
;
830 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
831 inplace relocation; this function exists in order to do the
832 R_MIPS_HI16 relocation described above. */
834 static bfd_reloc_status_type
835 mips_elf_lo16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
836 output_bfd
, error_message
)
838 arelent
*reloc_entry
;
841 asection
*input_section
;
843 char **error_message
;
845 arelent gp_disp_relent
;
847 if (mips_hi16_list
!= NULL
)
857 struct mips_hi16
*next
;
859 /* Do the HI16 relocation. Note that we actually don't need
860 to know anything about the LO16 itself, except where to
861 find the low 16 bits of the addend needed by the LO16. */
862 insn
= bfd_get_32 (abfd
, l
->addr
);
863 vallo
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
865 /* The low order 16 bits are always treated as a signed
867 vallo
= ((vallo
& 0xffff) ^ 0x8000) - 0x8000;
868 val
= ((insn
& 0xffff) << 16) + vallo
;
871 /* If PC-relative, we need to subtract out the address of the LO
872 half of the HI/LO. (The actual relocation is relative
873 to that instruction.) */
874 if (reloc_entry
->howto
->pc_relative
)
875 val
-= reloc_entry
->address
;
877 /* At this point, "val" has the value of the combined HI/LO
878 pair. If the low order 16 bits (which will be used for
879 the LO16 insn) are negative, then we will need an
880 adjustment for the high order 16 bits. */
882 val
= (val
>> 16) & 0xffff;
884 insn
&= ~ (bfd_vma
) 0xffff;
886 bfd_put_32 (abfd
, (bfd_vma
) insn
, l
->addr
);
888 if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
890 gp_disp_relent
= *reloc_entry
;
891 reloc_entry
= &gp_disp_relent
;
892 reloc_entry
->addend
= l
->addend
;
900 mips_hi16_list
= NULL
;
902 else if (strcmp (bfd_asymbol_name (symbol
), "_gp_disp") == 0)
904 bfd_reloc_status_type ret
;
905 bfd_vma gp
, relocation
;
907 /* FIXME: Does this case ever occur? */
909 ret
= mips_elf_final_gp (output_bfd
, symbol
, true, error_message
, &gp
);
910 if (ret
!= bfd_reloc_ok
)
913 relocation
= gp
- reloc_entry
->address
;
914 relocation
+= symbol
->section
->output_section
->vma
;
915 relocation
+= symbol
->section
->output_offset
;
916 relocation
+= reloc_entry
->addend
;
918 if (reloc_entry
->address
> input_section
->_cooked_size
)
919 return bfd_reloc_outofrange
;
921 gp_disp_relent
= *reloc_entry
;
922 reloc_entry
= &gp_disp_relent
;
923 reloc_entry
->addend
= relocation
- 4;
926 /* Now do the LO16 reloc in the usual way. */
927 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
928 input_section
, output_bfd
, error_message
);
931 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
932 table used for PIC code. If the symbol is an external symbol, the
933 instruction is modified to contain the offset of the appropriate
934 entry in the global offset table. If the symbol is a section
935 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
936 addends are combined to form the real addend against the section
937 symbol; the GOT16 is modified to contain the offset of an entry in
938 the global offset table, and the LO16 is modified to offset it
939 appropriately. Thus an offset larger than 16 bits requires a
940 modified value in the global offset table.
942 This implementation suffices for the assembler, but the linker does
943 not yet know how to create global offset tables. */
945 static bfd_reloc_status_type
946 mips_elf_got16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
947 output_bfd
, error_message
)
949 arelent
*reloc_entry
;
952 asection
*input_section
;
954 char **error_message
;
956 /* If we're relocating, and this is an external symbol, we don't want
957 to change anything. */
958 if (output_bfd
!= (bfd
*) NULL
959 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
960 && reloc_entry
->addend
== 0)
962 reloc_entry
->address
+= input_section
->output_offset
;
966 /* If we're relocating, and this is a local symbol, we can handle it
968 if (output_bfd
!= (bfd
*) NULL
969 && (symbol
->flags
& BSF_SECTION_SYM
) != 0)
970 return mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
971 input_section
, output_bfd
, error_message
);
976 /* Set the GP value for OUTPUT_BFD. Returns false if this is a
977 dangerous relocation. */
980 mips_elf_assign_gp (output_bfd
, pgp
)
988 /* If we've already figured out what GP will be, just return it. */
989 *pgp
= _bfd_get_gp_value (output_bfd
);
993 count
= bfd_get_symcount (output_bfd
);
994 sym
= bfd_get_outsymbols (output_bfd
);
996 /* The linker script will have created a symbol named `_gp' with the
997 appropriate value. */
998 if (sym
== (asymbol
**) NULL
)
1002 for (i
= 0; i
< count
; i
++, sym
++)
1004 register const char *name
;
1006 name
= bfd_asymbol_name (*sym
);
1007 if (*name
== '_' && strcmp (name
, "_gp") == 0)
1009 *pgp
= bfd_asymbol_value (*sym
);
1010 _bfd_set_gp_value (output_bfd
, *pgp
);
1018 /* Only get the error once. */
1020 _bfd_set_gp_value (output_bfd
, *pgp
);
1027 /* We have to figure out the gp value, so that we can adjust the
1028 symbol value correctly. We look up the symbol _gp in the output
1029 BFD. If we can't find it, we're stuck. We cache it in the ELF
1030 target data. We don't need to adjust the symbol value for an
1031 external symbol if we are producing relocateable output. */
1033 static bfd_reloc_status_type
1034 mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
, pgp
)
1037 boolean relocateable
;
1038 char **error_message
;
1041 if (bfd_is_und_section (symbol
->section
)
1045 return bfd_reloc_undefined
;
1048 *pgp
= _bfd_get_gp_value (output_bfd
);
1051 || (symbol
->flags
& BSF_SECTION_SYM
) != 0))
1055 /* Make up a value. */
1056 *pgp
= symbol
->section
->output_section
->vma
+ 0x4000;
1057 _bfd_set_gp_value (output_bfd
, *pgp
);
1059 else if (!mips_elf_assign_gp (output_bfd
, pgp
))
1062 (char *) _("GP relative relocation when _gp not defined");
1063 return bfd_reloc_dangerous
;
1067 return bfd_reloc_ok
;
1070 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
1071 become the offset from the gp register. This function also handles
1072 R_MIPS_LITERAL relocations, although those can be handled more
1073 cleverly because the entries in the .lit8 and .lit4 sections can be
1076 bfd_reloc_status_type
1077 _bfd_mips_elf32_gprel16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1078 output_bfd
, error_message
)
1080 arelent
*reloc_entry
;
1083 asection
*input_section
;
1085 char **error_message
;
1087 boolean relocateable
;
1088 bfd_reloc_status_type ret
;
1091 /* If we're relocating, and this is an external symbol with no
1092 addend, we don't want to change anything. We will only have an
1093 addend if this is a newly created reloc, not read from an ELF
1095 if (output_bfd
!= (bfd
*) NULL
1096 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1097 && reloc_entry
->addend
== 0)
1099 reloc_entry
->address
+= input_section
->output_offset
;
1100 return bfd_reloc_ok
;
1103 if (output_bfd
!= (bfd
*) NULL
)
1104 relocateable
= true;
1107 relocateable
= false;
1108 output_bfd
= symbol
->section
->output_section
->owner
;
1111 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1113 if (ret
!= bfd_reloc_ok
)
1116 return _bfd_mips_elf_gprel16_with_gp (abfd
, symbol
, reloc_entry
,
1117 input_section
, relocateable
,
1121 /* Do a R_MIPS_GPREL32 relocation. This is a 32 bit value which must
1122 become the offset from the gp register. */
1124 static bfd_reloc_status_type gprel32_with_gp
PARAMS ((bfd
*, asymbol
*,
1125 arelent
*, asection
*,
1126 boolean
, PTR
, bfd_vma
));
1128 static bfd_reloc_status_type
1129 mips_elf_gprel32_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1130 output_bfd
, error_message
)
1132 arelent
*reloc_entry
;
1135 asection
*input_section
;
1137 char **error_message
;
1139 boolean relocateable
;
1140 bfd_reloc_status_type ret
;
1143 /* If we're relocating, and this is an external symbol with no
1144 addend, we don't want to change anything. We will only have an
1145 addend if this is a newly created reloc, not read from an ELF
1147 if (output_bfd
!= (bfd
*) NULL
1148 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1149 && reloc_entry
->addend
== 0)
1151 *error_message
= (char *)
1152 _("32bits gp relative relocation occurs for an external symbol");
1153 return bfd_reloc_outofrange
;
1156 if (output_bfd
!= (bfd
*) NULL
)
1158 relocateable
= true;
1159 gp
= _bfd_get_gp_value (output_bfd
);
1163 relocateable
= false;
1164 output_bfd
= symbol
->section
->output_section
->owner
;
1166 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
,
1167 error_message
, &gp
);
1168 if (ret
!= bfd_reloc_ok
)
1172 return gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
,
1173 relocateable
, data
, gp
);
1176 static bfd_reloc_status_type
1177 gprel32_with_gp (abfd
, symbol
, reloc_entry
, input_section
, relocateable
, data
,
1181 arelent
*reloc_entry
;
1182 asection
*input_section
;
1183 boolean relocateable
;
1190 if (bfd_is_com_section (symbol
->section
))
1193 relocation
= symbol
->value
;
1195 relocation
+= symbol
->section
->output_section
->vma
;
1196 relocation
+= symbol
->section
->output_offset
;
1198 if (reloc_entry
->address
> input_section
->_cooked_size
)
1199 return bfd_reloc_outofrange
;
1201 if (reloc_entry
->howto
->src_mask
== 0)
1203 /* This case arises with the 64-bit MIPS ELF ABI. */
1207 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1209 /* Set val to the offset into the section or symbol. */
1210 val
+= reloc_entry
->addend
;
1212 /* Adjust val for the final section location and GP value. If we
1213 are producing relocateable output, we don't want to do this for
1214 an external symbol. */
1216 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1217 val
+= relocation
- gp
;
1219 bfd_put_32 (abfd
, (bfd_vma
) val
, (bfd_byte
*) data
+ reloc_entry
->address
);
1222 reloc_entry
->address
+= input_section
->output_offset
;
1224 return bfd_reloc_ok
;
1227 /* Handle a 64 bit reloc in a 32 bit MIPS ELF file. These are
1228 generated when addresses are 64 bits. The upper 32 bits are a simple
1231 static bfd_reloc_status_type
1232 mips32_64bit_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1233 output_bfd
, error_message
)
1235 arelent
*reloc_entry
;
1238 asection
*input_section
;
1240 char **error_message
;
1242 bfd_reloc_status_type r
;
1247 r
= bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1248 input_section
, output_bfd
, error_message
);
1249 if (r
!= bfd_reloc_continue
)
1252 /* Do a normal 32 bit relocation on the lower 32 bits. */
1253 reloc32
= *reloc_entry
;
1254 if (bfd_big_endian (abfd
))
1255 reloc32
.address
+= 4;
1256 reloc32
.howto
= &elf_mips_howto_table_rel
[R_MIPS_32
];
1257 r
= bfd_perform_relocation (abfd
, &reloc32
, data
, input_section
,
1258 output_bfd
, error_message
);
1260 /* Sign extend into the upper 32 bits. */
1261 val
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc32
.address
);
1262 if ((val
& 0x80000000) != 0)
1266 addr
= reloc_entry
->address
;
1267 if (bfd_little_endian (abfd
))
1269 bfd_put_32 (abfd
, (bfd_vma
) val
, (bfd_byte
*) data
+ addr
);
1274 /* Handle a mips16 jump. */
1276 static bfd_reloc_status_type
1277 mips16_jump_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1278 output_bfd
, error_message
)
1279 bfd
*abfd ATTRIBUTE_UNUSED
;
1280 arelent
*reloc_entry
;
1282 PTR data ATTRIBUTE_UNUSED
;
1283 asection
*input_section
;
1285 char **error_message ATTRIBUTE_UNUSED
;
1287 if (output_bfd
!= (bfd
*) NULL
1288 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1289 && reloc_entry
->addend
== 0)
1291 reloc_entry
->address
+= input_section
->output_offset
;
1292 return bfd_reloc_ok
;
1297 static boolean warned
;
1300 (*_bfd_error_handler
)
1301 (_("Linking mips16 objects into %s format is not supported"),
1302 bfd_get_target (input_section
->output_section
->owner
));
1306 return bfd_reloc_undefined
;
1309 /* Handle a mips16 GP relative reloc. */
1311 static bfd_reloc_status_type
1312 mips16_gprel_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1313 output_bfd
, error_message
)
1315 arelent
*reloc_entry
;
1318 asection
*input_section
;
1320 char **error_message
;
1322 boolean relocateable
;
1323 bfd_reloc_status_type ret
;
1325 unsigned short extend
, insn
;
1326 unsigned long final
;
1328 /* If we're relocating, and this is an external symbol with no
1329 addend, we don't want to change anything. We will only have an
1330 addend if this is a newly created reloc, not read from an ELF
1332 if (output_bfd
!= NULL
1333 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1334 && reloc_entry
->addend
== 0)
1336 reloc_entry
->address
+= input_section
->output_offset
;
1337 return bfd_reloc_ok
;
1340 if (output_bfd
!= NULL
)
1341 relocateable
= true;
1344 relocateable
= false;
1345 output_bfd
= symbol
->section
->output_section
->owner
;
1348 ret
= mips_elf_final_gp (output_bfd
, symbol
, relocateable
, error_message
,
1350 if (ret
!= bfd_reloc_ok
)
1353 if (reloc_entry
->address
> input_section
->_cooked_size
)
1354 return bfd_reloc_outofrange
;
1356 /* Pick up the mips16 extend instruction and the real instruction. */
1357 extend
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1358 insn
= bfd_get_16 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1360 /* Stuff the current addend back as a 32 bit value, do the usual
1361 relocation, and then clean up. */
1363 (bfd_vma
) (((extend
& 0x1f) << 11)
1366 (bfd_byte
*) data
+ reloc_entry
->address
);
1368 ret
= _bfd_mips_elf_gprel16_with_gp (abfd
, symbol
, reloc_entry
,
1369 input_section
, relocateable
, data
, gp
);
1371 final
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1373 (bfd_vma
) ((extend
& 0xf800)
1374 | ((final
>> 11) & 0x1f)
1376 (bfd_byte
*) data
+ reloc_entry
->address
);
1378 (bfd_vma
) ((insn
& 0xffe0)
1380 (bfd_byte
*) data
+ reloc_entry
->address
+ 2);
1385 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1387 struct elf_reloc_map
{
1388 bfd_reloc_code_real_type bfd_val
;
1389 enum elf_mips_reloc_type elf_val
;
1392 static const struct elf_reloc_map mips_reloc_map
[] =
1394 { BFD_RELOC_NONE
, R_MIPS_NONE
, },
1395 { BFD_RELOC_16
, R_MIPS_16
},
1396 { BFD_RELOC_32
, R_MIPS_32
},
1397 /* There is no BFD reloc for R_MIPS_REL32. */
1398 { BFD_RELOC_64
, R_MIPS_64
},
1399 { BFD_RELOC_MIPS_JMP
, R_MIPS_26
},
1400 { BFD_RELOC_HI16_S
, R_MIPS_HI16
},
1401 { BFD_RELOC_LO16
, R_MIPS_LO16
},
1402 { BFD_RELOC_GPREL16
, R_MIPS_GPREL16
},
1403 { BFD_RELOC_MIPS_LITERAL
, R_MIPS_LITERAL
},
1404 { BFD_RELOC_MIPS_GOT16
, R_MIPS_GOT16
},
1405 { BFD_RELOC_16_PCREL
, R_MIPS_PC16
},
1406 { BFD_RELOC_MIPS_CALL16
, R_MIPS_CALL16
},
1407 { BFD_RELOC_GPREL32
, R_MIPS_GPREL32
},
1408 { BFD_RELOC_MIPS_GOT_HI16
, R_MIPS_GOT_HI16
},
1409 { BFD_RELOC_MIPS_GOT_LO16
, R_MIPS_GOT_LO16
},
1410 { BFD_RELOC_MIPS_CALL_HI16
, R_MIPS_CALL_HI16
},
1411 { BFD_RELOC_MIPS_CALL_LO16
, R_MIPS_CALL_LO16
},
1412 { BFD_RELOC_MIPS_SUB
, R_MIPS_SUB
},
1413 { BFD_RELOC_MIPS_GOT_PAGE
, R_MIPS_GOT_PAGE
},
1414 { BFD_RELOC_MIPS_GOT_OFST
, R_MIPS_GOT_OFST
},
1415 { BFD_RELOC_MIPS_GOT_DISP
, R_MIPS_GOT_DISP
}
1418 /* Given a BFD reloc type, return a howto structure. */
1420 static reloc_howto_type
*
1421 bfd_elf32_bfd_reloc_type_lookup (abfd
, code
)
1423 bfd_reloc_code_real_type code
;
1426 reloc_howto_type
*howto_table
= elf_mips_howto_table_rel
;
1428 for (i
= 0; i
< sizeof (mips_reloc_map
) / sizeof (struct elf_reloc_map
);
1431 if (mips_reloc_map
[i
].bfd_val
== code
)
1432 return &howto_table
[(int) mips_reloc_map
[i
].elf_val
];
1438 bfd_set_error (bfd_error_bad_value
);
1441 case BFD_RELOC_CTOR
:
1442 /* We need to handle BFD_RELOC_CTOR specially.
1443 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the
1444 size of addresses on this architecture. */
1445 if (bfd_arch_bits_per_address (abfd
) == 32)
1446 return &howto_table
[(int) R_MIPS_32
];
1448 return &elf_mips_ctor64_howto
;
1450 case BFD_RELOC_MIPS16_JMP
:
1451 return &elf_mips16_jump_howto
;
1452 case BFD_RELOC_MIPS16_GPREL
:
1453 return &elf_mips16_gprel_howto
;
1454 case BFD_RELOC_VTABLE_INHERIT
:
1455 return &elf_mips_gnu_vtinherit_howto
;
1456 case BFD_RELOC_VTABLE_ENTRY
:
1457 return &elf_mips_gnu_vtentry_howto
;
1458 case BFD_RELOC_PCREL_HI16_S
:
1459 return &elf_mips_gnu_rel_hi16
;
1460 case BFD_RELOC_PCREL_LO16
:
1461 return &elf_mips_gnu_rel_lo16
;
1462 case BFD_RELOC_16_PCREL_S2
:
1463 return &elf_mips_gnu_rel16_s2
;
1464 case BFD_RELOC_64_PCREL
:
1465 return &elf_mips_gnu_pcrel64
;
1466 case BFD_RELOC_32_PCREL
:
1467 return &elf_mips_gnu_pcrel32
;
1471 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
1473 static reloc_howto_type
*
1474 mips_elf32_rtype_to_howto (r_type
, rela_p
)
1475 unsigned int r_type
;
1476 boolean rela_p ATTRIBUTE_UNUSED
;
1481 return &elf_mips16_jump_howto
;
1482 case R_MIPS16_GPREL
:
1483 return &elf_mips16_gprel_howto
;
1484 case R_MIPS_GNU_VTINHERIT
:
1485 return &elf_mips_gnu_vtinherit_howto
;
1486 case R_MIPS_GNU_VTENTRY
:
1487 return &elf_mips_gnu_vtentry_howto
;
1488 case R_MIPS_GNU_REL_HI16
:
1489 return &elf_mips_gnu_rel_hi16
;
1490 case R_MIPS_GNU_REL_LO16
:
1491 return &elf_mips_gnu_rel_lo16
;
1492 case R_MIPS_GNU_REL16_S2
:
1493 return &elf_mips_gnu_rel16_s2
;
1495 return &elf_mips_gnu_pcrel64
;
1497 return &elf_mips_gnu_pcrel32
;
1499 BFD_ASSERT (r_type
< (unsigned int) R_MIPS_max
);
1500 return &elf_mips_howto_table_rel
[r_type
];
1504 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */
1507 mips_info_to_howto_rel (abfd
, cache_ptr
, dst
)
1510 Elf32_Internal_Rel
*dst
;
1512 unsigned int r_type
;
1514 r_type
= ELF32_R_TYPE (dst
->r_info
);
1515 cache_ptr
->howto
= mips_elf32_rtype_to_howto (r_type
, false);
1517 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
1518 value for the object file. We get the addend now, rather than
1519 when we do the relocation, because the symbol manipulations done
1520 by the linker may cause us to lose track of the input BFD. */
1521 if (((*cache_ptr
->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) != 0
1522 && (r_type
== (unsigned int) R_MIPS_GPREL16
1523 || r_type
== (unsigned int) R_MIPS_LITERAL
))
1524 cache_ptr
->addend
= elf_gp (abfd
);
1527 /* Given a MIPS Elf32_Internal_Rela, fill in an arelent structure. */
1530 mips_info_to_howto_rela (abfd
, cache_ptr
, dst
)
1533 Elf32_Internal_Rela
*dst
;
1535 /* Since an Elf32_Internal_Rel is an initial prefix of an
1536 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel
1538 mips_info_to_howto_rel (abfd
, cache_ptr
, (Elf32_Internal_Rel
*) dst
);
1540 /* If we ever need to do any extra processing with dst->r_addend
1541 (the field omitted in an Elf32_Internal_Rel) we can do it here. */
1544 /* Determine whether a symbol is global for the purposes of splitting
1545 the symbol table into global symbols and local symbols. At least
1546 on Irix 5, this split must be between section symbols and all other
1547 symbols. On most ELF targets the split is between static symbols
1548 and externally visible symbols. */
1551 mips_elf_sym_is_global (abfd
, sym
)
1552 bfd
*abfd ATTRIBUTE_UNUSED
;
1555 if (SGI_COMPAT (abfd
))
1556 return (sym
->flags
& BSF_SECTION_SYM
) == 0;
1558 return ((sym
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
1559 || bfd_is_und_section (bfd_get_section (sym
))
1560 || bfd_is_com_section (bfd_get_section (sym
)));
1563 /* Set the right machine number for a MIPS ELF file. */
1566 mips_elf32_object_p (abfd
)
1571 /* Irix 5 and 6 are broken. Object file symbol tables are not always
1572 sorted correctly such that local symbols precede global symbols,
1573 and the sh_info field in the symbol table is not always right. */
1574 if (SGI_COMPAT (abfd
))
1575 elf_bad_symtab (abfd
) = true;
1577 mach
= _bfd_elf_mips_mach (elf_elfheader (abfd
)->e_flags
);
1578 bfd_default_set_arch_mach (abfd
, bfd_arch_mips
, mach
);
1583 /* MIPS ELF local labels start with '$', not 'L'. */
1586 mips_elf_is_local_label_name (abfd
, name
)
1593 /* On Irix 6, the labels go back to starting with '.', so we accept
1594 the generic ELF local label syntax as well. */
1595 return _bfd_elf_is_local_label_name (abfd
, name
);
1598 /* Support for core dump NOTE sections. */
1600 elf32_mips_grok_prstatus (abfd
, note
)
1602 Elf_Internal_Note
*note
;
1605 unsigned int raw_size
;
1607 switch (note
->descsz
)
1612 case 256: /* Linux/MIPS */
1614 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1617 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1626 /* Make a ".reg/999" section. */
1627 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1628 raw_size
, note
->descpos
+ offset
);
1632 elf32_mips_grok_psinfo (abfd
, note
)
1634 Elf_Internal_Note
*note
;
1636 switch (note
->descsz
)
1641 case 128: /* Linux/MIPS elf_prpsinfo */
1642 elf_tdata (abfd
)->core_program
1643 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
1644 elf_tdata (abfd
)->core_command
1645 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
1648 /* Note that for some reason, a spurious space is tacked
1649 onto the end of the args in some (at least one anyway)
1650 implementations, so strip it off if it exists. */
1653 char *command
= elf_tdata (abfd
)->core_command
;
1654 int n
= strlen (command
);
1656 if (0 < n
&& command
[n
- 1] == ' ')
1657 command
[n
- 1] = '\0';
1666 elf32_mips_discard_info (abfd
, cookie
, info
)
1668 struct elf_reloc_cookie
*cookie
;
1669 struct bfd_link_info
*info
;
1672 boolean ret
= false;
1673 unsigned char *tdata
;
1676 o
= bfd_get_section_by_name (abfd
, ".pdr");
1679 if (o
->_raw_size
== 0)
1681 if (o
->_raw_size
% PDR_SIZE
!= 0)
1683 if (o
->output_section
!= NULL
1684 && bfd_is_abs_section (o
->output_section
))
1687 tdata
= bfd_zmalloc (o
->_raw_size
/ PDR_SIZE
);
1691 cookie
->rels
= _bfd_elf32_link_read_relocs (abfd
, o
, (PTR
) NULL
,
1692 (Elf_Internal_Rela
*) NULL
,
1700 cookie
->rel
= cookie
->rels
;
1701 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
1703 for (i
= 0, skip
= 0; i
< o
->_raw_size
; i
++)
1705 if (_bfd_elf32_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
1714 elf_section_data (o
)->tdata
= tdata
;
1715 o
->_cooked_size
= o
->_raw_size
- skip
* PDR_SIZE
;
1721 if (! info
->keep_memory
)
1722 free (cookie
->rels
);
1728 elf32_mips_write_section (output_bfd
, sec
, contents
)
1733 bfd_byte
*to
, *from
, *end
;
1736 if (strcmp (sec
->name
, ".pdr") != 0)
1739 if (elf_section_data (sec
)->tdata
== NULL
)
1743 end
= contents
+ sec
->_raw_size
;
1744 for (from
= contents
, i
= 0;
1746 from
+= PDR_SIZE
, i
++)
1748 if (((unsigned char *)elf_section_data (sec
)->tdata
)[i
] == 1)
1751 memcpy (to
, from
, PDR_SIZE
);
1754 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
1755 (file_ptr
) sec
->output_offset
,
1760 /* Depending on the target vector we generate some version of Irix
1761 executables or "normal" MIPS ELF ABI executables. */
1762 static irix_compat_t
1763 elf32_mips_irix_compat (abfd
)
1766 if ((abfd
->xvec
== &bfd_elf32_bigmips_vec
)
1767 || (abfd
->xvec
== &bfd_elf32_littlemips_vec
))
1773 /* Given a data section and an in-memory embedded reloc section, store
1774 relocation information into the embedded reloc section which can be
1775 used at runtime to relocate the data section. This is called by the
1776 linker when the --embedded-relocs switch is used. This is called
1777 after the add_symbols entry point has been called for all the
1778 objects, and before the final_link entry point is called. */
1781 bfd_mips_elf32_create_embedded_relocs (abfd
, info
, datasec
, relsec
, errmsg
)
1783 struct bfd_link_info
*info
;
1788 Elf_Internal_Shdr
*symtab_hdr
;
1789 Elf_Internal_Shdr
*shndx_hdr
;
1790 Elf32_External_Sym
*extsyms
;
1791 Elf32_External_Sym
*free_extsyms
= NULL
;
1792 Elf_External_Sym_Shndx
*shndx_buf
= NULL
;
1793 Elf_Internal_Rela
*internal_relocs
;
1794 Elf_Internal_Rela
*free_relocs
= NULL
;
1795 Elf_Internal_Rela
*irel
, *irelend
;
1799 BFD_ASSERT (! info
->relocateable
);
1803 if (datasec
->reloc_count
== 0)
1806 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1807 /* Read this BFD's symbols if we haven't done so already, or get the cached
1808 copy if it exists. */
1809 if (symtab_hdr
->contents
!= NULL
)
1810 extsyms
= (Elf32_External_Sym
*) symtab_hdr
->contents
;
1813 /* Go get them off disk. */
1814 if (info
->keep_memory
)
1815 extsyms
= ((Elf32_External_Sym
*)
1816 bfd_alloc (abfd
, symtab_hdr
->sh_size
));
1818 extsyms
= ((Elf32_External_Sym
*)
1819 bfd_malloc (symtab_hdr
->sh_size
));
1820 if (extsyms
== NULL
)
1822 if (! info
->keep_memory
)
1823 free_extsyms
= extsyms
;
1824 if (bfd_seek (abfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
1825 || (bfd_bread (extsyms
, symtab_hdr
->sh_size
, abfd
)
1826 != symtab_hdr
->sh_size
))
1828 if (info
->keep_memory
)
1829 symtab_hdr
->contents
= (unsigned char *) extsyms
;
1832 shndx_hdr
= &elf_tdata (abfd
)->symtab_shndx_hdr
;
1833 if (shndx_hdr
->sh_size
!= 0)
1835 amt
= symtab_hdr
->sh_info
* sizeof (Elf_External_Sym_Shndx
);
1836 shndx_buf
= (Elf_External_Sym_Shndx
*) bfd_malloc (amt
);
1837 if (shndx_buf
== NULL
)
1839 if (bfd_seek (abfd
, shndx_hdr
->sh_offset
, SEEK_SET
) != 0
1840 || bfd_bread ((PTR
) shndx_buf
, amt
, abfd
) != amt
)
1844 /* Get a copy of the native relocations. */
1845 internal_relocs
= (_bfd_elf32_link_read_relocs
1846 (abfd
, datasec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
1847 info
->keep_memory
));
1848 if (internal_relocs
== NULL
)
1850 if (! info
->keep_memory
)
1851 free_relocs
= internal_relocs
;
1853 relsec
->contents
= (bfd_byte
*) bfd_alloc (abfd
, datasec
->reloc_count
* 12);
1854 if (relsec
->contents
== NULL
)
1857 p
= relsec
->contents
;
1859 irelend
= internal_relocs
+ datasec
->reloc_count
;
1861 for (irel
= internal_relocs
; irel
< irelend
; irel
++, p
+= 12)
1863 asection
*targetsec
;
1865 /* We are going to write a four byte longword into the runtime
1866 reloc section. The longword will be the address in the data
1867 section which must be relocated. It is followed by the name
1868 of the target section NUL-padded or truncated to 8
1871 /* We can only relocate absolute longword relocs at run time. */
1872 if ((ELF32_R_TYPE (irel
->r_info
) != (int) R_MIPS_32
) &&
1873 (ELF32_R_TYPE (irel
->r_info
) != (int) R_MIPS_64
))
1875 *errmsg
= _("unsupported reloc type");
1876 bfd_set_error (bfd_error_bad_value
);
1879 /* Get the target section referred to by the reloc. */
1880 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
1882 Elf32_External_Sym
*esym
;
1883 Elf_External_Sym_Shndx
*shndx
;
1884 Elf_Internal_Sym isym
;
1886 /* A local symbol. */
1887 esym
= extsyms
+ ELF32_R_SYM (irel
->r_info
);
1888 shndx
= shndx_buf
+ (shndx_buf
? ELF32_R_SYM (irel
->r_info
) : 0);
1889 bfd_elf32_swap_symbol_in (abfd
, (const PTR
) esym
, (const PTR
) shndx
,
1892 targetsec
= bfd_section_from_elf_index (abfd
, isym
.st_shndx
);
1897 struct elf_link_hash_entry
*h
;
1899 /* An external symbol. */
1900 indx
= ELF32_R_SYM (irel
->r_info
);
1901 h
= elf_sym_hashes (abfd
)[indx
];
1904 For some reason, in certain programs, the symbol will
1905 not be in the hash table. It seems to happen when you
1906 declare a static table of pointers to const external structures.
1907 In this case, the relocs are relative to data, not
1908 text, so just treating it like an undefined link
1909 should be sufficient. */
1910 BFD_ASSERT(h
!= NULL
);
1911 if (h
->root
.type
== bfd_link_hash_defined
1912 || h
->root
.type
== bfd_link_hash_defweak
)
1913 targetsec
= h
->root
.u
.def
.section
;
1918 Set the low bit of the relocation offset if it's a MIPS64 reloc.
1919 Relocations will always be on (at least) 32-bit boundaries. */
1921 bfd_put_32 (abfd
, ((irel
->r_offset
+ datasec
->output_offset
) +
1922 ((ELF32_R_TYPE (irel
->r_info
) == (int) R_MIPS_64
) ? 1 : 0)),
1924 memset (p
+ 4, 0, 8);
1925 if (targetsec
!= NULL
)
1926 strncpy (p
+ 4, targetsec
->output_section
->name
, 8);
1929 if (shndx_buf
!= NULL
)
1931 if (free_extsyms
!= NULL
)
1932 free (free_extsyms
);
1933 if (free_relocs
!= NULL
)
1938 if (shndx_buf
!= NULL
)
1940 if (free_extsyms
!= NULL
)
1941 free (free_extsyms
);
1942 if (free_relocs
!= NULL
)
1947 /* ECOFF swapping routines. These are used when dealing with the
1948 .mdebug section, which is in the ECOFF debugging format. */
1949 static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap
= {
1950 /* Symbol table magic number. */
1952 /* Alignment of debugging information. E.g., 4. */
1954 /* Sizes of external symbolic information. */
1955 sizeof (struct hdr_ext
),
1956 sizeof (struct dnr_ext
),
1957 sizeof (struct pdr_ext
),
1958 sizeof (struct sym_ext
),
1959 sizeof (struct opt_ext
),
1960 sizeof (struct fdr_ext
),
1961 sizeof (struct rfd_ext
),
1962 sizeof (struct ext_ext
),
1963 /* Functions to swap in external symbolic data. */
1972 _bfd_ecoff_swap_tir_in
,
1973 _bfd_ecoff_swap_rndx_in
,
1974 /* Functions to swap out external symbolic data. */
1983 _bfd_ecoff_swap_tir_out
,
1984 _bfd_ecoff_swap_rndx_out
,
1985 /* Function to read in symbolic data. */
1986 _bfd_mips_elf_read_ecoff_info
1989 #define ELF_ARCH bfd_arch_mips
1990 #define ELF_MACHINE_CODE EM_MIPS
1992 /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
1993 a value of 0x1000, and we are compatible. */
1994 #define ELF_MAXPAGESIZE 0x1000
1996 #define elf_backend_collect true
1997 #define elf_backend_type_change_ok true
1998 #define elf_backend_can_gc_sections true
1999 #define elf_info_to_howto mips_info_to_howto_rela
2000 #define elf_info_to_howto_rel mips_info_to_howto_rel
2001 #define elf_backend_sym_is_global mips_elf_sym_is_global
2002 #define elf_backend_object_p mips_elf32_object_p
2003 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
2004 #define elf_backend_section_processing _bfd_mips_elf_section_processing
2005 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
2006 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
2007 #define elf_backend_section_from_bfd_section \
2008 _bfd_mips_elf_section_from_bfd_section
2009 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
2010 #define elf_backend_link_output_symbol_hook \
2011 _bfd_mips_elf_link_output_symbol_hook
2012 #define elf_backend_create_dynamic_sections \
2013 _bfd_mips_elf_create_dynamic_sections
2014 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
2015 #define elf_backend_adjust_dynamic_symbol \
2016 _bfd_mips_elf_adjust_dynamic_symbol
2017 #define elf_backend_always_size_sections \
2018 _bfd_mips_elf_always_size_sections
2019 #define elf_backend_size_dynamic_sections \
2020 _bfd_mips_elf_size_dynamic_sections
2021 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
2022 #define elf_backend_finish_dynamic_symbol \
2023 _bfd_mips_elf_finish_dynamic_symbol
2024 #define elf_backend_finish_dynamic_sections \
2025 _bfd_mips_elf_finish_dynamic_sections
2026 #define elf_backend_final_write_processing \
2027 _bfd_mips_elf_final_write_processing
2028 #define elf_backend_additional_program_headers \
2029 _bfd_mips_elf_additional_program_headers
2030 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
2031 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
2032 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
2033 #define elf_backend_copy_indirect_symbol \
2034 _bfd_mips_elf_copy_indirect_symbol
2035 #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol
2036 #define elf_backend_grok_prstatus elf32_mips_grok_prstatus
2037 #define elf_backend_grok_psinfo elf32_mips_grok_psinfo
2038 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap
2040 #define elf_backend_got_header_size (4 * MIPS_RESERVED_GOTNO)
2041 #define elf_backend_plt_header_size 0
2042 #define elf_backend_may_use_rel_p 1
2043 #define elf_backend_may_use_rela_p 0
2044 #define elf_backend_default_use_rela_p 0
2045 #define elf_backend_sign_extend_vma true
2047 #define elf_backend_discard_info elf32_mips_discard_info
2048 #define elf_backend_ignore_discarded_relocs \
2049 _bfd_mips_elf_ignore_discarded_relocs
2050 #define elf_backend_write_section elf32_mips_write_section
2051 #define elf_backend_mips_irix_compat elf32_mips_irix_compat
2052 #define elf_backend_mips_rtype_to_howto mips_elf32_rtype_to_howto
2053 #define bfd_elf32_bfd_is_local_label_name \
2054 mips_elf_is_local_label_name
2055 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line
2056 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents
2057 #define bfd_elf32_bfd_get_relocated_section_contents \
2058 _bfd_elf_mips_get_relocated_section_contents
2059 #define bfd_elf32_bfd_link_hash_table_create \
2060 _bfd_mips_elf_link_hash_table_create
2061 #define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link
2062 #define bfd_elf32_bfd_merge_private_bfd_data \
2063 _bfd_mips_elf_merge_private_bfd_data
2064 #define bfd_elf32_bfd_set_private_flags _bfd_mips_elf_set_private_flags
2065 #define bfd_elf32_bfd_print_private_bfd_data \
2066 _bfd_mips_elf_print_private_bfd_data
2068 /* Support for SGI-ish mips targets. */
2069 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
2070 #define TARGET_LITTLE_NAME "elf32-littlemips"
2071 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
2072 #define TARGET_BIG_NAME "elf32-bigmips"
2074 #include "elf32-target.h"
2076 /* Support for traditional mips targets. */
2077 #define INCLUDED_TARGET_FILE /* More a type of flag. */
2079 #undef TARGET_LITTLE_SYM
2080 #undef TARGET_LITTLE_NAME
2081 #undef TARGET_BIG_SYM
2082 #undef TARGET_BIG_NAME
2084 #define TARGET_LITTLE_SYM bfd_elf32_tradlittlemips_vec
2085 #define TARGET_LITTLE_NAME "elf32-tradlittlemips"
2086 #define TARGET_BIG_SYM bfd_elf32_tradbigmips_vec
2087 #define TARGET_BIG_NAME "elf32-tradbigmips"
2089 /* Include the target file again for this target. */
2090 #include "elf32-target.h"