1 /* BFD back-end for MIPS Extended-Coff files.
2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3 Original version by Per Bothner.
4 Full support added by Ian Lance Taylor, ian@cygnus.com.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "aout/ranlib.h"
28 #include "coff/mips.h"
29 #include "coff/internal.h"
31 #include "coff/symconst.h"
32 #include "coff/ecoff-ext.h"
36 /* Each canonical asymbol really looks like this. */
38 typedef struct ecoff_symbol_struct
40 /* The actual symbol which the rest of BFD works with */
43 /* The fdr for this symbol. */
46 /* true if this is a local symbol rather than an external one. */
49 /* A pointer to the unswapped hidden information for this symbol */
52 struct sym_ext *lnative;
53 struct ext_ext *enative;
58 /* We take the address of the first element of a asymbol to ensure that the
59 macro is only ever applied to an asymbol. */
60 #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd)))
62 /* This is a hack borrowed from coffcode.h; we need to save the index
63 of a symbol when we write it out so that can set the symbol index
64 correctly when we write out the relocs. */
65 #define ecoff_get_sym_index(symbol) ((unsigned long) (symbol)->udata)
66 #define ecoff_set_sym_index(symbol, idx) ((symbol)->udata = (PTR) (idx))
68 /* The page boundary used to align sections in the executable file. */
69 #define PAGE_SIZE 0x2000
71 /* The linker needs a section to hold small common variables while
72 linking. There is no convenient way to create it when the linker
73 needs it, so we always create one for each BFD. We then avoid
75 #define SCOMMON ".scommon"
77 /* MIPS ECOFF has COFF sections, but the debugging information is
78 stored in a completely different format. This files uses the some
79 of the swapping routines from coffswap.h, and some of the generic
80 COFF routines in coffgen.c, but, unlike the real COFF targets, does
81 not use coffcode.h itself. */
83 /* Prototypes for static functions. */
85 static boolean ecoff_bad_format_hook PARAMS ((bfd *abfd, PTR filehdr));
86 static asection *ecoff_make_section_hook PARAMS ((bfd *abfd, char *name));
87 static boolean ecoff_new_section_hook PARAMS ((bfd *abfd, asection *section));
88 static boolean ecoff_mkobject PARAMS ((bfd *abfd));
89 static PTR ecoff_mkobject_hook PARAMS ((bfd *abfd, PTR filehdr, PTR aouthdr));
90 static boolean ecoff_set_arch_mach_hook PARAMS ((bfd *abfd, PTR filehdr));
91 static long ecoff_sec_to_styp_flags PARAMS ((CONST char *name,
93 static flagword ecoff_styp_to_sec_flags PARAMS ((bfd *abfd, PTR hdr));
94 static asymbol *ecoff_make_empty_symbol PARAMS ((bfd *abfd));
95 static void ecoff_set_symbol_info PARAMS ((bfd *abfd, SYMR *ecoff_sym,
96 asymbol *asym, int ext));
97 static boolean ecoff_slurp_symbol_table PARAMS ((bfd *abfd));
98 static unsigned int ecoff_get_symtab_upper_bound PARAMS ((bfd *abfd));
99 static unsigned int ecoff_get_symtab PARAMS ((bfd *abfd,
100 asymbol **alocation));
101 static void ecoff_emit_aggregate PARAMS ((bfd *abfd, char *string,
102 RNDXR *rndx, long isym,
104 static char *ecoff_type_to_string PARAMS ((bfd *abfd, union aux_ext *aux_ptr,
105 int indx, int bigendian));
106 static void ecoff_print_symbol PARAMS ((bfd *abfd, PTR filep,
108 bfd_print_symbol_type how));
109 static void ecoff_swap_reloc_in PARAMS ((bfd *abfd, RELOC *ext,
110 struct internal_reloc *intern));
111 static unsigned int ecoff_swap_reloc_out PARAMS ((bfd *abfd, PTR src,
113 static bfd_reloc_status_type ecoff_generic_reloc PARAMS ((bfd *abfd,
119 static bfd_reloc_status_type ecoff_refhi_reloc PARAMS ((bfd *abfd,
125 static bfd_reloc_status_type ecoff_gprel_reloc PARAMS ((bfd *abfd,
131 static boolean ecoff_slurp_reloc_table PARAMS ((bfd *abfd, asection *section,
133 static unsigned int ecoff_canonicalize_reloc PARAMS ((bfd *abfd,
137 static CONST struct reloc_howto_struct *ecoff_bfd_reloc_type_lookup
138 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
139 static boolean ecoff_find_nearest_line PARAMS ((bfd *abfd,
143 CONST char **filename_ptr,
144 CONST char **fnname_ptr,
145 unsigned int *retline_ptr));
146 static void ecoff_clear_output_flags PARAMS ((bfd *abfd));
147 static boolean ecoff_rel PARAMS ((bfd *output_bfd, bfd_seclet_type *seclet,
148 asection *output_section, PTR data,
149 boolean relocateable));
150 static boolean ecoff_dump_seclet PARAMS ((bfd *abfd, bfd_seclet_type *seclet,
151 asection *section, PTR data,
152 boolean relocateable));
153 static long ecoff_add_string PARAMS ((bfd *output_bfd, FDR *fdr,
154 CONST char *string, boolean external));
155 static boolean ecoff_get_debug PARAMS ((bfd *output_bfd,
156 bfd_seclet_type *seclet,
158 boolean relocateable));
159 static boolean ecoff_bfd_seclet_link PARAMS ((bfd *abfd, PTR data,
160 boolean relocateable));
161 static boolean ecoff_set_arch_mach PARAMS ((bfd *abfd,
162 enum bfd_architecture arch,
163 unsigned long machine));
164 static int ecoff_sizeof_headers PARAMS ((bfd *abfd, boolean reloc));
165 static void ecoff_compute_section_file_positions PARAMS ((bfd *abfd));
166 static boolean ecoff_set_section_contents PARAMS ((bfd *abfd,
170 bfd_size_type count));
171 static boolean ecoff_write_object_contents PARAMS ((bfd *abfd));
172 static unsigned int ecoff_armap_hash PARAMS ((CONST char *s,
173 unsigned int *rehash,
176 static boolean ecoff_slurp_armap PARAMS ((bfd *abfd));
177 static boolean ecoff_write_armap PARAMS ((bfd *abfd, unsigned int elength,
179 unsigned int orl_count,
181 static bfd_target *ecoff_archive_p PARAMS ((bfd *abfd));
183 /* Get the generic COFF swapping routines, except for the reloc,
184 symbol, and lineno ones. Give them ecoff names. */
186 #define NO_COFF_RELOCS
187 #define NO_COFF_SYMBOLS
188 #define NO_COFF_LINENOS
189 #define coff_swap_filehdr_in ecoff_swap_filehdr_in
190 #define coff_swap_filehdr_out ecoff_swap_filehdr_out
191 #define coff_swap_aouthdr_in ecoff_swap_aouthdr_in
192 #define coff_swap_aouthdr_out ecoff_swap_aouthdr_out
193 #define coff_swap_scnhdr_in ecoff_swap_scnhdr_in
194 #define coff_swap_scnhdr_out ecoff_swap_scnhdr_out
195 #include "coffswap.h"
197 /* This stuff is somewhat copied from coffcode.h. */
199 static asection bfd_debug_section = { "*DEBUG*" };
201 /* See whether the magic number matches. */
204 ecoff_bad_format_hook (abfd, filehdr)
208 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
210 if (ECOFFBADMAG (*internal_f))
216 /* This is a hook needed by SCO COFF, but we have nothing to do. */
219 ecoff_make_section_hook (abfd, name)
223 return (asection *) NULL;
226 /* Initialize a new section. */
229 ecoff_new_section_hook (abfd, section)
233 section->alignment_power = abfd->xvec->align_power_min;
235 if (strcmp (section->name, _TEXT) == 0)
236 section->flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
237 else if (strcmp (section->name, _DATA) == 0
238 || strcmp (section->name, _SDATA) == 0)
239 section->flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
240 else if (strcmp (section->name, _RDATA) == 0
241 || strcmp (section->name, _LIT8) == 0
242 || strcmp (section->name, _LIT4) == 0)
243 section->flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
244 else if (strcmp (section->name, _BSS) == 0
245 || strcmp (section->name, _SBSS) == 0)
246 section->flags |= SEC_ALLOC;
248 /* Probably any other section name is SEC_NEVER_LOAD, but I'm
249 uncertain about .init on some systems and I don't know how shared
255 /* Set the alignment of a section; we have nothing to do. */
257 #define ecoff_set_alignment_hook \
258 ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void)
260 /* Create an ECOFF object. */
263 ecoff_mkobject (abfd)
266 abfd->tdata.ecoff_obj_data = ((struct ecoff_tdata *)
267 bfd_zalloc (abfd, sizeof(ecoff_data_type)));
268 if (abfd->tdata.ecoff_obj_data == NULL)
270 bfd_error = no_memory;
274 /* Always create a .scommon section for every BFD. This is a hack so
275 that the linker has something to attach scSCommon symbols to. */
276 bfd_make_section (abfd, SCOMMON);
281 /* Create the ECOFF backend specific information. */
284 ecoff_mkobject_hook (abfd, filehdr, aouthdr)
289 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
290 struct internal_aouthdr *internal_a = (struct internal_aouthdr *) aouthdr;
291 ecoff_data_type *ecoff;
293 if (ecoff_mkobject (abfd) == false)
296 ecoff = ecoff_data (abfd);
297 ecoff->sym_filepos = internal_f->f_symptr;
299 if (internal_a != (struct internal_aouthdr *) NULL)
303 ecoff->text_start = internal_a->text_start;
304 ecoff->text_end = internal_a->text_start + internal_a->tsize;
305 ecoff->gp = internal_a->gp_value;
306 ecoff->gprmask = internal_a->gprmask;
307 for (i = 0; i < 4; i++)
308 ecoff->cprmask[i] = internal_a->cprmask[i];
314 /* Determine the machine architecture and type. */
317 ecoff_set_arch_mach_hook (abfd, filehdr)
321 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
322 enum bfd_architecture arch;
324 switch (internal_f->f_magic)
327 case MIPS_MAGIC_LITTLE:
329 arch = bfd_arch_mips;
333 arch = bfd_arch_obscure;
337 bfd_default_set_arch_mach (abfd, arch, (unsigned long) 0);
342 /* Get the section s_flags to use for a section. */
345 ecoff_sec_to_styp_flags (name, flags)
353 if (strcmp (name, _TEXT) == 0)
355 else if (strcmp (name, _DATA) == 0)
357 else if (strcmp (name, _SDATA) == 0)
359 else if (strcmp (name, _RDATA) == 0)
361 else if (strcmp (name, _LIT8) == 0)
363 else if (strcmp (name, _LIT4) == 0)
365 else if (strcmp (name, _BSS) == 0)
367 else if (strcmp (name, _SBSS) == 0)
369 else if (flags & SEC_CODE)
371 else if (flags & SEC_DATA)
373 else if (flags & SEC_READONLY)
375 else if (flags & SEC_LOAD)
380 if (flags & SEC_NEVER_LOAD)
386 /* Get the BFD flags to use for a section. */
389 ecoff_styp_to_sec_flags (abfd, hdr)
393 struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
394 long styp_flags = internal_s->s_flags;
395 flagword sec_flags=0;
397 if (styp_flags & STYP_NOLOAD)
398 sec_flags |= SEC_NEVER_LOAD;
400 /* For 386 COFF, at least, an unloadable text or data section is
401 actually a shared library section. */
402 if (styp_flags & STYP_TEXT)
404 if (sec_flags & SEC_NEVER_LOAD)
405 sec_flags |= SEC_CODE | SEC_SHARED_LIBRARY;
407 sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
409 else if ((styp_flags & STYP_DATA)
410 || (styp_flags & STYP_RDATA)
411 || (styp_flags & STYP_SDATA))
413 if (sec_flags & SEC_NEVER_LOAD)
414 sec_flags |= SEC_DATA | SEC_SHARED_LIBRARY;
416 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
417 if (styp_flags & STYP_RDATA)
418 sec_flags |= SEC_READONLY;
420 else if ((styp_flags & STYP_BSS)
421 || (styp_flags & STYP_SBSS))
423 sec_flags |= SEC_ALLOC;
425 else if (styp_flags & STYP_INFO)
427 sec_flags |= SEC_NEVER_LOAD;
429 else if ((styp_flags & STYP_LIT8)
430 || (styp_flags & STYP_LIT4))
432 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
436 sec_flags |= SEC_ALLOC | SEC_LOAD;
442 /* Read in and swap the important symbolic information for an ECOFF
443 object file. FIXME: This is called by gdb. If there is ever
444 another ECOFF target, it should be moved into some sort of target
445 specific structure. */
448 ecoff_slurp_symbolic_info (abfd)
451 struct hdr_ext external_symhdr;
452 HDRR *internal_symhdr;
453 bfd_size_type raw_base;
454 bfd_size_type raw_size;
456 struct fdr_ext *fraw_src;
457 struct fdr_ext *fraw_end;
460 /* Check whether we've already gotten it, and whether there's any to
462 if (ecoff_data (abfd)->raw_syments != (PTR) NULL)
464 if (ecoff_data (abfd)->sym_filepos == 0)
466 bfd_get_symcount (abfd) = 0;
470 /* At this point bfd_get_symcount (abfd) holds the number of symbols
471 as read from the file header, but on ECOFF this is always the
472 size of the symbolic information header. It would be cleaner to
473 handle this when we first read the file in coffgen.c. */
474 if (bfd_get_symcount (abfd) != sizeof (external_symhdr))
476 bfd_error = bad_value;
480 /* Read the symbolic information header. */
481 if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) == -1
482 || (bfd_read ((PTR) &external_symhdr, sizeof (external_symhdr), 1, abfd)
483 != sizeof (external_symhdr)))
485 bfd_error = system_call_error;
488 internal_symhdr = &ecoff_data (abfd)->symbolic_header;
489 ecoff_swap_hdr_in (abfd, &external_symhdr, internal_symhdr);
491 if (internal_symhdr->magic != magicSym)
493 bfd_error = bad_value;
497 /* Now we can get the correct number of symbols. */
498 bfd_get_symcount (abfd) = (internal_symhdr->isymMax
499 + internal_symhdr->iextMax);
501 /* Read all the symbolic information at once. */
502 raw_base = ecoff_data (abfd)->sym_filepos + sizeof (struct hdr_ext);
504 if (internal_symhdr->cbExtOffset != 0)
505 raw_size = (internal_symhdr->cbExtOffset
507 + internal_symhdr->iextMax * sizeof (struct ext_ext));
510 long cbline, issmax, issextmax;
512 cbline = (internal_symhdr->cbLine + 3) &~ 3;
513 issmax = (internal_symhdr->issMax + 3) &~ 3;
514 issextmax = (internal_symhdr->issExtMax + 3) &~ 3;
515 raw_size = (cbline * sizeof (unsigned char)
516 + internal_symhdr->idnMax * sizeof (struct dnr_ext)
517 + internal_symhdr->ipdMax * sizeof (struct pdr_ext)
518 + internal_symhdr->isymMax * sizeof (struct sym_ext)
519 + internal_symhdr->ioptMax * sizeof (struct opt_ext)
520 + internal_symhdr->iauxMax * sizeof (union aux_ext)
521 + issmax * sizeof (char)
522 + issextmax * sizeof (char)
523 + internal_symhdr->ifdMax * sizeof (struct fdr_ext)
524 + internal_symhdr->crfd * sizeof (struct rfd_ext)
525 + internal_symhdr->iextMax * sizeof (struct ext_ext));
530 ecoff_data (abfd)->sym_filepos = 0;
533 raw = (PTR) bfd_alloc (abfd, raw_size);
536 bfd_error = no_memory;
539 if (bfd_read (raw, raw_size, 1, abfd) != raw_size)
541 bfd_error = system_call_error;
542 bfd_release (abfd, raw);
546 ecoff_data (abfd)->raw_size = raw_size;
547 ecoff_data (abfd)->raw_syments = raw;
549 /* Get pointers for the numeric offsets in the HDRR structure. */
550 #define FIX(off1, off2, type) \
551 if (internal_symhdr->off1 == 0) \
552 ecoff_data (abfd)->off2 = (type *) NULL; \
554 ecoff_data (abfd)->off2 = (type *) ((char *) raw \
555 + internal_symhdr->off1 \
557 FIX (cbLineOffset, line, unsigned char);
558 FIX (cbDnOffset, external_dnr, struct dnr_ext);
559 FIX (cbPdOffset, external_pdr, struct pdr_ext);
560 FIX (cbSymOffset, external_sym, struct sym_ext);
561 FIX (cbOptOffset, external_opt, struct opt_ext);
562 FIX (cbAuxOffset, external_aux, union aux_ext);
563 FIX (cbSsOffset, ss, char);
564 FIX (cbSsExtOffset, ssext, char);
565 FIX (cbFdOffset, external_fdr, struct fdr_ext);
566 FIX (cbRfdOffset, external_rfd, struct rfd_ext);
567 FIX (cbExtOffset, external_ext, struct ext_ext);
570 /* I don't want to always swap all the data, because it will just
571 waste time and most programs will never look at it. The only
572 time the linker needs most of the debugging information swapped
573 is when linking big-endian and little-endian MIPS object files
574 together, which is not a common occurrence.
576 We need to look at the fdr to deal with a lot of information in
577 the symbols, so we swap them here. */
578 ecoff_data (abfd)->fdr = (struct fdr *) bfd_alloc (abfd,
579 (internal_symhdr->ifdMax *
580 sizeof (struct fdr)));
581 if (ecoff_data (abfd)->fdr == NULL)
583 bfd_error = no_memory;
586 fdr_ptr = ecoff_data (abfd)->fdr;
587 fraw_src = ecoff_data (abfd)->external_fdr;
588 fraw_end = fraw_src + internal_symhdr->ifdMax;
589 for (; fraw_src < fraw_end; fraw_src++, fdr_ptr++)
590 ecoff_swap_fdr_in (abfd, fraw_src, fdr_ptr);
595 /* ECOFF symbol table routines. The ECOFF symbol table is described
596 in gcc/mips-tfile.c. */
598 /* ECOFF uses two common sections. One is the usual one, and the
599 other is for small objects. All the small objects are kept
600 together, and then referenced via the gp pointer, which yields
601 faster assembler code. This is what we use for the small common
603 static asection ecoff_scom_section;
604 static asymbol ecoff_scom_symbol;
605 static asymbol *ecoff_scom_symbol_ptr;
607 /* Create an empty symbol. */
610 ecoff_make_empty_symbol (abfd)
613 ecoff_symbol_type *new;
615 new = (ecoff_symbol_type *) bfd_alloc (abfd, sizeof (ecoff_symbol_type));
616 if (new == (ecoff_symbol_type *) NULL)
618 bfd_error = no_memory;
619 return (asymbol *) NULL;
621 new->symbol.section = (asection *) NULL;
622 new->fdr = (FDR *) NULL;
624 new->native.lnative = (struct sym_ext *) NULL;
625 new->symbol.the_bfd = abfd;
629 /* Set the BFD flags and section for an ECOFF symbol. */
632 ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext)
638 asym->the_bfd = abfd;
639 asym->value = ecoff_sym->value;
640 asym->section = &bfd_debug_section;
643 /* Most symbol types are just for debugging. */
644 switch (ecoff_sym->st)
654 asym->flags = BSF_DEBUGGING;
659 asym->flags = BSF_EXPORT | BSF_GLOBAL;
661 asym->flags = BSF_LOCAL;
662 switch (ecoff_sym->sc)
665 /* Used for compiler generated labels. Leave them in the
666 debugging section, and mark them as local. If BSF_DEBUGGING
667 is set, then nm does not display them for some reason. If no
668 flags are set then the linker whines about them. */
669 asym->flags = BSF_LOCAL;
672 asym->section = bfd_make_section_old_way (abfd, ".text");
673 asym->value -= asym->section->vma;
676 asym->section = bfd_make_section_old_way (abfd, ".data");
677 asym->value -= asym->section->vma;
682 asym->section = &bfd_com_section;
687 asym->section = bfd_make_section_old_way (abfd, ".bss");
688 asym->value -= asym->section->vma;
692 asym->flags = BSF_DEBUGGING;
695 asym->section = &bfd_abs_section;
698 asym->section = &bfd_und_section;
708 asym->flags = BSF_DEBUGGING;
711 asym->section = bfd_make_section_old_way (abfd, ".sdata");
712 asym->value -= asym->section->vma;
715 asym->section = bfd_make_section_old_way (abfd, ".sbss");
717 asym->value -= asym->section->vma;
720 asym->section = bfd_make_section_old_way (abfd, ".rdata");
721 asym->value -= asym->section->vma;
724 asym->flags = BSF_DEBUGGING;
727 /* FIXME: We should take a -G argument, which gives the maximum
728 size of objects to be put in the small common section. Until
729 we do, we put objects of sizes up to 8 in the small common
730 section. The assembler should do this for us, but the native
731 assembler seems to get confused. */
734 asym->section = &bfd_com_section;
739 if (ecoff_scom_section.name == NULL)
741 /* Initialize the small common section. */
742 ecoff_scom_section.name = SCOMMON;
743 ecoff_scom_section.flags = SEC_IS_COMMON;
744 ecoff_scom_section.output_section = &ecoff_scom_section;
745 ecoff_scom_section.symbol = &ecoff_scom_symbol;
746 ecoff_scom_section.symbol_ptr_ptr = &ecoff_scom_symbol_ptr;
747 ecoff_scom_symbol.name = SCOMMON;
748 ecoff_scom_symbol.flags = BSF_SECTION_SYM;
749 ecoff_scom_symbol.section = &ecoff_scom_section;
750 ecoff_scom_symbol_ptr = &ecoff_scom_symbol;
752 asym->section = &ecoff_scom_section;
757 asym->flags = BSF_DEBUGGING;
760 asym->section = &bfd_und_section;
765 asym->section = bfd_make_section_old_way (abfd, ".init");
766 asym->value -= asym->section->vma;
771 asym->flags = BSF_DEBUGGING;
774 asym->section = bfd_make_section_old_way (abfd, ".fini");
775 asym->value -= asym->section->vma;
782 /* Read an ECOFF symbol table. */
785 ecoff_slurp_symbol_table (abfd)
788 bfd_size_type internal_size;
789 ecoff_symbol_type *internal;
790 ecoff_symbol_type *internal_ptr;
791 struct ext_ext *eraw_src;
792 struct ext_ext *eraw_end;
796 /* If we've already read in the symbol table, do nothing. */
797 if (ecoff_data (abfd)->canonical_symbols != NULL)
800 /* Get the symbolic information. */
801 if (ecoff_slurp_symbolic_info (abfd) == false)
803 if (bfd_get_symcount (abfd) == 0)
806 internal_size = bfd_get_symcount (abfd) * sizeof (ecoff_symbol_type);
807 internal = (ecoff_symbol_type *) bfd_alloc (abfd, internal_size);
808 if (internal == NULL)
810 bfd_error = no_memory;
814 internal_ptr = internal;
815 eraw_src = ecoff_data (abfd)->external_ext;
816 eraw_end = eraw_src + ecoff_data (abfd)->symbolic_header.iextMax;
817 for (; eraw_src < eraw_end; eraw_src++, internal_ptr++)
821 ecoff_swap_ext_in (abfd, eraw_src, &internal_esym);
822 internal_ptr->symbol.name = (ecoff_data (abfd)->ssext
823 + internal_esym.asym.iss);
824 ecoff_set_symbol_info (abfd, &internal_esym.asym,
825 &internal_ptr->symbol, 1);
826 internal_ptr->fdr = ecoff_data (abfd)->fdr + internal_esym.ifd;
827 internal_ptr->local = false;
828 internal_ptr->native.enative = eraw_src;
831 /* The local symbols must be accessed via the fdr's, because the
832 string and aux indices are relative to the fdr information. */
833 fdr_ptr = ecoff_data (abfd)->fdr;
834 fdr_end = fdr_ptr + ecoff_data (abfd)->symbolic_header.ifdMax;
835 for (; fdr_ptr < fdr_end; fdr_ptr++)
837 struct sym_ext *lraw_src;
838 struct sym_ext *lraw_end;
840 lraw_src = ecoff_data (abfd)->external_sym + fdr_ptr->isymBase;
841 lraw_end = lraw_src + fdr_ptr->csym;
842 for (; lraw_src < lraw_end; lraw_src++, internal_ptr++)
846 ecoff_swap_sym_in (abfd, lraw_src, &internal_sym);
847 internal_ptr->symbol.name = (ecoff_data (abfd)->ss
850 ecoff_set_symbol_info (abfd, &internal_sym,
851 &internal_ptr->symbol, 0);
852 internal_ptr->fdr = fdr_ptr;
853 internal_ptr->local = true;
854 internal_ptr->native.lnative = lraw_src;
858 ecoff_data (abfd)->canonical_symbols = internal;
864 ecoff_get_symtab_upper_bound (abfd)
867 if (ecoff_slurp_symbolic_info (abfd) == false
868 || bfd_get_symcount (abfd) == 0)
871 return (bfd_get_symcount (abfd) + 1) * (sizeof (ecoff_symbol_type *));
875 ecoff_get_symtab (abfd, alocation)
879 unsigned int counter = 0;
880 ecoff_symbol_type *symbase;
881 ecoff_symbol_type **location = (ecoff_symbol_type **) alocation;
883 if (ecoff_slurp_symbol_table (abfd) == false
884 || bfd_get_symcount (abfd) == 0)
887 symbase = ecoff_data (abfd)->canonical_symbols;
888 while (counter < bfd_get_symcount (abfd))
890 *(location++) = symbase++;
893 *location++ = (ecoff_symbol_type *) NULL;
894 return bfd_get_symcount (abfd);
897 /* Turn ECOFF type information into a printable string.
898 ecoff_emit_aggregate and ecoff_type_to_string are from
899 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
901 /* Write aggregate information to a string. */
904 ecoff_emit_aggregate (abfd, string, rndx, isym, which)
912 int indx = rndx->index;
913 int sym_base, ss_base;
919 sym_base = ecoff_data (abfd)->fdr[ifd].isymBase;
920 ss_base = ecoff_data (abfd)->fdr[ifd].issBase;
922 if (indx == indexNil)
923 name = "/* no name */";
929 ecoff_swap_sym_in (abfd,
930 ecoff_data (abfd)->external_sym + indx,
932 name = ecoff_data (abfd)->ss + ss_base + sym.iss;
936 "%s %s { ifd = %d, index = %d }",
938 indx + ecoff_data (abfd)->symbolic_header.iextMax);
941 /* Convert the type information to string format. */
944 ecoff_type_to_string (abfd, aux_ptr, indx, bigendian)
946 union aux_ext *aux_ptr;
958 unsigned int basic_type;
960 static char buffer1[1024];
961 static char buffer2[1024];
966 for (i = 0; i < 7; i++)
968 qualifiers[i].low_bound = 0;
969 qualifiers[i].high_bound = 0;
970 qualifiers[i].stride = 0;
973 if (AUX_GET_ISYM (bigendian, &aux_ptr[indx]) == -1)
974 return "-1 (no type)";
975 ecoff_swap_tir_in (bigendian, &aux_ptr[indx++].a_ti, &u.ti);
977 basic_type = u.ti.bt;
978 qualifiers[0].type = u.ti.tq0;
979 qualifiers[1].type = u.ti.tq1;
980 qualifiers[2].type = u.ti.tq2;
981 qualifiers[3].type = u.ti.tq3;
982 qualifiers[4].type = u.ti.tq4;
983 qualifiers[5].type = u.ti.tq5;
984 qualifiers[6].type = tqNil;
987 * Go get the basic type.
991 case btNil: /* undefined */
995 case btAdr: /* address - integer same size as pointer */
996 strcpy (p1, "address");
999 case btChar: /* character */
1000 strcpy (p1, "char");
1003 case btUChar: /* unsigned character */
1004 strcpy (p1, "unsigned char");
1007 case btShort: /* short */
1008 strcpy (p1, "short");
1011 case btUShort: /* unsigned short */
1012 strcpy (p1, "unsigned short");
1015 case btInt: /* int */
1019 case btUInt: /* unsigned int */
1020 strcpy (p1, "unsigned int");
1023 case btLong: /* long */
1024 strcpy (p1, "long");
1027 case btULong: /* unsigned long */
1028 strcpy (p1, "unsigned long");
1031 case btFloat: /* float (real) */
1032 strcpy (p1, "float");
1035 case btDouble: /* Double (real) */
1036 strcpy (p1, "double");
1039 /* Structures add 1-2 aux words:
1040 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1041 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1043 case btStruct: /* Structure (Record) */
1044 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1045 ecoff_emit_aggregate (abfd, p1, &rndx,
1046 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1048 indx++; /* skip aux words */
1051 /* Unions add 1-2 aux words:
1052 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1053 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1055 case btUnion: /* Union */
1056 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1057 ecoff_emit_aggregate (abfd, p1, &rndx,
1058 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1060 indx++; /* skip aux words */
1063 /* Enumerations add 1-2 aux words:
1064 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1065 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1067 case btEnum: /* Enumeration */
1068 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1069 ecoff_emit_aggregate (abfd, p1, &rndx,
1070 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1072 indx++; /* skip aux words */
1075 case btTypedef: /* defined via a typedef, isymRef points */
1076 strcpy (p1, "typedef");
1079 case btRange: /* subrange of int */
1080 strcpy (p1, "subrange");
1083 case btSet: /* pascal sets */
1087 case btComplex: /* fortran complex */
1088 strcpy (p1, "complex");
1091 case btDComplex: /* fortran double complex */
1092 strcpy (p1, "double complex");
1095 case btIndirect: /* forward or unnamed typedef */
1096 strcpy (p1, "forward/unamed typedef");
1099 case btFixedDec: /* Fixed Decimal */
1100 strcpy (p1, "fixed decimal");
1103 case btFloatDec: /* Float Decimal */
1104 strcpy (p1, "float decimal");
1107 case btString: /* Varying Length Character String */
1108 strcpy (p1, "string");
1111 case btBit: /* Aligned Bit String */
1115 case btPicture: /* Picture */
1116 strcpy (p1, "picture");
1119 case btVoid: /* Void */
1120 strcpy (p1, "void");
1124 sprintf (p1, "Unknown basic type %d", (int) basic_type);
1128 p1 += strlen (buffer1);
1131 * If this is a bitfield, get the bitsize.
1137 bitsize = AUX_GET_WIDTH (bigendian, &aux_ptr[indx++]);
1138 sprintf (p1, " : %d", bitsize);
1139 p1 += strlen (buffer1);
1144 * Deal with any qualifiers.
1146 if (qualifiers[0].type != tqNil)
1149 * Snarf up any array bounds in the correct order. Arrays
1150 * store 5 successive words in the aux. table:
1151 * word 0 RNDXR to type of the bounds (ie, int)
1152 * word 1 Current file descriptor index
1154 * word 3 high bound (or -1 if [])
1155 * word 4 stride size in bits
1157 for (i = 0; i < 7; i++)
1159 if (qualifiers[i].type == tqArray)
1161 qualifiers[i].low_bound =
1162 AUX_GET_DNLOW (bigendian, &aux_ptr[indx+2]);
1163 qualifiers[i].high_bound =
1164 AUX_GET_DNHIGH (bigendian, &aux_ptr[indx+3]);
1165 qualifiers[i].stride =
1166 AUX_GET_WIDTH (bigendian, &aux_ptr[indx+4]);
1172 * Now print out the qualifiers.
1174 for (i = 0; i < 6; i++)
1176 switch (qualifiers[i].type)
1183 strcpy (p2, "ptr to ");
1184 p2 += sizeof ("ptr to ")-1;
1188 strcpy (p2, "volatile ");
1189 p2 += sizeof ("volatile ")-1;
1193 strcpy (p2, "far ");
1194 p2 += sizeof ("far ")-1;
1198 strcpy (p2, "func. ret. ");
1199 p2 += sizeof ("func. ret. ");
1204 int first_array = i;
1207 /* Print array bounds reversed (ie, in the order the C
1208 programmer writes them). C is such a fun language.... */
1210 while (i < 5 && qualifiers[i+1].type == tqArray)
1213 for (j = i; j >= first_array; j--)
1215 strcpy (p2, "array [");
1216 p2 += sizeof ("array [")-1;
1217 if (qualifiers[j].low_bound != 0)
1219 "%ld:%ld {%ld bits}",
1220 (long) qualifiers[j].low_bound,
1221 (long) qualifiers[j].high_bound,
1222 (long) qualifiers[j].stride);
1224 else if (qualifiers[j].high_bound != -1)
1227 (long) (qualifiers[j].high_bound + 1),
1228 (long) (qualifiers[j].stride));
1231 sprintf (p2, " {%ld bits}", (long) (qualifiers[j].stride));
1234 strcpy (p2, "] of ");
1235 p2 += sizeof ("] of ")-1;
1243 strcpy (p2, buffer1);
1247 /* Print information about an ECOFF symbol. */
1250 ecoff_print_symbol (abfd, filep, symbol, how)
1254 bfd_print_symbol_type how;
1256 FILE *file = (FILE *)filep;
1260 case bfd_print_symbol_name:
1261 fprintf (file, "%s", symbol->name);
1263 case bfd_print_symbol_more:
1264 if (ecoffsymbol (symbol)->local)
1268 ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative,
1270 fprintf (file, "ecoff local %lx %x %x",
1271 (unsigned long) ecoff_sym.value,
1272 (unsigned) ecoff_sym.st, (unsigned) ecoff_sym.sc);
1278 ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative,
1280 fprintf (file, "ecoff extern %lx %x %x",
1281 (unsigned long) ecoff_ext.asym.value,
1282 (unsigned) ecoff_ext.asym.st,
1283 (unsigned) ecoff_ext.asym.sc);
1286 case bfd_print_symbol_nm:
1288 CONST char *section_name = symbol->section->name;
1290 bfd_print_symbol_vandf ((PTR) file, symbol);
1291 fprintf (file, " %-5s %s %s",
1293 ecoffsymbol (symbol)->local ? "l" : "e",
1297 case bfd_print_symbol_all:
1298 /* Print out the symbols in a reasonable way */
1307 if (ecoffsymbol (symbol)->local)
1309 ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative,
1312 pos = (ecoffsymbol (symbol)->native.lnative
1313 - ecoff_data (abfd)->external_sym
1314 + ecoff_data (abfd)->symbolic_header.iextMax);
1321 ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative,
1324 pos = (ecoffsymbol (symbol)->native.enative
1325 - ecoff_data (abfd)->external_ext);
1326 jmptbl = ecoff_ext.jmptbl ? 'j' : ' ';
1327 cobol_main = ecoff_ext.cobol_main ? 'c' : ' ';
1328 weakext = ecoff_ext.weakext ? 'w' : ' ';
1331 fprintf (file, "[%3d] %c %lx st %x sc %x indx %x %c%c%c %s",
1332 pos, type, (unsigned long) ecoff_ext.asym.value,
1333 (unsigned) ecoff_ext.asym.st,
1334 (unsigned) ecoff_ext.asym.sc,
1335 (unsigned) ecoff_ext.asym.index,
1336 jmptbl, cobol_main, weakext,
1339 if (ecoffsymbol (symbol)->fdr != NULL
1340 && ecoff_ext.asym.index != indexNil)
1345 union aux_ext *aux_base;
1347 indx = ecoff_ext.asym.index;
1349 /* sym_base is used to map the fdr relative indices which
1350 appear in the file to the position number which we are
1352 sym_base = ecoffsymbol (symbol)->fdr->isymBase;
1353 if (ecoffsymbol (symbol)->local)
1354 sym_base += ecoff_data (abfd)->symbolic_header.iextMax;
1356 /* aux_base is the start of the aux entries for this file;
1357 asym.index is an offset from this. */
1358 aux_base = (ecoff_data (abfd)->external_aux
1359 + ecoffsymbol (symbol)->fdr->iauxBase);
1361 /* The aux entries are stored in host byte order; the
1362 order is indicated by a bit in the fdr. */
1363 bigendian = ecoffsymbol (symbol)->fdr->fBigendian;
1365 /* This switch is basically from gcc/mips-tdump.c */
1366 switch (ecoff_ext.asym.st)
1374 printf ("\n End+1 symbol: %ld", indx + sym_base);
1378 if (ecoff_ext.asym.sc == scText
1379 || ecoff_ext.asym.sc == scInfo)
1380 printf ("\n First symbol: %ld", indx + sym_base);
1382 printf ("\n First symbol: %ld",
1383 (AUX_GET_ISYM (bigendian,
1384 &aux_base[ecoff_ext.asym.index])
1390 if (MIPS_IS_STAB (&ecoff_ext.asym))
1392 else if (ecoffsymbol (symbol)->local)
1393 printf ("\n End+1 symbol: %-7ld Type: %s",
1394 (AUX_GET_ISYM (bigendian,
1395 &aux_base[ecoff_ext.asym.index])
1397 ecoff_type_to_string (abfd, aux_base, indx + 1,
1400 printf ("\n Local symbol: %d",
1403 + ecoff_data (abfd)->symbolic_header.iextMax));
1407 if (!MIPS_IS_STAB (&ecoff_ext.asym))
1408 printf ("\n Type: %s",
1409 ecoff_type_to_string (abfd, aux_base, indx,
1419 /* Reloc handling. MIPS ECOFF relocs are packed into 8 bytes in
1420 external form. They use a bit which indicates whether the symbol
1423 /* Swap a reloc in. */
1426 ecoff_swap_reloc_in (abfd, ext, intern)
1429 struct internal_reloc *intern;
1431 intern->r_vaddr = bfd_h_get_32 (abfd, (bfd_byte *) ext->r_vaddr);
1432 if (abfd->xvec->header_byteorder_big_p != false)
1434 intern->r_symndx = (((int) ext->r_bits[0]
1435 << RELOC_BITS0_SYMNDX_SH_LEFT_BIG)
1436 | ((int) ext->r_bits[1]
1437 << RELOC_BITS1_SYMNDX_SH_LEFT_BIG)
1438 | ((int) ext->r_bits[2]
1439 << RELOC_BITS2_SYMNDX_SH_LEFT_BIG));
1440 intern->r_type = ((ext->r_bits[3] & RELOC_BITS3_TYPE_BIG)
1441 >> RELOC_BITS3_TYPE_SH_BIG);
1442 intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_BIG) != 0;
1446 intern->r_symndx = (((int) ext->r_bits[0]
1447 << RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE)
1448 | ((int) ext->r_bits[1]
1449 << RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE)
1450 | ((int) ext->r_bits[2]
1451 << RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE));
1452 intern->r_type = ((ext->r_bits[3] & RELOC_BITS3_TYPE_LITTLE)
1453 >> RELOC_BITS3_TYPE_SH_LITTLE);
1454 intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_LITTLE) != 0;
1458 /* Swap a reloc out. */
1461 ecoff_swap_reloc_out (abfd, src, dst)
1466 struct internal_reloc *intern = (struct internal_reloc *) src;
1467 RELOC *ext = (RELOC *) dst;
1469 bfd_h_put_32 (abfd, intern->r_vaddr, (bfd_byte *) ext->r_vaddr);
1470 if (abfd->xvec->header_byteorder_big_p != false)
1472 ext->r_bits[0] = intern->r_symndx >> RELOC_BITS0_SYMNDX_SH_LEFT_BIG;
1473 ext->r_bits[1] = intern->r_symndx >> RELOC_BITS1_SYMNDX_SH_LEFT_BIG;
1474 ext->r_bits[2] = intern->r_symndx >> RELOC_BITS2_SYMNDX_SH_LEFT_BIG;
1475 ext->r_bits[3] = (((intern->r_type << RELOC_BITS3_TYPE_SH_BIG)
1476 & RELOC_BITS3_TYPE_BIG)
1477 | (intern->r_extern ? RELOC_BITS3_EXTERN_BIG : 0));
1481 ext->r_bits[0] = intern->r_symndx >> RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE;
1482 ext->r_bits[1] = intern->r_symndx >> RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE;
1483 ext->r_bits[2] = intern->r_symndx >> RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE;
1484 ext->r_bits[3] = (((intern->r_type << RELOC_BITS3_TYPE_SH_LITTLE)
1485 & RELOC_BITS3_TYPE_LITTLE)
1486 | (intern->r_extern ? RELOC_BITS3_EXTERN_LITTLE : 0));
1492 /* ECOFF relocs are either against external symbols, or against
1493 sections. If we are producing relocateable output, and the reloc
1494 is against an external symbol, the resulting reloc will also be
1495 against the same symbol. In such a case, we don't want to change
1496 anything about the way the reloc is handled, since it will all be
1497 done at final link time. Rather than put special case code into
1498 bfd_perform_relocation, all the reloc types use this howto
1499 function. It just short circuits the reloc if producing
1500 relocateable output against an external symbol. */
1502 static bfd_reloc_status_type
1503 ecoff_generic_reloc (abfd,
1510 arelent *reloc_entry;
1513 asection *input_section;
1516 if (output_bfd != (bfd *) NULL
1517 && (symbol->flags & BSF_SECTION_SYM) == 0)
1519 reloc_entry->address += input_section->output_offset;
1520 return bfd_reloc_ok;
1523 return bfd_reloc_continue;
1526 /* Do a REFHI relocation. The next reloc must be the corresponding
1527 REFLO. This has to be done in a function so that carry is handled
1530 static bfd_reloc_status_type
1531 ecoff_refhi_reloc (abfd,
1538 arelent *reloc_entry;
1541 asection *input_section;
1544 bfd_reloc_status_type ret;
1549 unsigned long vallo;
1551 /* If we're relocating, and this an external symbol, we don't want
1552 to change anything. */
1553 if (output_bfd != (bfd *) NULL
1554 && (symbol->flags & BSF_SECTION_SYM) == 0)
1556 reloc_entry->address += input_section->output_offset;
1557 return bfd_reloc_ok;
1561 if (symbol->section == &bfd_und_section
1562 && output_bfd == (bfd *) NULL)
1563 ret = bfd_reloc_undefined;
1565 rello = reloc_entry + 1;
1566 BFD_ASSERT (rello->howto->type == ECOFF_R_REFLO
1567 && *rello->sym_ptr_ptr == *reloc_entry->sym_ptr_ptr);
1569 if (bfd_is_com_section (symbol->section))
1572 relocation = symbol->value;
1574 relocation += symbol->section->output_section->vma;
1575 relocation += symbol->section->output_offset;
1576 relocation += reloc_entry->addend;
1578 if (reloc_entry->address > input_section->_cooked_size)
1579 return bfd_reloc_outofrange;
1581 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1582 vallo = bfd_get_32 (abfd, (bfd_byte *) data + rello->address) & 0xffff;
1583 val = ((insn & 0xffff) << 16) + vallo;
1586 /* The low order 16 bits are always treated as a signed value.
1587 Therefore, a negative value in the low order bits requires an
1588 adjustment in the high order bits. We need to make this
1589 adjustment in two ways: once for the bits we took from the data,
1590 and once for the bits we are putting back in to the data. */
1591 if ((vallo & 0x8000) != 0)
1593 if ((val & 0x8000) != 0)
1596 insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
1597 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
1599 if (output_bfd != (bfd *) NULL)
1600 reloc_entry->address += input_section->output_offset;
1605 /* Do a GPREL relocation. This is a 16 bit value which must become
1606 the offset from the gp register. */
1608 static bfd_reloc_status_type
1609 ecoff_gprel_reloc (abfd,
1616 arelent *reloc_entry;
1619 asection *input_section;
1622 boolean relocateable;
1627 /* If we're relocating, and this an external symbol, we don't want
1628 to change anything. */
1629 if (output_bfd != (bfd *) NULL
1630 && (symbol->flags & BSF_SECTION_SYM) == 0)
1632 reloc_entry->address += input_section->output_offset;
1633 return bfd_reloc_ok;
1636 if (output_bfd != (bfd *) NULL)
1637 relocateable = true;
1640 relocateable = false;
1641 output_bfd = symbol->section->output_section->owner;
1644 if (symbol->section == &bfd_und_section
1645 && relocateable == false)
1646 return bfd_reloc_undefined;
1648 /* We have to figure out the gp value, so that we can adjust the
1649 symbol value correctly. We look up the symbol _gp in the output
1650 BFD. If we can't find it, we're stuck. We cache it in the ECOFF
1652 if (ecoff_data (output_bfd)->gp == 0)
1654 if (relocateable != false)
1656 /* Make up a value. */
1657 ecoff_data (output_bfd)->gp =
1658 symbol->section->output_section->vma + 0x4000;
1666 count = bfd_get_symcount (output_bfd);
1667 sym = bfd_get_outsymbols (output_bfd);
1669 /* We should do something more friendly here, but we don't
1670 have a good reloc status to return. */
1671 if (sym == (asymbol **) NULL)
1674 for (i = 0; i < count; i++, sym++)
1676 register CONST char *name;
1678 name = bfd_asymbol_name (*sym);
1679 if (*name == '_' && strcmp (name, "_gp") == 0)
1681 ecoff_data (output_bfd)->gp = bfd_asymbol_value (*sym);
1686 /* We should do something more friendly here, but we don't have
1687 a good reloc status to return. */
1693 if (bfd_is_com_section (symbol->section))
1696 relocation = symbol->value;
1698 relocation += symbol->section->output_section->vma;
1699 relocation += symbol->section->output_offset;
1701 if (reloc_entry->address > input_section->_cooked_size)
1702 return bfd_reloc_outofrange;
1704 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1706 /* Set val to the offset into the section (if we are relocating
1707 against an external symbol, insn & 0xffff will be zero and so
1708 will reloc_entry->addend). */
1709 val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff;
1713 /* Adjust val for the final section location and GP value. */
1714 val += (relocation - ecoff_data (output_bfd)->gp);
1716 insn = (insn &~ 0xffff) | (val & 0xffff);
1717 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
1719 if (relocateable != false)
1720 reloc_entry->address += input_section->output_offset;
1722 /* Make sure it fit in 16 bits. */
1723 if (val >= 0x8000 && val < 0xffff8000)
1724 return bfd_reloc_outofrange;
1726 return bfd_reloc_ok;
1729 /* How to process the various relocs types. */
1731 static reloc_howto_type ecoff_howto_table[] =
1733 /* Reloc type 0 is ignored. The reloc reading code ensures that
1734 this is a reference to the .abs section, which will cause
1735 bfd_perform_relocation to do nothing. */
1736 HOWTO (ECOFF_R_IGNORE, /* type */
1738 0, /* size (0 = byte, 1 = short, 2 = long) */
1739 8, /* bitsize (obsolete) */
1740 false, /* pc_relative */
1742 false, /* absolute (obsolete) */
1743 false, /* complain_on_overflow */
1744 0, /* special_function */
1745 "IGNORE", /* name */
1746 false, /* partial_inplace */
1749 false), /* pcrel_offset */
1751 /* A 16 bit reference to a symbol, normally from a data section. */
1752 HOWTO (ECOFF_R_REFHALF, /* type */
1754 1, /* size (0 = byte, 1 = short, 2 = long) */
1755 16, /* bitsize (obsolete) */
1756 false, /* pc_relative */
1758 false, /* absolute (obsolete) */
1759 true, /* complain_on_overflow */
1760 ecoff_generic_reloc, /* special_function */
1761 "REFHALF", /* name */
1762 true, /* partial_inplace */
1763 0xffff, /* src_mask */
1764 0xffff, /* dst_mask */
1765 false), /* pcrel_offset */
1767 /* A 32 bit reference to a symbol, normally from a data section. */
1768 HOWTO (ECOFF_R_REFWORD, /* type */
1770 2, /* size (0 = byte, 1 = short, 2 = long) */
1771 32, /* bitsize (obsolete) */
1772 false, /* pc_relative */
1774 false, /* absolute (obsolete) */
1775 true, /* complain_on_overflow */
1776 ecoff_generic_reloc, /* special_function */
1777 "REFWORD", /* name */
1778 true, /* partial_inplace */
1779 0xffffffff, /* src_mask */
1780 0xffffffff, /* dst_mask */
1781 false), /* pcrel_offset */
1783 /* A 26 bit absolute jump address. */
1784 HOWTO (ECOFF_R_JMPADDR, /* type */
1786 2, /* size (0 = byte, 1 = short, 2 = long) */
1787 32, /* bitsize (obsolete) */
1788 false, /* pc_relative */
1790 false, /* absolute (obsolete) */
1791 true, /* complain_on_overflow */
1792 ecoff_generic_reloc, /* special_function */
1793 "JMPADDR", /* name */
1794 true, /* partial_inplace */
1795 0x3ffffff, /* src_mask */
1796 0x3ffffff, /* dst_mask */
1797 false), /* pcrel_offset */
1799 /* The high 16 bits of a symbol value. Handled by the function
1800 ecoff_refhi_reloc. */
1801 HOWTO (ECOFF_R_REFHI, /* type */
1802 16, /* rightshift */
1803 2, /* size (0 = byte, 1 = short, 2 = long) */
1804 32, /* bitsize (obsolete) */
1805 false, /* pc_relative */
1807 false, /* absolute (obsolete) */
1808 true, /* complain_on_overflow */
1809 ecoff_refhi_reloc, /* special_function */
1811 true, /* partial_inplace */
1812 0xffff, /* src_mask */
1813 0xffff, /* dst_mask */
1814 false), /* pcrel_offset */
1816 /* The low 16 bits of a symbol value. */
1817 HOWTO (ECOFF_R_REFLO, /* type */
1819 2, /* size (0 = byte, 1 = short, 2 = long) */
1820 32, /* bitsize (obsolete) */
1821 false, /* pc_relative */
1823 false, /* absolute (obsolete) */
1824 true, /* complain_on_overflow */
1825 ecoff_generic_reloc, /* special_function */
1827 true, /* partial_inplace */
1828 0xffff, /* src_mask */
1829 0xffff, /* dst_mask */
1830 false), /* pcrel_offset */
1832 /* A reference to an offset from the gp register. Handled by the
1833 function ecoff_gprel_reloc. */
1834 HOWTO (ECOFF_R_GPREL, /* type */
1836 2, /* size (0 = byte, 1 = short, 2 = long) */
1837 32, /* bitsize (obsolete) */
1838 false, /* pc_relative */
1840 false, /* absolute (obsolete) */
1841 true, /* complain_on_overflow */
1842 ecoff_gprel_reloc, /* special_function */
1844 true, /* partial_inplace */
1845 0xffff, /* src_mask */
1846 0xffff, /* dst_mask */
1847 false), /* pcrel_offset */
1849 /* A reference to a literal using an offset from the gp register.
1850 Handled by the function ecoff_gprel_reloc. */
1851 HOWTO (ECOFF_R_LITERAL, /* type */
1853 2, /* size (0 = byte, 1 = short, 2 = long) */
1854 32, /* bitsize (obsolete) */
1855 false, /* pc_relative */
1857 false, /* absolute (obsolete) */
1858 true, /* complain_on_overflow */
1859 ecoff_gprel_reloc, /* special_function */
1860 "LITERAL", /* name */
1861 true, /* partial_inplace */
1862 0xffff, /* src_mask */
1863 0xffff, /* dst_mask */
1864 false) /* pcrel_offset */
1867 #define ECOFF_HOWTO_COUNT \
1868 (sizeof ecoff_howto_table / sizeof ecoff_howto_table[0])
1870 /* Read in the relocs for a section. */
1873 ecoff_slurp_reloc_table (abfd, section, symbols)
1878 RELOC *external_relocs;
1879 arelent *internal_relocs;
1883 if (section->relocation != (arelent *) NULL
1884 || section->reloc_count == 0
1885 || (section->flags & SEC_CONSTRUCTOR) != 0)
1888 if (ecoff_slurp_symbol_table (abfd) == false)
1891 internal_relocs = (arelent *) bfd_alloc (abfd,
1893 * section->reloc_count));
1894 external_relocs = (RELOC *) bfd_alloc (abfd, RELSZ * section->reloc_count);
1895 if (internal_relocs == (arelent *) NULL
1896 || external_relocs == (RELOC *) NULL)
1898 bfd_error = no_memory;
1901 if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0)
1903 if (bfd_read (external_relocs, 1, RELSZ * section->reloc_count, abfd)
1904 != RELSZ * section->reloc_count)
1906 bfd_error = system_call_error;
1910 for (i = 0, rptr = internal_relocs; i < section->reloc_count; i++, rptr++)
1912 struct internal_reloc intern;
1914 ecoff_swap_reloc_in (abfd, external_relocs + i, &intern);
1916 if (intern.r_type > ECOFF_R_LITERAL)
1919 if (intern.r_extern)
1921 /* r_symndx is an index into the external symbols. */
1922 BFD_ASSERT (intern.r_symndx >= 0
1924 < ecoff_data (abfd)->symbolic_header.iextMax));
1925 rptr->sym_ptr_ptr = symbols + intern.r_symndx;
1930 CONST char *sec_name;
1933 /* r_symndx is a section key. */
1934 switch (intern.r_symndx)
1936 case RELOC_SECTION_TEXT: sec_name = ".text"; break;
1937 case RELOC_SECTION_RDATA: sec_name = ".rdata"; break;
1938 case RELOC_SECTION_DATA: sec_name = ".data"; break;
1939 case RELOC_SECTION_SDATA: sec_name = ".sdata"; break;
1940 case RELOC_SECTION_SBSS: sec_name = ".sbss"; break;
1941 case RELOC_SECTION_BSS: sec_name = ".bss"; break;
1942 case RELOC_SECTION_INIT: sec_name = ".init"; break;
1943 case RELOC_SECTION_LIT8: sec_name = ".lit8"; break;
1944 case RELOC_SECTION_LIT4: sec_name = ".lit4"; break;
1948 sec = bfd_get_section_by_name (abfd, sec_name);
1949 if (sec == (asection *) NULL)
1951 rptr->sym_ptr_ptr = sec->symbol_ptr_ptr;
1953 rptr->addend = - bfd_get_section_vma (abfd, sec);
1954 if (intern.r_type == ECOFF_R_GPREL
1955 || intern.r_type == ECOFF_R_LITERAL)
1956 rptr->addend += ecoff_data (abfd)->gp;
1959 rptr->address = intern.r_vaddr - bfd_get_section_vma (abfd, section);
1960 rptr->howto = &ecoff_howto_table[intern.r_type];
1962 /* If the type is ECOFF_R_IGNORE, make sure this is a reference
1963 to the absolute section so that the reloc is ignored. */
1964 if (intern.r_type == ECOFF_R_IGNORE)
1965 rptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
1968 bfd_release (abfd, external_relocs);
1970 section->relocation = internal_relocs;
1975 /* Get a canonical list of relocs. */
1978 ecoff_canonicalize_reloc (abfd, section, relptr, symbols)
1986 if (section->flags & SEC_CONSTRUCTOR)
1988 arelent_chain *chain;
1990 /* This section has relocs made up by us, not the file, so take
1991 them out of their chain and place them into the data area
1993 for (count = 0, chain = section->constructor_chain;
1994 count < section->reloc_count;
1995 count++, chain = chain->next)
1996 *relptr++ = &chain->relent;
2002 if (ecoff_slurp_reloc_table (abfd, section, symbols) == false)
2005 tblptr = section->relocation;
2006 if (tblptr == (arelent *) NULL)
2009 for (count = 0; count < section->reloc_count; count++)
2010 *relptr++ = tblptr++;
2013 *relptr = (arelent *) NULL;
2015 return section->reloc_count;
2018 /* Get the howto structure for a generic reloc type. */
2020 static CONST struct reloc_howto_struct *
2021 ecoff_bfd_reloc_type_lookup (abfd, code)
2023 bfd_reloc_code_real_type code;
2030 ecoff_type = ECOFF_R_REFHALF;
2033 ecoff_type = ECOFF_R_REFWORD;
2035 case BFD_RELOC_MIPS_JMP:
2036 ecoff_type = ECOFF_R_JMPADDR;
2038 case BFD_RELOC_HI16_S:
2039 ecoff_type = ECOFF_R_REFHI;
2041 case BFD_RELOC_LO16:
2042 ecoff_type = ECOFF_R_REFLO;
2045 return (CONST struct reloc_howto_struct *) NULL;
2048 return &ecoff_howto_table[ecoff_type];
2051 /* Provided a BFD, a section and an offset into the section, calculate
2052 and return the name of the source file and the line nearest to the
2056 ecoff_find_nearest_line (abfd,
2065 asymbol **ignore_symbols;
2067 CONST char **filename_ptr;
2068 CONST char **functionname_ptr;
2069 unsigned int *retline_ptr;
2075 struct pdr_ext *pdr_ptr;
2076 struct pdr_ext *pdr_end;
2078 unsigned char *line_ptr;
2079 unsigned char *line_end;
2082 /* If we're not in the .text section, we don't have any line
2084 if (strcmp (section->name, _TEXT) != 0
2085 || offset < ecoff_data (abfd)->text_start
2086 || offset >= ecoff_data (abfd)->text_end)
2089 /* Make sure we have the FDR's. */
2090 if (ecoff_slurp_symbolic_info (abfd) == false
2091 || bfd_get_symcount (abfd) == 0)
2094 /* Each file descriptor (FDR) has a memory address. Here we track
2095 down which FDR we want. The FDR's are stored in increasing
2096 memory order. If speed is ever important, this can become a
2097 binary search. We must ignore FDR's with no PDR entries; they
2098 will have the adr of the FDR before or after them. */
2099 fdr_start = ecoff_data (abfd)->fdr;
2100 fdr_end = fdr_start + ecoff_data (abfd)->symbolic_header.ifdMax;
2101 fdr_hold = (FDR *) NULL;
2102 for (fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
2104 if (fdr_ptr->cpd == 0)
2106 if (offset < fdr_ptr->adr)
2110 if (fdr_hold == (FDR *) NULL)
2114 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2115 have an address, which is relative to the FDR address, and are
2116 also stored in increasing memory order. */
2117 offset -= fdr_ptr->adr;
2118 pdr_ptr = ecoff_data (abfd)->external_pdr + fdr_ptr->ipdFirst;
2119 pdr_end = pdr_ptr + fdr_ptr->cpd;
2120 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
2121 if (offset < pdr.adr)
2123 for (pdr_ptr++; pdr_ptr < pdr_end; pdr_ptr++)
2125 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
2126 if (offset < pdr.adr)
2130 /* Now we can look for the actual line number. The line numbers are
2131 stored in a very funky format, which I won't try to describe.
2132 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2133 we want; we need this to compute line_end. */
2134 line_end = ecoff_data (abfd)->line;
2135 if (pdr_ptr == pdr_end)
2136 line_end += fdr_ptr->cbLineOffset + fdr_ptr->cbLine;
2138 line_end += fdr_ptr->cbLineOffset + pdr.cbLineOffset;
2140 /* Now change pdr and pdr_ptr to the one we want. */
2142 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
2146 line_ptr = (ecoff_data (abfd)->line
2147 + fdr_ptr->cbLineOffset
2148 + pdr.cbLineOffset);
2149 while (line_ptr < line_end)
2154 delta = *line_ptr >> 4;
2157 count = (*line_ptr & 0xf) + 1;
2161 delta = (((line_ptr[0]) & 0xff) << 8) + ((line_ptr[1]) & 0xff);
2162 if (delta >= 0x8000)
2167 if (offset < count * 4)
2169 offset -= count * 4;
2172 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2173 at least according to gdb/mipsread.c. */
2174 if (fdr_ptr->rss == -1)
2176 *filename_ptr = NULL;
2178 *functionname_ptr = NULL;
2183 ecoff_swap_ext_in (abfd,
2184 (ecoff_data (abfd)->external_ext
2187 *functionname_ptr = ecoff_data (abfd)->ssext + proc_ext.asym.iss;
2194 *filename_ptr = ecoff_data (abfd)->ss + fdr_ptr->issBase + fdr_ptr->rss;
2195 ecoff_swap_sym_in (abfd,
2196 (ecoff_data (abfd)->external_sym
2200 *functionname_ptr = (ecoff_data (abfd)->ss
2204 *retline_ptr = lineno;
2208 /* We can't use the generic linking routines for ECOFF, because we
2209 have to handle all the debugging information. The generic link
2210 routine just works out the section contents and attaches a list of
2213 We link by looping over all the seclets. We make two passes. On
2214 the first we set the actual section contents and determine the size
2215 of the debugging information. On the second we accumulate the
2216 debugging information and write it out.
2218 This currently always accumulates the debugging information, which
2219 is incorrect, because it ignores the -s and -S options of the
2220 linker. The linker needs to be modified to give us that
2221 information in a more useful format (currently it just provides a
2222 list of symbols which should appear in the output file). */
2224 /* Clear the output_has_begun flag for all the input BFD's. We use it
2225 to avoid linking in the debugging information for a BFD more than
2229 ecoff_clear_output_flags (abfd)
2232 register asection *o;
2233 register bfd_seclet_type *p;
2235 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2236 for (p = o->seclets_head;
2237 p != (bfd_seclet_type *) NULL;
2239 if (p->type == bfd_indirect_seclet)
2240 p->u.indirect.section->owner->output_has_begun = false;
2243 /* Handle an indirect seclet on the first pass. Set the contents of
2244 the output section, and accumulate the debugging information if
2248 ecoff_rel (output_bfd, seclet, output_section, data, relocateable)
2250 bfd_seclet_type *seclet;
2251 asection *output_section;
2253 boolean relocateable;
2256 HDRR *output_symhdr;
2259 if ((output_section->flags & SEC_HAS_CONTENTS)
2260 && !(output_section->flags & SEC_NEVER_LOAD)
2261 && (output_section->flags & SEC_LOAD)
2264 data = (PTR) bfd_get_relocated_section_contents (output_bfd,
2268 if (bfd_set_section_contents (output_bfd,
2279 input_bfd = seclet->u.indirect.section->owner;
2281 /* We want to figure out how much space will be required to
2282 incorporate all the debugging information from input_bfd. We use
2283 the output_has_begun field to avoid adding it in more than once.
2284 The actual incorporation is done in the second pass, in
2285 ecoff_get_debug. The code has to parallel that code in its
2286 manipulations of output_symhdr. */
2288 if (input_bfd->output_has_begun)
2290 input_bfd->output_has_begun = true;
2292 output_symhdr = &ecoff_data (output_bfd)->symbolic_header;
2294 if (input_bfd->xvec->flavour != bfd_target_ecoff_flavour)
2300 /* We just accumulate local symbols from a non-ECOFF BFD. The
2301 external symbols are handled separately. */
2303 symbols = (asymbol **) bfd_alloc (output_bfd,
2304 get_symtab_upper_bound (input_bfd));
2305 if (symbols == (asymbol **) NULL)
2307 bfd_error = no_memory;
2310 sym_end = symbols + bfd_canonicalize_symtab (input_bfd, symbols);
2312 for (sym_ptr = symbols; sym_ptr < sym_end; sym_ptr++)
2316 len = strlen ((*sym_ptr)->name);
2317 if (((*sym_ptr)->flags & BSF_EXPORT) == 0)
2319 ++output_symhdr->isymMax;
2320 output_symhdr->issMax += len + 1;
2324 bfd_release (output_bfd, (PTR) symbols);
2326 ++output_symhdr->ifdMax;
2331 /* We simply add in the information from another ECOFF BFD. First
2332 we make sure we have the symbolic information. */
2333 if (ecoff_slurp_symbol_table (input_bfd) == false)
2335 if (bfd_get_symcount (input_bfd) == 0)
2338 input_symhdr = &ecoff_data (input_bfd)->symbolic_header;
2340 /* Figure out how much information we are going to be putting in.
2341 The external symbols are handled separately. */
2342 output_symhdr->ilineMax += input_symhdr->ilineMax;
2343 output_symhdr->cbLine += input_symhdr->cbLine;
2344 output_symhdr->idnMax += input_symhdr->idnMax;
2345 output_symhdr->ipdMax += input_symhdr->ipdMax;
2346 output_symhdr->isymMax += input_symhdr->isymMax;
2347 output_symhdr->ioptMax += input_symhdr->ioptMax;
2348 output_symhdr->iauxMax += input_symhdr->iauxMax;
2349 output_symhdr->issMax += input_symhdr->issMax;
2350 output_symhdr->ifdMax += input_symhdr->ifdMax;
2352 /* The RFD's are special, since we create them if needed. */
2353 if (input_symhdr->crfd > 0)
2354 output_symhdr->crfd += input_symhdr->crfd;
2356 output_symhdr->crfd += input_symhdr->ifdMax;
2361 /* Handle an arbitrary seclet on the first pass. */
2364 ecoff_dump_seclet (abfd, seclet, section, data, relocateable)
2366 bfd_seclet_type *seclet;
2369 boolean relocateable;
2371 switch (seclet->type)
2373 case bfd_indirect_seclet:
2374 /* The contents of this section come from another one somewhere
2376 return ecoff_rel (abfd, seclet, section, data, relocateable);
2378 case bfd_fill_seclet:
2379 /* Fill in the section with fill.value. This is used to pad out
2380 sections, but we must avoid padding the .bss section. */
2381 if ((section->flags & SEC_HAS_CONTENTS) == 0)
2383 if (seclet->u.fill.value != 0)
2388 char *d = (char *) bfd_alloc (abfd, seclet->size);
2392 for (i = 0; i < seclet->size; i+=2)
2393 d[i] = seclet->u.fill.value >> 8;
2394 for (i = 1; i < seclet->size; i+=2)
2395 d[i] = seclet->u.fill.value;
2396 ret = bfd_set_section_contents (abfd, section, d, seclet->offset,
2398 bfd_release (abfd, (PTR) d);
2410 /* Add a string to the debugging information we are accumulating for a
2411 file. Return the offset from the fdr string base or from the
2412 external string base. */
2415 ecoff_add_string (output_bfd, fdr, string, external)
2425 symhdr = &ecoff_data (output_bfd)->symbolic_header;
2426 len = strlen (string);
2429 strcpy (ecoff_data (output_bfd)->ssext + symhdr->issExtMax, string);
2430 ret = symhdr->issExtMax;
2431 symhdr->issExtMax += len + 1;
2435 strcpy (ecoff_data (output_bfd)->ss + symhdr->issMax, string);
2437 symhdr->issMax += len + 1;
2438 fdr->cbSs += len + 1;
2443 /* Accumulate the debugging information from an input section. */
2446 ecoff_get_debug (output_bfd, seclet, section, relocateable)
2448 bfd_seclet_type *seclet;
2450 boolean relocateable;
2453 HDRR *output_symhdr;
2455 ecoff_data_type *output_ecoff;
2456 ecoff_data_type *input_ecoff;
2458 struct sym_ext *sym_out;
2459 ecoff_symbol_type *esym_ptr;
2460 ecoff_symbol_type *esym_end;
2461 unsigned long pdr_off;
2464 struct fdr_ext *fdr_out;
2466 input_bfd = seclet->u.indirect.section->owner;
2468 /* Don't get the information more than once. */
2469 if (input_bfd->output_has_begun)
2471 input_bfd->output_has_begun = true;
2473 output_ecoff = ecoff_data (output_bfd);
2474 output_symhdr = &output_ecoff->symbolic_header;
2476 if (input_bfd->xvec->flavour != bfd_target_ecoff_flavour)
2483 /* This is not an ECOFF BFD. Just gather the symbols. */
2485 memset (&fdr, 0, sizeof fdr);
2487 fdr.adr = bfd_get_section_vma (output_bfd, section) + seclet->offset;
2488 fdr.issBase = output_symhdr->issMax;
2490 fdr.rss = ecoff_add_string (output_bfd,
2492 bfd_get_filename (input_bfd),
2494 fdr.isymBase = output_symhdr->isymMax;
2496 /* Get the local symbols from the input BFD. */
2497 symbols = (asymbol **) bfd_alloc (output_bfd,
2498 get_symtab_upper_bound (input_bfd));
2499 if (symbols == (asymbol **) NULL)
2501 bfd_error = no_memory;
2504 sym_end = symbols + bfd_canonicalize_symtab (input_bfd, symbols);
2506 /* Handle the local symbols. Any external symbols are handled
2509 for (sym_ptr = symbols; sym_ptr != sym_end; sym_ptr++)
2513 if (((*sym_ptr)->flags & BSF_EXPORT) != 0)
2515 memset (&internal_sym, 0, sizeof internal_sym);
2516 internal_sym.iss = ecoff_add_string (output_bfd,
2521 if (bfd_is_com_section ((*sym_ptr)->section)
2522 || (*sym_ptr)->section == &bfd_und_section)
2523 internal_sym.value = (*sym_ptr)->value;
2525 internal_sym.value = ((*sym_ptr)->value
2526 + (*sym_ptr)->section->output_offset
2527 + (*sym_ptr)->section->output_section->vma);
2528 internal_sym.st = stNil;
2529 internal_sym.sc = scUndefined;
2530 internal_sym.index = indexNil;
2531 ecoff_swap_sym_out (output_bfd, &internal_sym,
2532 (output_ecoff->external_sym
2533 + output_symhdr->isymMax));
2535 ++output_symhdr->isymMax;
2538 bfd_release (output_bfd, (PTR) symbols);
2540 /* Leave everything else in the FDR zeroed out. This will cause
2541 the lang field to be langC. The fBigendian field will
2542 indicate little endian format, but it doesn't matter because
2543 it only applies to aux fields and there are none. */
2545 ecoff_swap_fdr_out (output_bfd, &fdr,
2546 (output_ecoff->external_fdr
2547 + output_symhdr->ifdMax));
2548 ++output_symhdr->ifdMax;
2552 /* This is an ECOFF BFD. We want to grab the information from
2553 input_bfd and attach it to output_bfd. */
2554 count = bfd_get_symcount (input_bfd);
2557 input_ecoff = ecoff_data (input_bfd);
2558 input_symhdr = &input_ecoff->symbolic_header;
2560 /* I think that it is more efficient to simply copy the debugging
2561 information from the input BFD to the output BFD. Because ECOFF
2562 uses relative pointers for most of the debugging information,
2563 only a little of it has to be changed at all. */
2565 /* Swap in the local symbols, adjust their values, and swap them out
2566 again. The external symbols are handled separately. */
2567 sym_out = output_ecoff->external_sym + output_symhdr->isymMax;
2569 esym_ptr = ecoff_data (input_bfd)->canonical_symbols;
2570 esym_end = esym_ptr + count;
2571 for (; esym_ptr < esym_end; esym_ptr++)
2573 if (esym_ptr->local)
2577 ecoff_swap_sym_in (input_bfd, esym_ptr->native.lnative, &sym);
2579 /* If we're producing an executable, move common symbols
2581 if (relocateable == false)
2583 if (sym.sc == scCommon)
2585 else if (sym.sc == scSCommon)
2589 if (! bfd_is_com_section (esym_ptr->symbol.section)
2590 && (esym_ptr->symbol.flags & BSF_DEBUGGING) == 0
2591 && esym_ptr->symbol.section != &bfd_und_section)
2592 sym.value = (esym_ptr->symbol.value
2593 + esym_ptr->symbol.section->output_offset
2594 + esym_ptr->symbol.section->output_section->vma);
2595 ecoff_swap_sym_out (output_bfd, &sym, sym_out);
2600 /* That should have accounted for all the local symbols in
2602 BFD_ASSERT ((sym_out - output_ecoff->external_sym) - output_symhdr->isymMax
2603 == input_symhdr->isymMax);
2605 /* Copy the information that does not need swapping. */
2606 memcpy (output_ecoff->line + output_symhdr->cbLine,
2608 input_symhdr->cbLine * sizeof (unsigned char));
2609 memcpy (output_ecoff->external_aux + output_symhdr->iauxMax,
2610 input_ecoff->external_aux,
2611 input_symhdr->iauxMax * sizeof (union aux_ext));
2612 memcpy (output_ecoff->ss + output_symhdr->issMax,
2614 input_symhdr->issMax * sizeof (char));
2616 /* Some of the information may need to be swapped. */
2617 if (output_bfd->xvec->header_byteorder_big_p
2618 == input_bfd->xvec->header_byteorder_big_p)
2620 /* The two BFD's have the same endianness, so memcpy will
2622 memcpy (output_ecoff->external_dnr + output_symhdr->idnMax,
2623 input_ecoff->external_dnr,
2624 input_symhdr->idnMax * sizeof (struct dnr_ext));
2625 memcpy (output_ecoff->external_pdr + output_symhdr->ipdMax,
2626 input_ecoff->external_pdr,
2627 input_symhdr->ipdMax * sizeof (struct pdr_ext));
2628 if (input_symhdr->ipdMax == 0)
2634 ecoff_swap_pdr_in (input_bfd, input_ecoff->external_pdr, &pdr);
2637 memcpy (output_ecoff->external_opt + output_symhdr->ioptMax,
2638 input_ecoff->external_opt,
2639 input_symhdr->ioptMax * sizeof (struct opt_ext));
2643 struct dnr_ext *dnr_in;
2644 struct dnr_ext *dnr_end;
2645 struct dnr_ext *dnr_out;
2646 struct pdr_ext *pdr_in;
2647 struct pdr_ext *pdr_end;
2648 struct pdr_ext *pdr_out;
2650 struct opt_ext *opt_in;
2651 struct opt_ext *opt_end;
2652 struct opt_ext *opt_out;
2654 /* The two BFD's have different endianness, so we must swap
2655 everything in and out. This code would always work, but it
2656 would be slow in the normal case. */
2657 dnr_in = input_ecoff->external_dnr;
2658 dnr_end = dnr_in + input_symhdr->idnMax;
2659 dnr_out = output_ecoff->external_dnr + output_symhdr->idnMax;
2660 for (; dnr_in < dnr_end; dnr_in++, dnr_out++)
2664 ecoff_swap_dnr_in (input_bfd, dnr_in, &dnr);
2665 ecoff_swap_dnr_out (output_bfd, &dnr, dnr_out);
2667 pdr_in = input_ecoff->external_pdr;
2668 pdr_end = pdr_in + input_symhdr->ipdMax;
2669 pdr_out = output_ecoff->external_pdr + output_symhdr->ipdMax;
2672 for (; pdr_in < pdr_end; pdr_in++, pdr_out++)
2676 ecoff_swap_pdr_in (input_bfd, pdr_in, &pdr);
2677 ecoff_swap_pdr_out (output_bfd, &pdr, pdr_out);
2684 opt_in = input_ecoff->external_opt;
2685 opt_end = opt_in + input_symhdr->ioptMax;
2686 opt_out = output_ecoff->external_opt + output_symhdr->ioptMax;
2687 for (; opt_in < opt_end; opt_in++, opt_out++)
2691 ecoff_swap_opt_in (input_bfd, opt_in, &opt);
2692 ecoff_swap_opt_out (output_bfd, &opt, opt_out);
2696 /* Set ifdbase so that the external symbols know how to adjust their
2698 input_ecoff->ifdbase = output_symhdr->ifdMax;
2700 fdr_ptr = input_ecoff->fdr;
2701 fdr_end = fdr_ptr + input_symhdr->ifdMax;
2702 fdr_out = output_ecoff->external_fdr + output_symhdr->ifdMax;
2703 for (; fdr_ptr < fdr_end; fdr_ptr++, fdr_out++)
2709 /* The memory address for this fdr is the address for the seclet
2710 plus the offset to this fdr within input_bfd. For some
2711 reason the offset of the first procedure pointer is also
2713 fdr.adr = (bfd_get_section_vma (output_bfd, section)
2715 + (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 /* This must be an ECOFF reloc. */
3467 BFD_ASSERT (reloc->howto != (reloc_howto_type *) NULL
3468 && reloc->howto >= ecoff_howto_table
3470 < (ecoff_howto_table + ECOFF_HOWTO_COUNT)));
3472 in.r_vaddr = reloc->address + bfd_get_section_vma (abfd, current);
3473 in.r_type = reloc->howto->type;
3475 /* If this is a REFHI reloc, the next one must be a REFLO
3476 reloc for the same symbol. */
3477 BFD_ASSERT (in.r_type != ECOFF_R_REFHI
3478 || (reloc_ptr_ptr < reloc_end
3479 && (reloc_ptr_ptr[1]->howto
3480 != (reloc_howto_type *) NULL)
3481 && (reloc_ptr_ptr[1]->howto->type
3483 && (sym == *reloc_ptr_ptr[1]->sym_ptr_ptr)));
3485 if ((sym->flags & BSF_SECTION_SYM) == 0)
3487 in.r_symndx = ecoff_get_sym_index (*reloc->sym_ptr_ptr);
3494 name = bfd_get_section_name (abfd, bfd_get_section (sym));
3495 if (strcmp (name, ".text") == 0)
3496 in.r_symndx = RELOC_SECTION_TEXT;
3497 else if (strcmp (name, ".rdata") == 0)
3498 in.r_symndx = RELOC_SECTION_RDATA;
3499 else if (strcmp (name, ".data") == 0)
3500 in.r_symndx = RELOC_SECTION_DATA;
3501 else if (strcmp (name, ".sdata") == 0)
3502 in.r_symndx = RELOC_SECTION_SDATA;
3503 else if (strcmp (name, ".sbss") == 0)
3504 in.r_symndx = RELOC_SECTION_SBSS;
3505 else if (strcmp (name, ".bss") == 0)
3506 in.r_symndx = RELOC_SECTION_BSS;
3507 else if (strcmp (name, ".init") == 0)
3508 in.r_symndx = RELOC_SECTION_INIT;
3509 else if (strcmp (name, ".lit8") == 0)
3510 in.r_symndx = RELOC_SECTION_LIT8;
3511 else if (strcmp (name, ".lit4") == 0)
3512 in.r_symndx = RELOC_SECTION_LIT4;
3518 ecoff_swap_reloc_out (abfd, (PTR) &in, (PTR) out_ptr);
3521 if (bfd_seek (abfd, current->rel_filepos, SEEK_SET) != 0)
3523 if (bfd_write ((PTR) buff, RELSZ, current->reloc_count, abfd)
3524 != RELSZ * current->reloc_count)
3526 bfd_release (abfd, (PTR) buff);
3529 /* Write out the symbolic debugging information. */
3530 if (bfd_get_symcount (abfd) > 0)
3533 unsigned long sym_offset;
3534 struct hdr_ext buff;
3536 /* Set up the offsets in the symbolic header. */
3537 symhdr = &ecoff_data (abfd)->symbolic_header;
3538 sym_offset = ecoff_data (abfd)->sym_filepos + sizeof (struct hdr_ext);
3540 #define SET(offset, size, ptr) \
3541 if (symhdr->size == 0) \
3542 symhdr->offset = 0; \
3544 symhdr->offset = (((char *) ecoff_data (abfd)->ptr \
3545 - (char *) ecoff_data (abfd)->raw_syments) \
3548 SET (cbLineOffset, cbLine, line);
3549 SET (cbDnOffset, idnMax, external_dnr);
3550 SET (cbPdOffset, ipdMax, external_pdr);
3551 SET (cbSymOffset, isymMax, external_sym);
3552 SET (cbOptOffset, ioptMax, external_opt);
3553 SET (cbAuxOffset, iauxMax, external_aux);
3554 SET (cbSsOffset, issMax, ss);
3555 SET (cbSsExtOffset, issExtMax, ssext);
3556 SET (cbFdOffset, ifdMax, external_fdr);
3557 SET (cbRfdOffset, crfd, external_rfd);
3558 SET (cbExtOffset, iextMax, external_ext);
3561 if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos,
3564 ecoff_swap_hdr_out (abfd, &ecoff_data (abfd)->symbolic_header, &buff);
3565 if (bfd_write ((PTR) &buff, 1, sizeof buff, abfd) != sizeof buff)
3567 if (bfd_write ((PTR) ecoff_data (abfd)->raw_syments, 1,
3568 ecoff_data (abfd)->raw_size, abfd)
3569 != ecoff_data (abfd)->raw_size)
3576 /* Archive handling. ECOFF uses what appears to be a unique type of
3577 archive header (which I call an armap). The byte ordering of the
3578 armap and the contents are encoded in the name of the armap itself.
3579 At least for now, we only support archives with the same byte
3580 ordering in the armap and the contents.
3582 The first four bytes in the armap are the number of symbol
3583 definitions. This is always a power of two.
3585 This is followed by the symbol definitions. Each symbol definition
3586 occupies 8 bytes. The first four bytes are the offset from the
3587 start of the armap strings to the null-terminated string naming
3588 this symbol. The second four bytes are the file offset to the
3589 archive member which defines this symbol. If the second four bytes
3590 are 0, then this is not actually a symbol definition, and it should
3593 The symbols are hashed into the armap with a closed hashing scheme.
3594 See the functions below for the details of the algorithm.
3596 We could use the hash table when looking up symbols in a library.
3597 This would require a new BFD target entry point to replace the
3598 bfd_get_next_mapent function used by the linker.
3600 After the symbol definitions comes four bytes holding the size of
3601 the string table, followed by the string table itself. */
3603 /* The name of an archive headers looks like this:
3604 __________E[BL]E[BL]_ (with a trailing space).
3605 The trailing space is changed to an X if the archive is changed to
3606 indicate that the armap is out of date. */
3608 #define ARMAP_BIG_ENDIAN 'B'
3609 #define ARMAP_LITTLE_ENDIAN 'L'
3610 #define ARMAP_MARKER 'E'
3611 #define ARMAP_START "__________"
3612 #define ARMAP_HEADER_MARKER_INDEX 10
3613 #define ARMAP_HEADER_ENDIAN_INDEX 11
3614 #define ARMAP_OBJECT_MARKER_INDEX 12
3615 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3616 #define ARMAP_END_INDEX 14
3617 #define ARMAP_END "_ "
3619 /* This is a magic number used in the hashing algorithm. */
3620 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3622 /* This returns the hash value to use for a string. It also sets
3623 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3624 is the number of entries in the hash table, and HLOG is the log
3628 ecoff_armap_hash (s, rehash, size, hlog)
3630 unsigned int *rehash;
3638 hash = ((hash >> 27) | (hash << 5)) + *s++;
3639 hash *= ARMAP_HASH_MAGIC;
3640 *rehash = (hash & (size - 1)) | 1;
3641 return hash >> (32 - hlog);
3644 /* Read in the armap. */
3647 ecoff_slurp_armap (abfd)
3652 struct areltdata *mapdata;
3653 bfd_size_type parsed_size;
3655 struct artdata *ardata;
3658 struct symdef *symdef_ptr;
3661 /* Get the name of the first element. */
3662 i = bfd_read ((PTR) nextname, 1, 16, abfd);
3668 bfd_seek (abfd, (file_ptr) -16, SEEK_CUR);
3670 /* See if the first element is an armap. */
3671 if (strncmp (nextname, ARMAP_START, sizeof ARMAP_START - 1) != 0
3672 || nextname[ARMAP_HEADER_MARKER_INDEX] != ARMAP_MARKER
3673 || (nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
3674 && nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
3675 || nextname[ARMAP_OBJECT_MARKER_INDEX] != ARMAP_MARKER
3676 || (nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
3677 && nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
3678 || strncmp (nextname + ARMAP_END_INDEX,
3679 ARMAP_END, sizeof ARMAP_END - 1) != 0)
3681 bfd_has_map (abfd) = false;
3685 /* Make sure we have the right byte ordering. */
3686 if (((nextname[ARMAP_HEADER_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
3687 ^ (abfd->xvec->header_byteorder_big_p != false))
3688 || ((nextname[ARMAP_OBJECT_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
3689 ^ (abfd->xvec->byteorder_big_p != false)))
3691 bfd_error = wrong_format;
3695 /* Read in the armap. */
3696 ardata = bfd_ardata (abfd);
3697 mapdata = snarf_ar_hdr (abfd);
3698 if (mapdata == (struct areltdata *) NULL)
3700 parsed_size = mapdata->parsed_size;
3701 bfd_release (abfd, (PTR) mapdata);
3703 raw_armap = (char *) bfd_alloc (abfd, parsed_size);
3704 if (raw_armap == (char *) NULL)
3706 bfd_error = no_memory;
3710 if (bfd_read ((PTR) raw_armap, 1, parsed_size, abfd) != parsed_size)
3712 bfd_error = malformed_archive;
3713 bfd_release (abfd, (PTR) raw_armap);
3717 count = bfd_h_get_32 (abfd, (PTR) raw_armap);
3719 ardata->symdef_count = 0;
3720 ardata->cache = (struct ar_cache *) NULL;
3722 /* Hack: overlay the symdefs on top of the raw archive data. This
3723 is the way do_slurp_bsd_armap works. */
3724 raw_ptr = raw_armap + LONG_SIZE;
3725 symdef_ptr = (struct symdef *) raw_ptr;
3726 ardata->symdefs = (carsym *) symdef_ptr;
3727 stringbase = raw_ptr + count * (2 * LONG_SIZE) + LONG_SIZE;
3729 #ifdef CHECK_ARMAP_HASH
3733 /* Double check that I have the hashing algorithm right by making
3734 sure that every symbol can be looked up successfully. */
3736 for (i = 1; i < count; i <<= 1)
3738 BFD_ASSERT (i == count);
3740 for (i = 0; i < count; i++, raw_ptr += 2 * LONG_SIZE)
3742 unsigned int name_offset, file_offset;
3743 unsigned int hash, rehash, srch;
3745 name_offset = bfd_h_get_32 (abfd, (PTR) raw_ptr);
3746 file_offset = bfd_h_get_32 (abfd, (PTR) (raw_ptr + LONG_SIZE));
3747 if (file_offset == 0)
3749 hash = ecoff_armap_hash (stringbase + name_offset, &rehash, count,
3754 /* See if we can rehash to this location. */
3755 for (srch = (hash + rehash) & (count - 1);
3756 srch != hash && srch != i;
3757 srch = (srch + rehash) & (count - 1))
3758 BFD_ASSERT (bfd_h_get_32 (abfd,
3761 + (srch * 2 * LONG_SIZE)
3764 BFD_ASSERT (srch == i);
3768 raw_ptr = raw_armap + LONG_SIZE;
3769 #endif /* CHECK_ARMAP_HASH */
3771 for (i = 0; i < count; i++, raw_ptr += 2 * LONG_SIZE)
3773 unsigned int name_offset, file_offset;
3775 name_offset = bfd_h_get_32 (abfd, (PTR) raw_ptr);
3776 file_offset = bfd_h_get_32 (abfd, (PTR) (raw_ptr + LONG_SIZE));
3777 if (file_offset == 0)
3779 symdef_ptr->s.name = stringbase + name_offset;
3780 symdef_ptr->file_offset = file_offset;
3782 ++ardata->symdef_count;
3785 ardata->first_file_filepos = bfd_tell (abfd);
3786 /* Pad to an even boundary. */
3787 ardata->first_file_filepos += ardata->first_file_filepos % 2;
3789 bfd_has_map (abfd) = true;
3794 /* Write out an armap. */
3797 ecoff_write_armap (abfd, elength, map, orl_count, stridx)
3799 unsigned int elength;
3801 unsigned int orl_count;
3804 unsigned int hashsize, hashlog;
3805 unsigned int symdefsize;
3807 unsigned int stringsize;
3808 unsigned int mapsize;
3811 struct stat statbuf;
3813 bfd_byte temp[LONG_SIZE];
3814 bfd_byte *hashtable;
3818 /* Ultrix appears to use as a hash table size the least power of two
3819 greater than twice the number of entries. */
3820 for (hashlog = 0; (1 << hashlog) <= 2 * orl_count; hashlog++)
3822 hashsize = 1 << hashlog;
3824 symdefsize = hashsize * 2 * LONG_SIZE;
3826 stringsize = stridx + padit;
3828 /* Include 8 bytes to store symdefsize and stringsize in output. */
3829 mapsize = LONG_SIZE + symdefsize + stringsize + LONG_SIZE;
3831 firstreal = SARMAG + sizeof (struct ar_hdr) + mapsize + elength;
3833 memset ((PTR) &hdr, 0, sizeof hdr);
3835 /* Work out the ECOFF armap name. */
3836 strcpy (hdr.ar_name, ARMAP_START);
3837 hdr.ar_name[ARMAP_HEADER_MARKER_INDEX] = ARMAP_MARKER;
3838 hdr.ar_name[ARMAP_HEADER_ENDIAN_INDEX] =
3839 (abfd->xvec->header_byteorder_big_p
3841 : ARMAP_LITTLE_ENDIAN);
3842 hdr.ar_name[ARMAP_OBJECT_MARKER_INDEX] = ARMAP_MARKER;
3843 hdr.ar_name[ARMAP_OBJECT_ENDIAN_INDEX] =
3844 abfd->xvec->byteorder_big_p ? ARMAP_BIG_ENDIAN : ARMAP_LITTLE_ENDIAN;
3845 memcpy (hdr.ar_name + ARMAP_END_INDEX, ARMAP_END, sizeof ARMAP_END - 1);
3847 /* Write the timestamp of the archive header to be just a little bit
3848 later than the timestamp of the file, otherwise the linker will
3849 complain that the index is out of date. Actually, the Ultrix
3850 linker just checks the archive name; the GNU linker may check the
3852 stat (abfd->filename, &statbuf);
3853 sprintf (hdr.ar_date, "%ld", (long) (statbuf.st_mtime + 60));
3855 /* The DECstation uses zeroes for the uid, gid and mode of the
3857 hdr.ar_uid[0] = '0';
3858 hdr.ar_gid[0] = '0';
3859 hdr.ar_mode[0] = '0';
3861 sprintf (hdr.ar_size, "%-10d", (int) mapsize);
3863 hdr.ar_fmag[0] = '`';
3864 hdr.ar_fmag[1] = '\n';
3866 /* Turn all null bytes in the header into spaces. */
3867 for (i = 0; i < sizeof (struct ar_hdr); i++)
3868 if (((char *)(&hdr))[i] == '\0')
3869 (((char *)(&hdr))[i]) = ' ';
3871 if (bfd_write ((PTR) &hdr, 1, sizeof (struct ar_hdr), abfd)
3872 != sizeof (struct ar_hdr))
3875 bfd_h_put_32 (abfd, hashsize, temp);
3876 if (bfd_write (temp, 1, LONG_SIZE, abfd) != LONG_SIZE)
3879 hashtable = (bfd_byte *) bfd_zalloc (abfd, symdefsize);
3881 current = abfd->archive_head;
3883 for (i = 0; i < orl_count; i++)
3885 unsigned int hash, rehash;
3887 /* Advance firstreal to the file position of this archive
3889 if (((bfd *) map[i].pos) != last_elt)
3893 firstreal += arelt_size (current) + sizeof (struct ar_hdr);
3894 firstreal += firstreal % 2;
3895 current = current->next;
3897 while (current != (bfd *) map[i].pos);
3902 hash = ecoff_armap_hash (*map[i].name, &rehash, hashsize, hashlog);
3903 if (bfd_h_get_32 (abfd, (PTR) (hashtable
3904 + (hash * 2 * LONG_SIZE)
3910 /* The desired slot is already taken. */
3911 for (srch = (hash + rehash) & (hashsize - 1);
3913 srch = (srch + rehash) & (hashsize - 1))
3914 if (bfd_h_get_32 (abfd, (PTR) (hashtable
3915 + (srch * 2 * LONG_SIZE)
3920 BFD_ASSERT (srch != hash);
3925 bfd_h_put_32 (abfd, map[i].namidx,
3926 (PTR) (hashtable + hash * 2 * LONG_SIZE));
3927 bfd_h_put_32 (abfd, firstreal,
3928 (PTR) (hashtable + hash * 2 * LONG_SIZE + LONG_SIZE));
3931 if (bfd_write (hashtable, 1, symdefsize, abfd) != symdefsize)
3934 bfd_release (abfd, hashtable);
3936 /* Now write the strings. */
3937 bfd_h_put_32 (abfd, stringsize, temp);
3938 if (bfd_write (temp, 1, LONG_SIZE, abfd) != LONG_SIZE)
3940 for (i = 0; i < orl_count; i++)
3944 len = strlen (*map[i].name) + 1;
3945 if (bfd_write ((PTR) (*map[i].name), 1, len, abfd) != len)
3949 /* The spec sez this should be a newline. But in order to be
3950 bug-compatible for DECstation ar we use a null. */
3953 if (bfd_write ("\0", 1, 1, abfd) != 1)
3960 /* We just use the generic extended name support. This is a GNU
3962 #define ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table
3964 /* See whether this BFD is an archive. If it is, read in the armap
3965 and the extended name table. */
3968 ecoff_archive_p (abfd)
3971 char armag[SARMAG + 1];
3973 if (bfd_read ((PTR) armag, 1, SARMAG, abfd) != SARMAG
3974 || strncmp (armag, ARMAG, SARMAG) != 0)
3976 bfd_error = wrong_format;
3977 return (bfd_target *) NULL;
3980 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
3981 involves a cast, we can't do it as the left operand of
3983 abfd->tdata.aout_ar_data =
3984 (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata));
3986 if (bfd_ardata (abfd) == (struct artdata *) NULL)
3988 bfd_error = no_memory;
3989 return (bfd_target *) NULL;
3992 bfd_ardata (abfd)->first_file_filepos = SARMAG;
3994 if (ecoff_slurp_armap (abfd) == false
3995 || ecoff_slurp_extended_name_table (abfd) == false)
3997 bfd_release (abfd, bfd_ardata (abfd));
3998 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
3999 return (bfd_target *) NULL;
4005 /* This is the COFF backend structure. The backend_data field of the
4006 bfd_target structure is set to this. The section reading code in
4007 coffgen.c uses this structure. */
4009 static CONST bfd_coff_backend_data bfd_ecoff_std_swap_table = {
4010 (void (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_in */
4011 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_in */
4012 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_in */
4013 (unsigned (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_out */
4014 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_out */
4015 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_out */
4016 ecoff_swap_reloc_out, ecoff_swap_filehdr_out, ecoff_swap_aouthdr_out,
4017 ecoff_swap_scnhdr_out,
4018 FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, true,
4019 ecoff_swap_filehdr_in, ecoff_swap_aouthdr_in, ecoff_swap_scnhdr_in,
4020 ecoff_bad_format_hook, ecoff_set_arch_mach_hook, ecoff_mkobject_hook,
4021 ecoff_styp_to_sec_flags, ecoff_make_section_hook, ecoff_set_alignment_hook,
4022 ecoff_slurp_symbol_table
4025 /* get_lineno could be written for ECOFF, but it would currently only
4026 be useful for linking ECOFF and COFF files together, which doesn't
4028 #define ecoff_get_lineno \
4029 ((alent *(*) PARAMS ((bfd *, asymbol *))) bfd_nullvoidptr)
4031 /* These bfd_target functions are defined in other files. */
4033 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
4034 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
4035 #define ecoff_core_file_matches_executable_p \
4036 _bfd_dummy_core_file_matches_executable_p
4037 #define ecoff_truncate_arname bfd_dont_truncate_arname
4038 #define ecoff_openr_next_archived_file bfd_generic_openr_next_archived_file
4039 #define ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt
4040 #define ecoff_get_section_contents bfd_generic_get_section_contents
4041 #define ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound
4042 #define ecoff_close_and_cleanup bfd_generic_close_and_cleanup
4043 #define ecoff_bfd_debug_info_start bfd_void
4044 #define ecoff_bfd_debug_info_end bfd_void
4045 #define ecoff_bfd_debug_info_accumulate \
4046 ((void (*) PARAMS ((bfd *, struct sec *))) bfd_void)
4047 #define ecoff_bfd_get_relocated_section_contents \
4048 bfd_generic_get_relocated_section_contents
4049 #define ecoff_bfd_relax_section bfd_generic_relax_section
4050 #define ecoff_bfd_make_debug_symbol \
4051 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
4053 bfd_target ecoff_little_vec =
4055 "ecoff-littlemips", /* name */
4056 bfd_target_ecoff_flavour,
4057 false, /* data byte order is little */
4058 false, /* header byte order is little */
4060 (HAS_RELOC | EXEC_P | /* object flags */
4061 HAS_LINENO | HAS_DEBUG |
4062 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
4064 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect
4066 0, /* leading underscore */
4067 '/', /* ar_pad_char */
4068 15, /* ar_max_namelen */
4069 3, /* minimum alignment power */
4070 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
4071 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
4073 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
4074 ecoff_archive_p, _bfd_dummy_target},
4075 {bfd_false, ecoff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
4077 {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */
4078 _bfd_write_archive_contents, bfd_false},
4080 (PTR) &bfd_ecoff_std_swap_table
4083 bfd_target ecoff_big_vec =
4085 "ecoff-bigmips", /* name */
4086 bfd_target_ecoff_flavour,
4087 true, /* data byte order is big */
4088 true, /* header byte order is big */
4090 (HAS_RELOC | EXEC_P | /* object flags */
4091 HAS_LINENO | HAS_DEBUG |
4092 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
4094 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect flags */
4095 0, /* leading underscore */
4096 ' ', /* ar_pad_char */
4097 16, /* ar_max_namelen */
4098 3, /* minimum alignment power */
4099 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16,
4100 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16,
4101 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
4102 ecoff_archive_p, _bfd_dummy_target},
4103 {bfd_false, ecoff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
4105 {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */
4106 _bfd_write_archive_contents, bfd_false},
4108 (PTR) &bfd_ecoff_std_swap_table
4109 /* Note that there is another bfd_target just above this one. If
4110 you are adding initializers here, you should be adding them there