1 /* BFD back-end for MIPS Extended-Coff files.
2 Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
3 Written by Per Bothner.
4 Symbol and line number support added by Ian Lance Taylor.
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. */
25 #include "coff/mips.h"
26 #include "coff/internal.h"
28 #include "coff/symconst.h"
29 #include "coff/ecoff-ext.h"
32 /* `Tdata' information kept for ECOFF files. */
34 #define ecoff_data(abfd) ((abfd)->tdata.ecoff_obj_data)
36 typedef struct ecoff_tdata
38 /* The symbol table file position. */
41 /* The unswapped ECOFF symbolic information. */
44 /* The swapped ECOFF symbolic header. */
47 /* Pointers to the unswapped symbolic information. */
49 struct dnr_ext *external_dnr;
50 struct pdr_ext *external_pdr;
51 struct sym_ext *external_sym;
52 struct opt_ext *external_opt;
53 union aux_ext *external_aux;
56 struct fdr_ext *external_fdr;
57 struct rfd_ext *external_rfd;
58 struct ext_ext *external_ext;
60 /* The swapped fdr information. */
63 /* The canonical BFD symbols. */
64 struct ecoff_symbol_struct *canonical_symbols;
68 /* Each canonical asymbol really looks like this. */
70 typedef struct ecoff_symbol_struct
72 /* The actual symbol which the rest of BFD works with */
75 /* The fdr for this symbol. */
78 /* true if this is a local symbol rather than an external one. */
81 /* A pointer to the unswapped hidden information for this symbol */
84 struct sym_ext *lnative;
85 struct ext_ext *enative;
90 /* We take the address of the first element of a asymbol to ensure that the
91 macro is only ever applied to an asymbol. */
92 #define ecoffsymbol(asymbol) ((ecoff_symbol_type *) (&((asymbol)->the_bfd)))
94 /* MIPS ECOFF has COFF sections, but the debugging information is
95 stored in a completely different format. This files uses the some
96 of the swapping routines from coffswap.h, and some of the generic
97 COFF routines in coffgen.c, but, unlike the real COFF targets, does
98 not use coffcode.h itself. */
100 /* Get the generic COFF swapping routines, except for the symbol and
101 lineno ones. Give them ecoff names. */
102 #define NO_COFF_SYMBOLS
103 #define NO_COFF_LINENOS
104 #define coff_swap_reloc_in ecoff_swap_reloc_in
105 #define coff_swap_reloc_out ecoff_swap_reloc_out
106 #define coff_swap_filehdr_in ecoff_swap_filehdr_in
107 #define coff_swap_filehdr_out ecoff_swap_filehdr_out
108 #define coff_swap_aouthdr_in ecoff_swap_aouthdr_in
109 #define coff_swap_aouthdr_out ecoff_swap_aouthdr_out
110 #define coff_swap_scnhdr_in ecoff_swap_scnhdr_in
111 #define coff_swap_scnhdr_out ecoff_swap_scnhdr_out
112 #include "coffswap.h"
114 /* This stuff is somewhat copied from coffcode.h. */
116 static asection bfd_debug_section = { "*DEBUG*" };
118 /* See whether the magic number matches. */
121 DEFUN(ecoff_bad_format_hook, (abfd, filehdr),
125 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
127 if (ECOFFBADMAG (*internal_f))
133 /* This is a hook needed by SCO COFF, but we have nothing to do. */
136 DEFUN (ecoff_make_section_hook, (abfd, name),
140 return (asection *) NULL;
143 /* Initialize a new section. */
146 DEFUN (ecoff_new_section_hook, (abfd, section),
150 section->alignment_power = abfd->xvec->align_power_min;
154 #define ecoff_set_alignment_hook \
155 ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void)
158 DEFUN (ecoff_mkobject, (abfd),
161 abfd->tdata.ecoff_obj_data = ((struct ecoff_tdata *)
162 bfd_zalloc (abfd, sizeof(ecoff_data_type)));
163 if (abfd->tdata.ecoff_obj_data == NULL)
165 bfd_error = no_memory;
172 /* Create the COFF backend specific information. */
175 DEFUN(ecoff_mkobject_hook,(abfd, filehdr),
179 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
180 ecoff_data_type *ecoff;
182 if (ecoff_mkobject (abfd) == false)
185 ecoff = ecoff_data (abfd);
186 ecoff->sym_filepos = internal_f->f_symptr;
190 /* Determine the machine architecture and type. */
192 DEFUN (ecoff_set_arch_mach_hook, (abfd, filehdr),
197 enum bfd_architecture arch;
198 struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
201 switch (internal_f->f_magic) {
205 arch = bfd_arch_mips;
209 default: /* Unreadable input file type */
210 arch = bfd_arch_obscure;
214 bfd_default_set_arch_mach(abfd, arch, machine);
218 /* Get the BFD flags to use for a section. */
221 DEFUN(styp_to_sec_flags, (abfd, hdr),
225 struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
226 long styp_flags = internal_s->s_flags;
227 flagword sec_flags=0;
229 if (styp_flags & STYP_NOLOAD)
230 sec_flags |= SEC_NEVER_LOAD;
232 /* For 386 COFF, at least, an unloadable text or data section is
233 actually a shared library section. */
234 if (styp_flags & STYP_TEXT)
236 if (sec_flags & SEC_NEVER_LOAD)
237 sec_flags |= SEC_CODE | SEC_SHARED_LIBRARY;
239 sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
241 else if ((styp_flags & STYP_DATA)
242 || (styp_flags & STYP_RDATA)
243 || (styp_flags & STYP_SDATA))
245 if (sec_flags & SEC_NEVER_LOAD)
246 sec_flags |= SEC_DATA | SEC_SHARED_LIBRARY;
248 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
249 if (styp_flags & STYP_RDATA)
250 sec_flags |= SEC_READONLY;
252 else if ((styp_flags & STYP_BSS)
253 || (styp_flags & STYP_SBSS))
255 sec_flags |= SEC_ALLOC;
257 else if (styp_flags & STYP_INFO)
259 sec_flags |= SEC_NEVER_LOAD;
261 else if ((styp_flags & STYP_LIT8)
262 || (styp_flags & STYP_LIT4))
264 sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_READONLY;
268 sec_flags |= SEC_ALLOC | SEC_LOAD;
274 /* ECOFF symbol table routines. The ECOFF symbol table is described
275 in gcc/mips-tfile.c. */
277 /* Create an empty symbol. */
280 DEFUN (ecoff_make_empty_symbol, (abfd),
283 ecoff_symbol_type *new;
285 new = (ecoff_symbol_type *) bfd_alloc (abfd, sizeof (ecoff_symbol_type));
286 if (new == (ecoff_symbol_type *) NULL)
288 bfd_error = no_memory;
289 return (asymbol *) NULL;
291 new->symbol.section = (asection *) NULL;
292 new->fdr = (FDR *) NULL;
294 new->native.lnative = (struct sym_ext *) NULL;
295 new->symbol.the_bfd = abfd;
299 /* Set the BFD flags and section for an ECOFF symbol. */
302 DEFUN (ecoff_set_symbol_info, (abfd, ecoff_sym, asym, ext),
308 asym->the_bfd = abfd;
309 asym->value = ecoff_sym->value;
310 asym->section = &bfd_debug_section;
313 asym->flags = BSF_EXPORT | BSF_GLOBAL;
315 asym->flags = BSF_LOCAL;
316 switch (ecoff_sym->sc)
322 asym->section = bfd_make_section_old_way (abfd, ".text");
323 asym->value -= asym->section->vma;
326 asym->section = bfd_make_section_old_way (abfd, ".data");
327 asym->value -= asym->section->vma;
330 asym->section = &bfd_com_section;
334 asym->flags = BSF_DEBUGGING;
337 asym->section = &bfd_abs_section;
341 asym->section = &bfd_und_section;
350 asym->flags = BSF_DEBUGGING;
353 asym->section = bfd_make_section_old_way (abfd, ".sdata");
354 asym->value -= asym->section->vma;
357 asym->section = &bfd_com_section;
361 asym->section = bfd_make_section_old_way (abfd, ".rdata");
362 asym->value -= asym->section->vma;
365 asym->flags = BSF_DEBUGGING;
369 asym->section = &bfd_com_section;
374 asym->flags = BSF_DEBUGGING;
377 asym->section = &bfd_und_section;
381 asym->section = bfd_make_section_old_way (abfd, ".init");
382 asym->value -= asym->section->vma;
387 asym->flags = BSF_DEBUGGING;
390 asym->section = bfd_make_section_old_way (abfd, ".fini");
391 asym->value -= asym->section->vma;
399 /* Read an ECOFF symbol table. */
402 DEFUN (ecoff_slurp_symbol_table, (abfd),
405 struct hdr_ext external_symhdr;
406 HDRR *internal_symhdr;
407 bfd_size_type raw_base;
408 bfd_size_type raw_size;
410 bfd_size_type internal_size;
411 struct fdr_ext *fraw_src;
412 struct fdr_ext *fraw_end;
415 ecoff_symbol_type *internal;
416 ecoff_symbol_type *internal_ptr;
417 struct ext_ext *eraw_src;
418 struct ext_ext *eraw_end;
420 /* If we've already read in the symbol table, do nothing. */
421 if (ecoff_data (abfd)->canonical_symbols != NULL)
424 /* At this point bfd_get_symcount (abfd) holds the number of symbols
425 as read from the file header, but on ECOFF this is always the
426 size of the symbolic information header. It would be cleaner to
427 handle this when we first read the file in coffgen.c. */
428 if (bfd_get_symcount (abfd) != sizeof (external_symhdr))
430 bfd_error = bad_value;
434 /* Read the symbolic information header. */
435 if (bfd_seek (abfd, ecoff_data (abfd)->sym_filepos, SEEK_SET) == -1
436 || (bfd_read ((PTR) &external_symhdr, sizeof (external_symhdr), 1, abfd)
437 != sizeof (external_symhdr)))
439 bfd_error = system_call_error;
442 internal_symhdr = &ecoff_data (abfd)->symbolic_header;
443 ecoff_swap_hdr_in (abfd, &external_symhdr, internal_symhdr);
445 if (internal_symhdr->magic != magicSym)
447 bfd_error = bad_value;
451 /* Now we can get the correct number of symbols. */
452 bfd_get_symcount (abfd) = (internal_symhdr->isymMax
453 + internal_symhdr->iextMax);
455 /* Read the entire symbol table at once. This expression assumes
456 that the external symbols are always the last item. */
457 raw_base = ecoff_data (abfd)->sym_filepos + sizeof (external_symhdr);
458 raw_size = (internal_symhdr->cbExtOffset - raw_base
459 + internal_symhdr->iextMax * sizeof (struct ext_ext));
460 raw = (PTR) bfd_alloc (abfd, raw_size);
463 bfd_error = no_memory;
466 if (bfd_read (raw, raw_size, 1, abfd) != raw_size)
468 bfd_error = system_call_error;
469 bfd_release (abfd, raw);
473 ecoff_data (abfd)->raw_syments = raw;
475 /* Get pointers for the numeric offsets in the HDRR structure. */
476 #define FIX(off1, off2, type) \
477 if (internal_symhdr->off1 == 0) \
478 ecoff_data (abfd)->off2 = (type *) NULL; \
480 ecoff_data (abfd)->off2 = (type *) ((char *) raw \
481 + internal_symhdr->off1 \
483 FIX (cbLineOffset, line, unsigned char);
484 FIX (cbDnOffset, external_dnr, struct dnr_ext);
485 FIX (cbPdOffset, external_pdr, struct pdr_ext);
486 FIX (cbSymOffset, external_sym, struct sym_ext);
487 FIX (cbOptOffset, external_opt, struct opt_ext);
488 FIX (cbAuxOffset, external_aux, union aux_ext);
489 FIX (cbSsOffset, ss, char);
490 FIX (cbSsExtOffset, ssext, char);
491 FIX (cbFdOffset, external_fdr, struct fdr_ext);
492 FIX (cbRfdOffset, external_rfd, struct rfd_ext);
493 FIX (cbExtOffset, external_ext, struct ext_ext);
496 /* I don't want to always swap all the data, because it will just
497 waste time and most programs will never look at this data. The
498 only time the linker needs most of the debugging information
499 swapped is when linking big-endian and little-endian MIPS object
500 files together, which is not a common occurrence.
502 We need to look at the fdr to deal with a lot of information in
503 the symbols, so we swap them here. We also canonicalize the
505 ecoff_data (abfd)->fdr = (struct fdr *) bfd_alloc (abfd,
506 (internal_symhdr->ifdMax *
507 sizeof (struct fdr)));
508 if (ecoff_data (abfd)->fdr == NULL)
510 bfd_error = no_memory;
513 fdr_ptr = ecoff_data (abfd)->fdr;
514 fraw_src = ecoff_data (abfd)->external_fdr;
515 fraw_end = fraw_src + internal_symhdr->ifdMax;
516 for (; fraw_src < fraw_end; fraw_src++, fdr_ptr++)
517 ecoff_swap_fdr_in (abfd, fraw_src, fdr_ptr);
519 internal_size = bfd_get_symcount (abfd) * sizeof (ecoff_symbol_type);
520 internal = (ecoff_symbol_type *) bfd_alloc (abfd, internal_size);
521 if (internal == NULL)
523 bfd_error = no_memory;
527 internal_ptr = internal;
528 eraw_src = ecoff_data (abfd)->external_ext;
529 eraw_end = eraw_src + internal_symhdr->iextMax;
530 for (; eraw_src < eraw_end; eraw_src++, internal_ptr++)
534 ecoff_swap_ext_in (abfd, eraw_src, &internal_esym);
535 internal_ptr->symbol.name = (ecoff_data (abfd)->ssext
536 + internal_esym.asym.iss);
537 ecoff_set_symbol_info (abfd, &internal_esym.asym,
538 &internal_ptr->symbol, 1);
539 internal_ptr->fdr = ecoff_data (abfd)->fdr + internal_esym.ifd;
540 internal_ptr->local = false;
541 internal_ptr->native.enative = eraw_src;
544 /* The local symbols must be accessed via the fdr's, because the
545 string and aux indices are relative to the fdr information. */
546 fdr_ptr = ecoff_data (abfd)->fdr;
547 fdr_end = fdr_ptr + internal_symhdr->ifdMax;
548 for (; fdr_ptr < fdr_end; fdr_ptr++)
550 struct sym_ext *lraw_src;
551 struct sym_ext *lraw_end;
553 lraw_src = ecoff_data (abfd)->external_sym + fdr_ptr->isymBase;
554 lraw_end = lraw_src + fdr_ptr->csym;
555 for (; lraw_src < lraw_end; lraw_src++, internal_ptr++)
559 ecoff_swap_sym_in (abfd, lraw_src, &internal_sym);
560 internal_ptr->symbol.name = (ecoff_data (abfd)->ss
563 ecoff_set_symbol_info (abfd, &internal_sym,
564 &internal_ptr->symbol, 0);
565 internal_ptr->fdr = fdr_ptr;
566 internal_ptr->local = true;
567 internal_ptr->native.lnative = lraw_src;
571 ecoff_data (abfd)->canonical_symbols = internal;
577 DEFUN (ecoff_get_symtab_upper_bound, (abfd),
580 if (! ecoff_slurp_symbol_table (abfd))
583 return (bfd_get_symcount (abfd) + 1) * (sizeof (ecoff_symbol_type *));
587 DEFUN (ecoff_get_symtab, (abfd, alocation),
591 unsigned int counter = 0;
592 ecoff_symbol_type *symbase;
593 ecoff_symbol_type **location = (ecoff_symbol_type **) alocation;
595 if (! ecoff_slurp_symbol_table (abfd))
598 symbase = ecoff_data (abfd)->canonical_symbols;
599 while (counter < bfd_get_symcount (abfd))
601 *(location++) = symbase++;
604 *location++ = (ecoff_symbol_type *) NULL;
605 return bfd_get_symcount (abfd);
608 /* Turn ECOFF type information into a printable string.
609 emit_aggregate and type_to_string are from gcc/mips-tdump.c, with
610 swapping added and used_ptr removed. */
612 /* Write aggregate information to a string. */
615 DEFUN (emit_aggregate, (abfd, string, rndx, isym, which),
623 int indx = rndx->index;
624 int sym_base, ss_base;
630 sym_base = ecoff_data (abfd)->fdr[ifd].isymBase;
631 ss_base = ecoff_data (abfd)->fdr[ifd].issBase;
633 if (indx == indexNil)
634 name = "/* no name */";
640 ecoff_swap_sym_in (abfd,
641 ecoff_data (abfd)->external_sym + indx,
643 name = ecoff_data (abfd)->ss + ss_base + sym.iss;
647 "%s %s { ifd = %d, index = %d }",
649 indx + ecoff_data (abfd)->symbolic_header.iextMax);
652 /* Convert the type information to string format. */
655 DEFUN (type_to_string, (abfd, aux_ptr, indx, bigendian),
657 union aux_ext *aux_ptr AND
669 unsigned int basic_type;
671 static char buffer1[1024];
672 static char buffer2[1024];
677 for (i = 0; i < 7; i++)
679 qualifiers[i].low_bound = 0;
680 qualifiers[i].high_bound = 0;
681 qualifiers[i].stride = 0;
684 if (AUX_GET_ISYM (bigendian, &aux_ptr[indx]) == -1)
685 return "-1 (no type)";
686 ecoff_swap_tir_in (bigendian, &aux_ptr[indx++].a_ti, &u.ti);
688 basic_type = u.ti.bt;
689 qualifiers[0].type = u.ti.tq0;
690 qualifiers[1].type = u.ti.tq1;
691 qualifiers[2].type = u.ti.tq2;
692 qualifiers[3].type = u.ti.tq3;
693 qualifiers[4].type = u.ti.tq4;
694 qualifiers[5].type = u.ti.tq5;
695 qualifiers[6].type = tqNil;
698 * Go get the basic type.
702 case btNil: /* undefined */
706 case btAdr: /* address - integer same size as pointer */
707 strcpy (p1, "address");
710 case btChar: /* character */
714 case btUChar: /* unsigned character */
715 strcpy (p1, "unsigned char");
718 case btShort: /* short */
719 strcpy (p1, "short");
722 case btUShort: /* unsigned short */
723 strcpy (p1, "unsigned short");
726 case btInt: /* int */
730 case btUInt: /* unsigned int */
731 strcpy (p1, "unsigned int");
734 case btLong: /* long */
738 case btULong: /* unsigned long */
739 strcpy (p1, "unsigned long");
742 case btFloat: /* float (real) */
743 strcpy (p1, "float");
746 case btDouble: /* Double (real) */
747 strcpy (p1, "double");
750 /* Structures add 1-2 aux words:
751 1st word is [ST_RFDESCAPE, offset] pointer to struct def;
752 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
754 case btStruct: /* Structure (Record) */
755 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
756 emit_aggregate (abfd, p1, &rndx,
757 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
759 indx++; /* skip aux words */
762 /* Unions add 1-2 aux words:
763 1st word is [ST_RFDESCAPE, offset] pointer to union def;
764 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
766 case btUnion: /* Union */
767 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
768 emit_aggregate (abfd, p1, &rndx,
769 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
771 indx++; /* skip aux words */
774 /* Enumerations add 1-2 aux words:
775 1st word is [ST_RFDESCAPE, offset] pointer to enum def;
776 2nd word is file index if 1st word rfd is ST_RFDESCAPE. */
778 case btEnum: /* Enumeration */
779 ecoff_swap_rndx_in (bigendian, &aux_ptr[indx].a_rndx, &rndx);
780 emit_aggregate (abfd, p1, &rndx,
781 AUX_GET_ISYM (bigendian, &aux_ptr[indx+1]),
783 indx++; /* skip aux words */
786 case btTypedef: /* defined via a typedef, isymRef points */
787 strcpy (p1, "typedef");
790 case btRange: /* subrange of int */
791 strcpy (p1, "subrange");
794 case btSet: /* pascal sets */
798 case btComplex: /* fortran complex */
799 strcpy (p1, "complex");
802 case btDComplex: /* fortran double complex */
803 strcpy (p1, "double complex");
806 case btIndirect: /* forward or unnamed typedef */
807 strcpy (p1, "forward/unamed typedef");
810 case btFixedDec: /* Fixed Decimal */
811 strcpy (p1, "fixed decimal");
814 case btFloatDec: /* Float Decimal */
815 strcpy (p1, "float decimal");
818 case btString: /* Varying Length Character String */
819 strcpy (p1, "string");
822 case btBit: /* Aligned Bit String */
826 case btPicture: /* Picture */
827 strcpy (p1, "picture");
830 case btVoid: /* Void */
835 sprintf (p1, "Unknown basic type %d", (int) basic_type);
839 p1 += strlen (buffer1);
842 * If this is a bitfield, get the bitsize.
848 bitsize = AUX_GET_WIDTH (bigendian, &aux_ptr[indx++]);
849 sprintf (p1, " : %d", bitsize);
850 p1 += strlen (buffer1);
855 * Deal with any qualifiers.
857 if (qualifiers[0].type != tqNil)
860 * Snarf up any array bounds in the correct order. Arrays
861 * store 5 successive words in the aux. table:
862 * word 0 RNDXR to type of the bounds (ie, int)
863 * word 1 Current file descriptor index
865 * word 3 high bound (or -1 if [])
866 * word 4 stride size in bits
868 for (i = 0; i < 7; i++)
870 if (qualifiers[i].type == tqArray)
872 qualifiers[i].low_bound =
873 AUX_GET_DNLOW (bigendian, &aux_ptr[indx+2]);
874 qualifiers[i].high_bound =
875 AUX_GET_DNHIGH (bigendian, &aux_ptr[indx+3]);
876 qualifiers[i].stride =
877 AUX_GET_WIDTH (bigendian, &aux_ptr[indx+4]);
883 * Now print out the qualifiers.
885 for (i = 0; i < 6; i++)
887 switch (qualifiers[i].type)
894 strcpy (p2, "ptr to ");
895 p2 += sizeof ("ptr to ")-1;
899 strcpy (p2, "volatile ");
900 p2 += sizeof ("volatile ")-1;
905 p2 += sizeof ("far ")-1;
909 strcpy (p2, "func. ret. ");
910 p2 += sizeof ("func. ret. ");
918 /* Print array bounds reversed (ie, in the order the C
919 programmer writes them). C is such a fun language.... */
921 while (i < 5 && qualifiers[i+1].type == tqArray)
924 for (j = i; j >= first_array; j--)
926 strcpy (p2, "array [");
927 p2 += sizeof ("array [")-1;
928 if (qualifiers[j].low_bound != 0)
930 "%ld:%ld {%ld bits}",
931 (long) qualifiers[j].low_bound,
932 (long) qualifiers[j].high_bound,
933 (long) qualifiers[j].stride);
935 else if (qualifiers[j].high_bound != -1)
938 (long) (qualifiers[j].high_bound + 1),
939 (long) (qualifiers[j].stride));
942 sprintf (p2, " {%ld bits}", (long) (qualifiers[j].stride));
945 strcpy (p2, "] of ");
946 p2 += sizeof ("] of ")-1;
954 strcpy (p2, buffer1);
958 /* Print information about an ECOFF symbol. */
961 DEFUN (ecoff_print_symbol, (abfd, filep, symbol, how),
965 bfd_print_symbol_type how)
967 FILE *file = (FILE *)filep;
971 case bfd_print_symbol_name:
972 fprintf (file, "%s", symbol->name);
974 case bfd_print_symbol_more:
975 if (ecoffsymbol (symbol)->local)
979 ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative,
981 fprintf (file, "ecoff local %lx %x %x",
982 (unsigned long) ecoff_sym.value,
983 (unsigned) ecoff_sym.st, (unsigned) ecoff_sym.sc);
989 ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative,
991 fprintf (file, "ecoff extern %lx %x %x",
992 (unsigned long) ecoff_ext.asym.value,
993 (unsigned) ecoff_ext.asym.st,
994 (unsigned) ecoff_ext.asym.sc);
997 case bfd_print_symbol_nm:
999 CONST char *section_name = symbol->section->name;
1001 bfd_print_symbol_vandf ((PTR) file, symbol);
1002 fprintf (file, " %-5s %s %s",
1004 ecoffsymbol (symbol)->local ? "l" : "e",
1008 case bfd_print_symbol_all:
1009 /* Print out the symbols in a reasonable way */
1011 CONST char *section_name = symbol->section->name;
1019 if (ecoffsymbol (symbol)->local)
1021 ecoff_swap_sym_in (abfd, ecoffsymbol (symbol)->native.lnative,
1024 pos = (ecoffsymbol (symbol)->native.lnative
1025 - ecoff_data (abfd)->external_sym
1026 + ecoff_data (abfd)->symbolic_header.iextMax);
1033 ecoff_swap_ext_in (abfd, ecoffsymbol (symbol)->native.enative,
1036 pos = (ecoffsymbol (symbol)->native.enative
1037 - ecoff_data (abfd)->external_ext);
1038 jmptbl = ecoff_ext.jmptbl ? 'j' : ' ';
1039 cobol_main = ecoff_ext.cobol_main ? 'c' : ' ';
1040 weakext = ecoff_ext.weakext ? 'w' : ' ';
1043 fprintf (file, "[%3d] %c %lx st %x sc %x indx %x %c%c%c %s",
1044 pos, type, (unsigned long) ecoff_ext.asym.value,
1045 (unsigned) ecoff_ext.asym.st,
1046 (unsigned) ecoff_ext.asym.sc,
1047 (unsigned) ecoff_ext.asym.index,
1048 jmptbl, cobol_main, weakext,
1051 if (ecoffsymbol (symbol)->fdr != NULL
1052 && ecoff_ext.asym.index != indexNil)
1057 union aux_ext *aux_base;
1059 indx = ecoff_ext.asym.index;
1061 /* sym_base is used to map the fdr relative indices which
1062 appear in the file to the position number which we are
1064 sym_base = ecoffsymbol (symbol)->fdr->isymBase;
1065 if (ecoffsymbol (symbol)->local)
1066 sym_base += ecoff_data (abfd)->symbolic_header.iextMax;
1068 /* aux_base is the start of the aux entries for this file;
1069 asym.index is an offset from this. */
1070 aux_base = (ecoff_data (abfd)->external_aux
1071 + ecoffsymbol (symbol)->fdr->iauxBase);
1073 /* The aux entries are stored in host byte order; the
1074 order is indicated by a bit in the fdr. */
1075 bigendian = ecoffsymbol (symbol)->fdr->fBigendian;
1077 /* This switch is basically from gcc/mips-tdump.c */
1078 switch (ecoff_ext.asym.st)
1086 printf ("\n End+1 symbol: %ld", indx + sym_base);
1090 if (ecoff_ext.asym.sc == scText
1091 || ecoff_ext.asym.sc == scInfo)
1092 printf ("\n First symbol: %ld", indx + sym_base);
1094 printf ("\n First symbol: %ld",
1095 (AUX_GET_ISYM (bigendian,
1096 &aux_base[ecoff_ext.asym.index])
1102 if (MIPS_IS_STAB (&ecoff_ext.asym))
1104 else if (ecoffsymbol (symbol)->local)
1105 printf ("\n End+1 symbol: %-7ld Type: %s",
1106 (AUX_GET_ISYM (bigendian,
1107 &aux_base[ecoff_ext.asym.index])
1109 type_to_string (abfd, aux_base, indx + 1,
1112 printf ("\n Type: %s",
1113 type_to_string (abfd, aux_base, indx, bigendian));
1118 if (!MIPS_IS_STAB (&ecoff_ext.asym))
1119 printf ("\n Type: %s",
1120 type_to_string (abfd, aux_base, indx, bigendian));
1129 /* Provided a BFD, a section and an offset into the section, calculate
1130 and return the name of the source file and the line nearest to the
1134 DEFUN (ecoff_find_nearest_line, (abfd,
1142 asection *section AND
1143 asymbol **ignore_symbols AND
1145 CONST char **filename_ptr AND
1146 CONST char **functionname_ptr AND
1147 unsigned int *retline_ptr)
1153 struct pdr_ext *pdr_ptr;
1154 struct pdr_ext *pdr_end;
1156 unsigned char *line_ptr;
1157 unsigned char *line_end;
1161 /* If we're not in the .text section, we don't have any line
1163 if (strcmp (section->name, _TEXT) != 0)
1166 /* Each file descriptor (FDR) has a memory address. Here we track
1167 down which FDR we want. The FDR's are stored in increasing
1168 memory order. If speed is ever important, this can become a
1169 binary search. We must ignore FDR's with no PDR entries; they
1170 will have the adr of the FDR before or after them. */
1171 fdr_start = ecoff_data (abfd)->fdr;
1172 fdr_end = fdr_start + ecoff_data (abfd)->symbolic_header.ifdMax;
1173 fdr_hold = (FDR *) NULL;
1174 for (fdr_ptr = fdr_start; fdr_ptr < fdr_end; fdr_ptr++)
1176 if (offset < fdr_ptr->adr)
1178 if (fdr_ptr->cpd > 0)
1181 if (fdr_hold == (FDR *) NULL)
1185 /* Each FDR has a list of procedure descriptors (PDR). PDR's also
1186 have an address, which is relative to the FDR address, and are
1187 also stored in increasing memory order. */
1188 offset -= fdr_ptr->adr;
1189 pdr_ptr = ecoff_data (abfd)->external_pdr + fdr_ptr->ipdFirst;
1190 pdr_end = pdr_ptr + fdr_ptr->cpd;
1191 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
1192 if (offset < pdr.adr)
1194 for (pdr_ptr++; pdr_ptr < pdr_end; pdr_ptr++)
1196 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
1197 if (offset < pdr.adr)
1201 /* Now we can look for the actual line number. The line numbers are
1202 stored in a very funky format, which I won't try to describe.
1203 Note that right here pdr_ptr and pdr hold the PDR *after* the one
1204 we want; we need this to compute line_end. */
1205 line_end = ecoff_data (abfd)->line;
1206 if (pdr_ptr == pdr_end)
1207 line_end += fdr_ptr->cbLineOffset + fdr_ptr->cbLine;
1209 line_end += fdr_ptr->cbLineOffset + pdr.cbLineOffset;
1211 /* Now change pdr and pdr_ptr to the one we want. */
1213 ecoff_swap_pdr_in (abfd, pdr_ptr, &pdr);
1217 line_ptr = (ecoff_data (abfd)->line
1218 + fdr_ptr->cbLineOffset
1219 + pdr.cbLineOffset);
1220 while (line_ptr < line_end)
1225 delta = *line_ptr >> 4;
1228 count = (*line_ptr & 0xf) + 1;
1232 delta = (((line_ptr[0]) & 0xff) << 8) + ((line_ptr[1]) & 0xff);
1233 if (delta >= 0x8000)
1238 if (offset < count * 4)
1240 offset -= count * 4;
1243 /* If offset is too large, this line is not interesting. */
1247 *filename_ptr = ecoff_data (abfd)->ss + fdr_ptr->issBase + fdr_ptr->rss;
1248 ecoff_swap_sym_in (abfd,
1249 (ecoff_data (abfd)->external_sym
1253 *functionname_ptr = ecoff_data (abfd)->ss + proc_sym.iss;
1254 *retline_ptr = lineno;
1258 static CONST bfd_coff_backend_data bfd_ecoff_std_swap_table = {
1259 (void (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_in */
1260 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_in */
1261 (void (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_in */
1262 (unsigned (*) PARAMS ((bfd *,PTR,int,int,PTR))) bfd_void, /* aux_out */
1263 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* sym_out */
1264 (unsigned (*) PARAMS ((bfd *,PTR,PTR))) bfd_void, /* lineno_out */
1265 ecoff_swap_reloc_out, ecoff_swap_filehdr_out, ecoff_swap_aouthdr_out,
1266 ecoff_swap_scnhdr_out,
1267 FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, true,
1268 ecoff_swap_filehdr_in, ecoff_swap_aouthdr_in, ecoff_swap_scnhdr_in,
1269 ecoff_bad_format_hook, ecoff_set_arch_mach_hook, ecoff_mkobject_hook,
1270 styp_to_sec_flags, ecoff_make_section_hook, ecoff_set_alignment_hook,
1271 ecoff_slurp_symbol_table
1274 /* Routines that need to be written. */
1275 #define ecoff_write_object_contents (boolean (*) PARAMS ((bfd *))) bfd_false
1276 #define ecoff_set_section_contents (boolean (*) PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type))) bfd_false
1277 #define ecoff_get_reloc_upper_bound (unsigned int (*) PARAMS ((bfd *, sec_ptr))) bfd_0
1278 #define ecoff_canonicalize_reloc (unsigned int (*) PARAMS ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry **))) bfd_0
1279 #define ecoff_set_arch_mach (boolean (*) PARAMS ((bfd *, enum bfd_architecture, unsigned long))) bfd_false
1280 #define ecoff_sizeof_headers (int (*) PARAMS ((bfd *, boolean))) bfd_0
1282 /* get_lineno could be written for ECOFF, but it would currently only
1283 be useful for linking ECOFF and COFF files together, which doesn't
1285 #define ecoff_get_lineno (struct lineno_cache_entry *(*)()) bfd_nullvoidptr
1287 #define ecoff_core_file_failing_command _bfd_dummy_core_file_failing_command
1288 #define ecoff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
1289 #define ecoff_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
1290 #define ecoff_slurp_armap bfd_slurp_coff_armap
1291 #define ecoff_slurp_extended_name_table _bfd_slurp_extended_name_table
1292 #define ecoff_write_armap coff_write_armap
1293 #define ecoff_truncate_arname bfd_dont_truncate_arname
1294 #define ecoff_openr_next_archived_file bfd_generic_openr_next_archived_file
1295 #define ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt
1296 #define ecoff_get_section_contents bfd_generic_get_section_contents
1297 #define ecoff_close_and_cleanup bfd_generic_close_and_cleanup
1299 #define ecoff_bfd_debug_info_start bfd_void
1300 #define ecoff_bfd_debug_info_end bfd_void
1301 #define ecoff_bfd_debug_info_accumulate \
1302 (void (*) PARAMS ((bfd *, struct sec *))) bfd_void
1303 #define ecoff_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
1304 #define ecoff_bfd_relax_section bfd_generic_relax_section
1305 #define ecoff_bfd_seclet_link bfd_generic_seclet_link
1307 bfd_target ecoff_little_vec =
1309 "ecoff-littlemips", /* name */
1310 bfd_target_ecoff_flavour,
1311 false, /* data byte order is little */
1312 false, /* header byte order is little */
1314 (HAS_RELOC | EXEC_P | /* object flags */
1315 HAS_LINENO | HAS_DEBUG |
1316 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
1318 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect
1320 0, /* leading underscore */
1321 '/', /* ar_pad_char */
1322 15, /* ar_max_namelen */
1323 3, /* minimum alignment power */
1324 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
1325 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
1327 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
1328 bfd_generic_archive_p, _bfd_dummy_target},
1329 {bfd_false, ecoff_mkobject, bfd_false, /* bfd_set_format */
1331 {bfd_false, ecoff_write_object_contents, bfd_false, bfd_false},
1334 (PTR) &bfd_ecoff_std_swap_table
1337 bfd_target ecoff_big_vec =
1339 "ecoff-bigmips", /* name */
1340 bfd_target_ecoff_flavour,
1341 true, /* data byte order is big */
1342 true, /* header byte order is big */
1344 (HAS_RELOC | EXEC_P | /* object flags */
1345 HAS_LINENO | HAS_DEBUG |
1346 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
1348 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* sect flags */
1349 0, /* leading underscore */
1350 ' ', /* ar_pad_char */
1351 16, /* ar_max_namelen */
1352 3, /* minimum alignment power */
1353 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16,
1354 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16,
1355 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
1356 bfd_generic_archive_p, _bfd_dummy_target},
1357 {bfd_false, ecoff_mkobject, bfd_false, /* bfd_set_format */
1359 {bfd_false, ecoff_write_object_contents, /* bfd_write_contents */
1360 bfd_false, bfd_false},
1363 (PTR) &bfd_ecoff_std_swap_table
1364 /* Note that there is another bfd_target just above this one. If
1365 you are adding initializers here, you should be adding them there