⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linker.c

📁 基于4个mips核的noc设计
💻 C
📖 第 1 页 / 共 5 页
字号:
	  h->u.c.p =	    ((struct bfd_link_hash_common_entry *)	     bfd_hash_allocate (&info->hash->table,				sizeof (struct bfd_link_hash_common_entry)));	  if (h->u.c.p == NULL)	    return false;	  size = bfd_asymbol_value (p);	  h->u.c.size = size;	  power = bfd_log2 (size);	  if (power > 4)	    power = 4;	  h->u.c.p->alignment_power = power;	  if (p->section == bfd_com_section_ptr)	    h->u.c.p->section = bfd_make_section_old_way (symbfd, "COMMON");	  else	    h->u.c.p->section = bfd_make_section_old_way (symbfd,							  p->section->name);	  h->u.c.p->section->flags = SEC_ALLOC;	}      else	{	  /* Adjust the size of the common symbol if necessary.  This	     is how a.out works.  Object formats that require	     different semantics must implement this function	     differently.  */	  if (bfd_asymbol_value (p) > h->u.c.size)	    h->u.c.size = bfd_asymbol_value (p);	}    }  /* This archive element is not needed.  */  return true;}/* Add the symbols from an object file to the global hash table.  ABFD   is the object file.  INFO is the linker information.  SYMBOL_COUNT   is the number of symbols.  SYMBOLS is the list of symbols.  COLLECT   is true if constructors should be automatically collected by name   as is done by collect2.  */static booleangeneric_link_add_symbol_list (abfd, info, symbol_count, symbols, collect)     bfd *abfd;     struct bfd_link_info *info;     bfd_size_type symbol_count;     asymbol **symbols;     boolean collect;{  asymbol **pp, **ppend;  pp = symbols;  ppend = symbols + symbol_count;  for (; pp < ppend; pp++)    {      asymbol *p;      p = *pp;      if ((p->flags & (BSF_INDIRECT		       | BSF_WARNING		       | BSF_GLOBAL		       | BSF_CONSTRUCTOR		       | BSF_WEAK)) != 0	  || bfd_is_und_section (bfd_get_section (p))	  || bfd_is_com_section (bfd_get_section (p))	  || bfd_is_ind_section (bfd_get_section (p)))	{	  const char *name;	  const char *string;	  struct generic_link_hash_entry *h;	  name = bfd_asymbol_name (p);	  if (((p->flags & BSF_INDIRECT) != 0	       || bfd_is_ind_section (p->section))	      && pp + 1 < ppend)	    {	      pp++;	      string = bfd_asymbol_name (*pp);	    }	  else if ((p->flags & BSF_WARNING) != 0		   && pp + 1 < ppend)	    {	      /* The name of P is actually the warning string, and the		 next symbol is the one to warn about.  */	      string = name;	      pp++;	      name = bfd_asymbol_name (*pp);	    }	  else	    string = NULL;	  h = NULL;	  if (! (_bfd_generic_link_add_one_symbol		 (info, abfd, name, p->flags, bfd_get_section (p),		  p->value, string, false, collect,		  (struct bfd_link_hash_entry **) &h)))	    return false;	  /* If this is a constructor symbol, and the linker didn't do             anything with it, then we want to just pass the symbol             through to the output file.  This will happen when             linking with -r.  */	  if ((p->flags & BSF_CONSTRUCTOR) != 0	      && (h == NULL || h->root.type == bfd_link_hash_new))	    {	      p->udata.p = NULL;	      continue;	    }	  /* Save the BFD symbol so that we don't lose any backend	     specific information that may be attached to it.  We only	     want this one if it gives more information than the	     existing one; we don't want to replace a defined symbol	     with an undefined one.  This routine may be called with a	     hash table other than the generic hash table, so we only	     do this if we are certain that the hash table is a	     generic one.  */	  if (info->hash->creator == abfd->xvec)	    {	      if (h->sym == (asymbol *) NULL		  || (! bfd_is_und_section (bfd_get_section (p))		      && (! bfd_is_com_section (bfd_get_section (p))			  || bfd_is_und_section (bfd_get_section (h->sym)))))		{		  h->sym = p;		  /* BSF_OLD_COMMON is a hack to support COFF reloc		     reading, and it should go away when the COFF		     linker is switched to the new version.  */		  if (bfd_is_com_section (bfd_get_section (p)))		    p->flags |= BSF_OLD_COMMON;		}	    }	  /* Store a back pointer from the symbol to the hash	     table entry for the benefit of relaxation code until	     it gets rewritten to not use asymbol structures.	     Setting this is also used to check whether these	     symbols were set up by the generic linker.  */	  p->udata.p = (PTR) h;	}    }  return true;}/* We use a state table to deal with adding symbols from an object   file.  The first index into the state table describes the symbol   from the object file.  The second index into the state table is the   type of the symbol in the hash table.  *//* The symbol from the object file is turned into one of these row   values.  */enum link_row{  UNDEF_ROW,		/* Undefined.  */  UNDEFW_ROW,		/* Weak undefined.  */  DEF_ROW,		/* Defined.  */  DEFW_ROW,		/* Weak defined.  */  COMMON_ROW,		/* Common.  */  INDR_ROW,		/* Indirect.  */  WARN_ROW,		/* Warning.  */  SET_ROW		/* Member of set.  */};/* apparently needed for Hitachi 3050R(HI-UX/WE2)? */#undef FAIL/* The actions to take in the state table.  */enum link_action{  FAIL,		/* Abort.  */  UND,		/* Mark symbol undefined.  */  WEAK,		/* Mark symbol weak undefined.  */  DEF,		/* Mark symbol defined.  */  DEFW,		/* Mark symbol weak defined.  */  COM,		/* Mark symbol common.  */  REF,		/* Mark defined symbol referenced.  */  CREF,		/* Possibly warn about common reference to defined symbol.  */  CDEF,		/* Define existing common symbol.  */  NOACT,	/* No action.  */  BIG,		/* Mark symbol common using largest size.  */  MDEF,		/* Multiple definition error.  */  MIND,		/* Multiple indirect symbols.  */  IND,		/* Make indirect symbol.  */  CIND,		/* Make indirect symbol from existing common symbol.  */  SET,		/* Add value to set.  */  MWARN,	/* Make warning symbol.  */  WARN,		/* Issue warning.  */  CWARN,	/* Warn if referenced, else MWARN.  */  CYCLE,	/* Repeat with symbol pointed to.  */  REFC,		/* Mark indirect symbol referenced and then CYCLE.  */  WARNC		/* Issue warning and then CYCLE.  */};/* The state table itself.  The first index is a link_row and the   second index is a bfd_link_hash_type.  */static const enum link_action link_action[8][8] ={  /* current\prev    new    undef  undefw def    defw   com    indr   warn  */  /* UNDEF_ROW 	*/  {UND,   NOACT, UND,   REF,   REF,   NOACT, REFC,  WARNC },  /* UNDEFW_ROW	*/  {WEAK,  NOACT, NOACT, REF,   REF,   NOACT, REFC,  WARNC },  /* DEF_ROW 	*/  {DEF,   DEF,   DEF,   MDEF,  DEF,   CDEF,  MDEF,  CYCLE },  /* DEFW_ROW 	*/  {DEFW,  DEFW,  DEFW,  NOACT, NOACT, NOACT, NOACT, CYCLE },  /* COMMON_ROW	*/  {COM,   COM,   COM,   CREF,  CREF,  BIG,   REFC,  WARNC },  /* INDR_ROW	*/  {IND,   IND,   IND,   MDEF,  IND,   CIND,  MIND,  CYCLE },  /* WARN_ROW   */  {MWARN, WARN,  WARN,  CWARN, CWARN, WARN,  CWARN, MWARN },  /* SET_ROW	*/  {SET,   SET,   SET,   SET,   SET,   SET,   CYCLE, CYCLE }};/* Most of the entries in the LINK_ACTION table are straightforward,   but a few are somewhat subtle.   A reference to an indirect symbol (UNDEF_ROW/indr or   UNDEFW_ROW/indr) is counted as a reference both to the indirect   symbol and to the symbol the indirect symbol points to.   A reference to a warning symbol (UNDEF_ROW/warn or UNDEFW_ROW/warn)   causes the warning to be issued.   A common definition of an indirect symbol (COMMON_ROW/indr) is   treated as a multiple definition error.  Likewise for an indirect   definition of a common symbol (INDR_ROW/com).   An indirect definition of a warning (INDR_ROW/warn) does not cause   the warning to be issued.   If a warning is created for an indirect symbol (WARN_ROW/indr) no   warning is created for the symbol the indirect symbol points to.   Adding an entry to a set does not count as a reference to a set,   and no warning is issued (SET_ROW/warn).  *//* Return the BFD in which a hash entry has been defined, if known.  */static bfd *hash_entry_bfd (h)     struct bfd_link_hash_entry *h;{  while (h->type == bfd_link_hash_warning)    h = h->u.i.link;  switch (h->type)    {    default:      return NULL;    case bfd_link_hash_undefined:    case bfd_link_hash_undefweak:      return h->u.undef.abfd;    case bfd_link_hash_defined:    case bfd_link_hash_defweak:      return h->u.def.section->owner;    case bfd_link_hash_common:      return h->u.c.p->section->owner;    }  /*NOTREACHED*/}/* Add a symbol to the global hash table.   ABFD is the BFD the symbol comes from.   NAME is the name of the symbol.   FLAGS is the BSF_* bits associated with the symbol.   SECTION is the section in which the symbol is defined; this may be     bfd_und_section_ptr or bfd_com_section_ptr.   VALUE is the value of the symbol, relative to the section.   STRING is used for either an indirect symbol, in which case it is     the name of the symbol to indirect to, or a warning symbol, in     which case it is the warning string.   COPY is true if NAME or STRING must be copied into locally     allocated memory if they need to be saved.   COLLECT is true if we should automatically collect gcc constructor     or destructor names as collect2 does.   HASHP, if not NULL, is a place to store the created hash table     entry; if *HASHP is not NULL, the caller has already looked up     the hash table entry, and stored it in *HASHP.  */boolean_bfd_generic_link_add_one_symbol (info, abfd, name, flags, section, value,				  string, copy, collect, hashp)     struct bfd_link_info *info;     bfd *abfd;     const char *name;     flagword flags;     asection *section;     bfd_vma value;     const char *string;     boolean copy;     boolean collect;     struct bfd_link_hash_entry **hashp;{  enum link_row row;  struct bfd_link_hash_entry *h;  boolean cycle;  if (bfd_is_ind_section (section)      || (flags & BSF_INDIRECT) != 0)    row = INDR_ROW;  else if ((flags & BSF_WARNING) != 0)    row = WARN_ROW;  else if ((flags & BSF_CONSTRUCTOR) != 0)    row = SET_ROW;  else if (bfd_is_und_section (section))    {      if ((flags & BSF_WEAK) != 0)	row = UNDEFW_ROW;      else	row = UNDEF_ROW;    }  else if ((flags & BSF_WEAK) != 0)    row = DEFW_ROW;  else if (bfd_is_com_section (section))    row = COMMON_ROW;  else    row = DEF_ROW;  if (hashp != NULL && *hashp != NULL)    h = *hashp;  else    {      if (row == UNDEF_ROW || row == UNDEFW_ROW)	h = bfd_wrapped_link_hash_lookup (abfd, info, name, true, copy, false);      else	h = bfd_link_hash_lookup (info->hash, name, true, copy, false);      if (h == NULL)	{	  if (hashp != NULL)	    *hashp = NULL;	  return false;	}    }  if (info->notice_all      || (info->notice_hash != (struct bfd_hash_table *) NULL	  && (bfd_hash_lookup (info->notice_hash, name, false, false)	      != (struct bfd_hash_entry *) NULL)))    {      if (! (*info->callbacks->notice) (info, h->root.string, abfd, section,					value))	return false;    }  if (hashp != (struct bfd_link_hash_entry **) NULL)    *hashp = h;  do    {      enum link_action action;      cycle = false;      action = link_action[(int) row][(int) h->type];      switch (action)	{	case FAIL:	  abort ();	case NOACT:	  /* Do nothing.  */	  break;	case UND:	  /* Make a new undefined symbol.  */	  h->type = bfd_link_hash_undefined;	  h->u.undef.abfd = abfd;	  bfd_link_add_undef (info->hash, h);	  break;	case WEAK:	  /* Make a new weak undefined symbol.  */	  h->type = bfd_link_hash_undefweak;	  h->u.undef.abfd = abfd;	  break;	case CDEF:	  /* We have found a definition for a symbol which was	     previously common.  */	  BFD_ASSERT (h->type == bfd_link_hash_common);	  if (! ((*info->callbacks->multiple_common)		 (info, h->root.string,		  h->u.c.p->section->owner, bfd_link_hash_common, h->u.c.size,		  abfd, bfd_link_hash_defined, (bfd_vma) 0)))	    return false;	  /* Fall through.  */	case DEF:	case DEFW:	  {	    enum bfd_link_hash_type oldtype;	    /* Define a symbol.  */	    oldtype = h->type;	    if (action == DEFW)	      h->type = bfd_link_hash_defweak;	    else

⌨️ 快捷键说明

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