ecoff.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,282 行 · 第 1/5 页

C
2,282
字号
		AUX_GET_WIDTH (bigendian, &aux_ptr[indx+4]);	      indx += 5;	    }	}      /*       * Now print out the qualifiers.       */      for (i = 0; i < 6; i++)	{	  switch (qualifiers[i].type)	    {	    case tqNil:	    case tqMax:	      break;	    case tqPtr:	      strcpy (p2, "ptr to ");	      p2 += sizeof ("ptr to ")-1;	      break;	    case tqVol:	      strcpy (p2, "volatile ");	      p2 += sizeof ("volatile ")-1;	      break;	    case tqFar:	      strcpy (p2, "far ");	      p2 += sizeof ("far ")-1;	      break;	    case tqProc:	      strcpy (p2, "func. ret. ");	      p2 += sizeof ("func. ret. ");	      break;	    case tqArray:	      {		int first_array = i;		int j;		/* Print array bounds reversed (ie, in the order the C		   programmer writes them).  C is such a fun language....  */		while (i < 5 && qualifiers[i+1].type == tqArray)		  i++;		for (j = i; j >= first_array; j--)		  {		    strcpy (p2, "array [");		    p2 += sizeof ("array [")-1;		    if (qualifiers[j].low_bound != 0)		      sprintf (p2,			       "%ld:%ld {%ld bits}",			       (long) qualifiers[j].low_bound,			       (long) qualifiers[j].high_bound,			       (long) qualifiers[j].stride);		    else if (qualifiers[j].high_bound != -1)		      sprintf (p2,			       "%ld {%ld bits}",			       (long) (qualifiers[j].high_bound + 1),			       (long) (qualifiers[j].stride));		    else		      sprintf (p2, " {%ld bits}", (long) (qualifiers[j].stride));		    p2 += strlen (p2);		    strcpy (p2, "] of ");		    p2 += sizeof ("] of ")-1;		  }	      }	      break;	    }	}    }  strcpy (p2, buffer1);  return buffer2;}/* Return information about ECOFF symbol SYMBOL in RET.  */void_bfd_ecoff_get_symbol_info (abfd, symbol, ret)     bfd *abfd ATTRIBUTE_UNUSED;     asymbol *symbol;     symbol_info *ret;{  bfd_symbol_info (symbol, ret);}/* Return whether this is a local label.  */boolean_bfd_ecoff_bfd_is_local_label_name (abfd, name)     bfd *abfd ATTRIBUTE_UNUSED;     const char *name;{  return name[0] == '$';}/* Print information about an ECOFF symbol.  */void_bfd_ecoff_print_symbol (abfd, filep, symbol, how)     bfd *abfd;     PTR filep;     asymbol *symbol;     bfd_print_symbol_type how;{  const struct ecoff_debug_swap * const debug_swap    = &ecoff_backend (abfd)->debug_swap;  FILE *file = (FILE *)filep;  switch (how)    {    case bfd_print_symbol_name:      fprintf (file, "%s", symbol->name);      break;    case bfd_print_symbol_more:      if (ecoffsymbol (symbol)->local)	{	  SYMR ecoff_sym;	  (*debug_swap->swap_sym_in) (abfd, ecoffsymbol (symbol)->native,				      &ecoff_sym);	  fprintf (file, "ecoff local ");	  fprintf_vma (file, (bfd_vma) ecoff_sym.value);	  fprintf (file, " %x %x", (unsigned) ecoff_sym.st,		   (unsigned) ecoff_sym.sc);	}      else	{	  EXTR ecoff_ext;	  (*debug_swap->swap_ext_in) (abfd, ecoffsymbol (symbol)->native,				      &ecoff_ext);	  fprintf (file, "ecoff extern ");	  fprintf_vma (file, (bfd_vma) ecoff_ext.asym.value);	  fprintf (file, " %x %x", (unsigned) ecoff_ext.asym.st,		   (unsigned) ecoff_ext.asym.sc);	}      break;    case bfd_print_symbol_all:      /* Print out the symbols in a reasonable way */      {	char type;	int pos;	EXTR ecoff_ext;	char jmptbl;	char cobol_main;	char weakext;	if (ecoffsymbol (symbol)->local)	  {	    (*debug_swap->swap_sym_in) (abfd, ecoffsymbol (symbol)->native,					&ecoff_ext.asym);	    type = 'l';	    pos = ((((char *) ecoffsymbol (symbol)->native		     - (char *) ecoff_data (abfd)->debug_info.external_sym)		    / debug_swap->external_sym_size)		   + ecoff_data (abfd)->debug_info.symbolic_header.iextMax);	    jmptbl = ' ';	    cobol_main = ' ';	    weakext = ' ';	  }	else	  {	    (*debug_swap->swap_ext_in) (abfd, ecoffsymbol (symbol)->native,					&ecoff_ext);	    type = 'e';	    pos = (((char *) ecoffsymbol (symbol)->native		    - (char *) ecoff_data (abfd)->debug_info.external_ext)		   / debug_swap->external_ext_size);	    jmptbl = ecoff_ext.jmptbl ? 'j' : ' ';	    cobol_main = ecoff_ext.cobol_main ? 'c' : ' ';	    weakext = ecoff_ext.weakext ? 'w' : ' ';	  }	fprintf (file, "[%3d] %c ",		 pos, type);	fprintf_vma (file, (bfd_vma) ecoff_ext.asym.value);	fprintf (file, " st %x sc %x indx %x %c%c%c %s",		 (unsigned) ecoff_ext.asym.st,		 (unsigned) ecoff_ext.asym.sc,		 (unsigned) ecoff_ext.asym.index,		 jmptbl, cobol_main, weakext,		 symbol->name);	if (ecoffsymbol (symbol)->fdr != NULL	    && ecoff_ext.asym.index != indexNil)	  {	    FDR *fdr;	    unsigned int indx;	    int bigendian;	    bfd_size_type sym_base;	    union aux_ext *aux_base;	    fdr = ecoffsymbol (symbol)->fdr;	    indx = ecoff_ext.asym.index;	    /* sym_base is used to map the fdr relative indices which	       appear in the file to the position number which we are	       using.  */	    sym_base = fdr->isymBase;	    if (ecoffsymbol (symbol)->local)	      sym_base +=		ecoff_data (abfd)->debug_info.symbolic_header.iextMax;	    /* aux_base is the start of the aux entries for this file;	       asym.index is an offset from this.  */	    aux_base = (ecoff_data (abfd)->debug_info.external_aux			+ fdr->iauxBase);	    /* The aux entries are stored in host byte order; the	       order is indicated by a bit in the fdr.  */	    bigendian = fdr->fBigendian;	    /* This switch is basically from gcc/mips-tdump.c  */	    switch (ecoff_ext.asym.st)	      {	      case stNil:	      case stLabel:		break;	      case stFile:	      case stBlock:		fprintf (file, _("\n      End+1 symbol: %ld"),			 (long) (indx + sym_base));		break;	      case stEnd:		if (ecoff_ext.asym.sc == scText		    || ecoff_ext.asym.sc == scInfo)		  fprintf (file, _("\n      First symbol: %ld"),			   (long) (indx + sym_base));		else		  fprintf (file, _("\n      First symbol: %ld"),			   ((long)			    (AUX_GET_ISYM (bigendian,					   &aux_base[ecoff_ext.asym.index])			     + sym_base)));		break;	      case stProc:	      case stStaticProc:		if (ECOFF_IS_STAB (&ecoff_ext.asym))		  ;		else if (ecoffsymbol (symbol)->local)		  fprintf (file, _("\n      End+1 symbol: %-7ld   Type:  %s"),			   ((long)			    (AUX_GET_ISYM (bigendian,					   &aux_base[ecoff_ext.asym.index])			     + sym_base)),			   ecoff_type_to_string (abfd, fdr, indx + 1));		else		  fprintf (file, _("\n      Local symbol: %ld"),			   ((long) indx			    + (long) sym_base			    + (ecoff_data (abfd)			       ->debug_info.symbolic_header.iextMax)));		break;	      case stStruct:		fprintf (file, _("\n      struct; End+1 symbol: %ld"),			 (long) (indx + sym_base));		break;	      case stUnion:		fprintf (file, _("\n      union; End+1 symbol: %ld"),			 (long) (indx + sym_base));		break;	      case stEnum:		fprintf (file, _("\n      enum; End+1 symbol: %ld"),			 (long) (indx + sym_base));		break;	      default:		if (! ECOFF_IS_STAB (&ecoff_ext.asym))		  fprintf (file, _("\n      Type: %s"),			   ecoff_type_to_string (abfd, fdr, indx));		break;	      }	  }      }      break;    }}/* Read in the relocs for a section.  */static booleanecoff_slurp_reloc_table (abfd, section, symbols)     bfd *abfd;     asection *section;     asymbol **symbols;{  const struct ecoff_backend_data * const backend = ecoff_backend (abfd);  arelent *internal_relocs;  bfd_size_type external_reloc_size;  bfd_size_type external_relocs_size;  char *external_relocs;  arelent *rptr;  unsigned int i;  if (section->relocation != (arelent *) NULL      || section->reloc_count == 0      || (section->flags & SEC_CONSTRUCTOR) != 0)    return true;  if (_bfd_ecoff_slurp_symbol_table (abfd) == false)    return false;  internal_relocs = (arelent *) bfd_alloc (abfd,					   (sizeof (arelent)					    * section->reloc_count));  external_reloc_size = backend->external_reloc_size;  external_relocs_size = external_reloc_size * section->reloc_count;  external_relocs = (char *) bfd_alloc (abfd, external_relocs_size);  if (internal_relocs == (arelent *) NULL      || external_relocs == (char *) NULL)    return false;  if (bfd_seek (abfd, section->rel_filepos, SEEK_SET) != 0)    return false;  if (bfd_read (external_relocs, 1, external_relocs_size, abfd)      != external_relocs_size)    return false;  for (i = 0, rptr = internal_relocs; i < section->reloc_count; i++, rptr++)    {      struct internal_reloc intern;      (*backend->swap_reloc_in) (abfd,				 external_relocs + i * external_reloc_size,				 &intern);      if (intern.r_extern)	{	  /* r_symndx is an index into the external symbols.  */	  BFD_ASSERT (intern.r_symndx >= 0		      && (intern.r_symndx			  < (ecoff_data (abfd)			     ->debug_info.symbolic_header.iextMax)));	  rptr->sym_ptr_ptr = symbols + intern.r_symndx;	  rptr->addend = 0;	}      else if (intern.r_symndx == RELOC_SECTION_NONE	       || intern.r_symndx == RELOC_SECTION_ABS)	{	  rptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;	  rptr->addend = 0;	}      else	{	  CONST char *sec_name;	  asection *sec;	  /* r_symndx is a section key.  */	  switch (intern.r_symndx)	    {	    case RELOC_SECTION_TEXT:  sec_name = ".text";  break;	    case RELOC_SECTION_RDATA: sec_name = ".rdata"; break;	    case RELOC_SECTION_DATA:  sec_name = ".data";  break;	    case RELOC_SECTION_SDATA: sec_name = ".sdata"; break;	    case RELOC_SECTION_SBSS:  sec_name = ".sbss";  break;	    case RELOC_SECTION_BSS:   sec_name = ".bss";   break;	    case RELOC_SECTION_INIT:  sec_name = ".init";  break;	    case RELOC_SECTION_LIT8:  sec_name = ".lit8";  break;	    case RELOC_SECTION_LIT4:  sec_name = ".lit4";  break;	    case RELOC_SECTION_XDATA: sec_name = ".xdata"; break;	    case RELOC_SECTION_PDATA: sec_name = ".pdata"; break;	    case RELOC_SECTION_FINI:  sec_name = ".fini"; break;	    case RELOC_SECTION_LITA:  sec_name = ".lita";  break;	    case RELOC_SECTION_RCONST: sec_name = ".rconst"; break;	    default: abort ();	    }	  sec = bfd_get_section_by_name (abfd, sec_name);	  if (sec == (asection *) NULL)	    abort ();	  rptr->sym_ptr_ptr = sec->symbol_ptr_ptr;	  rptr->addend = - bfd_get_section_vma (abfd, sec);	}      rptr->address = intern.r_vaddr - bfd_get_section_vma (abfd, section);      /* Let the backend select the howto field and do any other	 required processing.  */      (*backend->adjust_reloc_in) (abfd, &intern, rptr);    }  bfd_release (abfd, external_relocs);  section->relocation = internal_relocs;  return true;}/* Get a canonical list of relocs.  */long_bfd_ecoff_canonicalize_reloc (abfd, section, relptr, symbols)     bfd *abfd;     asection *section;     arelent **relptr;     asymbol **symbols;{  unsigned int count;  if (section->flags & SEC_CONSTRUCTOR)    {      arelent_chain *chain;      /* This section has relocs made up by us, not the file, so take	 them out of their chain and place them into the data area	 provided.  */      for (count = 0, chain = section->constructor_chain;	   count < section->reloc_count;	   count++, chain = chain->next)	*relptr++ = &chain->relent;    }  else    {      arelent *tblptr;      if (ecoff_slurp_reloc_table (abfd, section, symbols) == false)	return -1;      tblptr = section->relocation;      for (count = 0; count < section->reloc_count; count++)	*relptr++ = tblptr++;    }  *relptr = (arelent *) NULL;  return section->reloc_count;}/* Provided a BFD, a section and an offset into the section, calculate   and return the name of the source file and the line nearest to the   wanted location.  */boolean_bfd_ecoff_find_nearest_line (abfd, section, ignore_symbols, offset,			      filename_ptr, functionname_ptr, retline_ptr)     bfd *abfd;     asection *section;     asymbol **ignore_symbols ATTRIBUTE_UNUSED;     bfd_vma offset;     CONST char **filename_ptr;     CONST char **functionname_ptr;     unsigned int *retline_ptr;{

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?