obj-coff.c

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

C
2,530
字号
    if (listing)      {	if (! appline)	  l += coff_line_base - 1;	listing_source_line (l);      }  }#endif  demand_empty_rest_of_line ();}/* .loc is essentially the same as .ln; parse it for assembler   compatibility.  */static voidobj_coff_loc (ignore)     int ignore ATTRIBUTE_UNUSED;{  int lineno;  /* FIXME: Why do we need this check?  We need it for ECOFF, but why     do we need it for COFF?  */  if (now_seg != text_section)    {      as_warn (_(".loc outside of .text"));      demand_empty_rest_of_line ();      return;    }  if (def_symbol_in_progress != NULL)    {      as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));      demand_empty_rest_of_line ();      return;    }  /* Skip the file number.  */  SKIP_WHITESPACE ();  get_absolute_expression ();  SKIP_WHITESPACE ();  lineno = get_absolute_expression ();#ifndef NO_LISTING  {    extern int listing;    if (listing)      {        lineno += coff_line_base - 1;	listing_source_line (lineno);      }  }#endif  demand_empty_rest_of_line ();  add_lineno (frag_now, frag_now_fix (), lineno);}/* Handle the .ident pseudo-op.  */static voidobj_coff_ident (ignore)     int ignore ATTRIBUTE_UNUSED;{  segT current_seg = now_seg;  subsegT current_subseg = now_subseg;#ifdef TE_PE  {    segT sec;    /* We could put it in .comment, but that creates an extra section       that shouldn't be loaded into memory, which requires linker       changes...  For now, until proven otherwise, use .rdata.  */    sec = subseg_new (".rdata$zzz", 0);    bfd_set_section_flags (stdoutput, sec,			   ((SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA)			    & bfd_applicable_section_flags (stdoutput)));  }#else  subseg_new (".comment", 0);#endif  stringer (1);  subseg_set (current_seg, current_subseg);}/* *			def() * * Handle .def directives. * * One might ask : why can't we symbol_new if the symbol does not * already exist and fill it with debug information.  Because of * the C_EFCN special symbol. It would clobber the value of the * function symbol before we have a chance to notice that it is * a C_EFCN. And a second reason is that the code is more clear this * way. (at least I think it is :-). * */#define SKIP_SEMI_COLON()	while (*input_line_pointer++ != ';')#define SKIP_WHITESPACES()	while (*input_line_pointer == ' ' || \				       *input_line_pointer == '\t') \    input_line_pointer++;static voidobj_coff_def (what)     int what ATTRIBUTE_UNUSED;{  char name_end;		/* Char after the end of name */  char *symbol_name;		/* Name of the debug symbol */  char *symbol_name_copy;	/* Temporary copy of the name */  unsigned int symbol_name_length;  if (def_symbol_in_progress != NULL)    {      as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));      demand_empty_rest_of_line ();      return;    }				/* if not inside .def/.endef */  SKIP_WHITESPACES ();  symbol_name = input_line_pointer;#ifdef STRIP_UNDERSCORE  if (symbol_name[0] == '_' && symbol_name[1] != 0)    symbol_name++;#endif /* STRIP_UNDERSCORE */  name_end = get_symbol_end ();  symbol_name_length = strlen (symbol_name);  symbol_name_copy = xmalloc (symbol_name_length + 1);  strcpy (symbol_name_copy, symbol_name);#ifdef tc_canonicalize_symbol_name  symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy);#endif  /* Initialize the new symbol */  def_symbol_in_progress = symbol_make (symbol_name_copy);  symbol_set_frag (def_symbol_in_progress, &zero_address_frag);  S_SET_VALUE (def_symbol_in_progress, 0);  if (S_IS_STRING (def_symbol_in_progress))    SF_SET_STRING (def_symbol_in_progress);  *input_line_pointer = name_end;  demand_empty_rest_of_line ();}unsigned int dim_index;static voidobj_coff_endef (ignore)     int ignore ATTRIBUTE_UNUSED;{  symbolS *symbolP = NULL;  /* DIM BUG FIX sac@cygnus.com */  dim_index = 0;  if (def_symbol_in_progress == NULL)    {      as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));      demand_empty_rest_of_line ();      return;    }				/* if not inside .def/.endef */  /* Set the section number according to storage class.  */  switch (S_GET_STORAGE_CLASS (def_symbol_in_progress))    {    case C_STRTAG:    case C_ENTAG:    case C_UNTAG:      SF_SET_TAG (def_symbol_in_progress);      /* intentional fallthrough */    case C_FILE:    case C_TPDEF:      SF_SET_DEBUG (def_symbol_in_progress);      S_SET_SEGMENT (def_symbol_in_progress, fetch_coff_debug_section ());      break;    case C_EFCN:      SF_SET_LOCAL (def_symbol_in_progress);	/* Do not emit this symbol.  */      /* intentional fallthrough */    case C_BLOCK:      SF_SET_PROCESS (def_symbol_in_progress);	/* Will need processing before writing */      /* intentional fallthrough */    case C_FCN:      {	CONST char *name;	S_SET_SEGMENT (def_symbol_in_progress, text_section);	name = S_GET_NAME (def_symbol_in_progress);	if (name[0] == '.' && name[2] == 'f' && name[3] == '\0')  	  {	    switch (name[1])	      {	      case 'b':		/* .bf */		if (! in_function ())		  as_warn (_("`%s' symbol without preceding function"), name);		/* Will need relocating.  */		SF_SET_PROCESS (def_symbol_in_progress);		clear_function ();		break;#ifdef TE_PE	      case 'e':		/* .ef */		/* The MS compilers output the actual endline, not the		   function-relative one... we want to match without		   changing the assembler input.  */		SA_SET_SYM_LNNO (def_symbol_in_progress,				 (SA_GET_SYM_LNNO (def_symbol_in_progress)				  + coff_line_base));		break;#endif	      }	  }      }      break;#ifdef C_AUTOARG    case C_AUTOARG:#endif /* C_AUTOARG */    case C_AUTO:    case C_REG:    case C_ARG:    case C_REGPARM:    case C_FIELD:    /* According to the COFF documentation:       http://osr5doc.sco.com:1996/topics/COFF_SectNumFld.html       A special section number (-2) marks symbolic debugging symbols,       including structure/union/enumeration tag names, typedefs, and       the name of the file. A section number of -1 indicates that the       symbol has a value but is not relocatable. Examples of       absolute-valued symbols include automatic and register variables,       function arguments, and .eos symbols.       But from Ian Lance Taylor:       http://sources.redhat.com/ml/binutils/2000-08/msg00202.html       the actual tools all marked them as section -1. So the GNU COFF       assembler follows historical COFF assemblers.       However, it causes problems for djgpp       http://sources.redhat.com/ml/binutils/2000-08/msg00210.html       By defining STRICTCOFF, a COFF port can make the assembler to       follow the documented behavior.  */#ifdef STRICTCOFF    case C_MOS:    case C_MOE:    case C_MOU:    case C_EOS:#endif      SF_SET_DEBUG (def_symbol_in_progress);      S_SET_SEGMENT (def_symbol_in_progress, absolute_section);      break;#ifndef STRICTCOFF    case C_MOS:    case C_MOE:    case C_MOU:    case C_EOS:      S_SET_SEGMENT (def_symbol_in_progress, absolute_section);      break;#endif    case C_EXT:    case C_WEAKEXT:#ifdef TE_PE    case C_NT_WEAK:#endif    case C_STAT:    case C_LABEL:      /* Valid but set somewhere else (s_comm, s_lcomm, colon) */      break;    default:    case C_USTATIC:    case C_EXTDEF:    case C_ULABEL:      as_warn (_("unexpected storage class %d"),	       S_GET_STORAGE_CLASS (def_symbol_in_progress));      break;    }				/* switch on storage class */  /* Now that we have built a debug symbol, try to find if we should     merge with an existing symbol or not.  If a symbol is C_EFCN or     absolute_section or untagged SEG_DEBUG it never merges.  We also     don't merge labels, which are in a different namespace, nor     symbols which have not yet been defined since they are typically     unique, nor do we merge tags with non-tags.  */  /* Two cases for functions.  Either debug followed by definition or     definition followed by debug.  For definition first, we will     merge the debug symbol into the definition.  For debug first, the     lineno entry MUST point to the definition function or else it     will point off into space when obj_crawl_symbol_chain() merges     the debug symbol into the real symbol.  Therefor, let's presume     the debug symbol is a real function reference.  */  /* FIXME-SOON If for some reason the definition label/symbol is     never seen, this will probably leave an undefined symbol at link     time.  */  if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN      || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL      || (!strcmp (bfd_get_section_name (stdoutput,					 S_GET_SEGMENT (def_symbol_in_progress)),		   "*DEBUG*")	  && !SF_GET_TAG (def_symbol_in_progress))      || S_GET_SEGMENT (def_symbol_in_progress) == absolute_section      || ! symbol_constant_p (def_symbol_in_progress)      || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress),                                      DO_NOT_STRIP)) == NULL      || SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP))    {      /* If it already is at the end of the symbol list, do nothing */      if (def_symbol_in_progress != symbol_lastP)        {	  symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);	  symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP,			 &symbol_lastP);        }    }  else    {      /* This symbol already exists, merge the newly created symbol	 into the old one.  This is not mandatory. The linker can	 handle duplicate symbols correctly. But I guess that it save	 a *lot* of space if the assembly file defines a lot of	 symbols. [loic] */      /* The debug entry (def_symbol_in_progress) is merged into the	 previous definition.  */      c_symbol_merge (def_symbol_in_progress, symbolP);      symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);      def_symbol_in_progress = symbolP;      if (SF_GET_FUNCTION (def_symbol_in_progress)	  || SF_GET_TAG (def_symbol_in_progress)	  || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_STAT)	{	  /* For functions, and tags, and static symbols, the symbol	     *must* be where the debug symbol appears.  Move the	     existing symbol to the current place.  */	  /* If it already is at the end of the symbol list, do nothing */	  if (def_symbol_in_progress != symbol_lastP)	    {	      symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);	      symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP, &symbol_lastP);	    }	}    }  if (SF_GET_TAG (def_symbol_in_progress))    {      symbolS *oldtag;      oldtag = symbol_find_base (S_GET_NAME (def_symbol_in_progress),				 DO_NOT_STRIP);      if (oldtag == NULL || ! SF_GET_TAG (oldtag))	tag_insert (S_GET_NAME (def_symbol_in_progress),		    def_symbol_in_progress);    }  if (SF_GET_FUNCTION (def_symbol_in_progress))    {      know (sizeof (def_symbol_in_progress) <= sizeof (long));      set_function (def_symbol_in_progress);      SF_SET_PROCESS (def_symbol_in_progress);      if (symbolP == NULL)	{	  /* That is, if this is the first time we've seen the	     function...  */	  symbol_table_insert (def_symbol_in_progress);	} /* definition follows debug */    } /* Create the line number entry pointing to the function being defined */  def_symbol_in_progress = NULL;  demand_empty_rest_of_line ();}static voidobj_coff_dim (ignore)     int ignore ATTRIBUTE_UNUSED;{  int dim_index;  if (def_symbol_in_progress == NULL)    {      as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));      demand_empty_rest_of_line ();      return;    }				/* if not inside .def/.endef */  S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);  for (dim_index = 0; dim_index < DIMNUM; dim_index++)    {      SKIP_WHITESPACES ();      SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index,			get_absolute_expression ());      switch (*input_line_pointer)	{	case ',':	  input_line_pointer++;	  break;	default:	  as_warn (_("badly formed .dim directive ignored"));	  /* intentional fallthrough */	case '\n':	case ';':	  dim_index = DIMNUM;	  break;	}    }  demand_empty_rest_of_line ();}static voidobj_coff_line (ignore)     int ignore ATTRIBUTE_UNUSED;{  int this_base;  if (def_symbol_in_progress == NULL)    {      /* Probably stabs-style line?  */      obj_coff_ln (0);      return;    }  this_base = get_absolute_expression ();  if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress)))    coff_line_base = this_base;  S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);  SA_SET_SYM_LNNO (def_symbol_in_progress, this_base);  demand_empty_rest_of_line ();#ifndef NO_LISTING  if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress)) == 0)    {      extern int listing;      if (listing)	listing_source_line ((unsigned int) this_base);    }#endif}static voidobj_coff_size (ignore)     int ignore ATTRIBUTE_UNUSED;{  if (def_symbol_in_progress == NULL)    {      as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));      demand_empty_rest_of_line ();      return;    }				/* if not inside .def/.endef */  S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);  SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ());  demand_empty_rest_of_line ();}static voidobj_coff_scl (ignore)     int ignore ATTRIBUTE_UNUSED;{  if (def_symbol_in_progress == NULL)    {      as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));      demand_empty_rest_of_line ();      return;    }				/* if not inside .def/.endef */  S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ());  demand_empty_rest_of_line ();}static voidobj_coff_tag (ignore)     int ignore ATTRIBUTE_UNUSED;{  char *symbol_name;

⌨️ 快捷键说明

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