1 /* MIPS-specific support for 64-bit ELF
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Ian Lance Taylor, Cygnus Support
5 Linker support added by Mark Mitchell, CodeSourcery, LLC.
6 <mark@codesourcery.com>
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 /* This file supports the 64-bit MIPS ELF ABI.
26 The MIPS 64-bit ELF ABI uses an unusual reloc format. This file
27 overrides the usual ELF reloc handling, and handles reading and
28 writing the relocations here.
30 The MIPS 64-bit ELF ABI also uses an unusual archive map format. */
41 /* Get the ECOFF swapping routines. The 64-bit ABI is not supposed to
42 use ECOFF. However, we support it anyhow for an easier changeover. */
44 #include "coff/symconst.h"
45 #include "coff/internal.h"
46 #include "coff/ecoff.h"
47 /* The 64 bit versions of the mdebug data structures are in alpha.h. */
48 #include "coff/alpha.h"
49 #define ECOFF_SIGNED_64
50 #include "ecoffswap.h"
52 static void mips_elf64_swap_reloc_in
53 PARAMS ((bfd *, const Elf64_Mips_External_Rel *,
54 Elf64_Mips_Internal_Rel *));
55 static void mips_elf64_swap_reloca_in
56 PARAMS ((bfd *, const Elf64_Mips_External_Rela *,
57 Elf64_Mips_Internal_Rela *));
58 static void mips_elf64_swap_reloc_out
59 PARAMS ((bfd *, const Elf64_Mips_Internal_Rel *,
60 Elf64_Mips_External_Rel *));
61 static void mips_elf64_swap_reloca_out
62 PARAMS ((bfd *, const Elf64_Mips_Internal_Rela *,
63 Elf64_Mips_External_Rela *));
64 static void mips_elf64_be_swap_reloc_in
65 PARAMS ((bfd *, const bfd_byte *, Elf_Internal_Rel *));
66 static void mips_elf64_be_swap_reloc_out
67 PARAMS ((bfd *, const Elf_Internal_Rel *, bfd_byte *));
68 static void mips_elf64_be_swap_reloca_in
69 PARAMS ((bfd *, const bfd_byte *, Elf_Internal_Rela *));
70 static void mips_elf64_be_swap_reloca_out
71 PARAMS ((bfd *, const Elf_Internal_Rela *, bfd_byte *));
72 static reloc_howto_type *mips_elf64_reloc_type_lookup
73 PARAMS ((bfd *, bfd_reloc_code_real_type));
74 static long mips_elf64_get_reloc_upper_bound PARAMS ((bfd *, asection *));
75 static boolean mips_elf64_slurp_one_reloc_table
76 PARAMS ((bfd *, asection *, asymbol **, const Elf_Internal_Shdr *));
77 static boolean mips_elf64_slurp_reloc_table
78 PARAMS ((bfd *, asection *, asymbol **, boolean));
79 static void mips_elf64_write_relocs PARAMS ((bfd *, asection *, PTR));
80 static boolean mips_elf64_slurp_armap PARAMS ((bfd *));
81 static boolean mips_elf64_write_armap
82 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
84 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
85 from smaller values. Start with zero, widen, *then* decrement. */
86 #define MINUS_ONE (((bfd_vma)0) - 1)
88 /* The number of local .got entries we reserve. */
89 #define MIPS_RESERVED_GOTNO (2)
91 /* The relocation table used for SHT_REL sections. */
93 #define UNUSED_RELOC(num) { num, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
95 static reloc_howto_type mips_elf64_howto_table_rel[] =
98 HOWTO (R_MIPS_NONE, /* type */
100 0, /* size (0 = byte, 1 = short, 2 = long) */
102 false, /* pc_relative */
104 complain_overflow_dont, /* complain_on_overflow */
105 bfd_elf_generic_reloc, /* special_function */
106 "R_MIPS_NONE", /* name */
107 false, /* partial_inplace */
110 false), /* pcrel_offset */
112 /* 16 bit relocation. */
113 HOWTO (R_MIPS_16, /* type */
115 1, /* size (0 = byte, 1 = short, 2 = long) */
117 false, /* pc_relative */
119 complain_overflow_bitfield, /* complain_on_overflow */
120 bfd_elf_generic_reloc, /* special_function */
121 "R_MIPS_16", /* name */
122 true, /* partial_inplace */
123 0xffff, /* src_mask */
124 0xffff, /* dst_mask */
125 false), /* pcrel_offset */
127 /* 32 bit relocation. */
128 HOWTO (R_MIPS_32, /* type */
130 2, /* size (0 = byte, 1 = short, 2 = long) */
132 false, /* pc_relative */
134 complain_overflow_dont, /* complain_on_overflow */
135 bfd_elf_generic_reloc, /* special_function */
136 "R_MIPS_32", /* name */
137 true, /* partial_inplace */
138 0xffffffff, /* src_mask */
139 0xffffffff, /* dst_mask */
140 false), /* pcrel_offset */
142 /* 32 bit symbol relative relocation. */
143 HOWTO (R_MIPS_REL32, /* 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_REL32", /* name */
152 true, /* partial_inplace */
153 0xffffffff, /* src_mask */
154 0xffffffff, /* dst_mask */
155 false), /* pcrel_offset */
157 /* 26 bit jump address. */
158 HOWTO (R_MIPS_26, /* type */
160 2, /* size (0 = byte, 1 = short, 2 = long) */
162 false, /* pc_relative */
164 complain_overflow_dont, /* complain_on_overflow */
165 /* This needs complex overflow
166 detection, because the upper 36
167 bits must match the PC + 4. */
168 bfd_elf_generic_reloc, /* special_function */
169 "R_MIPS_26", /* name */
170 true, /* partial_inplace */
171 0x3ffffff, /* src_mask */
172 0x3ffffff, /* dst_mask */
173 false), /* pcrel_offset */
175 /* High 16 bits of symbol value. */
176 HOWTO (R_MIPS_HI16, /* type */
178 2, /* size (0 = byte, 1 = short, 2 = long) */
180 false, /* pc_relative */
182 complain_overflow_dont, /* complain_on_overflow */
183 _bfd_mips_elf_hi16_reloc, /* special_function */
184 "R_MIPS_HI16", /* name */
185 true, /* partial_inplace */
186 0xffff, /* src_mask */
187 0xffff, /* dst_mask */
188 false), /* pcrel_offset */
190 /* Low 16 bits of symbol value. */
191 HOWTO (R_MIPS_LO16, /* type */
193 2, /* size (0 = byte, 1 = short, 2 = long) */
195 false, /* pc_relative */
197 complain_overflow_dont, /* complain_on_overflow */
198 _bfd_mips_elf_lo16_reloc, /* special_function */
199 "R_MIPS_LO16", /* name */
200 true, /* partial_inplace */
201 0xffff, /* src_mask */
202 0xffff, /* dst_mask */
203 false), /* pcrel_offset */
205 /* GP relative reference. */
206 HOWTO (R_MIPS_GPREL16, /* type */
208 2, /* size (0 = byte, 1 = short, 2 = long) */
210 false, /* pc_relative */
212 complain_overflow_signed, /* complain_on_overflow */
213 _bfd_mips_elf_gprel16_reloc, /* special_function */
214 "R_MIPS_GPREL16", /* name */
215 true, /* partial_inplace */
216 0xffff, /* src_mask */
217 0xffff, /* dst_mask */
218 false), /* pcrel_offset */
220 /* Reference to literal section. */
221 HOWTO (R_MIPS_LITERAL, /* type */
223 2, /* size (0 = byte, 1 = short, 2 = long) */
225 false, /* pc_relative */
227 complain_overflow_signed, /* complain_on_overflow */
228 _bfd_mips_elf_gprel16_reloc, /* special_function */
229 "R_MIPS_LITERAL", /* name */
230 true, /* partial_inplace */
231 0xffff, /* src_mask */
232 0xffff, /* dst_mask */
233 false), /* pcrel_offset */
235 /* Reference to global offset table. */
236 HOWTO (R_MIPS_GOT16, /* type */
238 2, /* size (0 = byte, 1 = short, 2 = long) */
240 false, /* pc_relative */
242 complain_overflow_signed, /* complain_on_overflow */
243 _bfd_mips_elf_got16_reloc, /* special_function */
244 "R_MIPS_GOT16", /* name */
245 false, /* partial_inplace */
247 0xffff, /* dst_mask */
248 false), /* pcrel_offset */
250 /* 16 bit PC relative reference. */
251 HOWTO (R_MIPS_PC16, /* type */
253 2, /* size (0 = byte, 1 = short, 2 = long) */
255 true, /* pc_relative */
257 complain_overflow_signed, /* complain_on_overflow */
258 bfd_elf_generic_reloc, /* special_function */
259 "R_MIPS_PC16", /* name */
260 true, /* partial_inplace */
261 0xffff, /* src_mask */
262 0xffff, /* dst_mask */
263 false), /* pcrel_offset */
265 /* 16 bit call through global offset table. */
266 /* FIXME: This is not handled correctly. */
267 HOWTO (R_MIPS_CALL16, /* type */
269 2, /* size (0 = byte, 1 = short, 2 = long) */
271 false, /* pc_relative */
273 complain_overflow_signed, /* complain_on_overflow */
274 bfd_elf_generic_reloc, /* special_function */
275 "R_MIPS_CALL16", /* name */
276 false, /* partial_inplace */
278 0xffff, /* dst_mask */
279 false), /* pcrel_offset */
281 /* 32 bit GP relative reference. */
282 HOWTO (R_MIPS_GPREL32, /* type */
284 2, /* size (0 = byte, 1 = short, 2 = long) */
286 false, /* pc_relative */
288 complain_overflow_bitfield, /* complain_on_overflow */
289 _bfd_mips_elf_gprel32_reloc, /* special_function */
290 "R_MIPS_GPREL32", /* name */
291 true, /* partial_inplace */
292 0xffffffff, /* src_mask */
293 0xffffffff, /* dst_mask */
294 false), /* pcrel_offset */
300 /* A 5 bit shift field. */
301 HOWTO (R_MIPS_SHIFT5, /* type */
303 2, /* size (0 = byte, 1 = short, 2 = long) */
305 false, /* pc_relative */
307 complain_overflow_bitfield, /* complain_on_overflow */
308 bfd_elf_generic_reloc, /* special_function */
309 "R_MIPS_SHIFT5", /* name */
310 true, /* partial_inplace */
311 0x000007c0, /* src_mask */
312 0x000007c0, /* dst_mask */
313 false), /* pcrel_offset */
315 /* A 6 bit shift field. */
316 /* FIXME: This is not handled correctly; a special function is
317 needed to put the most significant bit in the right place. */
318 HOWTO (R_MIPS_SHIFT6, /* type */
320 2, /* size (0 = byte, 1 = short, 2 = long) */
322 false, /* pc_relative */
324 complain_overflow_bitfield, /* complain_on_overflow */
325 bfd_elf_generic_reloc, /* special_function */
326 "R_MIPS_SHIFT6", /* name */
327 true, /* partial_inplace */
328 0x000007c4, /* src_mask */
329 0x000007c4, /* dst_mask */
330 false), /* pcrel_offset */
332 /* 64 bit relocation. */
333 HOWTO (R_MIPS_64, /* type */
335 4, /* size (0 = byte, 1 = short, 2 = long) */
337 false, /* pc_relative */
339 complain_overflow_dont, /* complain_on_overflow */
340 bfd_elf_generic_reloc, /* special_function */
341 "R_MIPS_64", /* name */
342 true, /* partial_inplace */
343 MINUS_ONE, /* src_mask */
344 MINUS_ONE, /* dst_mask */
345 false), /* pcrel_offset */
347 /* Displacement in the global offset table. */
348 /* FIXME: Not handled correctly. */
349 HOWTO (R_MIPS_GOT_DISP, /* type */
351 2, /* size (0 = byte, 1 = short, 2 = long) */
353 false, /* pc_relative */
355 complain_overflow_signed, /* complain_on_overflow */
356 bfd_elf_generic_reloc, /* special_function */
357 "R_MIPS_GOT_DISP", /* name */
358 false, /* partial_inplace */
359 0x0000ffff, /* src_mask */
360 0x0000ffff, /* dst_mask */
361 false), /* pcrel_offset */
363 /* Displacement to page pointer in the global offset table. */
364 /* FIXME: Not handled correctly. */
365 HOWTO (R_MIPS_GOT_PAGE, /* type */
367 2, /* size (0 = byte, 1 = short, 2 = long) */
369 false, /* pc_relative */
371 complain_overflow_signed, /* complain_on_overflow */
372 bfd_elf_generic_reloc, /* special_function */
373 "R_MIPS_GOT_PAGE", /* name */
374 false, /* partial_inplace */
375 0x0000ffff, /* src_mask */
376 0x0000ffff, /* dst_mask */
377 false), /* pcrel_offset */
379 /* Offset from page pointer in the global offset table. */
380 /* FIXME: Not handled correctly. */
381 HOWTO (R_MIPS_GOT_OFST, /* type */
383 2, /* size (0 = byte, 1 = short, 2 = long) */
385 false, /* pc_relative */
387 complain_overflow_signed, /* complain_on_overflow */
388 bfd_elf_generic_reloc, /* special_function */
389 "R_MIPS_GOT_OFST", /* name */
390 false, /* partial_inplace */
391 0x0000ffff, /* src_mask */
392 0x0000ffff, /* dst_mask */
393 false), /* pcrel_offset */
395 /* High 16 bits of displacement in global offset table. */
396 /* FIXME: Not handled correctly. */
397 HOWTO (R_MIPS_GOT_HI16, /* type */
399 2, /* size (0 = byte, 1 = short, 2 = long) */
401 false, /* pc_relative */
403 complain_overflow_dont, /* complain_on_overflow */
404 bfd_elf_generic_reloc, /* special_function */
405 "R_MIPS_GOT_HI16", /* name */
406 false, /* partial_inplace */
407 0x0000ffff, /* src_mask */
408 0x0000ffff, /* dst_mask */
409 false), /* pcrel_offset */
411 /* Low 16 bits of displacement in global offset table. */
412 /* FIXME: Not handled correctly. */
413 HOWTO (R_MIPS_GOT_LO16, /* type */
415 2, /* size (0 = byte, 1 = short, 2 = long) */
417 false, /* pc_relative */
419 complain_overflow_dont, /* complain_on_overflow */
420 bfd_elf_generic_reloc, /* special_function */
421 "R_MIPS_GOT_LO16", /* name */
422 false, /* partial_inplace */
423 0x0000ffff, /* src_mask */
424 0x0000ffff, /* dst_mask */
425 false), /* pcrel_offset */
427 /* 64 bit substraction. */
428 /* FIXME: Not handled correctly. */
429 HOWTO (R_MIPS_SUB, /* type */
431 4, /* size (0 = byte, 1 = short, 2 = long) */
433 false, /* pc_relative */
435 complain_overflow_dont, /* complain_on_overflow */
436 bfd_elf_generic_reloc, /* special_function */
437 "R_MIPS_SUB", /* name */
438 true, /* partial_inplace */
439 MINUS_ONE, /* src_mask */
440 MINUS_ONE, /* dst_mask */
441 false), /* pcrel_offset */
443 /* Insert the addend as an instruction. */
444 /* FIXME: Not handled correctly. */
445 HOWTO (R_MIPS_INSERT_A, /* type */
447 2, /* size (0 = byte, 1 = short, 2 = long) */
449 false, /* pc_relative */
451 complain_overflow_dont, /* complain_on_overflow */
452 bfd_elf_generic_reloc, /* special_function */
453 "R_MIPS_INSERT_A", /* name */
454 true, /* partial_inplace */
455 0xffffffff, /* src_mask */
456 0xffffffff, /* dst_mask */
457 false), /* pcrel_offset */
459 /* Insert the addend as an instruction, and change all relocations
460 to refer to the old instruction at the address. */
461 /* FIXME: Not handled correctly. */
462 HOWTO (R_MIPS_INSERT_B, /* type */
464 2, /* size (0 = byte, 1 = short, 2 = long) */
466 false, /* pc_relative */
468 complain_overflow_dont, /* complain_on_overflow */
469 bfd_elf_generic_reloc, /* special_function */
470 "R_MIPS_INSERT_B", /* name */
471 true, /* partial_inplace */
472 0xffffffff, /* src_mask */
473 0xffffffff, /* dst_mask */
474 false), /* pcrel_offset */
476 /* Delete a 32 bit instruction. */
477 /* FIXME: Not handled correctly. */
478 HOWTO (R_MIPS_DELETE, /* type */
480 2, /* size (0 = byte, 1 = short, 2 = long) */
482 false, /* pc_relative */
484 complain_overflow_dont, /* complain_on_overflow */
485 bfd_elf_generic_reloc, /* special_function */
486 "R_MIPS_DELETE", /* name */
487 true, /* partial_inplace */
488 0xffffffff, /* src_mask */
489 0xffffffff, /* dst_mask */
490 false), /* pcrel_offset */
492 /* Get the higher value of a 64 bit addend. */
493 HOWTO (R_MIPS_HIGHER, /* type */
495 2, /* size (0 = byte, 1 = short, 2 = long) */
497 false, /* pc_relative */
499 complain_overflow_dont, /* complain_on_overflow */
500 bfd_elf_generic_reloc, /* special_function */
501 "R_MIPS_HIGHER", /* name */
502 true, /* partial_inplace */
503 0xffff, /* src_mask */
504 0xffff, /* dst_mask */
505 false), /* pcrel_offset */
507 /* Get the highest value of a 64 bit addend. */
508 /* FIXME: Not handled correctly. */
509 HOWTO (R_MIPS_HIGHEST, /* type */
511 2, /* size (0 = byte, 1 = short, 2 = long) */
513 false, /* pc_relative */
515 complain_overflow_dont, /* complain_on_overflow */
516 bfd_elf_generic_reloc, /* special_function */
517 "R_MIPS_HIGHEST", /* name */
518 true, /* partial_inplace */
519 0xffff, /* src_mask */
520 0xffff, /* dst_mask */
521 false), /* pcrel_offset */
523 /* High 16 bits of displacement in global offset table. */
524 /* FIXME: Not handled correctly. */
525 HOWTO (R_MIPS_CALL_HI16, /* type */
527 2, /* size (0 = byte, 1 = short, 2 = long) */
529 false, /* pc_relative */
531 complain_overflow_dont, /* complain_on_overflow */
532 bfd_elf_generic_reloc, /* special_function */
533 "R_MIPS_CALL_HI16", /* name */
534 true, /* partial_inplace */
535 0xffff, /* src_mask */
536 0xffff, /* dst_mask */
537 false), /* pcrel_offset */
539 /* Low 16 bits of displacement in global offset table. */
540 /* FIXME: Not handled correctly. */
541 HOWTO (R_MIPS_CALL_LO16, /* type */
543 2, /* size (0 = byte, 1 = short, 2 = long) */
545 false, /* pc_relative */
547 complain_overflow_dont, /* complain_on_overflow */
548 bfd_elf_generic_reloc, /* special_function */
549 "R_MIPS_CALL_LO16", /* name */
550 true, /* partial_inplace */
551 0xffff, /* src_mask */
552 0xffff, /* dst_mask */
553 false), /* pcrel_offset */
555 /* I'm not sure what the remaining relocs are, but they are defined
558 HOWTO (R_MIPS_SCN_DISP, /* type */
560 2, /* size (0 = byte, 1 = short, 2 = long) */
562 false, /* pc_relative */
564 complain_overflow_dont, /* complain_on_overflow */
565 bfd_elf_generic_reloc, /* special_function */
566 "R_MIPS_SCN_DISP", /* name */
567 true, /* partial_inplace */
568 0xffffffff, /* src_mask */
569 0xffffffff, /* dst_mask */
570 false), /* pcrel_offset */
572 HOWTO (R_MIPS_REL16, /* type */
574 1, /* size (0 = byte, 1 = short, 2 = long) */
576 false, /* pc_relative */
578 complain_overflow_signed, /* complain_on_overflow */
579 bfd_elf_generic_reloc, /* special_function */
580 "R_MIPS_REL16", /* name */
581 true, /* partial_inplace */
582 0xffff, /* src_mask */
583 0xffff, /* dst_mask */
584 false), /* pcrel_offset */
586 /* These two are obsolete. */
587 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
588 EMPTY_HOWTO (R_MIPS_PJUMP),
590 HOWTO (R_MIPS_RELGOT, /* type */
592 2, /* size (0 = byte, 1 = short, 2 = long) */
594 false, /* pc_relative */
596 complain_overflow_dont, /* complain_on_overflow */
597 bfd_elf_generic_reloc, /* special_function */
598 "R_MIPS_RELGOT", /* name */
599 true, /* partial_inplace */
600 0xffffffff, /* src_mask */
601 0xffffffff, /* dst_mask */
602 false), /* pcrel_offset */
604 /* Protected jump conversion. This is an optimization hint. No
605 relocation is required for correctness. */
606 HOWTO (R_MIPS_JALR, /* type */
608 2, /* size (0 = byte, 1 = short, 2 = long) */
610 false, /* pc_relative */
612 complain_overflow_dont, /* complain_on_overflow */
613 bfd_elf_generic_reloc, /* special_function */
614 "R_MIPS_JALR", /* name */
615 false, /* partial_inplace */
618 false), /* pcrel_offset */
621 /* The relocation table used for SHT_RELA sections. */
623 static reloc_howto_type mips_elf64_howto_table_rela[] =
626 HOWTO (R_MIPS_NONE, /* type */
628 0, /* size (0 = byte, 1 = short, 2 = long) */
630 false, /* pc_relative */
632 complain_overflow_dont, /* complain_on_overflow */
633 bfd_elf_generic_reloc, /* special_function */
634 "R_MIPS_NONE", /* name */
635 false, /* partial_inplace */
638 false), /* pcrel_offset */
640 /* 16 bit relocation. */
641 HOWTO (R_MIPS_16, /* type */
643 1, /* size (0 = byte, 1 = short, 2 = long) */
645 false, /* pc_relative */
647 complain_overflow_bitfield, /* complain_on_overflow */
648 bfd_elf_generic_reloc, /* special_function */
649 "R_MIPS_16", /* name */
650 false, /* partial_inplace */
652 0xffff, /* dst_mask */
653 false), /* pcrel_offset */
655 /* 32 bit relocation. */
656 HOWTO (R_MIPS_32, /* type */
658 2, /* size (0 = byte, 1 = short, 2 = long) */
660 false, /* pc_relative */
662 complain_overflow_dont, /* complain_on_overflow */
663 bfd_elf_generic_reloc, /* special_function */
664 "R_MIPS_32", /* name */
665 false, /* partial_inplace */
667 0xffffffff, /* dst_mask */
668 false), /* pcrel_offset */
670 /* 32 bit symbol relative relocation. */
671 HOWTO (R_MIPS_REL32, /* type */
673 2, /* size (0 = byte, 1 = short, 2 = long) */
675 false, /* pc_relative */
677 complain_overflow_dont, /* complain_on_overflow */
678 bfd_elf_generic_reloc, /* special_function */
679 "R_MIPS_REL32", /* name */
680 false, /* partial_inplace */
682 0xffffffff, /* dst_mask */
683 false), /* pcrel_offset */
685 /* 26 bit jump address. */
686 HOWTO (R_MIPS_26, /* type */
688 2, /* size (0 = byte, 1 = short, 2 = long) */
690 false, /* pc_relative */
692 complain_overflow_dont, /* complain_on_overflow */
693 /* This needs complex overflow
694 detection, because the upper 36
695 bits must match the PC + 4. */
696 bfd_elf_generic_reloc, /* special_function */
697 "R_MIPS_26", /* name */
698 false, /* partial_inplace */
700 0x3ffffff, /* dst_mask */
701 false), /* pcrel_offset */
703 /* High 16 bits of symbol value. */
704 HOWTO (R_MIPS_HI16, /* type */
706 2, /* size (0 = byte, 1 = short, 2 = long) */
708 false, /* pc_relative */
710 complain_overflow_dont, /* complain_on_overflow */
711 bfd_elf_generic_reloc, /* special_function */
712 "R_MIPS_HI16", /* name */
713 false, /* partial_inplace */
715 0xffff, /* dst_mask */
716 false), /* pcrel_offset */
718 /* Low 16 bits of symbol value. */
719 HOWTO (R_MIPS_LO16, /* type */
721 2, /* size (0 = byte, 1 = short, 2 = long) */
723 false, /* pc_relative */
725 complain_overflow_dont, /* complain_on_overflow */
726 bfd_elf_generic_reloc, /* special_function */
727 "R_MIPS_LO16", /* name */
728 false, /* partial_inplace */
730 0xffff, /* dst_mask */
731 false), /* pcrel_offset */
733 /* GP relative reference. */
734 HOWTO (R_MIPS_GPREL16, /* type */
736 2, /* size (0 = byte, 1 = short, 2 = long) */
738 false, /* pc_relative */
740 complain_overflow_signed, /* complain_on_overflow */
741 _bfd_mips_elf_gprel16_reloc, /* special_function */
742 "R_MIPS_GPREL16", /* name */
743 true, /* partial_inplace */
745 0xffff, /* dst_mask */
746 false), /* pcrel_offset */
748 /* Reference to literal section. */
749 HOWTO (R_MIPS_LITERAL, /* type */
751 2, /* size (0 = byte, 1 = short, 2 = long) */
753 false, /* pc_relative */
755 complain_overflow_signed, /* complain_on_overflow */
756 _bfd_mips_elf_gprel16_reloc, /* special_function */
757 "R_MIPS_LITERAL", /* name */
758 true, /* partial_inplace */
760 0xffff, /* dst_mask */
761 false), /* pcrel_offset */
763 /* Reference to global offset table. */
764 /* FIXME: This is not handled correctly. */
765 HOWTO (R_MIPS_GOT16, /* type */
767 2, /* size (0 = byte, 1 = short, 2 = long) */
769 false, /* pc_relative */
771 complain_overflow_signed, /* complain_on_overflow */
772 bfd_elf_generic_reloc, /* special_function */
773 "R_MIPS_GOT16", /* name */
774 false, /* partial_inplace */
776 0xffff, /* dst_mask */
777 false), /* pcrel_offset */
779 /* 16 bit PC relative reference. */
780 HOWTO (R_MIPS_PC16, /* type */
782 2, /* size (0 = byte, 1 = short, 2 = long) */
784 true, /* pc_relative */
786 complain_overflow_signed, /* complain_on_overflow */
787 bfd_elf_generic_reloc, /* special_function */
788 "R_MIPS_PC16", /* name */
789 false, /* partial_inplace */
791 0xffff, /* dst_mask */
792 false), /* pcrel_offset */
794 /* 16 bit call through global offset table. */
795 /* FIXME: This is not handled correctly. */
796 HOWTO (R_MIPS_CALL16, /* type */
798 2, /* size (0 = byte, 1 = short, 2 = long) */
800 false, /* pc_relative */
802 complain_overflow_signed, /* complain_on_overflow */
803 bfd_elf_generic_reloc, /* special_function */
804 "R_MIPS_CALL16", /* name */
805 false, /* partial_inplace */
807 0xffff, /* dst_mask */
808 false), /* pcrel_offset */
810 /* 32 bit GP relative reference. */
811 HOWTO (R_MIPS_GPREL32, /* type */
813 2, /* size (0 = byte, 1 = short, 2 = long) */
815 false, /* pc_relative */
817 complain_overflow_bitfield, /* complain_on_overflow */
818 _bfd_mips_elf_gprel32_reloc, /* special_function */
819 "R_MIPS_GPREL32", /* name */
820 true, /* partial_inplace */
822 0xffffffff, /* dst_mask */
823 false), /* pcrel_offset */
829 /* A 5 bit shift field. */
830 HOWTO (R_MIPS_SHIFT5, /* type */
832 2, /* size (0 = byte, 1 = short, 2 = long) */
834 false, /* pc_relative */
836 complain_overflow_bitfield, /* complain_on_overflow */
837 bfd_elf_generic_reloc, /* special_function */
838 "R_MIPS_SHIFT5", /* name */
839 false, /* partial_inplace */
841 0x000007c0, /* dst_mask */
842 false), /* pcrel_offset */
844 /* A 6 bit shift field. */
845 /* FIXME: This is not handled correctly; a special function is
846 needed to put the most significant bit in the right place. */
847 HOWTO (R_MIPS_SHIFT6, /* type */
849 2, /* size (0 = byte, 1 = short, 2 = long) */
851 false, /* pc_relative */
853 complain_overflow_bitfield, /* complain_on_overflow */
854 bfd_elf_generic_reloc, /* special_function */
855 "R_MIPS_SHIFT6", /* name */
856 false, /* partial_inplace */
858 0x000007c4, /* dst_mask */
859 false), /* pcrel_offset */
861 /* 64 bit relocation. */
862 HOWTO (R_MIPS_64, /* type */
864 4, /* size (0 = byte, 1 = short, 2 = long) */
866 false, /* pc_relative */
868 complain_overflow_dont, /* complain_on_overflow */
869 bfd_elf_generic_reloc, /* special_function */
870 "R_MIPS_64", /* name */
871 false, /* partial_inplace */
873 MINUS_ONE, /* dst_mask */
874 false), /* pcrel_offset */
876 /* Displacement in the global offset table. */
877 /* FIXME: Not handled correctly. */
878 HOWTO (R_MIPS_GOT_DISP, /* type */
880 2, /* size (0 = byte, 1 = short, 2 = long) */
882 false, /* pc_relative */
884 complain_overflow_signed, /* complain_on_overflow */
885 bfd_elf_generic_reloc, /* special_function */
886 "R_MIPS_GOT_DISP", /* name */
887 false, /* partial_inplace */
889 0x0000ffff, /* dst_mask */
890 false), /* pcrel_offset */
892 /* Displacement to page pointer in the global offset table. */
893 /* FIXME: Not handled correctly. */
894 HOWTO (R_MIPS_GOT_PAGE, /* type */
896 2, /* size (0 = byte, 1 = short, 2 = long) */
898 false, /* pc_relative */
900 complain_overflow_signed, /* complain_on_overflow */
901 bfd_elf_generic_reloc, /* special_function */
902 "R_MIPS_GOT_PAGE", /* name */
903 false, /* partial_inplace */
905 0x0000ffff, /* dst_mask */
906 false), /* pcrel_offset */
908 /* Offset from page pointer in the global offset table. */
909 /* FIXME: Not handled correctly. */
910 HOWTO (R_MIPS_GOT_OFST, /* type */
912 2, /* size (0 = byte, 1 = short, 2 = long) */
914 false, /* pc_relative */
916 complain_overflow_signed, /* complain_on_overflow */
917 bfd_elf_generic_reloc, /* special_function */
918 "R_MIPS_GOT_OFST", /* name */
919 false, /* partial_inplace */
921 0x0000ffff, /* dst_mask */
922 false), /* pcrel_offset */
924 /* High 16 bits of displacement in global offset table. */
925 /* FIXME: Not handled correctly. */
926 HOWTO (R_MIPS_GOT_HI16, /* type */
928 2, /* size (0 = byte, 1 = short, 2 = long) */
930 false, /* pc_relative */
932 complain_overflow_dont, /* complain_on_overflow */
933 bfd_elf_generic_reloc, /* special_function */
934 "R_MIPS_GOT_HI16", /* name */
935 false, /* partial_inplace */
937 0x0000ffff, /* dst_mask */
938 false), /* pcrel_offset */
940 /* Low 16 bits of displacement in global offset table. */
941 /* FIXME: Not handled correctly. */
942 HOWTO (R_MIPS_GOT_LO16, /* type */
944 2, /* size (0 = byte, 1 = short, 2 = long) */
946 false, /* pc_relative */
948 complain_overflow_dont, /* complain_on_overflow */
949 bfd_elf_generic_reloc, /* special_function */
950 "R_MIPS_GOT_LO16", /* name */
951 false, /* partial_inplace */
953 0x0000ffff, /* dst_mask */
954 false), /* pcrel_offset */
956 /* 64 bit substraction. */
957 /* FIXME: Not handled correctly. */
958 HOWTO (R_MIPS_SUB, /* type */
960 4, /* size (0 = byte, 1 = short, 2 = long) */
962 false, /* pc_relative */
964 complain_overflow_dont, /* complain_on_overflow */
965 bfd_elf_generic_reloc, /* special_function */
966 "R_MIPS_SUB", /* name */
967 false, /* partial_inplace */
969 MINUS_ONE, /* dst_mask */
970 false), /* pcrel_offset */
972 /* Insert the addend as an instruction. */
973 /* FIXME: Not handled correctly. */
974 HOWTO (R_MIPS_INSERT_A, /* type */
976 2, /* size (0 = byte, 1 = short, 2 = long) */
978 false, /* pc_relative */
980 complain_overflow_dont, /* complain_on_overflow */
981 bfd_elf_generic_reloc, /* special_function */
982 "R_MIPS_INSERT_A", /* name */
983 false, /* partial_inplace */
985 0xffffffff, /* dst_mask */
986 false), /* pcrel_offset */
988 /* Insert the addend as an instruction, and change all relocations
989 to refer to the old instruction at the address. */
990 /* FIXME: Not handled correctly. */
991 HOWTO (R_MIPS_INSERT_B, /* type */
993 2, /* size (0 = byte, 1 = short, 2 = long) */
995 false, /* pc_relative */
997 complain_overflow_dont, /* complain_on_overflow */
998 bfd_elf_generic_reloc, /* special_function */
999 "R_MIPS_INSERT_B", /* name */
1000 false, /* partial_inplace */
1002 0xffffffff, /* dst_mask */
1003 false), /* pcrel_offset */
1005 /* Delete a 32 bit instruction. */
1006 /* FIXME: Not handled correctly. */
1007 HOWTO (R_MIPS_DELETE, /* type */
1009 2, /* size (0 = byte, 1 = short, 2 = long) */
1011 false, /* pc_relative */
1013 complain_overflow_dont, /* complain_on_overflow */
1014 bfd_elf_generic_reloc, /* special_function */
1015 "R_MIPS_DELETE", /* name */
1016 false, /* partial_inplace */
1018 0xffffffff, /* dst_mask */
1019 false), /* pcrel_offset */
1021 /* Get the higher value of a 64 bit addend. */
1022 HOWTO (R_MIPS_HIGHER, /* type */
1024 2, /* size (0 = byte, 1 = short, 2 = long) */
1026 false, /* pc_relative */
1028 complain_overflow_dont, /* complain_on_overflow */
1029 bfd_elf_generic_reloc, /* special_function */
1030 "R_MIPS_HIGHER", /* name */
1031 false, /* partial_inplace */
1033 0xffff, /* dst_mask */
1034 false), /* pcrel_offset */
1036 /* Get the highest value of a 64 bit addend. */
1037 HOWTO (R_MIPS_HIGHEST, /* type */
1039 2, /* size (0 = byte, 1 = short, 2 = long) */
1041 false, /* pc_relative */
1043 complain_overflow_dont, /* complain_on_overflow */
1044 bfd_elf_generic_reloc, /* special_function */
1045 "R_MIPS_HIGHEST", /* name */
1046 false, /* partial_inplace */
1048 0xffff, /* dst_mask */
1049 false), /* pcrel_offset */
1051 /* High 16 bits of displacement in global offset table. */
1052 /* FIXME: Not handled correctly. */
1053 HOWTO (R_MIPS_CALL_HI16, /* type */
1055 2, /* size (0 = byte, 1 = short, 2 = long) */
1057 false, /* pc_relative */
1059 complain_overflow_dont, /* complain_on_overflow */
1060 bfd_elf_generic_reloc, /* special_function */
1061 "R_MIPS_CALL_HI16", /* name */
1062 false, /* partial_inplace */
1064 0xffff, /* dst_mask */
1065 false), /* pcrel_offset */
1067 /* Low 16 bits of displacement in global offset table. */
1068 /* FIXME: Not handled correctly. */
1069 HOWTO (R_MIPS_CALL_LO16, /* type */
1071 2, /* size (0 = byte, 1 = short, 2 = long) */
1073 false, /* pc_relative */
1075 complain_overflow_dont, /* complain_on_overflow */
1076 bfd_elf_generic_reloc, /* special_function */
1077 "R_MIPS_CALL_LO16", /* name */
1078 false, /* partial_inplace */
1080 0xffff, /* dst_mask */
1081 false), /* pcrel_offset */
1083 /* I'm not sure what the remaining relocs are, but they are defined
1086 HOWTO (R_MIPS_SCN_DISP, /* type */
1088 2, /* size (0 = byte, 1 = short, 2 = long) */
1090 false, /* pc_relative */
1092 complain_overflow_dont, /* complain_on_overflow */
1093 bfd_elf_generic_reloc, /* special_function */
1094 "R_MIPS_SCN_DISP", /* name */
1095 false, /* partial_inplace */
1097 0xffffffff, /* dst_mask */
1098 false), /* pcrel_offset */
1100 HOWTO (R_MIPS_REL16, /* type */
1102 1, /* size (0 = byte, 1 = short, 2 = long) */
1104 false, /* pc_relative */
1106 complain_overflow_signed, /* complain_on_overflow */
1107 bfd_elf_generic_reloc, /* special_function */
1108 "R_MIPS_REL16", /* name */
1109 false, /* partial_inplace */
1111 0xffff, /* dst_mask */
1112 false), /* pcrel_offset */
1114 /* These two are obsolete. */
1115 EMPTY_HOWTO (R_MIPS_ADD_IMMEDIATE),
1116 EMPTY_HOWTO (R_MIPS_PJUMP),
1118 HOWTO (R_MIPS_RELGOT, /* type */
1120 2, /* size (0 = byte, 1 = short, 2 = long) */
1122 false, /* pc_relative */
1124 complain_overflow_dont, /* complain_on_overflow */
1125 bfd_elf_generic_reloc, /* special_function */
1126 "R_MIPS_RELGOT", /* name */
1127 false, /* partial_inplace */
1129 0xffffffff, /* dst_mask */
1130 false), /* pcrel_offset */
1132 /* Protected jump conversion. This is an optimization hint. No
1133 relocation is required for correctness. */
1134 HOWTO (R_MIPS_JALR, /* type */
1136 2, /* size (0 = byte, 1 = short, 2 = long) */
1138 false, /* pc_relative */
1140 complain_overflow_dont, /* complain_on_overflow */
1141 bfd_elf_generic_reloc, /* special_function */
1142 "R_MIPS_JALR", /* name */
1143 false, /* partial_inplace */
1146 false), /* pcrel_offset */
1149 /* Swap in a MIPS 64-bit Rel reloc. */
1152 mips_elf64_swap_reloc_in (abfd, src, dst)
1154 const Elf64_Mips_External_Rel *src;
1155 Elf64_Mips_Internal_Rel *dst;
1157 dst->r_offset = H_GET_64 (abfd, src->r_offset);
1158 dst->r_sym = H_GET_32 (abfd, src->r_sym);
1159 dst->r_ssym = H_GET_8 (abfd, src->r_ssym);
1160 dst->r_type3 = H_GET_8 (abfd, src->r_type3);
1161 dst->r_type2 = H_GET_8 (abfd, src->r_type2);
1162 dst->r_type = H_GET_8 (abfd, src->r_type);
1165 /* Swap in a MIPS 64-bit Rela reloc. */
1168 mips_elf64_swap_reloca_in (abfd, src, dst)
1170 const Elf64_Mips_External_Rela *src;
1171 Elf64_Mips_Internal_Rela *dst;
1173 dst->r_offset = H_GET_64 (abfd, src->r_offset);
1174 dst->r_sym = H_GET_32 (abfd, src->r_sym);
1175 dst->r_ssym = H_GET_8 (abfd, src->r_ssym);
1176 dst->r_type3 = H_GET_8 (abfd, src->r_type3);
1177 dst->r_type2 = H_GET_8 (abfd, src->r_type2);
1178 dst->r_type = H_GET_8 (abfd, src->r_type);
1179 dst->r_addend = H_GET_S64 (abfd, src->r_addend);
1182 /* Swap out a MIPS 64-bit Rel reloc. */
1185 mips_elf64_swap_reloc_out (abfd, src, dst)
1187 const Elf64_Mips_Internal_Rel *src;
1188 Elf64_Mips_External_Rel *dst;
1190 H_PUT_64 (abfd, src->r_offset, dst->r_offset);
1191 H_PUT_32 (abfd, src->r_sym, dst->r_sym);
1192 H_PUT_8 (abfd, src->r_ssym, dst->r_ssym);
1193 H_PUT_8 (abfd, src->r_type3, dst->r_type3);
1194 H_PUT_8 (abfd, src->r_type2, dst->r_type2);
1195 H_PUT_8 (abfd, src->r_type, dst->r_type);
1198 /* Swap out a MIPS 64-bit Rela reloc. */
1201 mips_elf64_swap_reloca_out (abfd, src, dst)
1203 const Elf64_Mips_Internal_Rela *src;
1204 Elf64_Mips_External_Rela *dst;
1206 H_PUT_64 (abfd, src->r_offset, dst->r_offset);
1207 H_PUT_32 (abfd, src->r_sym, dst->r_sym);
1208 H_PUT_8 (abfd, src->r_ssym, dst->r_ssym);
1209 H_PUT_8 (abfd, src->r_type3, dst->r_type3);
1210 H_PUT_8 (abfd, src->r_type2, dst->r_type2);
1211 H_PUT_8 (abfd, src->r_type, dst->r_type);
1212 H_PUT_64 (abfd, src->r_addend, dst->r_addend);
1215 /* Swap in a MIPS 64-bit Rel reloc. */
1218 mips_elf64_be_swap_reloc_in (abfd, src, dst)
1220 const bfd_byte *src;
1221 Elf_Internal_Rel *dst;
1223 Elf64_Mips_Internal_Rel mirel;
1225 mips_elf64_swap_reloc_in (abfd,
1226 (const Elf64_Mips_External_Rel *) src,
1229 dst[0].r_offset = mirel.r_offset;
1230 dst[0].r_info = ELF32_R_INFO (mirel.r_sym, mirel.r_type);
1231 dst[1].r_offset = mirel.r_offset;
1232 dst[1].r_info = ELF32_R_INFO (mirel.r_ssym, mirel.r_type2);
1233 dst[2].r_offset = mirel.r_offset;
1234 dst[2].r_info = ELF32_R_INFO (STN_UNDEF, mirel.r_type3);
1237 /* Swap in a MIPS 64-bit Rela reloc. */
1240 mips_elf64_be_swap_reloca_in (abfd, src, dst)
1242 const bfd_byte *src;
1243 Elf_Internal_Rela *dst;
1245 Elf64_Mips_Internal_Rela mirela;
1247 mips_elf64_swap_reloca_in (abfd,
1248 (const Elf64_Mips_External_Rela *) src,
1251 dst[0].r_offset = mirela.r_offset;
1252 dst[0].r_info = ELF32_R_INFO (mirela.r_sym, mirela.r_type);
1253 dst[0].r_addend = mirela.r_addend;
1254 dst[1].r_offset = mirela.r_offset;
1255 dst[1].r_info = ELF32_R_INFO (mirela.r_ssym, mirela.r_type2);
1256 dst[1].r_addend = 0;
1257 dst[2].r_offset = mirela.r_offset;
1258 dst[2].r_info = ELF32_R_INFO (STN_UNDEF, mirela.r_type3);
1259 dst[2].r_addend = 0;
1262 /* Swap out a MIPS 64-bit Rel reloc. */
1265 mips_elf64_be_swap_reloc_out (abfd, src, dst)
1267 const Elf_Internal_Rel *src;
1270 Elf64_Mips_Internal_Rel mirel;
1272 mirel.r_offset = src->r_offset;
1273 mirel.r_type = ELF32_R_TYPE (src->r_info);
1274 mirel.r_sym = ELF32_R_SYM (src->r_info);
1275 mirel.r_type2 = R_MIPS_NONE;
1276 mirel.r_ssym = STN_UNDEF;
1277 mirel.r_type3 = R_MIPS_NONE;
1279 mips_elf64_swap_reloc_out (abfd, &mirel,
1280 (Elf64_Mips_External_Rel *) dst);
1283 /* Swap out a MIPS 64-bit Rela reloc. */
1286 mips_elf64_be_swap_reloca_out (abfd, src, dst)
1288 const Elf_Internal_Rela *src;
1291 Elf64_Mips_Internal_Rela mirela;
1293 mirela.r_offset = src->r_offset;
1294 mirela.r_type = ELF32_R_TYPE (src->r_info);
1295 mirela.r_addend = src->r_addend;
1296 mirela.r_sym = ELF32_R_SYM (src->r_info);
1297 mirela.r_type2 = R_MIPS_NONE;
1298 mirela.r_ssym = STN_UNDEF;
1299 mirela.r_type3 = R_MIPS_NONE;
1301 mips_elf64_swap_reloca_out (abfd, &mirela,
1302 (Elf64_Mips_External_Rela *) dst);
1305 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1307 struct elf_reloc_map
1309 bfd_reloc_code_real_type bfd_reloc_val;
1310 enum elf_mips_reloc_type elf_reloc_val;
1313 static const struct elf_reloc_map mips_reloc_map[] =
1315 { BFD_RELOC_NONE, R_MIPS_NONE, },
1316 { BFD_RELOC_16, R_MIPS_16 },
1317 { BFD_RELOC_32, R_MIPS_32 },
1318 { BFD_RELOC_64, R_MIPS_64 },
1319 { BFD_RELOC_CTOR, R_MIPS_64 },
1320 { BFD_RELOC_32_PCREL, R_MIPS_REL32 },
1321 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
1322 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
1323 { BFD_RELOC_LO16, R_MIPS_LO16 },
1324 { BFD_RELOC_MIPS_GPREL, R_MIPS_GPREL16 },
1325 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
1326 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
1327 { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
1328 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
1329 { BFD_RELOC_MIPS_GPREL32, R_MIPS_GPREL32 },
1330 { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
1331 { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
1332 { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
1333 { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
1334 { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
1335 { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
1336 { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
1337 { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP }
1340 /* Given a BFD reloc type, return a howto structure. */
1342 static reloc_howto_type *
1343 mips_elf64_reloc_type_lookup (abfd, code)
1344 bfd *abfd ATTRIBUTE_UNUSED;
1345 bfd_reloc_code_real_type code;
1349 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); i++)
1351 if (mips_reloc_map[i].bfd_reloc_val == code)
1355 v = (int) mips_reloc_map[i].elf_reloc_val;
1356 return &mips_elf64_howto_table_rel[v];
1363 /* Since each entry in an SHT_REL or SHT_RELA section can represent up
1364 to three relocs, we must tell the user to allocate more space. */
1367 mips_elf64_get_reloc_upper_bound (abfd, sec)
1368 bfd *abfd ATTRIBUTE_UNUSED;
1371 return (sec->reloc_count * 3 + 1) * sizeof (arelent *);
1374 /* Read the relocations from one reloc section. */
1377 mips_elf64_slurp_one_reloc_table (abfd, asect, symbols, rel_hdr)
1381 const Elf_Internal_Shdr *rel_hdr;
1383 PTR allocated = NULL;
1384 bfd_byte *native_relocs;
1390 reloc_howto_type *howto_table;
1392 allocated = (PTR) bfd_malloc (rel_hdr->sh_size);
1393 if (allocated == NULL)
1396 if (bfd_seek (abfd, rel_hdr->sh_offset, SEEK_SET) != 0
1397 || (bfd_bread (allocated, rel_hdr->sh_size, abfd) != rel_hdr->sh_size))
1400 native_relocs = (bfd_byte *) allocated;
1402 relents = asect->relocation + asect->reloc_count;
1404 entsize = rel_hdr->sh_entsize;
1405 BFD_ASSERT (entsize == sizeof (Elf64_Mips_External_Rel)
1406 || entsize == sizeof (Elf64_Mips_External_Rela));
1408 count = rel_hdr->sh_size / entsize;
1410 if (entsize == sizeof (Elf64_Mips_External_Rel))
1411 howto_table = mips_elf64_howto_table_rel;
1413 howto_table = mips_elf64_howto_table_rela;
1416 for (i = 0; i < count; i++, native_relocs += entsize)
1418 Elf64_Mips_Internal_Rela rela;
1419 boolean used_sym, used_ssym;
1422 if (entsize == sizeof (Elf64_Mips_External_Rela))
1423 mips_elf64_swap_reloca_in (abfd,
1424 (Elf64_Mips_External_Rela *) native_relocs,
1428 Elf64_Mips_Internal_Rel rel;
1430 mips_elf64_swap_reloc_in (abfd,
1431 (Elf64_Mips_External_Rel *) native_relocs,
1433 rela.r_offset = rel.r_offset;
1434 rela.r_sym = rel.r_sym;
1435 rela.r_ssym = rel.r_ssym;
1436 rela.r_type3 = rel.r_type3;
1437 rela.r_type2 = rel.r_type2;
1438 rela.r_type = rel.r_type;
1442 /* Each entry represents up to three actual relocations. */
1446 for (ir = 0; ir < 3; ir++)
1448 enum elf_mips_reloc_type type;
1455 type = (enum elf_mips_reloc_type) rela.r_type;
1458 type = (enum elf_mips_reloc_type) rela.r_type2;
1461 type = (enum elf_mips_reloc_type) rela.r_type3;
1465 if (type == R_MIPS_NONE)
1467 /* There are no more relocations in this entry. If this
1468 is the first entry, we need to generate a dummy
1469 relocation so that the generic linker knows that
1470 there has been a break in the sequence of relocations
1471 applying to a particular address. */
1474 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
1475 if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
1476 relent->address = rela.r_offset;
1478 relent->address = rela.r_offset - asect->vma;
1480 relent->howto = &howto_table[(int) R_MIPS_NONE];
1486 /* Some types require symbols, whereas some do not. */
1490 case R_MIPS_LITERAL:
1491 case R_MIPS_INSERT_A:
1492 case R_MIPS_INSERT_B:
1494 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
1500 if (rela.r_sym == 0)
1501 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
1506 ps = symbols + rela.r_sym - 1;
1508 if ((s->flags & BSF_SECTION_SYM) == 0)
1509 relent->sym_ptr_ptr = ps;
1511 relent->sym_ptr_ptr = s->section->symbol_ptr_ptr;
1516 else if (! used_ssym)
1518 switch (rela.r_ssym)
1521 relent->sym_ptr_ptr =
1522 bfd_abs_section_ptr->symbol_ptr_ptr;
1528 /* FIXME: I think these need to be handled using
1529 special howto structures. */
1541 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
1546 /* The address of an ELF reloc is section relative for an
1547 object file, and absolute for an executable file or
1548 shared library. The address of a BFD reloc is always
1549 section relative. */
1550 if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
1551 relent->address = rela.r_offset;
1553 relent->address = rela.r_offset - asect->vma;
1555 relent->addend = rela.r_addend;
1557 relent->howto = &howto_table[(int) type];
1563 asect->reloc_count += relent - relents;
1565 if (allocated != NULL)
1571 if (allocated != NULL)
1576 /* Read the relocations. On Irix 6, there can be two reloc sections
1577 associated with a single data section. */
1580 mips_elf64_slurp_reloc_table (abfd, asect, symbols, dynamic)
1587 struct bfd_elf_section_data * const d = elf_section_data (asect);
1591 bfd_set_error (bfd_error_invalid_operation);
1595 if (asect->relocation != NULL
1596 || (asect->flags & SEC_RELOC) == 0
1597 || asect->reloc_count == 0)
1600 /* Allocate space for 3 arelent structures for each Rel structure. */
1601 amt = asect->reloc_count;
1602 amt *= 3 * sizeof (arelent);
1603 asect->relocation = (arelent *) bfd_alloc (abfd, amt);
1604 if (asect->relocation == NULL)
1607 /* The slurp_one_reloc_table routine increments reloc_count. */
1608 asect->reloc_count = 0;
1610 if (! mips_elf64_slurp_one_reloc_table (abfd, asect, symbols, &d->rel_hdr))
1612 if (d->rel_hdr2 != NULL)
1614 if (! mips_elf64_slurp_one_reloc_table (abfd, asect, symbols,
1622 /* Write out the relocations. */
1625 mips_elf64_write_relocs (abfd, sec, data)
1630 boolean *failedp = (boolean *) data;
1632 Elf_Internal_Shdr *rela_hdr;
1633 Elf64_Mips_External_Rela *ext_rela;
1635 asymbol *last_sym = 0;
1636 int last_sym_idx = 0;
1638 /* If we have already failed, don't do anything. */
1642 if ((sec->flags & SEC_RELOC) == 0)
1645 /* The linker backend writes the relocs out itself, and sets the
1646 reloc_count field to zero to inhibit writing them here. Also,
1647 sometimes the SEC_RELOC flag gets set even when there aren't any
1649 if (sec->reloc_count == 0)
1652 /* We can combine up to three relocs that refer to the same address
1653 if the latter relocs have no associated symbol. */
1655 for (idx = 0; idx < sec->reloc_count; idx++)
1662 addr = sec->orelocation[idx]->address;
1663 for (i = 0; i < 2; i++)
1667 if (idx + 1 >= sec->reloc_count)
1669 r = sec->orelocation[idx + 1];
1670 if (r->address != addr
1671 || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
1672 || (*r->sym_ptr_ptr)->value != 0)
1675 /* We can merge the reloc at IDX + 1 with the reloc at IDX. */
1681 rela_hdr = &elf_section_data (sec)->rel_hdr;
1683 rela_hdr->sh_size = rela_hdr->sh_entsize * count;
1684 rela_hdr->contents = (PTR) bfd_alloc (abfd, rela_hdr->sh_size);
1685 if (rela_hdr->contents == NULL)
1691 ext_rela = (Elf64_Mips_External_Rela *) rela_hdr->contents;
1692 for (idx = 0; idx < sec->reloc_count; idx++, ext_rela++)
1695 Elf64_Mips_Internal_Rela int_rela;
1700 ptr = sec->orelocation[idx];
1702 /* The address of an ELF reloc is section relative for an object
1703 file, and absolute for an executable file or shared library.
1704 The address of a BFD reloc is always section relative. */
1705 if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
1706 int_rela.r_offset = ptr->address;
1708 int_rela.r_offset = ptr->address + sec->vma;
1710 sym = *ptr->sym_ptr_ptr;
1711 if (sym == last_sym)
1716 n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
1727 int_rela.r_addend = ptr->addend;
1729 int_rela.r_ssym = RSS_UNDEF;
1731 if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
1732 && ! _bfd_elf_validate_reloc (abfd, ptr))
1738 int_rela.r_type = ptr->howto->type;
1739 int_rela.r_type2 = (int) R_MIPS_NONE;
1740 int_rela.r_type3 = (int) R_MIPS_NONE;
1742 for (i = 0; i < 2; i++)
1746 if (idx + 1 >= sec->reloc_count)
1748 r = sec->orelocation[idx + 1];
1749 if (r->address != ptr->address
1750 || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
1751 || (*r->sym_ptr_ptr)->value != 0)
1754 /* We can merge the reloc at IDX + 1 with the reloc at IDX. */
1757 int_rela.r_type2 = r->howto->type;
1759 int_rela.r_type3 = r->howto->type;
1764 mips_elf64_swap_reloca_out (abfd, &int_rela, ext_rela);
1767 BFD_ASSERT (ext_rela - (Elf64_Mips_External_Rela *) rela_hdr->contents
1771 /* Irix 6 defines a brand new archive map format, so that they can
1772 have archives more than 4 GB in size. */
1774 /* Read an Irix 6 armap. */
1777 mips_elf64_slurp_armap (abfd)
1780 struct artdata *ardata = bfd_ardata (abfd);
1783 bfd_size_type i, parsed_size, nsymz, stringsize, carsym_size, ptrsize;
1784 struct areltdata *mapdata;
1785 bfd_byte int_buf[8];
1787 bfd_byte *raw_armap = NULL;
1791 ardata->symdefs = NULL;
1793 /* Get the name of the first element. */
1794 arhdrpos = bfd_tell (abfd);
1795 i = bfd_bread ((PTR) nextname, (bfd_size_type) 16, abfd);
1801 if (bfd_seek (abfd, (file_ptr) -16, SEEK_CUR) != 0)
1804 /* Archives with traditional armaps are still permitted. */
1805 if (strncmp (nextname, "/ ", 16) == 0)
1806 return bfd_slurp_armap (abfd);
1808 if (strncmp (nextname, "/SYM64/ ", 16) != 0)
1810 bfd_has_map (abfd) = false;
1814 mapdata = (struct areltdata *) _bfd_read_ar_hdr (abfd);
1815 if (mapdata == NULL)
1817 parsed_size = mapdata->parsed_size;
1818 bfd_release (abfd, (PTR) mapdata);
1820 if (bfd_bread (int_buf, (bfd_size_type) 8, abfd) != 8)
1822 if (bfd_get_error () != bfd_error_system_call)
1823 bfd_set_error (bfd_error_malformed_archive);
1827 nsymz = bfd_getb64 (int_buf);
1828 stringsize = parsed_size - 8 * nsymz - 8;
1830 carsym_size = nsymz * sizeof (carsym);
1831 ptrsize = 8 * nsymz;
1833 amt = carsym_size + stringsize + 1;
1834 ardata->symdefs = (carsym *) bfd_zalloc (abfd, amt);
1835 if (ardata->symdefs == NULL)
1837 carsyms = ardata->symdefs;
1838 stringbase = ((char *) ardata->symdefs) + carsym_size;
1840 raw_armap = (bfd_byte *) bfd_alloc (abfd, ptrsize);
1841 if (raw_armap == NULL)
1844 if (bfd_bread (raw_armap, ptrsize, abfd) != ptrsize
1845 || bfd_bread (stringbase, stringsize, abfd) != stringsize)
1847 if (bfd_get_error () != bfd_error_system_call)
1848 bfd_set_error (bfd_error_malformed_archive);
1852 for (i = 0; i < nsymz; i++)
1854 carsyms->file_offset = bfd_getb64 (raw_armap + i * 8);
1855 carsyms->name = stringbase;
1856 stringbase += strlen (stringbase) + 1;
1861 ardata->symdef_count = nsymz;
1862 ardata->first_file_filepos = arhdrpos + sizeof (struct ar_hdr) + parsed_size;
1864 bfd_has_map (abfd) = true;
1865 bfd_release (abfd, raw_armap);
1870 if (raw_armap != NULL)
1871 bfd_release (abfd, raw_armap);
1872 if (ardata->symdefs != NULL)
1873 bfd_release (abfd, ardata->symdefs);
1877 /* Write out an Irix 6 armap. The Irix 6 tools are supposed to be
1878 able to handle ordinary ELF armaps, but at least on Irix 6.2 the
1882 mips_elf64_write_armap (arch, elength, map, symbol_count, stridx)
1884 unsigned int elength;
1886 unsigned int symbol_count;
1889 unsigned int ranlibsize = (symbol_count * 8) + 8;
1890 unsigned int stringsize = stridx;
1891 unsigned int mapsize = stringsize + ranlibsize;
1892 file_ptr archive_member_file_ptr;
1893 bfd *current = arch->archive_head;
1900 padding = BFD_ALIGN (mapsize, 8) - mapsize;
1903 /* work out where the first object file will go in the archive */
1904 archive_member_file_ptr = (mapsize
1906 + sizeof (struct ar_hdr)
1909 memset ((char *) (&hdr), 0, sizeof (struct ar_hdr));
1910 strcpy (hdr.ar_name, "/SYM64/");
1911 sprintf (hdr.ar_size, "%-10d", (int) mapsize);
1912 sprintf (hdr.ar_date, "%ld", (long) time (NULL));
1913 /* This, at least, is what Intel coff sets the values to.: */
1914 sprintf ((hdr.ar_uid), "%d", 0);
1915 sprintf ((hdr.ar_gid), "%d", 0);
1916 sprintf ((hdr.ar_mode), "%-7o", (unsigned) 0);
1917 strncpy (hdr.ar_fmag, ARFMAG, 2);
1919 for (i = 0; i < sizeof (struct ar_hdr); i++)
1920 if (((char *) (&hdr))[i] == '\0')
1921 (((char *) (&hdr))[i]) = ' ';
1923 /* Write the ar header for this item and the number of symbols */
1925 if (bfd_bwrite ((PTR) &hdr, (bfd_size_type) sizeof (struct ar_hdr), arch)
1926 != sizeof (struct ar_hdr))
1929 bfd_putb64 ((bfd_vma) symbol_count, buf);
1930 if (bfd_bwrite (buf, (bfd_size_type) 8, arch) != 8)
1933 /* Two passes, first write the file offsets for each symbol -
1934 remembering that each offset is on a two byte boundary. */
1936 /* Write out the file offset for the file associated with each
1937 symbol, and remember to keep the offsets padded out. */
1939 current = arch->archive_head;
1941 while (current != (bfd *) NULL && count < symbol_count)
1943 /* For each symbol which is used defined in this object, write out
1944 the object file's address in the archive */
1946 while (map[count].u.abfd == current)
1948 bfd_putb64 ((bfd_vma) archive_member_file_ptr, buf);
1949 if (bfd_bwrite (buf, (bfd_size_type) 8, arch) != 8)
1953 /* Add size of this archive entry */
1954 archive_member_file_ptr += (arelt_size (current)
1955 + sizeof (struct ar_hdr));
1956 /* remember about the even alignment */
1957 archive_member_file_ptr += archive_member_file_ptr % 2;
1958 current = current->next;
1961 /* now write the strings themselves */
1962 for (count = 0; count < symbol_count; count++)
1964 size_t len = strlen (*map[count].name) + 1;
1966 if (bfd_bwrite (*map[count].name, (bfd_size_type) len, arch) != len)
1970 /* The spec says that this should be padded to an 8 byte boundary.
1971 However, the Irix 6.2 tools do not appear to do this. */
1972 while (padding != 0)
1974 if (bfd_bwrite ("", (bfd_size_type) 1, arch) != 1)
1982 /* ECOFF swapping routines. These are used when dealing with the
1983 .mdebug section, which is in the ECOFF debugging format. */
1984 static const struct ecoff_debug_swap mips_elf64_ecoff_debug_swap =
1986 /* Symbol table magic number. */
1988 /* Alignment of debugging information. E.g., 4. */
1990 /* Sizes of external symbolic information. */
1991 sizeof (struct hdr_ext),
1992 sizeof (struct dnr_ext),
1993 sizeof (struct pdr_ext),
1994 sizeof (struct sym_ext),
1995 sizeof (struct opt_ext),
1996 sizeof (struct fdr_ext),
1997 sizeof (struct rfd_ext),
1998 sizeof (struct ext_ext),
1999 /* Functions to swap in external symbolic data. */
2008 _bfd_ecoff_swap_tir_in,
2009 _bfd_ecoff_swap_rndx_in,
2010 /* Functions to swap out external symbolic data. */
2019 _bfd_ecoff_swap_tir_out,
2020 _bfd_ecoff_swap_rndx_out,
2021 /* Function to read in symbolic data. */
2022 _bfd_mips_elf_read_ecoff_info
2025 /* Relocations in the 64 bit MIPS ELF ABI are more complex than in
2026 standard ELF. This structure is used to redirect the relocation
2027 handling routines. */
2029 const struct elf_size_info mips_elf64_size_info =
2031 sizeof (Elf64_External_Ehdr),
2032 sizeof (Elf64_External_Phdr),
2033 sizeof (Elf64_External_Shdr),
2034 sizeof (Elf64_Mips_External_Rel),
2035 sizeof (Elf64_Mips_External_Rela),
2036 sizeof (Elf64_External_Sym),
2037 sizeof (Elf64_External_Dyn),
2038 sizeof (Elf_External_Note),
2039 4, /* hash-table entry size */
2040 3, /* internal relocations per external relocations */
2045 bfd_elf64_write_out_phdrs,
2046 bfd_elf64_write_shdrs_and_ehdr,
2047 mips_elf64_write_relocs,
2048 bfd_elf64_swap_symbol_out,
2049 mips_elf64_slurp_reloc_table,
2050 bfd_elf64_slurp_symbol_table,
2051 bfd_elf64_swap_dyn_in,
2052 bfd_elf64_swap_dyn_out,
2053 mips_elf64_be_swap_reloc_in,
2054 mips_elf64_be_swap_reloc_out,
2055 mips_elf64_be_swap_reloca_in,
2056 mips_elf64_be_swap_reloca_out
2059 #define TARGET_LITTLE_SYM bfd_elf64_littlemips_vec
2060 #define TARGET_LITTLE_NAME "elf64-littlemips"
2061 #define TARGET_BIG_SYM bfd_elf64_bigmips_vec
2062 #define TARGET_BIG_NAME "elf64-bigmips"
2063 #define ELF_ARCH bfd_arch_mips
2064 #define ELF_MACHINE_CODE EM_MIPS
2066 #define ELF_MAXPAGESIZE 0x1000
2068 #define elf_backend_collect true
2069 #define elf_backend_type_change_ok true
2070 #define elf_backend_can_gc_sections true
2071 #define elf_backend_size_info mips_elf64_size_info
2072 #define elf_backend_object_p _bfd_mips_elf_object_p
2073 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
2074 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
2075 #define elf_backend_section_from_bfd_section \
2076 _bfd_mips_elf_section_from_bfd_section
2077 #define elf_backend_section_processing _bfd_mips_elf_section_processing
2078 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
2079 #define elf_backend_additional_program_headers \
2080 _bfd_mips_elf_additional_program_headers
2081 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
2082 #define elf_backend_final_write_processing \
2083 _bfd_mips_elf_final_write_processing
2084 #define elf_backend_ecoff_debug_swap &mips_elf64_ecoff_debug_swap
2085 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
2086 #define elf_backend_create_dynamic_sections \
2087 _bfd_mips_elf_create_dynamic_sections
2088 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
2089 #define elf_backend_adjust_dynamic_symbol \
2090 _bfd_mips_elf_adjust_dynamic_symbol
2091 #define elf_backend_always_size_sections \
2092 _bfd_mips_elf_always_size_sections
2093 #define elf_backend_size_dynamic_sections \
2094 _bfd_mips_elf_size_dynamic_sections
2095 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
2096 #define elf_backend_link_output_symbol_hook \
2097 _bfd_mips_elf_link_output_symbol_hook
2098 #define elf_backend_finish_dynamic_symbol \
2099 _bfd_mips_elf_finish_dynamic_symbol
2100 #define elf_backend_finish_dynamic_sections \
2101 _bfd_mips_elf_finish_dynamic_sections
2102 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
2103 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
2104 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
2105 #define elf_backend_plt_header_size 0
2106 #define elf_backend_may_use_rel_p 1
2108 /* We don't set bfd_elf64_bfd_is_local_label_name because the 32-bit
2109 MIPS-specific function only applies to IRIX5, which had no 64-bit
2111 #define bfd_elf64_find_nearest_line _bfd_mips_elf_find_nearest_line
2112 #define bfd_elf64_set_section_contents _bfd_mips_elf_set_section_contents
2113 #define bfd_elf64_bfd_link_hash_table_create \
2114 _bfd_mips_elf_link_hash_table_create
2115 #define bfd_elf64_bfd_final_link _bfd_mips_elf_final_link
2116 #define bfd_elf64_bfd_copy_private_bfd_data \
2117 _bfd_mips_elf_copy_private_bfd_data
2118 #define bfd_elf64_bfd_merge_private_bfd_data \
2119 _bfd_mips_elf_merge_private_bfd_data
2120 #define bfd_elf64_bfd_set_private_flags _bfd_mips_elf_set_private_flags
2121 #define bfd_elf64_bfd_print_private_bfd_data \
2122 _bfd_mips_elf_print_private_bfd_data
2124 #define bfd_elf64_get_reloc_upper_bound mips_elf64_get_reloc_upper_bound
2125 #define bfd_elf64_bfd_reloc_type_lookup mips_elf64_reloc_type_lookup
2126 #define bfd_elf64_archive_functions
2127 #define bfd_elf64_archive_slurp_armap mips_elf64_slurp_armap
2128 #define bfd_elf64_archive_slurp_extended_name_table \
2129 _bfd_archive_coff_slurp_extended_name_table
2130 #define bfd_elf64_archive_construct_extended_name_table \
2131 _bfd_archive_coff_construct_extended_name_table
2132 #define bfd_elf64_archive_truncate_arname \
2133 _bfd_archive_coff_truncate_arname
2134 #define bfd_elf64_archive_write_armap mips_elf64_write_armap
2135 #define bfd_elf64_archive_read_ar_hdr _bfd_archive_coff_read_ar_hdr
2136 #define bfd_elf64_archive_openr_next_archived_file \
2137 _bfd_archive_coff_openr_next_archived_file
2138 #define bfd_elf64_archive_get_elt_at_index \
2139 _bfd_archive_coff_get_elt_at_index
2140 #define bfd_elf64_archive_generic_stat_arch_elt \
2141 _bfd_archive_coff_generic_stat_arch_elt
2142 #define bfd_elf64_archive_update_armap_timestamp \
2143 _bfd_archive_coff_update_armap_timestamp
2145 #include "elf64-target.h"
2147 /* Support for traditional mips targets */
2149 #define INCLUDED_TARGET_FILE /* More a type of flag */
2151 #undef TARGET_LITTLE_SYM
2152 #undef TARGET_LITTLE_NAME
2153 #undef TARGET_BIG_SYM
2154 #undef TARGET_BIG_NAME
2156 #define TARGET_LITTLE_SYM bfd_elf64_tradlittlemips_vec
2157 #define TARGET_LITTLE_NAME "elf64-tradlittlemips"
2158 #define TARGET_BIG_SYM bfd_elf64_tradbigmips_vec
2159 #define TARGET_BIG_NAME "elf64-tradbigmips"
2161 /* Include the target file again for this target */
2162 #include "elf64-target.h"