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"
35 /* `Tdata' information kept for ECOFF files. */
37 #define ecoff_data(abfd) ((abfd)->tdata.ecoff_obj_data)
39 typedef struct ecoff_tdata
41 /* The reloc file position, set by
42 ecoff_compute_section_file_positions. */
43 file_ptr reloc_filepos;
45 /* The symbol table file position, set by ecoff_mkobject_hook. */
48 /* The start and end of the text segment. Only valid for an
49 existing file, not for one we are creating. */
50 unsigned long text_start;
51 unsigned long text_end;
53 /* The cached gp value. This is used when relocating. */
56 /* The register masks. When linking, all the masks found in the
57 input files are combined into the masks of the output file. */
58 unsigned long gprmask;
59 unsigned long cprmask[4];
61 /* The size of the unswapped ECOFF symbolic information. */
62 bfd_size_type raw_size;
64 /* The unswapped ECOFF symbolic information. */
67 /* The swapped ECOFF symbolic header. */
70 /* Pointers to the unswapped symbolic information. */
72 struct dnr_ext *external_dnr;
73 struct pdr_ext *external_pdr;
74 struct sym_ext *external_sym;
75 struct opt_ext *external_opt;
76 union aux_ext *external_aux;
79 struct fdr_ext *external_fdr;
80 struct rfd_ext *external_rfd;
81 struct ext_ext *external_ext;
83 /* The swapped FDR information. */
86 /* The FDR index. This is set for an input BFD to a link so that
87 the external symbols can set their FDR index correctly. */
90 /* The canonical BFD symbols. */
91 struct ecoff_symbol_struct *canonical_symbols;
95 /* Each canonical asymbol really looks like this. */
97 typedef struct ecoff_symbol_struct
99 /* The actual symbol which the rest of BFD works with */
102 /* The fdr for this symbol. */
105 /* true if this is a local symbol rather than an external one. */
108 /* A pointer to the unswapped hidden information for this symbol */
111 struct sym_ext *lnative;
112 struct ext_ext *enative;
117 /* We take the address of the first element of a asymbol to ensure that the
118 macro is only ever applied to an asymbol. */
119 #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd)))
121 /* This is a hack borrowed from coffcode.h; we need to save the index
122 of a symbol when we write it out so that can set the symbol index
123 correctly when we write out the relocs. */
124 #define ecoff_get_sym_index(symbol) ((unsigned long) (symbol)->udata)
125 #define ecoff_set_sym_index(symbol, idx) ((symbol)->udata = (PTR) (idx))
127 /* The page boundary used to align sections in the executable file. */
128 #define PAGE_SIZE 0x2000
130 /* The linker needs a section to hold small common variables while
131 linking. There is no convenient way to create it when the linker
132 needs it, so we always create one for each BFD. We then avoid
134 #define SCOMMON ".scommon"
136 /* MIPS ECOFF has COFF sections, but the debugging information is
137 stored in a completely different format. This files uses the some
138 of the swapping routines from coffswap.h, and some of the generic
139 COFF routines in coffgen.c, but, unlike the real COFF targets, does
140 not use coffcode.h itself. */
142 /* Prototypes for static functions. */
144 static boolean ecoff_bad_format_hook PARAMS ((bfd *abfd, PTR filehdr));
145 static asection *ecoff_make_section_hook PARAMS ((bfd *abfd, char *name));
146 static boolean ecoff_new_section_hook PARAMS ((bfd *abfd, asection *section));
147 static boolean ecoff_mkobject PARAMS ((bfd *abfd));
148 static PTR ecoff_mkobject_hook PARAMS ((bfd *abfd, PTR filehdr, PTR aouthdr));
149 static boolean ecoff_set_arch_mach_hook PARAMS ((bfd *abfd, PTR filehdr));
150 static long ecoff_sec_to_styp_flags PARAMS ((CONST char *name,
152 static flagword ecoff_styp_to_sec_flags PARAMS ((bfd *abfd, PTR hdr));
153 static boolean ecoff_slurp_symbolic_info PARAMS ((bfd *abfd));
154 static asymbol *ecoff_make_empty_symbol PARAMS ((bfd *abfd));
155 static void ecoff_set_symbol_info PARAMS ((bfd *abfd, SYMR *ecoff_sym,
156 asymbol *asym, int ext));
157 static boolean ecoff_slurp_symbol_table PARAMS ((bfd *abfd));
158 static unsigned int ecoff_get_symtab_upper_bound PARAMS ((bfd *abfd));
159 static unsigned int ecoff_get_symtab PARAMS ((bfd *abfd,
160 asymbol **alocation));
161 static void ecoff_emit_aggregate PARAMS ((bfd *abfd, char *string,
162 RNDXR *rndx, long isym,
164 static char *ecoff_type_to_string PARAMS ((bfd *abfd, union aux_ext *aux_ptr,
165 int indx, int bigendian));
166 static void ecoff_print_symbol PARAMS ((bfd *abfd, PTR filep,
168 bfd_print_symbol_type how));
169 static void ecoff_swap_reloc_in PARAMS ((bfd *abfd, RELOC *ext,
170 struct internal_reloc *intern));
171 static unsigned int ecoff_swap_reloc_out PARAMS ((bfd *abfd, PTR src,
173 static bfd_reloc_status_type ecoff_generic_reloc PARAMS ((bfd *abfd,
179 static bfd_reloc_status_type ecoff_refhi_reloc PARAMS ((bfd *abfd,
185 static bfd_reloc_status_type ecoff_gprel_reloc PARAMS ((bfd *abfd,
191 static boolean ecoff_slurp_reloc_table PARAMS ((bfd *abfd, asection *section,
193 static unsigned int ecoff_canonicalize_reloc PARAMS ((bfd *abfd,
197 static boolean ecoff_find_nearest_line PARAMS ((bfd *abfd,
201 CONST char **filename_ptr,
202 CONST char **fnname_ptr,
203 unsigned int *retline_ptr));
204 static void ecoff_clear_output_flags PARAMS ((bfd *abfd));
205 static boolean ecoff_rel PARAMS ((bfd *output_bfd, bfd_seclet_type *seclet,
206 asection *output_section, PTR data,
207 boolean relocateable));
208 static boolean ecoff_dump_seclet PARAMS ((bfd *abfd, bfd_seclet_type *seclet,
209 asection *section, PTR data,
210 boolean relocateable));
211 static long ecoff_add_string PARAMS ((bfd *output_bfd, FDR *fdr,
212 CONST char *string, boolean external));
213 static boolean ecoff_get_debug PARAMS ((bfd *output_bfd,
214 bfd_seclet_type *seclet,
216 boolean relocateable));
217 static boolean ecoff_bfd_seclet_link PARAMS ((bfd *abfd, PTR data,
218 boolean relocateable));
219 static boolean ecoff_set_arch_mach PARAMS ((bfd *abfd,
220 enum bfd_architecture arch,
221 unsigned long machine));
222 static int ecoff_sizeof_headers PARAMS ((bfd *abfd, boolean reloc));
223 static void ecoff_compute_section_file_positions PARAMS ((bfd *abfd));
224 static boolean ecoff_set_section_contents PARAMS ((bfd *abfd,
228 bfd_size_type count));
229 static boolean ecoff_write_object_contents PARAMS ((bfd *abfd));
230 static unsigned int ecoff_armap_hash PARAMS ((CONST char *s,
231 unsigned int *rehash,
234 static boolean ecoff_slurp_armap PARAMS ((bfd *abfd));
235 static boolean ecoff_write_armap PARAMS ((bfd *abfd, unsigned int elength,
237 unsigned int orl_count,
239 static bfd_target *ecoff_archive_p PARAMS ((bfd *abfd));
241 /* Get the generic COFF swapping routines, except for the reloc,
242 symbol, and lineno ones. Give them ecoff names. */
244 #define NO_COFF_RELOCS
245 #define NO_COFF_SYMBOLS
246 #define NO_COFF_LINENOS
247 #define coff_swap_filehdr_in ecoff_swap_filehdr_in
248 #define coff_swap_filehdr_out ecoff_swap_filehdr_out
249 #define coff_swap_aouthdr_in ecoff_swap_aouthdr_in
250 #define coff_swap_aouthdr_out ecoff_swap_aouthdr_out
251 #define coff_swap_scnhdr_in ecoff_swap_scnhdr_in
252 #define coff_swap_scnhdr_out ecoff_swap_scnhdr_out
253 #include "coffswap.h"
255 /* This stuff is somewhat copied from coffcode.h. */
257 static asection bfd_debug_section = { "*DEBUG*" };
259 /* See whether the magic number matches. */
262 ecoff_bad_format_hook (abfd, filehdr)
266 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
268 if (ECOFFBADMAG (*internal_f))
274 /* This is a hook needed by SCO COFF, but we have nothing to do. */
277 ecoff_make_section_hook (abfd, name)
281 return (asection *) NULL;
284 /* Initialize a new section. */
287 ecoff_new_section_hook (abfd, section)
291 section->alignment_power = abfd->xvec->align_power_min;
293 if (strcmp (section->name, _TEXT) == 0)
294 section->flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
295 else if (strcmp (section->name, _DATA) == 0
296 || strcmp (section->name, _SDATA) == 0)
297 section->flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
298 else if (strcmp (section->name, _RDATA) == 0
299 || strcmp (section->name, _LIT8) == 0
300 || strcmp (section->name, _LIT4) == 0)
301 section->flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
302 else if (strcmp (section->name, _BSS) == 0
303 || strcmp (section->name, _SBSS) == 0)
304 section->flags |= SEC_ALLOC;
306 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
307 uncertain about .init on some systems and I don't know how shared
313 /* Set the alignment of a section; we have nothing to do. */
315 #define ecoff_set_alignment_hook \
316 ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void)
318 /* Create an ECOFF object. */
321 ecoff_mkobject (abfd)
324 abfd->tdata.ecoff_obj_data = ((struct ecoff_tdata *)
325 bfd_zalloc (abfd, sizeof(ecoff_data_type)));
326 if (abfd->tdata.ecoff_obj_data == NULL)
328 bfd_error = no_memory;
332 /* Always create a .scommon section for every BFD. This is a hack so
333 that the linker has something to attach scSCommon symbols to. */
334 bfd_make_section (abfd, SCOMMON);
339 /* Create the ECOFF backend specific information. */
342 ecoff_mkobject_hook (abfd, filehdr, aouthdr)
347 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
348 struct internal_aouthdr *internal_a = (struct internal_aouthdr *) aouthdr;
349 ecoff_data_type *ecoff;
351 if (ecoff_mkobject (abfd) == false)
354 ecoff = ecoff_data (abfd);
355 ecoff->sym_filepos = internal_f->f_symptr;
357 if (internal_a != (struct internal_aouthdr *) NULL)
361 ecoff->text_start = internal_a->text_start;
362 ecoff->text_end = internal_a->text_start + internal_a->tsize;
363 ecoff->gp = internal_a->gp_value;
364 ecoff->gprmask = internal_a->gprmask;
365 for (i = 0; i < 4; i++)
366 ecoff->cprmask[i] = internal_a->cprmask[i];
372 /* Determine the machine architecture and type. */
375 ecoff_set_arch_mach_hook (abfd, filehdr)
379 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
380 enum bfd_architecture arch;
382 switch (internal_f->f_magic)
385 case MIPS_MAGIC_LITTLE:
387 arch = bfd_arch_mips;
391 arch = bfd_arch_obscure;
395 bfd_default_set_arch_mach (abfd, arch, (unsigned long) 0);
400 /* Get the section s_flags to use for a section. */
403 ecoff_sec_to_styp_flags (name, flags)
411 if (strcmp (name, _TEXT) == 0)
413 else if (strcmp (name, _DATA) == 0)
415 else if (strcmp (name, _SDATA) == 0)
417 else if (strcmp (name, _RDATA) == 0)
419 else if (strcmp (name, _LIT8) == 0)
421 else if (strcmp (name, _LIT4) == 0)
423 else if (strcmp (name, _BSS) == 0)
425 else if (strcmp (name, _SBSS) == 0)
427 else if (flags & SEC_CODE)
429 else if (flags & SEC_DATA)
431 else if (flags & SEC_READONLY)
433 else if (flags & SEC_LOAD)
438 if (flags & SEC_NEVER_LOAD)
444 /* Get the BFD flags to use for a section. */
447 ecoff_styp_to_sec_flags (abfd, hdr)
451 struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
452 long styp_flags = internal_s->s_flags;
453 flagword sec_flags=0;
455 if (styp_flags & STYP_NOLOAD)
456 sec_flags |= SEC_NEVER_LOAD;
458 /* For 386 COFF, at least, an unloadable text or data section is
459 actually a shared library section. */
460 if (styp_flags & STYP_TEXT)
462 if (sec_flags & SEC_NEVER_LOAD)
463 sec_flags |= SEC_CODE | SEC_SHARED_LIBRARY;
465 sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
467 else if ((styp_flags & STYP_DATA)
468 || (styp_flags & STYP_RDATA)
469 || (styp_flags & STYP_SDATA))
471 if (sec_flags & SEC_NEVER_LOAD)
472 sec_flags |= SEC_DATA | SEC_SHARED_LIBRARY;
474 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
475 if (styp_flags & STYP_RDATA)
476 sec_flags |= SEC_READONLY;
478 else if ((styp_flags & STYP_BSS)
479 || (styp_flags & STYP_SBSS))
481 sec_flags |= SEC_ALLOC;
483 else if (styp_flags & STYP_INFO)
485 sec_flags |= SEC_NEVER_LOAD;
487 else if ((styp_flags & STYP_LIT8)
488 || (styp_flags & STYP_LIT4))
490 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
494 sec_flags |= SEC_ALLOC | SEC_LOAD;
500 /* Read in and swap the important symbolic information for an ECOFF
504 ecoff_slurp_symbolic_info (abfd)
507 struct hdr_ext external_symhdr;
508 HDRR *internal_symhdr;
509 bfd_size_type raw_base;
510 bfd_size_type raw_size;
512 struct fdr_ext *fraw_src;
513 struct fdr_ext *fraw_end;
516 /* Check whether we've already gotten it, and whether there's any to
518 if (ecoff_data (abfd)->raw_syments != (PTR) NULL)
520 if (ecoff_data (abfd)->sym_filepos == 0)
522 bfd_get_symcount (abfd) = 0;
526 /* At this point bfd_get_symcount (abfd) holds the number of symbols
527 as read from the file header, but on ECOFF this is always the
528 size of the symbolic information header. It would be cleaner to
529 handle this when we first read the file in coffgen.c. */
530 if (bfd_get_symcount (abfd) != sizeof (external_symhdr))
532 bfd_error = bad_value;
536 /* Read the symbolic information header. */
537 if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) == -1
538 || (bfd_read ((PTR) &external_symhdr, sizeof (external_symhdr), 1, abfd)
539 != sizeof (external_symhdr)))
541 bfd_error = system_call_error;
544 internal_symhdr = &ecoff_data (abfd)->symbolic_header;
545 ecoff_swap_hdr_in (abfd, &external_symhdr, internal_symhdr);
547 if (internal_symhdr->magic != magicSym)
549 bfd_error = bad_value;
553 /* Now we can get the correct number of symbols. */
554 bfd_get_symcount (abfd) = (internal_symhdr->isymMax
555 + internal_symhdr->iextMax);
557 /* Read all the symbolic information at once. */
558 raw_base = ecoff_data (abfd)->sym_filepos + sizeof (struct hdr_ext);
560 if (internal_symhdr->cbExtOffset != 0)
561 raw_size = (internal_symhdr->cbExtOffset
563 + internal_symhdr->iextMax * sizeof (struct ext_ext));
566 long cbline, issmax, issextmax;
568 cbline = (internal_symhdr->cbLine + 3) &~ 3;
569 issmax = (internal_symhdr->issMax + 3) &~ 3;
570 issextmax = (internal_symhdr->issExtMax + 3) &~ 3;
571 raw_size = (cbline * sizeof (unsigned char)
572 + internal_symhdr->idnMax * sizeof (struct dnr_ext)
573 + internal_symhdr->ipdMax * sizeof (struct pdr_ext)
574 + internal_symhdr->isymMax * sizeof (struct sym_ext)
575 + internal_symhdr->ioptMax * sizeof (struct opt_ext)
576 + internal_symhdr->iauxMax * sizeof (union aux_ext)
577 + issmax * sizeof (char)
578 + issextmax * sizeof (char)
579 + internal_symhdr->ifdMax * sizeof (struct fdr_ext)
580 + internal_symhdr->crfd * sizeof (struct rfd_ext)
581 + internal_symhdr->iextMax * sizeof (struct ext_ext));
586 ecoff_data (abfd)->sym_filepos = 0;
589 raw = (PTR) bfd_alloc (abfd, raw_size);
592 bfd_error = no_memory;
595 if (bfd_read (raw, raw_size, 1, abfd) != raw_size)
597 bfd_error = system_call_error;
598 bfd_release (abfd, raw);
602 ecoff_data (abfd)->raw_size = raw_size;
603 ecoff_data (abfd)->raw_syments = raw;
605 /* Get pointers for the numeric offsets in the HDRR structure. */
606 #define FIX(off1, off2, type) \
607 if (internal_symhdr->off1 == 0) \
608 ecoff_data (abfd)->off2 = (type *) NULL; \
610 ecoff_data (abfd)->off2 = (type *) ((char *) raw \
611 + internal_symhdr->off1 \
613 FIX (cbLineOffset, line, unsigned char);
614 FIX (cbDnOffset, external_dnr, struct dnr_ext);
615 FIX (cbPdOffset, external_pdr, struct pdr_ext);
616 FIX (cbSymOffset, external_sym, struct sym_ext);
617 FIX (cbOptOffset, external_opt, struct opt_ext);
618 FIX (cbAuxOffset, external_aux, union aux_ext);
619 FIX (cbSsOffset, ss, char);
620 FIX (cbSsExtOffset, ssext, char);
621 FIX (cbFdOffset, external_fdr, struct fdr_ext);
622 FIX (cbRfdOffset, external_rfd, struct rfd_ext);
623 FIX (cbExtOffset, external_ext, struct ext_ext);
626 /* I don't want to always swap all the data, because it will just
627 waste time and most programs will never look at it. The only
628 time the linker needs most of the debugging information swapped
629 is when linking big-endian and little-endian MIPS object files
630 together, which is not a common occurrence.
632 We need to look at the fdr to deal with a lot of information in
633 the symbols, so we swap them here. */
634 ecoff_data (abfd)->fdr = (struct fdr *) bfd_alloc (abfd,
635 (internal_symhdr->ifdMax *
636 sizeof (struct fdr)));
637 if (ecoff_data (abfd)->fdr == NULL)
639 bfd_error = no_memory;
642 fdr_ptr = ecoff_data (abfd)->fdr;
643 fraw_src = ecoff_data (abfd)->external_fdr;
644 fraw_end = fraw_src + internal_symhdr->ifdMax;
645 for (; fraw_src < fraw_end; fraw_src++, fdr_ptr++)
646 ecoff_swap_fdr_in (abfd, fraw_src, fdr_ptr);
651 /* ECOFF symbol table routines. The ECOFF symbol table is described
652 in gcc/mips-tfile.c. */
654 /* ECOFF uses two common sections. One is the usual one, and the
655 other is for small objects. All the small objects are kept
656 together, and then referenced via the gp pointer, which yields
657 faster assembler code. This is what we use for the small common
659 static asection ecoff_scom_section;
660 static asymbol ecoff_scom_symbol;
661 static asymbol *ecoff_scom_symbol_ptr;
663 /* Create an empty symbol. */
666 ecoff_make_empty_symbol (abfd)
669 ecoff_symbol_type *new;
671 new = (ecoff_symbol_type *) bfd_alloc (abfd, sizeof (ecoff_symbol_type));
672 if (new == (ecoff_symbol_type *) NULL)
674 bfd_error = no_memory;
675 return (asymbol *) NULL;
677 new->symbol.section = (asection *) NULL;
678 new->fdr = (FDR *) NULL;
680 new->native.lnative = (struct sym_ext *) NULL;
681 new->symbol.the_bfd = abfd;
685 /* Set the BFD flags and section for an ECOFF symbol. */
688 ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext)
694 asym->the_bfd = abfd;
695 asym->value = ecoff_sym->value;
696 asym->section = &bfd_debug_section;
699 /* Most symbol types are just for debugging. */
700 switch (ecoff_sym->st)
711 asym->flags = BSF_DEBUGGING;
716 asym->flags = BSF_EXPORT | BSF_GLOBAL;
718 asym->flags = BSF_LOCAL;
719 switch (ecoff_sym->sc)
722 /* Used for compiler generated labels. Leave them in the
723 debugging section, and mark them as local. If BSF_DEBUGGING
724 is set, then nm does not display them for some reason. If no
725 flags are set then the linker whines about them. */
726 asym->flags = BSF_LOCAL;
729 asym->section = bfd_make_section_old_way (abfd, ".text");
730 asym->value -= asym->section->vma;
733 asym->section = bfd_make_section_old_way (abfd, ".data");
734 asym->value -= asym->section->vma;
739 asym->section = &bfd_com_section;
744 asym->section = bfd_make_section_old_way (abfd, ".bss");
745 asym->value -= asym->section->vma;
749 asym->flags = BSF_DEBUGGING;
752 asym->section = &bfd_abs_section;
755 asym->section = &bfd_und_section;
765 asym->flags = BSF_DEBUGGING;
768 asym->section = bfd_make_section_old_way (abfd, ".sdata");
769 asym->value -= asym->section->vma;
772 asym->section = bfd_make_section_old_way (abfd, ".sbss");
774 asym->value -= asym->section->vma;
777 asym->section = bfd_make_section_old_way (abfd, ".rdata");
778 asym->value -= asym->section->vma;
781 asym->flags = BSF_DEBUGGING;
784 /* FIXME: We should take a -G argument, which gives the maximum
785 size of objects to be put in the small common section. Until
786 we do, we put objects of sizes up to 8 in the small common
787 section. The assembler should do this for us, but the native
788 assembler seems to get confused. */
791 asym->section = &bfd_com_section;
796 if (ecoff_scom_section.name == NULL)
798 /* Initialize the small common section. */
799 ecoff_scom_section.name = SCOMMON;
800 ecoff_scom_section.flags = SEC_IS_COMMON;
801 ecoff_scom_section.output_section = &ecoff_scom_section;
802 ecoff_scom_section.symbol = &ecoff_scom_symbol;
803 ecoff_scom_section.symbol_ptr_ptr = &ecoff_scom_symbol_ptr;
804 ecoff_scom_symbol.name = SCOMMON;
805 ecoff_scom_symbol.flags = BSF_SECTION_SYM;
806 ecoff_scom_symbol.section = &ecoff_scom_section;
807 ecoff_scom_symbol_ptr = &ecoff_scom_symbol;
809 asym->section = &ecoff_scom_section;
814 asym->flags = BSF_DEBUGGING;
817 asym->section = &bfd_und_section;
822 asym->section = bfd_make_section_old_way (abfd, ".init");
823 asym->value -= asym->section->vma;
828 asym->flags = BSF_DEBUGGING;
831 asym->section = bfd_make_section_old_way (abfd, ".fini");
832 asym->value -= asym->section->vma;
839 /* Read an ECOFF symbol table. */
842 ecoff_slurp_symbol_table (abfd)
845 bfd_size_type internal_size;
846 ecoff_symbol_type *internal;
847 ecoff_symbol_type *internal_ptr;
848 struct ext_ext *eraw_src;
849 struct ext_ext *eraw_end;
853 /* If we've already read in the symbol table, do nothing. */
854 if (ecoff_data (abfd)->canonical_symbols != NULL)
857 /* Get the symbolic information. */
858 if (ecoff_slurp_symbolic_info (abfd) == false)
860 if (bfd_get_symcount (abfd) == 0)
863 internal_size = bfd_get_symcount (abfd) * sizeof (ecoff_symbol_type);
864 internal = (ecoff_symbol_type *) bfd_alloc (abfd, internal_size);
865 if (internal == NULL)
867 bfd_error = no_memory;
871 internal_ptr = internal;
872 eraw_src = ecoff_data (abfd)->external_ext;
873 eraw_end = eraw_src + ecoff_data (abfd)->symbolic_header.iextMax;
874 for (; eraw_src < eraw_end; eraw_src++, internal_ptr++)
878 ecoff_swap_ext_in (abfd, eraw_src, &internal_esym);
879 internal_ptr->symbol.name = (ecoff_data (abfd)->ssext
880 + internal_esym.asym.iss);
881 ecoff_set_symbol_info (abfd, &internal_esym.asym,
882 &internal_ptr->symbol, 1);
883 internal_ptr->fdr = ecoff_data (abfd)->fdr + internal_esym.ifd;
884 internal_ptr->local = false;
885 internal_ptr->native.enative = eraw_src;
888 /* The local symbols must be accessed via the fdr's, because the
889 string and aux indices are relative to the fdr information. */
890 fdr_ptr = ecoff_data (abfd)->fdr;
891 fdr_end = fdr_ptr + ecoff_data (abfd)->symbolic_header.ifdMax;
892 for (; fdr_ptr < fdr_end; fdr_ptr++)
894 struct sym_ext *lraw_src;
895 struct sym_ext *lraw_end;
897 lraw_src = ecoff_data (abfd)->external_sym + fdr_ptr->isymBase;
898 lraw_end = lraw_src + fdr_ptr->csym;
899 for (; lraw_src < lraw_end; lraw_src++, internal_ptr++)
903 ecoff_swap_sym_in (abfd, lraw_src, &internal_sym);
904 internal_ptr->symbol.name = (ecoff_data (abfd)->ss
907 ecoff_set_symbol_info (abfd, &internal_sym,
908 &internal_ptr->symbol, 0);
909 internal_ptr->fdr = fdr_ptr;
910 internal_ptr->local = true;
911 internal_ptr->native.lnative = lraw_src;
915 ecoff_data (abfd)->canonical_symbols = internal;
921 ecoff_get_symtab_upper_bound (abfd)
924 if (ecoff_slurp_symbolic_info (abfd) == false
925 || bfd_get_symcount (abfd) == 0)
928 return (bfd_get_symcount (abfd) + 1) * (sizeof (ecoff_symbol_type *));
932 ecoff_get_symtab (abfd, alocation)
936 unsigned int counter = 0;
937 ecoff_symbol_type *symbase;
938 ecoff_symbol_type **location = (ecoff_symbol_type **) alocation;
940 if (ecoff_slurp_symbol_table (abfd) == false
941 || bfd_get_symcount (abfd) == 0)
944 symbase = ecoff_data (abfd)->canonical_symbols;
945 while (counter < bfd_get_symcount (abfd))
947 *(location++) = symbase++;
950 *location++ = (ecoff_symbol_type *) NULL;
951 return bfd_get_symcount (abfd);
954 /* Turn ECOFF type information into a printable string.
955 ecoff_emit_aggregate and ecoff_type_to_string are from
956 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
958 /* Write aggregate information to a string. */
961 ecoff_emit_aggregate (abfd, string, rndx, isym, which)
969 int indx = rndx->index;
970 int sym_base, ss_base;
976 sym_base = ecoff_data (abfd)->fdr[ifd].isymBase;
977 ss_base = ecoff_data (abfd)->fdr[ifd].issBase;
979 if (indx == indexNil)
980 name = "/* no name */";
986 ecoff_swap_sym_in (abfd,
987 ecoff_data (abfd)->external_sym + indx,
989 name = ecoff_data (abfd)->ss + ss_base + sym.iss;
993 "%s %s { ifd = %d, index = %d }",
995 indx + ecoff_data (abfd)->symbolic_header.iextMax);
998 /* Convert the type information to string format. */
1001 ecoff_type_to_string (abfd, aux_ptr, indx, bigendian)
1003 union aux_ext *aux_ptr;
1015 unsigned int basic_type;
1017 static char buffer1[1024];
1018 static char buffer2[1024];
1023 for (i = 0; i < 7; i++)
1025 qualifiers[i].low_bound = 0;
1026 qualifiers[i].high_bound = 0;
1027 qualifiers[i].stride = 0;
1030 if (AUX_GET_ISYM (bigendian, &aux_ptr[indx]) == -1)
1031 return "-1 (no type)";
1032 ecoff_swap_tir_in (bigendian, &aux_ptr[indx++].a_ti, &u.ti);
1034 basic_type = u.ti.bt;
1035 qualifiers[0].type = u.ti.tq0;
1036 qualifiers[1].type = u.ti.tq1;
1037 qualifiers[2].type = u.ti.tq2;
1038 qualifiers[3].type = u.ti.tq3;
1039 qualifiers[4].type = u.ti.tq4;
1040 qualifiers[5].type = u.ti.tq5;
1041 qualifiers[6].type = tqNil;
1044 * Go get the basic type.
1048 case btNil: /* undefined */
1052 case btAdr: /* address - integer same size as pointer */
1053 strcpy (p1, "address");
1056 case btChar: /* character */
1057 strcpy (p1, "char");
1060 case btUChar: /* unsigned character */
1061 strcpy (p1, "unsigned char");
1064 case btShort: /* short */
1065 strcpy (p1, "short");
1068 case btUShort: /* unsigned short */
1069 strcpy (p1, "unsigned short");
1072 case btInt: /* int */
1076 case btUInt: /* unsigned int */
1077 strcpy (p1, "unsigned int");
1080 case btLong: /* long */
1081 strcpy (p1, "long");
1084 case btULong: /* unsigned long */
1085 strcpy (p1, "unsigned long");
1088 case btFloat: /* float (real) */
1089 strcpy (p1, "float");
1092 case btDouble: /* Double (real) */
1093 strcpy (p1, "double");
1096 /* Structures add 1-2 aux words:
1097 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1098 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1100 case btStruct: /* Structure (Record) */
1101 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1102 ecoff_emit_aggregate (abfd, p1, &rndx,
1103 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1105 indx++; /* skip aux words */
1108 /* Unions add 1-2 aux words:
1109 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1110 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1112 case btUnion: /* Union */
1113 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1114 ecoff_emit_aggregate (abfd, p1, &rndx,
1115 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1117 indx++; /* skip aux words */
1120 /* Enumerations add 1-2 aux words:
1121 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1122 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1124 case btEnum: /* Enumeration */
1125 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1126 ecoff_emit_aggregate (abfd, p1, &rndx,
1127 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1129 indx++; /* skip aux words */
1132 case btTypedef: /* defined via a typedef, isymRef points */
1133 strcpy (p1, "typedef");
1136 case btRange: /* subrange of int */
1137 strcpy (p1, "subrange");
1140 case btSet: /* pascal sets */
1144 case btComplex: /* fortran complex */
1145 strcpy (p1, "complex");
1148 case btDComplex: /* fortran double complex */
1149 strcpy (p1, "double complex");
1152 case btIndirect: /* forward or unnamed typedef */
1153 strcpy (p1, "forward/unamed typedef");
1156 case btFixedDec: /* Fixed Decimal */
1157 strcpy (p1, "fixed decimal");
1160 case btFloatDec: /* Float Decimal */
1161 strcpy (p1, "float decimal");
1164 case btString: /* Varying Length Character String */
1165 strcpy (p1, "string");
1168 case btBit: /* Aligned Bit String */
1172 case btPicture: /* Picture */
1173 strcpy (p1, "picture");
1176 case btVoid: /* Void */
1177 strcpy (p1, "void");
1181 sprintf (p1, "Unknown basic type %d", (int) basic_type);
1185 p1 += strlen (buffer1);
1188 * If this is a bitfield, get the bitsize.
1194 bitsize = AUX_GET_WIDTH (bigendian, &aux_ptr[indx++]);
1195 sprintf (p1, " : %d", bitsize);
1196 p1 += strlen (buffer1);
1201 * Deal with any qualifiers.
1203 if (qualifiers[0].type != tqNil)
1206 * Snarf up any array bounds in the correct order. Arrays
1207 * store 5 successive words in the aux. table:
1208 * word 0 RNDXR to type of the bounds (ie, int)
1209 * word 1 Current file descriptor index
1211 * word 3 high bound (or -1 if [])
1212 * word 4 stride size in bits
1214 for (i = 0; i < 7; i++)
1216 if (qualifiers[i].type == tqArray)
1218 qualifiers[i].low_bound =
1219 AUX_GET_DNLOW (bigendian, &aux_ptr[indx+2]);
1220 qualifiers[i].high_bound =
1221 AUX_GET_DNHIGH (bigendian, &aux_ptr[indx+3]);
1222 qualifiers[i].stride =
1223 AUX_GET_WIDTH (bigendian, &aux_ptr[indx+4]);
1229 * Now print out the qualifiers.
1231 for (i = 0; i < 6; i++)
1233 switch (qualifiers[i].type)
1240 strcpy (p2, "ptr to ");
1241 p2 += sizeof ("ptr to ")-1;
1245 strcpy (p2, "volatile ");
1246 p2 += sizeof ("volatile ")-1;
1250 strcpy (p2, "far ");
1251 p2 += sizeof ("far ")-1;
1255 strcpy (p2, "func. ret. ");
1256 p2 += sizeof ("func. ret. ");
1261 int first_array = i;
1264 /* Print array bounds reversed (ie, in the order the C
1265 programmer writes them). C is such a fun language.... */
1267 while (i < 5 && qualifiers[i+1].type == tqArray)
1270 for (j = i; j >= first_array; j--)
1272 strcpy (p2, "array [");
1273 p2 += sizeof ("array [")-1;
1274 if (qualifiers[j].low_bound != 0)
1276 "%ld:%ld {%ld bits}",
1277 (long) qualifiers[j].low_bound,
1278 (long) qualifiers[j].high_bound,
1279 (long) qualifiers[j].stride);
1281 else if (qualifiers[j].high_bound != -1)
1284 (long) (qualifiers[j].high_bound + 1),
1285 (long) (qualifiers[j].stride));
1288 sprintf (p2, " {%ld bits}", (long) (qualifiers[j].stride));
1291 strcpy (p2, "] of ");
1292 p2 += sizeof ("] of ")-1;
1300 strcpy (p2, buffer1);
1304 /* Print information about an ECOFF symbol. */
1307 ecoff_print_symbol (abfd, filep, symbol, how)
1311 bfd_print_symbol_type how;
1313 FILE *file = (FILE *)filep;
1317 case bfd_print_symbol_name:
1318 fprintf (file, "%s", symbol->name);
1320 case bfd_print_symbol_more:
1321 if (ecoffsymbol (symbol)->local)
1325 ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative,
1327 fprintf (file, "ecoff local %lx %x %x",
1328 (unsigned long) ecoff_sym.value,
1329 (unsigned) ecoff_sym.st, (unsigned) ecoff_sym.sc);
1335 ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative,
1337 fprintf (file, "ecoff extern %lx %x %x",
1338 (unsigned long) ecoff_ext.asym.value,
1339 (unsigned) ecoff_ext.asym.st,
1340 (unsigned) ecoff_ext.asym.sc);
1343 case bfd_print_symbol_nm:
1345 CONST char *section_name = symbol->section->name;
1347 bfd_print_symbol_vandf ((PTR) file, symbol);
1348 fprintf (file, " %-5s %s %s",
1350 ecoffsymbol (symbol)->local ? "l" : "e",
1354 case bfd_print_symbol_all:
1355 /* Print out the symbols in a reasonable way */
1364 if (ecoffsymbol (symbol)->local)
1366 ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative,
1369 pos = (ecoffsymbol (symbol)->native.lnative
1370 - ecoff_data (abfd)->external_sym
1371 + ecoff_data (abfd)->symbolic_header.iextMax);
1378 ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative,
1381 pos = (ecoffsymbol (symbol)->native.enative
1382 - ecoff_data (abfd)->external_ext);
1383 jmptbl = ecoff_ext.jmptbl ? 'j' : ' ';
1384 cobol_main = ecoff_ext.cobol_main ? 'c' : ' ';
1385 weakext = ecoff_ext.weakext ? 'w' : ' ';
1388 fprintf (file, "[%3d] %c %lx st %x sc %x indx %x %c%c%c %s",
1389 pos, type, (unsigned long) ecoff_ext.asym.value,
1390 (unsigned) ecoff_ext.asym.st,
1391 (unsigned) ecoff_ext.asym.sc,
1392 (unsigned) ecoff_ext.asym.index,
1393 jmptbl, cobol_main, weakext,
1396 if (ecoffsymbol (symbol)->fdr != NULL
1397 && ecoff_ext.asym.index != indexNil)
1402 union aux_ext *aux_base;
1404 indx = ecoff_ext.asym.index;
1406 /* sym_base is used to map the fdr relative indices which
1407 appear in the file to the position number which we are
1409 sym_base = ecoffsymbol (symbol)->fdr->isymBase;
1410 if (ecoffsymbol (symbol)->local)
1411 sym_base += ecoff_data (abfd)->symbolic_header.iextMax;
1413 /* aux_base is the start of the aux entries for this file;
1414 asym.index is an offset from this. */
1415 aux_base = (ecoff_data (abfd)->external_aux
1416 + ecoffsymbol (symbol)->fdr->iauxBase);
1418 /* The aux entries are stored in host byte order; the
1419 order is indicated by a bit in the fdr. */
1420 bigendian = ecoffsymbol (symbol)->fdr->fBigendian;
1422 /* This switch is basically from gcc/mips-tdump.c */
1423 switch (ecoff_ext.asym.st)
1431 printf ("\n End+1 symbol: %ld", indx + sym_base);
1435 if (ecoff_ext.asym.sc == scText
1436 || ecoff_ext.asym.sc == scInfo)
1437 printf ("\n First symbol: %ld", indx + sym_base);
1439 printf ("\n First symbol: %ld",
1440 (AUX_GET_ISYM (bigendian,
1441 &aux_base[ecoff_ext.asym.index])
1447 if (MIPS_IS_STAB (&ecoff_ext.asym))
1449 else if (ecoffsymbol (symbol)->local)
1450 printf ("\n End+1 symbol: %-7ld Type: %s",
1451 (AUX_GET_ISYM (bigendian,
1452 &aux_base[ecoff_ext.asym.index])
1454 ecoff_type_to_string (abfd, aux_base, indx + 1,
1457 printf ("\n Local symbol: %d",
1460 + ecoff_data (abfd)->symbolic_header.iextMax));
1464 if (!MIPS_IS_STAB (&ecoff_ext.asym))
1465 printf ("\n Type: %s",
1466 ecoff_type_to_string (abfd, aux_base, indx,
1476 /* Reloc handling. MIPS ECOFF relocs are packed into 8 bytes in
1477 external form. They use a bit which indicates whether the symbol
1480 /* Swap a reloc in. */
1483 ecoff_swap_reloc_in (abfd, ext, intern)
1486 struct internal_reloc *intern;
1488 intern->r_vaddr = bfd_h_get_32 (abfd, (bfd_byte *) ext->r_vaddr);
1489 if (abfd->xvec->header_byteorder_big_p != false)
1491 intern->r_symndx = (((int) ext->r_bits[0]
1492 << RELOC_BITS0_SYMNDX_SH_LEFT_BIG)
1493 | ((int) ext->r_bits[1]
1494 << RELOC_BITS1_SYMNDX_SH_LEFT_BIG)
1495 | ((int) ext->r_bits[2]
1496 << RELOC_BITS2_SYMNDX_SH_LEFT_BIG));
1497 intern->r_type = ((ext->r_bits[3] & RELOC_BITS3_TYPE_BIG)
1498 >> RELOC_BITS3_TYPE_SH_BIG);
1499 intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_BIG) != 0;
1503 intern->r_symndx = (((int) ext->r_bits[0]
1504 << RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE)
1505 | ((int) ext->r_bits[1]
1506 << RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE)
1507 | ((int) ext->r_bits[2]
1508 << RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE));
1509 intern->r_type = ((ext->r_bits[3] & RELOC_BITS3_TYPE_LITTLE)
1510 >> RELOC_BITS3_TYPE_SH_LITTLE);
1511 intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_LITTLE) != 0;
1515 /* Swap a reloc out. */
1518 ecoff_swap_reloc_out (abfd, src, dst)
1523 struct internal_reloc *intern = (struct internal_reloc *) src;
1524 RELOC *ext = (RELOC *) dst;
1526 bfd_h_put_32 (abfd, intern->r_vaddr, (bfd_byte *) ext->r_vaddr);
1527 if (abfd->xvec->header_byteorder_big_p != false)
1529 ext->r_bits[0] = intern->r_symndx >> RELOC_BITS0_SYMNDX_SH_LEFT_BIG;
1530 ext->r_bits[1] = intern->r_symndx >> RELOC_BITS1_SYMNDX_SH_LEFT_BIG;
1531 ext->r_bits[2] = intern->r_symndx >> RELOC_BITS2_SYMNDX_SH_LEFT_BIG;
1532 ext->r_bits[3] = (((intern->r_type << RELOC_BITS3_TYPE_SH_BIG)
1533 & RELOC_BITS3_TYPE_BIG)
1534 | (intern->r_extern ? RELOC_BITS3_EXTERN_BIG : 0));
1538 ext->r_bits[0] = intern->r_symndx >> RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE;
1539 ext->r_bits[1] = intern->r_symndx >> RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE;
1540 ext->r_bits[2] = intern->r_symndx >> RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE;
1541 ext->r_bits[3] = (((intern->r_type << RELOC_BITS3_TYPE_SH_LITTLE)
1542 & RELOC_BITS3_TYPE_LITTLE)
1543 | (intern->r_extern ? RELOC_BITS3_EXTERN_LITTLE : 0));
1549 /* ECOFF relocs are either against external symbols, or against
1550 sections. If we are producing relocateable output, and the reloc
1551 is against an external symbol, the resulting reloc will also be
1552 against the same symbol. In such a case, we don't want to change
1553 anything about the way the reloc is handled, since it will all be
1554 done at final link time. Rather than put special case code into
1555 bfd_perform_relocation, all the reloc types use this howto
1556 function. It just short circuits the reloc if producing
1557 relocateable output against an external symbol. */
1559 static bfd_reloc_status_type
1560 ecoff_generic_reloc (abfd,
1567 arelent *reloc_entry;
1570 asection *input_section;
1573 if (output_bfd != (bfd *) NULL
1574 && (symbol->flags & BSF_SECTION_SYM) == 0)
1576 reloc_entry->address += input_section->output_offset;
1577 return bfd_reloc_ok;
1580 return bfd_reloc_continue;
1583 /* Do a REFHI relocation. The next reloc must be the corresponding
1584 REFLO. This has to be done in a function so that carry is handled
1587 static bfd_reloc_status_type
1588 ecoff_refhi_reloc (abfd,
1595 arelent *reloc_entry;
1598 asection *input_section;
1601 bfd_reloc_status_type ret;
1606 unsigned long vallo;
1608 /* If we're relocating, and this an external symbol, we don't want
1609 to change anything. */
1610 if (output_bfd != (bfd *) NULL
1611 && (symbol->flags & BSF_SECTION_SYM) == 0)
1613 reloc_entry->address += input_section->output_offset;
1614 return bfd_reloc_ok;
1618 if (symbol->section == &bfd_und_section
1619 && output_bfd == (bfd *) NULL)
1620 ret = bfd_reloc_undefined;
1622 rello = reloc_entry + 1;
1623 BFD_ASSERT (rello->howto->type == ECOFF_R_REFLO
1624 && *rello->sym_ptr_ptr == *reloc_entry->sym_ptr_ptr);
1626 if (bfd_is_com_section (symbol->section))
1629 relocation = symbol->value;
1631 relocation += symbol->section->output_section->vma;
1632 relocation += symbol->section->output_offset;
1633 relocation += reloc_entry->addend;
1635 if (reloc_entry->address > input_section->_cooked_size)
1636 return bfd_reloc_outofrange;
1638 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1639 vallo = bfd_get_32 (abfd, (bfd_byte *) data + rello->address) & 0xffff;
1640 val = ((insn & 0xffff) << 16) + vallo;
1643 /* The low order 16 bits are always treated as a signed value.
1644 Therefore, a negative value in the low order bits requires an
1645 adjustment in the high order bits. We need to make this
1646 adjustment in two ways: once for the bits we took from the data,
1647 and once for the bits we are putting back in to the data. */
1648 if ((vallo & 0x8000) != 0)
1650 if ((val & 0x8000) != 0)
1653 insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
1654 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
1656 if (output_bfd != (bfd *) NULL)
1657 reloc_entry->address += input_section->output_offset;
1662 /* Do a GPREL relocation. This is a 16 bit value which must become
1663 the offset from the gp register. */
1665 static bfd_reloc_status_type
1666 ecoff_gprel_reloc (abfd,
1673 arelent *reloc_entry;
1676 asection *input_section;
1679 boolean relocateable;
1684 /* If we're relocating, and this an external symbol, we don't want
1685 to change anything. */
1686 if (output_bfd != (bfd *) NULL
1687 && (symbol->flags & BSF_SECTION_SYM) == 0)
1689 reloc_entry->address += input_section->output_offset;
1690 return bfd_reloc_ok;
1693 if (output_bfd != (bfd *) NULL)
1694 relocateable = true;
1697 relocateable = false;
1698 output_bfd = symbol->section->output_section->owner;
1701 if (symbol->section == &bfd_und_section
1702 && relocateable == false)
1703 return bfd_reloc_undefined;
1705 /* We have to figure out the gp value, so that we can adjust the
1706 symbol value correctly. We look up the symbol _gp in the output
1707 BFD. If we can't find it, we're stuck. We cache it in the ECOFF
1709 if (ecoff_data (output_bfd)->gp == 0)
1711 if (relocateable != false)
1713 /* Make up a value. */
1714 ecoff_data (output_bfd)->gp =
1715 symbol->section->output_section->vma + 0x4000;
1723 count = bfd_get_symcount (output_bfd);
1724 sym = bfd_get_outsymbols (output_bfd);
1726 /* We should do something more friendly here, but we don't
1727 have a good reloc status to return. */
1728 if (sym == (asymbol **) NULL)
1731 for (i = 0; i < count; i++, sym++)
1733 register CONST char *name;
1735 name = bfd_asymbol_name (*sym);
1736 if (*name == '_' && strcmp (name, "_gp") == 0)
1738 ecoff_data (output_bfd)->gp = bfd_asymbol_value (*sym);
1743 /* We should do something more friendly here, but we don't have
1744 a good reloc status to return. */
1750 if (bfd_is_com_section (symbol->section))
1753 relocation = symbol->value;
1755 relocation += symbol->section->output_section->vma;
1756 relocation += symbol->section->output_offset;
1758 if (reloc_entry->address > input_section->_cooked_size)
1759 return bfd_reloc_outofrange;
1761 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1763 /* Set val to the offset into the section (if we are relocating
1764 against an external symbol, insn & 0xffff will be zero and so
1765 will reloc_entry->addend). */
1766 val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff;
1770 /* Adjust val for the final section location and GP value. */
1771 val += (relocation - ecoff_data (output_bfd)->gp);
1773 insn = (insn &~ 0xffff) | (val & 0xffff);
1774 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
1776 if (relocateable != false)
1777 reloc_entry->address += input_section->output_offset;
1779 /* Make sure it fit in 16 bits. */
1780 if (val >= 0x8000 && val < 0xffff8000)
1781 return bfd_reloc_outofrange;
1783 return bfd_reloc_ok;
1786 /* How to process the various relocs types. */
1788 static reloc_howto_type ecoff_howto_table[] =
1790 /* Reloc type 0 is ignored. The reloc reading code ensures that
1791 this is a reference to the .abs section, which will cause
1792 bfd_perform_relocation to do nothing. */
1793 HOWTO (ECOFF_R_IGNORE, /* type */
1795 0, /* size (0 = byte, 1 = short, 2 = long) */
1796 8, /* bitsize (obsolete) */
1797 false, /* pc_relative */
1799 false, /* absolute (obsolete) */
1800 false, /* complain_on_overflow */
1801 0, /* special_function */
1802 "IGNORE", /* name */
1803 false, /* partial_inplace */
1806 false), /* pcrel_offset */
1808 /* A 16 bit reference to a symbol, normally from a data section. */
1809 HOWTO (ECOFF_R_REFHALF, /* type */
1811 1, /* size (0 = byte, 1 = short, 2 = long) */
1812 16, /* bitsize (obsolete) */
1813 false, /* pc_relative */
1815 false, /* absolute (obsolete) */
1816 true, /* complain_on_overflow */
1817 ecoff_generic_reloc, /* special_function */
1818 "REFHALF", /* name */
1819 true, /* partial_inplace */
1820 0xffff, /* src_mask */
1821 0xffff, /* dst_mask */
1822 false), /* pcrel_offset */
1824 /* A 32 bit reference to a symbol, normally from a data section. */
1825 HOWTO (ECOFF_R_REFWORD, /* type */
1827 2, /* size (0 = byte, 1 = short, 2 = long) */
1828 32, /* bitsize (obsolete) */
1829 false, /* pc_relative */
1831 false, /* absolute (obsolete) */
1832 true, /* complain_on_overflow */
1833 ecoff_generic_reloc, /* special_function */
1834 "REFWORD", /* name */
1835 true, /* partial_inplace */
1836 0xffffffff, /* src_mask */
1837 0xffffffff, /* dst_mask */
1838 false), /* pcrel_offset */
1840 /* A 26 bit absolute jump address. */
1841 HOWTO (ECOFF_R_JMPADDR, /* type */
1843 2, /* size (0 = byte, 1 = short, 2 = long) */
1844 32, /* bitsize (obsolete) */
1845 false, /* pc_relative */
1847 false, /* absolute (obsolete) */
1848 true, /* complain_on_overflow */
1849 ecoff_generic_reloc, /* special_function */
1850 "JMPADDR", /* name */
1851 true, /* partial_inplace */
1852 0x3ffffff, /* src_mask */
1853 0x3ffffff, /* dst_mask */
1854 false), /* pcrel_offset */
1856 /* The high 16 bits of a symbol value. Handled by the function
1857 ecoff_refhi_reloc. */
1858 HOWTO (ECOFF_R_REFHI, /* type */
1859 16, /* rightshift */
1860 2, /* size (0 = byte, 1 = short, 2 = long) */
1861 32, /* bitsize (obsolete) */
1862 false, /* pc_relative */
1864 false, /* absolute (obsolete) */
1865 true, /* complain_on_overflow */
1866 ecoff_refhi_reloc, /* special_function */
1868 true, /* partial_inplace */
1869 0xffff, /* src_mask */
1870 0xffff, /* dst_mask */
1871 false), /* pcrel_offset */
1873 /* The low 16 bits of a symbol value. */
1874 HOWTO (ECOFF_R_REFLO, /* type */
1876 2, /* size (0 = byte, 1 = short, 2 = long) */
1877 32, /* bitsize (obsolete) */
1878 false, /* pc_relative */
1880 false, /* absolute (obsolete) */
1881 true, /* complain_on_overflow */
1882 ecoff_generic_reloc, /* special_function */
1884 true, /* partial_inplace */
1885 0xffff, /* src_mask */
1886 0xffff, /* dst_mask */
1887 false), /* pcrel_offset */
1889 /* A reference to an offset from the gp register. Handled by the
1890 function ecoff_gprel_reloc. */
1891 HOWTO (ECOFF_R_GPREL, /* type */
1893 2, /* size (0 = byte, 1 = short, 2 = long) */
1894 32, /* bitsize (obsolete) */
1895 false, /* pc_relative */
1897 false, /* absolute (obsolete) */
1898 true, /* complain_on_overflow */
1899 ecoff_gprel_reloc, /* special_function */
1901 true, /* partial_inplace */
1902 0xffff, /* src_mask */
1903 0xffff, /* dst_mask */
1904 false), /* pcrel_offset */
1906 /* A reference to a literal using an offset from the gp register.
1907 Handled by the function ecoff_gprel_reloc. */
1908 HOWTO (ECOFF_R_LITERAL, /* type */
1910 2, /* size (0 = byte, 1 = short, 2 = long) */
1911 32, /* bitsize (obsolete) */
1912 false, /* pc_relative */
1914 false, /* absolute (obsolete) */
1915 true, /* complain_on_overflow */
1916 ecoff_gprel_reloc, /* special_function */
1917 "LITERAL", /* name */
1918 true, /* partial_inplace */
1919 0xffff, /* src_mask */
1920 0xffff, /* dst_mask */
1921 false) /* pcrel_offset */
1924 /* Read in the relocs for a section. */
1927 ecoff_slurp_reloc_table (abfd, section, symbols)
1932 RELOC *external_relocs;
1933 arelent *internal_relocs;
1937 if (section->relocation != (arelent *) NULL
1938 || section->reloc_count == 0
1939 || (section->flags & SEC_CONSTRUCTOR) != 0)
1942 if (ecoff_slurp_symbol_table (abfd) == false)
1945 internal_relocs = (arelent *) bfd_alloc (abfd,
1947 * section->reloc_count));
1948 external_relocs = (RELOC *) bfd_alloc (abfd, RELSZ * section->reloc_count);
1949 if (internal_relocs == (arelent *) NULL
1950 || external_relocs == (RELOC *) NULL)
1952 bfd_error = no_memory;
1955 if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0)
1957 if (bfd_read (external_relocs, 1, RELSZ * section->reloc_count, abfd)
1958 != RELSZ * section->reloc_count)
1960 bfd_error = system_call_error;
1964 for (i = 0, rptr = internal_relocs; i < section->reloc_count; i++, rptr++)
1966 struct internal_reloc intern;
1968 ecoff_swap_reloc_in (abfd, external_relocs + i, &intern);
1970 if (intern.r_type > ECOFF_R_LITERAL)
1973 if (intern.r_extern)
1975 /* r_symndx is an index into the external symbols. */
1976 BFD_ASSERT (intern.r_symndx >= 0
1978 < ecoff_data (abfd)->symbolic_header.iextMax));
1979 rptr->sym_ptr_ptr = symbols + intern.r_symndx;
1984 CONST char *sec_name;
1987 /* r_symndx is a section key. */
1988 switch (intern.r_symndx)
1990 case RELOC_SECTION_TEXT: sec_name = ".text"; break;
1991 case RELOC_SECTION_RDATA: sec_name = ".rdata"; break;
1992 case RELOC_SECTION_DATA: sec_name = ".data"; break;
1993 case RELOC_SECTION_SDATA: sec_name = ".sdata"; break;
1994 case RELOC_SECTION_SBSS: sec_name = ".sbss"; break;
1995 case RELOC_SECTION_BSS: sec_name = ".bss"; break;
1996 case RELOC_SECTION_INIT: sec_name = ".init"; break;
1997 case RELOC_SECTION_LIT8: sec_name = ".lit8"; break;
1998 case RELOC_SECTION_LIT4: sec_name = ".lit4"; break;
2002 sec = bfd_get_section_by_name (abfd, sec_name);
2003 if (sec == (asection *) NULL)
2005 rptr->sym_ptr_ptr = sec->symbol_ptr_ptr;
2007 rptr->addend = - bfd_get_section_vma (abfd, sec);
2008 if (intern.r_type == ECOFF_R_GPREL
2009 || intern.r_type == ECOFF_R_LITERAL)
2010 rptr->addend += ecoff_data (abfd)->gp;
2013 rptr->address = intern.r_vaddr - bfd_get_section_vma (abfd, section);
2014 rptr->howto = &ecoff_howto_table[intern.r_type];
2016 /* If the type is ECOFF_R_IGNORE, make sure this is a reference
2017 to the absolute section so that the reloc is ignored. */
2018 if (intern.r_type == ECOFF_R_IGNORE)
2019 rptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
2022 bfd_release (abfd, external_relocs);
2024 section->relocation = internal_relocs;
2029 /* Get a canonical list of relocs. */
2032 ecoff_canonicalize_reloc (abfd, section, relptr, symbols)
2040 if (section->flags & SEC_CONSTRUCTOR)
2042 arelent_chain *chain;
2044 /* This section has relocs made up by us, not the file, so take
2045 them out of their chain and place them into the data area
2047 for (count = 0, chain = section->constructor_chain;
2048 count < section->reloc_count;
2049 count++, chain = chain->next)
2050 *relptr++ = &chain->relent;
2056 if (ecoff_slurp_reloc_table (abfd, section, symbols) == false)
2059 tblptr = section->relocation;
2060 if (tblptr == (arelent *) NULL)
2063 for (count = 0; count < section->reloc_count; count++)
2064 *relptr++ = tblptr++;
2067 *relptr = (arelent *) NULL;
2069 return section->reloc_count;
2072 /* Provided a BFD, a section and an offset into the section, calculate
2073 and return the name of the source file and the line nearest to the
2077 ecoff_find_nearest_line (abfd,
2086 asymbol **ignore_symbols;
2088 CONST char **filename_ptr;
2089 CONST char **functionname_ptr;
2090 unsigned int *retline_ptr;
2096 struct pdr_ext *pdr_ptr;
2097 struct pdr_ext *pdr_end;
2099 unsigned char *line_ptr;
2100 unsigned char *line_end;
2103 /* If we're not in the .text section, we don't have any line
2105 if (strcmp (section->name, _TEXT) != 0
2106 || offset < ecoff_data (abfd)->text_start
2107 || offset >= ecoff_data (abfd)->text_end)
2110 /* Make sure we have the FDR's. */
2111 if (ecoff_slurp_symbolic_info (abfd) == false
2112 || bfd_get_symcount (abfd) == 0)
2115 /* Each file descriptor (FDR) has a memory address. Here we track
2116 down which FDR we want. The FDR's are stored in increasing
2117 memory order. If speed is ever important, this can become a
2118 binary search. We must ignore FDR's with no PDR entries; they
2119 will have the adr of the FDR before or after them. */
2120 fdr_start = ecoff_data (abfd)->fdr;
2121 fdr_end = fdr_start + ecoff_data (abfd)->symbolic_header.ifdMax;
2122 fdr_hold = (FDR *) NULL;
2123 for (fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
2125 if (fdr_ptr->cpd == 0)
2127 if (offset < fdr_ptr->adr)
2131 if (fdr_hold == (FDR *) NULL)
2135 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2136 have an address, which is relative to the FDR address, and are
2137 also stored in increasing memory order. */
2138 offset -= fdr_ptr->adr;
2139 pdr_ptr = ecoff_data (abfd)->external_pdr + fdr_ptr->ipdFirst;
2140 pdr_end = pdr_ptr + fdr_ptr->cpd;
2141 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
2142 if (offset < pdr.adr)
2144 for (pdr_ptr++; pdr_ptr < pdr_end; pdr_ptr++)
2146 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
2147 if (offset < pdr.adr)
2151 /* Now we can look for the actual line number. The line numbers are
2152 stored in a very funky format, which I won't try to describe.
2153 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2154 we want; we need this to compute line_end. */
2155 line_end = ecoff_data (abfd)->line;
2156 if (pdr_ptr == pdr_end)
2157 line_end += fdr_ptr->cbLineOffset + fdr_ptr->cbLine;
2159 line_end += fdr_ptr->cbLineOffset + pdr.cbLineOffset;
2161 /* Now change pdr and pdr_ptr to the one we want. */
2163 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
2167 line_ptr = (ecoff_data (abfd)->line
2168 + fdr_ptr->cbLineOffset
2169 + pdr.cbLineOffset);
2170 while (line_ptr < line_end)
2175 delta = *line_ptr >> 4;
2178 count = (*line_ptr & 0xf) + 1;
2182 delta = (((line_ptr[0]) & 0xff) << 8) + ((line_ptr[1]) & 0xff);
2183 if (delta >= 0x8000)
2188 if (offset < count * 4)
2190 offset -= count * 4;
2193 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2194 at least according to gdb/mipsread.c. */
2195 if (fdr_ptr->rss == -1)
2197 *filename_ptr = NULL;
2199 *functionname_ptr = NULL;
2204 ecoff_swap_ext_in (abfd,
2205 (ecoff_data (abfd)->external_ext
2208 *functionname_ptr = ecoff_data (abfd)->ssext + proc_ext.asym.iss;
2215 *filename_ptr = ecoff_data (abfd)->ss + fdr_ptr->issBase + fdr_ptr->rss;
2216 ecoff_swap_sym_in (abfd,
2217 (ecoff_data (abfd)->external_sym
2221 *functionname_ptr = (ecoff_data (abfd)->ss
2225 *retline_ptr = lineno;
2229 /* We can't use the generic linking routines for ECOFF, because we
2230 have to handle all the debugging information. The generic link
2231 routine just works out the section contents and attaches a list of
2234 We link by looping over all the seclets. We make two passes. On
2235 the first we set the actual section contents and determine the size
2236 of the debugging information. On the second we accumulate the
2237 debugging information and write it out.
2239 This currently always accumulates the debugging information, which
2240 is incorrect, because it ignores the -s and -S options of the
2241 linker. The linker needs to be modified to give us that
2242 information in a more useful format (currently it just provides a
2243 list of symbols which should appear in the output file). */
2245 /* Clear the output_has_begun flag for all the input BFD's. We use it
2246 to avoid linking in the debugging information for a BFD more than
2250 ecoff_clear_output_flags (abfd)
2253 register asection *o;
2254 register bfd_seclet_type *p;
2256 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2257 for (p = o->seclets_head;
2258 p != (bfd_seclet_type *) NULL;
2260 if (p->type == bfd_indirect_seclet)
2261 p->u.indirect.section->owner->output_has_begun = false;
2264 /* Handle an indirect seclet on the first pass. Set the contents of
2265 the output section, and accumulate the debugging information if
2269 ecoff_rel (output_bfd, seclet, output_section, data, relocateable)
2271 bfd_seclet_type *seclet;
2272 asection *output_section;
2274 boolean relocateable;
2277 HDRR *output_symhdr;
2280 if ((output_section->flags & SEC_HAS_CONTENTS)
2281 && !(output_section->flags & SEC_NEVER_LOAD)
2282 && (output_section->flags & SEC_LOAD)
2285 data = (PTR) bfd_get_relocated_section_contents (output_bfd,
2289 if (bfd_set_section_contents (output_bfd,
2300 input_bfd = seclet->u.indirect.section->owner;
2302 /* We want to figure out how much space will be required to
2303 incorporate all the debugging information from input_bfd. We use
2304 the output_has_begun field to avoid adding it in more than once.
2305 The actual incorporation is done in the second pass, in
2306 ecoff_get_debug. The code has to parallel that code in its
2307 manipulations of output_symhdr. */
2309 if (input_bfd->output_has_begun)
2311 input_bfd->output_has_begun = true;
2313 output_symhdr = &ecoff_data (output_bfd)->symbolic_header;
2315 if (input_bfd->xvec->flavour != bfd_target_ecoff_flavour)
2321 /* We just accumulate local symbols from a non-ECOFF BFD. The
2322 external symbols are handled separately. */
2324 symbols = (asymbol **) bfd_alloc (output_bfd,
2325 get_symtab_upper_bound (input_bfd));
2326 if (symbols == (asymbol **) NULL)
2328 bfd_error = no_memory;
2331 sym_end = symbols + bfd_canonicalize_symtab (input_bfd, symbols);
2333 for (sym_ptr = symbols; sym_ptr < sym_end; sym_ptr++)
2337 len = strlen ((*sym_ptr)->name);
2338 if (((*sym_ptr)->flags & BSF_EXPORT) == 0)
2340 ++output_symhdr->isymMax;
2341 output_symhdr->issMax += len + 1;
2345 bfd_release (output_bfd, (PTR) symbols);
2347 ++output_symhdr->ifdMax;
2352 /* We simply add in the information from another ECOFF BFD. First
2353 we make sure we have the symbolic information. */
2354 if (ecoff_slurp_symbol_table (input_bfd) == false)
2356 if (bfd_get_symcount (input_bfd) == 0)
2359 input_symhdr = &ecoff_data (input_bfd)->symbolic_header;
2361 /* Figure out how much information we are going to be putting in.
2362 The external symbols are handled separately. */
2363 output_symhdr->ilineMax += input_symhdr->ilineMax;
2364 output_symhdr->cbLine += input_symhdr->cbLine;
2365 output_symhdr->idnMax += input_symhdr->idnMax;
2366 output_symhdr->ipdMax += input_symhdr->ipdMax;
2367 output_symhdr->isymMax += input_symhdr->isymMax;
2368 output_symhdr->ioptMax += input_symhdr->ioptMax;
2369 output_symhdr->iauxMax += input_symhdr->iauxMax;
2370 output_symhdr->issMax += input_symhdr->issMax;
2371 output_symhdr->ifdMax += input_symhdr->ifdMax;
2373 /* The RFD's are special, since we create them if needed. */
2374 if (input_symhdr->crfd > 0)
2375 output_symhdr->crfd += input_symhdr->crfd;
2377 output_symhdr->crfd += input_symhdr->ifdMax;
2382 /* Handle an arbitrary seclet on the first pass. */
2385 ecoff_dump_seclet (abfd, seclet, section, data, relocateable)
2387 bfd_seclet_type *seclet;
2390 boolean relocateable;
2392 switch (seclet->type)
2394 case bfd_indirect_seclet:
2395 /* The contents of this section come from another one somewhere
2397 return ecoff_rel (abfd, seclet, section, data, relocateable);
2399 case bfd_fill_seclet:
2400 /* Fill in the section with fill.value. This is used to pad out
2401 sections, but we must avoid padding the .bss section. */
2402 if ((section->flags & SEC_HAS_CONTENTS) == 0)
2404 if (seclet->u.fill.value != 0)
2409 char *d = (char *) bfd_alloc (abfd, seclet->size);
2413 for (i = 0; i < seclet->size; i+=2)
2414 d[i] = seclet->u.fill.value >> 8;
2415 for (i = 1; i < seclet->size; i+=2)
2416 d[i] = seclet->u.fill.value;
2417 ret = bfd_set_section_contents (abfd, section, d, seclet->offset,
2419 bfd_release (abfd, (PTR) d);
2431 /* Add a string to the debugging information we are accumulating for a
2432 file. Return the offset from the fdr string base or from the
2433 external string base. */
2436 ecoff_add_string (output_bfd, fdr, string, external)
2446 symhdr = &ecoff_data (output_bfd)->symbolic_header;
2447 len = strlen (string);
2450 strcpy (ecoff_data (output_bfd)->ssext + symhdr->issExtMax, string);
2451 ret = symhdr->issExtMax;
2452 symhdr->issExtMax += len + 1;
2456 strcpy (ecoff_data (output_bfd)->ss + symhdr->issMax, string);
2458 symhdr->issMax += len + 1;
2459 fdr->cbSs += len + 1;
2464 /* Accumulate the debugging information from an input section. */
2467 ecoff_get_debug (output_bfd, seclet, section, relocateable)
2469 bfd_seclet_type *seclet;
2471 boolean relocateable;
2474 HDRR *output_symhdr;
2476 ecoff_data_type *output_ecoff;
2477 ecoff_data_type *input_ecoff;
2479 struct sym_ext *sym_out;
2480 ecoff_symbol_type *esym_ptr;
2481 ecoff_symbol_type *esym_end;
2484 struct fdr_ext *fdr_out;
2486 input_bfd = seclet->u.indirect.section->owner;
2488 /* Don't get the information more than once. */
2489 if (input_bfd->output_has_begun)
2491 input_bfd->output_has_begun = true;
2493 output_ecoff = ecoff_data (output_bfd);
2494 output_symhdr = &output_ecoff->symbolic_header;
2496 if (input_bfd->xvec->flavour != bfd_target_ecoff_flavour)
2503 /* This is not an ECOFF BFD. Just gather the symbols. */
2505 memset (&fdr, 0, sizeof fdr);
2507 fdr.adr = bfd_get_section_vma (output_bfd, section) + seclet->offset;
2508 fdr.issBase = output_symhdr->issMax;
2510 fdr.rss = ecoff_add_string (output_bfd,
2512 bfd_get_filename (input_bfd),
2514 fdr.isymBase = output_symhdr->isymMax;
2516 /* Get the local symbols from the input BFD. */
2517 symbols = (asymbol **) bfd_alloc (output_bfd,
2518 get_symtab_upper_bound (input_bfd));
2519 if (symbols == (asymbol **) NULL)
2521 bfd_error = no_memory;
2524 sym_end = symbols + bfd_canonicalize_symtab (input_bfd, symbols);
2526 /* Handle the local symbols. Any external symbols are handled
2529 for (sym_ptr = symbols; sym_ptr != sym_end; sym_ptr++)
2533 if (((*sym_ptr)->flags & BSF_EXPORT) != 0)
2535 memset (&internal_sym, 0, sizeof internal_sym);
2536 internal_sym.iss = ecoff_add_string (output_bfd,
2541 if (bfd_is_com_section ((*sym_ptr)->section)
2542 || (*sym_ptr)->section == &bfd_und_section)
2543 internal_sym.value = (*sym_ptr)->value;
2545 internal_sym.value = ((*sym_ptr)->value
2546 + (*sym_ptr)->section->output_offset
2547 + (*sym_ptr)->section->output_section->vma);
2548 internal_sym.st = stNil;
2549 internal_sym.sc = scUndefined;
2550 internal_sym.index = indexNil;
2551 ecoff_swap_sym_out (output_bfd, &internal_sym,
2552 (output_ecoff->external_sym
2553 + output_symhdr->isymMax));
2555 ++output_symhdr->isymMax;
2558 bfd_release (output_bfd, (PTR) symbols);
2560 /* Leave everything else in the FDR zeroed out. This will cause
2561 the lang field to be langC. The fBigendian field will
2562 indicate little endian format, but it doesn't matter because
2563 it only applies to aux fields and there are none. */
2565 ecoff_swap_fdr_out (output_bfd, &fdr,
2566 (output_ecoff->external_fdr
2567 + output_symhdr->ifdMax));
2568 ++output_symhdr->ifdMax;
2572 /* This is an ECOFF BFD. We want to grab the information from
2573 input_bfd and attach it to output_bfd. */
2574 count = bfd_get_symcount (input_bfd);
2577 input_ecoff = ecoff_data (input_bfd);
2578 input_symhdr = &input_ecoff->symbolic_header;
2580 /* I think that it is more efficient to simply copy the debugging
2581 information from the input BFD to the output BFD. Because ECOFF
2582 uses relative pointers for most of the debugging information,
2583 only a little of it has to be changed at all. */
2585 /* Swap in the local symbols, adjust their values, and swap them out
2586 again. The external symbols are handled separately. */
2587 sym_out = output_ecoff->external_sym + output_symhdr->isymMax;
2589 esym_ptr = ecoff_data (input_bfd)->canonical_symbols;
2590 esym_end = esym_ptr + count;
2591 for (; esym_ptr < esym_end; esym_ptr++)
2593 if (esym_ptr->local)
2597 ecoff_swap_sym_in (input_bfd, esym_ptr->native.lnative, &sym);
2599 /* If we're producing an executable, move common symbols
2601 if (relocateable == false)
2603 if (sym.sc == scCommon)
2605 else if (sym.sc == scSCommon)
2609 if (! bfd_is_com_section (esym_ptr->symbol.section)
2610 && (esym_ptr->symbol.flags & BSF_DEBUGGING) == 0
2611 && esym_ptr->symbol.section != &bfd_und_section)
2612 sym.value = (esym_ptr->symbol.value
2613 + esym_ptr->symbol.section->output_offset
2614 + esym_ptr->symbol.section->output_section->vma);
2615 ecoff_swap_sym_out (output_bfd, &sym, sym_out);
2620 /* That should have accounted for all the local symbols in
2622 BFD_ASSERT ((sym_out - output_ecoff->external_sym) - output_symhdr->isymMax
2623 == input_symhdr->isymMax);
2625 /* Copy the information that does not need swapping. */
2626 memcpy (output_ecoff->line + output_symhdr->cbLine,
2628 input_symhdr->cbLine * sizeof (unsigned char));
2629 memcpy (output_ecoff->external_aux + output_symhdr->iauxMax,
2630 input_ecoff->external_aux,
2631 input_symhdr->iauxMax * sizeof (union aux_ext));
2632 memcpy (output_ecoff->ss + output_symhdr->issMax,
2634 input_symhdr->issMax * sizeof (char));
2636 /* Some of the information may need to be swapped. */
2637 if (output_bfd->xvec->header_byteorder_big_p
2638 == input_bfd->xvec->header_byteorder_big_p)
2640 /* The two BFD's have the same endianness, so memcpy will
2642 memcpy (output_ecoff->external_dnr + output_symhdr->idnMax,
2643 input_ecoff->external_dnr,
2644 input_symhdr->idnMax * sizeof (struct dnr_ext));
2645 memcpy (output_ecoff->external_pdr + output_symhdr->ipdMax,
2646 input_ecoff->external_pdr,
2647 input_symhdr->ipdMax * sizeof (struct pdr_ext));
2648 memcpy (output_ecoff->external_opt + output_symhdr->ioptMax,
2649 input_ecoff->external_opt,
2650 input_symhdr->ioptMax * sizeof (struct opt_ext));
2654 struct dnr_ext *dnr_in;
2655 struct dnr_ext *dnr_end;
2656 struct dnr_ext *dnr_out;
2657 struct pdr_ext *pdr_in;
2658 struct pdr_ext *pdr_end;
2659 struct pdr_ext *pdr_out;
2660 struct opt_ext *opt_in;
2661 struct opt_ext *opt_end;
2662 struct opt_ext *opt_out;
2664 /* The two BFD's have different endianness, so we must swap
2665 everything in and out. This code would always work, but it
2666 would be slow in the normal case. */
2667 dnr_in = input_ecoff->external_dnr;
2668 dnr_end = dnr_in + input_symhdr->idnMax;
2669 dnr_out = output_ecoff->external_dnr + output_symhdr->idnMax;
2670 for (; dnr_in < dnr_end; dnr_in++, dnr_out++)
2674 ecoff_swap_dnr_in (input_bfd, dnr_in, &dnr);
2675 ecoff_swap_dnr_out (output_bfd, &dnr, dnr_out);
2677 pdr_in = input_ecoff->external_pdr;
2678 pdr_end = pdr_in + input_symhdr->ipdMax;
2679 pdr_out = output_ecoff->external_pdr + output_symhdr->ipdMax;
2680 for (; pdr_in < pdr_end; pdr_in++, pdr_out++)
2684 ecoff_swap_pdr_in (input_bfd, pdr_in, &pdr);
2685 ecoff_swap_pdr_out (output_bfd, &pdr, pdr_out);
2687 opt_in = input_ecoff->external_opt;
2688 opt_end = opt_in + input_symhdr->ioptMax;
2689 opt_out = output_ecoff->external_opt + output_symhdr->ioptMax;
2690 for (; opt_in < opt_end; opt_in++, opt_out++)
2694 ecoff_swap_opt_in (input_bfd, opt_in, &opt);
2695 ecoff_swap_opt_out (output_bfd, &opt, opt_out);
2699 /* Set ifdbase so that the external symbols know how to adjust their
2701 input_ecoff->ifdbase = output_symhdr->ifdMax;
2703 fdr_ptr = input_ecoff->fdr;
2704 fdr_end = fdr_ptr + input_symhdr->ifdMax;
2705 fdr_out = output_ecoff->external_fdr + output_symhdr->ifdMax;
2706 for (; fdr_ptr < fdr_end; fdr_ptr++, fdr_out++)
2712 /* The memory address for this fdr is the address for the seclet
2713 plus the offset to this fdr within input_bfd. */
2714 fdr.adr = (bfd_get_section_vma (output_bfd, section)
2716 + (fdr_ptr->adr - input_ecoff->fdr->adr));
2718 fdr.issBase += output_symhdr->issMax;
2719 fdr.isymBase += output_symhdr->isymMax;
2720 fdr.ilineBase += output_symhdr->ilineMax;
2721 fdr.ioptBase += output_symhdr->ioptMax;
2722 fdr.ipdFirst += output_symhdr->ipdMax;
2723 fdr.iauxBase += output_symhdr->iauxMax;
2724 fdr.rfdBase += output_symhdr->crfd;
2726 /* If there are no RFD's, we are going to add some. We don't
2727 want to adjust irfd for this, so that all the FDR's can share
2729 if (input_symhdr->crfd == 0)
2730 fdr.crfd = input_symhdr->ifdMax;
2732 if (fdr.cbLine != 0)
2733 fdr.cbLineOffset += output_symhdr->cbLine;
2735 ecoff_swap_fdr_out (output_bfd, &fdr, fdr_out);
2738 if (input_symhdr->crfd > 0)
2740 struct rfd_ext *rfd_in;
2741 struct rfd_ext *rfd_end;
2742 struct rfd_ext *rfd_out;
2744 /* Swap and adjust the RFD's. RFD's are only created by the
2745 linker, so this will only be necessary if one of the input
2746 files is the result of a partial link. Presumably all
2747 necessary RFD's are present. */
2748 rfd_in = input_ecoff->external_rfd;
2749 rfd_end = rfd_in + input_symhdr->crfd;
2750 rfd_out = output_ecoff->external_rfd + output_symhdr->crfd;
2751 for (; rfd_in < rfd_end; rfd_in++, rfd_out++)
2755 ecoff_swap_rfd_in (input_bfd, rfd_in, &rfd);
2756 rfd += output_symhdr->ifdMax;
2757 ecoff_swap_rfd_out (output_bfd, &rfd, rfd_out);
2759 output_symhdr->crfd += input_symhdr->crfd;
2763 struct rfd_ext *rfd_out;
2764 struct rfd_ext *rfd_end;
2767 /* Create RFD's. Some of the debugging information includes
2768 relative file indices. These indices are taken as indices to
2769 the RFD table if there is one, or to the global table if
2770 there is not. If we did not create RFD's, we would have to
2771 parse and adjust all the debugging information which contains
2773 rfd = output_symhdr->ifdMax;
2774 rfd_out = output_ecoff->external_rfd + output_symhdr->crfd;
2775 rfd_end = rfd_out + input_symhdr->ifdMax;
2776 for (; rfd_out < rfd_end; rfd_out++, rfd++)
2777 ecoff_swap_rfd_out (output_bfd, &rfd, rfd_out);
2778 output_symhdr->crfd += input_symhdr->ifdMax;
2781 /* Combine the register masks. */
2785 output_ecoff->gprmask |= input_ecoff->gprmask;
2786 for (i = 0; i < 4; i++)
2787 output_ecoff->cprmask[i] |= input_ecoff->cprmask[i];
2790 /* Update the counts. */
2791 output_symhdr->ilineMax += input_symhdr->ilineMax;
2792 output_symhdr->cbLine += input_symhdr->cbLine;
2793 output_symhdr->idnMax += input_symhdr->idnMax;
2794 output_symhdr->ipdMax += input_symhdr->ipdMax;
2795 output_symhdr->isymMax += input_symhdr->isymMax;
2796 output_symhdr->ioptMax += input_symhdr->ioptMax;
2797 output_symhdr->iauxMax += input_symhdr->iauxMax;
2798 output_symhdr->issMax += input_symhdr->issMax;
2799 output_symhdr->ifdMax += input_symhdr->ifdMax;
2804 /* This is the actual link routine. It makes two passes over all the
2808 ecoff_bfd_seclet_link (abfd, data, relocateable)
2811 boolean relocateable;
2815 register asection *o;
2816 register bfd_seclet_type *p;
2817 asymbol **sym_ptr_ptr;
2821 /* We accumulate the debugging information counts in the symbolic
2823 symhdr = &ecoff_data (abfd)->symbolic_header;
2824 symhdr->magic = magicSym;
2825 /* FIXME: What should the version stamp be? */
2827 symhdr->ilineMax = 0;
2831 symhdr->isymMax = 0;
2832 symhdr->ioptMax = 0;
2833 symhdr->iauxMax = 0;
2835 symhdr->issExtMax = 0;
2838 symhdr->iextMax = 0;
2840 /* We need to copy over the debugging symbols from each input BFD.
2841 When we do this copying, we have to adjust the text address in
2842 the FDR structures, so we have to know the text address used for
2843 the input BFD. Since we only want to copy the symbols once per
2844 input BFD, but we are going to look at each input BFD multiple
2845 times (once for each section it provides), we arrange to always
2846 look at the text section first. That means that when we copy the
2847 debugging information, we always know the text address. So we
2848 actually do each pass in two sub passes; first the text sections,
2849 then the non-text sections. We use the output_has_begun flag to
2850 determine whether we have copied over the debugging information
2853 /* Do the first pass: set the output section contents and count the
2854 debugging information. */
2855 ecoff_clear_output_flags (abfd);
2856 for (ipass = 0; ipass < 2; ipass++)
2858 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2860 /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false,
2861 so they are done on pass 0. For other sections the
2862 expression is true, so they are done on pass 1. */
2863 if (((o->flags & SEC_CODE) == 0) != ipass)
2866 for (p = o->seclets_head;
2867 p != (bfd_seclet_type *) NULL;
2870 if (ecoff_dump_seclet (abfd, p, o, data, relocateable)
2877 /* We handle the external symbols differently. We use the ones
2878 attached to the output_bfd. The linker will have already
2879 determined which symbols are to be attached. Here we just
2880 determine how much space we will need for them. */
2881 sym_ptr_ptr = bfd_get_outsymbols (abfd);
2882 if (sym_ptr_ptr != NULL)
2886 sym_end = sym_ptr_ptr + bfd_get_symcount (abfd);
2887 for (; sym_ptr_ptr < sym_end; sym_ptr_ptr++)
2889 if (((*sym_ptr_ptr)->flags & BSF_DEBUGGING) == 0
2890 && ((*sym_ptr_ptr)->flags & BSF_LOCAL) == 0)
2893 symhdr->issExtMax += strlen ((*sym_ptr_ptr)->name) + 1;
2898 /* Adjust the counts so that structures are longword aligned. */
2899 symhdr->cbLine = (symhdr->cbLine + 3) &~ 3;
2900 symhdr->issMax = (symhdr->issMax + 3) &~ 3;
2901 symhdr->issExtMax = (symhdr->issExtMax + 3) &~ 3;
2903 /* Now the counts in symhdr are the correct size for the debugging
2904 information. We allocate the right amount of space, and reset
2905 the counts so that the second pass can use them as indices. It
2906 would be possible to output the debugging information directly to
2907 the file in pass 2, rather than to build it in memory and then
2908 write it out. Outputting to the file would require a lot of
2909 seeks and small writes, though, and I think this approach is
2911 size = (symhdr->cbLine * sizeof (unsigned char)
2912 + symhdr->idnMax * sizeof (struct dnr_ext)
2913 + symhdr->ipdMax * sizeof (struct pdr_ext)
2914 + symhdr->isymMax * sizeof (struct sym_ext)
2915 + symhdr->ioptMax * sizeof (struct opt_ext)
2916 + symhdr->iauxMax * sizeof (union aux_ext)
2917 + symhdr->issMax * sizeof (char)
2918 + symhdr->issExtMax * sizeof (char)
2919 + symhdr->ifdMax * sizeof (struct fdr_ext)
2920 + symhdr->crfd * sizeof (struct rfd_ext)
2921 + symhdr->iextMax * sizeof (struct ext_ext));
2922 raw = (char *) bfd_alloc (abfd, size);
2923 if (raw == (char *) NULL)
2925 bfd_error = no_memory;
2928 ecoff_data (abfd)->raw_size = size;
2929 ecoff_data (abfd)->raw_syments = (PTR) raw;
2931 /* Initialize the raw pointers. */
2932 #define SET(field, count, type) \
2933 ecoff_data (abfd)->field = (type *) raw; \
2934 raw += symhdr->count * sizeof (type)
2936 SET (line, cbLine, unsigned char);
2937 SET (external_dnr, idnMax, struct dnr_ext);
2938 SET (external_pdr, ipdMax, struct pdr_ext);
2939 SET (external_sym, isymMax, struct sym_ext);
2940 SET (external_opt, ioptMax, struct opt_ext);
2941 SET (external_aux, iauxMax, union aux_ext);
2942 SET (ss, issMax, char);
2943 SET (ssext, issExtMax, char);
2944 SET (external_fdr, ifdMax, struct fdr_ext);
2945 SET (external_rfd, crfd, struct rfd_ext);
2946 SET (external_ext, iextMax, struct ext_ext);
2949 /* Reset the counts so the second pass can use them to know how far
2951 symhdr->ilineMax = 0;
2955 symhdr->isymMax = 0;
2956 symhdr->ioptMax = 0;
2957 symhdr->iauxMax = 0;
2959 symhdr->issExtMax = 0;
2962 symhdr->iextMax = 0;
2964 /* Do the second pass: accumulate the debugging information. */
2965 ecoff_clear_output_flags (abfd);
2966 for (ipass = 0; ipass < 2; ipass++)
2968 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2970 if (((o->flags & SEC_CODE) == 0) != ipass)
2972 for (p = o->seclets_head;
2973 p != (bfd_seclet_type *) NULL;
2976 if (p->type == bfd_indirect_seclet)
2978 if (ecoff_get_debug (abfd, p, o, relocateable) == false)
2985 /* Put in the external symbols. */
2986 sym_ptr_ptr = bfd_get_outsymbols (abfd);
2987 if (sym_ptr_ptr != NULL)
2990 struct ext_ext *external_ext;
2992 ssext = ecoff_data (abfd)->ssext;
2993 external_ext = ecoff_data (abfd)->external_ext;
2994 for (; *sym_ptr_ptr != NULL; sym_ptr_ptr++)
2999 sym_ptr = *sym_ptr_ptr;
3001 if ((sym_ptr->flags & BSF_DEBUGGING) != 0
3002 || (sym_ptr->flags & BSF_LOCAL) != 0)
3005 /* The enative pointer can be NULL for a symbol created by
3006 the linker via ecoff_make_empty_symbol. */
3007 if (bfd_asymbol_flavour (sym_ptr) != bfd_target_ecoff_flavour
3008 || (((ecoff_symbol_type *) sym_ptr)->native.enative
3009 == (struct ext_ext *) NULL))
3012 esym.cobol_main = 0;
3016 /* FIXME: we can do better than this for st and sc. */
3017 esym.asym.st = stGlobal;
3018 esym.asym.sc = scAbs;
3019 esym.asym.reserved = 0;
3020 esym.asym.index = indexNil;
3024 ecoff_symbol_type *ecoff_sym_ptr;
3026 ecoff_sym_ptr = (ecoff_symbol_type *) sym_ptr;
3027 if (ecoff_sym_ptr->local)
3029 ecoff_swap_ext_in (abfd, ecoff_sym_ptr->native.enative, &esym);
3031 /* If we're producing an executable, move common symbols
3033 if (relocateable == false)
3035 if (esym.asym.sc == scCommon)
3036 esym.asym.sc = scBss;
3037 else if (esym.asym.sc == scSCommon)
3038 esym.asym.sc = scSBss;
3041 /* Adjust the FDR index for the symbol by that used for
3043 esym.ifd += ecoff_data (bfd_asymbol_bfd (sym_ptr))->ifdbase;
3046 esym.asym.iss = symhdr->issExtMax;
3048 if (bfd_is_com_section (sym_ptr->section)
3049 || sym_ptr->section == &bfd_und_section)
3050 esym.asym.value = sym_ptr->value;
3052 esym.asym.value = (sym_ptr->value
3053 + sym_ptr->section->output_offset
3054 + sym_ptr->section->output_section->vma);
3056 ecoff_swap_ext_out (abfd, &esym, external_ext + symhdr->iextMax);
3058 ecoff_set_sym_index (sym_ptr, symhdr->iextMax);
3062 strcpy (ssext + symhdr->issExtMax, sym_ptr->name);
3063 symhdr->issExtMax += strlen (sym_ptr->name) + 1;
3067 /* Adjust the counts so that structures are longword aligned. */
3068 symhdr->cbLine = (symhdr->cbLine + 3) &~ 3;
3069 symhdr->issMax = (symhdr->issMax + 3) &~ 3;
3070 symhdr->issExtMax = (symhdr->issExtMax + 3) &~ 3;
3075 /* Set the architecture. The only architecture we support here is
3076 mips. We set the architecture anyhow, since many callers ignore
3077 the return value. */
3080 ecoff_set_arch_mach (abfd, arch, machine)
3082 enum bfd_architecture arch;
3083 unsigned long machine;
3085 bfd_default_set_arch_mach (abfd, arch, machine);
3086 return arch == bfd_arch_mips;
3089 /* Get the size of the section headers. We do not output the .scommon
3090 section which we created in ecoff_mkobject. */
3093 ecoff_sizeof_headers (abfd, reloc)
3097 return FILHSZ + AOUTSZ + (abfd->section_count - 1) * SCNHSZ;
3100 /* Calculate the file position for each section, and set
3104 ecoff_compute_section_file_positions (abfd)
3112 if (bfd_get_start_address (abfd))
3113 abfd->flags |= EXEC_P;
3115 sofar = ecoff_sizeof_headers (abfd, false);
3118 for (current = abfd->sections;
3119 current != (asection *) NULL;
3120 current = current->next)
3122 /* Only deal with sections which have contents */
3123 if (! (current->flags & SEC_HAS_CONTENTS)
3124 || strcmp (current->name, SCOMMON) == 0)
3127 /* On Ultrix, the data sections in an executable file must be
3128 aligned to a page boundary within the file. This does not
3129 affect the section size, though. FIXME: Does this work for
3131 if ((abfd->flags & EXEC_P) != 0
3132 && first_data != false
3133 && (current->flags & SEC_CODE) == 0)
3135 sofar = (sofar + PAGE_SIZE - 1) &~ (PAGE_SIZE - 1);
3139 /* Align the sections in the file to the same boundary on
3140 which they are aligned in virtual memory. */
3142 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
3144 current->filepos = sofar;
3146 sofar += current->_raw_size;
3148 /* make sure that this section is of the right size too */
3150 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
3151 current->_raw_size += sofar - old_sofar;
3154 ecoff_data (abfd)->reloc_filepos = sofar;
3157 /* Set the contents of a section. */
3160 ecoff_set_section_contents (abfd, section, location, offset, count)
3165 bfd_size_type count;
3167 if (abfd->output_has_begun == false)
3168 ecoff_compute_section_file_positions (abfd);
3170 bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET);
3173 return (bfd_write (location, 1, count, abfd) == count) ? true : false;
3178 /* Write out an ECOFF file. */
3181 ecoff_write_object_contents (abfd)
3187 file_ptr reloc_base;
3189 unsigned long reloc_size;
3190 unsigned long text_size;
3191 unsigned long text_start;
3192 unsigned long data_size;
3193 unsigned long data_start;
3194 unsigned long bss_size;
3195 struct internal_filehdr internal_f;
3196 struct internal_aouthdr internal_a;
3199 bfd_error = system_call_error;
3201 if(abfd->output_has_begun == false)
3202 ecoff_compute_section_file_positions(abfd);
3204 if (abfd->sections != (asection *) NULL)
3205 scn_base = abfd->sections->filepos;
3208 reloc_base = ecoff_data (abfd)->reloc_filepos;
3212 for (current = abfd->sections;
3213 current != (asection *)NULL;
3214 current = current->next)
3216 if (strcmp (current->name, SCOMMON) == 0)
3218 current->target_index = count;
3220 if (current->reloc_count != 0)
3222 bfd_size_type relsize;
3224 current->rel_filepos = reloc_base;
3225 relsize = current->reloc_count * RELSZ;
3226 reloc_size += relsize;
3227 reloc_base += relsize;
3230 current->rel_filepos = 0;
3233 sym_base = reloc_base + reloc_size;
3235 /* At least on Ultrix, the symbol table of an executable file must
3236 be aligned to a page boundary. FIXME: Is this true on other
3238 if ((abfd->flags & EXEC_P) != 0)
3239 sym_base = (sym_base + PAGE_SIZE - 1) &~ (PAGE_SIZE - 1);
3241 ecoff_data (abfd)->sym_filepos = sym_base;
3243 text_size = ecoff_sizeof_headers (abfd, false);
3249 /* Write section headers to the file. */
3251 internal_f.f_nscns = 0;
3252 if (bfd_seek (abfd, (file_ptr) (FILHSZ + AOUTSZ), SEEK_SET) != 0)
3254 for (current = abfd->sections;
3255 current != (asection *) NULL;
3256 current = current->next)
3258 struct internal_scnhdr section;
3261 if (strcmp (current->name, SCOMMON) == 0)
3263 BFD_ASSERT (bfd_get_section_size_before_reloc (current) == 0
3264 && current->reloc_count == 0);
3268 ++internal_f.f_nscns;
3270 strncpy (section.s_name, current->name, sizeof section.s_name);
3272 /* FIXME: is this correct for shared libraries? I think it is
3273 but I have no platform to check. Ian Lance Taylor. */
3274 vma = bfd_get_section_vma (abfd, current);
3275 if (strcmp (current->name, _LIB) == 0)
3276 section.s_vaddr = 0;
3278 section.s_vaddr = vma;
3280 section.s_paddr = vma;
3281 section.s_size = bfd_get_section_size_before_reloc (current);
3283 /* If this section has no size or is unloadable then the scnptr
3285 if (current->_raw_size == 0
3286 || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3287 section.s_scnptr = 0;
3289 section.s_scnptr = current->filepos;
3290 section.s_relptr = current->rel_filepos;
3292 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
3293 object file produced by the assembler is supposed to point to
3294 information about how much room is required by objects of
3295 various different sizes. I think this only matters if we
3296 want the linker to compute the best size to use, or
3297 something. I don't know what happens if the information is
3299 section.s_lnnoptr = 0;
3301 section.s_nreloc = current->reloc_count;
3302 section.s_nlnno = 0;
3303 section.s_flags = ecoff_sec_to_styp_flags (current->name,
3309 ecoff_swap_scnhdr_out (abfd, (PTR) §ion, (PTR) &buff);
3310 if (bfd_write ((PTR) &buff, 1, SCNHSZ, abfd) != SCNHSZ)
3314 if ((section.s_flags & STYP_TEXT) != 0)
3316 text_size += bfd_get_section_size_before_reloc (current);
3317 if (text_start == 0 || text_start > vma)
3320 else if ((section.s_flags & STYP_RDATA) != 0
3321 || (section.s_flags & STYP_DATA) != 0
3322 || (section.s_flags & STYP_LIT8) != 0
3323 || (section.s_flags & STYP_LIT4) != 0
3324 || (section.s_flags & STYP_SDATA) != 0)
3326 data_size += bfd_get_section_size_before_reloc (current);
3327 if (data_start == 0 || data_start > vma)
3330 else if ((section.s_flags & STYP_BSS) != 0
3331 || (section.s_flags & STYP_SBSS) != 0)
3332 bss_size += bfd_get_section_size_before_reloc (current);
3335 /* Set up the file header. */
3337 if (abfd->xvec->header_byteorder_big_p != false)
3338 internal_f.f_magic = MIPS_MAGIC_BIG;
3340 internal_f.f_magic = MIPS_MAGIC_LITTLE;
3343 We will NOT put a fucking timestamp in the header here. Every time you
3344 put it back, I will come in and take it out again. I'm sorry. This
3345 field does not belong here. We fill it with a 0 so it compares the
3346 same but is not a reasonable time. -- gnu@cygnus.com
3348 internal_f.f_timdat = 0;
3350 if (bfd_get_symcount (abfd) != 0)
3352 /* The ECOFF f_nsyms field is not actually the number of
3353 symbols, it's the size of symbolic information header. */
3354 internal_f.f_nsyms = sizeof (struct hdr_ext);
3355 internal_f.f_symptr = sym_base;
3359 internal_f.f_nsyms = 0;
3360 internal_f.f_symptr = 0;
3363 internal_f.f_opthdr = AOUTSZ;
3365 internal_f.f_flags = F_LNNO;
3366 if (reloc_size == 0)
3367 internal_f.f_flags |= F_RELFLG;
3368 if (bfd_get_symcount (abfd) == 0)
3369 internal_f.f_flags |= F_LSYMS;
3370 if (abfd->flags & EXEC_P)
3371 internal_f.f_flags |= F_EXEC;
3373 if (! abfd->xvec->byteorder_big_p)
3374 internal_f.f_flags |= F_AR32WR;
3376 internal_f.f_flags |= F_AR32W;
3378 /* Set up the ``optional'' header. */
3379 internal_a.magic = ZMAGIC;
3381 /* FIXME: This is what Ultrix puts in, and it makes the Ultrix
3382 linker happy. But, is it right? */
3383 internal_a.vstamp = 0x20a;
3385 /* At least on Ultrix, these have to be rounded to page boundaries.
3386 FIXME: Is this true on other platforms? */
3387 internal_a.tsize = (text_size + PAGE_SIZE - 1) &~ (PAGE_SIZE - 1);
3388 internal_a.text_start = text_start &~ (PAGE_SIZE - 1);
3389 internal_a.dsize = (data_size + PAGE_SIZE - 1) &~ (PAGE_SIZE - 1);
3390 internal_a.data_start = data_start &~ (PAGE_SIZE - 1);
3392 /* On Ultrix, the initial portions of the .sbss and .bss segments
3393 are at the end of the data section. The bsize field in the
3394 optional header records how many bss bytes are required beyond
3395 those in the data section. The value is not rounded to a page
3397 if (bss_size < internal_a.dsize - data_size)
3400 bss_size -= internal_a.dsize - data_size;
3401 internal_a.bsize = bss_size;
3402 internal_a.bss_start = internal_a.data_start + internal_a.dsize;
3404 internal_a.entry = bfd_get_start_address (abfd);
3406 internal_a.gp_value = ecoff_data (abfd)->gp;
3408 internal_a.gprmask = ecoff_data (abfd)->gprmask;
3409 for (i = 0; i < 4; i++)
3410 internal_a.cprmask[i] = ecoff_data (abfd)->cprmask[i];
3412 /* Write out the file header and the optional header. */
3414 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3419 ecoff_swap_filehdr_out (abfd, (PTR) &internal_f, (PTR) &buff);
3420 if (bfd_write ((PTR) &buff, 1, FILHSZ, abfd) != FILHSZ)
3427 ecoff_swap_aouthdr_out (abfd, (PTR) &internal_a, (PTR) &buff);
3428 if (bfd_write ((PTR) &buff, 1, AOUTSZ, abfd) != AOUTSZ)
3432 /* Write out the relocs. */
3433 for (current = abfd->sections;
3434 current != (asection *) NULL;
3435 current = current->next)
3438 arelent **reloc_ptr_ptr;
3439 arelent **reloc_end;
3442 if (current->reloc_count == 0)
3445 buff = (RELOC *) bfd_alloc (abfd, current->reloc_count * RELSZ);
3446 if (buff == (RELOC *) NULL)
3448 bfd_error = no_memory;
3452 reloc_ptr_ptr = current->orelocation;
3453 reloc_end = reloc_ptr_ptr + current->reloc_count;
3455 for (; reloc_ptr_ptr < reloc_end; reloc_ptr_ptr++, out_ptr++)
3459 struct internal_reloc in;
3461 memset (&in, 0, sizeof in);
3463 reloc = *reloc_ptr_ptr;
3464 sym = *reloc->sym_ptr_ptr;
3466 in.r_vaddr = reloc->address + bfd_get_section_vma (abfd, current);
3467 in.r_type = reloc->howto->type;
3468 if ((sym->flags & BSF_SECTION_SYM) == 0)
3470 in.r_symndx = ecoff_get_sym_index (*reloc->sym_ptr_ptr);
3477 name = bfd_get_section_name (abfd, bfd_get_section (sym));
3478 if (strcmp (name, ".text") == 0)
3479 in.r_symndx = RELOC_SECTION_TEXT;
3480 else if (strcmp (name, ".rdata") == 0)
3481 in.r_symndx = RELOC_SECTION_RDATA;
3482 else if (strcmp (name, ".data") == 0)
3483 in.r_symndx = RELOC_SECTION_DATA;
3484 else if (strcmp (name, ".sdata") == 0)
3485 in.r_symndx = RELOC_SECTION_SDATA;
3486 else if (strcmp (name, ".sbss") == 0)
3487 in.r_symndx = RELOC_SECTION_SBSS;
3488 else if (strcmp (name, ".bss") == 0)
3489 in.r_symndx = RELOC_SECTION_BSS;
3490 else if (strcmp (name, ".init") == 0)
3491 in.r_symndx = RELOC_SECTION_INIT;
3492 else if (strcmp (name, ".lit8") == 0)
3493 in.r_symndx = RELOC_SECTION_LIT8;
3494 else if (strcmp (name, ".lit4") == 0)
3495 in.r_symndx = RELOC_SECTION_LIT4;
3501 ecoff_swap_reloc_out (abfd, (PTR) &in, (PTR) out_ptr);
3504 if (bfd_seek (abfd, current->rel_filepos, SEEK_SET) != 0)
3506 if (bfd_write ((PTR) buff, RELSZ, current->reloc_count, abfd)
3507 != RELSZ * current->reloc_count)
3509 bfd_release (abfd, (PTR) buff);
3512 /* Write out the symbolic debugging information. */
3513 if (bfd_get_symcount (abfd) > 0)
3516 unsigned long sym_offset;
3517 struct hdr_ext buff;
3519 /* Set up the offsets in the symbolic header. */
3520 symhdr = &ecoff_data (abfd)->symbolic_header;
3521 sym_offset = ecoff_data (abfd)->sym_filepos + sizeof (struct hdr_ext);
3523 #define SET(offset, size, ptr) \
3524 if (symhdr->size == 0) \
3525 symhdr->offset = 0; \
3527 symhdr->offset = (((char *) ecoff_data (abfd)->ptr \
3528 - (char *) ecoff_data (abfd)->raw_syments) \
3531 SET (cbLineOffset, cbLine, line);
3532 SET (cbDnOffset, idnMax, external_dnr);
3533 SET (cbPdOffset, ipdMax, external_pdr);
3534 SET (cbSymOffset, isymMax, external_sym);
3535 SET (cbOptOffset, ioptMax, external_opt);
3536 SET (cbAuxOffset, iauxMax, external_aux);
3537 SET (cbSsOffset, issMax, ss);
3538 SET (cbSsExtOffset, issExtMax, ssext);
3539 SET (cbFdOffset, ifdMax, external_fdr);
3540 SET (cbRfdOffset, crfd, external_rfd);
3541 SET (cbExtOffset, iextMax, external_ext);
3544 if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos,
3547 ecoff_swap_hdr_out (abfd, &ecoff_data (abfd)->symbolic_header, &buff);
3548 if (bfd_write ((PTR) &buff, 1, sizeof buff, abfd) != sizeof buff)
3550 if (bfd_write ((PTR) ecoff_data (abfd)->raw_syments, 1,
3551 ecoff_data (abfd)->raw_size, abfd)
3552 != ecoff_data (abfd)->raw_size)
3559 /* Archive handling. ECOFF uses what appears to be a unique type of
3560 archive header (which I call an armap). The byte ordering of the
3561 armap and the contents are encoded in the name of the armap itself.
3562 At least for now, we only support archives with the same byte
3563 ordering in the armap and the contents.
3565 The first four bytes in the armap are the number of symbol
3566 definitions. This is always a power of two.
3568 This is followed by the symbol definitions. Each symbol definition
3569 occupies 8 bytes. The first four bytes are the offset from the
3570 start of the armap strings to the null-terminated string naming
3571 this symbol. The second four bytes are the file offset to the
3572 archive member which defines this symbol. If the second four bytes
3573 are 0, then this is not actually a symbol definition, and it should
3576 The symbols are hashed into the armap with a closed hashing scheme.
3577 See the functions below for the details of the algorithm.
3579 We could use the hash table when looking up symbols in a library.
3580 This would require a new BFD target entry point to replace the
3581 bfd_get_next_mapent function used by the linker.
3583 After the symbol definitions comes four bytes holding the size of
3584 the string table, followed by the string table itself. */
3586 /* The name of an archive headers looks like this:
3587 __________E[BL]E[BL]_ (with a trailing space).
3588 The trailing space is changed to an X if the archive is changed to
3589 indicate that the armap is out of date. */
3591 #define ARMAP_BIG_ENDIAN 'B'
3592 #define ARMAP_LITTLE_ENDIAN 'L'
3593 #define ARMAP_MARKER 'E'
3594 #define ARMAP_START "__________"
3595 #define ARMAP_HEADER_MARKER_INDEX 10
3596 #define ARMAP_HEADER_ENDIAN_INDEX 11
3597 #define ARMAP_OBJECT_MARKER_INDEX 12
3598 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3599 #define ARMAP_END_INDEX 14
3600 #define ARMAP_END "_ "
3602 /* This is a magic number used in the hashing algorithm. */
3603 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3605 /* This returns the hash value to use for a string. It also sets
3606 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3607 is the number of entries in the hash table, and HLOG is the log
3611 ecoff_armap_hash (s, rehash, size, hlog)
3613 unsigned int *rehash;
3621 hash = ((hash >> 27) | (hash << 5)) + *s++;
3622 hash *= ARMAP_HASH_MAGIC;
3623 *rehash = (hash & (size - 1)) | 1;
3624 return hash >> (32 - hlog);
3627 /* Read in the armap. */
3630 ecoff_slurp_armap (abfd)
3635 struct areltdata *mapdata;
3636 bfd_size_type parsed_size;
3638 struct artdata *ardata;
3641 struct symdef *symdef_ptr;
3644 /* Get the name of the first element. */
3645 i = bfd_read ((PTR) nextname, 1, 16, abfd);
3651 bfd_seek (abfd, (file_ptr) -16, SEEK_CUR);
3653 /* See if the first element is an armap. */
3654 if (strncmp (nextname, ARMAP_START, sizeof ARMAP_START - 1) != 0
3655 || nextname[ARMAP_HEADER_MARKER_INDEX] != ARMAP_MARKER
3656 || (nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
3657 && nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
3658 || nextname[ARMAP_OBJECT_MARKER_INDEX] != ARMAP_MARKER
3659 || (nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
3660 && nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
3661 || strncmp (nextname + ARMAP_END_INDEX,
3662 ARMAP_END, sizeof ARMAP_END - 1) != 0)
3664 bfd_has_map (abfd) = false;
3668 /* Make sure we have the right byte ordering. */
3669 if (((nextname[ARMAP_HEADER_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
3670 ^ (abfd->xvec->header_byteorder_big_p != false))
3671 || ((nextname[ARMAP_OBJECT_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
3672 ^ (abfd->xvec->byteorder_big_p != false)))
3674 bfd_error = wrong_format;
3678 /* Read in the armap. */
3679 ardata = bfd_ardata (abfd);
3680 mapdata = snarf_ar_hdr (abfd);
3681 if (mapdata == (struct areltdata *) NULL)
3683 parsed_size = mapdata->parsed_size;
3684 bfd_release (abfd, (PTR) mapdata);
3686 raw_armap = (char *) bfd_alloc (abfd, parsed_size);
3687 if (raw_armap == (char *) NULL)
3689 bfd_error = no_memory;
3693 if (bfd_read ((PTR) raw_armap, 1, parsed_size, abfd) != parsed_size)
3695 bfd_error = malformed_archive;
3696 bfd_release (abfd, (PTR) raw_armap);
3700 count = bfd_h_get_32 (abfd, (PTR) raw_armap);
3702 ardata->symdef_count = 0;
3703 ardata->cache = (struct ar_cache *) NULL;
3705 /* Hack: overlay the symdefs on top of the raw archive data. This
3706 is the way do_slurp_bsd_armap works. */
3707 raw_ptr = raw_armap + LONG_SIZE;
3708 symdef_ptr = (struct symdef *) raw_ptr;
3709 ardata->symdefs = (carsym *) symdef_ptr;
3710 stringbase = raw_ptr + count * (2 * LONG_SIZE) + LONG_SIZE;
3712 #ifdef CHECK_ARMAP_HASH
3716 /* Double check that I have the hashing algorithm right by making
3717 sure that every symbol can be looked up successfully. */
3719 for (i = 1; i < count; i <<= 1)
3721 BFD_ASSERT (i == count);
3723 for (i = 0; i < count; i++, raw_ptr += 2 * LONG_SIZE)
3725 unsigned int name_offset, file_offset;
3726 unsigned int hash, rehash, srch;
3728 name_offset = bfd_h_get_32 (abfd, (PTR) raw_ptr);
3729 file_offset = bfd_h_get_32 (abfd, (PTR) (raw_ptr + LONG_SIZE));
3730 if (file_offset == 0)
3732 hash = ecoff_armap_hash (stringbase + name_offset, &rehash, count,
3737 /* See if we can rehash to this location. */
3738 for (srch = (hash + rehash) & (count - 1);
3739 srch != hash && srch != i;
3740 srch = (srch + rehash) & (count - 1))
3741 BFD_ASSERT (bfd_h_get_32 (abfd,
3744 + (srch * 2 * LONG_SIZE)
3747 BFD_ASSERT (srch == i);
3751 raw_ptr = raw_armap + LONG_SIZE;
3752 #endif /* CHECK_ARMAP_HASH */
3754 for (i = 0; i < count; i++, raw_ptr += 2 * LONG_SIZE)
3756 unsigned int name_offset, file_offset;
3758 name_offset = bfd_h_get_32 (abfd, (PTR) raw_ptr);
3759 file_offset = bfd_h_get_32 (abfd, (PTR) (raw_ptr + LONG_SIZE));
3760 if (file_offset == 0)
3762 symdef_ptr->s.name = stringbase + name_offset;
3763 symdef_ptr->file_offset = file_offset;
3765 ++ardata->symdef_count;
3768 ardata->first_file_filepos = bfd_tell (abfd);
3769 /* Pad to an even boundary. */
3770 ardata->first_file_filepos += ardata->first_file_filepos % 2;
3772 bfd_has_map (abfd) = true;
3777 /* Write out an armap. */
3780 ecoff_write_armap (abfd, elength, map, orl_count, stridx)
3782 unsigned int elength;
3784 unsigned int orl_count;
3787 unsigned int hashsize, hashlog;
3788 unsigned int symdefsize;
3790 unsigned int stringsize;
3791 unsigned int mapsize;
3794 struct stat statbuf;
3796 bfd_byte temp[LONG_SIZE];
3797 bfd_byte *hashtable;
3801 /* Ultrix appears to use as a hash table size the least power of two
3802 greater than twice the number of entries. */
3803 for (hashlog = 0; (1 << hashlog) <= 2 * orl_count; hashlog++)
3805 hashsize = 1 << hashlog;
3807 symdefsize = hashsize * 2 * LONG_SIZE;
3809 stringsize = stridx + padit;
3811 /* Include 8 bytes to store symdefsize and stringsize in output. */
3812 mapsize = LONG_SIZE + symdefsize + stringsize + LONG_SIZE;
3814 firstreal = SARMAG + sizeof (struct ar_hdr) + mapsize + elength;
3816 memset ((PTR) &hdr, 0, sizeof hdr);
3818 /* Work out the ECOFF armap name. */
3819 strcpy (hdr.ar_name, ARMAP_START);
3820 hdr.ar_name[ARMAP_HEADER_MARKER_INDEX] = ARMAP_MARKER;
3821 hdr.ar_name[ARMAP_HEADER_ENDIAN_INDEX] =
3822 (abfd->xvec->header_byteorder_big_p
3824 : ARMAP_LITTLE_ENDIAN);
3825 hdr.ar_name[ARMAP_OBJECT_MARKER_INDEX] = ARMAP_MARKER;
3826 hdr.ar_name[ARMAP_OBJECT_ENDIAN_INDEX] =
3827 abfd->xvec->byteorder_big_p ? ARMAP_BIG_ENDIAN : ARMAP_LITTLE_ENDIAN;
3828 memcpy (hdr.ar_name + ARMAP_END_INDEX, ARMAP_END, sizeof ARMAP_END - 1);
3830 /* Write the timestamp of the archive header to be just a little bit
3831 later than the timestamp of the file, otherwise the linker will
3832 complain that the index is out of date. Actually, the Ultrix
3833 linker just checks the archive name; the GNU linker may check the
3835 stat (abfd->filename, &statbuf);
3836 sprintf (hdr.ar_date, "%ld", (long) (statbuf.st_mtime + 60));
3838 /* The DECstation uses zeroes for the uid, gid and mode of the
3840 hdr.ar_uid[0] = '0';
3841 hdr.ar_gid[0] = '0';
3842 hdr.ar_mode[0] = '0';
3844 sprintf (hdr.ar_size, "%-10d", (int) mapsize);
3846 hdr.ar_fmag[0] = '`';
3847 hdr.ar_fmag[1] = '\n';
3849 /* Turn all null bytes in the header into spaces. */
3850 for (i = 0; i < sizeof (struct ar_hdr); i++)
3851 if (((char *)(&hdr))[i] == '\0')
3852 (((char *)(&hdr))[i]) = ' ';
3854 if (bfd_write ((PTR) &hdr, 1, sizeof (struct ar_hdr), abfd)
3855 != sizeof (struct ar_hdr))
3858 bfd_h_put_32 (abfd, hashsize, temp);
3859 if (bfd_write (temp, 1, LONG_SIZE, abfd) != LONG_SIZE)
3862 hashtable = (bfd_byte *) bfd_zalloc (abfd, symdefsize);
3864 current = abfd->archive_head;
3866 for (i = 0; i < orl_count; i++)
3868 unsigned int hash, rehash;
3870 /* Advance firstreal to the file position of this archive
3872 if (((bfd *) map[i].pos) != last_elt)
3876 firstreal += arelt_size (current) + sizeof (struct ar_hdr);
3877 firstreal += firstreal % 2;
3878 current = current->next;
3880 while (current != (bfd *) map[i].pos);
3885 hash = ecoff_armap_hash (*map[i].name, &rehash, hashsize, hashlog);
3886 if (bfd_h_get_32 (abfd, (PTR) (hashtable
3887 + (hash * 2 * LONG_SIZE)
3893 /* The desired slot is already taken. */
3894 for (srch = (hash + rehash) & (hashsize - 1);
3896 srch = (srch + rehash) & (hashsize - 1))
3897 if (bfd_h_get_32 (abfd, (PTR) (hashtable
3898 + (srch * 2 * LONG_SIZE)
3903 BFD_ASSERT (srch != hash);
3908 bfd_h_put_32 (abfd, map[i].namidx,
3909 (PTR) (hashtable + hash * 2 * LONG_SIZE));
3910 bfd_h_put_32 (abfd, firstreal,
3911 (PTR) (hashtable + hash * 2 * LONG_SIZE + LONG_SIZE));
3914 if (bfd_write (hashtable, 1, symdefsize, abfd) != symdefsize)
3917 bfd_release (abfd, hashtable);
3919 /* Now write the strings. */
3920 bfd_h_put_32 (abfd, stringsize, temp);
3921 if (bfd_write (temp, 1, LONG_SIZE, abfd) != LONG_SIZE)
3923 for (i = 0; i < orl_count; i++)
3927 len = strlen (*map[i].name) + 1;
3928 if (bfd_write ((PTR) (*map[i].name), 1, len, abfd) != len)
3932 /* The spec sez this should be a newline. But in order to be
3933 bug-compatible for DECstation ar we use a null. */
3936 if (bfd_write ("\0", 1, 1, abfd) != 1)
3943 /* We just use the generic extended name support. This is a GNU
3945 #define ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table
3947 /* See whether this BFD is an archive. If it is, read in the armap
3948 and the extended name table. */
3951 ecoff_archive_p (abfd)
3954 char armag[SARMAG + 1];
3956 if (bfd_read ((PTR) armag, 1, SARMAG, abfd) != SARMAG
3957 || strncmp (armag, ARMAG, SARMAG) != 0)
3959 bfd_error = wrong_format;
3960 return (bfd_target *) NULL;
3963 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3964 involves a cast, we can't do it as the left operand of
3966 abfd->tdata.aout_ar_data =
3967 (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata));
3969 if (bfd_ardata (abfd) == (struct artdata *) NULL)
3971 bfd_error = no_memory;
3972 return (bfd_target *) NULL;
3975 bfd_ardata (abfd)->first_file_filepos = SARMAG;
3977 if (ecoff_slurp_armap (abfd) == false
3978 || ecoff_slurp_extended_name_table (abfd) == false)
3980 bfd_release (abfd, bfd_ardata (abfd));
3981 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
3982 return (bfd_target *) NULL;
3988 /* This is the COFF backend structure. The backend_data field of the
3989 bfd_target structure is set to this. The section reading code in
3990 coffgen.c uses this structure. */
3992 static CONST bfd_coff_backend_data bfd_ecoff_std_swap_table = {
3993 (void (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_in */
3994 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_in */
3995 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_in */
3996 (unsigned (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_out */
3997 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_out */
3998 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_out */
3999 ecoff_swap_reloc_out, ecoff_swap_filehdr_out, ecoff_swap_aouthdr_out,
4000 ecoff_swap_scnhdr_out,
4001 FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, true,
4002 ecoff_swap_filehdr_in, ecoff_swap_aouthdr_in, ecoff_swap_scnhdr_in,
4003 ecoff_bad_format_hook, ecoff_set_arch_mach_hook, ecoff_mkobject_hook,
4004 ecoff_styp_to_sec_flags, ecoff_make_section_hook, ecoff_set_alignment_hook,
4005 ecoff_slurp_symbol_table
4008 /* get_lineno could be written for ECOFF, but it would currently only
4009 be useful for linking ECOFF and COFF files together, which doesn't
4011 #define ecoff_get_lineno \
4012 ((alent *(*) PARAMS ((bfd *, asymbol *))) bfd_nullvoidptr)
4014 /* These bfd_target functions are defined in other files. */
4016 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
4017 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
4018 #define ecoff_core_file_matches_executable_p \
4019 _bfd_dummy_core_file_matches_executable_p
4020 #define ecoff_truncate_arname bfd_dont_truncate_arname
4021 #define ecoff_openr_next_archived_file bfd_generic_openr_next_archived_file
4022 #define ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt
4023 #define ecoff_get_section_contents bfd_generic_get_section_contents
4024 #define ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound
4025 #define ecoff_close_and_cleanup bfd_generic_close_and_cleanup
4026 #define ecoff_bfd_debug_info_start bfd_void
4027 #define ecoff_bfd_debug_info_end bfd_void
4028 #define ecoff_bfd_debug_info_accumulate \
4029 ((void (*) PARAMS ((bfd *, struct sec *))) bfd_void)
4030 #define ecoff_bfd_get_relocated_section_contents \
4031 bfd_generic_get_relocated_section_contents
4032 #define ecoff_bfd_relax_section bfd_generic_relax_section
4034 bfd_target ecoff_little_vec =
4036 "ecoff-littlemips", /* name */
4037 bfd_target_ecoff_flavour,
4038 false, /* data byte order is little */
4039 false, /* header byte order is little */
4041 (HAS_RELOC | EXEC_P | /* object flags */
4042 HAS_LINENO | HAS_DEBUG |
4043 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
4045 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect
4047 0, /* leading underscore */
4048 '/', /* ar_pad_char */
4049 15, /* ar_max_namelen */
4050 3, /* minimum alignment power */
4051 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
4052 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
4054 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
4055 ecoff_archive_p, _bfd_dummy_target},
4056 {bfd_false, ecoff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
4058 {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */
4059 _bfd_write_archive_contents, bfd_false},
4062 (PTR) &bfd_ecoff_std_swap_table
4065 bfd_target ecoff_big_vec =
4067 "ecoff-bigmips", /* name */
4068 bfd_target_ecoff_flavour,
4069 true, /* data byte order is big */
4070 true, /* header byte order is big */
4072 (HAS_RELOC | EXEC_P | /* object flags */
4073 HAS_LINENO | HAS_DEBUG |
4074 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
4076 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect flags */
4077 0, /* leading underscore */
4078 ' ', /* ar_pad_char */
4079 16, /* ar_max_namelen */
4080 3, /* minimum alignment power */
4081 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16,
4082 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16,
4083 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
4084 ecoff_archive_p, _bfd_dummy_target},
4085 {bfd_false, ecoff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
4087 {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */
4088 _bfd_write_archive_contents, bfd_false},
4091 (PTR) &bfd_ecoff_std_swap_table
4092 /* Note that there is another bfd_target just above this one. If
4093 you are adding initializers here, you should be adding them there