1 /* MIPS-specific support for 64-bit ELF
2 Copyright 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
3 Ian Lance Taylor, Cygnus Support
4 Linker support added by Mark Mitchell, CodeSourcery, LLC.
5 <mark@codesourcery.com>
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* This file supports the 64-bit MIPS ELF ABI.
25 The MIPS 64-bit ELF ABI uses an unusual reloc format. This file
26 overrides the usual ELF reloc handling, and handles reading and
27 writing the relocations here.
29 The MIPS 64-bit ELF ABI also uses an unusual archive map format. */
40 /* Get the ECOFF swapping routines. The 64-bit ABI is not supposed to
41 use ECOFF. However, we support it anyhow for an easier changeover. */
43 #include "coff/symconst.h"
44 #include "coff/internal.h"
45 #include "coff/ecoff.h"
46 /* The 64 bit versions of the mdebug data structures are in alpha.h. */
47 #include "coff/alpha.h"
49 #include "ecoffswap.h"
51 static void mips_elf64_swap_reloc_in
52 PARAMS ((bfd *, const Elf64_Mips_External_Rel *,
53 Elf64_Mips_Internal_Rel *));
54 static void mips_elf64_swap_reloca_in
55 PARAMS ((bfd *, const Elf64_Mips_External_Rela *,
56 Elf64_Mips_Internal_Rela *));
57 static void mips_elf64_swap_reloc_out
58 PARAMS ((bfd *, const Elf64_Mips_Internal_Rel *,
59 Elf64_Mips_External_Rel *));
60 static void mips_elf64_swap_reloca_out
61 PARAMS ((bfd *, const Elf64_Mips_Internal_Rela *,
62 Elf64_Mips_External_Rela *));
63 static void mips_elf64_be_swap_reloc_in
64 PARAMS ((bfd *, const bfd_byte *, Elf_Internal_Rel *));
65 static void mips_elf64_be_swap_reloc_out
66 PARAMS ((bfd *, const Elf_Internal_Rel *, bfd_byte *));
67 static void mips_elf64_be_swap_reloca_in
68 PARAMS ((bfd *, const bfd_byte *, Elf_Internal_Rela *));
69 static void mips_elf64_be_swap_reloca_out
70 PARAMS ((bfd *, const Elf_Internal_Rela *, bfd_byte *));
71 static reloc_howto_type *mips_elf64_reloc_type_lookup
72 PARAMS ((bfd *, bfd_reloc_code_real_type));
73 static long mips_elf64_get_reloc_upper_bound PARAMS ((bfd *, asection *));
74 static boolean mips_elf64_slurp_one_reloc_table
75 PARAMS ((bfd *, asection *, asymbol **, const Elf_Internal_Shdr *));
76 static boolean mips_elf64_slurp_reloc_table
77 PARAMS ((bfd *, asection *, asymbol **, boolean));
78 static void mips_elf64_write_relocs PARAMS ((bfd *, asection *, PTR));
79 static boolean mips_elf64_slurp_armap PARAMS ((bfd *));
80 static boolean mips_elf64_write_armap
81 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
83 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
84 from smaller values. Start with zero, widen, *then* decrement. */
85 #define MINUS_ONE (((bfd_vma)0) - 1)
87 /* The number of local .got entries we reserve. */
88 #define MIPS_RESERVED_GOTNO (2)
90 /* The relocation table used for SHT_REL sections. */
92 static reloc_howto_type mips_elf64_howto_table_rel[] =
95 HOWTO (R_MIPS_NONE, /* type */
97 0, /* size (0 = byte, 1 = short, 2 = long) */
99 false, /* pc_relative */
101 complain_overflow_dont, /* complain_on_overflow */
102 bfd_elf_generic_reloc, /* special_function */
103 "R_MIPS_NONE", /* name */
104 false, /* partial_inplace */
107 false), /* pcrel_offset */
109 /* 16 bit relocation. */
110 HOWTO (R_MIPS_16, /* type */
112 1, /* size (0 = byte, 1 = short, 2 = long) */
114 false, /* pc_relative */
116 complain_overflow_bitfield, /* complain_on_overflow */
117 bfd_elf_generic_reloc, /* special_function */
118 "R_MIPS_16", /* name */
119 true, /* partial_inplace */
120 0xffff, /* src_mask */
121 0xffff, /* dst_mask */
122 false), /* pcrel_offset */
124 /* 32 bit relocation. */
125 HOWTO (R_MIPS_32, /* type */
127 2, /* size (0 = byte, 1 = short, 2 = long) */
129 false, /* pc_relative */
131 complain_overflow_bitfield, /* complain_on_overflow */
132 bfd_elf_generic_reloc, /* special_function */
133 "R_MIPS_32", /* name */
134 true, /* partial_inplace */
135 0xffffffff, /* src_mask */
136 0xffffffff, /* dst_mask */
137 false), /* pcrel_offset */
139 /* 32 bit symbol relative relocation. */
140 HOWTO (R_MIPS_REL32, /* type */
142 2, /* size (0 = byte, 1 = short, 2 = long) */
144 false, /* pc_relative */
146 complain_overflow_bitfield, /* complain_on_overflow */
147 bfd_elf_generic_reloc, /* special_function */
148 "R_MIPS_REL32", /* name */
149 true, /* partial_inplace */
150 0xffffffff, /* src_mask */
151 0xffffffff, /* dst_mask */
152 false), /* pcrel_offset */
154 /* 26 bit branch address. */
155 HOWTO (R_MIPS_26, /* type */
157 2, /* size (0 = byte, 1 = short, 2 = long) */
159 false, /* pc_relative */
161 complain_overflow_dont, /* complain_on_overflow */
162 /* This needs complex overflow
163 detection, because the upper four
164 bits must match the PC. */
165 bfd_elf_generic_reloc, /* special_function */
166 "R_MIPS_26", /* name */
167 true, /* partial_inplace */
168 0x3ffffff, /* src_mask */
169 0x3ffffff, /* dst_mask */
170 false), /* pcrel_offset */
172 /* High 16 bits of symbol value. */
173 HOWTO (R_MIPS_HI16, /* type */
175 2, /* size (0 = byte, 1 = short, 2 = long) */
177 false, /* pc_relative */
179 complain_overflow_dont, /* complain_on_overflow */
180 _bfd_mips_elf_hi16_reloc, /* special_function */
181 "R_MIPS_HI16", /* name */
182 true, /* partial_inplace */
183 0xffff, /* src_mask */
184 0xffff, /* dst_mask */
185 false), /* pcrel_offset */
187 /* Low 16 bits of symbol value. */
188 HOWTO (R_MIPS_LO16, /* type */
190 2, /* size (0 = byte, 1 = short, 2 = long) */
192 false, /* pc_relative */
194 complain_overflow_dont, /* complain_on_overflow */
195 _bfd_mips_elf_lo16_reloc, /* special_function */
196 "R_MIPS_LO16", /* name */
197 true, /* partial_inplace */
198 0xffff, /* src_mask */
199 0xffff, /* dst_mask */
200 false), /* pcrel_offset */
202 /* GP relative reference. */
203 HOWTO (R_MIPS_GPREL16, /* type */
205 2, /* size (0 = byte, 1 = short, 2 = long) */
207 false, /* pc_relative */
209 complain_overflow_signed, /* complain_on_overflow */
210 _bfd_mips_elf_gprel16_reloc, /* special_function */
211 "R_MIPS_GPREL16", /* name */
212 true, /* partial_inplace */
213 0xffff, /* src_mask */
214 0xffff, /* dst_mask */
215 false), /* pcrel_offset */
217 /* Reference to literal section. */
218 HOWTO (R_MIPS_LITERAL, /* type */
220 2, /* size (0 = byte, 1 = short, 2 = long) */
222 false, /* pc_relative */
224 complain_overflow_signed, /* complain_on_overflow */
225 _bfd_mips_elf_gprel16_reloc, /* special_function */
226 "R_MIPS_LITERAL", /* name */
227 true, /* partial_inplace */
228 0xffff, /* src_mask */
229 0xffff, /* dst_mask */
230 false), /* pcrel_offset */
232 /* Reference to global offset table. */
233 HOWTO (R_MIPS_GOT16, /* type */
235 2, /* size (0 = byte, 1 = short, 2 = long) */
237 false, /* pc_relative */
239 complain_overflow_signed, /* complain_on_overflow */
240 _bfd_mips_elf_got16_reloc, /* special_function */
241 "R_MIPS_GOT16", /* name */
242 false, /* partial_inplace */
244 0xffff, /* dst_mask */
245 false), /* pcrel_offset */
247 /* 16 bit PC relative reference. */
248 HOWTO (R_MIPS_PC16, /* type */
250 2, /* size (0 = byte, 1 = short, 2 = long) */
252 true, /* pc_relative */
254 complain_overflow_signed, /* complain_on_overflow */
255 bfd_elf_generic_reloc, /* special_function */
256 "R_MIPS_PC16", /* name */
257 true, /* partial_inplace */
258 0xffff, /* src_mask */
259 0xffff, /* dst_mask */
260 false), /* pcrel_offset */
262 /* 16 bit call through global offset table. */
263 /* FIXME: This is not handled correctly. */
264 HOWTO (R_MIPS_CALL16, /* type */
266 2, /* size (0 = byte, 1 = short, 2 = long) */
268 false, /* pc_relative */
270 complain_overflow_signed, /* complain_on_overflow */
271 bfd_elf_generic_reloc, /* special_function */
272 "R_MIPS_CALL16", /* name */
273 false, /* partial_inplace */
275 0xffff, /* dst_mask */
276 false), /* pcrel_offset */
278 /* 32 bit GP relative reference. */
279 HOWTO (R_MIPS_GPREL32, /* type */
281 2, /* size (0 = byte, 1 = short, 2 = long) */
283 false, /* pc_relative */
285 complain_overflow_bitfield, /* complain_on_overflow */
286 _bfd_mips_elf_gprel32_reloc, /* special_function */
287 "R_MIPS_GPREL32", /* name */
288 true, /* partial_inplace */
289 0xffffffff, /* src_mask */
290 0xffffffff, /* dst_mask */
291 false), /* pcrel_offset */
297 /* A 5 bit shift field. */
298 HOWTO (R_MIPS_SHIFT5, /* type */
300 2, /* size (0 = byte, 1 = short, 2 = long) */
302 false, /* pc_relative */
304 complain_overflow_bitfield, /* complain_on_overflow */
305 bfd_elf_generic_reloc, /* special_function */
306 "R_MIPS_SHIFT5", /* name */
307 true, /* partial_inplace */
308 0x000007c0, /* src_mask */
309 0x000007c0, /* dst_mask */
310 false), /* pcrel_offset */
312 /* A 6 bit shift field. */
313 /* FIXME: This is not handled correctly; a special function is
314 needed to put the most significant bit in the right place. */
315 HOWTO (R_MIPS_SHIFT6, /* type */
317 2, /* size (0 = byte, 1 = short, 2 = long) */
319 false, /* pc_relative */
321 complain_overflow_bitfield, /* complain_on_overflow */
322 bfd_elf_generic_reloc, /* special_function */
323 "R_MIPS_SHIFT6", /* name */
324 true, /* partial_inplace */
325 0x000007c4, /* src_mask */
326 0x000007c4, /* dst_mask */
327 false), /* pcrel_offset */
329 /* 64 bit relocation. */
330 HOWTO (R_MIPS_64, /* type */
332 4, /* size (0 = byte, 1 = short, 2 = long) */
334 false, /* pc_relative */
336 complain_overflow_bitfield, /* complain_on_overflow */
337 bfd_elf_generic_reloc, /* special_function */
338 "R_MIPS_64", /* name */
339 true, /* partial_inplace */
340 MINUS_ONE, /* src_mask */
341 MINUS_ONE, /* dst_mask */
342 false), /* pcrel_offset */
344 /* Displacement in the global offset table. */
345 /* FIXME: Not handled correctly. */
346 HOWTO (R_MIPS_GOT_DISP, /* type */
348 2, /* size (0 = byte, 1 = short, 2 = long) */
350 false, /* pc_relative */
352 complain_overflow_bitfield, /* complain_on_overflow */
353 bfd_elf_generic_reloc, /* special_function */
354 "R_MIPS_GOT_DISP", /* name */
355 true, /* partial_inplace */
356 0x0000ffff, /* src_mask */
357 0x0000ffff, /* dst_mask */
358 false), /* pcrel_offset */
360 /* Displacement to page pointer in the global offset table. */
361 /* FIXME: Not handled correctly. */
362 HOWTO (R_MIPS_GOT_PAGE, /* type */
364 2, /* size (0 = byte, 1 = short, 2 = long) */
366 false, /* pc_relative */
368 complain_overflow_bitfield, /* complain_on_overflow */
369 bfd_elf_generic_reloc, /* special_function */
370 "R_MIPS_GOT_PAGE", /* name */
371 true, /* partial_inplace */
372 0x0000ffff, /* src_mask */
373 0x0000ffff, /* dst_mask */
374 false), /* pcrel_offset */
376 /* Offset from page pointer in the global offset table. */
377 /* FIXME: Not handled correctly. */
378 HOWTO (R_MIPS_GOT_OFST, /* type */
380 2, /* size (0 = byte, 1 = short, 2 = long) */
382 false, /* pc_relative */
384 complain_overflow_bitfield, /* complain_on_overflow */
385 bfd_elf_generic_reloc, /* special_function */
386 "R_MIPS_GOT_OFST", /* name */
387 true, /* partial_inplace */
388 0x0000ffff, /* src_mask */
389 0x0000ffff, /* dst_mask */
390 false), /* pcrel_offset */
392 /* High 16 bits of displacement in global offset table. */
393 /* FIXME: Not handled correctly. */
394 HOWTO (R_MIPS_GOT_HI16, /* type */
396 2, /* size (0 = byte, 1 = short, 2 = long) */
398 false, /* pc_relative */
400 complain_overflow_dont, /* complain_on_overflow */
401 bfd_elf_generic_reloc, /* special_function */
402 "R_MIPS_GOT_HI16", /* name */
403 true, /* partial_inplace */
404 0x0000ffff, /* src_mask */
405 0x0000ffff, /* dst_mask */
406 false), /* pcrel_offset */
408 /* Low 16 bits of displacement in global offset table. */
409 /* FIXME: Not handled correctly. */
410 HOWTO (R_MIPS_GOT_LO16, /* type */
412 2, /* size (0 = byte, 1 = short, 2 = long) */
414 false, /* pc_relative */
416 complain_overflow_dont, /* complain_on_overflow */
417 bfd_elf_generic_reloc, /* special_function */
418 "R_MIPS_GOT_LO16", /* name */
419 true, /* partial_inplace */
420 0x0000ffff, /* src_mask */
421 0x0000ffff, /* dst_mask */
422 false), /* pcrel_offset */
424 /* 64 bit substraction. */
425 /* FIXME: Not handled correctly. */
426 HOWTO (R_MIPS_SUB, /* type */
428 4, /* size (0 = byte, 1 = short, 2 = long) */
430 false, /* pc_relative */
432 complain_overflow_bitfield, /* complain_on_overflow */
433 bfd_elf_generic_reloc, /* special_function */
434 "R_MIPS_SUB", /* name */
435 true, /* partial_inplace */
436 MINUS_ONE, /* src_mask */
437 MINUS_ONE, /* dst_mask */
438 false), /* pcrel_offset */
440 /* Insert the addend as an instruction. */
441 /* FIXME: Not handled correctly. */
442 HOWTO (R_MIPS_INSERT_A, /* type */
444 0, /* size (0 = byte, 1 = short, 2 = long) */
446 false, /* pc_relative */
448 complain_overflow_dont, /* complain_on_overflow */
449 bfd_elf_generic_reloc, /* special_function */
450 "R_MIPS_INSERT_A", /* name */
451 false, /* partial_inplace */
454 false), /* pcrel_offset */
456 /* Insert the addend as an instruction, and change all relocations
457 to refer to the old instruction at the address. */
458 /* FIXME: Not handled correctly. */
459 HOWTO (R_MIPS_INSERT_B, /* type */
461 0, /* 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_INSERT_B", /* name */
468 false, /* partial_inplace */
471 false), /* pcrel_offset */
473 /* Delete a 32 bit instruction. */
474 /* FIXME: Not handled correctly. */
475 HOWTO (R_MIPS_DELETE, /* type */
477 0, /* size (0 = byte, 1 = short, 2 = long) */
479 false, /* pc_relative */
481 complain_overflow_dont, /* complain_on_overflow */
482 bfd_elf_generic_reloc, /* special_function */
483 "R_MIPS_DELETE", /* name */
484 false, /* partial_inplace */
487 false), /* pcrel_offset */
489 /* Get the higher value of a 64 bit addend. */
490 /* FIXME: Not handled correctly. */
491 HOWTO (R_MIPS_HIGHER, /* type */
493 2, /* size (0 = byte, 1 = short, 2 = long) */
495 false, /* pc_relative */
497 complain_overflow_dont, /* complain_on_overflow */
498 bfd_elf_generic_reloc, /* special_function */
499 "R_MIPS_HIGHER", /* name */
500 true, /* partial_inplace */
501 0xffff, /* src_mask */
502 0xffff, /* dst_mask */
503 false), /* pcrel_offset */
505 /* Get the highest value of a 64 bit addend. */
506 /* FIXME: Not handled correctly. */
507 HOWTO (R_MIPS_HIGHEST, /* type */
509 2, /* size (0 = byte, 1 = short, 2 = long) */
511 false, /* pc_relative */
513 complain_overflow_dont, /* complain_on_overflow */
514 bfd_elf_generic_reloc, /* special_function */
515 "R_MIPS_HIGHEST", /* name */
516 true, /* partial_inplace */
517 0xffff, /* src_mask */
518 0xffff, /* dst_mask */
519 false), /* pcrel_offset */
521 /* High 16 bits of displacement in global offset table. */
522 /* FIXME: Not handled correctly. */
523 HOWTO (R_MIPS_CALL_HI16, /* type */
525 2, /* size (0 = byte, 1 = short, 2 = long) */
527 false, /* pc_relative */
529 complain_overflow_dont, /* complain_on_overflow */
530 bfd_elf_generic_reloc, /* special_function */
531 "R_MIPS_CALL_HI16", /* name */
532 true, /* partial_inplace */
533 0x0000ffff, /* src_mask */
534 0x0000ffff, /* dst_mask */
535 false), /* pcrel_offset */
537 /* Low 16 bits of displacement in global offset table. */
538 /* FIXME: Not handled correctly. */
539 HOWTO (R_MIPS_CALL_LO16, /* type */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
543 false, /* pc_relative */
545 complain_overflow_dont, /* complain_on_overflow */
546 bfd_elf_generic_reloc, /* special_function */
547 "R_MIPS_CALL_LO16", /* name */
548 true, /* partial_inplace */
549 0x0000ffff, /* src_mask */
550 0x0000ffff, /* dst_mask */
551 false), /* pcrel_offset */
553 /* I'm not sure what the remaining relocs are, but they are defined
556 HOWTO (R_MIPS_SCN_DISP, /* type */
558 0, /* size (0 = byte, 1 = short, 2 = long) */
560 false, /* pc_relative */
562 complain_overflow_dont, /* complain_on_overflow */
563 bfd_elf_generic_reloc, /* special_function */
564 "R_MIPS_SCN_DISP", /* name */
565 false, /* partial_inplace */
568 false), /* pcrel_offset */
570 HOWTO (R_MIPS_REL16, /* type */
572 0, /* size (0 = byte, 1 = short, 2 = long) */
574 false, /* pc_relative */
576 complain_overflow_dont, /* complain_on_overflow */
577 bfd_elf_generic_reloc, /* special_function */
578 "R_MIPS_REL16", /* name */
579 false, /* partial_inplace */
582 false), /* pcrel_offset */
584 HOWTO (R_MIPS_ADD_IMMEDIATE, /* type */
586 0, /* size (0 = byte, 1 = short, 2 = long) */
588 false, /* pc_relative */
590 complain_overflow_dont, /* complain_on_overflow */
591 bfd_elf_generic_reloc, /* special_function */
592 "R_MIPS_ADD_IMMEDIATE", /* name */
593 false, /* partial_inplace */
596 false), /* pcrel_offset */
598 HOWTO (R_MIPS_PJUMP, /* type */
600 0, /* size (0 = byte, 1 = short, 2 = long) */
602 false, /* pc_relative */
604 complain_overflow_dont, /* complain_on_overflow */
605 bfd_elf_generic_reloc, /* special_function */
606 "R_MIPS_PJUMP", /* name */
607 false, /* partial_inplace */
610 false), /* pcrel_offset */
612 HOWTO (R_MIPS_RELGOT, /* type */
614 0, /* size (0 = byte, 1 = short, 2 = long) */
616 false, /* pc_relative */
618 complain_overflow_dont, /* complain_on_overflow */
619 bfd_elf_generic_reloc, /* special_function */
620 "R_MIPS_RELGOT", /* name */
621 false, /* partial_inplace */
624 false), /* pcrel_offset */
626 /* Protected jump conversion. This is an optimization hint. No
627 relocation is required for correctness. */
628 HOWTO (R_MIPS_JALR, /* type */
630 0, /* size (0 = byte, 1 = short, 2 = long) */
632 false, /* pc_relative */
634 complain_overflow_dont, /* complain_on_overflow */
635 bfd_elf_generic_reloc, /* special_function */
636 "R_MIPS_JALR", /* name */
637 false, /* partial_inplace */
638 0x00000000, /* src_mask */
639 0x00000000, /* dst_mask */
640 false), /* pcrel_offset */
643 /* The relocation table used for SHT_RELA sections. */
645 static reloc_howto_type mips_elf64_howto_table_rela[] =
648 HOWTO (R_MIPS_NONE, /* type */
650 0, /* size (0 = byte, 1 = short, 2 = long) */
652 false, /* pc_relative */
654 complain_overflow_dont, /* complain_on_overflow */
655 bfd_elf_generic_reloc, /* special_function */
656 "R_MIPS_NONE", /* name */
657 false, /* partial_inplace */
660 false), /* pcrel_offset */
662 /* 16 bit relocation. */
663 HOWTO (R_MIPS_16, /* type */
665 1, /* size (0 = byte, 1 = short, 2 = long) */
667 false, /* pc_relative */
669 complain_overflow_bitfield, /* complain_on_overflow */
670 bfd_elf_generic_reloc, /* special_function */
671 "R_MIPS_16", /* name */
672 true, /* partial_inplace */
674 0xffff, /* dst_mask */
675 false), /* pcrel_offset */
677 /* 32 bit relocation. */
678 HOWTO (R_MIPS_32, /* type */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 false, /* pc_relative */
684 complain_overflow_bitfield, /* complain_on_overflow */
685 bfd_elf_generic_reloc, /* special_function */
686 "R_MIPS_32", /* name */
687 true, /* partial_inplace */
689 0xffffffff, /* dst_mask */
690 false), /* pcrel_offset */
692 /* 32 bit symbol relative relocation. */
693 HOWTO (R_MIPS_REL32, /* type */
695 2, /* size (0 = byte, 1 = short, 2 = long) */
697 false, /* pc_relative */
699 complain_overflow_bitfield, /* complain_on_overflow */
700 bfd_elf_generic_reloc, /* special_function */
701 "R_MIPS_REL32", /* name */
702 true, /* partial_inplace */
704 0xffffffff, /* dst_mask */
705 false), /* pcrel_offset */
707 /* 26 bit branch address. */
708 HOWTO (R_MIPS_26, /* type */
710 2, /* size (0 = byte, 1 = short, 2 = long) */
712 false, /* pc_relative */
714 complain_overflow_dont, /* complain_on_overflow */
715 /* This needs complex overflow
716 detection, because the upper four
717 bits must match the PC. */
718 bfd_elf_generic_reloc, /* special_function */
719 "R_MIPS_26", /* name */
720 true, /* partial_inplace */
722 0x3ffffff, /* dst_mask */
723 false), /* pcrel_offset */
725 /* High 16 bits of symbol value. */
726 HOWTO (R_MIPS_HI16, /* type */
728 2, /* size (0 = byte, 1 = short, 2 = long) */
730 false, /* pc_relative */
732 complain_overflow_dont, /* complain_on_overflow */
733 bfd_elf_generic_reloc, /* special_function */
734 "R_MIPS_HI16", /* name */
735 true, /* partial_inplace */
737 0xffff, /* dst_mask */
738 false), /* pcrel_offset */
740 /* Low 16 bits of symbol value. */
741 HOWTO (R_MIPS_LO16, /* type */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
745 false, /* pc_relative */
747 complain_overflow_dont, /* complain_on_overflow */
748 bfd_elf_generic_reloc, /* special_function */
749 "R_MIPS_LO16", /* name */
750 true, /* partial_inplace */
752 0xffff, /* dst_mask */
753 false), /* pcrel_offset */
755 /* GP relative reference. */
756 HOWTO (R_MIPS_GPREL16, /* type */
758 2, /* size (0 = byte, 1 = short, 2 = long) */
760 false, /* pc_relative */
762 complain_overflow_signed, /* complain_on_overflow */
763 _bfd_mips_elf_gprel16_reloc, /* special_function */
764 "R_MIPS_GPREL16", /* name */
765 true, /* partial_inplace */
767 0xffff, /* dst_mask */
768 false), /* pcrel_offset */
770 /* Reference to literal section. */
771 HOWTO (R_MIPS_LITERAL, /* type */
773 2, /* size (0 = byte, 1 = short, 2 = long) */
775 false, /* pc_relative */
777 complain_overflow_signed, /* complain_on_overflow */
778 _bfd_mips_elf_gprel16_reloc, /* special_function */
779 "R_MIPS_LITERAL", /* name */
780 true, /* partial_inplace */
782 0xffff, /* dst_mask */
783 false), /* pcrel_offset */
785 /* Reference to global offset table. */
786 /* FIXME: This is not handled correctly. */
787 HOWTO (R_MIPS_GOT16, /* type */
789 2, /* size (0 = byte, 1 = short, 2 = long) */
791 false, /* pc_relative */
793 complain_overflow_signed, /* complain_on_overflow */
794 bfd_elf_generic_reloc, /* special_function */
795 "R_MIPS_GOT16", /* name */
796 false, /* partial_inplace */
798 0xffff, /* dst_mask */
799 false), /* pcrel_offset */
801 /* 16 bit PC relative reference. */
802 HOWTO (R_MIPS_PC16, /* type */
804 2, /* size (0 = byte, 1 = short, 2 = long) */
806 true, /* pc_relative */
808 complain_overflow_signed, /* complain_on_overflow */
809 bfd_elf_generic_reloc, /* special_function */
810 "R_MIPS_PC16", /* name */
811 true, /* partial_inplace */
813 0xffff, /* dst_mask */
814 false), /* pcrel_offset */
816 /* 16 bit call through global offset table. */
817 /* FIXME: This is not handled correctly. */
818 HOWTO (R_MIPS_CALL16, /* type */
820 2, /* size (0 = byte, 1 = short, 2 = long) */
822 false, /* pc_relative */
824 complain_overflow_signed, /* complain_on_overflow */
825 bfd_elf_generic_reloc, /* special_function */
826 "R_MIPS_CALL16", /* name */
827 false, /* partial_inplace */
829 0xffff, /* dst_mask */
830 false), /* pcrel_offset */
832 /* 32 bit GP relative reference. */
833 HOWTO (R_MIPS_GPREL32, /* type */
835 2, /* size (0 = byte, 1 = short, 2 = long) */
837 false, /* pc_relative */
839 complain_overflow_bitfield, /* complain_on_overflow */
840 _bfd_mips_elf_gprel32_reloc, /* special_function */
841 "R_MIPS_GPREL32", /* name */
842 true, /* partial_inplace */
844 0xffffffff, /* dst_mask */
845 false), /* pcrel_offset */
851 /* A 5 bit shift field. */
852 HOWTO (R_MIPS_SHIFT5, /* type */
854 2, /* size (0 = byte, 1 = short, 2 = long) */
856 false, /* pc_relative */
858 complain_overflow_bitfield, /* complain_on_overflow */
859 bfd_elf_generic_reloc, /* special_function */
860 "R_MIPS_SHIFT5", /* name */
861 true, /* partial_inplace */
863 0x000007c0, /* dst_mask */
864 false), /* pcrel_offset */
866 /* A 6 bit shift field. */
867 /* FIXME: This is not handled correctly; a special function is
868 needed to put the most significant bit in the right place. */
869 HOWTO (R_MIPS_SHIFT6, /* type */
871 2, /* size (0 = byte, 1 = short, 2 = long) */
873 false, /* pc_relative */
875 complain_overflow_bitfield, /* complain_on_overflow */
876 bfd_elf_generic_reloc, /* special_function */
877 "R_MIPS_SHIFT6", /* name */
878 true, /* partial_inplace */
880 0x000007c4, /* dst_mask */
881 false), /* pcrel_offset */
883 /* 64 bit relocation. */
884 HOWTO (R_MIPS_64, /* type */
886 4, /* size (0 = byte, 1 = short, 2 = long) */
888 false, /* pc_relative */
890 complain_overflow_bitfield, /* complain_on_overflow */
891 bfd_elf_generic_reloc, /* special_function */
892 "R_MIPS_64", /* name */
893 true, /* partial_inplace */
895 MINUS_ONE, /* dst_mask */
896 false), /* pcrel_offset */
898 /* Displacement in the global offset table. */
899 /* FIXME: Not handled correctly. */
900 HOWTO (R_MIPS_GOT_DISP, /* type */
902 2, /* size (0 = byte, 1 = short, 2 = long) */
904 false, /* pc_relative */
906 complain_overflow_bitfield, /* complain_on_overflow */
907 bfd_elf_generic_reloc, /* special_function */
908 "R_MIPS_GOT_DISP", /* name */
909 true, /* partial_inplace */
911 0x0000ffff, /* dst_mask */
912 false), /* pcrel_offset */
914 /* Displacement to page pointer in the global offset table. */
915 /* FIXME: Not handled correctly. */
916 HOWTO (R_MIPS_GOT_PAGE, /* type */
918 2, /* size (0 = byte, 1 = short, 2 = long) */
920 false, /* pc_relative */
922 complain_overflow_bitfield, /* complain_on_overflow */
923 bfd_elf_generic_reloc, /* special_function */
924 "R_MIPS_GOT_PAGE", /* name */
925 true, /* partial_inplace */
927 0x0000ffff, /* dst_mask */
928 false), /* pcrel_offset */
930 /* Offset from page pointer in the global offset table. */
931 /* FIXME: Not handled correctly. */
932 HOWTO (R_MIPS_GOT_OFST, /* type */
934 2, /* size (0 = byte, 1 = short, 2 = long) */
936 false, /* pc_relative */
938 complain_overflow_bitfield, /* complain_on_overflow */
939 bfd_elf_generic_reloc, /* special_function */
940 "R_MIPS_GOT_OFST", /* name */
941 true, /* partial_inplace */
943 0x0000ffff, /* dst_mask */
944 false), /* pcrel_offset */
946 /* High 16 bits of displacement in global offset table. */
947 /* FIXME: Not handled correctly. */
948 HOWTO (R_MIPS_GOT_HI16, /* type */
950 2, /* size (0 = byte, 1 = short, 2 = long) */
952 false, /* pc_relative */
954 complain_overflow_dont, /* complain_on_overflow */
955 bfd_elf_generic_reloc, /* special_function */
956 "R_MIPS_GOT_HI16", /* name */
957 true, /* partial_inplace */
959 0x0000ffff, /* dst_mask */
960 false), /* pcrel_offset */
962 /* Low 16 bits of displacement in global offset table. */
963 /* FIXME: Not handled correctly. */
964 HOWTO (R_MIPS_GOT_LO16, /* type */
966 2, /* size (0 = byte, 1 = short, 2 = long) */
968 false, /* pc_relative */
970 complain_overflow_dont, /* complain_on_overflow */
971 bfd_elf_generic_reloc, /* special_function */
972 "R_MIPS_GOT_LO16", /* name */
973 true, /* partial_inplace */
975 0x0000ffff, /* dst_mask */
976 false), /* pcrel_offset */
978 /* 64 bit substraction. */
979 /* FIXME: Not handled correctly. */
980 HOWTO (R_MIPS_SUB, /* type */
982 4, /* size (0 = byte, 1 = short, 2 = long) */
984 false, /* pc_relative */
986 complain_overflow_bitfield, /* complain_on_overflow */
987 bfd_elf_generic_reloc, /* special_function */
988 "R_MIPS_SUB", /* name */
989 true, /* partial_inplace */
991 MINUS_ONE, /* dst_mask */
992 false), /* pcrel_offset */
994 /* Insert the addend as an instruction. */
995 /* FIXME: Not handled correctly. */
996 HOWTO (R_MIPS_INSERT_A, /* type */
998 0, /* size (0 = byte, 1 = short, 2 = long) */
1000 false, /* pc_relative */
1002 complain_overflow_dont, /* complain_on_overflow */
1003 bfd_elf_generic_reloc, /* special_function */
1004 "R_MIPS_INSERT_A", /* name */
1005 false, /* partial_inplace */
1008 false), /* pcrel_offset */
1010 /* Insert the addend as an instruction, and change all relocations
1011 to refer to the old instruction at the address. */
1012 /* FIXME: Not handled correctly. */
1013 HOWTO (R_MIPS_INSERT_B, /* type */
1015 0, /* size (0 = byte, 1 = short, 2 = long) */
1017 false, /* pc_relative */
1019 complain_overflow_dont, /* complain_on_overflow */
1020 bfd_elf_generic_reloc, /* special_function */
1021 "R_MIPS_INSERT_B", /* name */
1022 false, /* partial_inplace */
1025 false), /* pcrel_offset */
1027 /* Delete a 32 bit instruction. */
1028 /* FIXME: Not handled correctly. */
1029 HOWTO (R_MIPS_DELETE, /* type */
1031 0, /* size (0 = byte, 1 = short, 2 = long) */
1033 false, /* pc_relative */
1035 complain_overflow_dont, /* complain_on_overflow */
1036 bfd_elf_generic_reloc, /* special_function */
1037 "R_MIPS_DELETE", /* name */
1038 false, /* partial_inplace */
1041 false), /* pcrel_offset */
1043 /* Get the higher value of a 64 bit addend. */
1044 /* FIXME: Not handled correctly. */
1045 HOWTO (R_MIPS_HIGHER, /* type */
1047 2, /* size (0 = byte, 1 = short, 2 = long) */
1049 false, /* pc_relative */
1051 complain_overflow_dont, /* complain_on_overflow */
1052 bfd_elf_generic_reloc, /* special_function */
1053 "R_MIPS_HIGHER", /* name */
1054 true, /* partial_inplace */
1056 0xffff, /* dst_mask */
1057 false), /* pcrel_offset */
1059 /* Get the highest value of a 64 bit addend. */
1060 /* FIXME: Not handled correctly. */
1061 HOWTO (R_MIPS_HIGHEST, /* type */
1063 2, /* size (0 = byte, 1 = short, 2 = long) */
1065 false, /* pc_relative */
1067 complain_overflow_dont, /* complain_on_overflow */
1068 bfd_elf_generic_reloc, /* special_function */
1069 "R_MIPS_HIGHEST", /* name */
1070 true, /* partial_inplace */
1072 0xffff, /* dst_mask */
1073 false), /* pcrel_offset */
1075 /* High 16 bits of displacement in global offset table. */
1076 /* FIXME: Not handled correctly. */
1077 HOWTO (R_MIPS_CALL_HI16, /* type */
1079 2, /* size (0 = byte, 1 = short, 2 = long) */
1081 false, /* pc_relative */
1083 complain_overflow_dont, /* complain_on_overflow */
1084 bfd_elf_generic_reloc, /* special_function */
1085 "R_MIPS_CALL_HI16", /* name */
1086 true, /* partial_inplace */
1088 0x0000ffff, /* dst_mask */
1089 false), /* pcrel_offset */
1091 /* Low 16 bits of displacement in global offset table. */
1092 /* FIXME: Not handled correctly. */
1093 HOWTO (R_MIPS_CALL_LO16, /* type */
1095 2, /* size (0 = byte, 1 = short, 2 = long) */
1097 false, /* pc_relative */
1099 complain_overflow_dont, /* complain_on_overflow */
1100 bfd_elf_generic_reloc, /* special_function */
1101 "R_MIPS_CALL_LO16", /* name */
1102 true, /* partial_inplace */
1104 0x0000ffff, /* dst_mask */
1105 false), /* pcrel_offset */
1107 /* I'm not sure what the remaining relocs are, but they are defined
1110 HOWTO (R_MIPS_SCN_DISP, /* type */
1112 0, /* size (0 = byte, 1 = short, 2 = long) */
1114 false, /* pc_relative */
1116 complain_overflow_dont, /* complain_on_overflow */
1117 bfd_elf_generic_reloc, /* special_function */
1118 "R_MIPS_SCN_DISP", /* name */
1119 false, /* partial_inplace */
1122 false), /* pcrel_offset */
1124 HOWTO (R_MIPS_REL16, /* type */
1126 0, /* size (0 = byte, 1 = short, 2 = long) */
1128 false, /* pc_relative */
1130 complain_overflow_dont, /* complain_on_overflow */
1131 bfd_elf_generic_reloc, /* special_function */
1132 "R_MIPS_REL16", /* name */
1133 false, /* partial_inplace */
1136 false), /* pcrel_offset */
1138 HOWTO (R_MIPS_ADD_IMMEDIATE, /* type */
1140 0, /* size (0 = byte, 1 = short, 2 = long) */
1142 false, /* pc_relative */
1144 complain_overflow_dont, /* complain_on_overflow */
1145 bfd_elf_generic_reloc, /* special_function */
1146 "R_MIPS_ADD_IMMEDIATE", /* name */
1147 false, /* partial_inplace */
1150 false), /* pcrel_offset */
1152 HOWTO (R_MIPS_PJUMP, /* type */
1154 0, /* size (0 = byte, 1 = short, 2 = long) */
1156 false, /* pc_relative */
1158 complain_overflow_dont, /* complain_on_overflow */
1159 bfd_elf_generic_reloc, /* special_function */
1160 "R_MIPS_PJUMP", /* name */
1161 false, /* partial_inplace */
1164 false), /* pcrel_offset */
1166 HOWTO (R_MIPS_RELGOT, /* type */
1168 0, /* size (0 = byte, 1 = short, 2 = long) */
1170 false, /* pc_relative */
1172 complain_overflow_dont, /* complain_on_overflow */
1173 bfd_elf_generic_reloc, /* special_function */
1174 "R_MIPS_RELGOT", /* name */
1175 false, /* partial_inplace */
1178 false), /* pcrel_offset */
1180 /* Protected jump conversion. This is an optimization hint. No
1181 relocation is required for correctness. */
1182 HOWTO (R_MIPS_JALR, /* type */
1184 0, /* size (0 = byte, 1 = short, 2 = long) */
1186 false, /* pc_relative */
1188 complain_overflow_dont, /* complain_on_overflow */
1189 bfd_elf_generic_reloc, /* special_function */
1190 "R_MIPS_JALR", /* name */
1191 false, /* partial_inplace */
1192 0x00000000, /* src_mask */
1193 0x00000000, /* dst_mask */
1194 false), /* pcrel_offset */
1197 /* Swap in a MIPS 64-bit Rel reloc. */
1200 mips_elf64_swap_reloc_in (abfd, src, dst)
1202 const Elf64_Mips_External_Rel *src;
1203 Elf64_Mips_Internal_Rel *dst;
1205 dst->r_offset = bfd_h_get_64 (abfd, (bfd_byte *) src->r_offset);
1206 dst->r_sym = bfd_h_get_32 (abfd, (bfd_byte *) src->r_sym);
1207 dst->r_ssym = bfd_h_get_8 (abfd, (bfd_byte *) src->r_ssym);
1208 dst->r_type3 = bfd_h_get_8 (abfd, (bfd_byte *) src->r_type3);
1209 dst->r_type2 = bfd_h_get_8 (abfd, (bfd_byte *) src->r_type2);
1210 dst->r_type = bfd_h_get_8 (abfd, (bfd_byte *) src->r_type);
1213 /* Swap in a MIPS 64-bit Rela reloc. */
1216 mips_elf64_swap_reloca_in (abfd, src, dst)
1218 const Elf64_Mips_External_Rela *src;
1219 Elf64_Mips_Internal_Rela *dst;
1221 dst->r_offset = bfd_h_get_64 (abfd, (bfd_byte *) src->r_offset);
1222 dst->r_sym = bfd_h_get_32 (abfd, (bfd_byte *) src->r_sym);
1223 dst->r_ssym = bfd_h_get_8 (abfd, (bfd_byte *) src->r_ssym);
1224 dst->r_type3 = bfd_h_get_8 (abfd, (bfd_byte *) src->r_type3);
1225 dst->r_type2 = bfd_h_get_8 (abfd, (bfd_byte *) src->r_type2);
1226 dst->r_type = bfd_h_get_8 (abfd, (bfd_byte *) src->r_type);
1227 dst->r_addend = bfd_h_get_signed_64 (abfd, (bfd_byte *) src->r_addend);
1230 /* Swap out a MIPS 64-bit Rel reloc. */
1233 mips_elf64_swap_reloc_out (abfd, src, dst)
1235 const Elf64_Mips_Internal_Rel *src;
1236 Elf64_Mips_External_Rel *dst;
1238 bfd_h_put_64 (abfd, src->r_offset, (bfd_byte *) dst->r_offset);
1239 bfd_h_put_32 (abfd, src->r_sym, (bfd_byte *) dst->r_sym);
1240 bfd_h_put_8 (abfd, src->r_ssym, (bfd_byte *) dst->r_ssym);
1241 bfd_h_put_8 (abfd, src->r_type3, (bfd_byte *) dst->r_type3);
1242 bfd_h_put_8 (abfd, src->r_type2, (bfd_byte *) dst->r_type2);
1243 bfd_h_put_8 (abfd, src->r_type, (bfd_byte *) dst->r_type);
1246 /* Swap out a MIPS 64-bit Rela reloc. */
1249 mips_elf64_swap_reloca_out (abfd, src, dst)
1251 const Elf64_Mips_Internal_Rela *src;
1252 Elf64_Mips_External_Rela *dst;
1254 bfd_h_put_64 (abfd, src->r_offset, (bfd_byte *) dst->r_offset);
1255 bfd_h_put_32 (abfd, src->r_sym, (bfd_byte *) dst->r_sym);
1256 bfd_h_put_8 (abfd, src->r_ssym, (bfd_byte *) dst->r_ssym);
1257 bfd_h_put_8 (abfd, src->r_type3, (bfd_byte *) dst->r_type3);
1258 bfd_h_put_8 (abfd, src->r_type2, (bfd_byte *) dst->r_type2);
1259 bfd_h_put_8 (abfd, src->r_type, (bfd_byte *) dst->r_type);
1260 bfd_h_put_64 (abfd, src->r_addend, (bfd_byte *) dst->r_addend);
1263 /* Swap in a MIPS 64-bit Rel reloc. */
1266 mips_elf64_be_swap_reloc_in (abfd, src, dst)
1268 const bfd_byte *src;
1269 Elf_Internal_Rel *dst;
1271 Elf64_Mips_Internal_Rel mirel;
1273 mips_elf64_swap_reloc_in (abfd,
1274 (const Elf64_Mips_External_Rel *) src,
1277 dst[0].r_offset = mirel.r_offset;
1278 dst[0].r_info = ELF32_R_INFO (mirel.r_sym, mirel.r_type);
1279 dst[1].r_offset = mirel.r_offset;
1280 dst[1].r_info = ELF32_R_INFO (mirel.r_ssym, mirel.r_type2);
1281 dst[2].r_offset = mirel.r_offset;
1282 dst[2].r_info = ELF32_R_INFO (STN_UNDEF, mirel.r_type3);
1285 /* Swap in a MIPS 64-bit Rela reloc. */
1288 mips_elf64_be_swap_reloca_in (abfd, src, dst)
1290 const bfd_byte *src;
1291 Elf_Internal_Rela *dst;
1293 Elf64_Mips_Internal_Rela mirela;
1295 mips_elf64_swap_reloca_in (abfd,
1296 (const Elf64_Mips_External_Rela *) src,
1299 dst[0].r_offset = mirela.r_offset;
1300 dst[0].r_info = ELF32_R_INFO (mirela.r_sym, mirela.r_type);
1301 dst[0].r_addend = mirela.r_addend;
1302 dst[1].r_offset = mirela.r_offset;
1303 dst[1].r_info = ELF32_R_INFO (mirela.r_ssym, mirela.r_type2);
1304 dst[1].r_addend = 0;
1305 dst[2].r_offset = mirela.r_offset;
1306 dst[2].r_info = ELF32_R_INFO (STN_UNDEF, mirela.r_type3);
1307 dst[2].r_addend = 0;
1310 /* Swap out a MIPS 64-bit Rel reloc. */
1313 mips_elf64_be_swap_reloc_out (abfd, src, dst)
1315 const Elf_Internal_Rel *src;
1318 Elf64_Mips_Internal_Rel mirel;
1320 mirel.r_offset = src->r_offset;
1321 mirel.r_type = ELF32_R_TYPE (src->r_info);
1322 mirel.r_sym = ELF32_R_SYM (src->r_info);
1323 mirel.r_type2 = R_MIPS_NONE;
1324 mirel.r_ssym = STN_UNDEF;
1325 mirel.r_type3 = R_MIPS_NONE;
1327 mips_elf64_swap_reloc_out (abfd, &mirel,
1328 (Elf64_Mips_External_Rel *) dst);
1331 /* Swap out a MIPS 64-bit Rela reloc. */
1334 mips_elf64_be_swap_reloca_out (abfd, src, dst)
1336 const Elf_Internal_Rela *src;
1339 Elf64_Mips_Internal_Rela mirela;
1341 mirela.r_offset = src->r_offset;
1342 mirela.r_type = ELF32_R_TYPE (src->r_info);
1343 mirela.r_addend = src->r_addend;
1344 mirela.r_sym = ELF32_R_SYM (src->r_info);
1345 mirela.r_type2 = R_MIPS_NONE;
1346 mirela.r_ssym = STN_UNDEF;
1347 mirela.r_type3 = R_MIPS_NONE;
1349 mips_elf64_swap_reloca_out (abfd, &mirela,
1350 (Elf64_Mips_External_Rela *) dst);
1353 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
1355 struct elf_reloc_map
1357 bfd_reloc_code_real_type bfd_reloc_val;
1358 enum elf_mips_reloc_type elf_reloc_val;
1361 static CONST struct elf_reloc_map mips_reloc_map[] =
1363 { BFD_RELOC_NONE, R_MIPS_NONE, },
1364 { BFD_RELOC_16, R_MIPS_16 },
1365 { BFD_RELOC_32, R_MIPS_32 },
1366 { BFD_RELOC_64, R_MIPS_64 },
1367 { BFD_RELOC_CTOR, R_MIPS_64 },
1368 { BFD_RELOC_32_PCREL, R_MIPS_REL32 },
1369 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
1370 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
1371 { BFD_RELOC_LO16, R_MIPS_LO16 },
1372 { BFD_RELOC_MIPS_GPREL, R_MIPS_GPREL16 },
1373 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
1374 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
1375 { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
1376 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
1377 { BFD_RELOC_MIPS_GPREL32, R_MIPS_GPREL32 },
1378 { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 },
1379 { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 },
1380 { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 },
1381 { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 },
1382 { BFD_RELOC_MIPS_SUB, R_MIPS_SUB },
1383 { BFD_RELOC_MIPS_GOT_PAGE, R_MIPS_GOT_PAGE },
1384 { BFD_RELOC_MIPS_GOT_OFST, R_MIPS_GOT_OFST },
1385 { BFD_RELOC_MIPS_GOT_DISP, R_MIPS_GOT_DISP }
1388 /* Given a BFD reloc type, return a howto structure. */
1390 static reloc_howto_type *
1391 mips_elf64_reloc_type_lookup (abfd, code)
1393 bfd_reloc_code_real_type code;
1397 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); i++)
1399 if (mips_reloc_map[i].bfd_reloc_val == code)
1403 v = (int) mips_reloc_map[i].elf_reloc_val;
1404 return &mips_elf64_howto_table_rel[v];
1411 /* Since each entry in an SHT_REL or SHT_RELA section can represent up
1412 to three relocs, we must tell the user to allocate more space. */
1415 mips_elf64_get_reloc_upper_bound (abfd, sec)
1419 return (sec->reloc_count * 3 + 1) * sizeof (arelent *);
1422 /* Read the relocations from one reloc section. */
1425 mips_elf64_slurp_one_reloc_table (abfd, asect, symbols, rel_hdr)
1429 const Elf_Internal_Shdr *rel_hdr;
1431 PTR allocated = NULL;
1432 bfd_byte *native_relocs;
1438 reloc_howto_type *howto_table;
1440 allocated = (PTR) bfd_malloc (rel_hdr->sh_size);
1441 if (allocated == NULL)
1444 if (bfd_seek (abfd, rel_hdr->sh_offset, SEEK_SET) != 0
1445 || (bfd_read (allocated, 1, rel_hdr->sh_size, abfd) != rel_hdr->sh_size))
1448 native_relocs = (bfd_byte *) allocated;
1450 relents = asect->relocation + asect->reloc_count;
1452 entsize = rel_hdr->sh_entsize;
1453 BFD_ASSERT (entsize == sizeof (Elf64_Mips_External_Rel)
1454 || entsize == sizeof (Elf64_Mips_External_Rela));
1456 count = rel_hdr->sh_size / entsize;
1458 if (entsize == sizeof (Elf64_Mips_External_Rel))
1459 howto_table = mips_elf64_howto_table_rel;
1461 howto_table = mips_elf64_howto_table_rela;
1464 for (i = 0; i < count; i++, native_relocs += entsize)
1466 Elf64_Mips_Internal_Rela rela;
1467 boolean used_sym, used_ssym;
1470 if (entsize == sizeof (Elf64_Mips_External_Rela))
1471 mips_elf64_swap_reloca_in (abfd,
1472 (Elf64_Mips_External_Rela *) native_relocs,
1476 Elf64_Mips_Internal_Rel rel;
1478 mips_elf64_swap_reloc_in (abfd,
1479 (Elf64_Mips_External_Rel *) native_relocs,
1481 rela.r_offset = rel.r_offset;
1482 rela.r_sym = rel.r_sym;
1483 rela.r_ssym = rel.r_ssym;
1484 rela.r_type3 = rel.r_type3;
1485 rela.r_type2 = rel.r_type2;
1486 rela.r_type = rel.r_type;
1490 /* Each entry represents up to three actual relocations. */
1494 for (ir = 0; ir < 3; ir++)
1496 enum elf_mips_reloc_type type;
1503 type = (enum elf_mips_reloc_type) rela.r_type;
1506 type = (enum elf_mips_reloc_type) rela.r_type2;
1509 type = (enum elf_mips_reloc_type) rela.r_type3;
1513 if (type == R_MIPS_NONE)
1515 /* There are no more relocations in this entry. If this
1516 is the first entry, we need to generate a dummy
1517 relocation so that the generic linker knows that
1518 there has been a break in the sequence of relocations
1519 applying to a particular address. */
1522 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
1523 if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
1524 relent->address = rela.r_offset;
1526 relent->address = rela.r_offset - asect->vma;
1528 relent->howto = &howto_table[(int) R_MIPS_NONE];
1534 /* Some types require symbols, whereas some do not. */
1538 case R_MIPS_LITERAL:
1539 case R_MIPS_INSERT_A:
1540 case R_MIPS_INSERT_B:
1542 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
1548 if (rela.r_sym == 0)
1549 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
1554 ps = symbols + rela.r_sym - 1;
1556 if ((s->flags & BSF_SECTION_SYM) == 0)
1557 relent->sym_ptr_ptr = ps;
1559 relent->sym_ptr_ptr = s->section->symbol_ptr_ptr;
1564 else if (! used_ssym)
1566 switch (rela.r_ssym)
1569 relent->sym_ptr_ptr =
1570 bfd_abs_section_ptr->symbol_ptr_ptr;
1576 /* FIXME: I think these need to be handled using
1577 special howto structures. */
1589 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
1594 /* The address of an ELF reloc is section relative for an
1595 object file, and absolute for an executable file or
1596 shared library. The address of a BFD reloc is always
1597 section relative. */
1598 if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
1599 relent->address = rela.r_offset;
1601 relent->address = rela.r_offset - asect->vma;
1603 relent->addend = rela.r_addend;
1605 relent->howto = &howto_table[(int) type];
1611 asect->reloc_count += relent - relents;
1613 if (allocated != NULL)
1619 if (allocated != NULL)
1624 /* Read the relocations. On Irix 6, there can be two reloc sections
1625 associated with a single data section. */
1628 mips_elf64_slurp_reloc_table (abfd, asect, symbols, dynamic)
1634 struct bfd_elf_section_data * const d = elf_section_data (asect);
1638 bfd_set_error (bfd_error_invalid_operation);
1642 if (asect->relocation != NULL
1643 || (asect->flags & SEC_RELOC) == 0
1644 || asect->reloc_count == 0)
1647 /* Allocate space for 3 arelent structures for each Rel structure. */
1648 asect->relocation = ((arelent *)
1650 asect->reloc_count * 3 * sizeof (arelent)));
1651 if (asect->relocation == NULL)
1654 /* The slurp_one_reloc_table routine increments reloc_count. */
1655 asect->reloc_count = 0;
1657 if (! mips_elf64_slurp_one_reloc_table (abfd, asect, symbols, &d->rel_hdr))
1659 if (d->rel_hdr2 != NULL)
1661 if (! mips_elf64_slurp_one_reloc_table (abfd, asect, symbols,
1669 /* Write out the relocations. */
1672 mips_elf64_write_relocs (abfd, sec, data)
1677 boolean *failedp = (boolean *) data;
1679 Elf_Internal_Shdr *rela_hdr;
1680 Elf64_Mips_External_Rela *ext_rela;
1682 asymbol *last_sym = 0;
1683 int last_sym_idx = 0;
1685 /* If we have already failed, don't do anything. */
1689 if ((sec->flags & SEC_RELOC) == 0)
1692 /* The linker backend writes the relocs out itself, and sets the
1693 reloc_count field to zero to inhibit writing them here. Also,
1694 sometimes the SEC_RELOC flag gets set even when there aren't any
1696 if (sec->reloc_count == 0)
1699 /* We can combine up to three relocs that refer to the same address
1700 if the latter relocs have no associated symbol. */
1702 for (idx = 0; idx < sec->reloc_count; idx++)
1709 addr = sec->orelocation[idx]->address;
1710 for (i = 0; i < 2; i++)
1714 if (idx + 1 >= sec->reloc_count)
1716 r = sec->orelocation[idx + 1];
1717 if (r->address != addr
1718 || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
1719 || (*r->sym_ptr_ptr)->value != 0)
1722 /* We can merge the reloc at IDX + 1 with the reloc at IDX. */
1728 rela_hdr = &elf_section_data (sec)->rel_hdr;
1730 rela_hdr->sh_size = rela_hdr->sh_entsize * count;
1731 rela_hdr->contents = (PTR) bfd_alloc (abfd, rela_hdr->sh_size);
1732 if (rela_hdr->contents == NULL)
1738 ext_rela = (Elf64_Mips_External_Rela *) rela_hdr->contents;
1739 for (idx = 0; idx < sec->reloc_count; idx++, ext_rela++)
1742 Elf64_Mips_Internal_Rela int_rela;
1747 ptr = sec->orelocation[idx];
1749 /* The address of an ELF reloc is section relative for an object
1750 file, and absolute for an executable file or shared library.
1751 The address of a BFD reloc is always section relative. */
1752 if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
1753 int_rela.r_offset = ptr->address;
1755 int_rela.r_offset = ptr->address + sec->vma;
1757 sym = *ptr->sym_ptr_ptr;
1758 if (sym == last_sym)
1763 n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
1774 int_rela.r_addend = ptr->addend;
1776 int_rela.r_ssym = RSS_UNDEF;
1778 if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
1779 && ! _bfd_elf_validate_reloc (abfd, ptr))
1785 int_rela.r_type = ptr->howto->type;
1786 int_rela.r_type2 = (int) R_MIPS_NONE;
1787 int_rela.r_type3 = (int) R_MIPS_NONE;
1789 for (i = 0; i < 2; i++)
1793 if (idx + 1 >= sec->reloc_count)
1795 r = sec->orelocation[idx + 1];
1796 if (r->address != ptr->address
1797 || ! bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
1798 || (*r->sym_ptr_ptr)->value != 0)
1801 /* We can merge the reloc at IDX + 1 with the reloc at IDX. */
1804 int_rela.r_type2 = r->howto->type;
1806 int_rela.r_type3 = r->howto->type;
1811 mips_elf64_swap_reloca_out (abfd, &int_rela, ext_rela);
1814 BFD_ASSERT (ext_rela - (Elf64_Mips_External_Rela *) rela_hdr->contents
1818 /* Irix 6 defines a brand new archive map format, so that they can
1819 have archives more than 4 GB in size. */
1821 /* Read an Irix 6 armap. */
1824 mips_elf64_slurp_armap (abfd)
1827 struct artdata *ardata = bfd_ardata (abfd);
1830 bfd_size_type i, parsed_size, nsymz, stringsize, carsym_size, ptrsize;
1831 struct areltdata *mapdata;
1832 bfd_byte int_buf[8];
1834 bfd_byte *raw_armap = NULL;
1837 ardata->symdefs = NULL;
1839 /* Get the name of the first element. */
1840 arhdrpos = bfd_tell (abfd);
1841 i = bfd_read ((PTR) nextname, 1, 16, abfd);
1847 if (bfd_seek (abfd, (file_ptr) - 16, SEEK_CUR) != 0)
1850 /* Archives with traditional armaps are still permitted. */
1851 if (strncmp (nextname, "/ ", 16) == 0)
1852 return bfd_slurp_armap (abfd);
1854 if (strncmp (nextname, "/SYM64/ ", 16) != 0)
1856 bfd_has_map (abfd) = false;
1860 mapdata = (struct areltdata *) _bfd_read_ar_hdr (abfd);
1861 if (mapdata == NULL)
1863 parsed_size = mapdata->parsed_size;
1864 bfd_release (abfd, (PTR) mapdata);
1866 if (bfd_read (int_buf, 1, 8, abfd) != 8)
1868 if (bfd_get_error () != bfd_error_system_call)
1869 bfd_set_error (bfd_error_malformed_archive);
1873 nsymz = bfd_getb64 (int_buf);
1874 stringsize = parsed_size - 8 * nsymz - 8;
1876 carsym_size = nsymz * sizeof (carsym);
1877 ptrsize = 8 * nsymz;
1879 ardata->symdefs = (carsym *) bfd_zalloc (abfd, carsym_size + stringsize + 1);
1880 if (ardata->symdefs == NULL)
1882 carsyms = ardata->symdefs;
1883 stringbase = ((char *) ardata->symdefs) + carsym_size;
1885 raw_armap = (bfd_byte *) bfd_alloc (abfd, ptrsize);
1886 if (raw_armap == NULL)
1889 if (bfd_read (raw_armap, 1, ptrsize, abfd) != ptrsize
1890 || bfd_read (stringbase, 1, stringsize, abfd) != stringsize)
1892 if (bfd_get_error () != bfd_error_system_call)
1893 bfd_set_error (bfd_error_malformed_archive);
1897 for (i = 0; i < nsymz; i++)
1899 carsyms->file_offset = bfd_getb64 (raw_armap + i * 8);
1900 carsyms->name = stringbase;
1901 stringbase += strlen (stringbase) + 1;
1906 ardata->symdef_count = nsymz;
1907 ardata->first_file_filepos = arhdrpos + sizeof (struct ar_hdr) + parsed_size;
1909 bfd_has_map (abfd) = true;
1910 bfd_release (abfd, raw_armap);
1915 if (raw_armap != NULL)
1916 bfd_release (abfd, raw_armap);
1917 if (ardata->symdefs != NULL)
1918 bfd_release (abfd, ardata->symdefs);
1922 /* Write out an Irix 6 armap. The Irix 6 tools are supposed to be
1923 able to handle ordinary ELF armaps, but at least on Irix 6.2 the
1927 mips_elf64_write_armap (arch, elength, map, symbol_count, stridx)
1929 unsigned int elength;
1931 unsigned int symbol_count;
1934 unsigned int ranlibsize = (symbol_count * 8) + 8;
1935 unsigned int stringsize = stridx;
1936 unsigned int mapsize = stringsize + ranlibsize;
1937 file_ptr archive_member_file_ptr;
1938 bfd *current = arch->archive_head;
1945 padding = BFD_ALIGN (mapsize, 8) - mapsize;
1948 /* work out where the first object file will go in the archive */
1949 archive_member_file_ptr = (mapsize
1951 + sizeof (struct ar_hdr)
1954 memset ((char *) (&hdr), 0, sizeof (struct ar_hdr));
1955 strcpy (hdr.ar_name, "/SYM64/");
1956 sprintf (hdr.ar_size, "%-10d", (int) mapsize);
1957 sprintf (hdr.ar_date, "%ld", (long) time (NULL));
1958 /* This, at least, is what Intel coff sets the values to.: */
1959 sprintf ((hdr.ar_uid), "%d", 0);
1960 sprintf ((hdr.ar_gid), "%d", 0);
1961 sprintf ((hdr.ar_mode), "%-7o", (unsigned) 0);
1962 strncpy (hdr.ar_fmag, ARFMAG, 2);
1964 for (i = 0; i < sizeof (struct ar_hdr); i++)
1965 if (((char *) (&hdr))[i] == '\0')
1966 (((char *) (&hdr))[i]) = ' ';
1968 /* Write the ar header for this item and the number of symbols */
1970 if (bfd_write ((PTR) &hdr, 1, sizeof (struct ar_hdr), arch)
1971 != sizeof (struct ar_hdr))
1974 bfd_putb64 (symbol_count, buf);
1975 if (bfd_write (buf, 1, 8, arch) != 8)
1978 /* Two passes, first write the file offsets for each symbol -
1979 remembering that each offset is on a two byte boundary. */
1981 /* Write out the file offset for the file associated with each
1982 symbol, and remember to keep the offsets padded out. */
1984 current = arch->archive_head;
1986 while (current != (bfd *) NULL && count < symbol_count)
1988 /* For each symbol which is used defined in this object, write out
1989 the object file's address in the archive */
1991 while (((bfd *) (map[count]).pos) == current)
1993 bfd_putb64 (archive_member_file_ptr, buf);
1994 if (bfd_write (buf, 1, 8, arch) != 8)
1998 /* Add size of this archive entry */
1999 archive_member_file_ptr += (arelt_size (current)
2000 + sizeof (struct ar_hdr));
2001 /* remember about the even alignment */
2002 archive_member_file_ptr += archive_member_file_ptr % 2;
2003 current = current->next;
2006 /* now write the strings themselves */
2007 for (count = 0; count < symbol_count; count++)
2009 size_t len = strlen (*map[count].name) + 1;
2011 if (bfd_write (*map[count].name, 1, len, arch) != len)
2015 /* The spec says that this should be padded to an 8 byte boundary.
2016 However, the Irix 6.2 tools do not appear to do this. */
2017 while (padding != 0)
2019 if (bfd_write ("", 1, 1, arch) != 1)
2027 /* ECOFF swapping routines. These are used when dealing with the
2028 .mdebug section, which is in the ECOFF debugging format. */
2029 static const struct ecoff_debug_swap mips_elf64_ecoff_debug_swap =
2031 /* Symbol table magic number. */
2033 /* Alignment of debugging information. E.g., 4. */
2035 /* Sizes of external symbolic information. */
2036 sizeof (struct hdr_ext),
2037 sizeof (struct dnr_ext),
2038 sizeof (struct pdr_ext),
2039 sizeof (struct sym_ext),
2040 sizeof (struct opt_ext),
2041 sizeof (struct fdr_ext),
2042 sizeof (struct rfd_ext),
2043 sizeof (struct ext_ext),
2044 /* Functions to swap in external symbolic data. */
2053 _bfd_ecoff_swap_tir_in,
2054 _bfd_ecoff_swap_rndx_in,
2055 /* Functions to swap out external symbolic data. */
2064 _bfd_ecoff_swap_tir_out,
2065 _bfd_ecoff_swap_rndx_out,
2066 /* Function to read in symbolic data. */
2067 _bfd_mips_elf_read_ecoff_info
2070 /* Relocations in the 64 bit MIPS ELF ABI are more complex than in
2071 standard ELF. This structure is used to redirect the relocation
2072 handling routines. */
2074 const struct elf_size_info mips_elf64_size_info =
2076 sizeof (Elf64_External_Ehdr),
2077 sizeof (Elf64_External_Phdr),
2078 sizeof (Elf64_External_Shdr),
2079 sizeof (Elf64_Mips_External_Rel),
2080 sizeof (Elf64_Mips_External_Rela),
2081 sizeof (Elf64_External_Sym),
2082 sizeof (Elf64_External_Dyn),
2083 sizeof (Elf_External_Note),
2084 4, /* hash-table entry size */
2085 3, /* internal relocations per external relocations */
2090 bfd_elf64_write_out_phdrs,
2091 bfd_elf64_write_shdrs_and_ehdr,
2092 mips_elf64_write_relocs,
2093 bfd_elf64_swap_symbol_out,
2094 mips_elf64_slurp_reloc_table,
2095 bfd_elf64_slurp_symbol_table,
2096 bfd_elf64_swap_dyn_in,
2097 bfd_elf64_swap_dyn_out,
2098 mips_elf64_be_swap_reloc_in,
2099 mips_elf64_be_swap_reloc_out,
2100 mips_elf64_be_swap_reloca_in,
2101 mips_elf64_be_swap_reloca_out
2104 #define TARGET_LITTLE_SYM bfd_elf64_littlemips_vec
2105 #define TARGET_LITTLE_NAME "elf64-littlemips"
2106 #define TARGET_BIG_SYM bfd_elf64_bigmips_vec
2107 #define TARGET_BIG_NAME "elf64-bigmips"
2108 #define ELF_ARCH bfd_arch_mips
2109 #define ELF_MACHINE_CODE EM_MIPS
2111 #define ELF_MAXPAGESIZE 0x1000
2113 #define elf_backend_collect true
2114 #define elf_backend_type_change_ok true
2115 #define elf_backend_can_gc_sections true
2116 #define elf_backend_size_info mips_elf64_size_info
2117 #define elf_backend_object_p _bfd_mips_elf_object_p
2118 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr
2119 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections
2120 #define elf_backend_section_from_bfd_section \
2121 _bfd_mips_elf_section_from_bfd_section
2122 #define elf_backend_section_processing _bfd_mips_elf_section_processing
2123 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing
2124 #define elf_backend_additional_program_headers \
2125 _bfd_mips_elf_additional_program_headers
2126 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map
2127 #define elf_backend_final_write_processing \
2128 _bfd_mips_elf_final_write_processing
2129 #define elf_backend_ecoff_debug_swap &mips_elf64_ecoff_debug_swap
2130 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook
2131 #define elf_backend_create_dynamic_sections \
2132 _bfd_mips_elf_create_dynamic_sections
2133 #define elf_backend_check_relocs _bfd_mips_elf_check_relocs
2134 #define elf_backend_adjust_dynamic_symbol \
2135 _bfd_mips_elf_adjust_dynamic_symbol
2136 #define elf_backend_always_size_sections \
2137 _bfd_mips_elf_always_size_sections
2138 #define elf_backend_size_dynamic_sections \
2139 _bfd_mips_elf_size_dynamic_sections
2140 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section
2141 #define elf_backend_link_output_symbol_hook \
2142 _bfd_mips_elf_link_output_symbol_hook
2143 #define elf_backend_finish_dynamic_symbol \
2144 _bfd_mips_elf_finish_dynamic_symbol
2145 #define elf_backend_finish_dynamic_sections \
2146 _bfd_mips_elf_finish_dynamic_sections
2147 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook
2148 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook
2149 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)
2150 #define elf_backend_plt_header_size 0
2151 #define elf_backend_may_use_rel_p 1
2153 /* We don't set bfd_elf64_bfd_is_local_label_name because the 32-bit
2154 MIPS-specific function only applies to IRIX5, which had no 64-bit
2156 #define bfd_elf64_find_nearest_line _bfd_mips_elf_find_nearest_line
2157 #define bfd_elf64_set_section_contents _bfd_mips_elf_set_section_contents
2158 #define bfd_elf64_bfd_link_hash_table_create \
2159 _bfd_mips_elf_link_hash_table_create
2160 #define bfd_elf64_bfd_final_link _bfd_mips_elf_final_link
2161 #define bfd_elf64_bfd_copy_private_bfd_data \
2162 _bfd_mips_elf_copy_private_bfd_data
2163 #define bfd_elf64_bfd_merge_private_bfd_data \
2164 _bfd_mips_elf_merge_private_bfd_data
2165 #define bfd_elf64_bfd_set_private_flags _bfd_mips_elf_set_private_flags
2166 #define bfd_elf64_bfd_print_private_bfd_data \
2167 _bfd_mips_elf_print_private_bfd_data
2169 #define bfd_elf64_get_reloc_upper_bound mips_elf64_get_reloc_upper_bound
2170 #define bfd_elf64_bfd_reloc_type_lookup mips_elf64_reloc_type_lookup
2171 #define bfd_elf64_archive_functions
2172 #define bfd_elf64_archive_slurp_armap mips_elf64_slurp_armap
2173 #define bfd_elf64_archive_slurp_extended_name_table \
2174 _bfd_archive_coff_slurp_extended_name_table
2175 #define bfd_elf64_archive_construct_extended_name_table \
2176 _bfd_archive_coff_construct_extended_name_table
2177 #define bfd_elf64_archive_truncate_arname \
2178 _bfd_archive_coff_truncate_arname
2179 #define bfd_elf64_archive_write_armap mips_elf64_write_armap
2180 #define bfd_elf64_archive_read_ar_hdr _bfd_archive_coff_read_ar_hdr
2181 #define bfd_elf64_archive_openr_next_archived_file \
2182 _bfd_archive_coff_openr_next_archived_file
2183 #define bfd_elf64_archive_get_elt_at_index \
2184 _bfd_archive_coff_get_elt_at_index
2185 #define bfd_elf64_archive_generic_stat_arch_elt \
2186 _bfd_archive_coff_generic_stat_arch_elt
2187 #define bfd_elf64_archive_update_armap_timestamp \
2188 _bfd_archive_coff_update_armap_timestamp
2190 #include "elf64-target.h"