1 /* BFD back-end for MIPS Extended-Coff files.
2 Copyright 1990, 1991, 1992, 1993 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "aout/ranlib.h"
28 #include "coff/mips.h"
29 #include "coff/internal.h"
31 #include "coff/symconst.h"
32 #include "coff/ecoff-ext.h"
36 /* Each canonical asymbol really looks like this. */
38 typedef struct ecoff_symbol_struct
40 /* The actual symbol which the rest of BFD works with */
43 /* The fdr for this symbol. */
46 /* true if this is a local symbol rather than an external one. */
49 /* A pointer to the unswapped hidden information for this symbol */
52 struct sym_ext *lnative;
53 struct ext_ext *enative;
58 /* We take the address of the first element of a asymbol to ensure that the
59 macro is only ever applied to an asymbol. */
60 #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd)))
62 /* This is a hack borrowed from coffcode.h; we need to save the index
63 of a symbol when we write it out so that can set the symbol index
64 correctly when we write out the relocs. */
65 #define ecoff_get_sym_index(symbol) ((unsigned long) (symbol)->udata)
66 #define ecoff_set_sym_index(symbol, idx) ((symbol)->udata = (PTR) (idx))
68 /* The page boundary used to align sections in the executable file. */
69 #define PAGE_SIZE 0x2000
71 /* The linker needs a section to hold small common variables while
72 linking. There is no convenient way to create it when the linker
73 needs it, so we always create one for each BFD. We then avoid
75 #define SCOMMON ".scommon"
77 /* MIPS ECOFF has COFF sections, but the debugging information is
78 stored in a completely different format. This files uses the some
79 of the swapping routines from coffswap.h, and some of the generic
80 COFF routines in coffgen.c, but, unlike the real COFF targets, does
81 not use coffcode.h itself. */
83 /* Prototypes for static functions. */
85 static boolean ecoff_bad_format_hook PARAMS ((bfd *abfd, PTR filehdr));
86 static asection *ecoff_make_section_hook PARAMS ((bfd *abfd, char *name));
87 static boolean ecoff_new_section_hook PARAMS ((bfd *abfd, asection *section));
88 static boolean ecoff_mkobject PARAMS ((bfd *abfd));
89 static PTR ecoff_mkobject_hook PARAMS ((bfd *abfd, PTR filehdr, PTR aouthdr));
90 static boolean ecoff_set_arch_mach_hook PARAMS ((bfd *abfd, PTR filehdr));
91 static long ecoff_sec_to_styp_flags PARAMS ((CONST char *name,
93 static flagword ecoff_styp_to_sec_flags PARAMS ((bfd *abfd, PTR hdr));
94 static asymbol *ecoff_make_empty_symbol PARAMS ((bfd *abfd));
95 static void ecoff_set_symbol_info PARAMS ((bfd *abfd, SYMR *ecoff_sym,
96 asymbol *asym, int ext));
97 static boolean ecoff_slurp_symbol_table PARAMS ((bfd *abfd));
98 static unsigned int ecoff_get_symtab_upper_bound PARAMS ((bfd *abfd));
99 static unsigned int ecoff_get_symtab PARAMS ((bfd *abfd,
100 asymbol **alocation));
101 static void ecoff_emit_aggregate PARAMS ((bfd *abfd, char *string,
102 RNDXR *rndx, long isym,
104 static char *ecoff_type_to_string PARAMS ((bfd *abfd, union aux_ext *aux_ptr,
105 int indx, int bigendian));
106 static void ecoff_print_symbol PARAMS ((bfd *abfd, PTR filep,
108 bfd_print_symbol_type how));
109 static void ecoff_swap_reloc_in PARAMS ((bfd *abfd, RELOC *ext,
110 struct internal_reloc *intern));
111 static unsigned int ecoff_swap_reloc_out PARAMS ((bfd *abfd, PTR src,
113 static bfd_reloc_status_type ecoff_generic_reloc PARAMS ((bfd *abfd,
119 static bfd_reloc_status_type ecoff_refhi_reloc PARAMS ((bfd *abfd,
125 static bfd_reloc_status_type ecoff_gprel_reloc PARAMS ((bfd *abfd,
131 static boolean ecoff_slurp_reloc_table PARAMS ((bfd *abfd, asection *section,
133 static unsigned int ecoff_canonicalize_reloc PARAMS ((bfd *abfd,
137 static boolean ecoff_find_nearest_line PARAMS ((bfd *abfd,
141 CONST char **filename_ptr,
142 CONST char **fnname_ptr,
143 unsigned int *retline_ptr));
144 static void ecoff_clear_output_flags PARAMS ((bfd *abfd));
145 static boolean ecoff_rel PARAMS ((bfd *output_bfd, bfd_seclet_type *seclet,
146 asection *output_section, PTR data,
147 boolean relocateable));
148 static boolean ecoff_dump_seclet PARAMS ((bfd *abfd, bfd_seclet_type *seclet,
149 asection *section, PTR data,
150 boolean relocateable));
151 static long ecoff_add_string PARAMS ((bfd *output_bfd, FDR *fdr,
152 CONST char *string, boolean external));
153 static boolean ecoff_get_debug PARAMS ((bfd *output_bfd,
154 bfd_seclet_type *seclet,
156 boolean relocateable));
157 static boolean ecoff_bfd_seclet_link PARAMS ((bfd *abfd, PTR data,
158 boolean relocateable));
159 static boolean ecoff_set_arch_mach PARAMS ((bfd *abfd,
160 enum bfd_architecture arch,
161 unsigned long machine));
162 static int ecoff_sizeof_headers PARAMS ((bfd *abfd, boolean reloc));
163 static void ecoff_compute_section_file_positions PARAMS ((bfd *abfd));
164 static boolean ecoff_set_section_contents PARAMS ((bfd *abfd,
168 bfd_size_type count));
169 static boolean ecoff_write_object_contents PARAMS ((bfd *abfd));
170 static unsigned int ecoff_armap_hash PARAMS ((CONST char *s,
171 unsigned int *rehash,
174 static boolean ecoff_slurp_armap PARAMS ((bfd *abfd));
175 static boolean ecoff_write_armap PARAMS ((bfd *abfd, unsigned int elength,
177 unsigned int orl_count,
179 static bfd_target *ecoff_archive_p PARAMS ((bfd *abfd));
181 /* Get the generic COFF swapping routines, except for the reloc,
182 symbol, and lineno ones. Give them ecoff names. */
184 #define NO_COFF_RELOCS
185 #define NO_COFF_SYMBOLS
186 #define NO_COFF_LINENOS
187 #define coff_swap_filehdr_in ecoff_swap_filehdr_in
188 #define coff_swap_filehdr_out ecoff_swap_filehdr_out
189 #define coff_swap_aouthdr_in ecoff_swap_aouthdr_in
190 #define coff_swap_aouthdr_out ecoff_swap_aouthdr_out
191 #define coff_swap_scnhdr_in ecoff_swap_scnhdr_in
192 #define coff_swap_scnhdr_out ecoff_swap_scnhdr_out
193 #include "coffswap.h"
195 /* This stuff is somewhat copied from coffcode.h. */
197 static asection bfd_debug_section = { "*DEBUG*" };
199 /* See whether the magic number matches. */
202 ecoff_bad_format_hook (abfd, filehdr)
206 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
208 if (ECOFFBADMAG (*internal_f))
214 /* This is a hook needed by SCO COFF, but we have nothing to do. */
217 ecoff_make_section_hook (abfd, name)
221 return (asection *) NULL;
224 /* Initialize a new section. */
227 ecoff_new_section_hook (abfd, section)
231 section->alignment_power = abfd->xvec->align_power_min;
233 if (strcmp (section->name, _TEXT) == 0)
234 section->flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
235 else if (strcmp (section->name, _DATA) == 0
236 || strcmp (section->name, _SDATA) == 0)
237 section->flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
238 else if (strcmp (section->name, _RDATA) == 0
239 || strcmp (section->name, _LIT8) == 0
240 || strcmp (section->name, _LIT4) == 0)
241 section->flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
242 else if (strcmp (section->name, _BSS) == 0
243 || strcmp (section->name, _SBSS) == 0)
244 section->flags |= SEC_ALLOC;
246 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
247 uncertain about .init on some systems and I don't know how shared
253 /* Set the alignment of a section; we have nothing to do. */
255 #define ecoff_set_alignment_hook \
256 ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void)
258 /* Create an ECOFF object. */
261 ecoff_mkobject (abfd)
264 abfd->tdata.ecoff_obj_data = ((struct ecoff_tdata *)
265 bfd_zalloc (abfd, sizeof(ecoff_data_type)));
266 if (abfd->tdata.ecoff_obj_data == NULL)
268 bfd_error = no_memory;
272 /* Always create a .scommon section for every BFD. This is a hack so
273 that the linker has something to attach scSCommon symbols to. */
274 bfd_make_section (abfd, SCOMMON);
279 /* Create the ECOFF backend specific information. */
282 ecoff_mkobject_hook (abfd, filehdr, aouthdr)
287 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
288 struct internal_aouthdr *internal_a = (struct internal_aouthdr *) aouthdr;
289 ecoff_data_type *ecoff;
291 if (ecoff_mkobject (abfd) == false)
294 ecoff = ecoff_data (abfd);
295 ecoff->sym_filepos = internal_f->f_symptr;
297 if (internal_a != (struct internal_aouthdr *) NULL)
301 ecoff->text_start = internal_a->text_start;
302 ecoff->text_end = internal_a->text_start + internal_a->tsize;
303 ecoff->gp = internal_a->gp_value;
304 ecoff->gprmask = internal_a->gprmask;
305 for (i = 0; i < 4; i++)
306 ecoff->cprmask[i] = internal_a->cprmask[i];
312 /* Determine the machine architecture and type. */
315 ecoff_set_arch_mach_hook (abfd, filehdr)
319 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
320 enum bfd_architecture arch;
322 switch (internal_f->f_magic)
325 case MIPS_MAGIC_LITTLE:
327 arch = bfd_arch_mips;
331 arch = bfd_arch_obscure;
335 bfd_default_set_arch_mach (abfd, arch, (unsigned long) 0);
340 /* Get the section s_flags to use for a section. */
343 ecoff_sec_to_styp_flags (name, flags)
351 if (strcmp (name, _TEXT) == 0)
353 else if (strcmp (name, _DATA) == 0)
355 else if (strcmp (name, _SDATA) == 0)
357 else if (strcmp (name, _RDATA) == 0)
359 else if (strcmp (name, _LIT8) == 0)
361 else if (strcmp (name, _LIT4) == 0)
363 else if (strcmp (name, _BSS) == 0)
365 else if (strcmp (name, _SBSS) == 0)
367 else if (flags & SEC_CODE)
369 else if (flags & SEC_DATA)
371 else if (flags & SEC_READONLY)
373 else if (flags & SEC_LOAD)
378 if (flags & SEC_NEVER_LOAD)
384 /* Get the BFD flags to use for a section. */
387 ecoff_styp_to_sec_flags (abfd, hdr)
391 struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
392 long styp_flags = internal_s->s_flags;
393 flagword sec_flags=0;
395 if (styp_flags & STYP_NOLOAD)
396 sec_flags |= SEC_NEVER_LOAD;
398 /* For 386 COFF, at least, an unloadable text or data section is
399 actually a shared library section. */
400 if (styp_flags & STYP_TEXT)
402 if (sec_flags & SEC_NEVER_LOAD)
403 sec_flags |= SEC_CODE | SEC_SHARED_LIBRARY;
405 sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
407 else if ((styp_flags & STYP_DATA)
408 || (styp_flags & STYP_RDATA)
409 || (styp_flags & STYP_SDATA))
411 if (sec_flags & SEC_NEVER_LOAD)
412 sec_flags |= SEC_DATA | SEC_SHARED_LIBRARY;
414 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
415 if (styp_flags & STYP_RDATA)
416 sec_flags |= SEC_READONLY;
418 else if ((styp_flags & STYP_BSS)
419 || (styp_flags & STYP_SBSS))
421 sec_flags |= SEC_ALLOC;
423 else if (styp_flags & STYP_INFO)
425 sec_flags |= SEC_NEVER_LOAD;
427 else if ((styp_flags & STYP_LIT8)
428 || (styp_flags & STYP_LIT4))
430 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
434 sec_flags |= SEC_ALLOC | SEC_LOAD;
440 /* Read in and swap the important symbolic information for an ECOFF
441 object file. FIXME: This is called by gdb. If there is ever
442 another ECOFF target, it should be moved into some sort of target
443 specific structure. */
446 ecoff_slurp_symbolic_info (abfd)
449 struct hdr_ext external_symhdr;
450 HDRR *internal_symhdr;
451 bfd_size_type raw_base;
452 bfd_size_type raw_size;
454 struct fdr_ext *fraw_src;
455 struct fdr_ext *fraw_end;
458 /* Check whether we've already gotten it, and whether there's any to
460 if (ecoff_data (abfd)->raw_syments != (PTR) NULL)
462 if (ecoff_data (abfd)->sym_filepos == 0)
464 bfd_get_symcount (abfd) = 0;
468 /* At this point bfd_get_symcount (abfd) holds the number of symbols
469 as read from the file header, but on ECOFF this is always the
470 size of the symbolic information header. It would be cleaner to
471 handle this when we first read the file in coffgen.c. */
472 if (bfd_get_symcount (abfd) != sizeof (external_symhdr))
474 bfd_error = bad_value;
478 /* Read the symbolic information header. */
479 if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) == -1
480 || (bfd_read ((PTR) &external_symhdr, sizeof (external_symhdr), 1, abfd)
481 != sizeof (external_symhdr)))
483 bfd_error = system_call_error;
486 internal_symhdr = &ecoff_data (abfd)->symbolic_header;
487 ecoff_swap_hdr_in (abfd, &external_symhdr, internal_symhdr);
489 if (internal_symhdr->magic != magicSym)
491 bfd_error = bad_value;
495 /* Now we can get the correct number of symbols. */
496 bfd_get_symcount (abfd) = (internal_symhdr->isymMax
497 + internal_symhdr->iextMax);
499 /* Read all the symbolic information at once. */
500 raw_base = ecoff_data (abfd)->sym_filepos + sizeof (struct hdr_ext);
502 if (internal_symhdr->cbExtOffset != 0)
503 raw_size = (internal_symhdr->cbExtOffset
505 + internal_symhdr->iextMax * sizeof (struct ext_ext));
508 long cbline, issmax, issextmax;
510 cbline = (internal_symhdr->cbLine + 3) &~ 3;
511 issmax = (internal_symhdr->issMax + 3) &~ 3;
512 issextmax = (internal_symhdr->issExtMax + 3) &~ 3;
513 raw_size = (cbline * sizeof (unsigned char)
514 + internal_symhdr->idnMax * sizeof (struct dnr_ext)
515 + internal_symhdr->ipdMax * sizeof (struct pdr_ext)
516 + internal_symhdr->isymMax * sizeof (struct sym_ext)
517 + internal_symhdr->ioptMax * sizeof (struct opt_ext)
518 + internal_symhdr->iauxMax * sizeof (union aux_ext)
519 + issmax * sizeof (char)
520 + issextmax * sizeof (char)
521 + internal_symhdr->ifdMax * sizeof (struct fdr_ext)
522 + internal_symhdr->crfd * sizeof (struct rfd_ext)
523 + internal_symhdr->iextMax * sizeof (struct ext_ext));
528 ecoff_data (abfd)->sym_filepos = 0;
531 raw = (PTR) bfd_alloc (abfd, raw_size);
534 bfd_error = no_memory;
537 if (bfd_read (raw, raw_size, 1, abfd) != raw_size)
539 bfd_error = system_call_error;
540 bfd_release (abfd, raw);
544 ecoff_data (abfd)->raw_size = raw_size;
545 ecoff_data (abfd)->raw_syments = raw;
547 /* Get pointers for the numeric offsets in the HDRR structure. */
548 #define FIX(off1, off2, type) \
549 if (internal_symhdr->off1 == 0) \
550 ecoff_data (abfd)->off2 = (type *) NULL; \
552 ecoff_data (abfd)->off2 = (type *) ((char *) raw \
553 + internal_symhdr->off1 \
555 FIX (cbLineOffset, line, unsigned char);
556 FIX (cbDnOffset, external_dnr, struct dnr_ext);
557 FIX (cbPdOffset, external_pdr, struct pdr_ext);
558 FIX (cbSymOffset, external_sym, struct sym_ext);
559 FIX (cbOptOffset, external_opt, struct opt_ext);
560 FIX (cbAuxOffset, external_aux, union aux_ext);
561 FIX (cbSsOffset, ss, char);
562 FIX (cbSsExtOffset, ssext, char);
563 FIX (cbFdOffset, external_fdr, struct fdr_ext);
564 FIX (cbRfdOffset, external_rfd, struct rfd_ext);
565 FIX (cbExtOffset, external_ext, struct ext_ext);
568 /* I don't want to always swap all the data, because it will just
569 waste time and most programs will never look at it. The only
570 time the linker needs most of the debugging information swapped
571 is when linking big-endian and little-endian MIPS object files
572 together, which is not a common occurrence.
574 We need to look at the fdr to deal with a lot of information in
575 the symbols, so we swap them here. */
576 ecoff_data (abfd)->fdr = (struct fdr *) bfd_alloc (abfd,
577 (internal_symhdr->ifdMax *
578 sizeof (struct fdr)));
579 if (ecoff_data (abfd)->fdr == NULL)
581 bfd_error = no_memory;
584 fdr_ptr = ecoff_data (abfd)->fdr;
585 fraw_src = ecoff_data (abfd)->external_fdr;
586 fraw_end = fraw_src + internal_symhdr->ifdMax;
587 for (; fraw_src < fraw_end; fraw_src++, fdr_ptr++)
588 ecoff_swap_fdr_in (abfd, fraw_src, fdr_ptr);
593 /* ECOFF symbol table routines. The ECOFF symbol table is described
594 in gcc/mips-tfile.c. */
596 /* ECOFF uses two common sections. One is the usual one, and the
597 other is for small objects. All the small objects are kept
598 together, and then referenced via the gp pointer, which yields
599 faster assembler code. This is what we use for the small common
601 static asection ecoff_scom_section;
602 static asymbol ecoff_scom_symbol;
603 static asymbol *ecoff_scom_symbol_ptr;
605 /* Create an empty symbol. */
608 ecoff_make_empty_symbol (abfd)
611 ecoff_symbol_type *new;
613 new = (ecoff_symbol_type *) bfd_alloc (abfd, sizeof (ecoff_symbol_type));
614 if (new == (ecoff_symbol_type *) NULL)
616 bfd_error = no_memory;
617 return (asymbol *) NULL;
619 new->symbol.section = (asection *) NULL;
620 new->fdr = (FDR *) NULL;
622 new->native.lnative = (struct sym_ext *) NULL;
623 new->symbol.the_bfd = abfd;
627 /* Set the BFD flags and section for an ECOFF symbol. */
630 ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext)
636 asym->the_bfd = abfd;
637 asym->value = ecoff_sym->value;
638 asym->section = &bfd_debug_section;
641 /* Most symbol types are just for debugging. */
642 switch (ecoff_sym->st)
652 asym->flags = BSF_DEBUGGING;
657 asym->flags = BSF_EXPORT | BSF_GLOBAL;
659 asym->flags = BSF_LOCAL;
660 switch (ecoff_sym->sc)
663 /* Used for compiler generated labels. Leave them in the
664 debugging section, and mark them as local. If BSF_DEBUGGING
665 is set, then nm does not display them for some reason. If no
666 flags are set then the linker whines about them. */
667 asym->flags = BSF_LOCAL;
670 asym->section = bfd_make_section_old_way (abfd, ".text");
671 asym->value -= asym->section->vma;
674 asym->section = bfd_make_section_old_way (abfd, ".data");
675 asym->value -= asym->section->vma;
680 asym->section = &bfd_com_section;
685 asym->section = bfd_make_section_old_way (abfd, ".bss");
686 asym->value -= asym->section->vma;
690 asym->flags = BSF_DEBUGGING;
693 asym->section = &bfd_abs_section;
696 asym->section = &bfd_und_section;
706 asym->flags = BSF_DEBUGGING;
709 asym->section = bfd_make_section_old_way (abfd, ".sdata");
710 asym->value -= asym->section->vma;
713 asym->section = bfd_make_section_old_way (abfd, ".sbss");
715 asym->value -= asym->section->vma;
718 asym->section = bfd_make_section_old_way (abfd, ".rdata");
719 asym->value -= asym->section->vma;
722 asym->flags = BSF_DEBUGGING;
725 /* FIXME: We should take a -G argument, which gives the maximum
726 size of objects to be put in the small common section. Until
727 we do, we put objects of sizes up to 8 in the small common
728 section. The assembler should do this for us, but the native
729 assembler seems to get confused. */
732 asym->section = &bfd_com_section;
737 if (ecoff_scom_section.name == NULL)
739 /* Initialize the small common section. */
740 ecoff_scom_section.name = SCOMMON;
741 ecoff_scom_section.flags = SEC_IS_COMMON;
742 ecoff_scom_section.output_section = &ecoff_scom_section;
743 ecoff_scom_section.symbol = &ecoff_scom_symbol;
744 ecoff_scom_section.symbol_ptr_ptr = &ecoff_scom_symbol_ptr;
745 ecoff_scom_symbol.name = SCOMMON;
746 ecoff_scom_symbol.flags = BSF_SECTION_SYM;
747 ecoff_scom_symbol.section = &ecoff_scom_section;
748 ecoff_scom_symbol_ptr = &ecoff_scom_symbol;
750 asym->section = &ecoff_scom_section;
755 asym->flags = BSF_DEBUGGING;
758 asym->section = &bfd_und_section;
763 asym->section = bfd_make_section_old_way (abfd, ".init");
764 asym->value -= asym->section->vma;
769 asym->flags = BSF_DEBUGGING;
772 asym->section = bfd_make_section_old_way (abfd, ".fini");
773 asym->value -= asym->section->vma;
780 /* Read an ECOFF symbol table. */
783 ecoff_slurp_symbol_table (abfd)
786 bfd_size_type internal_size;
787 ecoff_symbol_type *internal;
788 ecoff_symbol_type *internal_ptr;
789 struct ext_ext *eraw_src;
790 struct ext_ext *eraw_end;
794 /* If we've already read in the symbol table, do nothing. */
795 if (ecoff_data (abfd)->canonical_symbols != NULL)
798 /* Get the symbolic information. */
799 if (ecoff_slurp_symbolic_info (abfd) == false)
801 if (bfd_get_symcount (abfd) == 0)
804 internal_size = bfd_get_symcount (abfd) * sizeof (ecoff_symbol_type);
805 internal = (ecoff_symbol_type *) bfd_alloc (abfd, internal_size);
806 if (internal == NULL)
808 bfd_error = no_memory;
812 internal_ptr = internal;
813 eraw_src = ecoff_data (abfd)->external_ext;
814 eraw_end = eraw_src + ecoff_data (abfd)->symbolic_header.iextMax;
815 for (; eraw_src < eraw_end; eraw_src++, internal_ptr++)
819 ecoff_swap_ext_in (abfd, eraw_src, &internal_esym);
820 internal_ptr->symbol.name = (ecoff_data (abfd)->ssext
821 + internal_esym.asym.iss);
822 ecoff_set_symbol_info (abfd, &internal_esym.asym,
823 &internal_ptr->symbol, 1);
824 internal_ptr->fdr = ecoff_data (abfd)->fdr + internal_esym.ifd;
825 internal_ptr->local = false;
826 internal_ptr->native.enative = eraw_src;
829 /* The local symbols must be accessed via the fdr's, because the
830 string and aux indices are relative to the fdr information. */
831 fdr_ptr = ecoff_data (abfd)->fdr;
832 fdr_end = fdr_ptr + ecoff_data (abfd)->symbolic_header.ifdMax;
833 for (; fdr_ptr < fdr_end; fdr_ptr++)
835 struct sym_ext *lraw_src;
836 struct sym_ext *lraw_end;
838 lraw_src = ecoff_data (abfd)->external_sym + fdr_ptr->isymBase;
839 lraw_end = lraw_src + fdr_ptr->csym;
840 for (; lraw_src < lraw_end; lraw_src++, internal_ptr++)
844 ecoff_swap_sym_in (abfd, lraw_src, &internal_sym);
845 internal_ptr->symbol.name = (ecoff_data (abfd)->ss
848 ecoff_set_symbol_info (abfd, &internal_sym,
849 &internal_ptr->symbol, 0);
850 internal_ptr->fdr = fdr_ptr;
851 internal_ptr->local = true;
852 internal_ptr->native.lnative = lraw_src;
856 ecoff_data (abfd)->canonical_symbols = internal;
862 ecoff_get_symtab_upper_bound (abfd)
865 if (ecoff_slurp_symbolic_info (abfd) == false
866 || bfd_get_symcount (abfd) == 0)
869 return (bfd_get_symcount (abfd) + 1) * (sizeof (ecoff_symbol_type *));
873 ecoff_get_symtab (abfd, alocation)
877 unsigned int counter = 0;
878 ecoff_symbol_type *symbase;
879 ecoff_symbol_type **location = (ecoff_symbol_type **) alocation;
881 if (ecoff_slurp_symbol_table (abfd) == false
882 || bfd_get_symcount (abfd) == 0)
885 symbase = ecoff_data (abfd)->canonical_symbols;
886 while (counter < bfd_get_symcount (abfd))
888 *(location++) = symbase++;
891 *location++ = (ecoff_symbol_type *) NULL;
892 return bfd_get_symcount (abfd);
895 /* Turn ECOFF type information into a printable string.
896 ecoff_emit_aggregate and ecoff_type_to_string are from
897 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
899 /* Write aggregate information to a string. */
902 ecoff_emit_aggregate (abfd, string, rndx, isym, which)
910 int indx = rndx->index;
911 int sym_base, ss_base;
917 sym_base = ecoff_data (abfd)->fdr[ifd].isymBase;
918 ss_base = ecoff_data (abfd)->fdr[ifd].issBase;
920 if (indx == indexNil)
921 name = "/* no name */";
927 ecoff_swap_sym_in (abfd,
928 ecoff_data (abfd)->external_sym + indx,
930 name = ecoff_data (abfd)->ss + ss_base + sym.iss;
934 "%s %s { ifd = %d, index = %d }",
936 indx + ecoff_data (abfd)->symbolic_header.iextMax);
939 /* Convert the type information to string format. */
942 ecoff_type_to_string (abfd, aux_ptr, indx, bigendian)
944 union aux_ext *aux_ptr;
956 unsigned int basic_type;
958 static char buffer1[1024];
959 static char buffer2[1024];
964 for (i = 0; i < 7; i++)
966 qualifiers[i].low_bound = 0;
967 qualifiers[i].high_bound = 0;
968 qualifiers[i].stride = 0;
971 if (AUX_GET_ISYM (bigendian, &aux_ptr[indx]) == -1)
972 return "-1 (no type)";
973 ecoff_swap_tir_in (bigendian, &aux_ptr[indx++].a_ti, &u.ti);
975 basic_type = u.ti.bt;
976 qualifiers[0].type = u.ti.tq0;
977 qualifiers[1].type = u.ti.tq1;
978 qualifiers[2].type = u.ti.tq2;
979 qualifiers[3].type = u.ti.tq3;
980 qualifiers[4].type = u.ti.tq4;
981 qualifiers[5].type = u.ti.tq5;
982 qualifiers[6].type = tqNil;
985 * Go get the basic type.
989 case btNil: /* undefined */
993 case btAdr: /* address - integer same size as pointer */
994 strcpy (p1, "address");
997 case btChar: /* character */
1001 case btUChar: /* unsigned character */
1002 strcpy (p1, "unsigned char");
1005 case btShort: /* short */
1006 strcpy (p1, "short");
1009 case btUShort: /* unsigned short */
1010 strcpy (p1, "unsigned short");
1013 case btInt: /* int */
1017 case btUInt: /* unsigned int */
1018 strcpy (p1, "unsigned int");
1021 case btLong: /* long */
1022 strcpy (p1, "long");
1025 case btULong: /* unsigned long */
1026 strcpy (p1, "unsigned long");
1029 case btFloat: /* float (real) */
1030 strcpy (p1, "float");
1033 case btDouble: /* Double (real) */
1034 strcpy (p1, "double");
1037 /* Structures add 1-2 aux words:
1038 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1039 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1041 case btStruct: /* Structure (Record) */
1042 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1043 ecoff_emit_aggregate (abfd, p1, &rndx,
1044 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1046 indx++; /* skip aux words */
1049 /* Unions add 1-2 aux words:
1050 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1051 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1053 case btUnion: /* Union */
1054 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1055 ecoff_emit_aggregate (abfd, p1, &rndx,
1056 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1058 indx++; /* skip aux words */
1061 /* Enumerations add 1-2 aux words:
1062 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1063 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1065 case btEnum: /* Enumeration */
1066 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1067 ecoff_emit_aggregate (abfd, p1, &rndx,
1068 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1070 indx++; /* skip aux words */
1073 case btTypedef: /* defined via a typedef, isymRef points */
1074 strcpy (p1, "typedef");
1077 case btRange: /* subrange of int */
1078 strcpy (p1, "subrange");
1081 case btSet: /* pascal sets */
1085 case btComplex: /* fortran complex */
1086 strcpy (p1, "complex");
1089 case btDComplex: /* fortran double complex */
1090 strcpy (p1, "double complex");
1093 case btIndirect: /* forward or unnamed typedef */
1094 strcpy (p1, "forward/unamed typedef");
1097 case btFixedDec: /* Fixed Decimal */
1098 strcpy (p1, "fixed decimal");
1101 case btFloatDec: /* Float Decimal */
1102 strcpy (p1, "float decimal");
1105 case btString: /* Varying Length Character String */
1106 strcpy (p1, "string");
1109 case btBit: /* Aligned Bit String */
1113 case btPicture: /* Picture */
1114 strcpy (p1, "picture");
1117 case btVoid: /* Void */
1118 strcpy (p1, "void");
1122 sprintf (p1, "Unknown basic type %d", (int) basic_type);
1126 p1 += strlen (buffer1);
1129 * If this is a bitfield, get the bitsize.
1135 bitsize = AUX_GET_WIDTH (bigendian, &aux_ptr[indx++]);
1136 sprintf (p1, " : %d", bitsize);
1137 p1 += strlen (buffer1);
1142 * Deal with any qualifiers.
1144 if (qualifiers[0].type != tqNil)
1147 * Snarf up any array bounds in the correct order. Arrays
1148 * store 5 successive words in the aux. table:
1149 * word 0 RNDXR to type of the bounds (ie, int)
1150 * word 1 Current file descriptor index
1152 * word 3 high bound (or -1 if [])
1153 * word 4 stride size in bits
1155 for (i = 0; i < 7; i++)
1157 if (qualifiers[i].type == tqArray)
1159 qualifiers[i].low_bound =
1160 AUX_GET_DNLOW (bigendian, &aux_ptr[indx+2]);
1161 qualifiers[i].high_bound =
1162 AUX_GET_DNHIGH (bigendian, &aux_ptr[indx+3]);
1163 qualifiers[i].stride =
1164 AUX_GET_WIDTH (bigendian, &aux_ptr[indx+4]);
1170 * Now print out the qualifiers.
1172 for (i = 0; i < 6; i++)
1174 switch (qualifiers[i].type)
1181 strcpy (p2, "ptr to ");
1182 p2 += sizeof ("ptr to ")-1;
1186 strcpy (p2, "volatile ");
1187 p2 += sizeof ("volatile ")-1;
1191 strcpy (p2, "far ");
1192 p2 += sizeof ("far ")-1;
1196 strcpy (p2, "func. ret. ");
1197 p2 += sizeof ("func. ret. ");
1202 int first_array = i;
1205 /* Print array bounds reversed (ie, in the order the C
1206 programmer writes them). C is such a fun language.... */
1208 while (i < 5 && qualifiers[i+1].type == tqArray)
1211 for (j = i; j >= first_array; j--)
1213 strcpy (p2, "array [");
1214 p2 += sizeof ("array [")-1;
1215 if (qualifiers[j].low_bound != 0)
1217 "%ld:%ld {%ld bits}",
1218 (long) qualifiers[j].low_bound,
1219 (long) qualifiers[j].high_bound,
1220 (long) qualifiers[j].stride);
1222 else if (qualifiers[j].high_bound != -1)
1225 (long) (qualifiers[j].high_bound + 1),
1226 (long) (qualifiers[j].stride));
1229 sprintf (p2, " {%ld bits}", (long) (qualifiers[j].stride));
1232 strcpy (p2, "] of ");
1233 p2 += sizeof ("] of ")-1;
1241 strcpy (p2, buffer1);
1245 /* Print information about an ECOFF symbol. */
1248 ecoff_print_symbol (abfd, filep, symbol, how)
1252 bfd_print_symbol_type how;
1254 FILE *file = (FILE *)filep;
1258 case bfd_print_symbol_name:
1259 fprintf (file, "%s", symbol->name);
1261 case bfd_print_symbol_more:
1262 if (ecoffsymbol (symbol)->local)
1266 ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative,
1268 fprintf (file, "ecoff local %lx %x %x",
1269 (unsigned long) ecoff_sym.value,
1270 (unsigned) ecoff_sym.st, (unsigned) ecoff_sym.sc);
1276 ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative,
1278 fprintf (file, "ecoff extern %lx %x %x",
1279 (unsigned long) ecoff_ext.asym.value,
1280 (unsigned) ecoff_ext.asym.st,
1281 (unsigned) ecoff_ext.asym.sc);
1284 case bfd_print_symbol_nm:
1286 CONST char *section_name = symbol->section->name;
1288 bfd_print_symbol_vandf ((PTR) file, symbol);
1289 fprintf (file, " %-5s %s %s",
1291 ecoffsymbol (symbol)->local ? "l" : "e",
1295 case bfd_print_symbol_all:
1296 /* Print out the symbols in a reasonable way */
1305 if (ecoffsymbol (symbol)->local)
1307 ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative,
1310 pos = (ecoffsymbol (symbol)->native.lnative
1311 - ecoff_data (abfd)->external_sym
1312 + ecoff_data (abfd)->symbolic_header.iextMax);
1319 ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative,
1322 pos = (ecoffsymbol (symbol)->native.enative
1323 - ecoff_data (abfd)->external_ext);
1324 jmptbl = ecoff_ext.jmptbl ? 'j' : ' ';
1325 cobol_main = ecoff_ext.cobol_main ? 'c' : ' ';
1326 weakext = ecoff_ext.weakext ? 'w' : ' ';
1329 fprintf (file, "[%3d] %c %lx st %x sc %x indx %x %c%c%c %s",
1330 pos, type, (unsigned long) ecoff_ext.asym.value,
1331 (unsigned) ecoff_ext.asym.st,
1332 (unsigned) ecoff_ext.asym.sc,
1333 (unsigned) ecoff_ext.asym.index,
1334 jmptbl, cobol_main, weakext,
1337 if (ecoffsymbol (symbol)->fdr != NULL
1338 && ecoff_ext.asym.index != indexNil)
1343 union aux_ext *aux_base;
1345 indx = ecoff_ext.asym.index;
1347 /* sym_base is used to map the fdr relative indices which
1348 appear in the file to the position number which we are
1350 sym_base = ecoffsymbol (symbol)->fdr->isymBase;
1351 if (ecoffsymbol (symbol)->local)
1352 sym_base += ecoff_data (abfd)->symbolic_header.iextMax;
1354 /* aux_base is the start of the aux entries for this file;
1355 asym.index is an offset from this. */
1356 aux_base = (ecoff_data (abfd)->external_aux
1357 + ecoffsymbol (symbol)->fdr->iauxBase);
1359 /* The aux entries are stored in host byte order; the
1360 order is indicated by a bit in the fdr. */
1361 bigendian = ecoffsymbol (symbol)->fdr->fBigendian;
1363 /* This switch is basically from gcc/mips-tdump.c */
1364 switch (ecoff_ext.asym.st)
1372 printf ("\n End+1 symbol: %ld", indx + sym_base);
1376 if (ecoff_ext.asym.sc == scText
1377 || ecoff_ext.asym.sc == scInfo)
1378 printf ("\n First symbol: %ld", indx + sym_base);
1380 printf ("\n First symbol: %ld",
1381 (AUX_GET_ISYM (bigendian,
1382 &aux_base[ecoff_ext.asym.index])
1388 if (MIPS_IS_STAB (&ecoff_ext.asym))
1390 else if (ecoffsymbol (symbol)->local)
1391 printf ("\n End+1 symbol: %-7ld Type: %s",
1392 (AUX_GET_ISYM (bigendian,
1393 &aux_base[ecoff_ext.asym.index])
1395 ecoff_type_to_string (abfd, aux_base, indx + 1,
1398 printf ("\n Local symbol: %d",
1401 + ecoff_data (abfd)->symbolic_header.iextMax));
1405 if (!MIPS_IS_STAB (&ecoff_ext.asym))
1406 printf ("\n Type: %s",
1407 ecoff_type_to_string (abfd, aux_base, indx,
1417 /* Reloc handling. MIPS ECOFF relocs are packed into 8 bytes in
1418 external form. They use a bit which indicates whether the symbol
1421 /* Swap a reloc in. */
1424 ecoff_swap_reloc_in (abfd, ext, intern)
1427 struct internal_reloc *intern;
1429 intern->r_vaddr = bfd_h_get_32 (abfd, (bfd_byte *) ext->r_vaddr);
1430 if (abfd->xvec->header_byteorder_big_p != false)
1432 intern->r_symndx = (((int) ext->r_bits[0]
1433 << RELOC_BITS0_SYMNDX_SH_LEFT_BIG)
1434 | ((int) ext->r_bits[1]
1435 << RELOC_BITS1_SYMNDX_SH_LEFT_BIG)
1436 | ((int) ext->r_bits[2]
1437 << RELOC_BITS2_SYMNDX_SH_LEFT_BIG));
1438 intern->r_type = ((ext->r_bits[3] & RELOC_BITS3_TYPE_BIG)
1439 >> RELOC_BITS3_TYPE_SH_BIG);
1440 intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_BIG) != 0;
1444 intern->r_symndx = (((int) ext->r_bits[0]
1445 << RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE)
1446 | ((int) ext->r_bits[1]
1447 << RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE)
1448 | ((int) ext->r_bits[2]
1449 << RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE));
1450 intern->r_type = ((ext->r_bits[3] & RELOC_BITS3_TYPE_LITTLE)
1451 >> RELOC_BITS3_TYPE_SH_LITTLE);
1452 intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_LITTLE) != 0;
1456 /* Swap a reloc out. */
1459 ecoff_swap_reloc_out (abfd, src, dst)
1464 struct internal_reloc *intern = (struct internal_reloc *) src;
1465 RELOC *ext = (RELOC *) dst;
1467 bfd_h_put_32 (abfd, intern->r_vaddr, (bfd_byte *) ext->r_vaddr);
1468 if (abfd->xvec->header_byteorder_big_p != false)
1470 ext->r_bits[0] = intern->r_symndx >> RELOC_BITS0_SYMNDX_SH_LEFT_BIG;
1471 ext->r_bits[1] = intern->r_symndx >> RELOC_BITS1_SYMNDX_SH_LEFT_BIG;
1472 ext->r_bits[2] = intern->r_symndx >> RELOC_BITS2_SYMNDX_SH_LEFT_BIG;
1473 ext->r_bits[3] = (((intern->r_type << RELOC_BITS3_TYPE_SH_BIG)
1474 & RELOC_BITS3_TYPE_BIG)
1475 | (intern->r_extern ? RELOC_BITS3_EXTERN_BIG : 0));
1479 ext->r_bits[0] = intern->r_symndx >> RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE;
1480 ext->r_bits[1] = intern->r_symndx >> RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE;
1481 ext->r_bits[2] = intern->r_symndx >> RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE;
1482 ext->r_bits[3] = (((intern->r_type << RELOC_BITS3_TYPE_SH_LITTLE)
1483 & RELOC_BITS3_TYPE_LITTLE)
1484 | (intern->r_extern ? RELOC_BITS3_EXTERN_LITTLE : 0));
1490 /* ECOFF relocs are either against external symbols, or against
1491 sections. If we are producing relocateable output, and the reloc
1492 is against an external symbol, the resulting reloc will also be
1493 against the same symbol. In such a case, we don't want to change
1494 anything about the way the reloc is handled, since it will all be
1495 done at final link time. Rather than put special case code into
1496 bfd_perform_relocation, all the reloc types use this howto
1497 function. It just short circuits the reloc if producing
1498 relocateable output against an external symbol. */
1500 static bfd_reloc_status_type
1501 ecoff_generic_reloc (abfd,
1508 arelent *reloc_entry;
1511 asection *input_section;
1514 if (output_bfd != (bfd *) NULL
1515 && (symbol->flags & BSF_SECTION_SYM) == 0)
1517 reloc_entry->address += input_section->output_offset;
1518 return bfd_reloc_ok;
1521 return bfd_reloc_continue;
1524 /* Do a REFHI relocation. The next reloc must be the corresponding
1525 REFLO. This has to be done in a function so that carry is handled
1528 static bfd_reloc_status_type
1529 ecoff_refhi_reloc (abfd,
1536 arelent *reloc_entry;
1539 asection *input_section;
1542 bfd_reloc_status_type ret;
1547 unsigned long vallo;
1549 /* If we're relocating, and this an external symbol, we don't want
1550 to change anything. */
1551 if (output_bfd != (bfd *) NULL
1552 && (symbol->flags & BSF_SECTION_SYM) == 0)
1554 reloc_entry->address += input_section->output_offset;
1555 return bfd_reloc_ok;
1559 if (symbol->section == &bfd_und_section
1560 && output_bfd == (bfd *) NULL)
1561 ret = bfd_reloc_undefined;
1563 rello = reloc_entry + 1;
1564 BFD_ASSERT (rello->howto->type == ECOFF_R_REFLO
1565 && *rello->sym_ptr_ptr == *reloc_entry->sym_ptr_ptr);
1567 if (bfd_is_com_section (symbol->section))
1570 relocation = symbol->value;
1572 relocation += symbol->section->output_section->vma;
1573 relocation += symbol->section->output_offset;
1574 relocation += reloc_entry->addend;
1576 if (reloc_entry->address > input_section->_cooked_size)
1577 return bfd_reloc_outofrange;
1579 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1580 vallo = bfd_get_32 (abfd, (bfd_byte *) data + rello->address) & 0xffff;
1581 val = ((insn & 0xffff) << 16) + vallo;
1584 /* The low order 16 bits are always treated as a signed value.
1585 Therefore, a negative value in the low order bits requires an
1586 adjustment in the high order bits. We need to make this
1587 adjustment in two ways: once for the bits we took from the data,
1588 and once for the bits we are putting back in to the data. */
1589 if ((vallo & 0x8000) != 0)
1591 if ((val & 0x8000) != 0)
1594 insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
1595 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
1597 if (output_bfd != (bfd *) NULL)
1598 reloc_entry->address += input_section->output_offset;
1603 /* Do a GPREL relocation. This is a 16 bit value which must become
1604 the offset from the gp register. */
1606 static bfd_reloc_status_type
1607 ecoff_gprel_reloc (abfd,
1614 arelent *reloc_entry;
1617 asection *input_section;
1620 boolean relocateable;
1625 /* If we're relocating, and this an external symbol, we don't want
1626 to change anything. */
1627 if (output_bfd != (bfd *) NULL
1628 && (symbol->flags & BSF_SECTION_SYM) == 0)
1630 reloc_entry->address += input_section->output_offset;
1631 return bfd_reloc_ok;
1634 if (output_bfd != (bfd *) NULL)
1635 relocateable = true;
1638 relocateable = false;
1639 output_bfd = symbol->section->output_section->owner;
1642 if (symbol->section == &bfd_und_section
1643 && relocateable == false)
1644 return bfd_reloc_undefined;
1646 /* We have to figure out the gp value, so that we can adjust the
1647 symbol value correctly. We look up the symbol _gp in the output
1648 BFD. If we can't find it, we're stuck. We cache it in the ECOFF
1650 if (ecoff_data (output_bfd)->gp == 0)
1652 if (relocateable != false)
1654 /* Make up a value. */
1655 ecoff_data (output_bfd)->gp =
1656 symbol->section->output_section->vma + 0x4000;
1664 count = bfd_get_symcount (output_bfd);
1665 sym = bfd_get_outsymbols (output_bfd);
1667 /* We should do something more friendly here, but we don't
1668 have a good reloc status to return. */
1669 if (sym == (asymbol **) NULL)
1672 for (i = 0; i < count; i++, sym++)
1674 register CONST char *name;
1676 name = bfd_asymbol_name (*sym);
1677 if (*name == '_' && strcmp (name, "_gp") == 0)
1679 ecoff_data (output_bfd)->gp = bfd_asymbol_value (*sym);
1684 /* We should do something more friendly here, but we don't have
1685 a good reloc status to return. */
1691 if (bfd_is_com_section (symbol->section))
1694 relocation = symbol->value;
1696 relocation += symbol->section->output_section->vma;
1697 relocation += symbol->section->output_offset;
1699 if (reloc_entry->address > input_section->_cooked_size)
1700 return bfd_reloc_outofrange;
1702 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1704 /* Set val to the offset into the section (if we are relocating
1705 against an external symbol, insn & 0xffff will be zero and so
1706 will reloc_entry->addend). */
1707 val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff;
1711 /* Adjust val for the final section location and GP value. */
1712 val += (relocation - ecoff_data (output_bfd)->gp);
1714 insn = (insn &~ 0xffff) | (val & 0xffff);
1715 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
1717 if (relocateable != false)
1718 reloc_entry->address += input_section->output_offset;
1720 /* Make sure it fit in 16 bits. */
1721 if (val >= 0x8000 && val < 0xffff8000)
1722 return bfd_reloc_outofrange;
1724 return bfd_reloc_ok;
1727 /* How to process the various relocs types. */
1729 static reloc_howto_type ecoff_howto_table[] =
1731 /* Reloc type 0 is ignored. The reloc reading code ensures that
1732 this is a reference to the .abs section, which will cause
1733 bfd_perform_relocation to do nothing. */
1734 HOWTO (ECOFF_R_IGNORE, /* type */
1736 0, /* size (0 = byte, 1 = short, 2 = long) */
1737 8, /* bitsize (obsolete) */
1738 false, /* pc_relative */
1740 false, /* absolute (obsolete) */
1741 false, /* complain_on_overflow */
1742 0, /* special_function */
1743 "IGNORE", /* name */
1744 false, /* partial_inplace */
1747 false), /* pcrel_offset */
1749 /* A 16 bit reference to a symbol, normally from a data section. */
1750 HOWTO (ECOFF_R_REFHALF, /* type */
1752 1, /* size (0 = byte, 1 = short, 2 = long) */
1753 16, /* bitsize (obsolete) */
1754 false, /* pc_relative */
1756 false, /* absolute (obsolete) */
1757 true, /* complain_on_overflow */
1758 ecoff_generic_reloc, /* special_function */
1759 "REFHALF", /* name */
1760 true, /* partial_inplace */
1761 0xffff, /* src_mask */
1762 0xffff, /* dst_mask */
1763 false), /* pcrel_offset */
1765 /* A 32 bit reference to a symbol, normally from a data section. */
1766 HOWTO (ECOFF_R_REFWORD, /* type */
1768 2, /* size (0 = byte, 1 = short, 2 = long) */
1769 32, /* bitsize (obsolete) */
1770 false, /* pc_relative */
1772 false, /* absolute (obsolete) */
1773 true, /* complain_on_overflow */
1774 ecoff_generic_reloc, /* special_function */
1775 "REFWORD", /* name */
1776 true, /* partial_inplace */
1777 0xffffffff, /* src_mask */
1778 0xffffffff, /* dst_mask */
1779 false), /* pcrel_offset */
1781 /* A 26 bit absolute jump address. */
1782 HOWTO (ECOFF_R_JMPADDR, /* type */
1784 2, /* size (0 = byte, 1 = short, 2 = long) */
1785 32, /* bitsize (obsolete) */
1786 false, /* pc_relative */
1788 false, /* absolute (obsolete) */
1789 true, /* complain_on_overflow */
1790 ecoff_generic_reloc, /* special_function */
1791 "JMPADDR", /* name */
1792 true, /* partial_inplace */
1793 0x3ffffff, /* src_mask */
1794 0x3ffffff, /* dst_mask */
1795 false), /* pcrel_offset */
1797 /* The high 16 bits of a symbol value. Handled by the function
1798 ecoff_refhi_reloc. */
1799 HOWTO (ECOFF_R_REFHI, /* type */
1800 16, /* rightshift */
1801 2, /* size (0 = byte, 1 = short, 2 = long) */
1802 32, /* bitsize (obsolete) */
1803 false, /* pc_relative */
1805 false, /* absolute (obsolete) */
1806 true, /* complain_on_overflow */
1807 ecoff_refhi_reloc, /* special_function */
1809 true, /* partial_inplace */
1810 0xffff, /* src_mask */
1811 0xffff, /* dst_mask */
1812 false), /* pcrel_offset */
1814 /* The low 16 bits of a symbol value. */
1815 HOWTO (ECOFF_R_REFLO, /* type */
1817 2, /* size (0 = byte, 1 = short, 2 = long) */
1818 32, /* bitsize (obsolete) */
1819 false, /* pc_relative */
1821 false, /* absolute (obsolete) */
1822 true, /* complain_on_overflow */
1823 ecoff_generic_reloc, /* special_function */
1825 true, /* partial_inplace */
1826 0xffff, /* src_mask */
1827 0xffff, /* dst_mask */
1828 false), /* pcrel_offset */
1830 /* A reference to an offset from the gp register. Handled by the
1831 function ecoff_gprel_reloc. */
1832 HOWTO (ECOFF_R_GPREL, /* type */
1834 2, /* size (0 = byte, 1 = short, 2 = long) */
1835 32, /* bitsize (obsolete) */
1836 false, /* pc_relative */
1838 false, /* absolute (obsolete) */
1839 true, /* complain_on_overflow */
1840 ecoff_gprel_reloc, /* special_function */
1842 true, /* partial_inplace */
1843 0xffff, /* src_mask */
1844 0xffff, /* dst_mask */
1845 false), /* pcrel_offset */
1847 /* A reference to a literal using an offset from the gp register.
1848 Handled by the function ecoff_gprel_reloc. */
1849 HOWTO (ECOFF_R_LITERAL, /* type */
1851 2, /* size (0 = byte, 1 = short, 2 = long) */
1852 32, /* bitsize (obsolete) */
1853 false, /* pc_relative */
1855 false, /* absolute (obsolete) */
1856 true, /* complain_on_overflow */
1857 ecoff_gprel_reloc, /* special_function */
1858 "LITERAL", /* name */
1859 true, /* partial_inplace */
1860 0xffff, /* src_mask */
1861 0xffff, /* dst_mask */
1862 false) /* pcrel_offset */
1865 /* Read in the relocs for a section. */
1868 ecoff_slurp_reloc_table (abfd, section, symbols)
1873 RELOC *external_relocs;
1874 arelent *internal_relocs;
1878 if (section->relocation != (arelent *) NULL
1879 || section->reloc_count == 0
1880 || (section->flags & SEC_CONSTRUCTOR) != 0)
1883 if (ecoff_slurp_symbol_table (abfd) == false)
1886 internal_relocs = (arelent *) bfd_alloc (abfd,
1888 * section->reloc_count));
1889 external_relocs = (RELOC *) bfd_alloc (abfd, RELSZ * section->reloc_count);
1890 if (internal_relocs == (arelent *) NULL
1891 || external_relocs == (RELOC *) NULL)
1893 bfd_error = no_memory;
1896 if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0)
1898 if (bfd_read (external_relocs, 1, RELSZ * section->reloc_count, abfd)
1899 != RELSZ * section->reloc_count)
1901 bfd_error = system_call_error;
1905 for (i = 0, rptr = internal_relocs; i < section->reloc_count; i++, rptr++)
1907 struct internal_reloc intern;
1909 ecoff_swap_reloc_in (abfd, external_relocs + i, &intern);
1911 if (intern.r_type > ECOFF_R_LITERAL)
1914 if (intern.r_extern)
1916 /* r_symndx is an index into the external symbols. */
1917 BFD_ASSERT (intern.r_symndx >= 0
1919 < ecoff_data (abfd)->symbolic_header.iextMax));
1920 rptr->sym_ptr_ptr = symbols + intern.r_symndx;
1925 CONST char *sec_name;
1928 /* r_symndx is a section key. */
1929 switch (intern.r_symndx)
1931 case RELOC_SECTION_TEXT: sec_name = ".text"; break;
1932 case RELOC_SECTION_RDATA: sec_name = ".rdata"; break;
1933 case RELOC_SECTION_DATA: sec_name = ".data"; break;
1934 case RELOC_SECTION_SDATA: sec_name = ".sdata"; break;
1935 case RELOC_SECTION_SBSS: sec_name = ".sbss"; break;
1936 case RELOC_SECTION_BSS: sec_name = ".bss"; break;
1937 case RELOC_SECTION_INIT: sec_name = ".init"; break;
1938 case RELOC_SECTION_LIT8: sec_name = ".lit8"; break;
1939 case RELOC_SECTION_LIT4: sec_name = ".lit4"; break;
1943 sec = bfd_get_section_by_name (abfd, sec_name);
1944 if (sec == (asection *) NULL)
1946 rptr->sym_ptr_ptr = sec->symbol_ptr_ptr;
1948 rptr->addend = - bfd_get_section_vma (abfd, sec);
1949 if (intern.r_type == ECOFF_R_GPREL
1950 || intern.r_type == ECOFF_R_LITERAL)
1951 rptr->addend += ecoff_data (abfd)->gp;
1954 rptr->address = intern.r_vaddr - bfd_get_section_vma (abfd, section);
1955 rptr->howto = &ecoff_howto_table[intern.r_type];
1957 /* If the type is ECOFF_R_IGNORE, make sure this is a reference
1958 to the absolute section so that the reloc is ignored. */
1959 if (intern.r_type == ECOFF_R_IGNORE)
1960 rptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
1963 bfd_release (abfd, external_relocs);
1965 section->relocation = internal_relocs;
1970 /* Get a canonical list of relocs. */
1973 ecoff_canonicalize_reloc (abfd, section, relptr, symbols)
1981 if (section->flags & SEC_CONSTRUCTOR)
1983 arelent_chain *chain;
1985 /* This section has relocs made up by us, not the file, so take
1986 them out of their chain and place them into the data area
1988 for (count = 0, chain = section->constructor_chain;
1989 count < section->reloc_count;
1990 count++, chain = chain->next)
1991 *relptr++ = &chain->relent;
1997 if (ecoff_slurp_reloc_table (abfd, section, symbols) == false)
2000 tblptr = section->relocation;
2001 if (tblptr == (arelent *) NULL)
2004 for (count = 0; count < section->reloc_count; count++)
2005 *relptr++ = tblptr++;
2008 *relptr = (arelent *) NULL;
2010 return section->reloc_count;
2013 /* Provided a BFD, a section and an offset into the section, calculate
2014 and return the name of the source file and the line nearest to the
2018 ecoff_find_nearest_line (abfd,
2027 asymbol **ignore_symbols;
2029 CONST char **filename_ptr;
2030 CONST char **functionname_ptr;
2031 unsigned int *retline_ptr;
2037 struct pdr_ext *pdr_ptr;
2038 struct pdr_ext *pdr_end;
2040 unsigned char *line_ptr;
2041 unsigned char *line_end;
2044 /* If we're not in the .text section, we don't have any line
2046 if (strcmp (section->name, _TEXT) != 0
2047 || offset < ecoff_data (abfd)->text_start
2048 || offset >= ecoff_data (abfd)->text_end)
2051 /* Make sure we have the FDR's. */
2052 if (ecoff_slurp_symbolic_info (abfd) == false
2053 || bfd_get_symcount (abfd) == 0)
2056 /* Each file descriptor (FDR) has a memory address. Here we track
2057 down which FDR we want. The FDR's are stored in increasing
2058 memory order. If speed is ever important, this can become a
2059 binary search. We must ignore FDR's with no PDR entries; they
2060 will have the adr of the FDR before or after them. */
2061 fdr_start = ecoff_data (abfd)->fdr;
2062 fdr_end = fdr_start + ecoff_data (abfd)->symbolic_header.ifdMax;
2063 fdr_hold = (FDR *) NULL;
2064 for (fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
2066 if (fdr_ptr->cpd == 0)
2068 if (offset < fdr_ptr->adr)
2072 if (fdr_hold == (FDR *) NULL)
2076 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2077 have an address, which is relative to the FDR address, and are
2078 also stored in increasing memory order. */
2079 offset -= fdr_ptr->adr;
2080 pdr_ptr = ecoff_data (abfd)->external_pdr + fdr_ptr->ipdFirst;
2081 pdr_end = pdr_ptr + fdr_ptr->cpd;
2082 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
2083 if (offset < pdr.adr)
2085 for (pdr_ptr++; pdr_ptr < pdr_end; pdr_ptr++)
2087 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
2088 if (offset < pdr.adr)
2092 /* Now we can look for the actual line number. The line numbers are
2093 stored in a very funky format, which I won't try to describe.
2094 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2095 we want; we need this to compute line_end. */
2096 line_end = ecoff_data (abfd)->line;
2097 if (pdr_ptr == pdr_end)
2098 line_end += fdr_ptr->cbLineOffset + fdr_ptr->cbLine;
2100 line_end += fdr_ptr->cbLineOffset + pdr.cbLineOffset;
2102 /* Now change pdr and pdr_ptr to the one we want. */
2104 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
2108 line_ptr = (ecoff_data (abfd)->line
2109 + fdr_ptr->cbLineOffset
2110 + pdr.cbLineOffset);
2111 while (line_ptr < line_end)
2116 delta = *line_ptr >> 4;
2119 count = (*line_ptr & 0xf) + 1;
2123 delta = (((line_ptr[0]) & 0xff) << 8) + ((line_ptr[1]) & 0xff);
2124 if (delta >= 0x8000)
2129 if (offset < count * 4)
2131 offset -= count * 4;
2134 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2135 at least according to gdb/mipsread.c. */
2136 if (fdr_ptr->rss == -1)
2138 *filename_ptr = NULL;
2140 *functionname_ptr = NULL;
2145 ecoff_swap_ext_in (abfd,
2146 (ecoff_data (abfd)->external_ext
2149 *functionname_ptr = ecoff_data (abfd)->ssext + proc_ext.asym.iss;
2156 *filename_ptr = ecoff_data (abfd)->ss + fdr_ptr->issBase + fdr_ptr->rss;
2157 ecoff_swap_sym_in (abfd,
2158 (ecoff_data (abfd)->external_sym
2162 *functionname_ptr = (ecoff_data (abfd)->ss
2166 *retline_ptr = lineno;
2170 /* We can't use the generic linking routines for ECOFF, because we
2171 have to handle all the debugging information. The generic link
2172 routine just works out the section contents and attaches a list of
2175 We link by looping over all the seclets. We make two passes. On
2176 the first we set the actual section contents and determine the size
2177 of the debugging information. On the second we accumulate the
2178 debugging information and write it out.
2180 This currently always accumulates the debugging information, which
2181 is incorrect, because it ignores the -s and -S options of the
2182 linker. The linker needs to be modified to give us that
2183 information in a more useful format (currently it just provides a
2184 list of symbols which should appear in the output file). */
2186 /* Clear the output_has_begun flag for all the input BFD's. We use it
2187 to avoid linking in the debugging information for a BFD more than
2191 ecoff_clear_output_flags (abfd)
2194 register asection *o;
2195 register bfd_seclet_type *p;
2197 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2198 for (p = o->seclets_head;
2199 p != (bfd_seclet_type *) NULL;
2201 if (p->type == bfd_indirect_seclet)
2202 p->u.indirect.section->owner->output_has_begun = false;
2205 /* Handle an indirect seclet on the first pass. Set the contents of
2206 the output section, and accumulate the debugging information if
2210 ecoff_rel (output_bfd, seclet, output_section, data, relocateable)
2212 bfd_seclet_type *seclet;
2213 asection *output_section;
2215 boolean relocateable;
2218 HDRR *output_symhdr;
2221 if ((output_section->flags & SEC_HAS_CONTENTS)
2222 && !(output_section->flags & SEC_NEVER_LOAD)
2223 && (output_section->flags & SEC_LOAD)
2226 data = (PTR) bfd_get_relocated_section_contents (output_bfd,
2230 if (bfd_set_section_contents (output_bfd,
2241 input_bfd = seclet->u.indirect.section->owner;
2243 /* We want to figure out how much space will be required to
2244 incorporate all the debugging information from input_bfd. We use
2245 the output_has_begun field to avoid adding it in more than once.
2246 The actual incorporation is done in the second pass, in
2247 ecoff_get_debug. The code has to parallel that code in its
2248 manipulations of output_symhdr. */
2250 if (input_bfd->output_has_begun)
2252 input_bfd->output_has_begun = true;
2254 output_symhdr = &ecoff_data (output_bfd)->symbolic_header;
2256 if (input_bfd->xvec->flavour != bfd_target_ecoff_flavour)
2262 /* We just accumulate local symbols from a non-ECOFF BFD. The
2263 external symbols are handled separately. */
2265 symbols = (asymbol **) bfd_alloc (output_bfd,
2266 get_symtab_upper_bound (input_bfd));
2267 if (symbols == (asymbol **) NULL)
2269 bfd_error = no_memory;
2272 sym_end = symbols + bfd_canonicalize_symtab (input_bfd, symbols);
2274 for (sym_ptr = symbols; sym_ptr < sym_end; sym_ptr++)
2278 len = strlen ((*sym_ptr)->name);
2279 if (((*sym_ptr)->flags & BSF_EXPORT) == 0)
2281 ++output_symhdr->isymMax;
2282 output_symhdr->issMax += len + 1;
2286 bfd_release (output_bfd, (PTR) symbols);
2288 ++output_symhdr->ifdMax;
2293 /* We simply add in the information from another ECOFF BFD. First
2294 we make sure we have the symbolic information. */
2295 if (ecoff_slurp_symbol_table (input_bfd) == false)
2297 if (bfd_get_symcount (input_bfd) == 0)
2300 input_symhdr = &ecoff_data (input_bfd)->symbolic_header;
2302 /* Figure out how much information we are going to be putting in.
2303 The external symbols are handled separately. */
2304 output_symhdr->ilineMax += input_symhdr->ilineMax;
2305 output_symhdr->cbLine += input_symhdr->cbLine;
2306 output_symhdr->idnMax += input_symhdr->idnMax;
2307 output_symhdr->ipdMax += input_symhdr->ipdMax;
2308 output_symhdr->isymMax += input_symhdr->isymMax;
2309 output_symhdr->ioptMax += input_symhdr->ioptMax;
2310 output_symhdr->iauxMax += input_symhdr->iauxMax;
2311 output_symhdr->issMax += input_symhdr->issMax;
2312 output_symhdr->ifdMax += input_symhdr->ifdMax;
2314 /* The RFD's are special, since we create them if needed. */
2315 if (input_symhdr->crfd > 0)
2316 output_symhdr->crfd += input_symhdr->crfd;
2318 output_symhdr->crfd += input_symhdr->ifdMax;
2323 /* Handle an arbitrary seclet on the first pass. */
2326 ecoff_dump_seclet (abfd, seclet, section, data, relocateable)
2328 bfd_seclet_type *seclet;
2331 boolean relocateable;
2333 switch (seclet->type)
2335 case bfd_indirect_seclet:
2336 /* The contents of this section come from another one somewhere
2338 return ecoff_rel (abfd, seclet, section, data, relocateable);
2340 case bfd_fill_seclet:
2341 /* Fill in the section with fill.value. This is used to pad out
2342 sections, but we must avoid padding the .bss section. */
2343 if ((section->flags & SEC_HAS_CONTENTS) == 0)
2345 if (seclet->u.fill.value != 0)
2350 char *d = (char *) bfd_alloc (abfd, seclet->size);
2354 for (i = 0; i < seclet->size; i+=2)
2355 d[i] = seclet->u.fill.value >> 8;
2356 for (i = 1; i < seclet->size; i+=2)
2357 d[i] = seclet->u.fill.value;
2358 ret = bfd_set_section_contents (abfd, section, d, seclet->offset,
2360 bfd_release (abfd, (PTR) d);
2372 /* Add a string to the debugging information we are accumulating for a
2373 file. Return the offset from the fdr string base or from the
2374 external string base. */
2377 ecoff_add_string (output_bfd, fdr, string, external)
2387 symhdr = &ecoff_data (output_bfd)->symbolic_header;
2388 len = strlen (string);
2391 strcpy (ecoff_data (output_bfd)->ssext + symhdr->issExtMax, string);
2392 ret = symhdr->issExtMax;
2393 symhdr->issExtMax += len + 1;
2397 strcpy (ecoff_data (output_bfd)->ss + symhdr->issMax, string);
2399 symhdr->issMax += len + 1;
2400 fdr->cbSs += len + 1;
2405 /* Accumulate the debugging information from an input section. */
2408 ecoff_get_debug (output_bfd, seclet, section, relocateable)
2410 bfd_seclet_type *seclet;
2412 boolean relocateable;
2415 HDRR *output_symhdr;
2417 ecoff_data_type *output_ecoff;
2418 ecoff_data_type *input_ecoff;
2420 struct sym_ext *sym_out;
2421 ecoff_symbol_type *esym_ptr;
2422 ecoff_symbol_type *esym_end;
2423 unsigned long pdr_off;
2426 struct fdr_ext *fdr_out;
2428 input_bfd = seclet->u.indirect.section->owner;
2430 /* Don't get the information more than once. */
2431 if (input_bfd->output_has_begun)
2433 input_bfd->output_has_begun = true;
2435 output_ecoff = ecoff_data (output_bfd);
2436 output_symhdr = &output_ecoff->symbolic_header;
2438 if (input_bfd->xvec->flavour != bfd_target_ecoff_flavour)
2445 /* This is not an ECOFF BFD. Just gather the symbols. */
2447 memset (&fdr, 0, sizeof fdr);
2449 fdr.adr = bfd_get_section_vma (output_bfd, section) + seclet->offset;
2450 fdr.issBase = output_symhdr->issMax;
2452 fdr.rss = ecoff_add_string (output_bfd,
2454 bfd_get_filename (input_bfd),
2456 fdr.isymBase = output_symhdr->isymMax;
2458 /* Get the local symbols from the input BFD. */
2459 symbols = (asymbol **) bfd_alloc (output_bfd,
2460 get_symtab_upper_bound (input_bfd));
2461 if (symbols == (asymbol **) NULL)
2463 bfd_error = no_memory;
2466 sym_end = symbols + bfd_canonicalize_symtab (input_bfd, symbols);
2468 /* Handle the local symbols. Any external symbols are handled
2471 for (sym_ptr = symbols; sym_ptr != sym_end; sym_ptr++)
2475 if (((*sym_ptr)->flags & BSF_EXPORT) != 0)
2477 memset (&internal_sym, 0, sizeof internal_sym);
2478 internal_sym.iss = ecoff_add_string (output_bfd,
2483 if (bfd_is_com_section ((*sym_ptr)->section)
2484 || (*sym_ptr)->section == &bfd_und_section)
2485 internal_sym.value = (*sym_ptr)->value;
2487 internal_sym.value = ((*sym_ptr)->value
2488 + (*sym_ptr)->section->output_offset
2489 + (*sym_ptr)->section->output_section->vma);
2490 internal_sym.st = stNil;
2491 internal_sym.sc = scUndefined;
2492 internal_sym.index = indexNil;
2493 ecoff_swap_sym_out (output_bfd, &internal_sym,
2494 (output_ecoff->external_sym
2495 + output_symhdr->isymMax));
2497 ++output_symhdr->isymMax;
2500 bfd_release (output_bfd, (PTR) symbols);
2502 /* Leave everything else in the FDR zeroed out. This will cause
2503 the lang field to be langC. The fBigendian field will
2504 indicate little endian format, but it doesn't matter because
2505 it only applies to aux fields and there are none. */
2507 ecoff_swap_fdr_out (output_bfd, &fdr,
2508 (output_ecoff->external_fdr
2509 + output_symhdr->ifdMax));
2510 ++output_symhdr->ifdMax;
2514 /* This is an ECOFF BFD. We want to grab the information from
2515 input_bfd and attach it to output_bfd. */
2516 count = bfd_get_symcount (input_bfd);
2519 input_ecoff = ecoff_data (input_bfd);
2520 input_symhdr = &input_ecoff->symbolic_header;
2522 /* I think that it is more efficient to simply copy the debugging
2523 information from the input BFD to the output BFD. Because ECOFF
2524 uses relative pointers for most of the debugging information,
2525 only a little of it has to be changed at all. */
2527 /* Swap in the local symbols, adjust their values, and swap them out
2528 again. The external symbols are handled separately. */
2529 sym_out = output_ecoff->external_sym + output_symhdr->isymMax;
2531 esym_ptr = ecoff_data (input_bfd)->canonical_symbols;
2532 esym_end = esym_ptr + count;
2533 for (; esym_ptr < esym_end; esym_ptr++)
2535 if (esym_ptr->local)
2539 ecoff_swap_sym_in (input_bfd, esym_ptr->native.lnative, &sym);
2541 /* If we're producing an executable, move common symbols
2543 if (relocateable == false)
2545 if (sym.sc == scCommon)
2547 else if (sym.sc == scSCommon)
2551 if (! bfd_is_com_section (esym_ptr->symbol.section)
2552 && (esym_ptr->symbol.flags & BSF_DEBUGGING) == 0
2553 && esym_ptr->symbol.section != &bfd_und_section)
2554 sym.value = (esym_ptr->symbol.value
2555 + esym_ptr->symbol.section->output_offset
2556 + esym_ptr->symbol.section->output_section->vma);
2557 ecoff_swap_sym_out (output_bfd, &sym, sym_out);
2562 /* That should have accounted for all the local symbols in
2564 BFD_ASSERT ((sym_out - output_ecoff->external_sym) - output_symhdr->isymMax
2565 == input_symhdr->isymMax);
2567 /* Copy the information that does not need swapping. */
2568 memcpy (output_ecoff->line + output_symhdr->cbLine,
2570 input_symhdr->cbLine * sizeof (unsigned char));
2571 memcpy (output_ecoff->external_aux + output_symhdr->iauxMax,
2572 input_ecoff->external_aux,
2573 input_symhdr->iauxMax * sizeof (union aux_ext));
2574 memcpy (output_ecoff->ss + output_symhdr->issMax,
2576 input_symhdr->issMax * sizeof (char));
2578 /* Some of the information may need to be swapped. */
2579 if (output_bfd->xvec->header_byteorder_big_p
2580 == input_bfd->xvec->header_byteorder_big_p)
2582 /* The two BFD's have the same endianness, so memcpy will
2584 memcpy (output_ecoff->external_dnr + output_symhdr->idnMax,
2585 input_ecoff->external_dnr,
2586 input_symhdr->idnMax * sizeof (struct dnr_ext));
2587 memcpy (output_ecoff->external_pdr + output_symhdr->ipdMax,
2588 input_ecoff->external_pdr,
2589 input_symhdr->ipdMax * sizeof (struct pdr_ext));
2590 if (input_symhdr->ipdMax == 0)
2596 ecoff_swap_pdr_in (input_bfd, input_ecoff->external_pdr, &pdr);
2599 memcpy (output_ecoff->external_opt + output_symhdr->ioptMax,
2600 input_ecoff->external_opt,
2601 input_symhdr->ioptMax * sizeof (struct opt_ext));
2605 struct dnr_ext *dnr_in;
2606 struct dnr_ext *dnr_end;
2607 struct dnr_ext *dnr_out;
2608 struct pdr_ext *pdr_in;
2609 struct pdr_ext *pdr_end;
2610 struct pdr_ext *pdr_out;
2612 struct opt_ext *opt_in;
2613 struct opt_ext *opt_end;
2614 struct opt_ext *opt_out;
2616 /* The two BFD's have different endianness, so we must swap
2617 everything in and out. This code would always work, but it
2618 would be slow in the normal case. */
2619 dnr_in = input_ecoff->external_dnr;
2620 dnr_end = dnr_in + input_symhdr->idnMax;
2621 dnr_out = output_ecoff->external_dnr + output_symhdr->idnMax;
2622 for (; dnr_in < dnr_end; dnr_in++, dnr_out++)
2626 ecoff_swap_dnr_in (input_bfd, dnr_in, &dnr);
2627 ecoff_swap_dnr_out (output_bfd, &dnr, dnr_out);
2629 pdr_in = input_ecoff->external_pdr;
2630 pdr_end = pdr_in + input_symhdr->ipdMax;
2631 pdr_out = output_ecoff->external_pdr + output_symhdr->ipdMax;
2634 for (; pdr_in < pdr_end; pdr_in++, pdr_out++)
2638 ecoff_swap_pdr_in (input_bfd, pdr_in, &pdr);
2639 ecoff_swap_pdr_out (output_bfd, &pdr, pdr_out);
2646 opt_in = input_ecoff->external_opt;
2647 opt_end = opt_in + input_symhdr->ioptMax;
2648 opt_out = output_ecoff->external_opt + output_symhdr->ioptMax;
2649 for (; opt_in < opt_end; opt_in++, opt_out++)
2653 ecoff_swap_opt_in (input_bfd, opt_in, &opt);
2654 ecoff_swap_opt_out (output_bfd, &opt, opt_out);
2658 /* Set ifdbase so that the external symbols know how to adjust their
2660 input_ecoff->ifdbase = output_symhdr->ifdMax;
2662 fdr_ptr = input_ecoff->fdr;
2663 fdr_end = fdr_ptr + input_symhdr->ifdMax;
2664 fdr_out = output_ecoff->external_fdr + output_symhdr->ifdMax;
2665 for (; fdr_ptr < fdr_end; fdr_ptr++, fdr_out++)
2671 /* The memory address for this fdr is the address for the seclet
2672 plus the offset to this fdr within input_bfd. For some
2673 reason the offset of the first procedure pointer is also
2675 fdr.adr = (bfd_get_section_vma (output_bfd, section)
2677 + (fdr_ptr->adr - input_ecoff->fdr->adr)
2680 fdr.issBase += output_symhdr->issMax;
2681 fdr.isymBase += output_symhdr->isymMax;
2682 fdr.ilineBase += output_symhdr->ilineMax;
2683 fdr.ioptBase += output_symhdr->ioptMax;
2684 fdr.ipdFirst += output_symhdr->ipdMax;
2685 fdr.iauxBase += output_symhdr->iauxMax;
2686 fdr.rfdBase += output_symhdr->crfd;
2688 /* If there are no RFD's, we are going to add some. We don't
2689 want to adjust irfd for this, so that all the FDR's can share
2691 if (input_symhdr->crfd == 0)
2692 fdr.crfd = input_symhdr->ifdMax;
2694 if (fdr.cbLine != 0)
2695 fdr.cbLineOffset += output_symhdr->cbLine;
2697 ecoff_swap_fdr_out (output_bfd, &fdr, fdr_out);
2700 if (input_symhdr->crfd > 0)
2702 struct rfd_ext *rfd_in;
2703 struct rfd_ext *rfd_end;
2704 struct rfd_ext *rfd_out;
2706 /* Swap and adjust the RFD's. RFD's are only created by the
2707 linker, so this will only be necessary if one of the input
2708 files is the result of a partial link. Presumably all
2709 necessary RFD's are present. */
2710 rfd_in = input_ecoff->external_rfd;
2711 rfd_end = rfd_in + input_symhdr->crfd;
2712 rfd_out = output_ecoff->external_rfd + output_symhdr->crfd;
2713 for (; rfd_in < rfd_end; rfd_in++, rfd_out++)
2717 ecoff_swap_rfd_in (input_bfd, rfd_in, &rfd);
2718 rfd += output_symhdr->ifdMax;
2719 ecoff_swap_rfd_out (output_bfd, &rfd, rfd_out);
2721 output_symhdr->crfd += input_symhdr->crfd;
2725 struct rfd_ext *rfd_out;
2726 struct rfd_ext *rfd_end;
2729 /* Create RFD's. Some of the debugging information includes
2730 relative file indices. These indices are taken as indices to
2731 the RFD table if there is one, or to the global table if
2732 there is not. If we did not create RFD's, we would have to
2733 parse and adjust all the debugging information which contains
2735 rfd = output_symhdr->ifdMax;
2736 rfd_out = output_ecoff->external_rfd + output_symhdr->crfd;
2737 rfd_end = rfd_out + input_symhdr->ifdMax;
2738 for (; rfd_out < rfd_end; rfd_out++, rfd++)
2739 ecoff_swap_rfd_out (output_bfd, &rfd, rfd_out);
2740 output_symhdr->crfd += input_symhdr->ifdMax;
2743 /* Combine the register masks. */
2747 output_ecoff->gprmask |= input_ecoff->gprmask;
2748 for (i = 0; i < 4; i++)
2749 output_ecoff->cprmask[i] |= input_ecoff->cprmask[i];
2752 /* Update the counts. */
2753 output_symhdr->ilineMax += input_symhdr->ilineMax;
2754 output_symhdr->cbLine += input_symhdr->cbLine;
2755 output_symhdr->idnMax += input_symhdr->idnMax;
2756 output_symhdr->ipdMax += input_symhdr->ipdMax;
2757 output_symhdr->isymMax += input_symhdr->isymMax;
2758 output_symhdr->ioptMax += input_symhdr->ioptMax;
2759 output_symhdr->iauxMax += input_symhdr->iauxMax;
2760 output_symhdr->issMax += input_symhdr->issMax;
2761 output_symhdr->ifdMax += input_symhdr->ifdMax;
2766 /* This is the actual link routine. It makes two passes over all the
2770 ecoff_bfd_seclet_link (abfd, data, relocateable)
2773 boolean relocateable;
2777 register asection *o;
2778 register bfd_seclet_type *p;
2779 asymbol **sym_ptr_ptr;
2783 /* We accumulate the debugging information counts in the symbolic
2785 symhdr = &ecoff_data (abfd)->symbolic_header;
2786 symhdr->magic = magicSym;
2787 /* FIXME: What should the version stamp be? */
2789 symhdr->ilineMax = 0;
2793 symhdr->isymMax = 0;
2794 symhdr->ioptMax = 0;
2795 symhdr->iauxMax = 0;
2797 symhdr->issExtMax = 0;
2800 symhdr->iextMax = 0;
2802 /* We need to copy over the debugging symbols from each input BFD.
2803 When we do this copying, we have to adjust the text address in
2804 the FDR structures, so we have to know the text address used for
2805 the input BFD. Since we only want to copy the symbols once per
2806 input BFD, but we are going to look at each input BFD multiple
2807 times (once for each section it provides), we arrange to always
2808 look at the text section first. That means that when we copy the
2809 debugging information, we always know the text address. So we
2810 actually do each pass in two sub passes; first the text sections,
2811 then the non-text sections. We use the output_has_begun flag to
2812 determine whether we have copied over the debugging information
2815 /* Do the first pass: set the output section contents and count the
2816 debugging information. */
2817 ecoff_clear_output_flags (abfd);
2818 for (ipass = 0; ipass < 2; ipass++)
2820 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2822 /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false,
2823 so they are done on pass 0. For other sections the
2824 expression is true, so they are done on pass 1. */
2825 if (((o->flags & SEC_CODE) == 0) != ipass)
2828 for (p = o->seclets_head;
2829 p != (bfd_seclet_type *) NULL;
2832 if (ecoff_dump_seclet (abfd, p, o, data, relocateable)
2839 /* We handle the external symbols differently. We use the ones
2840 attached to the output_bfd. The linker will have already
2841 determined which symbols are to be attached. Here we just
2842 determine how much space we will need for them. */
2843 sym_ptr_ptr = bfd_get_outsymbols (abfd);
2844 if (sym_ptr_ptr != NULL)
2848 sym_end = sym_ptr_ptr + bfd_get_symcount (abfd);
2849 for (; sym_ptr_ptr < sym_end; sym_ptr_ptr++)
2851 if (((*sym_ptr_ptr)->flags & BSF_DEBUGGING) == 0
2852 && ((*sym_ptr_ptr)->flags & BSF_LOCAL) == 0)
2855 symhdr->issExtMax += strlen ((*sym_ptr_ptr)->name) + 1;
2860 /* Adjust the counts so that structures are longword aligned. */
2861 symhdr->cbLine = (symhdr->cbLine + 3) &~ 3;
2862 symhdr->issMax = (symhdr->issMax + 3) &~ 3;
2863 symhdr->issExtMax = (symhdr->issExtMax + 3) &~ 3;
2865 /* Now the counts in symhdr are the correct size for the debugging
2866 information. We allocate the right amount of space, and reset
2867 the counts so that the second pass can use them as indices. It
2868 would be possible to output the debugging information directly to
2869 the file in pass 2, rather than to build it in memory and then
2870 write it out. Outputting to the file would require a lot of
2871 seeks and small writes, though, and I think this approach is
2873 size = (symhdr->cbLine * sizeof (unsigned char)
2874 + symhdr->idnMax * sizeof (struct dnr_ext)
2875 + symhdr->ipdMax * sizeof (struct pdr_ext)
2876 + symhdr->isymMax * sizeof (struct sym_ext)
2877 + symhdr->ioptMax * sizeof (struct opt_ext)
2878 + symhdr->iauxMax * sizeof (union aux_ext)
2879 + symhdr->issMax * sizeof (char)
2880 + symhdr->issExtMax * sizeof (char)
2881 + symhdr->ifdMax * sizeof (struct fdr_ext)
2882 + symhdr->crfd * sizeof (struct rfd_ext)
2883 + symhdr->iextMax * sizeof (struct ext_ext));
2884 raw = (char *) bfd_alloc (abfd, size);
2885 if (raw == (char *) NULL)
2887 bfd_error = no_memory;
2890 ecoff_data (abfd)->raw_size = size;
2891 ecoff_data (abfd)->raw_syments = (PTR) raw;
2893 /* Initialize the raw pointers. */
2894 #define SET(field, count, type) \
2895 ecoff_data (abfd)->field = (type *) raw; \
2896 raw += symhdr->count * sizeof (type)
2898 SET (line, cbLine, unsigned char);
2899 SET (external_dnr, idnMax, struct dnr_ext);
2900 SET (external_pdr, ipdMax, struct pdr_ext);
2901 SET (external_sym, isymMax, struct sym_ext);
2902 SET (external_opt, ioptMax, struct opt_ext);
2903 SET (external_aux, iauxMax, union aux_ext);
2904 SET (ss, issMax, char);
2905 SET (ssext, issExtMax, char);
2906 SET (external_fdr, ifdMax, struct fdr_ext);
2907 SET (external_rfd, crfd, struct rfd_ext);
2908 SET (external_ext, iextMax, struct ext_ext);
2911 /* Reset the counts so the second pass can use them to know how far
2913 symhdr->ilineMax = 0;
2917 symhdr->isymMax = 0;
2918 symhdr->ioptMax = 0;
2919 symhdr->iauxMax = 0;
2921 symhdr->issExtMax = 0;
2924 symhdr->iextMax = 0;
2926 /* Do the second pass: accumulate the debugging information. */
2927 ecoff_clear_output_flags (abfd);
2928 for (ipass = 0; ipass < 2; ipass++)
2930 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2932 if (((o->flags & SEC_CODE) == 0) != ipass)
2934 for (p = o->seclets_head;
2935 p != (bfd_seclet_type *) NULL;
2938 if (p->type == bfd_indirect_seclet)
2940 if (ecoff_get_debug (abfd, p, o, relocateable) == false)
2947 /* Put in the external symbols. */
2948 sym_ptr_ptr = bfd_get_outsymbols (abfd);
2949 if (sym_ptr_ptr != NULL)
2952 struct ext_ext *external_ext;
2954 ssext = ecoff_data (abfd)->ssext;
2955 external_ext = ecoff_data (abfd)->external_ext;
2956 for (; *sym_ptr_ptr != NULL; sym_ptr_ptr++)
2961 sym_ptr = *sym_ptr_ptr;
2963 if ((sym_ptr->flags & BSF_DEBUGGING) != 0
2964 || (sym_ptr->flags & BSF_LOCAL) != 0)
2967 /* The enative pointer can be NULL for a symbol created by
2968 the linker via ecoff_make_empty_symbol. */
2969 if (bfd_asymbol_flavour (sym_ptr) != bfd_target_ecoff_flavour
2970 || (((ecoff_symbol_type *) sym_ptr)->native.enative
2971 == (struct ext_ext *) NULL))
2974 esym.cobol_main = 0;
2978 /* FIXME: we can do better than this for st and sc. */
2979 esym.asym.st = stGlobal;
2980 esym.asym.sc = scAbs;
2981 esym.asym.reserved = 0;
2982 esym.asym.index = indexNil;
2986 ecoff_symbol_type *ecoff_sym_ptr;
2988 ecoff_sym_ptr = (ecoff_symbol_type *) sym_ptr;
2989 if (ecoff_sym_ptr->local)
2991 ecoff_swap_ext_in (abfd, ecoff_sym_ptr->native.enative, &esym);
2993 /* If we're producing an executable, move common symbols
2995 if (relocateable == false)
2997 if (esym.asym.sc == scCommon)
2998 esym.asym.sc = scBss;
2999 else if (esym.asym.sc == scSCommon)
3000 esym.asym.sc = scSBss;
3003 /* Adjust the FDR index for the symbol by that used for
3005 esym.ifd += ecoff_data (bfd_asymbol_bfd (sym_ptr))->ifdbase;
3008 esym.asym.iss = symhdr->issExtMax;
3010 if (bfd_is_com_section (sym_ptr->section)
3011 || sym_ptr->section == &bfd_und_section)
3012 esym.asym.value = sym_ptr->value;
3014 esym.asym.value = (sym_ptr->value
3015 + sym_ptr->section->output_offset
3016 + sym_ptr->section->output_section->vma);
3018 ecoff_swap_ext_out (abfd, &esym, external_ext + symhdr->iextMax);
3020 ecoff_set_sym_index (sym_ptr, symhdr->iextMax);
3024 strcpy (ssext + symhdr->issExtMax, sym_ptr->name);
3025 symhdr->issExtMax += strlen (sym_ptr->name) + 1;
3029 /* Adjust the counts so that structures are longword aligned. */
3030 symhdr->cbLine = (symhdr->cbLine + 3) &~ 3;
3031 symhdr->issMax = (symhdr->issMax + 3) &~ 3;
3032 symhdr->issExtMax = (symhdr->issExtMax + 3) &~ 3;
3037 /* Set the architecture. The only architecture we support here is
3038 mips. We set the architecture anyhow, since many callers ignore
3039 the return value. */
3042 ecoff_set_arch_mach (abfd, arch, machine)
3044 enum bfd_architecture arch;
3045 unsigned long machine;
3047 bfd_default_set_arch_mach (abfd, arch, machine);
3048 return arch == bfd_arch_mips;
3051 /* Get the size of the section headers. We do not output the .scommon
3052 section which we created in ecoff_mkobject. */
3055 ecoff_sizeof_headers (abfd, reloc)
3059 return FILHSZ + AOUTSZ + (abfd->section_count - 1) * SCNHSZ;
3062 /* Calculate the file position for each section, and set
3066 ecoff_compute_section_file_positions (abfd)
3074 if (bfd_get_start_address (abfd))
3075 abfd->flags |= EXEC_P;
3077 sofar = ecoff_sizeof_headers (abfd, false);
3080 for (current = abfd->sections;
3081 current != (asection *) NULL;
3082 current = current->next)
3084 /* Only deal with sections which have contents */
3085 if (! (current->flags & SEC_HAS_CONTENTS)
3086 || strcmp (current->name, SCOMMON) == 0)
3089 /* On Ultrix, the data sections in an executable file must be
3090 aligned to a page boundary within the file. This does not
3091 affect the section size, though. FIXME: Does this work for
3093 if ((abfd->flags & EXEC_P) != 0
3094 && first_data != false
3095 && (current->flags & SEC_CODE) == 0)
3097 sofar = (sofar + PAGE_SIZE - 1) &~ (PAGE_SIZE - 1);
3101 /* Align the sections in the file to the same boundary on
3102 which they are aligned in virtual memory. */
3104 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
3106 current->filepos = sofar;
3108 sofar += current->_raw_size;
3110 /* make sure that this section is of the right size too */
3112 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
3113 current->_raw_size += sofar - old_sofar;
3116 ecoff_data (abfd)->reloc_filepos = sofar;
3119 /* Set the contents of a section. */
3122 ecoff_set_section_contents (abfd, section, location, offset, count)
3127 bfd_size_type count;
3129 if (abfd->output_has_begun == false)
3130 ecoff_compute_section_file_positions (abfd);
3132 bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET);
3135 return (bfd_write (location, 1, count, abfd) == count) ? true : false;
3140 /* Write out an ECOFF file. */
3143 ecoff_write_object_contents (abfd)
3149 file_ptr reloc_base;
3151 unsigned long reloc_size;
3152 unsigned long text_size;
3153 unsigned long text_start;
3154 unsigned long data_size;
3155 unsigned long data_start;
3156 unsigned long bss_size;
3157 struct internal_filehdr internal_f;
3158 struct internal_aouthdr internal_a;
3161 bfd_error = system_call_error;
3163 if(abfd->output_has_begun == false)
3164 ecoff_compute_section_file_positions(abfd);
3166 if (abfd->sections != (asection *) NULL)
3167 scn_base = abfd->sections->filepos;
3170 reloc_base = ecoff_data (abfd)->reloc_filepos;
3174 for (current = abfd->sections;
3175 current != (asection *)NULL;
3176 current = current->next)
3178 if (strcmp (current->name, SCOMMON) == 0)
3180 current->target_index = count;
3182 if (current->reloc_count != 0)
3184 bfd_size_type relsize;
3186 current->rel_filepos = reloc_base;
3187 relsize = current->reloc_count * RELSZ;
3188 reloc_size += relsize;
3189 reloc_base += relsize;
3192 current->rel_filepos = 0;
3195 sym_base = reloc_base + reloc_size;
3197 /* At least on Ultrix, the symbol table of an executable file must
3198 be aligned to a page boundary. FIXME: Is this true on other
3200 if ((abfd->flags & EXEC_P) != 0)
3201 sym_base = (sym_base + PAGE_SIZE - 1) &~ (PAGE_SIZE - 1);
3203 ecoff_data (abfd)->sym_filepos = sym_base;
3205 text_size = ecoff_sizeof_headers (abfd, false);
3211 /* Write section headers to the file. */
3213 internal_f.f_nscns = 0;
3214 if (bfd_seek (abfd, (file_ptr) (FILHSZ + AOUTSZ), SEEK_SET) != 0)
3216 for (current = abfd->sections;
3217 current != (asection *) NULL;
3218 current = current->next)
3220 struct internal_scnhdr section;
3223 if (strcmp (current->name, SCOMMON) == 0)
3225 BFD_ASSERT (bfd_get_section_size_before_reloc (current) == 0
3226 && current->reloc_count == 0);
3230 ++internal_f.f_nscns;
3232 strncpy (section.s_name, current->name, sizeof section.s_name);
3234 /* FIXME: is this correct for shared libraries? I think it is
3235 but I have no platform to check. Ian Lance Taylor. */
3236 vma = bfd_get_section_vma (abfd, current);
3237 if (strcmp (current->name, _LIB) == 0)
3238 section.s_vaddr = 0;
3240 section.s_vaddr = vma;
3242 section.s_paddr = vma;
3243 section.s_size = bfd_get_section_size_before_reloc (current);
3245 /* If this section has no size or is unloadable then the scnptr
3247 if (current->_raw_size == 0
3248 || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3249 section.s_scnptr = 0;
3251 section.s_scnptr = current->filepos;
3252 section.s_relptr = current->rel_filepos;
3254 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
3255 object file produced by the assembler is supposed to point to
3256 information about how much room is required by objects of
3257 various different sizes. I think this only matters if we
3258 want the linker to compute the best size to use, or
3259 something. I don't know what happens if the information is
3261 section.s_lnnoptr = 0;
3263 section.s_nreloc = current->reloc_count;
3264 section.s_nlnno = 0;
3265 section.s_flags = ecoff_sec_to_styp_flags (current->name,
3271 ecoff_swap_scnhdr_out (abfd, (PTR) §ion, (PTR) &buff);
3272 if (bfd_write ((PTR) &buff, 1, SCNHSZ, abfd) != SCNHSZ)
3276 if ((section.s_flags & STYP_TEXT) != 0)
3278 text_size += bfd_get_section_size_before_reloc (current);
3279 if (text_start == 0 || text_start > vma)
3282 else if ((section.s_flags & STYP_RDATA) != 0
3283 || (section.s_flags & STYP_DATA) != 0
3284 || (section.s_flags & STYP_LIT8) != 0
3285 || (section.s_flags & STYP_LIT4) != 0
3286 || (section.s_flags & STYP_SDATA) != 0)
3288 data_size += bfd_get_section_size_before_reloc (current);
3289 if (data_start == 0 || data_start > vma)
3292 else if ((section.s_flags & STYP_BSS) != 0
3293 || (section.s_flags & STYP_SBSS) != 0)
3294 bss_size += bfd_get_section_size_before_reloc (current);
3297 /* Set up the file header. */
3299 if (abfd->xvec->header_byteorder_big_p != false)
3300 internal_f.f_magic = MIPS_MAGIC_BIG;
3302 internal_f.f_magic = MIPS_MAGIC_LITTLE;
3305 We will NOT put a fucking timestamp in the header here. Every time you
3306 put it back, I will come in and take it out again. I'm sorry. This
3307 field does not belong here. We fill it with a 0 so it compares the
3308 same but is not a reasonable time. -- gnu@cygnus.com
3310 internal_f.f_timdat = 0;
3312 if (bfd_get_symcount (abfd) != 0)
3314 /* The ECOFF f_nsyms field is not actually the number of
3315 symbols, it's the size of symbolic information header. */
3316 internal_f.f_nsyms = sizeof (struct hdr_ext);
3317 internal_f.f_symptr = sym_base;
3321 internal_f.f_nsyms = 0;
3322 internal_f.f_symptr = 0;
3325 internal_f.f_opthdr = AOUTSZ;
3327 internal_f.f_flags = F_LNNO;
3328 if (reloc_size == 0)
3329 internal_f.f_flags |= F_RELFLG;
3330 if (bfd_get_symcount (abfd) == 0)
3331 internal_f.f_flags |= F_LSYMS;
3332 if (abfd->flags & EXEC_P)
3333 internal_f.f_flags |= F_EXEC;
3335 if (! abfd->xvec->byteorder_big_p)
3336 internal_f.f_flags |= F_AR32WR;
3338 internal_f.f_flags |= F_AR32W;
3340 /* Set up the ``optional'' header. */
3341 internal_a.magic = ZMAGIC;
3343 /* FIXME: This is what Ultrix puts in, and it makes the Ultrix
3344 linker happy. But, is it right? */
3345 internal_a.vstamp = 0x20a;
3347 /* At least on Ultrix, these have to be rounded to page boundaries.
3348 FIXME: Is this true on other platforms? */
3349 internal_a.tsize = (text_size + PAGE_SIZE - 1) &~ (PAGE_SIZE - 1);
3350 internal_a.text_start = text_start &~ (PAGE_SIZE - 1);
3351 internal_a.dsize = (data_size + PAGE_SIZE - 1) &~ (PAGE_SIZE - 1);
3352 internal_a.data_start = data_start &~ (PAGE_SIZE - 1);
3354 /* On Ultrix, the initial portions of the .sbss and .bss segments
3355 are at the end of the data section. The bsize field in the
3356 optional header records how many bss bytes are required beyond
3357 those in the data section. The value is not rounded to a page
3359 if (bss_size < internal_a.dsize - data_size)
3362 bss_size -= internal_a.dsize - data_size;
3363 internal_a.bsize = bss_size;
3364 internal_a.bss_start = internal_a.data_start + internal_a.dsize;
3366 internal_a.entry = bfd_get_start_address (abfd);
3368 internal_a.gp_value = ecoff_data (abfd)->gp;
3370 internal_a.gprmask = ecoff_data (abfd)->gprmask;
3371 for (i = 0; i < 4; i++)
3372 internal_a.cprmask[i] = ecoff_data (abfd)->cprmask[i];
3374 /* Write out the file header and the optional header. */
3376 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3381 ecoff_swap_filehdr_out (abfd, (PTR) &internal_f, (PTR) &buff);
3382 if (bfd_write ((PTR) &buff, 1, FILHSZ, abfd) != FILHSZ)
3389 ecoff_swap_aouthdr_out (abfd, (PTR) &internal_a, (PTR) &buff);
3390 if (bfd_write ((PTR) &buff, 1, AOUTSZ, abfd) != AOUTSZ)
3394 /* Write out the relocs. */
3395 for (current = abfd->sections;
3396 current != (asection *) NULL;
3397 current = current->next)
3400 arelent **reloc_ptr_ptr;
3401 arelent **reloc_end;
3404 if (current->reloc_count == 0)
3407 buff = (RELOC *) bfd_alloc (abfd, current->reloc_count * RELSZ);
3408 if (buff == (RELOC *) NULL)
3410 bfd_error = no_memory;
3414 reloc_ptr_ptr = current->orelocation;
3415 reloc_end = reloc_ptr_ptr + current->reloc_count;
3417 for (; reloc_ptr_ptr < reloc_end; reloc_ptr_ptr++, out_ptr++)
3421 struct internal_reloc in;
3423 memset (&in, 0, sizeof in);
3425 reloc = *reloc_ptr_ptr;
3426 sym = *reloc->sym_ptr_ptr;
3428 in.r_vaddr = reloc->address + bfd_get_section_vma (abfd, current);
3429 in.r_type = reloc->howto->type;
3430 if ((sym->flags & BSF_SECTION_SYM) == 0)
3432 in.r_symndx = ecoff_get_sym_index (*reloc->sym_ptr_ptr);
3439 name = bfd_get_section_name (abfd, bfd_get_section (sym));
3440 if (strcmp (name, ".text") == 0)
3441 in.r_symndx = RELOC_SECTION_TEXT;
3442 else if (strcmp (name, ".rdata") == 0)
3443 in.r_symndx = RELOC_SECTION_RDATA;
3444 else if (strcmp (name, ".data") == 0)
3445 in.r_symndx = RELOC_SECTION_DATA;
3446 else if (strcmp (name, ".sdata") == 0)
3447 in.r_symndx = RELOC_SECTION_SDATA;
3448 else if (strcmp (name, ".sbss") == 0)
3449 in.r_symndx = RELOC_SECTION_SBSS;
3450 else if (strcmp (name, ".bss") == 0)
3451 in.r_symndx = RELOC_SECTION_BSS;
3452 else if (strcmp (name, ".init") == 0)
3453 in.r_symndx = RELOC_SECTION_INIT;
3454 else if (strcmp (name, ".lit8") == 0)
3455 in.r_symndx = RELOC_SECTION_LIT8;
3456 else if (strcmp (name, ".lit4") == 0)
3457 in.r_symndx = RELOC_SECTION_LIT4;
3463 ecoff_swap_reloc_out (abfd, (PTR) &in, (PTR) out_ptr);
3466 if (bfd_seek (abfd, current->rel_filepos, SEEK_SET) != 0)
3468 if (bfd_write ((PTR) buff, RELSZ, current->reloc_count, abfd)
3469 != RELSZ * current->reloc_count)
3471 bfd_release (abfd, (PTR) buff);
3474 /* Write out the symbolic debugging information. */
3475 if (bfd_get_symcount (abfd) > 0)
3478 unsigned long sym_offset;
3479 struct hdr_ext buff;
3481 /* Set up the offsets in the symbolic header. */
3482 symhdr = &ecoff_data (abfd)->symbolic_header;
3483 sym_offset = ecoff_data (abfd)->sym_filepos + sizeof (struct hdr_ext);
3485 #define SET(offset, size, ptr) \
3486 if (symhdr->size == 0) \
3487 symhdr->offset = 0; \
3489 symhdr->offset = (((char *) ecoff_data (abfd)->ptr \
3490 - (char *) ecoff_data (abfd)->raw_syments) \
3493 SET (cbLineOffset, cbLine, line);
3494 SET (cbDnOffset, idnMax, external_dnr);
3495 SET (cbPdOffset, ipdMax, external_pdr);
3496 SET (cbSymOffset, isymMax, external_sym);
3497 SET (cbOptOffset, ioptMax, external_opt);
3498 SET (cbAuxOffset, iauxMax, external_aux);
3499 SET (cbSsOffset, issMax, ss);
3500 SET (cbSsExtOffset, issExtMax, ssext);
3501 SET (cbFdOffset, ifdMax, external_fdr);
3502 SET (cbRfdOffset, crfd, external_rfd);
3503 SET (cbExtOffset, iextMax, external_ext);
3506 if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos,
3509 ecoff_swap_hdr_out (abfd, &ecoff_data (abfd)->symbolic_header, &buff);
3510 if (bfd_write ((PTR) &buff, 1, sizeof buff, abfd) != sizeof buff)
3512 if (bfd_write ((PTR) ecoff_data (abfd)->raw_syments, 1,
3513 ecoff_data (abfd)->raw_size, abfd)
3514 != ecoff_data (abfd)->raw_size)
3521 /* Archive handling. ECOFF uses what appears to be a unique type of
3522 archive header (which I call an armap). The byte ordering of the
3523 armap and the contents are encoded in the name of the armap itself.
3524 At least for now, we only support archives with the same byte
3525 ordering in the armap and the contents.
3527 The first four bytes in the armap are the number of symbol
3528 definitions. This is always a power of two.
3530 This is followed by the symbol definitions. Each symbol definition
3531 occupies 8 bytes. The first four bytes are the offset from the
3532 start of the armap strings to the null-terminated string naming
3533 this symbol. The second four bytes are the file offset to the
3534 archive member which defines this symbol. If the second four bytes
3535 are 0, then this is not actually a symbol definition, and it should
3538 The symbols are hashed into the armap with a closed hashing scheme.
3539 See the functions below for the details of the algorithm.
3541 We could use the hash table when looking up symbols in a library.
3542 This would require a new BFD target entry point to replace the
3543 bfd_get_next_mapent function used by the linker.
3545 After the symbol definitions comes four bytes holding the size of
3546 the string table, followed by the string table itself. */
3548 /* The name of an archive headers looks like this:
3549 __________E[BL]E[BL]_ (with a trailing space).
3550 The trailing space is changed to an X if the archive is changed to
3551 indicate that the armap is out of date. */
3553 #define ARMAP_BIG_ENDIAN 'B'
3554 #define ARMAP_LITTLE_ENDIAN 'L'
3555 #define ARMAP_MARKER 'E'
3556 #define ARMAP_START "__________"
3557 #define ARMAP_HEADER_MARKER_INDEX 10
3558 #define ARMAP_HEADER_ENDIAN_INDEX 11
3559 #define ARMAP_OBJECT_MARKER_INDEX 12
3560 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3561 #define ARMAP_END_INDEX 14
3562 #define ARMAP_END "_ "
3564 /* This is a magic number used in the hashing algorithm. */
3565 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3567 /* This returns the hash value to use for a string. It also sets
3568 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3569 is the number of entries in the hash table, and HLOG is the log
3573 ecoff_armap_hash (s, rehash, size, hlog)
3575 unsigned int *rehash;
3583 hash = ((hash >> 27) | (hash << 5)) + *s++;
3584 hash *= ARMAP_HASH_MAGIC;
3585 *rehash = (hash & (size - 1)) | 1;
3586 return hash >> (32 - hlog);
3589 /* Read in the armap. */
3592 ecoff_slurp_armap (abfd)
3597 struct areltdata *mapdata;
3598 bfd_size_type parsed_size;
3600 struct artdata *ardata;
3603 struct symdef *symdef_ptr;
3606 /* Get the name of the first element. */
3607 i = bfd_read ((PTR) nextname, 1, 16, abfd);
3613 bfd_seek (abfd, (file_ptr) -16, SEEK_CUR);
3615 /* See if the first element is an armap. */
3616 if (strncmp (nextname, ARMAP_START, sizeof ARMAP_START - 1) != 0
3617 || nextname[ARMAP_HEADER_MARKER_INDEX] != ARMAP_MARKER
3618 || (nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
3619 && nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
3620 || nextname[ARMAP_OBJECT_MARKER_INDEX] != ARMAP_MARKER
3621 || (nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
3622 && nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
3623 || strncmp (nextname + ARMAP_END_INDEX,
3624 ARMAP_END, sizeof ARMAP_END - 1) != 0)
3626 bfd_has_map (abfd) = false;
3630 /* Make sure we have the right byte ordering. */
3631 if (((nextname[ARMAP_HEADER_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
3632 ^ (abfd->xvec->header_byteorder_big_p != false))
3633 || ((nextname[ARMAP_OBJECT_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
3634 ^ (abfd->xvec->byteorder_big_p != false)))
3636 bfd_error = wrong_format;
3640 /* Read in the armap. */
3641 ardata = bfd_ardata (abfd);
3642 mapdata = snarf_ar_hdr (abfd);
3643 if (mapdata == (struct areltdata *) NULL)
3645 parsed_size = mapdata->parsed_size;
3646 bfd_release (abfd, (PTR) mapdata);
3648 raw_armap = (char *) bfd_alloc (abfd, parsed_size);
3649 if (raw_armap == (char *) NULL)
3651 bfd_error = no_memory;
3655 if (bfd_read ((PTR) raw_armap, 1, parsed_size, abfd) != parsed_size)
3657 bfd_error = malformed_archive;
3658 bfd_release (abfd, (PTR) raw_armap);
3662 count = bfd_h_get_32 (abfd, (PTR) raw_armap);
3664 ardata->symdef_count = 0;
3665 ardata->cache = (struct ar_cache *) NULL;
3667 /* Hack: overlay the symdefs on top of the raw archive data. This
3668 is the way do_slurp_bsd_armap works. */
3669 raw_ptr = raw_armap + LONG_SIZE;
3670 symdef_ptr = (struct symdef *) raw_ptr;
3671 ardata->symdefs = (carsym *) symdef_ptr;
3672 stringbase = raw_ptr + count * (2 * LONG_SIZE) + LONG_SIZE;
3674 #ifdef CHECK_ARMAP_HASH
3678 /* Double check that I have the hashing algorithm right by making
3679 sure that every symbol can be looked up successfully. */
3681 for (i = 1; i < count; i <<= 1)
3683 BFD_ASSERT (i == count);
3685 for (i = 0; i < count; i++, raw_ptr += 2 * LONG_SIZE)
3687 unsigned int name_offset, file_offset;
3688 unsigned int hash, rehash, srch;
3690 name_offset = bfd_h_get_32 (abfd, (PTR) raw_ptr);
3691 file_offset = bfd_h_get_32 (abfd, (PTR) (raw_ptr + LONG_SIZE));
3692 if (file_offset == 0)
3694 hash = ecoff_armap_hash (stringbase + name_offset, &rehash, count,
3699 /* See if we can rehash to this location. */
3700 for (srch = (hash + rehash) & (count - 1);
3701 srch != hash && srch != i;
3702 srch = (srch + rehash) & (count - 1))
3703 BFD_ASSERT (bfd_h_get_32 (abfd,
3706 + (srch * 2 * LONG_SIZE)
3709 BFD_ASSERT (srch == i);
3713 raw_ptr = raw_armap + LONG_SIZE;
3714 #endif /* CHECK_ARMAP_HASH */
3716 for (i = 0; i < count; i++, raw_ptr += 2 * LONG_SIZE)
3718 unsigned int name_offset, file_offset;
3720 name_offset = bfd_h_get_32 (abfd, (PTR) raw_ptr);
3721 file_offset = bfd_h_get_32 (abfd, (PTR) (raw_ptr + LONG_SIZE));
3722 if (file_offset == 0)
3724 symdef_ptr->s.name = stringbase + name_offset;
3725 symdef_ptr->file_offset = file_offset;
3727 ++ardata->symdef_count;
3730 ardata->first_file_filepos = bfd_tell (abfd);
3731 /* Pad to an even boundary. */
3732 ardata->first_file_filepos += ardata->first_file_filepos % 2;
3734 bfd_has_map (abfd) = true;
3739 /* Write out an armap. */
3742 ecoff_write_armap (abfd, elength, map, orl_count, stridx)
3744 unsigned int elength;
3746 unsigned int orl_count;
3749 unsigned int hashsize, hashlog;
3750 unsigned int symdefsize;
3752 unsigned int stringsize;
3753 unsigned int mapsize;
3756 struct stat statbuf;
3758 bfd_byte temp[LONG_SIZE];
3759 bfd_byte *hashtable;
3763 /* Ultrix appears to use as a hash table size the least power of two
3764 greater than twice the number of entries. */
3765 for (hashlog = 0; (1 << hashlog) <= 2 * orl_count; hashlog++)
3767 hashsize = 1 << hashlog;
3769 symdefsize = hashsize * 2 * LONG_SIZE;
3771 stringsize = stridx + padit;
3773 /* Include 8 bytes to store symdefsize and stringsize in output. */
3774 mapsize = LONG_SIZE + symdefsize + stringsize + LONG_SIZE;
3776 firstreal = SARMAG + sizeof (struct ar_hdr) + mapsize + elength;
3778 memset ((PTR) &hdr, 0, sizeof hdr);
3780 /* Work out the ECOFF armap name. */
3781 strcpy (hdr.ar_name, ARMAP_START);
3782 hdr.ar_name[ARMAP_HEADER_MARKER_INDEX] = ARMAP_MARKER;
3783 hdr.ar_name[ARMAP_HEADER_ENDIAN_INDEX] =
3784 (abfd->xvec->header_byteorder_big_p
3786 : ARMAP_LITTLE_ENDIAN);
3787 hdr.ar_name[ARMAP_OBJECT_MARKER_INDEX] = ARMAP_MARKER;
3788 hdr.ar_name[ARMAP_OBJECT_ENDIAN_INDEX] =
3789 abfd->xvec->byteorder_big_p ? ARMAP_BIG_ENDIAN : ARMAP_LITTLE_ENDIAN;
3790 memcpy (hdr.ar_name + ARMAP_END_INDEX, ARMAP_END, sizeof ARMAP_END - 1);
3792 /* Write the timestamp of the archive header to be just a little bit
3793 later than the timestamp of the file, otherwise the linker will
3794 complain that the index is out of date. Actually, the Ultrix
3795 linker just checks the archive name; the GNU linker may check the
3797 stat (abfd->filename, &statbuf);
3798 sprintf (hdr.ar_date, "%ld", (long) (statbuf.st_mtime + 60));
3800 /* The DECstation uses zeroes for the uid, gid and mode of the
3802 hdr.ar_uid[0] = '0';
3803 hdr.ar_gid[0] = '0';
3804 hdr.ar_mode[0] = '0';
3806 sprintf (hdr.ar_size, "%-10d", (int) mapsize);
3808 hdr.ar_fmag[0] = '`';
3809 hdr.ar_fmag[1] = '\n';
3811 /* Turn all null bytes in the header into spaces. */
3812 for (i = 0; i < sizeof (struct ar_hdr); i++)
3813 if (((char *)(&hdr))[i] == '\0')
3814 (((char *)(&hdr))[i]) = ' ';
3816 if (bfd_write ((PTR) &hdr, 1, sizeof (struct ar_hdr), abfd)
3817 != sizeof (struct ar_hdr))
3820 bfd_h_put_32 (abfd, hashsize, temp);
3821 if (bfd_write (temp, 1, LONG_SIZE, abfd) != LONG_SIZE)
3824 hashtable = (bfd_byte *) bfd_zalloc (abfd, symdefsize);
3826 current = abfd->archive_head;
3828 for (i = 0; i < orl_count; i++)
3830 unsigned int hash, rehash;
3832 /* Advance firstreal to the file position of this archive
3834 if (((bfd *) map[i].pos) != last_elt)
3838 firstreal += arelt_size (current) + sizeof (struct ar_hdr);
3839 firstreal += firstreal % 2;
3840 current = current->next;
3842 while (current != (bfd *) map[i].pos);
3847 hash = ecoff_armap_hash (*map[i].name, &rehash, hashsize, hashlog);
3848 if (bfd_h_get_32 (abfd, (PTR) (hashtable
3849 + (hash * 2 * LONG_SIZE)
3855 /* The desired slot is already taken. */
3856 for (srch = (hash + rehash) & (hashsize - 1);
3858 srch = (srch + rehash) & (hashsize - 1))
3859 if (bfd_h_get_32 (abfd, (PTR) (hashtable
3860 + (srch * 2 * LONG_SIZE)
3865 BFD_ASSERT (srch != hash);
3870 bfd_h_put_32 (abfd, map[i].namidx,
3871 (PTR) (hashtable + hash * 2 * LONG_SIZE));
3872 bfd_h_put_32 (abfd, firstreal,
3873 (PTR) (hashtable + hash * 2 * LONG_SIZE + LONG_SIZE));
3876 if (bfd_write (hashtable, 1, symdefsize, abfd) != symdefsize)
3879 bfd_release (abfd, hashtable);
3881 /* Now write the strings. */
3882 bfd_h_put_32 (abfd, stringsize, temp);
3883 if (bfd_write (temp, 1, LONG_SIZE, abfd) != LONG_SIZE)
3885 for (i = 0; i < orl_count; i++)
3889 len = strlen (*map[i].name) + 1;
3890 if (bfd_write ((PTR) (*map[i].name), 1, len, abfd) != len)
3894 /* The spec sez this should be a newline. But in order to be
3895 bug-compatible for DECstation ar we use a null. */
3898 if (bfd_write ("\0", 1, 1, abfd) != 1)
3905 /* We just use the generic extended name support. This is a GNU
3907 #define ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table
3909 /* See whether this BFD is an archive. If it is, read in the armap
3910 and the extended name table. */
3913 ecoff_archive_p (abfd)
3916 char armag[SARMAG + 1];
3918 if (bfd_read ((PTR) armag, 1, SARMAG, abfd) != SARMAG
3919 || strncmp (armag, ARMAG, SARMAG) != 0)
3921 bfd_error = wrong_format;
3922 return (bfd_target *) NULL;
3925 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3926 involves a cast, we can't do it as the left operand of
3928 abfd->tdata.aout_ar_data =
3929 (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata));
3931 if (bfd_ardata (abfd) == (struct artdata *) NULL)
3933 bfd_error = no_memory;
3934 return (bfd_target *) NULL;
3937 bfd_ardata (abfd)->first_file_filepos = SARMAG;
3939 if (ecoff_slurp_armap (abfd) == false
3940 || ecoff_slurp_extended_name_table (abfd) == false)
3942 bfd_release (abfd, bfd_ardata (abfd));
3943 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
3944 return (bfd_target *) NULL;
3950 /* This is the COFF backend structure. The backend_data field of the
3951 bfd_target structure is set to this. The section reading code in
3952 coffgen.c uses this structure. */
3954 static CONST bfd_coff_backend_data bfd_ecoff_std_swap_table = {
3955 (void (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_in */
3956 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_in */
3957 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_in */
3958 (unsigned (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_out */
3959 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_out */
3960 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_out */
3961 ecoff_swap_reloc_out, ecoff_swap_filehdr_out, ecoff_swap_aouthdr_out,
3962 ecoff_swap_scnhdr_out,
3963 FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, true,
3964 ecoff_swap_filehdr_in, ecoff_swap_aouthdr_in, ecoff_swap_scnhdr_in,
3965 ecoff_bad_format_hook, ecoff_set_arch_mach_hook, ecoff_mkobject_hook,
3966 ecoff_styp_to_sec_flags, ecoff_make_section_hook, ecoff_set_alignment_hook,
3967 ecoff_slurp_symbol_table
3970 /* get_lineno could be written for ECOFF, but it would currently only
3971 be useful for linking ECOFF and COFF files together, which doesn't
3973 #define ecoff_get_lineno \
3974 ((alent *(*) PARAMS ((bfd *, asymbol *))) bfd_nullvoidptr)
3976 /* These bfd_target functions are defined in other files. */
3978 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
3979 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
3980 #define ecoff_core_file_matches_executable_p \
3981 _bfd_dummy_core_file_matches_executable_p
3982 #define ecoff_truncate_arname bfd_dont_truncate_arname
3983 #define ecoff_openr_next_archived_file bfd_generic_openr_next_archived_file
3984 #define ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt
3985 #define ecoff_get_section_contents bfd_generic_get_section_contents
3986 #define ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound
3987 #define ecoff_close_and_cleanup bfd_generic_close_and_cleanup
3988 #define ecoff_bfd_debug_info_start bfd_void
3989 #define ecoff_bfd_debug_info_end bfd_void
3990 #define ecoff_bfd_debug_info_accumulate \
3991 ((void (*) PARAMS ((bfd *, struct sec *))) bfd_void)
3992 #define ecoff_bfd_get_relocated_section_contents \
3993 bfd_generic_get_relocated_section_contents
3994 #define ecoff_bfd_relax_section bfd_generic_relax_section
3996 bfd_target ecoff_little_vec =
3998 "ecoff-littlemips", /* name */
3999 bfd_target_ecoff_flavour,
4000 false, /* data byte order is little */
4001 false, /* header byte order is little */
4003 (HAS_RELOC | EXEC_P | /* object flags */
4004 HAS_LINENO | HAS_DEBUG |
4005 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
4007 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect
4009 0, /* leading underscore */
4010 '/', /* ar_pad_char */
4011 15, /* ar_max_namelen */
4012 3, /* minimum alignment power */
4013 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
4014 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
4016 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
4017 ecoff_archive_p, _bfd_dummy_target},
4018 {bfd_false, ecoff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
4020 {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */
4021 _bfd_write_archive_contents, bfd_false},
4024 (PTR) &bfd_ecoff_std_swap_table
4027 bfd_target ecoff_big_vec =
4029 "ecoff-bigmips", /* name */
4030 bfd_target_ecoff_flavour,
4031 true, /* data byte order is big */
4032 true, /* header byte order is big */
4034 (HAS_RELOC | EXEC_P | /* object flags */
4035 HAS_LINENO | HAS_DEBUG |
4036 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
4038 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect flags */
4039 0, /* leading underscore */
4040 ' ', /* ar_pad_char */
4041 16, /* ar_max_namelen */
4042 3, /* minimum alignment power */
4043 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16,
4044 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16,
4045 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
4046 ecoff_archive_p, _bfd_dummy_target},
4047 {bfd_false, ecoff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
4049 {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */
4050 _bfd_write_archive_contents, bfd_false},
4053 (PTR) &bfd_ecoff_std_swap_table
4054 /* Note that there is another bfd_target just above this one. If
4055 you are adding initializers here, you should be adding them there