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 /* The page boundary used to align sections in the executable file. */
63 #define ROUND_SIZE 0x1000
65 /* The linker needs a section to hold small common variables while
66 linking. There is no convenient way to create it when the linker
67 needs it, so we always create one for each BFD. We then avoid
69 #define SCOMMON ".scommon"
71 /* MIPS ECOFF has COFF sections, but the debugging information is
72 stored in a completely different format. This files uses the some
73 of the swapping routines from coffswap.h, and some of the generic
74 COFF routines in coffgen.c, but, unlike the real COFF targets, does
75 not use coffcode.h itself. */
77 /* Prototypes for static functions. */
79 static boolean ecoff_bad_format_hook PARAMS ((bfd *abfd, PTR filehdr));
80 static asection *ecoff_make_section_hook PARAMS ((bfd *abfd, char *name));
81 static boolean ecoff_new_section_hook PARAMS ((bfd *abfd, asection *section));
82 static boolean ecoff_mkobject PARAMS ((bfd *abfd));
83 static PTR ecoff_mkobject_hook PARAMS ((bfd *abfd, PTR filehdr, PTR aouthdr));
84 static boolean ecoff_set_arch_mach_hook PARAMS ((bfd *abfd, PTR filehdr));
85 static long ecoff_sec_to_styp_flags PARAMS ((CONST char *name,
87 static flagword ecoff_styp_to_sec_flags PARAMS ((bfd *abfd, PTR hdr));
88 static asymbol *ecoff_make_empty_symbol PARAMS ((bfd *abfd));
89 static void ecoff_set_symbol_info PARAMS ((bfd *abfd, SYMR *ecoff_sym,
90 asymbol *asym, int ext));
91 static boolean ecoff_slurp_symbol_table PARAMS ((bfd *abfd));
92 static unsigned int ecoff_get_symtab_upper_bound PARAMS ((bfd *abfd));
93 static unsigned int ecoff_get_symtab PARAMS ((bfd *abfd,
94 asymbol **alocation));
95 static void ecoff_emit_aggregate PARAMS ((bfd *abfd, char *string,
96 RNDXR *rndx, long isym,
98 static char *ecoff_type_to_string PARAMS ((bfd *abfd, union aux_ext *aux_ptr,
99 int indx, int bigendian));
100 static void ecoff_print_symbol PARAMS ((bfd *abfd, PTR filep,
102 bfd_print_symbol_type how));
103 static void ecoff_swap_reloc_in PARAMS ((bfd *abfd, RELOC *ext,
104 struct internal_reloc *intern));
105 static unsigned int ecoff_swap_reloc_out PARAMS ((bfd *abfd, PTR src,
107 static bfd_reloc_status_type ecoff_generic_reloc PARAMS ((bfd *abfd,
113 static bfd_reloc_status_type ecoff_refhi_reloc PARAMS ((bfd *abfd,
119 static bfd_reloc_status_type ecoff_reflo_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);
298 ecoff->sym_filepos = internal_f->f_symptr;
300 if (internal_a != (struct internal_aouthdr *) NULL)
304 ecoff->text_start = internal_a->text_start;
305 ecoff->text_end = internal_a->text_start + internal_a->tsize;
306 ecoff->gp = internal_a->gp_value;
307 ecoff->gprmask = internal_a->gprmask;
308 for (i = 0; i < 4; i++)
309 ecoff->cprmask[i] = internal_a->cprmask[i];
315 /* Determine the machine architecture and type. */
318 ecoff_set_arch_mach_hook (abfd, filehdr)
322 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
323 enum bfd_architecture arch;
325 switch (internal_f->f_magic)
328 case MIPS_MAGIC_LITTLE:
330 arch = bfd_arch_mips;
334 arch = bfd_arch_obscure;
338 bfd_default_set_arch_mach (abfd, arch, (unsigned long) 0);
343 /* Get the section s_flags to use for a section. */
346 ecoff_sec_to_styp_flags (name, flags)
354 if (strcmp (name, _TEXT) == 0)
356 else if (strcmp (name, _DATA) == 0)
358 else if (strcmp (name, _SDATA) == 0)
360 else if (strcmp (name, _RDATA) == 0)
362 else if (strcmp (name, _LIT8) == 0)
364 else if (strcmp (name, _LIT4) == 0)
366 else if (strcmp (name, _BSS) == 0)
368 else if (strcmp (name, _SBSS) == 0)
370 else if (flags & SEC_CODE)
372 else if (flags & SEC_DATA)
374 else if (flags & SEC_READONLY)
376 else if (flags & SEC_LOAD)
381 if (flags & SEC_NEVER_LOAD)
387 /* Get the BFD flags to use for a section. */
390 ecoff_styp_to_sec_flags (abfd, hdr)
394 struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
395 long styp_flags = internal_s->s_flags;
396 flagword sec_flags=0;
398 if (styp_flags & STYP_NOLOAD)
399 sec_flags |= SEC_NEVER_LOAD;
401 /* For 386 COFF, at least, an unloadable text or data section is
402 actually a shared library section. */
403 if (styp_flags & STYP_TEXT)
405 if (sec_flags & SEC_NEVER_LOAD)
406 sec_flags |= SEC_CODE | SEC_SHARED_LIBRARY;
408 sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
410 else if ((styp_flags & STYP_DATA)
411 || (styp_flags & STYP_RDATA)
412 || (styp_flags & STYP_SDATA))
414 if (sec_flags & SEC_NEVER_LOAD)
415 sec_flags |= SEC_DATA | SEC_SHARED_LIBRARY;
417 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
418 if (styp_flags & STYP_RDATA)
419 sec_flags |= SEC_READONLY;
421 else if ((styp_flags & STYP_BSS)
422 || (styp_flags & STYP_SBSS))
424 sec_flags |= SEC_ALLOC;
426 else if (styp_flags & STYP_INFO)
428 sec_flags |= SEC_NEVER_LOAD;
430 else if ((styp_flags & STYP_LIT8)
431 || (styp_flags & STYP_LIT4))
433 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
437 sec_flags |= SEC_ALLOC | SEC_LOAD;
443 /* Read in and swap the important symbolic information for an ECOFF
444 object file. FIXME: This is called by gdb. If there is ever
445 another ECOFF target, it should be moved into some sort of target
446 specific structure. */
449 ecoff_slurp_symbolic_info (abfd)
452 struct hdr_ext external_symhdr;
453 HDRR *internal_symhdr;
454 bfd_size_type raw_base;
455 bfd_size_type raw_size;
457 struct fdr_ext *fraw_src;
458 struct fdr_ext *fraw_end;
461 /* Check whether we've already gotten it, and whether there's any to
463 if (ecoff_data (abfd)->raw_syments != (PTR) NULL)
465 if (ecoff_data (abfd)->sym_filepos == 0)
467 bfd_get_symcount (abfd) = 0;
471 /* At this point bfd_get_symcount (abfd) holds the number of symbols
472 as read from the file header, but on ECOFF this is always the
473 size of the symbolic information header. It would be cleaner to
474 handle this when we first read the file in coffgen.c. */
475 if (bfd_get_symcount (abfd) != sizeof (external_symhdr))
477 bfd_error = bad_value;
481 /* Read the symbolic information header. */
482 if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) == -1
483 || (bfd_read ((PTR) &external_symhdr, sizeof (external_symhdr), 1, abfd)
484 != sizeof (external_symhdr)))
486 bfd_error = system_call_error;
489 internal_symhdr = &ecoff_data (abfd)->symbolic_header;
490 ecoff_swap_hdr_in (abfd, &external_symhdr, internal_symhdr);
492 if (internal_symhdr->magic != magicSym)
494 bfd_error = bad_value;
498 /* Now we can get the correct number of symbols. */
499 bfd_get_symcount (abfd) = (internal_symhdr->isymMax
500 + internal_symhdr->iextMax);
502 /* Read all the symbolic information at once. */
503 raw_base = ecoff_data (abfd)->sym_filepos + sizeof (struct hdr_ext);
505 if (internal_symhdr->cbExtOffset != 0)
506 raw_size = (internal_symhdr->cbExtOffset
508 + internal_symhdr->iextMax * sizeof (struct ext_ext));
511 long cbline, issmax, issextmax;
513 cbline = (internal_symhdr->cbLine + 3) &~ 3;
514 issmax = (internal_symhdr->issMax + 3) &~ 3;
515 issextmax = (internal_symhdr->issExtMax + 3) &~ 3;
516 raw_size = (cbline * sizeof (unsigned char)
517 + internal_symhdr->idnMax * sizeof (struct dnr_ext)
518 + internal_symhdr->ipdMax * sizeof (struct pdr_ext)
519 + internal_symhdr->isymMax * sizeof (struct sym_ext)
520 + internal_symhdr->ioptMax * sizeof (struct opt_ext)
521 + internal_symhdr->iauxMax * sizeof (union aux_ext)
522 + issmax * sizeof (char)
523 + issextmax * sizeof (char)
524 + internal_symhdr->ifdMax * sizeof (struct fdr_ext)
525 + internal_symhdr->crfd * sizeof (struct rfd_ext)
526 + internal_symhdr->iextMax * sizeof (struct ext_ext));
531 ecoff_data (abfd)->sym_filepos = 0;
534 raw = (PTR) bfd_alloc (abfd, raw_size);
537 bfd_error = no_memory;
540 if (bfd_read (raw, raw_size, 1, abfd) != raw_size)
542 bfd_error = system_call_error;
543 bfd_release (abfd, raw);
547 ecoff_data (abfd)->raw_size = raw_size;
548 ecoff_data (abfd)->raw_syments = raw;
550 /* Get pointers for the numeric offsets in the HDRR structure. */
551 #define FIX(off1, off2, type) \
552 if (internal_symhdr->off1 == 0) \
553 ecoff_data (abfd)->off2 = (type *) NULL; \
555 ecoff_data (abfd)->off2 = (type *) ((char *) raw \
556 + internal_symhdr->off1 \
558 FIX (cbLineOffset, line, unsigned char);
559 FIX (cbDnOffset, external_dnr, struct dnr_ext);
560 FIX (cbPdOffset, external_pdr, struct pdr_ext);
561 FIX (cbSymOffset, external_sym, struct sym_ext);
562 FIX (cbOptOffset, external_opt, struct opt_ext);
563 FIX (cbAuxOffset, external_aux, union aux_ext);
564 FIX (cbSsOffset, ss, char);
565 FIX (cbSsExtOffset, ssext, char);
566 FIX (cbFdOffset, external_fdr, struct fdr_ext);
567 FIX (cbRfdOffset, external_rfd, struct rfd_ext);
568 FIX (cbExtOffset, external_ext, struct ext_ext);
571 /* I don't want to always swap all the data, because it will just
572 waste time and most programs will never look at it. The only
573 time the linker needs most of the debugging information swapped
574 is when linking big-endian and little-endian MIPS object files
575 together, which is not a common occurrence.
577 We need to look at the fdr to deal with a lot of information in
578 the symbols, so we swap them here. */
579 ecoff_data (abfd)->fdr = (struct fdr *) bfd_alloc (abfd,
580 (internal_symhdr->ifdMax *
581 sizeof (struct fdr)));
582 if (ecoff_data (abfd)->fdr == NULL)
584 bfd_error = no_memory;
587 fdr_ptr = ecoff_data (abfd)->fdr;
588 fraw_src = ecoff_data (abfd)->external_fdr;
589 fraw_end = fraw_src + internal_symhdr->ifdMax;
590 for (; fraw_src < fraw_end; fraw_src++, fdr_ptr++)
591 ecoff_swap_fdr_in (abfd, fraw_src, fdr_ptr);
596 /* ECOFF symbol table routines. The ECOFF symbol table is described
597 in gcc/mips-tfile.c. */
599 /* ECOFF uses two common sections. One is the usual one, and the
600 other is for small objects. All the small objects are kept
601 together, and then referenced via the gp pointer, which yields
602 faster assembler code. This is what we use for the small common
604 static asection ecoff_scom_section;
605 static asymbol ecoff_scom_symbol;
606 static asymbol *ecoff_scom_symbol_ptr;
608 /* Create an empty symbol. */
611 ecoff_make_empty_symbol (abfd)
614 ecoff_symbol_type *new;
616 new = (ecoff_symbol_type *) bfd_alloc (abfd, sizeof (ecoff_symbol_type));
617 if (new == (ecoff_symbol_type *) NULL)
619 bfd_error = no_memory;
620 return (asymbol *) NULL;
622 memset (new, 0, sizeof *new);
623 new->symbol.section = (asection *) NULL;
624 new->fdr = (FDR *) NULL;
626 new->native.lnative = (struct sym_ext *) NULL;
627 new->symbol.the_bfd = abfd;
631 /* Set the BFD flags and section for an ECOFF symbol. */
634 ecoff_set_symbol_info (abfd, ecoff_sym, asym, ext)
640 asym->the_bfd = abfd;
641 asym->value = ecoff_sym->value;
642 asym->section = &bfd_debug_section;
645 /* Most symbol types are just for debugging. */
646 switch (ecoff_sym->st)
655 if (MIPS_IS_STAB (ecoff_sym))
657 asym->flags = BSF_DEBUGGING;
662 asym->flags = BSF_DEBUGGING;
667 asym->flags = BSF_EXPORT | BSF_GLOBAL;
669 asym->flags = BSF_LOCAL;
670 switch (ecoff_sym->sc)
673 /* Used for compiler generated labels. Leave them in the
674 debugging section, and mark them as local. If BSF_DEBUGGING
675 is set, then nm does not display them for some reason. If no
676 flags are set then the linker whines about them. */
677 asym->flags = BSF_LOCAL;
680 asym->section = bfd_make_section_old_way (abfd, ".text");
681 asym->value -= asym->section->vma;
684 asym->section = bfd_make_section_old_way (abfd, ".data");
685 asym->value -= asym->section->vma;
690 asym->section = &bfd_com_section;
695 asym->section = bfd_make_section_old_way (abfd, ".bss");
696 asym->value -= asym->section->vma;
700 asym->flags = BSF_DEBUGGING;
703 asym->section = &bfd_abs_section;
706 asym->section = &bfd_und_section;
716 asym->flags = BSF_DEBUGGING;
719 asym->section = bfd_make_section_old_way (abfd, ".sdata");
720 asym->value -= asym->section->vma;
723 asym->section = bfd_make_section_old_way (abfd, ".sbss");
725 asym->value -= asym->section->vma;
728 asym->section = bfd_make_section_old_way (abfd, ".rdata");
729 asym->value -= asym->section->vma;
732 asym->flags = BSF_DEBUGGING;
735 if (asym->value > ecoff_data (abfd)->gp_size)
737 asym->section = &bfd_com_section;
743 if (ecoff_scom_section.name == NULL)
745 /* Initialize the small common section. */
746 ecoff_scom_section.name = SCOMMON;
747 ecoff_scom_section.flags = SEC_IS_COMMON;
748 ecoff_scom_section.output_section = &ecoff_scom_section;
749 ecoff_scom_section.symbol = &ecoff_scom_symbol;
750 ecoff_scom_section.symbol_ptr_ptr = &ecoff_scom_symbol_ptr;
751 ecoff_scom_symbol.name = SCOMMON;
752 ecoff_scom_symbol.flags = BSF_SECTION_SYM;
753 ecoff_scom_symbol.section = &ecoff_scom_section;
754 ecoff_scom_symbol_ptr = &ecoff_scom_symbol;
756 asym->section = &ecoff_scom_section;
761 asym->flags = BSF_DEBUGGING;
764 asym->section = &bfd_und_section;
769 asym->section = bfd_make_section_old_way (abfd, ".init");
770 asym->value -= asym->section->vma;
775 asym->flags = BSF_DEBUGGING;
778 asym->section = bfd_make_section_old_way (abfd, ".fini");
779 asym->value -= asym->section->vma;
786 /* Read an ECOFF symbol table. */
789 ecoff_slurp_symbol_table (abfd)
792 bfd_size_type internal_size;
793 ecoff_symbol_type *internal;
794 ecoff_symbol_type *internal_ptr;
795 struct ext_ext *eraw_src;
796 struct ext_ext *eraw_end;
800 /* If we've already read in the symbol table, do nothing. */
801 if (ecoff_data (abfd)->canonical_symbols != NULL)
804 /* Get the symbolic information. */
805 if (ecoff_slurp_symbolic_info (abfd) == false)
807 if (bfd_get_symcount (abfd) == 0)
810 internal_size = bfd_get_symcount (abfd) * sizeof (ecoff_symbol_type);
811 internal = (ecoff_symbol_type *) bfd_alloc (abfd, internal_size);
812 if (internal == NULL)
814 bfd_error = no_memory;
818 internal_ptr = internal;
819 eraw_src = ecoff_data (abfd)->external_ext;
820 eraw_end = eraw_src + ecoff_data (abfd)->symbolic_header.iextMax;
821 for (; eraw_src < eraw_end; eraw_src++, internal_ptr++)
825 ecoff_swap_ext_in (abfd, eraw_src, &internal_esym);
826 internal_ptr->symbol.name = (ecoff_data (abfd)->ssext
827 + internal_esym.asym.iss);
828 ecoff_set_symbol_info (abfd, &internal_esym.asym,
829 &internal_ptr->symbol, 1);
830 internal_ptr->fdr = ecoff_data (abfd)->fdr + internal_esym.ifd;
831 internal_ptr->local = false;
832 internal_ptr->native.enative = eraw_src;
835 /* The local symbols must be accessed via the fdr's, because the
836 string and aux indices are relative to the fdr information. */
837 fdr_ptr = ecoff_data (abfd)->fdr;
838 fdr_end = fdr_ptr + ecoff_data (abfd)->symbolic_header.ifdMax;
839 for (; fdr_ptr < fdr_end; fdr_ptr++)
841 struct sym_ext *lraw_src;
842 struct sym_ext *lraw_end;
844 lraw_src = ecoff_data (abfd)->external_sym + fdr_ptr->isymBase;
845 lraw_end = lraw_src + fdr_ptr->csym;
846 for (; lraw_src < lraw_end; lraw_src++, internal_ptr++)
850 ecoff_swap_sym_in (abfd, lraw_src, &internal_sym);
851 internal_ptr->symbol.name = (ecoff_data (abfd)->ss
854 ecoff_set_symbol_info (abfd, &internal_sym,
855 &internal_ptr->symbol, 0);
856 internal_ptr->fdr = fdr_ptr;
857 internal_ptr->local = true;
858 internal_ptr->native.lnative = lraw_src;
862 ecoff_data (abfd)->canonical_symbols = internal;
868 ecoff_get_symtab_upper_bound (abfd)
871 if (ecoff_slurp_symbolic_info (abfd) == false
872 || bfd_get_symcount (abfd) == 0)
875 return (bfd_get_symcount (abfd) + 1) * (sizeof (ecoff_symbol_type *));
879 ecoff_get_symtab (abfd, alocation)
883 unsigned int counter = 0;
884 ecoff_symbol_type *symbase;
885 ecoff_symbol_type **location = (ecoff_symbol_type **) alocation;
887 if (ecoff_slurp_symbol_table (abfd) == false
888 || bfd_get_symcount (abfd) == 0)
891 symbase = ecoff_data (abfd)->canonical_symbols;
892 while (counter < bfd_get_symcount (abfd))
894 *(location++) = symbase++;
897 *location++ = (ecoff_symbol_type *) NULL;
898 return bfd_get_symcount (abfd);
901 /* Turn ECOFF type information into a printable string.
902 ecoff_emit_aggregate and ecoff_type_to_string are from
903 gcc/mips-tdump.c, with swapping added and used_ptr removed. */
905 /* Write aggregate information to a string. */
908 ecoff_emit_aggregate (abfd, string, rndx, isym, which)
916 int indx = rndx->index;
917 int sym_base, ss_base;
923 sym_base = ecoff_data (abfd)->fdr[ifd].isymBase;
924 ss_base = ecoff_data (abfd)->fdr[ifd].issBase;
926 if (indx == indexNil)
927 name = "/* no name */";
933 ecoff_swap_sym_in (abfd,
934 ecoff_data (abfd)->external_sym + indx,
936 name = ecoff_data (abfd)->ss + ss_base + sym.iss;
940 "%s %s { ifd = %d, index = %d }",
942 indx + ecoff_data (abfd)->symbolic_header.iextMax);
945 /* Convert the type information to string format. */
948 ecoff_type_to_string (abfd, aux_ptr, indx, bigendian)
950 union aux_ext *aux_ptr;
962 unsigned int basic_type;
964 static char buffer1[1024];
965 static char buffer2[1024];
970 for (i = 0; i < 7; i++)
972 qualifiers[i].low_bound = 0;
973 qualifiers[i].high_bound = 0;
974 qualifiers[i].stride = 0;
977 if (AUX_GET_ISYM (bigendian, &aux_ptr[indx]) == -1)
978 return "-1 (no type)";
979 ecoff_swap_tir_in (bigendian, &aux_ptr[indx++].a_ti, &u.ti);
981 basic_type = u.ti.bt;
982 qualifiers[0].type = u.ti.tq0;
983 qualifiers[1].type = u.ti.tq1;
984 qualifiers[2].type = u.ti.tq2;
985 qualifiers[3].type = u.ti.tq3;
986 qualifiers[4].type = u.ti.tq4;
987 qualifiers[5].type = u.ti.tq5;
988 qualifiers[6].type = tqNil;
991 * Go get the basic type.
995 case btNil: /* undefined */
999 case btAdr: /* address - integer same size as pointer */
1000 strcpy (p1, "address");
1003 case btChar: /* character */
1004 strcpy (p1, "char");
1007 case btUChar: /* unsigned character */
1008 strcpy (p1, "unsigned char");
1011 case btShort: /* short */
1012 strcpy (p1, "short");
1015 case btUShort: /* unsigned short */
1016 strcpy (p1, "unsigned short");
1019 case btInt: /* int */
1023 case btUInt: /* unsigned int */
1024 strcpy (p1, "unsigned int");
1027 case btLong: /* long */
1028 strcpy (p1, "long");
1031 case btULong: /* unsigned long */
1032 strcpy (p1, "unsigned long");
1035 case btFloat: /* float (real) */
1036 strcpy (p1, "float");
1039 case btDouble: /* Double (real) */
1040 strcpy (p1, "double");
1043 /* Structures add 1-2 aux words:
1044 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
1045 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1047 case btStruct: /* Structure (Record) */
1048 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1049 ecoff_emit_aggregate (abfd, p1, &rndx,
1050 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1052 indx++; /* skip aux words */
1055 /* Unions add 1-2 aux words:
1056 1st word is [ST_RFDESCAPE, offset] pointer to union def;
1057 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1059 case btUnion: /* Union */
1060 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1061 ecoff_emit_aggregate (abfd, p1, &rndx,
1062 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1064 indx++; /* skip aux words */
1067 /* Enumerations add 1-2 aux words:
1068 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
1069 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
1071 case btEnum: /* Enumeration */
1072 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
1073 ecoff_emit_aggregate (abfd, p1, &rndx,
1074 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
1076 indx++; /* skip aux words */
1079 case btTypedef: /* defined via a typedef, isymRef points */
1080 strcpy (p1, "typedef");
1083 case btRange: /* subrange of int */
1084 strcpy (p1, "subrange");
1087 case btSet: /* pascal sets */
1091 case btComplex: /* fortran complex */
1092 strcpy (p1, "complex");
1095 case btDComplex: /* fortran double complex */
1096 strcpy (p1, "double complex");
1099 case btIndirect: /* forward or unnamed typedef */
1100 strcpy (p1, "forward/unamed typedef");
1103 case btFixedDec: /* Fixed Decimal */
1104 strcpy (p1, "fixed decimal");
1107 case btFloatDec: /* Float Decimal */
1108 strcpy (p1, "float decimal");
1111 case btString: /* Varying Length Character String */
1112 strcpy (p1, "string");
1115 case btBit: /* Aligned Bit String */
1119 case btPicture: /* Picture */
1120 strcpy (p1, "picture");
1123 case btVoid: /* Void */
1124 strcpy (p1, "void");
1128 sprintf (p1, "Unknown basic type %d", (int) basic_type);
1132 p1 += strlen (buffer1);
1135 * If this is a bitfield, get the bitsize.
1141 bitsize = AUX_GET_WIDTH (bigendian, &aux_ptr[indx++]);
1142 sprintf (p1, " : %d", bitsize);
1143 p1 += strlen (buffer1);
1148 * Deal with any qualifiers.
1150 if (qualifiers[0].type != tqNil)
1153 * Snarf up any array bounds in the correct order. Arrays
1154 * store 5 successive words in the aux. table:
1155 * word 0 RNDXR to type of the bounds (ie, int)
1156 * word 1 Current file descriptor index
1158 * word 3 high bound (or -1 if [])
1159 * word 4 stride size in bits
1161 for (i = 0; i < 7; i++)
1163 if (qualifiers[i].type == tqArray)
1165 qualifiers[i].low_bound =
1166 AUX_GET_DNLOW (bigendian, &aux_ptr[indx+2]);
1167 qualifiers[i].high_bound =
1168 AUX_GET_DNHIGH (bigendian, &aux_ptr[indx+3]);
1169 qualifiers[i].stride =
1170 AUX_GET_WIDTH (bigendian, &aux_ptr[indx+4]);
1176 * Now print out the qualifiers.
1178 for (i = 0; i < 6; i++)
1180 switch (qualifiers[i].type)
1187 strcpy (p2, "ptr to ");
1188 p2 += sizeof ("ptr to ")-1;
1192 strcpy (p2, "volatile ");
1193 p2 += sizeof ("volatile ")-1;
1197 strcpy (p2, "far ");
1198 p2 += sizeof ("far ")-1;
1202 strcpy (p2, "func. ret. ");
1203 p2 += sizeof ("func. ret. ");
1208 int first_array = i;
1211 /* Print array bounds reversed (ie, in the order the C
1212 programmer writes them). C is such a fun language.... */
1214 while (i < 5 && qualifiers[i+1].type == tqArray)
1217 for (j = i; j >= first_array; j--)
1219 strcpy (p2, "array [");
1220 p2 += sizeof ("array [")-1;
1221 if (qualifiers[j].low_bound != 0)
1223 "%ld:%ld {%ld bits}",
1224 (long) qualifiers[j].low_bound,
1225 (long) qualifiers[j].high_bound,
1226 (long) qualifiers[j].stride);
1228 else if (qualifiers[j].high_bound != -1)
1231 (long) (qualifiers[j].high_bound + 1),
1232 (long) (qualifiers[j].stride));
1235 sprintf (p2, " {%ld bits}", (long) (qualifiers[j].stride));
1238 strcpy (p2, "] of ");
1239 p2 += sizeof ("] of ")-1;
1247 strcpy (p2, buffer1);
1251 /* Print information about an ECOFF symbol. */
1254 ecoff_print_symbol (abfd, filep, symbol, how)
1258 bfd_print_symbol_type how;
1260 FILE *file = (FILE *)filep;
1264 case bfd_print_symbol_name:
1265 fprintf (file, "%s", symbol->name);
1267 case bfd_print_symbol_more:
1268 if (ecoffsymbol (symbol)->local)
1272 ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative,
1274 fprintf (file, "ecoff local %lx %x %x",
1275 (unsigned long) ecoff_sym.value,
1276 (unsigned) ecoff_sym.st, (unsigned) ecoff_sym.sc);
1282 ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative,
1284 fprintf (file, "ecoff extern %lx %x %x",
1285 (unsigned long) ecoff_ext.asym.value,
1286 (unsigned) ecoff_ext.asym.st,
1287 (unsigned) ecoff_ext.asym.sc);
1290 case bfd_print_symbol_nm:
1292 CONST char *section_name = symbol->section->name;
1294 bfd_print_symbol_vandf ((PTR) file, symbol);
1295 fprintf (file, " %-5s %s %s",
1297 ecoffsymbol (symbol)->local ? "l" : "e",
1301 case bfd_print_symbol_all:
1302 /* Print out the symbols in a reasonable way */
1311 if (ecoffsymbol (symbol)->local)
1313 ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative,
1316 pos = (ecoffsymbol (symbol)->native.lnative
1317 - ecoff_data (abfd)->external_sym
1318 + ecoff_data (abfd)->symbolic_header.iextMax);
1325 ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative,
1328 pos = (ecoffsymbol (symbol)->native.enative
1329 - ecoff_data (abfd)->external_ext);
1330 jmptbl = ecoff_ext.jmptbl ? 'j' : ' ';
1331 cobol_main = ecoff_ext.cobol_main ? 'c' : ' ';
1332 weakext = ecoff_ext.weakext ? 'w' : ' ';
1335 fprintf (file, "[%3d] %c %lx st %x sc %x indx %x %c%c%c %s",
1336 pos, type, (unsigned long) ecoff_ext.asym.value,
1337 (unsigned) ecoff_ext.asym.st,
1338 (unsigned) ecoff_ext.asym.sc,
1339 (unsigned) ecoff_ext.asym.index,
1340 jmptbl, cobol_main, weakext,
1343 if (ecoffsymbol (symbol)->fdr != NULL
1344 && ecoff_ext.asym.index != indexNil)
1349 union aux_ext *aux_base;
1351 indx = ecoff_ext.asym.index;
1353 /* sym_base is used to map the fdr relative indices which
1354 appear in the file to the position number which we are
1356 sym_base = ecoffsymbol (symbol)->fdr->isymBase;
1357 if (ecoffsymbol (symbol)->local)
1358 sym_base += ecoff_data (abfd)->symbolic_header.iextMax;
1360 /* aux_base is the start of the aux entries for this file;
1361 asym.index is an offset from this. */
1362 aux_base = (ecoff_data (abfd)->external_aux
1363 + ecoffsymbol (symbol)->fdr->iauxBase);
1365 /* The aux entries are stored in host byte order; the
1366 order is indicated by a bit in the fdr. */
1367 bigendian = ecoffsymbol (symbol)->fdr->fBigendian;
1369 /* This switch is basically from gcc/mips-tdump.c */
1370 switch (ecoff_ext.asym.st)
1378 printf ("\n End+1 symbol: %ld", indx + sym_base);
1382 if (ecoff_ext.asym.sc == scText
1383 || ecoff_ext.asym.sc == scInfo)
1384 printf ("\n First symbol: %ld", indx + sym_base);
1386 printf ("\n First symbol: %ld",
1387 (AUX_GET_ISYM (bigendian,
1388 &aux_base[ecoff_ext.asym.index])
1394 if (MIPS_IS_STAB (&ecoff_ext.asym))
1396 else if (ecoffsymbol (symbol)->local)
1397 printf ("\n End+1 symbol: %-7ld Type: %s",
1398 (AUX_GET_ISYM (bigendian,
1399 &aux_base[ecoff_ext.asym.index])
1401 ecoff_type_to_string (abfd, aux_base, indx + 1,
1404 printf ("\n Local symbol: %d",
1407 + ecoff_data (abfd)->symbolic_header.iextMax));
1411 if (!MIPS_IS_STAB (&ecoff_ext.asym))
1412 printf ("\n Type: %s",
1413 ecoff_type_to_string (abfd, aux_base, indx,
1423 /* Reloc handling. MIPS ECOFF relocs are packed into 8 bytes in
1424 external form. They use a bit which indicates whether the symbol
1427 /* Swap a reloc in. */
1430 ecoff_swap_reloc_in (abfd, ext, intern)
1433 struct internal_reloc *intern;
1435 intern->r_vaddr = bfd_h_get_32 (abfd, (bfd_byte *) ext->r_vaddr);
1436 if (abfd->xvec->header_byteorder_big_p != false)
1438 intern->r_symndx = (((int) ext->r_bits[0]
1439 << RELOC_BITS0_SYMNDX_SH_LEFT_BIG)
1440 | ((int) ext->r_bits[1]
1441 << RELOC_BITS1_SYMNDX_SH_LEFT_BIG)
1442 | ((int) ext->r_bits[2]
1443 << RELOC_BITS2_SYMNDX_SH_LEFT_BIG));
1444 intern->r_type = ((ext->r_bits[3] & RELOC_BITS3_TYPE_BIG)
1445 >> RELOC_BITS3_TYPE_SH_BIG);
1446 intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_BIG) != 0;
1450 intern->r_symndx = (((int) ext->r_bits[0]
1451 << RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE)
1452 | ((int) ext->r_bits[1]
1453 << RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE)
1454 | ((int) ext->r_bits[2]
1455 << RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE));
1456 intern->r_type = ((ext->r_bits[3] & RELOC_BITS3_TYPE_LITTLE)
1457 >> RELOC_BITS3_TYPE_SH_LITTLE);
1458 intern->r_extern = (ext->r_bits[3] & RELOC_BITS3_EXTERN_LITTLE) != 0;
1462 /* Swap a reloc out. */
1465 ecoff_swap_reloc_out (abfd, src, dst)
1470 struct internal_reloc *intern = (struct internal_reloc *) src;
1471 RELOC *ext = (RELOC *) dst;
1473 bfd_h_put_32 (abfd, intern->r_vaddr, (bfd_byte *) ext->r_vaddr);
1474 if (abfd->xvec->header_byteorder_big_p != false)
1476 ext->r_bits[0] = intern->r_symndx >> RELOC_BITS0_SYMNDX_SH_LEFT_BIG;
1477 ext->r_bits[1] = intern->r_symndx >> RELOC_BITS1_SYMNDX_SH_LEFT_BIG;
1478 ext->r_bits[2] = intern->r_symndx >> RELOC_BITS2_SYMNDX_SH_LEFT_BIG;
1479 ext->r_bits[3] = (((intern->r_type << RELOC_BITS3_TYPE_SH_BIG)
1480 & RELOC_BITS3_TYPE_BIG)
1481 | (intern->r_extern ? RELOC_BITS3_EXTERN_BIG : 0));
1485 ext->r_bits[0] = intern->r_symndx >> RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE;
1486 ext->r_bits[1] = intern->r_symndx >> RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE;
1487 ext->r_bits[2] = intern->r_symndx >> RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE;
1488 ext->r_bits[3] = (((intern->r_type << RELOC_BITS3_TYPE_SH_LITTLE)
1489 & RELOC_BITS3_TYPE_LITTLE)
1490 | (intern->r_extern ? RELOC_BITS3_EXTERN_LITTLE : 0));
1496 /* ECOFF relocs are either against external symbols, or against
1497 sections. If we are producing relocateable output, and the reloc
1498 is against an external symbol, and nothing has given us any
1499 additional addend, the resulting reloc will also be against the
1500 same symbol. In such a case, we don't want to change anything
1501 about the way the reloc is handled, since it will all be done at
1502 final link time. Rather than put special case code into
1503 bfd_perform_relocation, all the reloc types use this howto
1504 function. It just short circuits the reloc if producing
1505 relocateable output against an external symbol. */
1507 static bfd_reloc_status_type
1508 ecoff_generic_reloc (abfd,
1515 arelent *reloc_entry;
1518 asection *input_section;
1521 if (output_bfd != (bfd *) NULL
1522 && (symbol->flags & BSF_SECTION_SYM) == 0
1523 && reloc_entry->addend == 0)
1525 reloc_entry->address += input_section->output_offset;
1526 return bfd_reloc_ok;
1529 return bfd_reloc_continue;
1532 /* Do a REFHI relocation. This has to be done in combination with a
1533 REFLO reloc, because there is a carry from the REFLO to the REFHI.
1534 Here we just save the information we need; we do the actual
1535 relocation when we see the REFLO. ECOFF requires that the REFLO
1536 immediately follow the REFHI, so this ought to work. */
1538 static bfd_byte *ecoff_refhi_addr;
1539 static bfd_vma ecoff_refhi_addend;
1541 static bfd_reloc_status_type
1542 ecoff_refhi_reloc (abfd,
1549 arelent *reloc_entry;
1552 asection *input_section;
1555 bfd_reloc_status_type ret;
1558 /* If we're relocating, and this an external symbol, we don't want
1559 to change anything. */
1560 if (output_bfd != (bfd *) NULL
1561 && (symbol->flags & BSF_SECTION_SYM) == 0
1562 && reloc_entry->addend == 0)
1564 reloc_entry->address += input_section->output_offset;
1565 return bfd_reloc_ok;
1569 if (symbol->section == &bfd_und_section
1570 && output_bfd == (bfd *) NULL)
1571 ret = bfd_reloc_undefined;
1573 if (bfd_is_com_section (symbol->section))
1576 relocation = symbol->value;
1578 relocation += symbol->section->output_section->vma;
1579 relocation += symbol->section->output_offset;
1580 relocation += reloc_entry->addend;
1582 if (reloc_entry->address > input_section->_cooked_size)
1583 return bfd_reloc_outofrange;
1585 /* Save the information, and let REFLO do the actual relocation. */
1586 ecoff_refhi_addr = (bfd_byte *) data + reloc_entry->address;
1587 ecoff_refhi_addend = relocation;
1589 if (output_bfd != (bfd *) NULL)
1590 reloc_entry->address += input_section->output_offset;
1595 /* Do a REFLO relocation. This is a straightforward 16 bit inplace
1596 relocation; this function exists in order to do the REFHI
1597 relocation described above. */
1599 static bfd_reloc_status_type
1600 ecoff_reflo_reloc (abfd,
1607 arelent *reloc_entry;
1610 asection *input_section;
1613 if (ecoff_refhi_addr != (bfd_byte *) NULL)
1617 unsigned long vallo;
1619 /* Do the REFHI relocation. Note that we actually don't need to
1620 know anything about the REFLO itself, except where to find
1621 the low 16 bits of the addend needed by the REFHI. */
1622 insn = bfd_get_32 (abfd, ecoff_refhi_addr);
1623 vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address)
1625 val = ((insn & 0xffff) << 16) + vallo;
1626 val += ecoff_refhi_addend;
1628 /* The low order 16 bits are always treated as a signed value.
1629 Therefore, a negative value in the low order bits requires an
1630 adjustment in the high order bits. We need to make this
1631 adjustment in two ways: once for the bits we took from the
1632 data, and once for the bits we are putting back in to the
1634 if ((vallo & 0x8000) != 0)
1636 if ((val & 0x8000) != 0)
1639 insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
1640 bfd_put_32 (abfd, insn, ecoff_refhi_addr);
1642 ecoff_refhi_addr = (bfd_byte *) NULL;
1645 /* Now do the REFLO reloc in the usual way. */
1646 return ecoff_generic_reloc (abfd, reloc_entry, symbol, data,
1647 input_section, output_bfd);
1650 /* Do a GPREL relocation. This is a 16 bit value which must become
1651 the offset from the gp register. */
1653 static bfd_reloc_status_type
1654 ecoff_gprel_reloc (abfd,
1661 arelent *reloc_entry;
1664 asection *input_section;
1667 boolean relocateable;
1672 /* If we're relocating, and this is an external symbol with no
1673 addend, we don't want to change anything. We will only have an
1674 addend if this is a newly created reloc, not read from an ECOFF
1676 if (output_bfd != (bfd *) NULL
1677 && (symbol->flags & BSF_SECTION_SYM) == 0
1678 && reloc_entry->addend == 0)
1680 reloc_entry->address += input_section->output_offset;
1681 return bfd_reloc_ok;
1684 if (output_bfd != (bfd *) NULL)
1685 relocateable = true;
1688 relocateable = false;
1689 output_bfd = symbol->section->output_section->owner;
1692 if (symbol->section == &bfd_und_section
1693 && relocateable == false)
1694 return bfd_reloc_undefined;
1696 /* We have to figure out the gp value, so that we can adjust the
1697 symbol value correctly. We look up the symbol _gp in the output
1698 BFD. If we can't find it, we're stuck. We cache it in the ECOFF
1699 target data. We don't need to adjust the symbol value for an
1700 external symbol if we are producing relocateable output. */
1701 if (ecoff_data (output_bfd)->gp == 0
1702 && (relocateable == false
1703 || (symbol->flags & BSF_SECTION_SYM) != 0))
1705 if (relocateable != false)
1707 /* Make up a value. */
1708 ecoff_data (output_bfd)->gp =
1709 symbol->section->output_section->vma + 0x4000;
1717 count = bfd_get_symcount (output_bfd);
1718 sym = bfd_get_outsymbols (output_bfd);
1720 /* We should do something more friendly here, but we don't
1721 have a good reloc status to return. */
1722 if (sym == (asymbol **) NULL)
1725 for (i = 0; i < count; i++, sym++)
1727 register CONST char *name;
1729 name = bfd_asymbol_name (*sym);
1730 if (*name == '_' && strcmp (name, "_gp") == 0)
1732 ecoff_data (output_bfd)->gp = bfd_asymbol_value (*sym);
1737 /* We should do something more friendly here, but we don't have
1738 a good reloc status to return. */
1744 if (bfd_is_com_section (symbol->section))
1747 relocation = symbol->value;
1749 relocation += symbol->section->output_section->vma;
1750 relocation += symbol->section->output_offset;
1752 if (reloc_entry->address > input_section->_cooked_size)
1753 return bfd_reloc_outofrange;
1755 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
1757 /* Set val to the offset into the section or symbol. */
1758 val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff;
1762 /* Adjust val for the final section location and GP value. If we
1763 are producing relocateable output, we don't want to do this for
1764 an external symbol. */
1765 if (relocateable == false
1766 || (symbol->flags & BSF_SECTION_SYM) != 0)
1767 val += relocation - ecoff_data (output_bfd)->gp;
1769 insn = (insn &~ 0xffff) | (val & 0xffff);
1770 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
1772 if (relocateable != false)
1773 reloc_entry->address += input_section->output_offset;
1775 /* Make sure it fit in 16 bits. */
1776 if (val >= 0x8000 && val < 0xffff8000)
1777 return bfd_reloc_outofrange;
1779 return bfd_reloc_ok;
1782 /* How to process the various relocs types. */
1784 static reloc_howto_type ecoff_howto_table[] =
1786 /* Reloc type 0 is ignored. The reloc reading code ensures that
1787 this is a reference to the .abs section, which will cause
1788 bfd_perform_relocation to do nothing. */
1789 HOWTO (ECOFF_R_IGNORE, /* type */
1791 0, /* size (0 = byte, 1 = short, 2 = long) */
1792 8, /* bitsize (obsolete) */
1793 false, /* pc_relative */
1795 false, /* absolute (obsolete) */
1796 false, /* complain_on_overflow */
1797 0, /* special_function */
1798 "IGNORE", /* name */
1799 false, /* partial_inplace */
1802 false), /* pcrel_offset */
1804 /* A 16 bit reference to a symbol, normally from a data section. */
1805 HOWTO (ECOFF_R_REFHALF, /* type */
1807 1, /* size (0 = byte, 1 = short, 2 = long) */
1808 16, /* bitsize (obsolete) */
1809 false, /* pc_relative */
1811 false, /* absolute (obsolete) */
1812 true, /* complain_on_overflow */
1813 ecoff_generic_reloc, /* special_function */
1814 "REFHALF", /* name */
1815 true, /* partial_inplace */
1816 0xffff, /* src_mask */
1817 0xffff, /* dst_mask */
1818 false), /* pcrel_offset */
1820 /* A 32 bit reference to a symbol, normally from a data section. */
1821 HOWTO (ECOFF_R_REFWORD, /* type */
1823 2, /* size (0 = byte, 1 = short, 2 = long) */
1824 32, /* bitsize (obsolete) */
1825 false, /* pc_relative */
1827 false, /* absolute (obsolete) */
1828 true, /* complain_on_overflow */
1829 ecoff_generic_reloc, /* special_function */
1830 "REFWORD", /* name */
1831 true, /* partial_inplace */
1832 0xffffffff, /* src_mask */
1833 0xffffffff, /* dst_mask */
1834 false), /* pcrel_offset */
1836 /* A 26 bit absolute jump address. */
1837 HOWTO (ECOFF_R_JMPADDR, /* type */
1839 2, /* size (0 = byte, 1 = short, 2 = long) */
1840 32, /* bitsize (obsolete) */
1841 false, /* pc_relative */
1843 false, /* absolute (obsolete) */
1844 true, /* complain_on_overflow */
1845 ecoff_generic_reloc, /* special_function */
1846 "JMPADDR", /* name */
1847 true, /* partial_inplace */
1848 0x3ffffff, /* src_mask */
1849 0x3ffffff, /* dst_mask */
1850 false), /* pcrel_offset */
1852 /* The high 16 bits of a symbol value. Handled by the function
1853 ecoff_refhi_reloc. */
1854 HOWTO (ECOFF_R_REFHI, /* type */
1855 16, /* rightshift */
1856 2, /* size (0 = byte, 1 = short, 2 = long) */
1857 32, /* bitsize (obsolete) */
1858 false, /* pc_relative */
1860 false, /* absolute (obsolete) */
1861 true, /* complain_on_overflow */
1862 ecoff_refhi_reloc, /* special_function */
1864 true, /* partial_inplace */
1865 0xffff, /* src_mask */
1866 0xffff, /* dst_mask */
1867 false), /* pcrel_offset */
1869 /* The low 16 bits of a symbol value. */
1870 HOWTO (ECOFF_R_REFLO, /* type */
1872 2, /* size (0 = byte, 1 = short, 2 = long) */
1873 32, /* bitsize (obsolete) */
1874 false, /* pc_relative */
1876 false, /* absolute (obsolete) */
1877 true, /* complain_on_overflow */
1878 ecoff_reflo_reloc, /* special_function */
1880 true, /* partial_inplace */
1881 0xffff, /* src_mask */
1882 0xffff, /* dst_mask */
1883 false), /* pcrel_offset */
1885 /* A reference to an offset from the gp register. Handled by the
1886 function ecoff_gprel_reloc. */
1887 HOWTO (ECOFF_R_GPREL, /* type */
1889 2, /* size (0 = byte, 1 = short, 2 = long) */
1890 32, /* bitsize (obsolete) */
1891 false, /* pc_relative */
1893 false, /* absolute (obsolete) */
1894 true, /* complain_on_overflow */
1895 ecoff_gprel_reloc, /* special_function */
1897 true, /* partial_inplace */
1898 0xffff, /* src_mask */
1899 0xffff, /* dst_mask */
1900 false), /* pcrel_offset */
1902 /* A reference to a literal using an offset from the gp register.
1903 Handled by the function ecoff_gprel_reloc. */
1904 HOWTO (ECOFF_R_LITERAL, /* type */
1906 2, /* size (0 = byte, 1 = short, 2 = long) */
1907 32, /* bitsize (obsolete) */
1908 false, /* pc_relative */
1910 false, /* absolute (obsolete) */
1911 true, /* complain_on_overflow */
1912 ecoff_gprel_reloc, /* special_function */
1913 "LITERAL", /* name */
1914 true, /* partial_inplace */
1915 0xffff, /* src_mask */
1916 0xffff, /* dst_mask */
1917 false) /* pcrel_offset */
1920 #define ECOFF_HOWTO_COUNT \
1921 (sizeof ecoff_howto_table / sizeof ecoff_howto_table[0])
1923 /* Read in the relocs for a section. */
1926 ecoff_slurp_reloc_table (abfd, section, symbols)
1931 RELOC *external_relocs;
1932 arelent *internal_relocs;
1936 if (section->relocation != (arelent *) NULL
1937 || section->reloc_count == 0
1938 || (section->flags & SEC_CONSTRUCTOR) != 0)
1941 if (ecoff_slurp_symbol_table (abfd) == false)
1944 internal_relocs = (arelent *) bfd_alloc (abfd,
1946 * section->reloc_count));
1947 external_relocs = (RELOC *) bfd_alloc (abfd, RELSZ * section->reloc_count);
1948 if (internal_relocs == (arelent *) NULL
1949 || external_relocs == (RELOC *) NULL)
1951 bfd_error = no_memory;
1954 if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0)
1956 if (bfd_read (external_relocs, 1, RELSZ * section->reloc_count, abfd)
1957 != RELSZ * section->reloc_count)
1959 bfd_error = system_call_error;
1963 for (i = 0, rptr = internal_relocs; i < section->reloc_count; i++, rptr++)
1965 struct internal_reloc intern;
1967 ecoff_swap_reloc_in (abfd, external_relocs + i, &intern);
1969 if (intern.r_type > ECOFF_R_LITERAL)
1972 if (intern.r_extern)
1974 /* r_symndx is an index into the external symbols. */
1975 BFD_ASSERT (intern.r_symndx >= 0
1977 < ecoff_data (abfd)->symbolic_header.iextMax));
1978 rptr->sym_ptr_ptr = symbols + intern.r_symndx;
1983 CONST char *sec_name;
1986 /* r_symndx is a section key. */
1987 switch (intern.r_symndx)
1989 case RELOC_SECTION_TEXT: sec_name = ".text"; break;
1990 case RELOC_SECTION_RDATA: sec_name = ".rdata"; break;
1991 case RELOC_SECTION_DATA: sec_name = ".data"; break;
1992 case RELOC_SECTION_SDATA: sec_name = ".sdata"; break;
1993 case RELOC_SECTION_SBSS: sec_name = ".sbss"; break;
1994 case RELOC_SECTION_BSS: sec_name = ".bss"; break;
1995 case RELOC_SECTION_INIT: sec_name = ".init"; break;
1996 case RELOC_SECTION_LIT8: sec_name = ".lit8"; break;
1997 case RELOC_SECTION_LIT4: sec_name = ".lit4"; break;
2001 sec = bfd_get_section_by_name (abfd, sec_name);
2002 if (sec == (asection *) NULL)
2004 rptr->sym_ptr_ptr = sec->symbol_ptr_ptr;
2006 rptr->addend = - bfd_get_section_vma (abfd, sec);
2007 if (intern.r_type == ECOFF_R_GPREL
2008 || intern.r_type == ECOFF_R_LITERAL)
2009 rptr->addend += ecoff_data (abfd)->gp;
2012 rptr->address = intern.r_vaddr - bfd_get_section_vma (abfd, section);
2013 rptr->howto = &ecoff_howto_table[intern.r_type];
2015 /* If the type is ECOFF_R_IGNORE, make sure this is a reference
2016 to the absolute section so that the reloc is ignored. */
2017 if (intern.r_type == ECOFF_R_IGNORE)
2018 rptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
2021 bfd_release (abfd, external_relocs);
2023 section->relocation = internal_relocs;
2028 /* Get a canonical list of relocs. */
2031 ecoff_canonicalize_reloc (abfd, section, relptr, symbols)
2039 if (section->flags & SEC_CONSTRUCTOR)
2041 arelent_chain *chain;
2043 /* This section has relocs made up by us, not the file, so take
2044 them out of their chain and place them into the data area
2046 for (count = 0, chain = section->constructor_chain;
2047 count < section->reloc_count;
2048 count++, chain = chain->next)
2049 *relptr++ = &chain->relent;
2055 if (ecoff_slurp_reloc_table (abfd, section, symbols) == false)
2058 tblptr = section->relocation;
2059 if (tblptr == (arelent *) NULL)
2062 for (count = 0; count < section->reloc_count; count++)
2063 *relptr++ = tblptr++;
2066 *relptr = (arelent *) NULL;
2068 return section->reloc_count;
2071 /* Get the howto structure for a generic reloc type. */
2073 static CONST struct reloc_howto_struct *
2074 ecoff_bfd_reloc_type_lookup (abfd, code)
2076 bfd_reloc_code_real_type code;
2083 ecoff_type = ECOFF_R_REFHALF;
2086 ecoff_type = ECOFF_R_REFWORD;
2088 case BFD_RELOC_MIPS_JMP:
2089 ecoff_type = ECOFF_R_JMPADDR;
2091 case BFD_RELOC_HI16_S:
2092 ecoff_type = ECOFF_R_REFHI;
2094 case BFD_RELOC_LO16:
2095 ecoff_type = ECOFF_R_REFLO;
2097 case BFD_RELOC_MIPS_GPREL:
2098 ecoff_type = ECOFF_R_GPREL;
2101 return (CONST struct reloc_howto_struct *) NULL;
2104 return &ecoff_howto_table[ecoff_type];
2107 /* Provided a BFD, a section and an offset into the section, calculate
2108 and return the name of the source file and the line nearest to the
2112 ecoff_find_nearest_line (abfd,
2121 asymbol **ignore_symbols;
2123 CONST char **filename_ptr;
2124 CONST char **functionname_ptr;
2125 unsigned int *retline_ptr;
2131 struct pdr_ext *pdr_ptr;
2132 struct pdr_ext *pdr_end;
2134 unsigned char *line_ptr;
2135 unsigned char *line_end;
2138 /* If we're not in the .text section, we don't have any line
2140 if (strcmp (section->name, _TEXT) != 0
2141 || offset < ecoff_data (abfd)->text_start
2142 || offset >= ecoff_data (abfd)->text_end)
2145 /* Make sure we have the FDR's. */
2146 if (ecoff_slurp_symbolic_info (abfd) == false
2147 || bfd_get_symcount (abfd) == 0)
2150 /* Each file descriptor (FDR) has a memory address. Here we track
2151 down which FDR we want. The FDR's are stored in increasing
2152 memory order. If speed is ever important, this can become a
2153 binary search. We must ignore FDR's with no PDR entries; they
2154 will have the adr of the FDR before or after them. */
2155 fdr_start = ecoff_data (abfd)->fdr;
2156 fdr_end = fdr_start + ecoff_data (abfd)->symbolic_header.ifdMax;
2157 fdr_hold = (FDR *) NULL;
2158 for (fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
2160 if (fdr_ptr->cpd == 0)
2162 if (offset < fdr_ptr->adr)
2166 if (fdr_hold == (FDR *) NULL)
2170 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
2171 have an address, which is relative to the FDR address, and are
2172 also stored in increasing memory order. */
2173 offset -= fdr_ptr->adr;
2174 pdr_ptr = ecoff_data (abfd)->external_pdr + fdr_ptr->ipdFirst;
2175 pdr_end = pdr_ptr + fdr_ptr->cpd;
2176 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
2178 /* The address of the first PDR is an offset which applies to the
2179 addresses of all the PDR's. */
2182 for (pdr_ptr++; pdr_ptr < pdr_end; pdr_ptr++)
2184 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
2185 if (offset < pdr.adr)
2189 /* Now we can look for the actual line number. The line numbers are
2190 stored in a very funky format, which I won't try to describe.
2191 Note that right here pdr_ptr and pdr hold the PDR *after* the one
2192 we want; we need this to compute line_end. */
2193 line_end = ecoff_data (abfd)->line;
2194 if (pdr_ptr == pdr_end)
2195 line_end += fdr_ptr->cbLineOffset + fdr_ptr->cbLine;
2197 line_end += fdr_ptr->cbLineOffset + pdr.cbLineOffset;
2199 /* Now change pdr and pdr_ptr to the one we want. */
2201 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
2205 line_ptr = (ecoff_data (abfd)->line
2206 + fdr_ptr->cbLineOffset
2207 + pdr.cbLineOffset);
2208 while (line_ptr < line_end)
2213 delta = *line_ptr >> 4;
2216 count = (*line_ptr & 0xf) + 1;
2220 delta = (((line_ptr[0]) & 0xff) << 8) + ((line_ptr[1]) & 0xff);
2221 if (delta >= 0x8000)
2226 if (offset < count * 4)
2228 offset -= count * 4;
2231 /* If fdr_ptr->rss is -1, then this file does not have full symbols,
2232 at least according to gdb/mipsread.c. */
2233 if (fdr_ptr->rss == -1)
2235 *filename_ptr = NULL;
2237 *functionname_ptr = NULL;
2242 ecoff_swap_ext_in (abfd,
2243 (ecoff_data (abfd)->external_ext
2246 *functionname_ptr = ecoff_data (abfd)->ssext + proc_ext.asym.iss;
2253 *filename_ptr = ecoff_data (abfd)->ss + fdr_ptr->issBase + fdr_ptr->rss;
2254 ecoff_swap_sym_in (abfd,
2255 (ecoff_data (abfd)->external_sym
2259 *functionname_ptr = (ecoff_data (abfd)->ss
2263 *retline_ptr = lineno;
2267 /* We can't use the generic linking routines for ECOFF, because we
2268 have to handle all the debugging information. The generic link
2269 routine just works out the section contents and attaches a list of
2272 We link by looping over all the seclets. We make two passes. On
2273 the first we set the actual section contents and determine the size
2274 of the debugging information. On the second we accumulate the
2275 debugging information and write it out.
2277 This currently always accumulates the debugging information, which
2278 is incorrect, because it ignores the -s and -S options of the
2279 linker. The linker needs to be modified to give us that
2280 information in a more useful format (currently it just provides a
2281 list of symbols which should appear in the output file). */
2283 /* Clear the output_has_begun flag for all the input BFD's. We use it
2284 to avoid linking in the debugging information for a BFD more than
2288 ecoff_clear_output_flags (abfd)
2291 register asection *o;
2292 register bfd_seclet_type *p;
2294 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2295 for (p = o->seclets_head;
2296 p != (bfd_seclet_type *) NULL;
2298 if (p->type == bfd_indirect_seclet)
2299 p->u.indirect.section->owner->output_has_begun = false;
2302 /* Handle an indirect seclet on the first pass. Set the contents of
2303 the output section, and accumulate the debugging information if
2307 ecoff_rel (output_bfd, seclet, output_section, data, relocateable)
2309 bfd_seclet_type *seclet;
2310 asection *output_section;
2312 boolean relocateable;
2315 HDRR *output_symhdr;
2318 if ((output_section->flags & SEC_HAS_CONTENTS)
2319 && !(output_section->flags & SEC_NEVER_LOAD)
2320 && (output_section->flags & SEC_LOAD)
2323 data = (PTR) bfd_get_relocated_section_contents (output_bfd,
2327 if (bfd_set_section_contents (output_bfd,
2338 input_bfd = seclet->u.indirect.section->owner;
2340 /* We want to figure out how much space will be required to
2341 incorporate all the debugging information from input_bfd. We use
2342 the output_has_begun field to avoid adding it in more than once.
2343 The actual incorporation is done in the second pass, in
2344 ecoff_get_debug. The code has to parallel that code in its
2345 manipulations of output_symhdr. */
2347 if (input_bfd->output_has_begun)
2349 input_bfd->output_has_begun = true;
2351 output_symhdr = &ecoff_data (output_bfd)->symbolic_header;
2353 if (input_bfd->xvec->flavour != bfd_target_ecoff_flavour)
2359 /* We just accumulate local symbols from a non-ECOFF BFD. The
2360 external symbols are handled separately. */
2362 symbols = (asymbol **) bfd_alloc (output_bfd,
2363 get_symtab_upper_bound (input_bfd));
2364 if (symbols == (asymbol **) NULL)
2366 bfd_error = no_memory;
2369 sym_end = symbols + bfd_canonicalize_symtab (input_bfd, symbols);
2371 for (sym_ptr = symbols; sym_ptr < sym_end; sym_ptr++)
2375 len = strlen ((*sym_ptr)->name);
2376 if (((*sym_ptr)->flags & BSF_EXPORT) == 0)
2378 ++output_symhdr->isymMax;
2379 output_symhdr->issMax += len + 1;
2383 bfd_release (output_bfd, (PTR) symbols);
2385 ++output_symhdr->ifdMax;
2390 /* We simply add in the information from another ECOFF BFD. First
2391 we make sure we have the symbolic information. */
2392 if (ecoff_slurp_symbol_table (input_bfd) == false)
2394 if (bfd_get_symcount (input_bfd) == 0)
2397 input_symhdr = &ecoff_data (input_bfd)->symbolic_header;
2399 /* Figure out how much information we are going to be putting in.
2400 The external symbols are handled separately. */
2401 output_symhdr->ilineMax += input_symhdr->ilineMax;
2402 output_symhdr->cbLine += input_symhdr->cbLine;
2403 output_symhdr->idnMax += input_symhdr->idnMax;
2404 output_symhdr->ipdMax += input_symhdr->ipdMax;
2405 output_symhdr->isymMax += input_symhdr->isymMax;
2406 output_symhdr->ioptMax += input_symhdr->ioptMax;
2407 output_symhdr->iauxMax += input_symhdr->iauxMax;
2408 output_symhdr->issMax += input_symhdr->issMax;
2409 output_symhdr->ifdMax += input_symhdr->ifdMax;
2411 /* The RFD's are special, since we create them if needed. */
2412 if (input_symhdr->crfd > 0)
2413 output_symhdr->crfd += input_symhdr->crfd;
2415 output_symhdr->crfd += input_symhdr->ifdMax;
2420 /* Handle an arbitrary seclet on the first pass. */
2423 ecoff_dump_seclet (abfd, seclet, section, data, relocateable)
2425 bfd_seclet_type *seclet;
2428 boolean relocateable;
2430 switch (seclet->type)
2432 case bfd_indirect_seclet:
2433 /* The contents of this section come from another one somewhere
2435 return ecoff_rel (abfd, seclet, section, data, relocateable);
2437 case bfd_fill_seclet:
2438 /* Fill in the section with fill.value. This is used to pad out
2439 sections, but we must avoid padding the .bss section. */
2440 if ((section->flags & SEC_HAS_CONTENTS) == 0)
2442 if (seclet->u.fill.value != 0)
2447 char *d = (char *) bfd_alloc (abfd, seclet->size);
2451 for (i = 0; i < seclet->size; i+=2)
2452 d[i] = seclet->u.fill.value >> 8;
2453 for (i = 1; i < seclet->size; i+=2)
2454 d[i] = seclet->u.fill.value;
2455 ret = bfd_set_section_contents (abfd, section, d, seclet->offset,
2457 bfd_release (abfd, (PTR) d);
2469 /* Add a string to the debugging information we are accumulating for a
2470 file. Return the offset from the fdr string base or from the
2471 external string base. */
2474 ecoff_add_string (output_bfd, fdr, string, external)
2484 symhdr = &ecoff_data (output_bfd)->symbolic_header;
2485 len = strlen (string);
2488 strcpy (ecoff_data (output_bfd)->ssext + symhdr->issExtMax, string);
2489 ret = symhdr->issExtMax;
2490 symhdr->issExtMax += len + 1;
2494 strcpy (ecoff_data (output_bfd)->ss + symhdr->issMax, string);
2496 symhdr->issMax += len + 1;
2497 fdr->cbSs += len + 1;
2502 /* Accumulate the debugging information from an input section. */
2505 ecoff_get_debug (output_bfd, seclet, section, relocateable)
2507 bfd_seclet_type *seclet;
2509 boolean relocateable;
2512 HDRR *output_symhdr;
2514 ecoff_data_type *output_ecoff;
2515 ecoff_data_type *input_ecoff;
2517 struct sym_ext *sym_out;
2518 ecoff_symbol_type *esym_ptr;
2519 ecoff_symbol_type *esym_end;
2520 unsigned long pdr_off;
2523 struct fdr_ext *fdr_out;
2525 input_bfd = seclet->u.indirect.section->owner;
2527 /* Don't get the information more than once. */
2528 if (input_bfd->output_has_begun)
2530 input_bfd->output_has_begun = true;
2532 output_ecoff = ecoff_data (output_bfd);
2533 output_symhdr = &output_ecoff->symbolic_header;
2535 if (input_bfd->xvec->flavour != bfd_target_ecoff_flavour)
2542 /* This is not an ECOFF BFD. Just gather the symbols. */
2544 memset (&fdr, 0, sizeof fdr);
2546 fdr.adr = bfd_get_section_vma (output_bfd, section) + seclet->offset;
2547 fdr.issBase = output_symhdr->issMax;
2549 fdr.rss = ecoff_add_string (output_bfd,
2551 bfd_get_filename (input_bfd),
2553 fdr.isymBase = output_symhdr->isymMax;
2555 /* Get the local symbols from the input BFD. */
2556 symbols = (asymbol **) bfd_alloc (output_bfd,
2557 get_symtab_upper_bound (input_bfd));
2558 if (symbols == (asymbol **) NULL)
2560 bfd_error = no_memory;
2563 sym_end = symbols + bfd_canonicalize_symtab (input_bfd, symbols);
2565 /* Handle the local symbols. Any external symbols are handled
2568 for (sym_ptr = symbols; sym_ptr != sym_end; sym_ptr++)
2572 if (((*sym_ptr)->flags & BSF_EXPORT) != 0)
2574 memset (&internal_sym, 0, sizeof internal_sym);
2575 internal_sym.iss = ecoff_add_string (output_bfd,
2580 if (bfd_is_com_section ((*sym_ptr)->section)
2581 || (*sym_ptr)->section == &bfd_und_section)
2582 internal_sym.value = (*sym_ptr)->value;
2584 internal_sym.value = ((*sym_ptr)->value
2585 + (*sym_ptr)->section->output_offset
2586 + (*sym_ptr)->section->output_section->vma);
2587 internal_sym.st = stNil;
2588 internal_sym.sc = scUndefined;
2589 internal_sym.index = indexNil;
2590 ecoff_swap_sym_out (output_bfd, &internal_sym,
2591 (output_ecoff->external_sym
2592 + output_symhdr->isymMax));
2594 ++output_symhdr->isymMax;
2597 bfd_release (output_bfd, (PTR) symbols);
2599 /* Leave everything else in the FDR zeroed out. This will cause
2600 the lang field to be langC. The fBigendian field will
2601 indicate little endian format, but it doesn't matter because
2602 it only applies to aux fields and there are none. */
2604 ecoff_swap_fdr_out (output_bfd, &fdr,
2605 (output_ecoff->external_fdr
2606 + output_symhdr->ifdMax));
2607 ++output_symhdr->ifdMax;
2611 /* This is an ECOFF BFD. We want to grab the information from
2612 input_bfd and attach it to output_bfd. */
2613 count = bfd_get_symcount (input_bfd);
2616 input_ecoff = ecoff_data (input_bfd);
2617 input_symhdr = &input_ecoff->symbolic_header;
2619 /* I think that it is more efficient to simply copy the debugging
2620 information from the input BFD to the output BFD. Because ECOFF
2621 uses relative pointers for most of the debugging information,
2622 only a little of it has to be changed at all. */
2624 /* Swap in the local symbols, adjust their values, and swap them out
2625 again. The external symbols are handled separately. */
2626 sym_out = output_ecoff->external_sym + output_symhdr->isymMax;
2628 esym_ptr = ecoff_data (input_bfd)->canonical_symbols;
2629 esym_end = esym_ptr + count;
2630 for (; esym_ptr < esym_end; esym_ptr++)
2632 if (esym_ptr->local)
2636 ecoff_swap_sym_in (input_bfd, esym_ptr->native.lnative, &sym);
2638 /* If we're producing an executable, move common symbols
2640 if (relocateable == false)
2642 if (sym.sc == scCommon)
2644 else if (sym.sc == scSCommon)
2648 if (! bfd_is_com_section (esym_ptr->symbol.section)
2649 && (esym_ptr->symbol.flags & BSF_DEBUGGING) == 0
2650 && esym_ptr->symbol.section != &bfd_und_section)
2651 sym.value = (esym_ptr->symbol.value
2652 + esym_ptr->symbol.section->output_offset
2653 + esym_ptr->symbol.section->output_section->vma);
2654 ecoff_swap_sym_out (output_bfd, &sym, sym_out);
2659 /* That should have accounted for all the local symbols in
2661 BFD_ASSERT ((sym_out - output_ecoff->external_sym) - output_symhdr->isymMax
2662 == input_symhdr->isymMax);
2664 /* Copy the information that does not need swapping. */
2665 memcpy (output_ecoff->line + output_symhdr->cbLine,
2667 input_symhdr->cbLine * sizeof (unsigned char));
2668 memcpy (output_ecoff->external_aux + output_symhdr->iauxMax,
2669 input_ecoff->external_aux,
2670 input_symhdr->iauxMax * sizeof (union aux_ext));
2671 memcpy (output_ecoff->ss + output_symhdr->issMax,
2673 input_symhdr->issMax * sizeof (char));
2675 /* Some of the information may need to be swapped. */
2676 if (output_bfd->xvec->header_byteorder_big_p
2677 == input_bfd->xvec->header_byteorder_big_p)
2679 /* The two BFD's have the same endianness, so memcpy will
2681 memcpy (output_ecoff->external_dnr + output_symhdr->idnMax,
2682 input_ecoff->external_dnr,
2683 input_symhdr->idnMax * sizeof (struct dnr_ext));
2684 memcpy (output_ecoff->external_pdr + output_symhdr->ipdMax,
2685 input_ecoff->external_pdr,
2686 input_symhdr->ipdMax * sizeof (struct pdr_ext));
2687 if (input_symhdr->ipdMax == 0)
2693 ecoff_swap_pdr_in (input_bfd, input_ecoff->external_pdr, &pdr);
2696 memcpy (output_ecoff->external_opt + output_symhdr->ioptMax,
2697 input_ecoff->external_opt,
2698 input_symhdr->ioptMax * sizeof (struct opt_ext));
2702 struct dnr_ext *dnr_in;
2703 struct dnr_ext *dnr_end;
2704 struct dnr_ext *dnr_out;
2705 struct pdr_ext *pdr_in;
2706 struct pdr_ext *pdr_end;
2707 struct pdr_ext *pdr_out;
2709 struct opt_ext *opt_in;
2710 struct opt_ext *opt_end;
2711 struct opt_ext *opt_out;
2713 /* The two BFD's have different endianness, so we must swap
2714 everything in and out. This code would always work, but it
2715 would be slow in the normal case. */
2716 dnr_in = input_ecoff->external_dnr;
2717 dnr_end = dnr_in + input_symhdr->idnMax;
2718 dnr_out = output_ecoff->external_dnr + output_symhdr->idnMax;
2719 for (; dnr_in < dnr_end; dnr_in++, dnr_out++)
2723 ecoff_swap_dnr_in (input_bfd, dnr_in, &dnr);
2724 ecoff_swap_dnr_out (output_bfd, &dnr, dnr_out);
2726 pdr_in = input_ecoff->external_pdr;
2727 pdr_end = pdr_in + input_symhdr->ipdMax;
2728 pdr_out = output_ecoff->external_pdr + output_symhdr->ipdMax;
2731 for (; pdr_in < pdr_end; pdr_in++, pdr_out++)
2735 ecoff_swap_pdr_in (input_bfd, pdr_in, &pdr);
2736 ecoff_swap_pdr_out (output_bfd, &pdr, pdr_out);
2743 opt_in = input_ecoff->external_opt;
2744 opt_end = opt_in + input_symhdr->ioptMax;
2745 opt_out = output_ecoff->external_opt + output_symhdr->ioptMax;
2746 for (; opt_in < opt_end; opt_in++, opt_out++)
2750 ecoff_swap_opt_in (input_bfd, opt_in, &opt);
2751 ecoff_swap_opt_out (output_bfd, &opt, opt_out);
2755 /* Set ifdbase so that the external symbols know how to adjust their
2757 input_ecoff->ifdbase = output_symhdr->ifdMax;
2759 fdr_ptr = input_ecoff->fdr;
2760 fdr_end = fdr_ptr + input_symhdr->ifdMax;
2761 fdr_out = output_ecoff->external_fdr + output_symhdr->ifdMax;
2762 for (; fdr_ptr < fdr_end; fdr_ptr++, fdr_out++)
2768 /* The memory address for this fdr is the address for the seclet
2769 plus the offset to this fdr within input_bfd. For some
2770 reason the offset of the first procedure pointer is also
2772 fdr.adr = (bfd_get_section_vma (output_bfd, section)
2774 + (fdr_ptr->adr - input_ecoff->fdr->adr)
2777 fdr.issBase += output_symhdr->issMax;
2778 fdr.isymBase += output_symhdr->isymMax;
2779 fdr.ilineBase += output_symhdr->ilineMax;
2780 fdr.ioptBase += output_symhdr->ioptMax;
2781 fdr.ipdFirst += output_symhdr->ipdMax;
2782 fdr.iauxBase += output_symhdr->iauxMax;
2783 fdr.rfdBase += output_symhdr->crfd;
2785 /* If there are no RFD's, we are going to add some. We don't
2786 want to adjust irfd for this, so that all the FDR's can share
2788 if (input_symhdr->crfd == 0)
2789 fdr.crfd = input_symhdr->ifdMax;
2791 if (fdr.cbLine != 0)
2792 fdr.cbLineOffset += output_symhdr->cbLine;
2794 ecoff_swap_fdr_out (output_bfd, &fdr, fdr_out);
2797 if (input_symhdr->crfd > 0)
2799 struct rfd_ext *rfd_in;
2800 struct rfd_ext *rfd_end;
2801 struct rfd_ext *rfd_out;
2803 /* Swap and adjust the RFD's. RFD's are only created by the
2804 linker, so this will only be necessary if one of the input
2805 files is the result of a partial link. Presumably all
2806 necessary RFD's are present. */
2807 rfd_in = input_ecoff->external_rfd;
2808 rfd_end = rfd_in + input_symhdr->crfd;
2809 rfd_out = output_ecoff->external_rfd + output_symhdr->crfd;
2810 for (; rfd_in < rfd_end; rfd_in++, rfd_out++)
2814 ecoff_swap_rfd_in (input_bfd, rfd_in, &rfd);
2815 rfd += output_symhdr->ifdMax;
2816 ecoff_swap_rfd_out (output_bfd, &rfd, rfd_out);
2818 output_symhdr->crfd += input_symhdr->crfd;
2822 struct rfd_ext *rfd_out;
2823 struct rfd_ext *rfd_end;
2826 /* Create RFD's. Some of the debugging information includes
2827 relative file indices. These indices are taken as indices to
2828 the RFD table if there is one, or to the global table if
2829 there is not. If we did not create RFD's, we would have to
2830 parse and adjust all the debugging information which contains
2832 rfd = output_symhdr->ifdMax;
2833 rfd_out = output_ecoff->external_rfd + output_symhdr->crfd;
2834 rfd_end = rfd_out + input_symhdr->ifdMax;
2835 for (; rfd_out < rfd_end; rfd_out++, rfd++)
2836 ecoff_swap_rfd_out (output_bfd, &rfd, rfd_out);
2837 output_symhdr->crfd += input_symhdr->ifdMax;
2840 /* Combine the register masks. */
2844 output_ecoff->gprmask |= input_ecoff->gprmask;
2845 for (i = 0; i < 4; i++)
2846 output_ecoff->cprmask[i] |= input_ecoff->cprmask[i];
2849 /* Update the counts. */
2850 output_symhdr->ilineMax += input_symhdr->ilineMax;
2851 output_symhdr->cbLine += input_symhdr->cbLine;
2852 output_symhdr->idnMax += input_symhdr->idnMax;
2853 output_symhdr->ipdMax += input_symhdr->ipdMax;
2854 output_symhdr->isymMax += input_symhdr->isymMax;
2855 output_symhdr->ioptMax += input_symhdr->ioptMax;
2856 output_symhdr->iauxMax += input_symhdr->iauxMax;
2857 output_symhdr->issMax += input_symhdr->issMax;
2858 output_symhdr->ifdMax += input_symhdr->ifdMax;
2863 /* This is the actual link routine. It makes two passes over all the
2867 ecoff_bfd_seclet_link (abfd, data, relocateable)
2870 boolean relocateable;
2874 register asection *o;
2875 register bfd_seclet_type *p;
2876 asymbol **sym_ptr_ptr;
2880 /* We accumulate the debugging information counts in the symbolic
2882 symhdr = &ecoff_data (abfd)->symbolic_header;
2883 symhdr->magic = magicSym;
2884 /* FIXME: What should the version stamp be? */
2886 symhdr->ilineMax = 0;
2890 symhdr->isymMax = 0;
2891 symhdr->ioptMax = 0;
2892 symhdr->iauxMax = 0;
2894 symhdr->issExtMax = 0;
2897 symhdr->iextMax = 0;
2899 /* We need to copy over the debugging symbols from each input BFD.
2900 When we do this copying, we have to adjust the text address in
2901 the FDR structures, so we have to know the text address used for
2902 the input BFD. Since we only want to copy the symbols once per
2903 input BFD, but we are going to look at each input BFD multiple
2904 times (once for each section it provides), we arrange to always
2905 look at the text section first. That means that when we copy the
2906 debugging information, we always know the text address. So we
2907 actually do each pass in two sub passes; first the text sections,
2908 then the non-text sections. We use the output_has_begun flag to
2909 determine whether we have copied over the debugging information
2912 /* Do the first pass: set the output section contents and count the
2913 debugging information. */
2914 ecoff_clear_output_flags (abfd);
2915 for (ipass = 0; ipass < 2; ipass++)
2917 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
2919 /* For SEC_CODE sections, (flags & SEC_CODE) == 0 is false,
2920 so they are done on pass 0. For other sections the
2921 expression is true, so they are done on pass 1. */
2922 if (((o->flags & SEC_CODE) == 0) != ipass)
2925 for (p = o->seclets_head;
2926 p != (bfd_seclet_type *) NULL;
2929 if (ecoff_dump_seclet (abfd, p, o, data, relocateable)
2936 /* We handle the external symbols differently. We use the ones
2937 attached to the output_bfd. The linker will have already
2938 determined which symbols are to be attached. Here we just
2939 determine how much space we will need for them. */
2940 sym_ptr_ptr = bfd_get_outsymbols (abfd);
2941 if (sym_ptr_ptr != NULL)
2945 sym_end = sym_ptr_ptr + bfd_get_symcount (abfd);
2946 for (; sym_ptr_ptr < sym_end; sym_ptr_ptr++)
2948 if (((*sym_ptr_ptr)->flags & BSF_DEBUGGING) == 0
2949 && ((*sym_ptr_ptr)->flags & BSF_LOCAL) == 0)
2952 symhdr->issExtMax += strlen ((*sym_ptr_ptr)->name) + 1;
2957 /* Adjust the counts so that structures are longword aligned. */
2958 symhdr->cbLine = (symhdr->cbLine + 3) &~ 3;
2959 symhdr->issMax = (symhdr->issMax + 3) &~ 3;
2960 symhdr->issExtMax = (symhdr->issExtMax + 3) &~ 3;
2962 /* Now the counts in symhdr are the correct size for the debugging
2963 information. We allocate the right amount of space, and reset
2964 the counts so that the second pass can use them as indices. It
2965 would be possible to output the debugging information directly to
2966 the file in pass 2, rather than to build it in memory and then
2967 write it out. Outputting to the file would require a lot of
2968 seeks and small writes, though, and I think this approach is
2970 size = (symhdr->cbLine * sizeof (unsigned char)
2971 + symhdr->idnMax * sizeof (struct dnr_ext)
2972 + symhdr->ipdMax * sizeof (struct pdr_ext)
2973 + symhdr->isymMax * sizeof (struct sym_ext)
2974 + symhdr->ioptMax * sizeof (struct opt_ext)
2975 + symhdr->iauxMax * sizeof (union aux_ext)
2976 + symhdr->issMax * sizeof (char)
2977 + symhdr->issExtMax * sizeof (char)
2978 + symhdr->ifdMax * sizeof (struct fdr_ext)
2979 + symhdr->crfd * sizeof (struct rfd_ext)
2980 + symhdr->iextMax * sizeof (struct ext_ext));
2981 raw = (char *) bfd_alloc (abfd, size);
2982 if (raw == (char *) NULL)
2984 bfd_error = no_memory;
2987 ecoff_data (abfd)->raw_size = size;
2988 ecoff_data (abfd)->raw_syments = (PTR) raw;
2990 /* Initialize the raw pointers. */
2991 #define SET(field, count, type) \
2992 ecoff_data (abfd)->field = (type *) raw; \
2993 raw += symhdr->count * sizeof (type)
2995 SET (line, cbLine, unsigned char);
2996 SET (external_dnr, idnMax, struct dnr_ext);
2997 SET (external_pdr, ipdMax, struct pdr_ext);
2998 SET (external_sym, isymMax, struct sym_ext);
2999 SET (external_opt, ioptMax, struct opt_ext);
3000 SET (external_aux, iauxMax, union aux_ext);
3001 SET (ss, issMax, char);
3002 SET (ssext, issExtMax, char);
3003 SET (external_fdr, ifdMax, struct fdr_ext);
3004 SET (external_rfd, crfd, struct rfd_ext);
3005 SET (external_ext, iextMax, struct ext_ext);
3008 /* Reset the counts so the second pass can use them to know how far
3010 symhdr->ilineMax = 0;
3014 symhdr->isymMax = 0;
3015 symhdr->ioptMax = 0;
3016 symhdr->iauxMax = 0;
3018 symhdr->issExtMax = 0;
3021 symhdr->iextMax = 0;
3023 /* Do the second pass: accumulate the debugging information. */
3024 ecoff_clear_output_flags (abfd);
3025 for (ipass = 0; ipass < 2; ipass++)
3027 for (o = abfd->sections; o != (asection *) NULL; o = o->next)
3029 if (((o->flags & SEC_CODE) == 0) != ipass)
3031 for (p = o->seclets_head;
3032 p != (bfd_seclet_type *) NULL;
3035 if (p->type == bfd_indirect_seclet)
3037 if (ecoff_get_debug (abfd, p, o, relocateable) == false)
3044 /* Put in the external symbols. */
3045 sym_ptr_ptr = bfd_get_outsymbols (abfd);
3046 if (sym_ptr_ptr != NULL)
3049 struct ext_ext *external_ext;
3051 ssext = ecoff_data (abfd)->ssext;
3052 external_ext = ecoff_data (abfd)->external_ext;
3053 for (; *sym_ptr_ptr != NULL; sym_ptr_ptr++)
3058 sym_ptr = *sym_ptr_ptr;
3060 if ((sym_ptr->flags & BSF_DEBUGGING) != 0
3061 || (sym_ptr->flags & BSF_LOCAL) != 0)
3064 /* The enative pointer can be NULL for a symbol created by
3065 the linker via ecoff_make_empty_symbol. */
3066 if (bfd_asymbol_flavour (sym_ptr) != bfd_target_ecoff_flavour
3067 || (((ecoff_symbol_type *) sym_ptr)->native.enative
3068 == (struct ext_ext *) NULL))
3071 esym.cobol_main = 0;
3075 /* FIXME: we can do better than this for st and sc. */
3076 esym.asym.st = stGlobal;
3077 esym.asym.sc = scAbs;
3078 esym.asym.reserved = 0;
3079 esym.asym.index = indexNil;
3083 ecoff_symbol_type *ecoff_sym_ptr;
3085 ecoff_sym_ptr = (ecoff_symbol_type *) sym_ptr;
3086 if (ecoff_sym_ptr->local)
3088 ecoff_swap_ext_in (abfd, ecoff_sym_ptr->native.enative, &esym);
3090 /* If we're producing an executable, move common symbols
3092 if (relocateable == false)
3094 if (esym.asym.sc == scCommon)
3095 esym.asym.sc = scBss;
3096 else if (esym.asym.sc == scSCommon)
3097 esym.asym.sc = scSBss;
3100 /* Adjust the FDR index for the symbol by that used for
3102 esym.ifd += ecoff_data (bfd_asymbol_bfd (sym_ptr))->ifdbase;
3105 esym.asym.iss = symhdr->issExtMax;
3107 if (bfd_is_com_section (sym_ptr->section)
3108 || sym_ptr->section == &bfd_und_section)
3109 esym.asym.value = sym_ptr->value;
3111 esym.asym.value = (sym_ptr->value
3112 + sym_ptr->section->output_offset
3113 + sym_ptr->section->output_section->vma);
3115 ecoff_swap_ext_out (abfd, &esym, external_ext + symhdr->iextMax);
3117 ecoff_set_sym_index (sym_ptr, symhdr->iextMax);
3121 strcpy (ssext + symhdr->issExtMax, sym_ptr->name);
3122 symhdr->issExtMax += strlen (sym_ptr->name) + 1;
3126 /* Adjust the counts so that structures are longword aligned. */
3127 symhdr->cbLine = (symhdr->cbLine + 3) &~ 3;
3128 symhdr->issMax = (symhdr->issMax + 3) &~ 3;
3129 symhdr->issExtMax = (symhdr->issExtMax + 3) &~ 3;
3134 /* Set the architecture. The only architecture we support here is
3135 mips. We set the architecture anyhow, since many callers ignore
3136 the return value. */
3139 ecoff_set_arch_mach (abfd, arch, machine)
3141 enum bfd_architecture arch;
3142 unsigned long machine;
3144 bfd_default_set_arch_mach (abfd, arch, machine);
3145 return arch == bfd_arch_mips;
3148 /* Get the size of the section headers. We do not output the .scommon
3149 section which we created in ecoff_mkobject. */
3152 ecoff_sizeof_headers (abfd, reloc)
3156 return FILHSZ + AOUTSZ + (abfd->section_count - 1) * SCNHSZ;
3159 /* Calculate the file position for each section, and set
3163 ecoff_compute_section_file_positions (abfd)
3171 if (bfd_get_start_address (abfd))
3172 abfd->flags |= EXEC_P;
3174 sofar = ecoff_sizeof_headers (abfd, false);
3177 for (current = abfd->sections;
3178 current != (asection *) NULL;
3179 current = current->next)
3181 /* Only deal with sections which have contents */
3182 if (! (current->flags & SEC_HAS_CONTENTS)
3183 || strcmp (current->name, SCOMMON) == 0)
3186 /* On Ultrix, the data sections in an executable file must be
3187 aligned to a page boundary within the file. This does not
3188 affect the section size, though. FIXME: Does this work for
3190 if ((abfd->flags & EXEC_P) != 0
3191 && first_data != false
3192 && (current->flags & SEC_CODE) == 0)
3194 sofar = (sofar + ROUND_SIZE - 1) &~ (ROUND_SIZE - 1);
3198 /* Align the sections in the file to the same boundary on
3199 which they are aligned in virtual memory. */
3201 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
3203 current->filepos = sofar;
3205 sofar += current->_raw_size;
3207 /* make sure that this section is of the right size too */
3209 sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
3210 current->_raw_size += sofar - old_sofar;
3213 ecoff_data (abfd)->reloc_filepos = sofar;
3216 /* Set the contents of a section. */
3219 ecoff_set_section_contents (abfd, section, location, offset, count)
3224 bfd_size_type count;
3226 if (abfd->output_has_begun == false)
3227 ecoff_compute_section_file_positions (abfd);
3229 bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET);
3232 return (bfd_write (location, 1, count, abfd) == count) ? true : false;
3237 /* Write out an ECOFF file. */
3240 ecoff_write_object_contents (abfd)
3246 file_ptr reloc_base;
3248 unsigned long reloc_size;
3249 unsigned long text_size;
3250 unsigned long text_start;
3251 unsigned long data_size;
3252 unsigned long data_start;
3253 unsigned long bss_size;
3254 struct internal_filehdr internal_f;
3255 struct internal_aouthdr internal_a;
3258 bfd_error = system_call_error;
3260 if(abfd->output_has_begun == false)
3261 ecoff_compute_section_file_positions(abfd);
3263 if (abfd->sections != (asection *) NULL)
3264 scn_base = abfd->sections->filepos;
3267 reloc_base = ecoff_data (abfd)->reloc_filepos;
3271 for (current = abfd->sections;
3272 current != (asection *)NULL;
3273 current = current->next)
3275 if (strcmp (current->name, SCOMMON) == 0)
3277 current->target_index = count;
3279 if (current->reloc_count != 0)
3281 bfd_size_type relsize;
3283 current->rel_filepos = reloc_base;
3284 relsize = current->reloc_count * RELSZ;
3285 reloc_size += relsize;
3286 reloc_base += relsize;
3289 current->rel_filepos = 0;
3292 sym_base = reloc_base + reloc_size;
3294 /* At least on Ultrix, the symbol table of an executable file must
3295 be aligned to a page boundary. FIXME: Is this true on other
3297 if ((abfd->flags & EXEC_P) != 0)
3298 sym_base = (sym_base + ROUND_SIZE - 1) &~ (ROUND_SIZE - 1);
3300 ecoff_data (abfd)->sym_filepos = sym_base;
3302 text_size = ecoff_sizeof_headers (abfd, false);
3308 /* Write section headers to the file. */
3310 internal_f.f_nscns = 0;
3311 if (bfd_seek (abfd, (file_ptr) (FILHSZ + AOUTSZ), SEEK_SET) != 0)
3313 for (current = abfd->sections;
3314 current != (asection *) NULL;
3315 current = current->next)
3317 struct internal_scnhdr section;
3320 if (strcmp (current->name, SCOMMON) == 0)
3322 BFD_ASSERT (bfd_get_section_size_before_reloc (current) == 0
3323 && current->reloc_count == 0);
3327 ++internal_f.f_nscns;
3329 strncpy (section.s_name, current->name, sizeof section.s_name);
3331 /* FIXME: is this correct for shared libraries? I think it is
3332 but I have no platform to check. Ian Lance Taylor. */
3333 vma = bfd_get_section_vma (abfd, current);
3334 if (strcmp (current->name, _LIB) == 0)
3335 section.s_vaddr = 0;
3337 section.s_vaddr = vma;
3339 section.s_paddr = vma;
3340 section.s_size = bfd_get_section_size_before_reloc (current);
3342 /* If this section has no size or is unloadable then the scnptr
3344 if (current->_raw_size == 0
3345 || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
3346 section.s_scnptr = 0;
3348 section.s_scnptr = current->filepos;
3349 section.s_relptr = current->rel_filepos;
3351 /* FIXME: the lnnoptr of the .sbss or .sdata section of an
3352 object file produced by the assembler is supposed to point to
3353 information about how much room is required by objects of
3354 various different sizes. I think this only matters if we
3355 want the linker to compute the best size to use, or
3356 something. I don't know what happens if the information is
3358 section.s_lnnoptr = 0;
3360 section.s_nreloc = current->reloc_count;
3361 section.s_nlnno = 0;
3362 section.s_flags = ecoff_sec_to_styp_flags (current->name,
3368 ecoff_swap_scnhdr_out (abfd, (PTR) §ion, (PTR) &buff);
3369 if (bfd_write ((PTR) &buff, 1, SCNHSZ, abfd) != SCNHSZ)
3373 if ((section.s_flags & STYP_TEXT) != 0)
3375 text_size += bfd_get_section_size_before_reloc (current);
3376 if (text_start == 0 || text_start > vma)
3379 else if ((section.s_flags & STYP_RDATA) != 0
3380 || (section.s_flags & STYP_DATA) != 0
3381 || (section.s_flags & STYP_LIT8) != 0
3382 || (section.s_flags & STYP_LIT4) != 0
3383 || (section.s_flags & STYP_SDATA) != 0)
3385 data_size += bfd_get_section_size_before_reloc (current);
3386 if (data_start == 0 || data_start > vma)
3389 else if ((section.s_flags & STYP_BSS) != 0
3390 || (section.s_flags & STYP_SBSS) != 0)
3391 bss_size += bfd_get_section_size_before_reloc (current);
3394 /* Set up the file header. */
3396 if (abfd->xvec->header_byteorder_big_p != false)
3397 internal_f.f_magic = MIPS_MAGIC_BIG;
3399 internal_f.f_magic = MIPS_MAGIC_LITTLE;
3402 We will NOT put a fucking timestamp in the header here. Every time you
3403 put it back, I will come in and take it out again. I'm sorry. This
3404 field does not belong here. We fill it with a 0 so it compares the
3405 same but is not a reasonable time. -- gnu@cygnus.com
3407 internal_f.f_timdat = 0;
3409 if (bfd_get_symcount (abfd) != 0)
3411 /* The ECOFF f_nsyms field is not actually the number of
3412 symbols, it's the size of symbolic information header. */
3413 internal_f.f_nsyms = sizeof (struct hdr_ext);
3414 internal_f.f_symptr = sym_base;
3418 internal_f.f_nsyms = 0;
3419 internal_f.f_symptr = 0;
3422 internal_f.f_opthdr = AOUTSZ;
3424 internal_f.f_flags = F_LNNO;
3425 if (reloc_size == 0)
3426 internal_f.f_flags |= F_RELFLG;
3427 if (bfd_get_symcount (abfd) == 0)
3428 internal_f.f_flags |= F_LSYMS;
3429 if (abfd->flags & EXEC_P)
3430 internal_f.f_flags |= F_EXEC;
3432 if (! abfd->xvec->byteorder_big_p)
3433 internal_f.f_flags |= F_AR32WR;
3435 internal_f.f_flags |= F_AR32W;
3437 /* Set up the ``optional'' header. */
3438 internal_a.magic = ZMAGIC;
3440 /* FIXME: This is what Ultrix puts in, and it makes the Ultrix
3441 linker happy. But, is it right? */
3442 internal_a.vstamp = 0x20a;
3444 /* At least on Ultrix, these have to be rounded to page boundaries.
3445 FIXME: Is this true on other platforms? */
3446 internal_a.tsize = (text_size + ROUND_SIZE - 1) &~ (ROUND_SIZE - 1);
3447 internal_a.text_start = text_start &~ (ROUND_SIZE - 1);
3448 internal_a.dsize = (data_size + ROUND_SIZE - 1) &~ (ROUND_SIZE - 1);
3449 internal_a.data_start = data_start &~ (ROUND_SIZE - 1);
3451 /* On Ultrix, the initial portions of the .sbss and .bss segments
3452 are at the end of the data section. The bsize field in the
3453 optional header records how many bss bytes are required beyond
3454 those in the data section. The value is not rounded to a page
3456 if (bss_size < internal_a.dsize - data_size)
3459 bss_size -= internal_a.dsize - data_size;
3460 internal_a.bsize = bss_size;
3461 internal_a.bss_start = internal_a.data_start + internal_a.dsize;
3463 internal_a.entry = bfd_get_start_address (abfd);
3465 internal_a.gp_value = ecoff_data (abfd)->gp;
3467 internal_a.gprmask = ecoff_data (abfd)->gprmask;
3468 for (i = 0; i < 4; i++)
3469 internal_a.cprmask[i] = ecoff_data (abfd)->cprmask[i];
3471 /* Write out the file header and the optional header. */
3473 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
3478 ecoff_swap_filehdr_out (abfd, (PTR) &internal_f, (PTR) &buff);
3479 if (bfd_write ((PTR) &buff, 1, FILHSZ, abfd) != FILHSZ)
3486 ecoff_swap_aouthdr_out (abfd, (PTR) &internal_a, (PTR) &buff);
3487 if (bfd_write ((PTR) &buff, 1, AOUTSZ, abfd) != AOUTSZ)
3491 /* Write out the relocs. */
3492 for (current = abfd->sections;
3493 current != (asection *) NULL;
3494 current = current->next)
3497 arelent **reloc_ptr_ptr;
3498 arelent **reloc_end;
3501 if (current->reloc_count == 0)
3504 buff = (RELOC *) bfd_alloc (abfd, current->reloc_count * RELSZ);
3505 if (buff == (RELOC *) NULL)
3507 bfd_error = no_memory;
3511 reloc_ptr_ptr = current->orelocation;
3512 reloc_end = reloc_ptr_ptr + current->reloc_count;
3514 for (; reloc_ptr_ptr < reloc_end; reloc_ptr_ptr++, out_ptr++)
3518 struct internal_reloc in;
3520 memset (&in, 0, sizeof in);
3522 reloc = *reloc_ptr_ptr;
3523 sym = *reloc->sym_ptr_ptr;
3525 /* This must be an ECOFF reloc. */
3526 BFD_ASSERT (reloc->howto != (reloc_howto_type *) NULL
3527 && reloc->howto >= ecoff_howto_table
3529 < (ecoff_howto_table + ECOFF_HOWTO_COUNT)));
3531 in.r_vaddr = reloc->address + bfd_get_section_vma (abfd, current);
3532 in.r_type = reloc->howto->type;
3534 /* If this is a REFHI reloc, the next one must be a REFLO
3535 reloc for the same symbol. */
3536 BFD_ASSERT (in.r_type != ECOFF_R_REFHI
3537 || (reloc_ptr_ptr < reloc_end
3538 && (reloc_ptr_ptr[1]->howto
3539 != (reloc_howto_type *) NULL)
3540 && (reloc_ptr_ptr[1]->howto->type
3542 && (sym == *reloc_ptr_ptr[1]->sym_ptr_ptr)));
3544 if ((sym->flags & BSF_SECTION_SYM) == 0)
3546 in.r_symndx = ecoff_get_sym_index (*reloc->sym_ptr_ptr);
3553 name = bfd_get_section_name (abfd, bfd_get_section (sym));
3554 if (strcmp (name, ".text") == 0)
3555 in.r_symndx = RELOC_SECTION_TEXT;
3556 else if (strcmp (name, ".rdata") == 0)
3557 in.r_symndx = RELOC_SECTION_RDATA;
3558 else if (strcmp (name, ".data") == 0)
3559 in.r_symndx = RELOC_SECTION_DATA;
3560 else if (strcmp (name, ".sdata") == 0)
3561 in.r_symndx = RELOC_SECTION_SDATA;
3562 else if (strcmp (name, ".sbss") == 0)
3563 in.r_symndx = RELOC_SECTION_SBSS;
3564 else if (strcmp (name, ".bss") == 0)
3565 in.r_symndx = RELOC_SECTION_BSS;
3566 else if (strcmp (name, ".init") == 0)
3567 in.r_symndx = RELOC_SECTION_INIT;
3568 else if (strcmp (name, ".lit8") == 0)
3569 in.r_symndx = RELOC_SECTION_LIT8;
3570 else if (strcmp (name, ".lit4") == 0)
3571 in.r_symndx = RELOC_SECTION_LIT4;
3577 ecoff_swap_reloc_out (abfd, (PTR) &in, (PTR) out_ptr);
3580 if (bfd_seek (abfd, current->rel_filepos, SEEK_SET) != 0)
3582 if (bfd_write ((PTR) buff, RELSZ, current->reloc_count, abfd)
3583 != RELSZ * current->reloc_count)
3585 bfd_release (abfd, (PTR) buff);
3588 /* Write out the symbolic debugging information. */
3589 if (bfd_get_symcount (abfd) > 0)
3592 unsigned long sym_offset;
3593 struct hdr_ext buff;
3595 /* Set up the offsets in the symbolic header. */
3596 symhdr = &ecoff_data (abfd)->symbolic_header;
3597 sym_offset = ecoff_data (abfd)->sym_filepos + sizeof (struct hdr_ext);
3599 #define SET(offset, size, ptr) \
3600 if (symhdr->size == 0) \
3601 symhdr->offset = 0; \
3603 symhdr->offset = (((char *) ecoff_data (abfd)->ptr \
3604 - (char *) ecoff_data (abfd)->raw_syments) \
3607 SET (cbLineOffset, cbLine, line);
3608 SET (cbDnOffset, idnMax, external_dnr);
3609 SET (cbPdOffset, ipdMax, external_pdr);
3610 SET (cbSymOffset, isymMax, external_sym);
3611 SET (cbOptOffset, ioptMax, external_opt);
3612 SET (cbAuxOffset, iauxMax, external_aux);
3613 SET (cbSsOffset, issMax, ss);
3614 SET (cbSsExtOffset, issExtMax, ssext);
3615 SET (cbFdOffset, ifdMax, external_fdr);
3616 SET (cbRfdOffset, crfd, external_rfd);
3617 SET (cbExtOffset, iextMax, external_ext);
3620 if (bfd_seek (abfd, (file_ptr) ecoff_data (abfd)->sym_filepos,
3623 ecoff_swap_hdr_out (abfd, &ecoff_data (abfd)->symbolic_header, &buff);
3624 if (bfd_write ((PTR) &buff, 1, sizeof buff, abfd) != sizeof buff)
3626 if (bfd_write ((PTR) ecoff_data (abfd)->raw_syments, 1,
3627 ecoff_data (abfd)->raw_size, abfd)
3628 != ecoff_data (abfd)->raw_size)
3635 /* Archive handling. ECOFF uses what appears to be a unique type of
3636 archive header (which I call an armap). The byte ordering of the
3637 armap and the contents are encoded in the name of the armap itself.
3638 At least for now, we only support archives with the same byte
3639 ordering in the armap and the contents.
3641 The first four bytes in the armap are the number of symbol
3642 definitions. This is always a power of two.
3644 This is followed by the symbol definitions. Each symbol definition
3645 occupies 8 bytes. The first four bytes are the offset from the
3646 start of the armap strings to the null-terminated string naming
3647 this symbol. The second four bytes are the file offset to the
3648 archive member which defines this symbol. If the second four bytes
3649 are 0, then this is not actually a symbol definition, and it should
3652 The symbols are hashed into the armap with a closed hashing scheme.
3653 See the functions below for the details of the algorithm.
3655 We could use the hash table when looking up symbols in a library.
3656 This would require a new BFD target entry point to replace the
3657 bfd_get_next_mapent function used by the linker.
3659 After the symbol definitions comes four bytes holding the size of
3660 the string table, followed by the string table itself. */
3662 /* The name of an archive headers looks like this:
3663 __________E[BL]E[BL]_ (with a trailing space).
3664 The trailing space is changed to an X if the archive is changed to
3665 indicate that the armap is out of date. */
3667 #define ARMAP_BIG_ENDIAN 'B'
3668 #define ARMAP_LITTLE_ENDIAN 'L'
3669 #define ARMAP_MARKER 'E'
3670 #define ARMAP_START "__________"
3671 #define ARMAP_HEADER_MARKER_INDEX 10
3672 #define ARMAP_HEADER_ENDIAN_INDEX 11
3673 #define ARMAP_OBJECT_MARKER_INDEX 12
3674 #define ARMAP_OBJECT_ENDIAN_INDEX 13
3675 #define ARMAP_END_INDEX 14
3676 #define ARMAP_END "_ "
3678 /* This is a magic number used in the hashing algorithm. */
3679 #define ARMAP_HASH_MAGIC 0x9dd68ab5
3681 /* This returns the hash value to use for a string. It also sets
3682 *REHASH to the rehash adjustment if the first slot is taken. SIZE
3683 is the number of entries in the hash table, and HLOG is the log
3687 ecoff_armap_hash (s, rehash, size, hlog)
3689 unsigned int *rehash;
3697 hash = ((hash >> 27) | (hash << 5)) + *s++;
3698 hash *= ARMAP_HASH_MAGIC;
3699 *rehash = (hash & (size - 1)) | 1;
3700 return hash >> (32 - hlog);
3703 /* Read in the armap. */
3706 ecoff_slurp_armap (abfd)
3711 struct areltdata *mapdata;
3712 bfd_size_type parsed_size;
3714 struct artdata *ardata;
3717 struct symdef *symdef_ptr;
3720 /* Get the name of the first element. */
3721 i = bfd_read ((PTR) nextname, 1, 16, abfd);
3727 bfd_seek (abfd, (file_ptr) -16, SEEK_CUR);
3729 /* See if the first element is an armap. */
3730 if (strncmp (nextname, ARMAP_START, sizeof ARMAP_START - 1) != 0
3731 || nextname[ARMAP_HEADER_MARKER_INDEX] != ARMAP_MARKER
3732 || (nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
3733 && nextname[ARMAP_HEADER_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
3734 || nextname[ARMAP_OBJECT_MARKER_INDEX] != ARMAP_MARKER
3735 || (nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_BIG_ENDIAN
3736 && nextname[ARMAP_OBJECT_ENDIAN_INDEX] != ARMAP_LITTLE_ENDIAN)
3737 || strncmp (nextname + ARMAP_END_INDEX,
3738 ARMAP_END, sizeof ARMAP_END - 1) != 0)
3740 bfd_has_map (abfd) = false;
3744 /* Make sure we have the right byte ordering. */
3745 if (((nextname[ARMAP_HEADER_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
3746 ^ (abfd->xvec->header_byteorder_big_p != false))
3747 || ((nextname[ARMAP_OBJECT_ENDIAN_INDEX] == ARMAP_BIG_ENDIAN)
3748 ^ (abfd->xvec->byteorder_big_p != false)))
3750 bfd_error = wrong_format;
3754 /* Read in the armap. */
3755 ardata = bfd_ardata (abfd);
3756 mapdata = snarf_ar_hdr (abfd);
3757 if (mapdata == (struct areltdata *) NULL)
3759 parsed_size = mapdata->parsed_size;
3760 bfd_release (abfd, (PTR) mapdata);
3762 raw_armap = (char *) bfd_alloc (abfd, parsed_size);
3763 if (raw_armap == (char *) NULL)
3765 bfd_error = no_memory;
3769 if (bfd_read ((PTR) raw_armap, 1, parsed_size, abfd) != parsed_size)
3771 bfd_error = malformed_archive;
3772 bfd_release (abfd, (PTR) raw_armap);
3776 count = bfd_h_get_32 (abfd, (PTR) raw_armap);
3778 ardata->symdef_count = 0;
3779 ardata->cache = (struct ar_cache *) NULL;
3781 /* Hack: overlay the symdefs on top of the raw archive data. This
3782 is the way do_slurp_bsd_armap works. */
3783 raw_ptr = raw_armap + LONG_SIZE;
3784 symdef_ptr = (struct symdef *) raw_ptr;
3785 ardata->symdefs = (carsym *) symdef_ptr;
3786 stringbase = raw_ptr + count * (2 * LONG_SIZE) + LONG_SIZE;
3788 #ifdef CHECK_ARMAP_HASH
3792 /* Double check that I have the hashing algorithm right by making
3793 sure that every symbol can be looked up successfully. */
3795 for (i = 1; i < count; i <<= 1)
3797 BFD_ASSERT (i == count);
3799 for (i = 0; i < count; i++, raw_ptr += 2 * LONG_SIZE)
3801 unsigned int name_offset, file_offset;
3802 unsigned int hash, rehash, srch;
3804 name_offset = bfd_h_get_32 (abfd, (PTR) raw_ptr);
3805 file_offset = bfd_h_get_32 (abfd, (PTR) (raw_ptr + LONG_SIZE));
3806 if (file_offset == 0)
3808 hash = ecoff_armap_hash (stringbase + name_offset, &rehash, count,
3813 /* See if we can rehash to this location. */
3814 for (srch = (hash + rehash) & (count - 1);
3815 srch != hash && srch != i;
3816 srch = (srch + rehash) & (count - 1))
3817 BFD_ASSERT (bfd_h_get_32 (abfd,
3820 + (srch * 2 * LONG_SIZE)
3823 BFD_ASSERT (srch == i);
3827 raw_ptr = raw_armap + LONG_SIZE;
3828 #endif /* CHECK_ARMAP_HASH */
3830 for (i = 0; i < count; i++, raw_ptr += 2 * LONG_SIZE)
3832 unsigned int name_offset, file_offset;
3834 name_offset = bfd_h_get_32 (abfd, (PTR) raw_ptr);
3835 file_offset = bfd_h_get_32 (abfd, (PTR) (raw_ptr + LONG_SIZE));
3836 if (file_offset == 0)
3838 symdef_ptr->s.name = stringbase + name_offset;
3839 symdef_ptr->file_offset = file_offset;
3841 ++ardata->symdef_count;
3844 ardata->first_file_filepos = bfd_tell (abfd);
3845 /* Pad to an even boundary. */
3846 ardata->first_file_filepos += ardata->first_file_filepos % 2;
3848 bfd_has_map (abfd) = true;
3853 /* Write out an armap. */
3856 ecoff_write_armap (abfd, elength, map, orl_count, stridx)
3858 unsigned int elength;
3860 unsigned int orl_count;
3863 unsigned int hashsize, hashlog;
3864 unsigned int symdefsize;
3866 unsigned int stringsize;
3867 unsigned int mapsize;
3870 struct stat statbuf;
3872 bfd_byte temp[LONG_SIZE];
3873 bfd_byte *hashtable;
3877 /* Ultrix appears to use as a hash table size the least power of two
3878 greater than twice the number of entries. */
3879 for (hashlog = 0; (1 << hashlog) <= 2 * orl_count; hashlog++)
3881 hashsize = 1 << hashlog;
3883 symdefsize = hashsize * 2 * LONG_SIZE;
3885 stringsize = stridx + padit;
3887 /* Include 8 bytes to store symdefsize and stringsize in output. */
3888 mapsize = LONG_SIZE + symdefsize + stringsize + LONG_SIZE;
3890 firstreal = SARMAG + sizeof (struct ar_hdr) + mapsize + elength;
3892 memset ((PTR) &hdr, 0, sizeof hdr);
3894 /* Work out the ECOFF armap name. */
3895 strcpy (hdr.ar_name, ARMAP_START);
3896 hdr.ar_name[ARMAP_HEADER_MARKER_INDEX] = ARMAP_MARKER;
3897 hdr.ar_name[ARMAP_HEADER_ENDIAN_INDEX] =
3898 (abfd->xvec->header_byteorder_big_p
3900 : ARMAP_LITTLE_ENDIAN);
3901 hdr.ar_name[ARMAP_OBJECT_MARKER_INDEX] = ARMAP_MARKER;
3902 hdr.ar_name[ARMAP_OBJECT_ENDIAN_INDEX] =
3903 abfd->xvec->byteorder_big_p ? ARMAP_BIG_ENDIAN : ARMAP_LITTLE_ENDIAN;
3904 memcpy (hdr.ar_name + ARMAP_END_INDEX, ARMAP_END, sizeof ARMAP_END - 1);
3906 /* Write the timestamp of the archive header to be just a little bit
3907 later than the timestamp of the file, otherwise the linker will
3908 complain that the index is out of date. Actually, the Ultrix
3909 linker just checks the archive name; the GNU linker may check the
3911 stat (abfd->filename, &statbuf);
3912 sprintf (hdr.ar_date, "%ld", (long) (statbuf.st_mtime + 60));
3914 /* The DECstation uses zeroes for the uid, gid and mode of the
3916 hdr.ar_uid[0] = '0';
3917 hdr.ar_gid[0] = '0';
3918 hdr.ar_mode[0] = '0';
3920 sprintf (hdr.ar_size, "%-10d", (int) mapsize);
3922 hdr.ar_fmag[0] = '`';
3923 hdr.ar_fmag[1] = '\n';
3925 /* Turn all null bytes in the header into spaces. */
3926 for (i = 0; i < sizeof (struct ar_hdr); i++)
3927 if (((char *)(&hdr))[i] == '\0')
3928 (((char *)(&hdr))[i]) = ' ';
3930 if (bfd_write ((PTR) &hdr, 1, sizeof (struct ar_hdr), abfd)
3931 != sizeof (struct ar_hdr))
3934 bfd_h_put_32 (abfd, hashsize, temp);
3935 if (bfd_write (temp, 1, LONG_SIZE, abfd) != LONG_SIZE)
3938 hashtable = (bfd_byte *) bfd_zalloc (abfd, symdefsize);
3940 current = abfd->archive_head;
3942 for (i = 0; i < orl_count; i++)
3944 unsigned int hash, rehash;
3946 /* Advance firstreal to the file position of this archive
3948 if (((bfd *) map[i].pos) != last_elt)
3952 firstreal += arelt_size (current) + sizeof (struct ar_hdr);
3953 firstreal += firstreal % 2;
3954 current = current->next;
3956 while (current != (bfd *) map[i].pos);
3961 hash = ecoff_armap_hash (*map[i].name, &rehash, hashsize, hashlog);
3962 if (bfd_h_get_32 (abfd, (PTR) (hashtable
3963 + (hash * 2 * LONG_SIZE)
3969 /* The desired slot is already taken. */
3970 for (srch = (hash + rehash) & (hashsize - 1);
3972 srch = (srch + rehash) & (hashsize - 1))
3973 if (bfd_h_get_32 (abfd, (PTR) (hashtable
3974 + (srch * 2 * LONG_SIZE)
3979 BFD_ASSERT (srch != hash);
3984 bfd_h_put_32 (abfd, map[i].namidx,
3985 (PTR) (hashtable + hash * 2 * LONG_SIZE));
3986 bfd_h_put_32 (abfd, firstreal,
3987 (PTR) (hashtable + hash * 2 * LONG_SIZE + LONG_SIZE));
3990 if (bfd_write (hashtable, 1, symdefsize, abfd) != symdefsize)
3993 bfd_release (abfd, hashtable);
3995 /* Now write the strings. */
3996 bfd_h_put_32 (abfd, stringsize, temp);
3997 if (bfd_write (temp, 1, LONG_SIZE, abfd) != LONG_SIZE)
3999 for (i = 0; i < orl_count; i++)
4003 len = strlen (*map[i].name) + 1;
4004 if (bfd_write ((PTR) (*map[i].name), 1, len, abfd) != len)
4008 /* The spec sez this should be a newline. But in order to be
4009 bug-compatible for DECstation ar we use a null. */
4012 if (bfd_write ("\0", 1, 1, abfd) != 1)
4019 /* We just use the generic extended name support. This is a GNU
4021 #define ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table
4023 /* See whether this BFD is an archive. If it is, read in the armap
4024 and the extended name table. */
4027 ecoff_archive_p (abfd)
4030 char armag[SARMAG + 1];
4032 if (bfd_read ((PTR) armag, 1, SARMAG, abfd) != SARMAG
4033 || strncmp (armag, ARMAG, SARMAG) != 0)
4035 bfd_error = wrong_format;
4036 return (bfd_target *) NULL;
4039 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
4040 involves a cast, we can't do it as the left operand of
4042 abfd->tdata.aout_ar_data =
4043 (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata));
4045 if (bfd_ardata (abfd) == (struct artdata *) NULL)
4047 bfd_error = no_memory;
4048 return (bfd_target *) NULL;
4051 bfd_ardata (abfd)->first_file_filepos = SARMAG;
4053 if (ecoff_slurp_armap (abfd) == false
4054 || ecoff_slurp_extended_name_table (abfd) == false)
4056 bfd_release (abfd, bfd_ardata (abfd));
4057 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
4058 return (bfd_target *) NULL;
4064 /* This is the COFF backend structure. The backend_data field of the
4065 bfd_target structure is set to this. The section reading code in
4066 coffgen.c uses this structure. */
4068 static CONST bfd_coff_backend_data bfd_ecoff_std_swap_table = {
4069 (void (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_in */
4070 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_in */
4071 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_in */
4072 (unsigned (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_out */
4073 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_out */
4074 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_out */
4075 ecoff_swap_reloc_out, ecoff_swap_filehdr_out, ecoff_swap_aouthdr_out,
4076 ecoff_swap_scnhdr_out,
4077 FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, true,
4078 ecoff_swap_filehdr_in, ecoff_swap_aouthdr_in, ecoff_swap_scnhdr_in,
4079 ecoff_bad_format_hook, ecoff_set_arch_mach_hook, ecoff_mkobject_hook,
4080 ecoff_styp_to_sec_flags, ecoff_make_section_hook, ecoff_set_alignment_hook,
4081 ecoff_slurp_symbol_table
4084 /* get_lineno could be written for ECOFF, but it would currently only
4085 be useful for linking ECOFF and COFF files together, which doesn't
4087 #define ecoff_get_lineno \
4088 ((alent *(*) PARAMS ((bfd *, asymbol *))) bfd_nullvoidptr)
4090 /* These bfd_target functions are defined in other files. */
4092 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
4093 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
4094 #define ecoff_core_file_matches_executable_p \
4095 _bfd_dummy_core_file_matches_executable_p
4096 #define ecoff_truncate_arname bfd_dont_truncate_arname
4097 #define ecoff_openr_next_archived_file bfd_generic_openr_next_archived_file
4098 #define ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt
4099 #define ecoff_get_section_contents bfd_generic_get_section_contents
4100 #define ecoff_get_reloc_upper_bound coff_get_reloc_upper_bound
4101 #define ecoff_close_and_cleanup bfd_generic_close_and_cleanup
4102 #define ecoff_bfd_debug_info_start bfd_void
4103 #define ecoff_bfd_debug_info_end bfd_void
4104 #define ecoff_bfd_debug_info_accumulate \
4105 ((void (*) PARAMS ((bfd *, struct sec *))) bfd_void)
4106 #define ecoff_bfd_get_relocated_section_contents \
4107 bfd_generic_get_relocated_section_contents
4108 #define ecoff_bfd_relax_section bfd_generic_relax_section
4109 #define ecoff_bfd_make_debug_symbol \
4110 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
4112 bfd_target ecoff_little_vec =
4114 "ecoff-littlemips", /* name */
4115 bfd_target_ecoff_flavour,
4116 false, /* data byte order is little */
4117 false, /* header byte order is little */
4119 (HAS_RELOC | EXEC_P | /* object flags */
4120 HAS_LINENO | HAS_DEBUG |
4121 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
4123 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect
4125 0, /* leading underscore */
4126 '/', /* ar_pad_char */
4127 15, /* ar_max_namelen */
4128 3, /* minimum alignment power */
4129 _do_getl64, _do_getl_signed_64, _do_putl64,
4130 _do_getl32, _do_getl_signed_32, _do_putl32,
4131 _do_getl16, _do_getl_signed_16, _do_putl16, /* data */
4132 _do_getl64, _do_getl_signed_64, _do_putl64,
4133 _do_getl32, _do_getl_signed_32, _do_putl32,
4134 _do_getl16, _do_getl_signed_16, _do_putl16, /* hdrs */
4136 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
4137 ecoff_archive_p, _bfd_dummy_target},
4138 {bfd_false, ecoff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
4140 {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */
4141 _bfd_write_archive_contents, bfd_false},
4143 (PTR) &bfd_ecoff_std_swap_table
4146 bfd_target ecoff_big_vec =
4148 "ecoff-bigmips", /* name */
4149 bfd_target_ecoff_flavour,
4150 true, /* data byte order is big */
4151 true, /* header byte order is big */
4153 (HAS_RELOC | EXEC_P | /* object flags */
4154 HAS_LINENO | HAS_DEBUG |
4155 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
4157 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect flags */
4158 0, /* leading underscore */
4159 ' ', /* ar_pad_char */
4160 16, /* ar_max_namelen */
4161 3, /* minimum alignment power */
4162 _do_getb64, _do_getb_signed_64, _do_putb64,
4163 _do_getb32, _do_getb_signed_32, _do_putb32,
4164 _do_getb16, _do_getb_signed_16, _do_putb16,
4165 _do_getb64, _do_getb_signed_64, _do_putb64,
4166 _do_getb32, _do_getb_signed_32, _do_putb32,
4167 _do_getb16, _do_getb_signed_16, _do_putb16,
4168 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
4169 ecoff_archive_p, _bfd_dummy_target},
4170 {bfd_false, ecoff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
4172 {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */
4173 _bfd_write_archive_contents, bfd_false},
4175 (PTR) &bfd_ecoff_std_swap_table
4176 /* Note that there is another bfd_target just above this one. If
4177 you are adding initializers here, you should be adding them there