1 /* MIPS-specific support for 32-bit ELF
2 Copyright 1993, 1994 Free Software Foundation, Inc.
4 Most of the information added by Ian Lance Taylor, Cygnus Support,
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
31 /* Get the ECOFF swapping routines. */
33 #include "coff/symconst.h"
34 #include "coff/internal.h"
35 #include "coff/ecoff.h"
36 #include "coff/mips.h"
38 #include "ecoffswap.h"
40 static bfd_reloc_status_type mips_elf_hi16_reloc PARAMS ((bfd *abfd,
47 static bfd_reloc_status_type mips_elf_got16_reloc PARAMS ((bfd *abfd,
54 static bfd_reloc_status_type mips_elf_lo16_reloc PARAMS ((bfd *abfd,
61 static bfd_reloc_status_type mips_elf_gprel16_reloc PARAMS ((bfd *abfd,
68 static const struct reloc_howto_struct *bfd_elf32_bfd_reloc_type_lookup
69 PARAMS ((bfd *, bfd_reloc_code_real_type));
70 static void mips_info_to_howto_rel
71 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
72 static boolean mips_elf_sym_is_global PARAMS ((bfd *, asymbol *));
73 static boolean mips_elf_object_p PARAMS ((bfd *));
74 static void mips_elf_final_write_processing PARAMS ((bfd *));
75 static boolean mips_elf_section_from_shdr
76 PARAMS ((bfd *, Elf32_Internal_Shdr *, char *));
77 static boolean mips_elf_fake_sections
78 PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *));
79 static boolean mips_elf_section_from_bfd_section
80 PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *, int *));
81 static boolean mips_elf_section_processing
82 PARAMS ((bfd *, Elf32_Internal_Shdr *));
83 static void mips_elf_symbol_processing PARAMS ((bfd *, asymbol *));
84 static boolean mips_elf_read_ecoff_info
85 PARAMS ((bfd *, asection *, struct ecoff_debug_info *));
86 static struct bfd_hash_entry *mips_elf_link_hash_newfunc
87 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
88 static struct bfd_link_hash_table *mips_elf_link_hash_table_create
90 static int gptab_compare PARAMS ((const void *, const void *));
91 static boolean mips_elf_final_link
92 PARAMS ((bfd *, struct bfd_link_info *));
93 static void mips_elf_relocate_hi16
94 PARAMS ((bfd *, Elf_Internal_Rela *, Elf_Internal_Rela *, bfd_byte *,
96 static boolean mips_elf_relocate_section
97 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
98 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
99 static boolean mips_elf_add_symbol_hook
100 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
101 const char **, flagword *, asection **, bfd_vma *));
103 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */
108 R_MIPS_16, R_MIPS_32,
109 R_MIPS_REL32, R_MIPS_26,
110 R_MIPS_HI16, R_MIPS_LO16,
111 R_MIPS_GPREL16, R_MIPS_LITERAL,
112 R_MIPS_GOT16, R_MIPS_PC16,
113 R_MIPS_CALL16, R_MIPS_GPREL32,
117 static reloc_howto_type elf_mips_howto_table[] =
120 HOWTO (R_MIPS_NONE, /* type */
122 0, /* size (0 = byte, 1 = short, 2 = long) */
124 false, /* pc_relative */
126 complain_overflow_dont, /* complain_on_overflow */
127 bfd_elf_generic_reloc, /* special_function */
128 "R_MIPS_NONE", /* name */
129 false, /* partial_inplace */
132 false), /* pcrel_offset */
134 /* 16 bit relocation. */
135 HOWTO (R_MIPS_16, /* type */
137 1, /* size (0 = byte, 1 = short, 2 = long) */
139 false, /* pc_relative */
141 complain_overflow_bitfield, /* complain_on_overflow */
142 bfd_elf_generic_reloc, /* special_function */
143 "R_MIPS_16", /* name */
144 true, /* partial_inplace */
145 0xffff, /* src_mask */
146 0xffff, /* dst_mask */
147 false), /* pcrel_offset */
149 /* 32 bit relocation. */
150 HOWTO (R_MIPS_32, /* type */
152 2, /* size (0 = byte, 1 = short, 2 = long) */
154 false, /* pc_relative */
156 complain_overflow_bitfield, /* complain_on_overflow */
157 bfd_elf_generic_reloc, /* special_function */
158 "R_MIPS_32", /* name */
159 true, /* partial_inplace */
160 0xffffffff, /* src_mask */
161 0xffffffff, /* dst_mask */
162 false), /* pcrel_offset */
164 /* 32 bit symbol relative relocation. */
165 HOWTO (R_MIPS_REL32, /* type */
167 2, /* size (0 = byte, 1 = short, 2 = long) */
169 false, /* pc_relative */
171 complain_overflow_bitfield, /* complain_on_overflow */
172 bfd_elf_generic_reloc, /* special_function */
173 "R_MIPS_REL32", /* name */
174 true, /* partial_inplace */
175 0xffffffff, /* src_mask */
176 0xffffffff, /* dst_mask */
177 false), /* pcrel_offset */
179 /* 26 bit branch address. */
180 HOWTO (R_MIPS_26, /* type */
182 2, /* size (0 = byte, 1 = short, 2 = long) */
184 false, /* pc_relative */
186 complain_overflow_dont, /* complain_on_overflow */
187 /* This needs complex overflow
188 detection, because the upper four
189 bits must match the PC. */
190 bfd_elf_generic_reloc, /* special_function */
191 "R_MIPS_26", /* name */
192 true, /* partial_inplace */
193 0x3ffffff, /* src_mask */
194 0x3ffffff, /* dst_mask */
195 false), /* pcrel_offset */
197 /* High 16 bits of symbol value. */
198 HOWTO (R_MIPS_HI16, /* type */
200 2, /* size (0 = byte, 1 = short, 2 = long) */
202 false, /* pc_relative */
204 complain_overflow_dont, /* complain_on_overflow */
205 mips_elf_hi16_reloc, /* special_function */
206 "R_MIPS_HI16", /* name */
207 true, /* partial_inplace */
208 0xffff, /* src_mask */
209 0xffff, /* dst_mask */
210 false), /* pcrel_offset */
212 /* Low 16 bits of symbol value. */
213 HOWTO (R_MIPS_LO16, /* type */
215 2, /* size (0 = byte, 1 = short, 2 = long) */
217 false, /* pc_relative */
219 complain_overflow_dont, /* complain_on_overflow */
220 mips_elf_lo16_reloc, /* special_function */
221 "R_MIPS_LO16", /* name */
222 true, /* partial_inplace */
223 0xffff, /* src_mask */
224 0xffff, /* dst_mask */
225 false), /* pcrel_offset */
227 /* GP relative reference. */
228 HOWTO (R_MIPS_GPREL16, /* type */
230 2, /* size (0 = byte, 1 = short, 2 = long) */
232 false, /* pc_relative */
234 complain_overflow_signed, /* complain_on_overflow */
235 mips_elf_gprel16_reloc, /* special_function */
236 "R_MIPS_GPREL16", /* name */
237 true, /* partial_inplace */
238 0xffff, /* src_mask */
239 0xffff, /* dst_mask */
240 false), /* pcrel_offset */
242 /* Reference to literal section. */
243 HOWTO (R_MIPS_LITERAL, /* type */
245 2, /* size (0 = byte, 1 = short, 2 = long) */
247 false, /* pc_relative */
249 complain_overflow_signed, /* complain_on_overflow */
250 mips_elf_gprel16_reloc, /* special_function */
251 "R_MIPS_LITERAL", /* name */
252 true, /* partial_inplace */
253 0xffff, /* src_mask */
254 0xffff, /* dst_mask */
255 false), /* pcrel_offset */
257 /* Reference to global offset table. */
258 /* FIXME: This is not handled correctly. */
259 HOWTO (R_MIPS_GOT16, /* type */
261 2, /* size (0 = byte, 1 = short, 2 = long) */
263 false, /* pc_relative */
265 complain_overflow_signed, /* complain_on_overflow */
266 mips_elf_got16_reloc, /* special_function */
267 "R_MIPS_GOT16", /* name */
268 false, /* partial_inplace */
270 0xffff, /* dst_mask */
271 false), /* pcrel_offset */
273 /* 16 bit PC relative reference. */
274 HOWTO (R_MIPS_PC16, /* type */
276 2, /* size (0 = byte, 1 = short, 2 = long) */
278 true, /* pc_relative */
280 complain_overflow_signed, /* complain_on_overflow */
281 bfd_elf_generic_reloc, /* special_function */
282 "R_MIPS_PC16", /* name */
283 true, /* partial_inplace */
284 0xffff, /* src_mask */
285 0xffff, /* dst_mask */
286 false), /* pcrel_offset */
288 /* 16 bit call through global offset table. */
289 /* FIXME: This is not handled correctly. */
290 HOWTO (R_MIPS_CALL16, /* type */
292 2, /* size (0 = byte, 1 = short, 2 = long) */
294 false, /* pc_relative */
296 complain_overflow_signed, /* complain_on_overflow */
297 bfd_elf_generic_reloc, /* special_function */
298 "R_MIPS_CALL16", /* name */
299 false, /* partial_inplace */
301 0xffff, /* dst_mask */
302 false), /* pcrel_offset */
304 /* 32 bit GP relative reference. */
305 /* FIXME: This is not handled correctly. */
306 HOWTO (R_MIPS_GPREL32, /* type */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
310 false, /* pc_relative */
312 complain_overflow_bitfield, /* complain_on_overflow */
313 bfd_elf_generic_reloc, /* special_function */
314 "R_MIPS_GPREL32", /* name */
315 true, /* partial_inplace */
316 0xffffffff, /* src_mask */
317 0xffffffff, /* dst_mask */
318 false) /* pcrel_offset */
321 /* Do a R_MIPS_HI16 relocation. This has to be done in combination
322 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to
323 the HI16. Here we just save the information we need; we do the
324 actual relocation when we see the LO16. MIPS ELF requires that the
325 LO16 immediately follow the HI16, so this ought to work. */
327 static bfd_byte *mips_hi16_addr;
328 static bfd_vma mips_hi16_addend;
330 static bfd_reloc_status_type
331 mips_elf_hi16_reloc (abfd,
339 arelent *reloc_entry;
342 asection *input_section;
344 char **error_message;
346 bfd_reloc_status_type ret;
349 /* If we're relocating, and this an external symbol, we don't want
350 to change anything. */
351 if (output_bfd != (bfd *) NULL
352 && (symbol->flags & BSF_SECTION_SYM) == 0
353 && reloc_entry->addend == 0)
355 reloc_entry->address += input_section->output_offset;
359 /* FIXME: The symbol _gp_disp requires special handling, which we do
361 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
365 if (symbol->section == &bfd_und_section
366 && output_bfd == (bfd *) NULL)
367 ret = bfd_reloc_undefined;
369 if (bfd_is_com_section (symbol->section))
372 relocation = symbol->value;
374 relocation += symbol->section->output_section->vma;
375 relocation += symbol->section->output_offset;
376 relocation += reloc_entry->addend;
378 if (reloc_entry->address > input_section->_cooked_size)
379 return bfd_reloc_outofrange;
381 /* Save the information, and let LO16 do the actual relocation. */
382 mips_hi16_addr = (bfd_byte *) data + reloc_entry->address;
383 mips_hi16_addend = relocation;
385 if (output_bfd != (bfd *) NULL)
386 reloc_entry->address += input_section->output_offset;
391 /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit
392 inplace relocation; this function exists in order to do the
393 R_MIPS_HI16 relocation described above. */
395 static bfd_reloc_status_type
396 mips_elf_lo16_reloc (abfd,
404 arelent *reloc_entry;
407 asection *input_section;
409 char **error_message;
411 /* FIXME: The symbol _gp_disp requires special handling, which we do
413 if (output_bfd == (bfd *) NULL
414 && strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0)
417 if (mips_hi16_addr != (bfd_byte *) NULL)
423 /* Do the HI16 relocation. Note that we actually don't need to
424 know anything about the LO16 itself, except where to find the
425 low 16 bits of the addend needed by the LO16. */
426 insn = bfd_get_32 (abfd, mips_hi16_addr);
427 vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address)
429 val = ((insn & 0xffff) << 16) + vallo;
430 val += mips_hi16_addend;
432 /* The low order 16 bits are always treated as a signed value.
433 Therefore, a negative value in the low order bits requires an
434 adjustment in the high order bits. We need to make this
435 adjustment in two ways: once for the bits we took from the
436 data, and once for the bits we are putting back in to the
438 if ((vallo & 0x8000) != 0)
440 if ((val & 0x8000) != 0)
443 insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
444 bfd_put_32 (abfd, insn, mips_hi16_addr);
446 mips_hi16_addr = (bfd_byte *) NULL;
449 /* Now do the LO16 reloc in the usual way. */
450 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
451 input_section, output_bfd, error_message);
454 /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset
455 table used for PIC code. If the symbol is an external symbol, the
456 instruction is modified to contain the offset of the appropriate
457 entry in the global offset table. If the symbol is a section
458 symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit
459 addends are combined to form the real addend against the section
460 symbol; the GOT16 is modified to contain the offset of an entry in
461 the global offset table, and the LO16 is modified to offset it
462 appropriately. Thus an offset larger than 16 bits requires a
463 modified value in the global offset table.
465 This implementation suffices for the assembler, but the linker does
466 not yet know how to create global offset tables. */
468 static bfd_reloc_status_type
469 mips_elf_got16_reloc (abfd,
477 arelent *reloc_entry;
480 asection *input_section;
482 char **error_message;
484 /* If we're relocating, and this an external symbol, we don't want
485 to change anything. */
486 if (output_bfd != (bfd *) NULL
487 && (symbol->flags & BSF_SECTION_SYM) == 0
488 && reloc_entry->addend == 0)
490 reloc_entry->address += input_section->output_offset;
494 /* If we're relocating, and this is a local symbol, we can handle it
496 if (output_bfd != (bfd *) NULL
497 && (symbol->flags & BSF_SECTION_SYM) != 0)
498 return mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
499 input_section, output_bfd, error_message);
504 /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must
505 become the offset from the gp register. This function also handles
506 R_MIPS_LITERAL relocations, although those can be handled more
507 cleverly because the entries in the .lit8 and .lit4 sections can be
510 static bfd_reloc_status_type
511 mips_elf_gprel16_reloc (abfd,
519 arelent *reloc_entry;
522 asection *input_section;
524 char **error_message;
526 boolean relocateable;
531 /* If we're relocating, and this is an external symbol with no
532 addend, we don't want to change anything. We will only have an
533 addend if this is a newly created reloc, not read from an ELF
535 if (output_bfd != (bfd *) NULL
536 && (symbol->flags & BSF_SECTION_SYM) == 0
537 && reloc_entry->addend == 0)
539 reloc_entry->address += input_section->output_offset;
543 if (output_bfd != (bfd *) NULL)
547 relocateable = false;
548 output_bfd = symbol->section->output_section->owner;
551 if (symbol->section == &bfd_und_section
552 && relocateable == false)
553 return bfd_reloc_undefined;
555 /* We have to figure out the gp value, so that we can adjust the
556 symbol value correctly. We look up the symbol _gp in the output
557 BFD. If we can't find it, we're stuck. We cache it in the ELF
558 target data. We don't need to adjust the symbol value for an
559 external symbol if we are producing relocateable output. */
560 if (elf_gp (output_bfd) == 0
561 && (relocateable == false
562 || (symbol->flags & BSF_SECTION_SYM) != 0))
564 if (relocateable != false)
566 /* Make up a value. */
567 elf_gp (output_bfd) =
568 symbol->section->output_section->vma + 0x4000;
576 count = bfd_get_symcount (output_bfd);
577 sym = bfd_get_outsymbols (output_bfd);
579 if (sym == (asymbol **) NULL)
583 for (i = 0; i < count; i++, sym++)
585 register CONST char *name;
587 name = bfd_asymbol_name (*sym);
588 if (*name == '_' && strcmp (name, "_gp") == 0)
590 elf_gp (output_bfd) = bfd_asymbol_value (*sym);
598 /* Only get the error once. */
599 elf_gp (output_bfd) = 4;
601 (char *) "GP relative relocation when _gp not defined";
602 return bfd_reloc_dangerous;
607 if (bfd_is_com_section (symbol->section))
610 relocation = symbol->value;
612 relocation += symbol->section->output_section->vma;
613 relocation += symbol->section->output_offset;
615 if (reloc_entry->address > input_section->_cooked_size)
616 return bfd_reloc_outofrange;
618 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
620 /* Set val to the offset into the section or symbol. */
621 val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff;
625 /* Adjust val for the final section location and GP value. If we
626 are producing relocateable output, we don't want to do this for
627 an external symbol. */
628 if (relocateable == false
629 || (symbol->flags & BSF_SECTION_SYM) != 0)
630 val += relocation - elf_gp (output_bfd);
632 insn = (insn &~ 0xffff) | (val & 0xffff);
633 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
635 if (relocateable != false)
636 reloc_entry->address += input_section->output_offset;
638 /* Make sure it fit in 16 bits. */
639 if (val >= 0x8000 && val < 0xffff8000)
640 return bfd_reloc_overflow;
645 /* A mapping from BFD reloc types to MIPS ELF reloc types. */
647 struct elf_reloc_map {
648 bfd_reloc_code_real_type bfd_reloc_val;
649 enum reloc_type elf_reloc_val;
652 static CONST struct elf_reloc_map mips_reloc_map[] =
654 { BFD_RELOC_NONE, R_MIPS_NONE, },
655 { BFD_RELOC_16, R_MIPS_16 },
656 { BFD_RELOC_32, R_MIPS_32 },
657 { BFD_RELOC_CTOR, R_MIPS_32 },
658 { BFD_RELOC_32_PCREL, R_MIPS_REL32 },
659 { BFD_RELOC_MIPS_JMP, R_MIPS_26 },
660 { BFD_RELOC_HI16_S, R_MIPS_HI16 },
661 { BFD_RELOC_LO16, R_MIPS_LO16 },
662 { BFD_RELOC_MIPS_GPREL, R_MIPS_GPREL16 },
663 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL },
664 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 },
665 { BFD_RELOC_16_PCREL, R_MIPS_PC16 },
666 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 },
667 { BFD_RELOC_MIPS_GPREL32, R_MIPS_GPREL32 }
670 /* Given a BFD reloc type, return a howto structure. */
672 static const struct reloc_howto_struct *
673 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
675 bfd_reloc_code_real_type code;
679 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); i++)
681 if (mips_reloc_map[i].bfd_reloc_val == code)
682 return &elf_mips_howto_table[(int) mips_reloc_map[i].elf_reloc_val];
687 /* Given a MIPS reloc type, fill in an arelent structure. */
690 mips_info_to_howto_rel (abfd, cache_ptr, dst)
693 Elf32_Internal_Rel *dst;
697 r_type = ELF32_R_TYPE (dst->r_info);
698 BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
699 cache_ptr->howto = &elf_mips_howto_table[r_type];
701 /* The addend for a GPREL16 or LITERAL relocation comes from the GP
702 value for the object file. We get the addend now, rather than
703 when we do the relocation, because the symbol manipulations done
704 by the linker may cause us to lose track of the input BFD. */
705 if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0
706 && (r_type == (unsigned int) R_MIPS_GPREL16
707 || r_type == (unsigned int) R_MIPS_LITERAL))
708 cache_ptr->addend = elf_gp (abfd);
711 /* A .reginfo section holds a single Elf32_RegInfo structure. These
712 routines swap this structure in and out. They are used outside of
713 BFD, so they are globally visible. */
716 bfd_mips_elf32_swap_reginfo_in (abfd, ex, in)
718 const Elf32_External_RegInfo *ex;
721 in->ri_gprmask = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gprmask);
722 in->ri_cprmask[0] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[0]);
723 in->ri_cprmask[1] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[1]);
724 in->ri_cprmask[2] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[2]);
725 in->ri_cprmask[3] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[3]);
726 in->ri_gp_value = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gp_value);
730 bfd_mips_elf32_swap_reginfo_out (abfd, in, ex)
732 const Elf32_RegInfo *in;
733 Elf32_External_RegInfo *ex;
735 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gprmask,
736 (bfd_byte *) ex->ri_gprmask);
737 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[0],
738 (bfd_byte *) ex->ri_cprmask[0]);
739 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[1],
740 (bfd_byte *) ex->ri_cprmask[1]);
741 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[2],
742 (bfd_byte *) ex->ri_cprmask[2]);
743 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[3],
744 (bfd_byte *) ex->ri_cprmask[3]);
745 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gp_value,
746 (bfd_byte *) ex->ri_gp_value);
749 /* Swap an entry in a .gptab section. Note that these routines rely
750 on the equivalence of the two elements of the union. */
753 bfd_mips_elf32_swap_gptab_in (abfd, ex, in)
755 const Elf32_External_gptab *ex;
758 in->gt_entry.gt_g_value = bfd_h_get_32 (abfd, ex->gt_entry.gt_g_value);
759 in->gt_entry.gt_bytes = bfd_h_get_32 (abfd, ex->gt_entry.gt_bytes);
763 bfd_mips_elf32_swap_gptab_out (abfd, in, ex)
765 const Elf32_gptab *in;
766 Elf32_External_gptab *ex;
768 bfd_h_put_32 (abfd, (bfd_vma) in->gt_entry.gt_g_value,
769 ex->gt_entry.gt_g_value);
770 bfd_h_put_32 (abfd, (bfd_vma) in->gt_entry.gt_bytes,
771 ex->gt_entry.gt_bytes);
774 /* Determine whether a symbol is global for the purposes of splitting
775 the symbol table into global symbols and local symbols. At least
776 on Irix 5, this split must be between section symbols and all other
777 symbols. On most ELF targets the split is between static symbols
778 and externally visible symbols. */
782 mips_elf_sym_is_global (abfd, sym)
786 return (sym->flags & BSF_SECTION_SYM) == 0 ? true : false;
789 /* Set the right machine number for a MIPS ELF file. */
792 mips_elf_object_p (abfd)
795 switch (elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH)
799 /* Just use the default, which was set in elfcode.h. */
803 (void) bfd_default_set_arch_mach (abfd, bfd_arch_mips, 6000);
807 (void) bfd_default_set_arch_mach (abfd, bfd_arch_mips, 4000);
811 /* Irix 5 is broken. Object file symbol tables are not always
812 sorted correctly such that local symbols precede global symbols,
813 and the sh_info field in the symbol table is not always right.
814 We try to quickly check whether the symbol table is broken for
815 this BFD, and, if it is, we set elf_bad_symtab in tdata. */
816 if (elf_onesymtab (abfd) != 0)
818 Elf_Internal_Shdr *symtab_hdr;
819 Elf32_External_Sym esym;
821 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
823 (symtab_hdr->sh_offset
824 + symtab_hdr->sh_size
825 - sizeof (Elf32_External_Sym)),
827 || (bfd_read ((PTR) &esym, 1, sizeof (Elf32_External_Sym), abfd)
828 != sizeof (Elf32_External_Sym)))
830 if (ELF_ST_BIND (bfd_h_get_8 (abfd, (bfd_byte *) esym.st_info))
832 elf_bad_symtab (abfd) = true;
838 /* The final processing done just before writing out a MIPS ELF object
839 file. This gets the MIPS architecture right based on the machine
843 mips_elf_final_write_processing (abfd)
848 Elf_Internal_Shdr **hdrpp;
850 switch (bfd_get_mach (abfd))
868 elf_elfheader (abfd)->e_flags &=~ EF_MIPS_ARCH;
869 elf_elfheader (abfd)->e_flags |= val;
871 /* Set the sh_info field for .gptab sections. */
872 for (i = 1, hdrpp = elf_elfsections (abfd) + 1;
873 i < elf_elfheader (abfd)->e_shnum;
876 if ((*hdrpp)->sh_type == SHT_MIPS_GPTAB)
881 BFD_ASSERT ((*hdrpp)->rawdata != NULL);
882 name = ((asection *) (*hdrpp)->rawdata)->name;
883 BFD_ASSERT (name != NULL
884 && strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0);
885 sec = bfd_get_section_by_name (abfd, name + sizeof ".gptab" - 1);
886 BFD_ASSERT (sec != NULL);
887 (*hdrpp)->sh_info = elf_section_data (sec)->this_idx;
892 /* Handle a MIPS specific section when reading an object file. This
893 is called when elfcode.h finds a section with an unknown type.
894 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
898 mips_elf_section_from_shdr (abfd, hdr, name)
900 Elf32_Internal_Shdr *hdr;
905 /* There ought to be a place to keep ELF backend specific flags, but
906 at the moment there isn't one. We just keep track of the
907 sections by their name, instead. Fortunately, the ABI gives
908 suggested names for all the MIPS specific sections, so we will
909 probably get away with this. */
910 switch (hdr->sh_type)
912 case SHT_MIPS_LIBLIST:
913 if (strcmp (name, ".liblist") != 0)
916 case SHT_MIPS_CONFLICT:
917 if (strcmp (name, ".conflict") != 0)
921 if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) != 0)
925 if (strcmp (name, ".ucode") != 0)
929 if (strcmp (name, ".mdebug") != 0)
932 case SHT_MIPS_REGINFO:
933 if (strcmp (name, ".reginfo") != 0
934 || hdr->sh_size != sizeof (Elf32_External_RegInfo))
937 case SHT_MIPS_OPTIONS:
938 if (strcmp (name, ".options") != 0)
945 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
947 newsect = (asection *) hdr->rawdata;
949 if (hdr->sh_type == SHT_MIPS_DEBUG)
951 if (! bfd_set_section_flags (abfd, newsect,
952 (bfd_get_section_flags (abfd, newsect)
957 /* FIXME: We should record sh_info for a .gptab section. */
959 /* For a .reginfo section, set the gp value in the tdata information
960 from the contents of this section. We need the gp value while
961 processing relocs, so we just get it now. */
962 if (hdr->sh_type == SHT_MIPS_REGINFO)
964 Elf32_External_RegInfo ext;
967 if (! bfd_get_section_contents (abfd, newsect, (PTR) &ext,
968 (file_ptr) 0, sizeof ext))
970 bfd_mips_elf32_swap_reginfo_in (abfd, &ext, &s);
971 elf_gp (abfd) = s.ri_gp_value;
977 /* Set the correct type for a MIPS ELF section. We do this by the
978 section name, which is a hack, but ought to work. */
981 mips_elf_fake_sections (abfd, hdr, sec)
983 Elf32_Internal_Shdr *hdr;
986 register const char *name;
988 name = bfd_get_section_name (abfd, sec);
990 if (strcmp (name, ".liblist") == 0)
992 hdr->sh_type = SHT_MIPS_LIBLIST;
993 hdr->sh_info = sec->_raw_size / sizeof (Elf32_Lib);
994 /* FIXME: Set the sh_link field. */
996 else if (strcmp (name, ".conflict") == 0)
997 hdr->sh_type = SHT_MIPS_CONFLICT;
998 else if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0)
1000 hdr->sh_type = SHT_MIPS_GPTAB;
1001 hdr->sh_entsize = sizeof (Elf32_External_gptab);
1002 /* The sh_info field is set in mips_elf_final_write_processing. */
1004 else if (strcmp (name, ".ucode") == 0)
1005 hdr->sh_type = SHT_MIPS_UCODE;
1006 else if (strcmp (name, ".mdebug") == 0)
1008 hdr->sh_type = SHT_MIPS_DEBUG;
1009 hdr->sh_entsize = 1;
1011 else if (strcmp (name, ".reginfo") == 0)
1013 hdr->sh_type = SHT_MIPS_REGINFO;
1014 hdr->sh_entsize = 1;
1016 /* Force the section size to the correct value, even if the
1017 linker thinks it is larger. The link routine below will only
1018 write out this much data for .reginfo. */
1019 hdr->sh_size = sec->_raw_size = sizeof (Elf32_External_RegInfo);
1021 else if (strcmp (name, ".options") == 0)
1023 hdr->sh_type = SHT_MIPS_OPTIONS;
1024 hdr->sh_entsize = 1;
1030 /* Given a BFD section, try to locate the corresponding ELF section
1034 mips_elf_section_from_bfd_section (abfd, hdr, sec, retval)
1036 Elf32_Internal_Shdr *hdr;
1040 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0)
1042 *retval = SHN_MIPS_SCOMMON;
1045 if ((asection *) hdr->rawdata == sec)
1050 /* Work over a section just before writing it out. We update the GP
1051 value in the .reginfo section based on the value we are using.
1052 FIXME: We recognize sections that need the SHF_MIPS_GPREL flag by
1053 name; there has to be a better way. */
1056 mips_elf_section_processing (abfd, hdr)
1058 Elf32_Internal_Shdr *hdr;
1060 if (hdr->sh_type == SHT_MIPS_REGINFO)
1064 BFD_ASSERT (hdr->sh_size == sizeof (Elf32_External_RegInfo));
1065 BFD_ASSERT (hdr->contents == NULL);
1068 hdr->sh_offset + sizeof (Elf32_External_RegInfo) - 4,
1071 bfd_h_put_32 (abfd, (bfd_vma) elf_gp (abfd), buf);
1072 if (bfd_write (buf, (bfd_size_type) 1, (bfd_size_type) 4, abfd) != 4)
1076 if (hdr->rawdata != NULL)
1078 const char *name = ((asection *) hdr->rawdata)->name;
1080 if (strcmp (name, ".sdata") == 0)
1082 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
1083 hdr->sh_type = SHT_PROGBITS;
1085 else if (strcmp (name, ".sbss") == 0)
1087 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
1088 hdr->sh_type = SHT_NOBITS;
1090 else if (strcmp (name, ".lit8") == 0
1091 || strcmp (name, ".lit4") == 0)
1093 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL;
1094 hdr->sh_type = SHT_PROGBITS;
1101 /* MIPS ELF uses two common sections. One is the usual one, and the
1102 other is for small objects. All the small objects are kept
1103 together, and then referenced via the gp pointer, which yields
1104 faster assembler code. This is what we use for the small common
1105 section. This approach is copied from ecoff.c. */
1106 static asection mips_elf_scom_section;
1107 static asymbol mips_elf_scom_symbol;
1108 static asymbol *mips_elf_scom_symbol_ptr;
1110 /* MIPS ELF also uses an acommon section, which represents an
1111 allocated common symbol which may be overridden by a
1112 definition in a shared library. */
1113 static asection mips_elf_acom_section;
1114 static asymbol mips_elf_acom_symbol;
1115 static asymbol *mips_elf_acom_symbol_ptr;
1117 /* Handle the special MIPS section numbers that a symbol may use. */
1120 mips_elf_symbol_processing (abfd, asym)
1124 elf_symbol_type *elfsym;
1126 elfsym = (elf_symbol_type *) asym;
1127 switch (elfsym->internal_elf_sym.st_shndx)
1129 case SHN_MIPS_ACOMMON:
1130 /* This section is used in a dynamically linked executable file.
1131 It is an allocated common section. The dynamic linker can
1132 either resolve these symbols to something in a shared
1133 library, or it can just leave them here. For our purposes,
1134 we can consider these symbols to be in a new section. */
1135 if (mips_elf_acom_section.name == NULL)
1137 /* Initialize the acommon section. */
1138 mips_elf_acom_section.name = ".acommon";
1139 mips_elf_acom_section.flags = SEC_NO_FLAGS;
1140 mips_elf_acom_section.output_section = &mips_elf_acom_section;
1141 mips_elf_acom_section.symbol = &mips_elf_acom_symbol;
1142 mips_elf_acom_section.symbol_ptr_ptr = &mips_elf_acom_symbol_ptr;
1143 mips_elf_acom_symbol.name = ".acommon";
1144 mips_elf_acom_symbol.flags = BSF_SECTION_SYM;
1145 mips_elf_acom_symbol.section = &mips_elf_acom_section;
1146 mips_elf_acom_symbol_ptr = &mips_elf_acom_symbol;
1148 asym->section = &mips_elf_acom_section;
1152 /* Common symbols less than the GP size are automatically
1153 treated as SHN_MIPS_SCOMMON symbols. */
1154 if (asym->value > elf_gp_size (abfd))
1157 case SHN_MIPS_SCOMMON:
1158 if (mips_elf_scom_section.name == NULL)
1160 /* Initialize the small common section. */
1161 mips_elf_scom_section.name = ".scommon";
1162 mips_elf_scom_section.flags = SEC_IS_COMMON;
1163 mips_elf_scom_section.output_section = &mips_elf_scom_section;
1164 mips_elf_scom_section.symbol = &mips_elf_scom_symbol;
1165 mips_elf_scom_section.symbol_ptr_ptr = &mips_elf_scom_symbol_ptr;
1166 mips_elf_scom_symbol.name = ".scommon";
1167 mips_elf_scom_symbol.flags = BSF_SECTION_SYM;
1168 mips_elf_scom_symbol.section = &mips_elf_scom_section;
1169 mips_elf_scom_symbol_ptr = &mips_elf_scom_symbol;
1171 asym->section = &mips_elf_scom_section;
1172 asym->value = elfsym->internal_elf_sym.st_size;
1175 case SHN_MIPS_SUNDEFINED:
1176 asym->section = &bfd_und_section;
1181 /* Read ECOFF debugging information from a .mdebug section into a
1182 ecoff_debug_info structure. */
1185 mips_elf_read_ecoff_info (abfd, section, debug)
1188 struct ecoff_debug_info *debug;
1191 const struct ecoff_debug_swap *swap;
1192 char *ext_hdr = NULL;
1194 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1196 ext_hdr = (char *) malloc (swap->external_hdr_size);
1197 if (ext_hdr == NULL && swap->external_hdr_size != 0)
1199 bfd_set_error (bfd_error_no_memory);
1203 if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0,
1204 swap->external_hdr_size)
1208 symhdr = &debug->symbolic_header;
1209 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr);
1211 /* The symbolic header contains absolute file offsets and sizes to
1213 #define READ(ptr, offset, count, size, type) \
1214 if (symhdr->count == 0) \
1215 debug->ptr = NULL; \
1218 debug->ptr = (type) malloc (size * symhdr->count); \
1219 if (debug->ptr == NULL) \
1221 bfd_set_error (bfd_error_no_memory); \
1222 goto error_return; \
1224 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \
1225 || (bfd_read (debug->ptr, size, symhdr->count, \
1226 abfd) != size * symhdr->count)) \
1227 goto error_return; \
1230 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *);
1231 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR);
1232 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR);
1233 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR);
1234 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR);
1235 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext),
1237 READ (ss, cbSsOffset, issMax, sizeof (char), char *);
1238 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *);
1239 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR);
1240 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR);
1241 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR);
1245 debug->adjust = NULL;
1250 if (ext_hdr != NULL)
1252 if (debug->line != NULL)
1254 if (debug->external_dnr != NULL)
1255 free (debug->external_dnr);
1256 if (debug->external_pdr != NULL)
1257 free (debug->external_pdr);
1258 if (debug->external_sym != NULL)
1259 free (debug->external_sym);
1260 if (debug->external_opt != NULL)
1261 free (debug->external_opt);
1262 if (debug->external_aux != NULL)
1263 free (debug->external_aux);
1264 if (debug->ss != NULL)
1266 if (debug->ssext != NULL)
1267 free (debug->ssext);
1268 if (debug->external_fdr != NULL)
1269 free (debug->external_fdr);
1270 if (debug->external_rfd != NULL)
1271 free (debug->external_rfd);
1272 if (debug->external_ext != NULL)
1273 free (debug->external_ext);
1277 /* The MIPS ELF linker needs additional information for each symbol in
1278 the global hash table. */
1280 struct mips_elf_link_hash_entry
1282 struct elf_link_hash_entry root;
1284 /* External symbol information. */
1288 /* MIPS ELF linker hash table. */
1290 struct mips_elf_link_hash_table
1292 struct elf_link_hash_table root;
1295 /* Look up an entry in a MIPS ELF linker hash table. */
1297 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
1298 ((struct mips_elf_link_hash_entry *) \
1299 elf_link_hash_lookup (&(table)->root, (string), (create), \
1302 /* Traverse a MIPS ELF linker hash table. */
1304 #define mips_elf_link_hash_traverse(table, func, info) \
1305 (elf_link_hash_traverse \
1307 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
1310 /* Get the MIPS ELF linker hash table from a link_info structure. */
1312 #define mips_elf_hash_table(p) \
1313 ((struct mips_elf_link_hash_table *) ((p)->hash))
1315 static boolean mips_elf_output_extsym
1316 PARAMS ((struct mips_elf_link_hash_entry *, PTR));
1318 /* Create an entry in a MIPS ELF linker hash table. */
1320 static struct bfd_hash_entry *
1321 mips_elf_link_hash_newfunc (entry, table, string)
1322 struct bfd_hash_entry *entry;
1323 struct bfd_hash_table *table;
1326 struct mips_elf_link_hash_entry *ret =
1327 (struct mips_elf_link_hash_entry *) entry;
1329 /* Allocate the structure if it has not already been allocated by a
1331 if (ret == (struct mips_elf_link_hash_entry *) NULL)
1332 ret = ((struct mips_elf_link_hash_entry *)
1333 bfd_hash_allocate (table,
1334 sizeof (struct mips_elf_link_hash_entry)));
1335 if (ret == (struct mips_elf_link_hash_entry *) NULL)
1337 bfd_set_error (bfd_error_no_memory);
1338 return (struct bfd_hash_entry *) ret;
1341 /* Call the allocation method of the superclass. */
1342 ret = ((struct mips_elf_link_hash_entry *)
1343 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1345 if (ret != (struct mips_elf_link_hash_entry *) NULL)
1347 /* Set local fields. */
1348 memset (&ret->esym, 0, sizeof (EXTR));
1349 /* We use -2 as a marker to indicate that the information has
1350 not been set. -1 means there is no associated ifd. */
1354 return (struct bfd_hash_entry *) ret;
1357 /* Create a MIPS ELF linker hash table. */
1359 static struct bfd_link_hash_table *
1360 mips_elf_link_hash_table_create (abfd)
1363 struct mips_elf_link_hash_table *ret;
1365 ret = ((struct mips_elf_link_hash_table *)
1366 bfd_alloc (abfd, sizeof (struct mips_elf_link_hash_table)));
1367 if (ret == (struct mips_elf_link_hash_table *) NULL)
1369 bfd_set_error (bfd_error_no_memory);
1373 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
1374 mips_elf_link_hash_newfunc))
1376 bfd_release (abfd, ret);
1380 return &ret->root.root;
1383 /* Hook called by the linker routine which adds symbols from an object
1384 file. We must handle the special MIPS section numbers here. */
1388 mips_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
1390 struct bfd_link_info *info;
1391 const Elf_Internal_Sym *sym;
1397 switch (sym->st_shndx)
1400 /* Common symbols less than the GP size are automatically
1401 treated as SHN_MIPS_SCOMMON symbols. */
1402 if (sym->st_size > elf_gp_size (abfd))
1405 case SHN_MIPS_SCOMMON:
1406 *secp = bfd_make_section_old_way (abfd, ".scommon");
1407 (*secp)->flags |= SEC_IS_COMMON;
1408 *valp = sym->st_size;
1411 case SHN_MIPS_SUNDEFINED:
1412 *secp = &bfd_und_section;
1419 /* Structure used to pass information to mips_elf_output_extsym. */
1424 struct bfd_link_info *info;
1425 struct ecoff_debug_info *debug;
1426 const struct ecoff_debug_swap *swap;
1430 /* This routine is used to write out ECOFF debugging external symbol
1431 information. It is called via mips_elf_link_hash_traverse. The
1432 ECOFF external symbol information must match the ELF external
1433 symbol information. Unfortunately, at this point we don't know
1434 whether a symbol is required by reloc information, so the two
1435 tables may wind up being different. We must sort out the external
1436 symbol information before we can set the final size of the .mdebug
1437 section, and we must set the size of the .mdebug section before we
1438 can relocate any sections, and we can't know which symbols are
1439 required by relocation until we relocate the sections.
1440 Fortunately, it is relatively unlikely that any symbol will be
1441 stripped but required by a reloc. In particular, it can not happen
1442 when generating a final executable. */
1445 mips_elf_output_extsym (h, data)
1446 struct mips_elf_link_hash_entry *h;
1449 struct extsym_info *einfo = (struct extsym_info *) data;
1452 if (h->root.indx == -2)
1454 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1455 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
1456 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
1457 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
1459 else if (einfo->info->strip == strip_all
1460 || (einfo->info->strip == strip_some
1461 && bfd_hash_lookup (einfo->info->keep_hash,
1462 h->root.root.root.string,
1463 false, false) == NULL))
1471 if (h->esym.ifd == -2)
1474 h->esym.cobol_main = 0;
1475 h->esym.weakext = 0;
1476 h->esym.reserved = 0;
1477 h->esym.ifd = ifdNil;
1478 h->esym.asym.value = 0;
1479 h->esym.asym.st = stGlobal;
1481 if (h->root.root.type != bfd_link_hash_defined)
1482 h->esym.asym.sc = scAbs;
1485 asection *output_section;
1488 output_section = h->root.root.u.def.section->output_section;
1489 name = bfd_section_name (output_section->owner, output_section);
1491 if (strcmp (name, ".text") == 0)
1492 h->esym.asym.sc = scText;
1493 else if (strcmp (name, ".data") == 0)
1494 h->esym.asym.sc = scData;
1495 else if (strcmp (name, ".sdata") == 0)
1496 h->esym.asym.sc = scSData;
1497 else if (strcmp (name, ".rodata") == 0
1498 || strcmp (name, ".rdata") == 0)
1499 h->esym.asym.sc = scRData;
1500 else if (strcmp (name, ".bss") == 0)
1501 h->esym.asym.sc = scBss;
1502 else if (strcmp (name, ".sbss") == 0)
1503 h->esym.asym.sc = scSBss;
1504 else if (strcmp (name, ".init") == 0)
1505 h->esym.asym.sc = scInit;
1506 else if (strcmp (name, ".fini") == 0)
1507 h->esym.asym.sc = scFini;
1509 h->esym.asym.sc = scAbs;
1512 h->esym.asym.reserved = 0;
1513 h->esym.asym.index = indexNil;
1517 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap,
1518 h->root.root.root.string,
1521 einfo->failed = true;
1528 /* A comparison routine used to sort .gptab entries. */
1531 gptab_compare (p1, p2)
1535 const Elf32_gptab *a1 = (const Elf32_gptab *) p1;
1536 const Elf32_gptab *a2 = (const Elf32_gptab *) p2;
1538 return a1->gt_entry.gt_g_value - a2->gt_entry.gt_g_value;
1541 /* We need to use a special link routine to handle the .reginfo and
1542 the .mdebug sections. We need to merge all instances of these
1543 sections together, not write them all out sequentially. */
1546 mips_elf_final_link (abfd, info)
1548 struct bfd_link_info *info;
1552 struct bfd_link_order *p;
1553 asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec;
1554 Elf32_RegInfo reginfo;
1555 struct ecoff_debug_info debug;
1556 const struct ecoff_debug_swap *swap
1557 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1558 HDRR *symhdr = &debug.symbolic_header;
1559 PTR mdebug_handle = NULL;
1561 /* Drop the .options section, since it has special semantics which I
1562 haven't bothered to figure out. */
1563 for (secpp = &abfd->sections; *secpp != NULL; secpp = &(*secpp)->next)
1565 if (strcmp ((*secpp)->name, ".options") == 0)
1567 for (p = (*secpp)->link_order_head; p != NULL; p = p->next)
1568 if (p->type == bfd_indirect_link_order)
1569 p->u.indirect.section->flags &=~ SEC_HAS_CONTENTS;
1570 (*secpp)->link_order_head = NULL;
1571 *secpp = (*secpp)->next;
1572 --abfd->section_count;
1577 /* Go through the sections and collect the .reginfo and .mdebug
1581 gptab_data_sec = NULL;
1582 gptab_bss_sec = NULL;
1583 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
1585 if (strcmp (o->name, ".reginfo") == 0)
1587 memset (®info, 0, sizeof reginfo);
1589 /* We have found the .reginfo section in the output file.
1590 Look through all the link_orders comprising it and merge
1591 the information together. */
1592 for (p = o->link_order_head;
1593 p != (struct bfd_link_order *) NULL;
1596 asection *input_section;
1598 Elf32_External_RegInfo ext;
1601 if (p->type != bfd_indirect_link_order)
1603 if (p->type == bfd_fill_link_order)
1608 input_section = p->u.indirect.section;
1609 input_bfd = input_section->owner;
1610 BFD_ASSERT (input_section->_raw_size
1611 == sizeof (Elf32_External_RegInfo));
1612 if (! bfd_get_section_contents (input_bfd, input_section,
1618 bfd_mips_elf32_swap_reginfo_in (input_bfd, &ext, &sub);
1620 reginfo.ri_gprmask |= sub.ri_gprmask;
1621 reginfo.ri_cprmask[0] |= sub.ri_cprmask[0];
1622 reginfo.ri_cprmask[1] |= sub.ri_cprmask[1];
1623 reginfo.ri_cprmask[2] |= sub.ri_cprmask[2];
1624 reginfo.ri_cprmask[3] |= sub.ri_cprmask[3];
1626 /* ri_gp_value is set by the function
1627 mips_elf_section_processing when the section is
1628 finally written out. */
1630 /* Hack: reset the SEC_HAS_CONTENTS flag so that
1631 elf_link_input_bfd ignores this section. */
1632 input_section->flags &=~ SEC_HAS_CONTENTS;
1635 /* Force the section size to the value we want. */
1636 o->_raw_size = sizeof (Elf32_External_RegInfo);
1638 /* Skip this section later on (I don't think this currently
1639 matters, but someday it might). */
1640 o->link_order_head = (struct bfd_link_order *) NULL;
1645 if (strcmp (o->name, ".mdebug") == 0)
1647 struct extsym_info einfo;
1649 /* We have found the .mdebug section in the output file.
1650 Look through all the link_orders comprising it and merge
1651 the information together. */
1652 symhdr->magic = swap->sym_magic;
1653 /* FIXME: What should the version stamp be? */
1655 symhdr->ilineMax = 0;
1659 symhdr->isymMax = 0;
1660 symhdr->ioptMax = 0;
1661 symhdr->iauxMax = 0;
1663 symhdr->issExtMax = 0;
1666 symhdr->iextMax = 0;
1668 /* We accumulate the debugging information itself in the
1669 debug_info structure. */
1671 debug.external_dnr = NULL;
1672 debug.external_pdr = NULL;
1673 debug.external_sym = NULL;
1674 debug.external_opt = NULL;
1675 debug.external_aux = NULL;
1677 debug.ssext = debug.ssext_end = NULL;
1678 debug.external_fdr = NULL;
1679 debug.external_rfd = NULL;
1680 debug.external_ext = debug.external_ext_end = NULL;
1682 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info);
1683 if (mdebug_handle == (PTR) NULL)
1686 for (p = o->link_order_head;
1687 p != (struct bfd_link_order *) NULL;
1690 asection *input_section;
1692 const struct ecoff_debug_swap *input_swap;
1693 struct ecoff_debug_info input_debug;
1697 if (p->type != bfd_indirect_link_order)
1699 if (p->type == bfd_fill_link_order)
1704 input_section = p->u.indirect.section;
1705 input_bfd = input_section->owner;
1707 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour
1708 || (get_elf_backend_data (input_bfd)
1709 ->elf_backend_ecoff_debug_swap) == NULL)
1711 /* I don't know what a non MIPS ELF bfd would be
1712 doing with a .mdebug section, but I don't really
1713 want to deal with it. */
1717 input_swap = (get_elf_backend_data (input_bfd)
1718 ->elf_backend_ecoff_debug_swap);
1720 BFD_ASSERT (p->size == input_section->_raw_size);
1722 /* The ECOFF linking code expects that we have already
1723 read in the debugging information and set up an
1724 ecoff_debug_info structure, so we do that now. */
1725 if (! mips_elf_read_ecoff_info (input_bfd, input_section,
1729 if (! (bfd_ecoff_debug_accumulate
1730 (mdebug_handle, abfd, &debug, swap, input_bfd,
1731 &input_debug, input_swap, info)))
1734 /* Loop through the external symbols. For each one with
1735 interesting information, try to find the symbol in
1736 the linker global hash table and save the information
1737 for the output external symbols. */
1738 eraw_src = input_debug.external_ext;
1739 eraw_end = (eraw_src
1740 + (input_debug.symbolic_header.iextMax
1741 * input_swap->external_ext_size));
1743 eraw_src < eraw_end;
1744 eraw_src += input_swap->external_ext_size)
1748 struct mips_elf_link_hash_entry *h;
1750 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext);
1751 if (ext.asym.sc == scNil
1752 || ext.asym.sc == scUndefined
1753 || ext.asym.sc == scSUndefined)
1756 name = input_debug.ssext + ext.asym.iss;
1757 h = mips_elf_link_hash_lookup (mips_elf_hash_table (info),
1758 name, false, false, true);
1759 if (h == NULL || h->esym.ifd != -2)
1765 < input_debug.symbolic_header.ifdMax);
1766 ext.ifd = input_debug.ifdmap[ext.ifd];
1772 /* Free up the information we just read. */
1773 free (input_debug.line);
1774 free (input_debug.external_dnr);
1775 free (input_debug.external_pdr);
1776 free (input_debug.external_sym);
1777 free (input_debug.external_opt);
1778 free (input_debug.external_aux);
1779 free (input_debug.ss);
1780 free (input_debug.ssext);
1781 free (input_debug.external_fdr);
1782 free (input_debug.external_rfd);
1783 free (input_debug.external_ext);
1785 /* Hack: reset the SEC_HAS_CONTENTS flag so that
1786 elf_link_input_bfd ignores this section. */
1787 input_section->flags &=~ SEC_HAS_CONTENTS;
1790 /* Build the external symbol information. */
1793 einfo.debug = &debug;
1795 einfo.failed = false;
1796 mips_elf_link_hash_traverse (mips_elf_hash_table (info),
1797 mips_elf_output_extsym,
1802 /* Set the size of the .mdebug section. */
1803 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap);
1805 /* Skip this section later on (I don't think this currently
1806 matters, but someday it might). */
1807 o->link_order_head = (struct bfd_link_order *) NULL;
1812 if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0)
1814 const char *subname;
1817 Elf32_External_gptab *ext_tab;
1820 /* The .gptab.sdata and .gptab.sbss sections hold
1821 information describing how the small data area would
1822 change depending upon the -G switch. These sections
1823 not used in executables files. */
1824 if (! info->relocateable)
1828 for (p = o->link_order_head;
1829 p != (struct bfd_link_order *) NULL;
1832 asection *input_section;
1834 if (p->type != bfd_indirect_link_order)
1836 if (p->type == bfd_fill_link_order)
1841 input_section = p->u.indirect.section;
1843 /* Hack: reset the SEC_HAS_CONTENTS flag so that
1844 elf_link_input_bfd ignores this section. */
1845 input_section->flags &=~ SEC_HAS_CONTENTS;
1848 /* Skip this section later on (I don't think this
1849 currently matters, but someday it might). */
1850 o->link_order_head = (struct bfd_link_order *) NULL;
1852 /* Really remove the section. */
1853 for (secpp = &abfd->sections;
1855 secpp = &(*secpp)->next)
1857 *secpp = (*secpp)->next;
1858 --abfd->section_count;
1863 /* There is one gptab for initialized data, and one for
1864 uninitialized data. */
1865 if (strcmp (o->name, ".gptab.sdata") == 0)
1867 else if (strcmp (o->name, ".gptab.sbss") == 0)
1871 bfd_set_error (bfd_error_nonrepresentable_section);
1875 /* The linker script always combines .gptab.data and
1876 .gptab.sdata into .gptab.sdata, and likewise for
1877 .gptab.bss and .gptab.sbss. It is possible that there is
1878 no .sdata or .sbss section in the output file, in which
1879 case we must change the name of the output section. */
1880 subname = o->name + sizeof ".gptab" - 1;
1881 if (bfd_get_section_by_name (abfd, subname) == NULL)
1883 if (o == gptab_data_sec)
1884 o->name = ".gptab.data";
1886 o->name = ".gptab.bss";
1887 subname = o->name + sizeof ".gptab" - 1;
1888 BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL);
1891 /* Set up the first entry. */
1893 tab = (Elf32_gptab *) malloc (c * sizeof (Elf32_gptab));
1896 bfd_set_error (bfd_error_no_memory);
1899 tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd);
1900 tab[0].gt_header.gt_unused = 0;
1902 /* Combine the input sections. */
1903 for (p = o->link_order_head;
1904 p != (struct bfd_link_order *) NULL;
1907 asection *input_section;
1911 bfd_size_type gpentry;
1913 if (p->type != bfd_indirect_link_order)
1915 if (p->type == bfd_fill_link_order)
1920 input_section = p->u.indirect.section;
1921 input_bfd = input_section->owner;
1923 /* Combine the gptab entries for this input section one
1924 by one. We know that the input gptab entries are
1925 sorted by ascending -G value. */
1926 size = bfd_section_size (input_bfd, input_section);
1928 for (gpentry = sizeof (Elf32_External_gptab);
1930 gpentry += sizeof (Elf32_External_gptab))
1932 Elf32_External_gptab ext_gptab;
1933 Elf32_gptab int_gptab;
1939 if (! (bfd_get_section_contents
1940 (input_bfd, input_section, (PTR) &ext_gptab,
1941 gpentry, sizeof (Elf32_External_gptab))))
1947 bfd_mips_elf32_swap_gptab_in (input_bfd, &ext_gptab,
1949 val = int_gptab.gt_entry.gt_g_value;
1950 add = int_gptab.gt_entry.gt_bytes - last;
1953 for (look = 1; look < c; look++)
1955 if (tab[look].gt_entry.gt_g_value >= val)
1956 tab[look].gt_entry.gt_bytes += add;
1958 if (tab[look].gt_entry.gt_g_value == val)
1964 Elf32_gptab *new_tab;
1967 /* We need a new table entry. */
1968 new_tab = ((Elf32_gptab *)
1970 (c + 1) * sizeof (Elf32_gptab)));
1971 if (new_tab == NULL)
1973 bfd_set_error (bfd_error_no_memory);
1978 tab[c].gt_entry.gt_g_value = val;
1979 tab[c].gt_entry.gt_bytes = add;
1981 /* Merge in the size for the next smallest -G
1982 value, since that will be implied by this new
1985 for (look = 1; look < c; look++)
1987 if (tab[look].gt_entry.gt_g_value < val
1989 || (tab[look].gt_entry.gt_g_value
1990 > tab[max].gt_entry.gt_g_value)))
1994 tab[c].gt_entry.gt_bytes +=
1995 tab[max].gt_entry.gt_bytes;
2000 last = int_gptab.gt_entry.gt_bytes;
2003 /* Hack: reset the SEC_HAS_CONTENTS flag so that
2004 elf_link_input_bfd ignores this section. */
2005 input_section->flags &=~ SEC_HAS_CONTENTS;
2008 /* The table must be sorted by -G value. */
2010 qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare);
2012 /* Swap out the table. */
2013 ext_tab = ((Elf32_External_gptab *)
2014 bfd_alloc (abfd, c * sizeof (Elf32_External_gptab)));
2015 if (ext_tab == NULL)
2017 bfd_set_error (bfd_error_no_memory);
2022 for (i = 0; i < c; i++)
2023 bfd_mips_elf32_swap_gptab_out (abfd, tab + i, ext_tab + i);
2026 o->_raw_size = c * sizeof (Elf32_External_gptab);
2027 o->contents = (bfd_byte *) ext_tab;
2029 /* Skip this section later on (I don't think this currently
2030 matters, but someday it might). */
2031 o->link_order_head = (struct bfd_link_order *) NULL;
2035 /* Get a value for the GP register. */
2036 if (elf_gp (abfd) == 0)
2038 struct bfd_link_hash_entry *h;
2040 h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true);
2041 if (h != (struct bfd_link_hash_entry *) NULL
2042 && h->type == bfd_link_hash_defined)
2043 elf_gp (abfd) = (h->u.def.value
2044 + h->u.def.section->output_section->vma
2045 + h->u.def.section->output_offset);
2046 else if (info->relocateable)
2050 /* Make up a value. */
2052 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2055 && (strcmp (o->name, ".sbss") == 0
2056 || strcmp (o->name, ".sdata") == 0
2057 || strcmp (o->name, ".lit4") == 0
2058 || strcmp (o->name, ".lit8") == 0))
2061 elf_gp (abfd) = lo + 0x8000;
2065 /* If the relocate_section function needs to do a reloc
2066 involving the GP value, it should make a reloc_dangerous
2067 callback to warn that GP is not defined. */
2071 /* Invoke the regular ELF backend linker to do all the work. */
2072 if (! bfd_elf32_bfd_final_link (abfd, info))
2075 /* Now write out the computed sections. */
2077 if (reginfo_sec != (asection *) NULL)
2079 Elf32_External_RegInfo ext;
2081 bfd_mips_elf32_swap_reginfo_out (abfd, ®info, &ext);
2082 if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext,
2083 (file_ptr) 0, sizeof ext))
2087 if (mdebug_sec != (asection *) NULL)
2089 BFD_ASSERT (abfd->output_has_begun);
2090 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug,
2092 mdebug_sec->filepos))
2095 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info);
2098 if (gptab_data_sec != (asection *) NULL)
2100 if (! bfd_set_section_contents (abfd, gptab_data_sec,
2101 gptab_data_sec->contents,
2103 gptab_data_sec->_raw_size))
2107 if (gptab_bss_sec != (asection *) NULL)
2109 if (! bfd_set_section_contents (abfd, gptab_bss_sec,
2110 gptab_bss_sec->contents,
2112 gptab_bss_sec->_raw_size))
2119 /* Handle a MIPS ELF HI16 reloc. */
2122 mips_elf_relocate_hi16 (input_bfd, relhi, rello, contents, addend)
2124 Elf_Internal_Rela *relhi;
2125 Elf_Internal_Rela *rello;
2132 insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
2134 addlo = bfd_get_32 (input_bfd, contents + rello->r_offset);
2137 addend += ((insn & 0xffff) << 16) + addlo;
2139 if ((addlo & 0x8000) != 0)
2141 if ((addend & 0x8000) != 0)
2144 bfd_put_32 (input_bfd,
2145 (insn & 0xffff0000) | ((addend >> 16) & 0xffff),
2146 contents + relhi->r_offset);
2149 /* Relocate a MIPS ELF section. */
2152 mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
2153 contents, relocs, local_syms, local_sections)
2155 struct bfd_link_info *info;
2157 asection *input_section;
2159 Elf_Internal_Rela *relocs;
2160 Elf_Internal_Sym *local_syms;
2161 asection **local_sections;
2163 Elf_Internal_Shdr *symtab_hdr;
2166 Elf_Internal_Rela *rel;
2167 Elf_Internal_Rela *relend;
2169 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2171 if (elf_bad_symtab (input_bfd))
2173 locsymcount = symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
2178 locsymcount = symtab_hdr->sh_info;
2179 extsymoff = symtab_hdr->sh_info;
2183 relend = relocs + input_section->reloc_count;
2184 for (; rel < relend; rel++)
2187 const reloc_howto_type *howto;
2190 struct elf_link_hash_entry *h;
2192 Elf_Internal_Sym *sym;
2193 bfd_reloc_status_type r;
2195 r_type = ELF32_R_TYPE (rel->r_info);
2196 if (r_type < 0 || r_type >= (int) R_MIPS_max)
2198 bfd_set_error (bfd_error_bad_value);
2201 howto = elf_mips_howto_table + r_type;
2203 r_symndx = ELF32_R_SYM (rel->r_info);
2205 /* Mix in the change in GP address for a GP relative reloc. */
2206 if (r_type != R_MIPS_GPREL16
2207 && r_type != R_MIPS_LITERAL
2208 && r_type != R_MIPS_GPREL32)
2212 if (elf_gp (output_bfd) == 0)
2214 if (! ((*info->callbacks->reloc_dangerous)
2216 "GP relative relocation when GP not defined",
2217 input_bfd, input_section,
2220 /* Only give the error once per link. */
2221 elf_gp (output_bfd) = 4;
2224 if (r_symndx < extsymoff
2225 || (elf_bad_symtab (input_bfd)
2226 && local_sections[r_symndx] != NULL))
2228 /* This is a relocation against a section. The current
2229 addend in the instruction is the difference between
2230 INPUT_SECTION->vma and the GP value of INPUT_BFD. We
2231 must change this to be the difference between the
2232 final definition (which will end up in RELOCATION)
2233 and the GP value of OUTPUT_BFD (which is in GP). */
2234 addend = elf_gp (input_bfd) - elf_gp (output_bfd);
2236 else if (! info->relocateable)
2238 /* We are doing a final link. The current addend in the
2239 instruction is simply the desired offset into the
2240 symbol (normally zero). We want the instruction to
2241 hold the difference between the final definition of
2242 the symbol (which will end up in RELOCATION) and the
2243 GP value of OUTPUT_BFD (which is in GP). */
2244 addend = - elf_gp (output_bfd);
2248 /* We are generating relocateable output, and we aren't
2249 going to define this symbol, so we just leave the
2250 instruction alone. */
2258 if (info->relocateable)
2260 /* This is a relocateable link. We don't have to change
2261 anything, unless the reloc is against a section symbol,
2262 in which case we have to adjust according to where the
2263 section symbol winds up in the output section. */
2264 if (r_symndx >= locsymcount
2265 || (elf_bad_symtab (input_bfd)
2266 && local_sections[r_symndx] == NULL))
2270 sym = local_syms + r_symndx;
2271 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
2275 sec = local_sections[r_symndx];
2277 /* It would be logical to add sym->st_value here,
2278 but Irix 5 sometimes generates a garbage symbol
2280 addend += sec->output_offset;
2282 /* If this is HI16 with an associated LO16, adjust
2283 the addend accordingly. Otherwise, just
2285 if (r_type != R_MIPS_HI16
2286 || (rel + 1) >= relend
2287 || ELF32_R_TYPE ((rel + 1)->r_info) != R_MIPS_LO16)
2288 r = _bfd_relocate_contents (howto, input_bfd,
2290 contents + rel->r_offset);
2293 mips_elf_relocate_hi16 (input_bfd, rel, rel + 1,
2304 /* This is a final link. */
2306 if (r_symndx < extsymoff
2307 || (elf_bad_symtab (input_bfd)
2308 && local_sections[r_symndx] != NULL))
2310 sym = local_syms + r_symndx;
2311 sec = local_sections[r_symndx];
2312 relocation = (sec->output_section->vma
2313 + sec->output_offset);
2315 /* It would be logical to always add sym->st_value here,
2316 but Irix 5 sometimes generates a garbage symbol
2318 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
2319 relocation += sym->st_value;
2325 indx = r_symndx - extsymoff;
2326 h = elf_sym_hashes (input_bfd)[indx];
2327 if (h->root.type == bfd_link_hash_defined)
2329 sec = h->root.u.def.section;
2330 relocation = (h->root.u.def.value
2331 + sec->output_section->vma
2332 + sec->output_offset);
2334 else if (h->root.type == bfd_link_hash_weak)
2338 if (! ((*info->callbacks->undefined_symbol)
2339 (info, h->root.root.string, input_bfd,
2340 input_section, rel->r_offset)))
2346 if (r_type != R_MIPS_HI16
2347 || (rel + 1) >= relend
2348 || ELF32_R_TYPE ((rel + 1)->r_info) != R_MIPS_LO16)
2349 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
2350 contents, rel->r_offset,
2351 relocation, addend);
2354 mips_elf_relocate_hi16 (input_bfd, rel, rel + 1,
2355 contents, relocation + addend);
2360 if (r != bfd_reloc_ok)
2365 case bfd_reloc_outofrange:
2367 case bfd_reloc_overflow:
2372 name = h->root.root.string;
2375 name = elf_string_from_elf_section (input_bfd,
2376 symtab_hdr->sh_link,
2381 name = bfd_section_name (input_bfd, sec);
2383 if (! ((*info->callbacks->reloc_overflow)
2384 (info, name, howto->name, (bfd_vma) 0,
2385 input_bfd, input_section, rel->r_offset)))
2396 /* ECOFF swapping routines. These are used when dealing with the
2397 .mdebug section, which is in the ECOFF debugging format. */
2398 static const struct ecoff_debug_swap mips_elf_ecoff_debug_swap =
2400 /* Symbol table magic number. */
2402 /* Alignment of debugging information. E.g., 4. */
2404 /* Sizes of external symbolic information. */
2405 sizeof (struct hdr_ext),
2406 sizeof (struct dnr_ext),
2407 sizeof (struct pdr_ext),
2408 sizeof (struct sym_ext),
2409 sizeof (struct opt_ext),
2410 sizeof (struct fdr_ext),
2411 sizeof (struct rfd_ext),
2412 sizeof (struct ext_ext),
2413 /* Functions to swap in external symbolic data. */
2422 _bfd_ecoff_swap_tir_in,
2423 _bfd_ecoff_swap_rndx_in,
2424 /* Functions to swap out external symbolic data. */
2433 _bfd_ecoff_swap_tir_out,
2434 _bfd_ecoff_swap_rndx_out,
2435 /* Function to read in symbolic data. */
2436 mips_elf_read_ecoff_info
2439 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
2440 #define TARGET_LITTLE_NAME "elf32-littlemips"
2441 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec
2442 #define TARGET_BIG_NAME "elf32-bigmips"
2443 #define ELF_ARCH bfd_arch_mips
2444 #define ELF_MACHINE_CODE EM_MIPS
2445 #define ELF_MAXPAGESIZE 0x10000
2446 #define elf_backend_collect true
2447 #define elf_info_to_howto 0
2448 #define elf_info_to_howto_rel mips_info_to_howto_rel
2449 #define elf_backend_sym_is_global mips_elf_sym_is_global
2450 #define elf_backend_object_p mips_elf_object_p
2451 #define elf_backend_section_from_shdr mips_elf_section_from_shdr
2452 #define elf_backend_fake_sections mips_elf_fake_sections
2453 #define elf_backend_section_from_bfd_section \
2454 mips_elf_section_from_bfd_section
2455 #define elf_backend_section_processing mips_elf_section_processing
2456 #define elf_backend_symbol_processing mips_elf_symbol_processing
2457 #define elf_backend_final_write_processing \
2458 mips_elf_final_write_processing
2459 #define elf_backend_ecoff_debug_swap &mips_elf_ecoff_debug_swap
2461 #define bfd_elf32_bfd_link_hash_table_create \
2462 mips_elf_link_hash_table_create
2463 #define bfd_elf32_bfd_final_link mips_elf_final_link
2464 #define elf_backend_relocate_section mips_elf_relocate_section
2465 #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook
2467 #include "elf32-target.h"