syms.c

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

C
1,302
字号
	Print the value and flags of the @var{symbol} supplied to the	stream @var{file}.*/voidbfd_print_symbol_vandf (arg, symbol)     PTR arg;     asymbol *symbol;{  FILE *file = (FILE *) arg;  flagword type = symbol->flags;  if (symbol->section != (asection *) NULL)    {      fprintf_vma (file, symbol->value + symbol->section->vma);    }  else    {      fprintf_vma (file, symbol->value);    }  /* This presumes that a symbol can not be both BSF_DEBUGGING and     BSF_DYNAMIC, nor more than one of BSF_FUNCTION, BSF_FILE, and     BSF_OBJECT.  */  fprintf (file, " %c%c%c%c%c%c%c",	   ((type & BSF_LOCAL)	    ? (type & BSF_GLOBAL) ? '!' : 'l'	    : (type & BSF_GLOBAL) ? 'g' : ' '),	   (type & BSF_WEAK) ? 'w' : ' ',	   (type & BSF_CONSTRUCTOR) ? 'C' : ' ',	   (type & BSF_WARNING) ? 'W' : ' ',	   (type & BSF_INDIRECT) ? 'I' : ' ',	   (type & BSF_DEBUGGING) ? 'd' : (type & BSF_DYNAMIC) ? 'D' : ' ',	   ((type & BSF_FUNCTION)	    ? 'F'	    : ((type & BSF_FILE)	       ? 'f'	       : ((type & BSF_OBJECT) ? 'O' : ' '))));}/*FUNCTION	bfd_make_empty_symbolDESCRIPTION	Create a new <<asymbol>> structure for the BFD @var{abfd}	and return a pointer to it.	This routine is necessary because each back end has private	information surrounding the <<asymbol>>. Building your own	<<asymbol>> and pointing to it will not create the private	information, and will cause problems later on..#define bfd_make_empty_symbol(abfd) \.     BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))*//*FUNCTION	bfd_make_debug_symbolDESCRIPTION	Create a new <<asymbol>> structure for the BFD @var{abfd},	to be used as a debugging symbol.  Further details of its use have	yet to be worked out..#define bfd_make_debug_symbol(abfd,ptr,size) \.        BFD_SEND (abfd, _bfd_make_debug_symbol, (abfd, ptr, size))*/struct section_to_type{  CONST char *section;  char type;};/* Map section names to POSIX/BSD single-character symbol types.   This table is probably incomplete.  It is sorted for convenience of   adding entries.  Since it is so short, a linear search is used.  */static CONST struct section_to_type stt[] ={  {"*DEBUG*", 'N'},  {".bss", 'b'},  {"zerovars", 'b'},		/* MRI .bss */  {".data", 'd'},  {"vars", 'd'},		/* MRI .data */  {".rdata", 'r'},		/* Read only data.  */  {".rodata", 'r'},		/* Read only data.  */  {".sbss", 's'},		/* Small BSS (uninitialized data).  */  {".scommon", 'c'},		/* Small common.  */  {".sdata", 'g'},		/* Small initialized data.  */  {".text", 't'},  {"code", 't'},		/* MRI .text */  {".drectve", 'i'},            /* MSVC's .drective section */  {".idata", 'i'},              /* MSVC's .idata (import) section */  {".edata", 'e'},              /* MSVC's .edata (export) section */  {".pdata", 'p'},              /* MSVC's .pdata (stack unwind) section */  {".debug", 'N'},              /* MSVC's .debug (non-standard debug syms) */  {0, 0}};/* Return the single-character symbol type corresponding to   section S, or '?' for an unknown COFF section.   Check for any leading string which matches, so .text5 returns   't' as well as .text */static charcoff_section_type (s)     const char *s;{  CONST struct section_to_type *t;  for (t = &stt[0]; t->section; t++)    if (!strncmp (s, t->section, strlen (t->section)))      return t->type;  return '?';}#ifndef islower#define islower(c) ((c) >= 'a' && (c) <= 'z')#endif#ifndef toupper#define toupper(c) (islower(c) ? ((c) & ~0x20) : (c))#endif/*FUNCTION	bfd_decode_symclassDESCRIPTION	Return a character corresponding to the symbol	class of @var{symbol}, or '?' for an unknown class.SYNOPSIS	int bfd_decode_symclass(asymbol *symbol);*/intbfd_decode_symclass (symbol)     asymbol *symbol;{  char c;  if (bfd_is_com_section (symbol->section))    return 'C';  if (bfd_is_und_section (symbol->section))    {      if (symbol->flags & BSF_WEAK)	{	  /* If weak, determine if it's specifically an object	     or non-object weak.  */	  if (symbol->flags & BSF_OBJECT)	    return 'v';	  else	    return 'w';	}      else	return 'U';    }  if (bfd_is_ind_section (symbol->section))    return 'I';  if (symbol->flags & BSF_WEAK)    {      /* If weak, determine if it's specifically an object	 or non-object weak.  */      if (symbol->flags & BSF_OBJECT)	return 'V';      else	return 'W';    }  if (!(symbol->flags & (BSF_GLOBAL | BSF_LOCAL)))    return '?';  if (bfd_is_abs_section (symbol->section))    c = 'a';  else if (symbol->section)    c = coff_section_type (symbol->section->name);  else    return '?';  if (symbol->flags & BSF_GLOBAL)    c = toupper (c);  return c;  /* We don't have to handle these cases just yet, but we will soon:     N_SETV: 'v';     N_SETA: 'l';     N_SETT: 'x';     N_SETD: 'z';     N_SETB: 's';     N_INDR: 'i';     */}/*FUNCTION	bfd_is_undefined_symclassDESCRIPTION	Returns non-zero if the class symbol returned by	bfd_decode_symclass represents an undefined symbol.	Returns zero otherwise.SYNOPSIS	boolean bfd_is_undefined_symclass (int symclass);*/booleanbfd_is_undefined_symclass (symclass)     int symclass;{  return symclass == 'U' || symclass == 'w' || symclass == 'v';}/*FUNCTION	bfd_symbol_infoDESCRIPTION	Fill in the basic info about symbol that nm needs.	Additional info may be added by the back-ends after	calling this function.SYNOPSIS	void bfd_symbol_info(asymbol *symbol, symbol_info *ret);*/voidbfd_symbol_info (symbol, ret)     asymbol *symbol;     symbol_info *ret;{  ret->type = bfd_decode_symclass (symbol);  if (bfd_is_undefined_symclass (ret->type))    ret->value = 0;  else    ret->value = symbol->value + symbol->section->vma;  ret->name = symbol->name;}/*FUNCTION	bfd_copy_private_symbol_dataSYNOPSIS	boolean bfd_copy_private_symbol_data(bfd *ibfd, asymbol *isym, bfd *obfd, asymbol *osym);DESCRIPTION	Copy private symbol information from @var{isym} in the BFD	@var{ibfd} to the symbol @var{osym} in the BFD @var{obfd}.	Return <<true>> on success, <<false>> on error.  Possible error	returns are:	o <<bfd_error_no_memory>> -	Not enough memory exists to create private data for @var{osec}..#define bfd_copy_private_symbol_data(ibfd, isymbol, obfd, osymbol) \.     BFD_SEND (obfd, _bfd_copy_private_symbol_data, \.		(ibfd, isymbol, obfd, osymbol))*//* The generic version of the function which returns mini symbols.   This is used when the backend does not provide a more efficient   version.  It just uses BFD asymbol structures as mini symbols.  */long_bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep)     bfd *abfd;     boolean dynamic;     PTR *minisymsp;     unsigned int *sizep;{  long storage;  asymbol **syms = NULL;  long symcount;  if (dynamic)    storage = bfd_get_dynamic_symtab_upper_bound (abfd);  else    storage = bfd_get_symtab_upper_bound (abfd);  if (storage < 0)    goto error_return;  syms = (asymbol **) bfd_malloc ((size_t) storage);  if (syms == NULL)    goto error_return;  if (dynamic)    symcount = bfd_canonicalize_dynamic_symtab (abfd, syms);  else    symcount = bfd_canonicalize_symtab (abfd, syms);  if (symcount < 0)    goto error_return;  *minisymsp = (PTR) syms;  *sizep = sizeof (asymbol *);  return symcount; error_return:  if (syms != NULL)    free (syms);  return -1;}/* The generic version of the function which converts a minisymbol to   an asymbol.  We don't worry about the sym argument we are passed;   we just return the asymbol the minisymbol points to.  *//*ARGSUSED*/asymbol *_bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym)     bfd *abfd ATTRIBUTE_UNUSED;     boolean dynamic ATTRIBUTE_UNUSED;     const PTR minisym;     asymbol *sym ATTRIBUTE_UNUSED;{  return *(asymbol **) minisym;}/* Look through stabs debugging information in .stab and .stabstr   sections to find the source file and line closest to a desired   location.  This is used by COFF and ELF targets.  It sets *pfound   to true if it finds some information.  The *pinfo field is used to   pass cached information in and out of this routine; this first time   the routine is called for a BFD, *pinfo should be NULL.  The value   placed in *pinfo should be saved with the BFD, and passed back each   time this function is called.  *//* We use a cache by default.  */#define ENABLE_CACHING/* We keep an array of indexentry structures to record where in the   stabs section we should look to find line number information for a   particular address.  */struct indexentry{  bfd_vma val;  bfd_byte *stab;  bfd_byte *str;  char *directory_name;  char *file_name;  char *function_name;};/* Compare two indexentry structures.  This is called via qsort.  */static intcmpindexentry (a, b)     const PTR a;     const PTR b;{  const struct indexentry *contestantA = (const struct indexentry *) a;  const struct indexentry *contestantB = (const struct indexentry *) b;  if (contestantA->val < contestantB->val)    return -1;  else if (contestantA->val > contestantB->val)    return 1;  else    return 0;}/* A pointer to this structure is stored in *pinfo.  */struct stab_find_info{  /* The .stab section.  */  asection *stabsec;  /* The .stabstr section.  */  asection *strsec;  /* The contents of the .stab section.  */  bfd_byte *stabs;  /* The contents of the .stabstr section.  */  bfd_byte *strs;  /* A table that indexes stabs by memory address.  */  struct indexentry *indextable;  /* The number of entries in indextable.  */  int indextablesize;#ifdef ENABLE_CACHING  /* Cached values to restart quickly.  */  struct indexentry *cached_indexentry;  bfd_vma cached_offset;  bfd_byte *cached_stab;  char *cached_file_name;#endif  /* Saved ptr to malloc'ed filename.  */  char *filename;};boolean_bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, pfound,				     pfilename, pfnname, pline, pinfo)     bfd *abfd;     asymbol **symbols;     asection *section;     bfd_vma offset;     boolean *pfound;     const char **pfilename;     const char **pfnname;     unsigned int *pline;     PTR *pinfo;{  struct stab_find_info *info;  bfd_size_type stabsize, strsize;  bfd_byte *stab, *str;  bfd_byte *last_stab = NULL;  bfd_size_type stroff;  struct indexentry *indexentry;  char *directory_name, *file_name;  int saw_fun;  *pfound = false;  *pfilename = bfd_get_filename (abfd);  *pfnname = NULL;  *pline = 0;  /* Stabs entries use a 12 byte format:       4 byte string table index       1 byte stab type       1 byte stab other field       2 byte stab desc field       4 byte stab value     FIXME: This will have to change for a 64 bit object format.     The stabs symbols are divided into compilation units.  For the     first entry in each unit, the type of 0, the value is the length     of the string table for this unit, and the desc field is the     number of stabs symbols for this unit.  */

⌨️ 快捷键说明

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