1 /* BFD back-end for MIPS Extended-Coff files.
2 Copyright 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Original version by Per Bothner.
4 Full support added by Ian Lance Taylor, ian@cygnus.com.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include "coff/internal.h"
28 #include "coff/symconst.h"
29 #include "coff/ecoff.h"
30 #include "coff/mips.h"
34 /* Prototypes for static functions. */
36 static boolean mips_ecoff_bad_format_hook PARAMS ((bfd *abfd, PTR filehdr));
37 static void mips_ecoff_swap_reloc_in PARAMS ((bfd *, PTR,
38 struct internal_reloc *));
39 static void mips_ecoff_swap_reloc_out PARAMS ((bfd *,
40 const struct internal_reloc *,
42 static void mips_adjust_reloc_in PARAMS ((bfd *,
43 const struct internal_reloc *,
45 static void mips_adjust_reloc_out PARAMS ((bfd *, const arelent *,
46 struct internal_reloc *));
47 static bfd_reloc_status_type mips_generic_reloc PARAMS ((bfd *abfd,
54 static bfd_reloc_status_type mips_refhi_reloc PARAMS ((bfd *abfd,
61 static bfd_reloc_status_type mips_reflo_reloc PARAMS ((bfd *abfd,
68 static bfd_reloc_status_type mips_gprel_reloc PARAMS ((bfd *abfd,
75 static bfd_reloc_status_type mips_relhi_reloc PARAMS ((bfd *abfd,
82 static bfd_reloc_status_type mips_rello_reloc PARAMS ((bfd *abfd,
89 static bfd_reloc_status_type mips_switch_reloc PARAMS ((bfd *abfd,
96 static void mips_relocate_hi PARAMS ((struct internal_reloc *refhi,
97 struct internal_reloc *reflo,
99 asection *input_section,
104 static boolean mips_relocate_section PARAMS ((bfd *, struct bfd_link_info *,
107 static boolean mips_read_relocs PARAMS ((bfd *, asection *));
108 static boolean mips_relax_section PARAMS ((bfd *, asection *,
109 struct bfd_link_info *,
111 static boolean mips_relax_pcrel16 PARAMS ((struct bfd_link_info *, bfd *,
113 struct ecoff_link_hash_entry *,
114 bfd_byte *, bfd_vma));
116 /* ECOFF has COFF sections, but the debugging information is stored in
117 a completely different format. ECOFF targets use some of the
118 swapping routines from coffswap.h, and some of the generic COFF
119 routines in coffgen.c, but, unlike the real COFF targets, do not
120 use coffcode.h itself.
122 Get the generic COFF swapping routines, except for the reloc,
123 symbol, and lineno ones. Give them ECOFF names. */
125 #define NO_COFF_RELOCS
126 #define NO_COFF_SYMBOLS
127 #define NO_COFF_LINENOS
128 #define coff_swap_filehdr_in mips_ecoff_swap_filehdr_in
129 #define coff_swap_filehdr_out mips_ecoff_swap_filehdr_out
130 #define coff_swap_aouthdr_in mips_ecoff_swap_aouthdr_in
131 #define coff_swap_aouthdr_out mips_ecoff_swap_aouthdr_out
132 #define coff_swap_scnhdr_in mips_ecoff_swap_scnhdr_in
133 #define coff_swap_scnhdr_out mips_ecoff_swap_scnhdr_out
134 #include "coffswap.h"
136 /* Get the ECOFF swapping routines. */
138 #include "ecoffswap.h"
140 /* How to process the various relocs types. */
142 static reloc_howto_type mips_howto_table[] =
144 /* Reloc type 0 is ignored. The reloc reading code ensures that
145 this is a reference to the .abs section, which will cause
146 bfd_perform_relocation to do nothing. */
147 HOWTO (MIPS_R_IGNORE, /* type */
149 0, /* size (0 = byte, 1 = short, 2 = long) */
151 false, /* pc_relative */
153 complain_overflow_dont, /* complain_on_overflow */
154 0, /* special_function */
156 false, /* partial_inplace */
159 false), /* pcrel_offset */
161 /* A 16 bit reference to a symbol, normally from a data section. */
162 HOWTO (MIPS_R_REFHALF, /* type */
164 1, /* size (0 = byte, 1 = short, 2 = long) */
166 false, /* pc_relative */
168 complain_overflow_bitfield, /* complain_on_overflow */
169 mips_generic_reloc, /* special_function */
170 "REFHALF", /* name */
171 true, /* partial_inplace */
172 0xffff, /* src_mask */
173 0xffff, /* dst_mask */
174 false), /* pcrel_offset */
176 /* A 32 bit reference to a symbol, normally from a data section. */
177 HOWTO (MIPS_R_REFWORD, /* type */
179 2, /* size (0 = byte, 1 = short, 2 = long) */
181 false, /* pc_relative */
183 complain_overflow_bitfield, /* complain_on_overflow */
184 mips_generic_reloc, /* special_function */
185 "REFWORD", /* name */
186 true, /* partial_inplace */
187 0xffffffff, /* src_mask */
188 0xffffffff, /* dst_mask */
189 false), /* pcrel_offset */
191 /* A 26 bit absolute jump address. */
192 HOWTO (MIPS_R_JMPADDR, /* type */
194 2, /* size (0 = byte, 1 = short, 2 = long) */
196 false, /* pc_relative */
198 complain_overflow_dont, /* complain_on_overflow */
199 /* This needs complex overflow
200 detection, because the upper four
201 bits must match the PC. */
202 mips_generic_reloc, /* special_function */
203 "JMPADDR", /* name */
204 true, /* partial_inplace */
205 0x3ffffff, /* src_mask */
206 0x3ffffff, /* dst_mask */
207 false), /* pcrel_offset */
209 /* The high 16 bits of a symbol value. Handled by the function
211 HOWTO (MIPS_R_REFHI, /* type */
213 2, /* size (0 = byte, 1 = short, 2 = long) */
215 false, /* pc_relative */
217 complain_overflow_bitfield, /* complain_on_overflow */
218 mips_refhi_reloc, /* special_function */
220 true, /* partial_inplace */
221 0xffff, /* src_mask */
222 0xffff, /* dst_mask */
223 false), /* pcrel_offset */
225 /* The low 16 bits of a symbol value. */
226 HOWTO (MIPS_R_REFLO, /* type */
228 2, /* size (0 = byte, 1 = short, 2 = long) */
230 false, /* pc_relative */
232 complain_overflow_dont, /* complain_on_overflow */
233 mips_reflo_reloc, /* special_function */
235 true, /* partial_inplace */
236 0xffff, /* src_mask */
237 0xffff, /* dst_mask */
238 false), /* pcrel_offset */
240 /* A reference to an offset from the gp register. Handled by the
241 function mips_gprel_reloc. */
242 HOWTO (MIPS_R_GPREL, /* type */
244 2, /* size (0 = byte, 1 = short, 2 = long) */
246 false, /* pc_relative */
248 complain_overflow_signed, /* complain_on_overflow */
249 mips_gprel_reloc, /* special_function */
251 true, /* partial_inplace */
252 0xffff, /* src_mask */
253 0xffff, /* dst_mask */
254 false), /* pcrel_offset */
256 /* A reference to a literal using an offset from the gp register.
257 Handled by the function mips_gprel_reloc. */
258 HOWTO (MIPS_R_LITERAL, /* type */
260 2, /* size (0 = byte, 1 = short, 2 = long) */
262 false, /* pc_relative */
264 complain_overflow_signed, /* complain_on_overflow */
265 mips_gprel_reloc, /* special_function */
266 "LITERAL", /* name */
267 true, /* partial_inplace */
268 0xffff, /* src_mask */
269 0xffff, /* dst_mask */
270 false), /* pcrel_offset */
277 /* This reloc is a Cygnus extension used when generating position
278 independent code for embedded systems. It represents a 16 bit PC
279 relative reloc rightshifted twice as used in the MIPS branch
281 HOWTO (MIPS_R_PCREL16, /* type */
283 2, /* size (0 = byte, 1 = short, 2 = long) */
285 true, /* pc_relative */
287 complain_overflow_signed, /* complain_on_overflow */
288 mips_generic_reloc, /* special_function */
289 "PCREL16", /* name */
290 true, /* partial_inplace */
291 0xffff, /* src_mask */
292 0xffff, /* dst_mask */
293 true), /* pcrel_offset */
295 /* This reloc is a Cygnus extension used when generating position
296 independent code for embedded systems. It represents the high 16
297 bits of a PC relative reloc. The next reloc must be
298 MIPS_R_RELLO, and the addend is formed from the addends of the
299 two instructions, just as in MIPS_R_REFHI and MIPS_R_REFLO. The
300 final value is actually PC relative to the location of the
301 MIPS_R_RELLO reloc, not the MIPS_R_RELHI reloc. */
302 HOWTO (MIPS_R_RELHI, /* type */
304 2, /* size (0 = byte, 1 = short, 2 = long) */
306 true, /* pc_relative */
308 complain_overflow_bitfield, /* complain_on_overflow */
309 mips_relhi_reloc, /* special_function */
311 true, /* partial_inplace */
312 0xffff, /* src_mask */
313 0xffff, /* dst_mask */
314 true), /* pcrel_offset */
316 /* This reloc is a Cygnus extension used when generating position
317 independent code for embedded systems. It represents the low 16
318 bits of a PC relative reloc. */
319 HOWTO (MIPS_R_RELLO, /* type */
321 2, /* size (0 = byte, 1 = short, 2 = long) */
323 true, /* pc_relative */
325 complain_overflow_dont, /* complain_on_overflow */
326 mips_rello_reloc, /* special_function */
328 true, /* partial_inplace */
329 0xffff, /* src_mask */
330 0xffff, /* dst_mask */
331 true), /* pcrel_offset */
341 /* This reloc is a Cygnus extension used when generating position
342 independent code for embedded systems. It represents an entry in
343 a switch table, which is the difference between two symbols in
344 the .text section. The symndx is actually the offset from the
345 reloc address to the subtrahend. See include/coff/mips.h for
347 HOWTO (MIPS_R_SWITCH, /* type */
349 2, /* size (0 = byte, 1 = short, 2 = long) */
351 true, /* pc_relative */
353 complain_overflow_dont, /* complain_on_overflow */
354 mips_switch_reloc, /* special_function */
356 true, /* partial_inplace */
357 0xffffffff, /* src_mask */
358 0xffffffff, /* dst_mask */
359 true) /* pcrel_offset */
362 #define MIPS_HOWTO_COUNT \
363 (sizeof mips_howto_table / sizeof mips_howto_table[0])
365 /* When the linker is doing relaxing, it may change a external PCREL16
366 reloc. This typically represents an instruction like
371 lui $at,%hi(foo - $L1)
373 addiu $at,%lo(foo - $L1)
376 PCREL16_EXPANSION_ADJUSTMENT is the number of bytes this changes the
379 #define PCREL16_EXPANSION_ADJUSTMENT (4 * 4)
381 /* See whether the magic number matches. */
384 mips_ecoff_bad_format_hook (abfd, filehdr)
388 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
390 switch (internal_f->f_magic)
393 /* I don't know what endianness this implies. */
397 case MIPS_MAGIC_BIG2:
398 case MIPS_MAGIC_BIG3:
399 return bfd_big_endian (abfd);
401 case MIPS_MAGIC_LITTLE:
402 case MIPS_MAGIC_LITTLE2:
403 case MIPS_MAGIC_LITTLE3:
404 return bfd_little_endian (abfd);
411 /* Reloc handling. MIPS ECOFF relocs are packed into 8 bytes in
412 external form. They use a bit which indicates whether the symbol
415 /* Swap a reloc in. */
418 mips_ecoff_swap_reloc_in (abfd, ext_ptr, intern)
421 struct internal_reloc *intern;
423 const RELOC *ext = (RELOC *) ext_ptr;
425 intern->r_vaddr = bfd_h_get_32 (abfd, (bfd_byte *) ext->r_vaddr);
426 if (bfd_header_big_endian (abfd))
428 intern->r_symndx = (((int) ext->r_bits[0]
429 << RELOC_BITS0_SYMNDX_SH_LEFT_BIG)
430 | ((int) ext->r_bits[1]
431 << RELOC_BITS1_SYMNDX_SH_LEFT_BIG)
432 | ((int) ext->r_bits[2]
433 << RELOC_BITS2_SYMNDX_SH_LEFT_BIG));
434 intern->r_type = ((ext->r_bits[3] & RELOC_BITS3_TYPE_BIG)
435 >> RELOC_BITS3_TYPE_SH_BIG);
436 intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_BIG) != 0;
440 intern->r_symndx = (((int) ext->r_bits[0]
441 << RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE)
442 | ((int) ext->r_bits[1]
443 << RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE)
444 | ((int) ext->r_bits[2]
445 << RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE));
446 intern->r_type = (((ext->r_bits[3] & RELOC_BITS3_TYPE_LITTLE)
447 >> RELOC_BITS3_TYPE_SH_LITTLE)
448 | ((ext->r_bits[3] & RELOC_BITS3_TYPEHI_LITTLE)
449 << RELOC_BITS3_TYPEHI_SH_LITTLE));
450 intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_LITTLE) != 0;
453 /* If this is a MIPS_R_SWITCH reloc, or an internal MIPS_R_RELHI or
454 MIPS_R_RELLO reloc, r_symndx is actually the offset from the
455 reloc address to the base of the difference (see
456 include/coff/mips.h for more details). We copy symndx into the
457 r_offset field so as not to confuse ecoff_slurp_reloc_table in
458 ecoff.c. In adjust_reloc_in we then copy r_offset into the reloc
460 if (intern->r_type == MIPS_R_SWITCH
461 || (! intern->r_extern
462 && (intern->r_type == MIPS_R_RELLO
463 || intern->r_type == MIPS_R_RELHI)))
465 BFD_ASSERT (! intern->r_extern);
466 intern->r_offset = intern->r_symndx;
467 if (intern->r_offset & 0x800000)
468 intern->r_offset -= 0x1000000;
469 intern->r_symndx = RELOC_SECTION_TEXT;
473 /* Swap a reloc out. */
476 mips_ecoff_swap_reloc_out (abfd, intern, dst)
478 const struct internal_reloc *intern;
481 RELOC *ext = (RELOC *) dst;
484 BFD_ASSERT (intern->r_extern
485 || (intern->r_symndx >= 0 && intern->r_symndx <= 12));
487 /* If this is a MIPS_R_SWITCH reloc, or an internal MIPS_R_RELLO or
488 MIPS_R_RELHI reloc, we actually want to write the contents of
489 r_offset out as the symbol index. This undoes the change made by
490 mips_ecoff_swap_reloc_in. */
491 if (intern->r_type != MIPS_R_SWITCH
493 || (intern->r_type != MIPS_R_RELHI
494 && intern->r_type != MIPS_R_RELLO)))
495 r_symndx = intern->r_symndx;
498 BFD_ASSERT (intern->r_symndx == RELOC_SECTION_TEXT);
499 r_symndx = intern->r_offset & 0xffffff;
502 bfd_h_put_32 (abfd, intern->r_vaddr, (bfd_byte *) ext->r_vaddr);
503 if (bfd_header_big_endian (abfd))
505 ext->r_bits[0] = r_symndx >> RELOC_BITS0_SYMNDX_SH_LEFT_BIG;
506 ext->r_bits[1] = r_symndx >> RELOC_BITS1_SYMNDX_SH_LEFT_BIG;
507 ext->r_bits[2] = r_symndx >> RELOC_BITS2_SYMNDX_SH_LEFT_BIG;
508 ext->r_bits[3] = (((intern->r_type << RELOC_BITS3_TYPE_SH_BIG)
509 & RELOC_BITS3_TYPE_BIG)
510 | (intern->r_extern ? RELOC_BITS3_EXTERN_BIG : 0));
514 ext->r_bits[0] = r_symndx >> RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE;
515 ext->r_bits[1] = r_symndx >> RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE;
516 ext->r_bits[2] = r_symndx >> RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE;
517 ext->r_bits[3] = (((intern->r_type << RELOC_BITS3_TYPE_SH_LITTLE)
518 & RELOC_BITS3_TYPE_LITTLE)
519 | ((intern->r_type >> RELOC_BITS3_TYPEHI_SH_LITTLE
520 & RELOC_BITS3_TYPEHI_LITTLE))
521 | (intern->r_extern ? RELOC_BITS3_EXTERN_LITTLE : 0));
525 /* Finish canonicalizing a reloc. Part of this is generic to all
526 ECOFF targets, and that part is in ecoff.c. The rest is done in
527 this backend routine. It must fill in the howto field. */
530 mips_adjust_reloc_in (abfd, intern, rptr)
532 const struct internal_reloc *intern;
535 if (intern->r_type > MIPS_R_SWITCH)
538 if (! intern->r_extern
539 && (intern->r_type == MIPS_R_GPREL
540 || intern->r_type == MIPS_R_LITERAL))
541 rptr->addend += _bfd_get_gp_value (abfd);
543 /* If the type is MIPS_R_IGNORE, make sure this is a reference to
544 the absolute section so that the reloc is ignored. */
545 if (intern->r_type == MIPS_R_IGNORE)
546 rptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
548 /* If this is a MIPS_R_SWITCH reloc, or an internal MIPS_R_RELHI or
549 MIPS_R_RELLO reloc, we want the addend field of the BFD relocto
550 hold the value which was originally in the symndx field of the
551 internal MIPS ECOFF reloc. This value was copied into
552 intern->r_offset by mips_swap_reloc_in, and here we copy it into
554 if (intern->r_type == MIPS_R_SWITCH
555 || (! intern->r_extern
556 && (intern->r_type == MIPS_R_RELHI
557 || intern->r_type == MIPS_R_RELLO)))
558 rptr->addend = intern->r_offset;
560 rptr->howto = &mips_howto_table[intern->r_type];
563 /* Make any adjustments needed to a reloc before writing it out. None
564 are needed for MIPS. */
567 mips_adjust_reloc_out (abfd, rel, intern)
570 struct internal_reloc *intern;
572 /* For a MIPS_R_SWITCH reloc, or an internal MIPS_R_RELHI or
573 MIPS_R_RELLO reloc, we must copy rel->addend into
574 intern->r_offset. This will then be written out as the symbol
575 index by mips_ecoff_swap_reloc_out. This operation parallels the
576 action of mips_adjust_reloc_in. */
577 if (intern->r_type == MIPS_R_SWITCH
578 || (! intern->r_extern
579 && (intern->r_type == MIPS_R_RELHI
580 || intern->r_type == MIPS_R_RELLO)))
581 intern->r_offset = rel->addend;
584 /* ECOFF relocs are either against external symbols, or against
585 sections. If we are producing relocateable output, and the reloc
586 is against an external symbol, and nothing has given us any
587 additional addend, the resulting reloc will also be against the
588 same symbol. In such a case, we don't want to change anything
589 about the way the reloc is handled, since it will all be done at
590 final link time. Rather than put special case code into
591 bfd_perform_relocation, all the reloc types use this howto
592 function. It just short circuits the reloc if producing
593 relocateable output against an external symbol. */
595 static bfd_reloc_status_type
596 mips_generic_reloc (abfd,
604 arelent *reloc_entry;
607 asection *input_section;
609 char **error_message;
611 if (output_bfd != (bfd *) NULL
612 && (symbol->flags & BSF_SECTION_SYM) == 0
613 && reloc_entry->addend == 0)
615 reloc_entry->address += input_section->output_offset;
619 return bfd_reloc_continue;
622 /* Do a REFHI relocation. This has to be done in combination with a
623 REFLO reloc, because there is a carry from the REFLO to the REFHI.
624 Here we just save the information we need; we do the actual
625 relocation when we see the REFLO. MIPS ECOFF requires that the
626 REFLO immediately follow the REFHI, so this ought to work. */
628 static bfd_byte *mips_refhi_addr;
629 static bfd_vma mips_refhi_addend;
631 static bfd_reloc_status_type
632 mips_refhi_reloc (abfd,
640 arelent *reloc_entry;
643 asection *input_section;
645 char **error_message;
647 bfd_reloc_status_type ret;
650 /* If we're relocating, and this an external symbol, we don't want
651 to change anything. */
652 if (output_bfd != (bfd *) NULL
653 && (symbol->flags & BSF_SECTION_SYM) == 0
654 && reloc_entry->addend == 0)
656 reloc_entry->address += input_section->output_offset;
661 if (bfd_is_und_section (symbol->section)
662 && output_bfd == (bfd *) NULL)
663 ret = bfd_reloc_undefined;
665 if (bfd_is_com_section (symbol->section))
668 relocation = symbol->value;
670 relocation += symbol->section->output_section->vma;
671 relocation += symbol->section->output_offset;
672 relocation += reloc_entry->addend;
674 if (reloc_entry->address > input_section->_cooked_size)
675 return bfd_reloc_outofrange;
677 /* Save the information, and let REFLO do the actual relocation. */
678 mips_refhi_addr = (bfd_byte *) data + reloc_entry->address;
679 mips_refhi_addend = relocation;
681 if (output_bfd != (bfd *) NULL)
682 reloc_entry->address += input_section->output_offset;
687 /* Do a REFLO relocation. This is a straightforward 16 bit inplace
688 relocation; this function exists in order to do the REFHI
689 relocation described above. */
691 static bfd_reloc_status_type
692 mips_reflo_reloc (abfd,
700 arelent *reloc_entry;
703 asection *input_section;
705 char **error_message;
707 if (mips_refhi_addr != (bfd_byte *) NULL)
713 /* Do the REFHI relocation. Note that we actually don't need to
714 know anything about the REFLO itself, except where to find
715 the low 16 bits of the addend needed by the REFHI. */
716 insn = bfd_get_32 (abfd, mips_refhi_addr);
717 vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address)
719 val = ((insn & 0xffff) << 16) + vallo;
720 val += mips_refhi_addend;
722 /* The low order 16 bits are always treated as a signed value.
723 Therefore, a negative value in the low order bits requires an
724 adjustment in the high order bits. We need to make this
725 adjustment in two ways: once for the bits we took from the
726 data, and once for the bits we are putting back in to the
728 if ((vallo & 0x8000) != 0)
730 if ((val & 0x8000) != 0)
733 insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
734 bfd_put_32 (abfd, insn, mips_refhi_addr);
736 mips_refhi_addr = (bfd_byte *) NULL;
739 /* Now do the REFLO reloc in the usual way. */
740 return mips_generic_reloc (abfd, reloc_entry, symbol, data,
741 input_section, output_bfd, error_message);
744 /* Do a GPREL relocation. This is a 16 bit value which must become
745 the offset from the gp register. */
747 static bfd_reloc_status_type
748 mips_gprel_reloc (abfd,
756 arelent *reloc_entry;
759 asection *input_section;
761 char **error_message;
763 boolean relocateable;
768 /* If we're relocating, and this is an external symbol with no
769 addend, we don't want to change anything. We will only have an
770 addend if this is a newly created reloc, not read from an ECOFF
772 if (output_bfd != (bfd *) NULL
773 && (symbol->flags & BSF_SECTION_SYM) == 0
774 && reloc_entry->addend == 0)
776 reloc_entry->address += input_section->output_offset;
780 if (output_bfd != (bfd *) NULL)
784 relocateable = false;
785 output_bfd = symbol->section->output_section->owner;
788 if (bfd_is_und_section (symbol->section)
789 && relocateable == false)
790 return bfd_reloc_undefined;
792 /* We have to figure out the gp value, so that we can adjust the
793 symbol value correctly. We look up the symbol _gp in the output
794 BFD. If we can't find it, we're stuck. We cache it in the ECOFF
795 target data. We don't need to adjust the symbol value for an
796 external symbol if we are producing relocateable output. */
797 if (_bfd_get_gp_value (output_bfd) == 0
798 && (relocateable == false
799 || (symbol->flags & BSF_SECTION_SYM) != 0))
801 if (relocateable != false)
803 /* Make up a value. */
804 _bfd_set_gp_value (output_bfd,
805 symbol->section->output_section->vma + 0x4000);
813 count = bfd_get_symcount (output_bfd);
814 sym = bfd_get_outsymbols (output_bfd);
816 if (sym == (asymbol **) NULL)
820 for (i = 0; i < count; i++, sym++)
822 register CONST char *name;
824 name = bfd_asymbol_name (*sym);
825 if (*name == '_' && strcmp (name, "_gp") == 0)
827 _bfd_set_gp_value (output_bfd,
828 bfd_asymbol_value (*sym));
836 /* Only get the error once. */
837 _bfd_set_gp_value (output_bfd, 4);
839 (char *) "GP relative relocation when _gp not defined";
840 return bfd_reloc_dangerous;
845 if (bfd_is_com_section (symbol->section))
848 relocation = symbol->value;
850 relocation += symbol->section->output_section->vma;
851 relocation += symbol->section->output_offset;
853 if (reloc_entry->address > input_section->_cooked_size)
854 return bfd_reloc_outofrange;
856 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
858 /* Set val to the offset into the section or symbol. */
859 val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff;
863 /* Adjust val for the final section location and GP value. If we
864 are producing relocateable output, we don't want to do this for
865 an external symbol. */
866 if (relocateable == false
867 || (symbol->flags & BSF_SECTION_SYM) != 0)
868 val += relocation - _bfd_get_gp_value (output_bfd);
870 insn = (insn &~ 0xffff) | (val & 0xffff);
871 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
873 if (relocateable != false)
874 reloc_entry->address += input_section->output_offset;
876 /* Make sure it fit in 16 bits. */
877 if (val >= 0x8000 && val < 0xffff8000)
878 return bfd_reloc_overflow;
883 /* Do a RELHI relocation. We do this in conjunction with a RELLO
884 reloc, just as REFHI and REFLO are done together. RELHI and RELLO
885 are Cygnus extensions used when generating position independent
886 code for embedded systems. */
888 static bfd_byte *mips_relhi_addr;
889 static bfd_vma mips_relhi_addend;
891 static bfd_reloc_status_type
892 mips_relhi_reloc (abfd,
900 arelent *reloc_entry;
903 asection *input_section;
905 char **error_message;
907 bfd_reloc_status_type ret;
910 /* If this is a reloc against a section symbol, then it is correct
911 in the object file. The only time we want to change this case is
912 when we are relaxing, and that is handled entirely by
913 mips_relocate_section and never calls this function. */
914 if ((symbol->flags & BSF_SECTION_SYM) != 0)
916 if (output_bfd != (bfd *) NULL)
917 reloc_entry->address += input_section->output_offset;
921 /* This is an external symbol. If we're relocating, we don't want
922 to change anything. */
923 if (output_bfd != (bfd *) NULL)
925 reloc_entry->address += input_section->output_offset;
930 if (bfd_is_und_section (symbol->section)
931 && output_bfd == (bfd *) NULL)
932 ret = bfd_reloc_undefined;
934 if (bfd_is_com_section (symbol->section))
937 relocation = symbol->value;
939 relocation += symbol->section->output_section->vma;
940 relocation += symbol->section->output_offset;
941 relocation += reloc_entry->addend;
943 if (reloc_entry->address > input_section->_cooked_size)
944 return bfd_reloc_outofrange;
946 /* Save the information, and let RELLO do the actual relocation. */
947 mips_relhi_addr = (bfd_byte *) data + reloc_entry->address;
948 mips_relhi_addend = relocation;
950 if (output_bfd != (bfd *) NULL)
951 reloc_entry->address += input_section->output_offset;
956 /* Do a RELLO relocation. This is a straightforward 16 bit PC
957 relative relocation; this function exists in order to do the RELHI
958 relocation described above. */
960 static bfd_reloc_status_type
961 mips_rello_reloc (abfd,
969 arelent *reloc_entry;
972 asection *input_section;
974 char **error_message;
976 if (mips_relhi_addr != (bfd_byte *) NULL)
982 /* Do the RELHI relocation. Note that we actually don't need to
983 know anything about the RELLO itself, except where to find
984 the low 16 bits of the addend needed by the RELHI. */
985 insn = bfd_get_32 (abfd, mips_relhi_addr);
986 vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address)
988 val = ((insn & 0xffff) << 16) + vallo;
989 val += mips_relhi_addend;
991 /* If the symbol is defined, make val PC relative. If the
992 symbol is not defined we don't want to do this, because we
993 don't want the value in the object file to incorporate the
994 address of the reloc. */
995 if (! bfd_is_und_section (bfd_get_section (symbol))
996 && ! bfd_is_com_section (bfd_get_section (symbol)))
997 val -= (input_section->output_section->vma
998 + input_section->output_offset
999 + reloc_entry->address);
1001 /* The low order 16 bits are always treated as a signed value.
1002 Therefore, a negative value in the low order bits requires an
1003 adjustment in the high order bits. We need to make this
1004 adjustment in two ways: once for the bits we took from the
1005 data, and once for the bits we are putting back in to the
1007 if ((vallo & 0x8000) != 0)
1009 if ((val & 0x8000) != 0)
1012 insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
1013 bfd_put_32 (abfd, insn, mips_relhi_addr);
1015 mips_relhi_addr = (bfd_byte *) NULL;
1018 /* If this is a reloc against a section symbol, then it is correct
1019 in the object file. The only time we want to change this case is
1020 when we are relaxing, and that is handled entirely by
1021 mips_relocate_section and never calls this function. */
1022 if ((symbol->flags & BSF_SECTION_SYM) != 0)
1024 if (output_bfd != (bfd *) NULL)
1025 reloc_entry->address += input_section->output_offset;
1026 return bfd_reloc_ok;
1029 /* bfd_perform_relocation does not handle pcrel_offset relocations
1030 correctly when generating a relocateable file, so handle them
1032 if (output_bfd != (bfd *) NULL)
1034 reloc_entry->address += input_section->output_offset;
1035 return bfd_reloc_ok;
1038 /* Now do the RELLO reloc in the usual way. */
1039 return mips_generic_reloc (abfd, reloc_entry, symbol, data,
1040 input_section, output_bfd, error_message);
1043 /* This is the special function for the MIPS_R_SWITCH reloc. This
1044 special reloc is normally correct in the object file, and only
1045 requires special handling when relaxing. We don't want
1046 bfd_perform_relocation to tamper with it at all. */
1049 static bfd_reloc_status_type
1050 mips_switch_reloc (abfd,
1058 arelent *reloc_entry;
1061 asection *input_section;
1063 char **error_message;
1065 return bfd_reloc_ok;
1068 /* Get the howto structure for a generic reloc type. */
1070 static reloc_howto_type *
1071 mips_bfd_reloc_type_lookup (abfd, code)
1073 bfd_reloc_code_real_type code;
1080 mips_type = MIPS_R_REFHALF;
1083 case BFD_RELOC_CTOR:
1084 mips_type = MIPS_R_REFWORD;
1086 case BFD_RELOC_MIPS_JMP:
1087 mips_type = MIPS_R_JMPADDR;
1089 case BFD_RELOC_HI16_S:
1090 mips_type = MIPS_R_REFHI;
1092 case BFD_RELOC_LO16:
1093 mips_type = MIPS_R_REFLO;
1095 case BFD_RELOC_MIPS_GPREL:
1096 mips_type = MIPS_R_GPREL;
1098 case BFD_RELOC_MIPS_LITERAL:
1099 mips_type = MIPS_R_LITERAL;
1101 case BFD_RELOC_16_PCREL_S2:
1102 mips_type = MIPS_R_PCREL16;
1104 case BFD_RELOC_PCREL_HI16_S:
1105 mips_type = MIPS_R_RELHI;
1107 case BFD_RELOC_PCREL_LO16:
1108 mips_type = MIPS_R_RELLO;
1110 case BFD_RELOC_GPREL32:
1111 mips_type = MIPS_R_SWITCH;
1114 return (reloc_howto_type *) NULL;
1117 return &mips_howto_table[mips_type];
1120 /* A helper routine for mips_relocate_section which handles the REFHI
1121 and RELHI relocations. The REFHI relocation must be followed by a
1122 REFLO relocation (and RELHI by a RELLO), and the addend used is
1123 formed from the addends of both instructions. */
1126 mips_relocate_hi (refhi, reflo, input_bfd, input_section, contents, adjust,
1128 struct internal_reloc *refhi;
1129 struct internal_reloc *reflo;
1131 asection *input_section;
1139 unsigned long vallo;
1141 insn = bfd_get_32 (input_bfd,
1142 contents + adjust + refhi->r_vaddr - input_section->vma);
1143 vallo = (bfd_get_32 (input_bfd,
1144 contents + adjust + reflo->r_vaddr - input_section->vma)
1146 val = ((insn & 0xffff) << 16) + vallo;
1149 /* The low order 16 bits are always treated as a signed value.
1150 Therefore, a negative value in the low order bits requires an
1151 adjustment in the high order bits. We need to make this
1152 adjustment in two ways: once for the bits we took from the data,
1153 and once for the bits we are putting back in to the data. */
1154 if ((vallo & 0x8000) != 0)
1158 val -= (input_section->output_section->vma
1159 + input_section->output_offset
1160 + (reflo->r_vaddr - input_section->vma + adjust));
1162 if ((val & 0x8000) != 0)
1165 insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
1166 bfd_put_32 (input_bfd, (bfd_vma) insn,
1167 contents + adjust + refhi->r_vaddr - input_section->vma);
1170 /* Relocate a section while linking a MIPS ECOFF file. */
1173 mips_relocate_section (output_bfd, info, input_bfd, input_section,
1174 contents, external_relocs)
1176 struct bfd_link_info *info;
1178 asection *input_section;
1180 PTR external_relocs;
1182 asection **symndx_to_section;
1183 struct ecoff_link_hash_entry **sym_hashes;
1185 boolean gp_undefined;
1188 struct external_reloc *ext_rel;
1189 struct external_reloc *ext_rel_end;
1192 struct internal_reloc lo_int_rel;
1194 BFD_ASSERT (input_bfd->xvec->header_byteorder
1195 == output_bfd->xvec->header_byteorder);
1197 /* We keep a table mapping the symndx found in an internal reloc to
1198 the appropriate section. This is faster than looking up the
1199 section by name each time. */
1200 symndx_to_section = ecoff_data (input_bfd)->symndx_to_section;
1201 if (symndx_to_section == (asection **) NULL)
1203 symndx_to_section = ((asection **)
1204 bfd_alloc (input_bfd,
1206 * sizeof (asection *))));
1207 if (!symndx_to_section)
1210 symndx_to_section[RELOC_SECTION_NONE] = NULL;
1211 symndx_to_section[RELOC_SECTION_TEXT] =
1212 bfd_get_section_by_name (input_bfd, ".text");
1213 symndx_to_section[RELOC_SECTION_RDATA] =
1214 bfd_get_section_by_name (input_bfd, ".rdata");
1215 symndx_to_section[RELOC_SECTION_DATA] =
1216 bfd_get_section_by_name (input_bfd, ".data");
1217 symndx_to_section[RELOC_SECTION_SDATA] =
1218 bfd_get_section_by_name (input_bfd, ".sdata");
1219 symndx_to_section[RELOC_SECTION_SBSS] =
1220 bfd_get_section_by_name (input_bfd, ".sbss");
1221 symndx_to_section[RELOC_SECTION_BSS] =
1222 bfd_get_section_by_name (input_bfd, ".bss");
1223 symndx_to_section[RELOC_SECTION_INIT] =
1224 bfd_get_section_by_name (input_bfd, ".init");
1225 symndx_to_section[RELOC_SECTION_LIT8] =
1226 bfd_get_section_by_name (input_bfd, ".lit8");
1227 symndx_to_section[RELOC_SECTION_LIT4] =
1228 bfd_get_section_by_name (input_bfd, ".lit4");
1229 symndx_to_section[RELOC_SECTION_XDATA] = NULL;
1230 symndx_to_section[RELOC_SECTION_PDATA] = NULL;
1231 symndx_to_section[RELOC_SECTION_FINI] =
1232 bfd_get_section_by_name (input_bfd, ".fini");
1233 symndx_to_section[RELOC_SECTION_LITA] = NULL;
1234 symndx_to_section[RELOC_SECTION_ABS] = NULL;
1236 ecoff_data (input_bfd)->symndx_to_section = symndx_to_section;
1239 sym_hashes = ecoff_data (input_bfd)->sym_hashes;
1241 gp = _bfd_get_gp_value (output_bfd);
1243 gp_undefined = true;
1245 gp_undefined = false;
1251 if (ecoff_section_data (input_bfd, input_section) == NULL)
1254 offsets = ecoff_section_data (input_bfd, input_section)->offsets;
1256 ext_rel = (struct external_reloc *) external_relocs;
1257 ext_rel_end = ext_rel + input_section->reloc_count;
1258 for (i = 0; ext_rel < ext_rel_end; ext_rel++, i++)
1260 struct internal_reloc int_rel;
1262 reloc_howto_type *howto;
1263 struct ecoff_link_hash_entry *h = NULL;
1266 bfd_reloc_status_type r;
1269 mips_ecoff_swap_reloc_in (input_bfd, (PTR) ext_rel, &int_rel);
1272 int_rel = lo_int_rel;
1276 BFD_ASSERT (int_rel.r_type
1277 < sizeof mips_howto_table / sizeof mips_howto_table[0]);
1279 /* The REFHI and RELHI relocs requires special handling. they
1280 must be followed by a REFLO or RELLO reloc, respectively, and
1281 the addend is formed from both relocs. */
1282 if (int_rel.r_type == MIPS_R_REFHI
1283 || int_rel.r_type == MIPS_R_RELHI)
1285 BFD_ASSERT ((ext_rel + 1) < ext_rel_end);
1286 mips_ecoff_swap_reloc_in (input_bfd, (PTR) (ext_rel + 1),
1288 BFD_ASSERT ((lo_int_rel.r_type
1289 == (int_rel.r_type == MIPS_R_REFHI
1292 && int_rel.r_extern == lo_int_rel.r_extern
1293 && int_rel.r_symndx == lo_int_rel.r_symndx);
1297 howto = &mips_howto_table[int_rel.r_type];
1299 /* The SWITCH reloc must be handled specially. This reloc is
1300 marks the location of a difference between two portions of an
1301 object file. The symbol index does not reference a symbol,
1302 but is actually the offset from the reloc to the subtrahend
1303 of the difference. This reloc is correct in the object file,
1304 and needs no further adjustment, unless we are relaxing. If
1305 we are relaxing, we may have to add in an offset. Since no
1306 symbols are involved in this reloc, we handle it completely
1308 if (int_rel.r_type == MIPS_R_SWITCH)
1313 r = _bfd_relocate_contents (howto, input_bfd,
1314 (bfd_vma) offsets[i],
1318 - input_section->vma));
1319 BFD_ASSERT (r == bfd_reloc_ok);
1325 if (int_rel.r_extern)
1327 h = sym_hashes[int_rel.r_symndx];
1328 /* If h is NULL, that means that there is a reloc against an
1329 external symbol which we thought was just a debugging
1330 symbol. This should not happen. */
1331 if (h == (struct ecoff_link_hash_entry *) NULL)
1336 if (int_rel.r_symndx < 0 || int_rel.r_symndx >= NUM_RELOC_SECTIONS)
1339 s = symndx_to_section[int_rel.r_symndx];
1341 if (s == (asection *) NULL)
1345 /* The GPREL reloc uses an addend: the difference in the GP
1347 if (int_rel.r_type != MIPS_R_GPREL
1348 && int_rel.r_type != MIPS_R_LITERAL)
1354 if (! ((*info->callbacks->reloc_dangerous)
1355 (info, "GP relative relocation when GP not defined",
1356 input_bfd, input_section,
1357 int_rel.r_vaddr - input_section->vma)))
1359 /* Only give the error once per link. */
1361 _bfd_set_gp_value (output_bfd, gp);
1362 gp_undefined = false;
1364 if (! int_rel.r_extern)
1366 /* This is a relocation against a section. The current
1367 addend in the instruction is the difference between
1368 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
1369 must change this to be the difference between the
1370 final definition (which will end up in RELOCATION)
1371 and the GP value of OUTPUT_BFD (which is in GP). */
1372 addend = ecoff_data (input_bfd)->gp - gp;
1374 else if (! info->relocateable
1375 || h->root.type == bfd_link_hash_defined
1376 || h->root.type == bfd_link_hash_defweak)
1378 /* This is a relocation against a defined symbol. The
1379 current addend in the instruction is simply the
1380 desired offset into the symbol (normally zero). We
1381 are going to change this into a relocation against a
1382 defined symbol, so we want the instruction to hold
1383 the difference between the final definition of the
1384 symbol (which will end up in RELOCATION) and the GP
1385 value of OUTPUT_BFD (which is in GP). */
1390 /* This is a relocation against an undefined or common
1391 symbol. The current addend in the instruction is
1392 simply the desired offset into the symbol (normally
1393 zero). We are generating relocateable output, and we
1394 aren't going to define this symbol, so we just leave
1395 the instruction alone. */
1400 /* If we are relaxing, mips_relax_section may have set
1401 offsets[i] to some value. A value of 1 means we must expand
1402 a PC relative branch into a multi-instruction of sequence,
1403 and any other value is an addend. */
1407 BFD_ASSERT (! info->relocateable);
1408 BFD_ASSERT (int_rel.r_type == MIPS_R_PCREL16
1409 || int_rel.r_type == MIPS_R_RELHI
1410 || int_rel.r_type == MIPS_R_RELLO);
1411 if (offsets[i] != 1)
1412 addend += offsets[i];
1417 BFD_ASSERT (int_rel.r_extern
1418 && int_rel.r_type == MIPS_R_PCREL16);
1420 /* Move the rest of the instructions up. */
1424 - input_section->vma);
1425 memmove (here + PCREL16_EXPANSION_ADJUSTMENT, here,
1426 (size_t) (input_section->_raw_size
1427 - (int_rel.r_vaddr - input_section->vma)));
1429 /* Generate the new instructions. */
1430 if (! mips_relax_pcrel16 (info, input_bfd, input_section,
1432 (input_section->output_section->vma
1433 + input_section->output_offset
1435 - input_section->vma)
1439 /* We must adjust everything else up a notch. */
1440 adjust += PCREL16_EXPANSION_ADJUSTMENT;
1442 /* mips_relax_pcrel16 handles all the details of this
1448 /* If we are relaxing, and this is a reloc against the .text
1449 segment, we may need to adjust it if some branches have been
1450 expanded. The reloc types which are likely to occur in the
1451 .text section are handled efficiently by mips_relax_section,
1452 and thus do not need to be handled here. */
1453 if (ecoff_data (input_bfd)->debug_info.adjust != NULL
1454 && ! int_rel.r_extern
1455 && int_rel.r_symndx == RELOC_SECTION_TEXT
1456 && (strcmp (bfd_get_section_name (input_bfd, input_section),
1458 || (int_rel.r_type != MIPS_R_PCREL16
1459 && int_rel.r_type != MIPS_R_SWITCH
1460 && int_rel.r_type != MIPS_R_RELHI
1461 && int_rel.r_type != MIPS_R_RELLO)))
1464 struct ecoff_value_adjust *a;
1466 /* We need to get the addend so that we know whether we need
1467 to adjust the address. */
1468 BFD_ASSERT (int_rel.r_type == MIPS_R_REFWORD);
1470 adr = bfd_get_32 (input_bfd,
1474 - input_section->vma));
1476 for (a = ecoff_data (input_bfd)->debug_info.adjust;
1477 a != (struct ecoff_value_adjust *) NULL;
1480 if (adr >= a->start && adr < a->end)
1481 addend += a->adjust;
1485 if (info->relocateable)
1487 /* We are generating relocateable output, and must convert
1488 the existing reloc. */
1489 if (int_rel.r_extern)
1491 if ((h->root.type == bfd_link_hash_defined
1492 || h->root.type == bfd_link_hash_defweak)
1493 && ! bfd_is_abs_section (h->root.u.def.section))
1497 /* This symbol is defined in the output. Convert
1498 the reloc from being against the symbol to being
1499 against the section. */
1501 /* Clear the r_extern bit. */
1502 int_rel.r_extern = 0;
1504 /* Compute a new r_symndx value. */
1505 s = h->root.u.def.section;
1506 name = bfd_get_section_name (output_bfd,
1509 int_rel.r_symndx = -1;
1513 if (strcmp (name, ".bss") == 0)
1514 int_rel.r_symndx = RELOC_SECTION_BSS;
1517 if (strcmp (name, ".data") == 0)
1518 int_rel.r_symndx = RELOC_SECTION_DATA;
1521 if (strcmp (name, ".fini") == 0)
1522 int_rel.r_symndx = RELOC_SECTION_FINI;
1525 if (strcmp (name, ".init") == 0)
1526 int_rel.r_symndx = RELOC_SECTION_INIT;
1529 if (strcmp (name, ".lit8") == 0)
1530 int_rel.r_symndx = RELOC_SECTION_LIT8;
1531 else if (strcmp (name, ".lit4") == 0)
1532 int_rel.r_symndx = RELOC_SECTION_LIT4;
1535 if (strcmp (name, ".rdata") == 0)
1536 int_rel.r_symndx = RELOC_SECTION_RDATA;
1539 if (strcmp (name, ".sdata") == 0)
1540 int_rel.r_symndx = RELOC_SECTION_SDATA;
1541 else if (strcmp (name, ".sbss") == 0)
1542 int_rel.r_symndx = RELOC_SECTION_SBSS;
1545 if (strcmp (name, ".text") == 0)
1546 int_rel.r_symndx = RELOC_SECTION_TEXT;
1550 if (int_rel.r_symndx == -1)
1553 /* Add the section VMA and the symbol value. */
1554 relocation = (h->root.u.def.value
1555 + s->output_section->vma
1556 + s->output_offset);
1558 /* For a PC relative relocation, the object file
1559 currently holds just the addend. We must adjust
1560 by the address to get the right value. */
1561 if (howto->pc_relative)
1563 relocation -= int_rel.r_vaddr - input_section->vma;
1565 /* If we are converting a RELHI or RELLO reloc
1566 from being against an external symbol to
1567 being against a section, we must put a
1568 special value into the r_offset field. This
1569 value is the old addend. The r_offset for
1570 both the RELOHI and RELLO relocs are the
1571 same, and we set both when we see RELHI. */
1572 if (int_rel.r_type == MIPS_R_RELHI)
1576 addhi = bfd_get_32 (input_bfd,
1580 - input_section->vma));
1586 addlo = bfd_get_32 (input_bfd,
1589 + lo_int_rel.r_vaddr
1590 - input_section->vma));
1595 int_rel.r_offset = addhi + addlo;
1596 lo_int_rel.r_offset = int_rel.r_offset;
1604 /* Change the symndx value to the right one for the
1606 int_rel.r_symndx = h->indx;
1607 if (int_rel.r_symndx == -1)
1609 /* This symbol is not being written out. */
1610 if (! ((*info->callbacks->unattached_reloc)
1611 (info, h->root.root.string, input_bfd,
1613 int_rel.r_vaddr - input_section->vma)))
1615 int_rel.r_symndx = 0;
1622 /* This is a relocation against a section. Adjust the
1623 value by the amount the section moved. */
1624 relocation = (s->output_section->vma
1629 relocation += addend;
1632 /* Adjust a PC relative relocation by removing the reference
1633 to the original address in the section and including the
1634 reference to the new address. However, external RELHI
1635 and RELLO relocs are PC relative, but don't include any
1636 reference to the address. The addend is merely an
1638 if (howto->pc_relative
1639 && (! int_rel.r_extern
1640 || (int_rel.r_type != MIPS_R_RELHI
1641 && int_rel.r_type != MIPS_R_RELLO)))
1642 relocation -= (input_section->output_section->vma
1643 + input_section->output_offset
1644 - input_section->vma);
1646 /* Adjust the contents. */
1647 if (relocation == 0)
1651 if (int_rel.r_type != MIPS_R_REFHI
1652 && int_rel.r_type != MIPS_R_RELHI)
1653 r = _bfd_relocate_contents (howto, input_bfd, relocation,
1657 - input_section->vma));
1660 mips_relocate_hi (&int_rel, &lo_int_rel,
1661 input_bfd, input_section, contents,
1663 int_rel.r_type == MIPS_R_RELHI);
1668 /* Adjust the reloc address. */
1669 int_rel.r_vaddr += (input_section->output_section->vma
1670 + input_section->output_offset
1671 - input_section->vma);
1673 /* Save the changed reloc information. */
1674 mips_ecoff_swap_reloc_out (input_bfd, &int_rel, (PTR) ext_rel);
1678 /* We are producing a final executable. */
1679 if (int_rel.r_extern)
1681 /* This is a reloc against a symbol. */
1682 if (h->root.type == bfd_link_hash_defined
1683 || h->root.type == bfd_link_hash_defweak)
1687 hsec = h->root.u.def.section;
1688 relocation = (h->root.u.def.value
1689 + hsec->output_section->vma
1690 + hsec->output_offset);
1694 if (! ((*info->callbacks->undefined_symbol)
1695 (info, h->root.root.string, input_bfd,
1697 int_rel.r_vaddr - input_section->vma)))
1704 /* This is a reloc against a section. */
1705 relocation = (s->output_section->vma
1709 /* A PC relative reloc is already correct in the object
1710 file. Make it look like a pcrel_offset relocation by
1711 adding in the start address. */
1712 if (howto->pc_relative)
1714 if (int_rel.r_type != MIPS_R_RELHI)
1715 relocation += int_rel.r_vaddr + adjust;
1717 relocation += lo_int_rel.r_vaddr + adjust;
1721 if (int_rel.r_type != MIPS_R_REFHI
1722 && int_rel.r_type != MIPS_R_RELHI)
1723 r = _bfd_final_link_relocate (howto,
1728 - input_section->vma
1734 mips_relocate_hi (&int_rel, &lo_int_rel, input_bfd,
1735 input_section, contents, adjust,
1737 int_rel.r_type == MIPS_R_RELHI);
1742 /* MIPS_R_JMPADDR requires peculiar overflow detection. The
1743 instruction provides a 28 bit address (the two lower bits are
1744 implicit zeroes) which is combined with the upper four bits
1745 of the instruction address. */
1746 if (r == bfd_reloc_ok
1747 && int_rel.r_type == MIPS_R_JMPADDR
1750 + (int_rel.r_extern ? 0 : s->vma))
1752 != ((input_section->output_section->vma
1753 + input_section->output_offset
1754 + (int_rel.r_vaddr - input_section->vma)
1757 r = bfd_reloc_overflow;
1759 if (r != bfd_reloc_ok)
1764 case bfd_reloc_outofrange:
1766 case bfd_reloc_overflow:
1770 if (int_rel.r_extern)
1771 name = h->root.root.string;
1773 name = bfd_section_name (input_bfd, s);
1774 if (! ((*info->callbacks->reloc_overflow)
1775 (info, name, howto->name, (bfd_vma) 0,
1776 input_bfd, input_section,
1777 int_rel.r_vaddr - input_section->vma)))
1788 /* Read in the relocs for a section. */
1791 mips_read_relocs (abfd, sec)
1795 struct ecoff_section_tdata *section_tdata;
1797 section_tdata = ecoff_section_data (abfd, sec);
1798 if (section_tdata == (struct ecoff_section_tdata *) NULL)
1801 (PTR) bfd_alloc_by_size_t (abfd, sizeof (struct ecoff_section_tdata));
1802 if (sec->used_by_bfd == NULL)
1805 section_tdata = ecoff_section_data (abfd, sec);
1806 section_tdata->external_relocs = NULL;
1807 section_tdata->contents = NULL;
1808 section_tdata->offsets = NULL;
1811 if (section_tdata->external_relocs == NULL)
1813 bfd_size_type external_relocs_size;
1815 external_relocs_size = (ecoff_backend (abfd)->external_reloc_size
1816 * sec->reloc_count);
1818 section_tdata->external_relocs =
1819 (PTR) bfd_alloc (abfd, external_relocs_size);
1820 if (section_tdata->external_relocs == NULL && external_relocs_size != 0)
1823 if (bfd_seek (abfd, sec->rel_filepos, SEEK_SET) != 0
1824 || (bfd_read (section_tdata->external_relocs, 1,
1825 external_relocs_size, abfd)
1826 != external_relocs_size))
1833 /* Relax a section when linking a MIPS ECOFF file. This is used for
1834 embedded PIC code, which always uses PC relative branches which
1835 only have an 18 bit range on MIPS. If a branch is not in range, we
1836 generate a long instruction sequence to compensate. Each time we
1837 find a branch to expand, we have to check all the others again to
1838 make sure they are still in range. This is slow, but it only has
1839 to be done when -relax is passed to the linker.
1841 This routine figures out which branches need to expand; the actual
1842 expansion is done in mips_relocate_section when the section
1843 contents are relocated. The information is stored in the offsets
1844 field of the ecoff_section_tdata structure. An offset of 1 means
1845 that the branch must be expanded into a multi-instruction PC
1846 relative branch (such an offset will only occur for a PC relative
1847 branch to an external symbol). Any other offset must be a multiple
1848 of four, and is the amount to change the branch by (such an offset
1849 will only occur for a PC relative branch within the same section).
1851 We do not modify the section relocs or contents themselves so that
1852 if memory usage becomes an issue we can discard them and read them
1853 again. The only information we must save in memory between this
1854 routine and the mips_relocate_section routine is the table of
1858 mips_relax_section (abfd, sec, info, again)
1861 struct bfd_link_info *info;
1864 struct ecoff_section_tdata *section_tdata;
1865 bfd_byte *contents = NULL;
1867 struct external_reloc *ext_rel;
1868 struct external_reloc *ext_rel_end;
1871 /* Assume we are not going to need another pass. */
1874 /* If we are not generating an ECOFF file, this is much too
1875 confusing to deal with. */
1876 if (info->hash->creator->flavour != bfd_get_flavour (abfd))
1879 /* If there are no relocs, there is nothing to do. */
1880 if (sec->reloc_count == 0)
1883 /* We are only interested in PC relative relocs, and why would there
1884 ever be one from anything but the .text section? */
1885 if (strcmp (bfd_get_section_name (abfd, sec), ".text") != 0)
1888 /* Read in the relocs, if we haven't already got them. */
1889 section_tdata = ecoff_section_data (abfd, sec);
1890 if (section_tdata == (struct ecoff_section_tdata *) NULL
1891 || section_tdata->external_relocs == NULL)
1893 if (! mips_read_relocs (abfd, sec))
1895 section_tdata = ecoff_section_data (abfd, sec);
1898 if (sec->_cooked_size == 0)
1900 /* We must initialize _cooked_size only the first time we are
1902 sec->_cooked_size = sec->_raw_size;
1905 contents = section_tdata->contents;
1906 offsets = section_tdata->offsets;
1908 /* Look for any external PC relative relocs. Internal PC relative
1909 relocs are already correct in the object file, so they certainly
1910 can not overflow. */
1911 ext_rel = (struct external_reloc *) section_tdata->external_relocs;
1912 ext_rel_end = ext_rel + sec->reloc_count;
1913 for (i = 0; ext_rel < ext_rel_end; ext_rel++, i++)
1915 struct internal_reloc int_rel;
1916 struct ecoff_link_hash_entry *h;
1918 bfd_signed_vma relocation;
1919 struct external_reloc *adj_ext_rel;
1921 unsigned long ext_count;
1922 struct ecoff_link_hash_entry **adj_h_ptr;
1923 struct ecoff_link_hash_entry **adj_h_ptr_end;
1924 struct ecoff_value_adjust *adjust;
1926 /* If we have already expanded this reloc, we certainly don't
1927 need to do it again. */
1928 if (offsets != (long *) NULL && offsets[i] == 1)
1931 /* Quickly check that this reloc is external PCREL16. */
1932 if (bfd_header_big_endian (abfd))
1934 if ((ext_rel->r_bits[3] & RELOC_BITS3_EXTERN_BIG) == 0
1935 || (((ext_rel->r_bits[3] & RELOC_BITS3_TYPE_BIG)
1936 >> RELOC_BITS3_TYPE_SH_BIG)
1942 if ((ext_rel->r_bits[3] & RELOC_BITS3_EXTERN_LITTLE) == 0
1943 || (((ext_rel->r_bits[3] & RELOC_BITS3_TYPE_LITTLE)
1944 >> RELOC_BITS3_TYPE_SH_LITTLE)
1949 mips_ecoff_swap_reloc_in (abfd, (PTR) ext_rel, &int_rel);
1951 h = ecoff_data (abfd)->sym_hashes[int_rel.r_symndx];
1952 if (h == (struct ecoff_link_hash_entry *) NULL)
1955 if (h->root.type != bfd_link_hash_defined
1956 && h->root.type != bfd_link_hash_defweak)
1958 /* Just ignore undefined symbols. These will presumably
1959 generate an error later in the link. */
1963 /* Get the value of the symbol. */
1964 hsec = h->root.u.def.section;
1965 relocation = (h->root.u.def.value
1966 + hsec->output_section->vma
1967 + hsec->output_offset);
1969 /* Subtract out the current address. */
1970 relocation -= (sec->output_section->vma
1971 + sec->output_offset
1972 + (int_rel.r_vaddr - sec->vma));
1974 /* The addend is stored in the object file. In the normal case
1975 of ``bal symbol'', the addend will be -4. It will only be
1976 different in the case of ``bal symbol+constant''. To avoid
1977 always reading in the section contents, we don't check the
1978 addend in the object file (we could easily check the contents
1979 if we happen to have already read them in, but I fear that
1980 this could be confusing). This means we will screw up if
1981 there is a branch to a symbol that is in range, but added to
1982 a constant which puts it out of range; in such a case the
1983 link will fail with a reloc overflow error. Since the
1984 compiler will never generate such code, it should be easy
1985 enough to work around it by changing the assembly code in the
1989 /* Now RELOCATION is the number we want to put in the object
1990 file. See whether it fits. */
1991 if (relocation >= -0x20000 && relocation < 0x20000)
1994 /* Now that we know this reloc needs work, which will rarely
1995 happen, go ahead and grab the section contents. */
1996 if (contents == (bfd_byte *) NULL)
1998 if (info->keep_memory)
1999 contents = (bfd_byte *) bfd_alloc (abfd, sec->_raw_size);
2001 contents = (bfd_byte *) bfd_malloc ((size_t) sec->_raw_size);
2002 if (contents == (bfd_byte *) NULL)
2004 if (! bfd_get_section_contents (abfd, sec, (PTR) contents,
2005 (file_ptr) 0, sec->_raw_size))
2007 if (info->keep_memory)
2008 section_tdata->contents = contents;
2011 /* We only support changing the bal instruction. It would be
2012 possible to handle other PC relative branches, but some of
2013 them (the conditional branches) would require a different
2014 length instruction sequence which would complicate both this
2015 routine and mips_relax_pcrel16. It could be written if
2016 somebody felt it were important. Ignoring this reloc will
2017 presumably cause a reloc overflow error later on. */
2018 if (bfd_get_32 (abfd, contents + int_rel.r_vaddr - sec->vma)
2019 != 0x0411ffff) /* bgezal $0,. == bal . */
2022 /* Bother. We need to expand this reloc, and we will need to
2023 make another relaxation pass since this change may put other
2024 relocs out of range. We need to examine the local branches
2025 and we need to allocate memory to hold the offsets we must
2026 add to them. We also need to adjust the values of all
2027 symbols in the object file following this location. */
2029 sec->_cooked_size += PCREL16_EXPANSION_ADJUSTMENT;
2032 if (offsets == (long *) NULL)
2036 size = sec->reloc_count * sizeof (long);
2037 offsets = (long *) bfd_alloc_by_size_t (abfd, size);
2038 if (offsets == (long *) NULL)
2040 memset (offsets, 0, size);
2041 section_tdata->offsets = offsets;
2046 /* Now look for all PC relative references that cross this reloc
2047 and adjust their offsets. */
2048 adj_ext_rel = (struct external_reloc *) section_tdata->external_relocs;
2049 for (adj_i = 0; adj_ext_rel < ext_rel_end; adj_ext_rel++, adj_i++)
2051 struct internal_reloc adj_int_rel;
2052 bfd_vma start, stop;
2055 mips_ecoff_swap_reloc_in (abfd, (PTR) adj_ext_rel, &adj_int_rel);
2057 if (adj_int_rel.r_type == MIPS_R_PCREL16)
2061 /* We only care about local references. External ones
2062 will be relocated correctly anyhow. */
2063 if (adj_int_rel.r_extern)
2066 /* We are only interested in a PC relative reloc within
2067 this section. FIXME: Cross section PC relative
2068 relocs may not be handled correctly; does anybody
2070 if (adj_int_rel.r_symndx != RELOC_SECTION_TEXT)
2073 start = adj_int_rel.r_vaddr;
2075 insn = bfd_get_32 (abfd,
2076 contents + adj_int_rel.r_vaddr - sec->vma);
2078 stop = (insn & 0xffff) << 2;
2079 if ((stop & 0x20000) != 0)
2081 stop += adj_int_rel.r_vaddr + 4;
2083 else if (adj_int_rel.r_type == MIPS_R_RELHI)
2085 struct internal_reloc rello;
2088 /* The next reloc must be MIPS_R_RELLO, and we handle
2090 BFD_ASSERT (adj_ext_rel + 1 < ext_rel_end);
2092 mips_ecoff_swap_reloc_in (abfd, (PTR) (adj_ext_rel + 1), &rello);
2094 BFD_ASSERT (rello.r_type == MIPS_R_RELLO);
2096 addhi = bfd_get_32 (abfd,
2097 contents + adj_int_rel.r_vaddr - sec->vma);
2103 addlo = bfd_get_32 (abfd, contents + rello.r_vaddr - sec->vma);
2108 if (adj_int_rel.r_extern)
2110 /* The value we want here is
2111 sym - RELLOaddr + addend
2112 which we can express as
2113 sym - (RELLOaddr - addend)
2114 Therefore if we are expanding the area between
2115 RELLOaddr and RELLOaddr - addend we must adjust
2116 the addend. This is admittedly ambiguous, since
2117 we might mean (sym + addend) - RELLOaddr, but in
2118 practice we don't, and there is no way to handle
2119 that case correctly since at this point we have
2120 no idea whether any reloc is being expanded
2121 between sym and sym + addend. */
2122 start = rello.r_vaddr - (addhi + addlo);
2123 stop = rello.r_vaddr;
2127 /* An internal RELHI/RELLO pair represents the
2128 difference between two addresses, $LC0 - foo.
2129 The symndx value is actually the difference
2130 between the reloc address and $LC0. This lets us
2131 compute $LC0, and, by considering the addend,
2132 foo. If the reloc we are expanding falls between
2133 those two relocs, we must adjust the addend. At
2134 this point, the symndx value is actually in the
2135 r_offset field, where it was put by
2136 mips_ecoff_swap_reloc_in. */
2137 start = rello.r_vaddr - adj_int_rel.r_offset;
2138 stop = start + addhi + addlo;
2141 else if (adj_int_rel.r_type == MIPS_R_SWITCH)
2143 /* A MIPS_R_SWITCH reloc represents a word of the form
2145 The value in the object file is correct, assuming the
2146 original value of $L3. The symndx value is actually
2147 the difference between the reloc address and $LS12.
2148 This lets us compute the original value of $LS12 as
2150 and the original value of $L3 as
2151 vaddr - symndx + addend
2152 where addend is the value from the object file. At
2153 this point, the symndx value is actually found in the
2154 r_offset field, since it was moved by
2155 mips_ecoff_swap_reloc_in. */
2156 start = adj_int_rel.r_vaddr - adj_int_rel.r_offset;
2157 stop = start + bfd_get_32 (abfd,
2159 + adj_int_rel.r_vaddr
2165 /* If the range expressed by this reloc, which is the
2166 distance between START and STOP crosses the reloc we are
2167 expanding, we must adjust the offset. The sign of the
2168 adjustment depends upon the direction in which the range
2169 crosses the reloc being expanded. */
2170 if (start <= int_rel.r_vaddr && stop > int_rel.r_vaddr)
2171 change = PCREL16_EXPANSION_ADJUSTMENT;
2172 else if (start > int_rel.r_vaddr && stop <= int_rel.r_vaddr)
2173 change = - PCREL16_EXPANSION_ADJUSTMENT;
2177 offsets[adj_i] += change;
2179 if (adj_int_rel.r_type == MIPS_R_RELHI)
2183 offsets[adj_i] += change;
2187 /* Find all symbols in this section defined by this object file
2188 and adjust their values. Note that we decide whether to
2189 adjust the value based on the value stored in the ECOFF EXTR
2190 structure, because the value stored in the hash table may
2191 have been changed by an earlier expanded reloc and thus may
2192 no longer correctly indicate whether the symbol is before or
2193 after the expanded reloc. */
2194 ext_count = ecoff_data (abfd)->debug_info.symbolic_header.iextMax;
2195 adj_h_ptr = ecoff_data (abfd)->sym_hashes;
2196 adj_h_ptr_end = adj_h_ptr + ext_count;
2197 for (; adj_h_ptr < adj_h_ptr_end; adj_h_ptr++)
2199 struct ecoff_link_hash_entry *adj_h;
2202 if (adj_h != (struct ecoff_link_hash_entry *) NULL
2203 && (adj_h->root.type == bfd_link_hash_defined
2204 || adj_h->root.type == bfd_link_hash_defweak)
2205 && adj_h->root.u.def.section == sec
2206 && adj_h->esym.asym.value > int_rel.r_vaddr)
2207 adj_h->root.u.def.value += PCREL16_EXPANSION_ADJUSTMENT;
2210 /* Add an entry to the symbol value adjust list. This is used
2211 by bfd_ecoff_debug_accumulate to adjust the values of
2212 internal symbols and FDR's. */
2213 adjust = ((struct ecoff_value_adjust *)
2214 bfd_alloc (abfd, sizeof (struct ecoff_value_adjust)));
2215 if (adjust == (struct ecoff_value_adjust *) NULL)
2218 adjust->start = int_rel.r_vaddr;
2219 adjust->end = sec->vma + sec->_raw_size;
2220 adjust->adjust = PCREL16_EXPANSION_ADJUSTMENT;
2222 adjust->next = ecoff_data (abfd)->debug_info.adjust;
2223 ecoff_data (abfd)->debug_info.adjust = adjust;
2226 if (contents != (bfd_byte *) NULL && ! info->keep_memory)
2232 if (contents != (bfd_byte *) NULL && ! info->keep_memory)
2237 /* This routine is called from mips_relocate_section when a PC
2238 relative reloc must be expanded into the five instruction sequence.
2239 It handles all the details of the expansion, including resolving
2243 mips_relax_pcrel16 (info, input_bfd, input_section, h, location, address)
2244 struct bfd_link_info *info;
2246 asection *input_section;
2247 struct ecoff_link_hash_entry *h;
2253 /* 0x0411ffff is bgezal $0,. == bal . */
2254 BFD_ASSERT (bfd_get_32 (input_bfd, location) == 0x0411ffff);
2256 /* We need to compute the distance between the symbol and the
2257 current address plus eight. */
2258 relocation = (h->root.u.def.value
2259 + h->root.u.def.section->output_section->vma
2260 + h->root.u.def.section->output_offset);
2261 relocation -= address + 8;
2263 /* If the lower half is negative, increment the upper 16 half. */
2264 if ((relocation & 0x8000) != 0)
2265 relocation += 0x10000;
2267 bfd_put_32 (input_bfd, 0x04110001, location); /* bal .+8 */
2268 bfd_put_32 (input_bfd,
2269 0x3c010000 | ((relocation >> 16) & 0xffff), /* lui $at,XX */
2271 bfd_put_32 (input_bfd,
2272 0x24210000 | (relocation & 0xffff), /* addiu $at,$at,XX */
2274 bfd_put_32 (input_bfd, 0x003f0821, location + 12); /* addu $at,$at,$ra */
2275 bfd_put_32 (input_bfd, 0x0020f809, location + 16); /* jalr $at */
2280 /* Given a .sdata section and a .rel.sdata in-memory section, store
2281 relocation information into the .rel.sdata section which can be
2282 used at runtime to relocate the section. This is called by the
2283 linker when the --embedded-relocs switch is used. This is called
2284 after the add_symbols entry point has been called for all the
2285 objects, and before the final_link entry point is called. This
2286 function presumes that the object was compiled using
2290 bfd_mips_ecoff_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
2292 struct bfd_link_info *info;
2297 struct ecoff_link_hash_entry **sym_hashes;
2298 struct ecoff_section_tdata *section_tdata;
2299 struct external_reloc *ext_rel;
2300 struct external_reloc *ext_rel_end;
2303 BFD_ASSERT (! info->relocateable);
2307 if (datasec->reloc_count == 0)
2310 sym_hashes = ecoff_data (abfd)->sym_hashes;
2312 if (! mips_read_relocs (abfd, datasec))
2315 relsec->contents = (bfd_byte *) bfd_alloc (abfd, datasec->reloc_count * 4);
2316 if (relsec->contents == NULL)
2319 p = relsec->contents;
2321 section_tdata = ecoff_section_data (abfd, datasec);
2322 ext_rel = (struct external_reloc *) section_tdata->external_relocs;
2323 ext_rel_end = ext_rel + datasec->reloc_count;
2324 for (; ext_rel < ext_rel_end; ext_rel++, p += 4)
2326 struct internal_reloc int_rel;
2327 boolean text_relative;
2329 mips_ecoff_swap_reloc_in (abfd, (PTR) ext_rel, &int_rel);
2331 /* We are going to write a four byte word into the runtime reloc
2332 section. The word will be the address in the data section
2333 which must be relocated. This must be on a word boundary,
2334 which means the lower two bits must be zero. We use the
2335 least significant bit to indicate how the value in the data
2336 section must be relocated. A 0 means that the value is
2337 relative to the text section, while a 1 indicates that the
2338 value is relative to the data section. Given that we are
2339 assuming the code was compiled using -membedded-pic, there
2340 should not be any other possibilities. */
2342 /* We can only relocate REFWORD relocs at run time. */
2343 if (int_rel.r_type != MIPS_R_REFWORD)
2345 *errmsg = "unsupported reloc type";
2346 bfd_set_error (bfd_error_bad_value);
2350 if (int_rel.r_extern)
2352 struct ecoff_link_hash_entry *h;
2354 h = sym_hashes[int_rel.r_symndx];
2355 /* If h is NULL, that means that there is a reloc against an
2356 external symbol which we thought was just a debugging
2357 symbol. This should not happen. */
2358 if (h == (struct ecoff_link_hash_entry *) NULL)
2360 if ((h->root.type == bfd_link_hash_defined
2361 || h->root.type == bfd_link_hash_defweak)
2362 && (h->root.u.def.section->flags & SEC_CODE) != 0)
2363 text_relative = true;
2365 text_relative = false;
2369 switch (int_rel.r_symndx)
2371 case RELOC_SECTION_TEXT:
2372 text_relative = true;
2374 case RELOC_SECTION_SDATA:
2375 case RELOC_SECTION_SBSS:
2376 case RELOC_SECTION_LIT8:
2377 text_relative = false;
2380 /* No other sections should appear in -membedded-pic
2382 *errmsg = "reloc against unsupported section";
2383 bfd_set_error (bfd_error_bad_value);
2388 if ((int_rel.r_offset & 3) != 0)
2390 *errmsg = "reloc not properly aligned";
2391 bfd_set_error (bfd_error_bad_value);
2396 (int_rel.r_vaddr - datasec->vma + datasec->output_offset
2397 + (text_relative ? 0 : 1)),
2404 /* This is the ECOFF backend structure. The backend field of the
2405 target vector points to this. */
2407 static const struct ecoff_backend_data mips_ecoff_backend_data =
2409 /* COFF backend structure. */
2411 (void (*) PARAMS ((bfd *,PTR,int,int,int,int,PTR))) bfd_void, /* aux_in */
2412 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_in */
2413 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_in */
2414 (unsigned (*) PARAMS ((bfd *,PTR,int,int,int,int,PTR)))bfd_void,/*aux_out*/
2415 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_out */
2416 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_out */
2417 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* reloc_out */
2418 mips_ecoff_swap_filehdr_out, mips_ecoff_swap_aouthdr_out,
2419 mips_ecoff_swap_scnhdr_out,
2420 FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, 0, true,
2421 mips_ecoff_swap_filehdr_in, mips_ecoff_swap_aouthdr_in,
2422 mips_ecoff_swap_scnhdr_in, NULL,
2423 mips_ecoff_bad_format_hook, _bfd_ecoff_set_arch_mach_hook,
2424 _bfd_ecoff_mkobject_hook, _bfd_ecoff_styp_to_sec_flags,
2425 _bfd_ecoff_set_alignment_hook, _bfd_ecoff_slurp_symbol_table,
2426 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
2428 /* Supported architecture. */
2430 /* Initial portion of armap string. */
2432 /* The page boundary used to align sections in a demand-paged
2433 executable file. E.g., 0x1000. */
2435 /* True if the .rdata section is part of the text segment, as on the
2436 Alpha. False if .rdata is part of the data segment, as on the
2439 /* Bitsize of constructor entries. */
2441 /* Reloc to use for constructor entries. */
2442 &mips_howto_table[MIPS_R_REFWORD],
2444 /* Symbol table magic number. */
2446 /* Alignment of debugging information. E.g., 4. */
2448 /* Sizes of external symbolic information. */
2449 sizeof (struct hdr_ext),
2450 sizeof (struct dnr_ext),
2451 sizeof (struct pdr_ext),
2452 sizeof (struct sym_ext),
2453 sizeof (struct opt_ext),
2454 sizeof (struct fdr_ext),
2455 sizeof (struct rfd_ext),
2456 sizeof (struct ext_ext),
2457 /* Functions to swap in external symbolic data. */
2466 _bfd_ecoff_swap_tir_in,
2467 _bfd_ecoff_swap_rndx_in,
2468 /* Functions to swap out external symbolic data. */
2477 _bfd_ecoff_swap_tir_out,
2478 _bfd_ecoff_swap_rndx_out,
2479 /* Function to read in symbolic data. */
2480 _bfd_ecoff_slurp_symbolic_info
2482 /* External reloc size. */
2484 /* Reloc swapping functions. */
2485 mips_ecoff_swap_reloc_in,
2486 mips_ecoff_swap_reloc_out,
2487 /* Backend reloc tweaking. */
2488 mips_adjust_reloc_in,
2489 mips_adjust_reloc_out,
2490 /* Relocate section contents while linking. */
2491 mips_relocate_section,
2492 /* Do final adjustments to filehdr and aouthdr. */
2494 /* Read an element from an archive at a given file position. */
2495 _bfd_get_elt_at_filepos
2498 /* Looking up a reloc type is MIPS specific. */
2499 #define _bfd_ecoff_bfd_reloc_type_lookup mips_bfd_reloc_type_lookup
2501 /* Getting relocated section contents is generic. */
2502 #define _bfd_ecoff_bfd_get_relocated_section_contents \
2503 bfd_generic_get_relocated_section_contents
2505 /* Handling file windows is generic. */
2506 #define _bfd_ecoff_get_section_contents_in_window \
2507 _bfd_generic_get_section_contents_in_window
2509 /* Relaxing sections is MIPS specific. */
2510 #define _bfd_ecoff_bfd_relax_section mips_relax_section
2512 const bfd_target ecoff_little_vec =
2514 "ecoff-littlemips", /* name */
2515 bfd_target_ecoff_flavour,
2516 BFD_ENDIAN_LITTLE, /* data byte order is little */
2517 BFD_ENDIAN_LITTLE, /* header byte order is little */
2519 (HAS_RELOC | EXEC_P | /* object flags */
2520 HAS_LINENO | HAS_DEBUG |
2521 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
2523 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA),
2524 0, /* leading underscore */
2525 ' ', /* ar_pad_char */
2526 15, /* ar_max_namelen */
2527 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
2528 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
2529 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
2530 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
2531 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
2532 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
2534 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
2535 _bfd_ecoff_archive_p, _bfd_dummy_target},
2536 {bfd_false, _bfd_ecoff_mkobject, /* bfd_set_format */
2537 _bfd_generic_mkarchive, bfd_false},
2538 {bfd_false, _bfd_ecoff_write_object_contents, /* bfd_write_contents */
2539 _bfd_write_archive_contents, bfd_false},
2541 BFD_JUMP_TABLE_GENERIC (_bfd_ecoff),
2542 BFD_JUMP_TABLE_COPY (_bfd_ecoff),
2543 BFD_JUMP_TABLE_CORE (_bfd_nocore),
2544 BFD_JUMP_TABLE_ARCHIVE (_bfd_ecoff),
2545 BFD_JUMP_TABLE_SYMBOLS (_bfd_ecoff),
2546 BFD_JUMP_TABLE_RELOCS (_bfd_ecoff),
2547 BFD_JUMP_TABLE_WRITE (_bfd_ecoff),
2548 BFD_JUMP_TABLE_LINK (_bfd_ecoff),
2549 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2551 (PTR) &mips_ecoff_backend_data
2554 const bfd_target ecoff_big_vec =
2556 "ecoff-bigmips", /* name */
2557 bfd_target_ecoff_flavour,
2558 BFD_ENDIAN_BIG, /* data byte order is big */
2559 BFD_ENDIAN_BIG, /* header byte order is big */
2561 (HAS_RELOC | EXEC_P | /* object flags */
2562 HAS_LINENO | HAS_DEBUG |
2563 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
2565 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA),
2566 0, /* leading underscore */
2567 ' ', /* ar_pad_char */
2568 15, /* ar_max_namelen */
2569 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2570 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2571 bfd_getb16, bfd_getb_signed_16, bfd_putb16,
2572 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2573 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2574 bfd_getb16, bfd_getb_signed_16, bfd_putb16,
2575 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
2576 _bfd_ecoff_archive_p, _bfd_dummy_target},
2577 {bfd_false, _bfd_ecoff_mkobject, /* bfd_set_format */
2578 _bfd_generic_mkarchive, bfd_false},
2579 {bfd_false, _bfd_ecoff_write_object_contents, /* bfd_write_contents */
2580 _bfd_write_archive_contents, bfd_false},
2582 BFD_JUMP_TABLE_GENERIC (_bfd_ecoff),
2583 BFD_JUMP_TABLE_COPY (_bfd_ecoff),
2584 BFD_JUMP_TABLE_CORE (_bfd_nocore),
2585 BFD_JUMP_TABLE_ARCHIVE (_bfd_ecoff),
2586 BFD_JUMP_TABLE_SYMBOLS (_bfd_ecoff),
2587 BFD_JUMP_TABLE_RELOCS (_bfd_ecoff),
2588 BFD_JUMP_TABLE_WRITE (_bfd_ecoff),
2589 BFD_JUMP_TABLE_LINK (_bfd_ecoff),
2590 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2592 (PTR) &mips_ecoff_backend_data