elf32.em

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

EM
1,533
字号
gld${EMULATION_NAME}_check_needed (s)     lang_input_statement_type *s;{  if (global_found)    return;  if (s->filename != NULL)    {      const char *f;      if (strcmp (s->filename, global_needed->name) == 0)	{	  global_found = true;	  return;	}      if (s->search_dirs_flag)	{	  f = strrchr (s->filename, '/');	  if (f != NULL	      && strcmp (f + 1, global_needed->name) == 0)	    {	      global_found = true;	      return;	    }	}    }  if (s->the_bfd != NULL)    {      const char *soname;      soname = bfd_elf_get_dt_soname (s->the_bfd);      if (soname != NULL	  && strcmp (soname, global_needed->name) == 0)	{	  global_found = true;	  return;	}    }}EOFif test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; thencat >>e${EMULATION_NAME}.c <<EOF/* This is called after all the input files have been opened.  */static voidgld${EMULATION_NAME}_after_open (){  struct bfd_link_needed_list *needed, *l;  /* We only need to worry about this when doing a final link.  */  if (link_info.relocateable || link_info.shared)    return;  /* Get the list of files which appear in DT_NEEDED entries in     dynamic objects included in the link (often there will be none).     For each such file, we want to track down the corresponding     library, and include the symbol table in the link.  This is what     the runtime dynamic linker will do.  Tracking the files down here     permits one dynamic object to include another without requiring     special action by the person doing the link.  Note that the     needed list can actually grow while we are stepping through this     loop.  */  needed = bfd_elf_get_needed_list (output_bfd, &link_info);  for (l = needed; l != NULL; l = l->next)    {      struct bfd_link_needed_list *ll;      int force;      /* If we've already seen this file, skip it.  */      for (ll = needed; ll != l; ll = ll->next)	if (strcmp (ll->name, l->name) == 0)	  break;      if (ll != l)	continue;      /* See if this file was included in the link explicitly.  */      global_needed = l;      global_found = false;      lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);      if (global_found)	continue;      if (trace_file_tries)	info_msg (_("%s needed by %B\n"), l->name, l->by);      /* We need to find this file and include the symbol table.  We	 want to search for the file in the same way that the dynamic	 linker will search.  That means that we want to use	 rpath_link, rpath, then the environment variable	 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH	 entries (native only), then the linker script LIB_SEARCH_DIRS.	 We do not search using the -L arguments.	 We search twice.  The first time, we skip objects which may	 introduce version mismatches.  The second time, we force	 their use.  See gld${EMULATION_NAME}_vercheck comment.  */      for (force = 0; force < 2; force++)	{	  size_t len;	  search_dirs_type *search;EOFif [ "x${host}" = "x${target}" ] ; then  case " ${EMULATION_LIBPATH} " in  *" ${EMULATION_NAME} "*)cat >>e${EMULATION_NAME}.c <<EOF	  const char *lib_path;	  struct bfd_link_needed_list *rp;	  int found;EOF  ;;  esacficat >>e${EMULATION_NAME}.c <<EOF	  if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,						  l->name, force))	    break;EOFif [ "x${host}" = "x${target}" ] ; then  case " ${EMULATION_LIBPATH} " in  *" ${EMULATION_NAME} "*)cat >>e${EMULATION_NAME}.c <<EOF	  if (gld${EMULATION_NAME}_search_needed (command_line.rpath,						  l->name, force))	    break;	  if (command_line.rpath_link == NULL	      && command_line.rpath == NULL)	    {	      lib_path = (const char *) getenv ("LD_RUN_PATH");	      if (gld${EMULATION_NAME}_search_needed (lib_path, l->name,						      force))		break;	    }	  lib_path = (const char *) getenv ("LD_LIBRARY_PATH");	  if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, force))	    break;	  found = 0;	  rp = bfd_elf_get_runpath_list (output_bfd, &link_info);	  for (; !found && rp != NULL; rp = rp->next)	    {	      found = (rp->by == l->by		       && gld${EMULATION_NAME}_search_needed (rp->name,							      l->name,							      force));	    }	  if (found)	    break;EOF  ;;  esacficat >>e${EMULATION_NAME}.c <<EOF	  len = strlen (l->name);	  for (search = search_head; search != NULL; search = search->next)	    {	      char *filename;	      if (search->cmdline)		continue;	      filename = (char *) xmalloc (strlen (search->name) + len + 2);	      sprintf (filename, "%s/%s", search->name, l->name);	      if (gld${EMULATION_NAME}_try_needed (filename, force))		break;	      free (filename);	    }	  if (search != NULL)	    break;EOFif [ "x${host}" = "x${target}" ] ; then  case " ${EMULATION_LIBPATH} " in  *" ${EMULATION_NAME} "*)    case ${target} in      *-*-linux-gnu*)	cat >>e${EMULATION_NAME}.c <<EOF	  if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force))	    break;EOF	# Linux        ;;    esac  ;;  esacficat >>e${EMULATION_NAME}.c <<EOF	}      if (force < 2)	continue;      einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n",	     l->name, l->by);    }}EOFficat >>e${EMULATION_NAME}.c <<EOF/* Look through an expression for an assignment statement.  */static voidgld${EMULATION_NAME}_find_exp_assignment (exp)     etree_type *exp;{  struct bfd_link_hash_entry *h;  switch (exp->type.node_class)    {    case etree_provide:      h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,				false, false, false);      if (h == NULL)	break;      /* We call record_link_assignment even if the symbol is defined.	 This is because if it is defined by a dynamic object, we	 actually want to use the value defined by the linker script,	 not the value from the dynamic object (because we are setting	 symbols like etext).  If the symbol is defined by a regular	 object, then, as it happens, calling record_link_assignment	 will do no harm.  */      /* Fall through.  */    case etree_assign:      if (strcmp (exp->assign.dst, ".") != 0)	{	  if (! (bfd_elf${ELFSIZE}_record_link_assignment		 (output_bfd, &link_info, exp->assign.dst,		  exp->type.node_class == etree_provide ? true : false)))	    einfo ("%P%F: failed to record assignment to %s: %E\n",		   exp->assign.dst);	}      gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);      break;    case etree_binary:      gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);      gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);      break;    case etree_trinary:      gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);      gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);      gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);      break;    case etree_unary:      gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);      break;    default:      break;    }}/* This is called by the before_allocation routine via   lang_for_each_statement.  It locates any assignment statements, and   tells the ELF backend about them, in case they are assignments to   symbols which are referred to by dynamic objects.  */static voidgld${EMULATION_NAME}_find_statement_assignment (s)     lang_statement_union_type *s;{  if (s->header.type == lang_assignment_statement_enum)    gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);}EOFif test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; thencat >>e${EMULATION_NAME}.c <<EOF/* This is called after the sections have been attached to output   sections, but before any sizes or addresses have been set.  */static voidgld${EMULATION_NAME}_before_allocation (){  const char *rpath;  asection *sinterp;  /* If we are going to make any variable assignments, we need to let     the ELF backend know about them in case the variables are     referred to by dynamic objects.  */  lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);  /* Let the ELF backend work out the sizes of any sections required     by dynamic linking.  */  rpath = command_line.rpath;  if (rpath == NULL)    rpath = (const char *) getenv ("LD_RUN_PATH");  if (! (bfd_elf${ELFSIZE}_size_dynamic_sections         (output_bfd, command_line.soname, rpath,	  command_line.export_dynamic, command_line.filter_shlib,	  (const char * const *) command_line.auxiliary_filters,	  &link_info, &sinterp, lang_elf_version_info)))    einfo ("%P%F: failed to set dynamic section sizes: %E\n");  /* Let the user override the dynamic linker we are using.  */  if (command_line.interpreter != NULL      && sinterp != NULL)    {      sinterp->contents = (bfd_byte *) command_line.interpreter;      sinterp->_raw_size = strlen (command_line.interpreter) + 1;    }  /* Look for any sections named .gnu.warning.  As a GNU extensions,     we treat such sections as containing warning messages.  We print     out the warning message, and then zero out the section size so     that it does not get copied into the output file.  */  {    LANG_FOR_EACH_INPUT_STATEMENT (is)      {	asection *s;	bfd_size_type sz;	char *msg;	boolean ret;	if (is->just_syms_flag)	  continue;	s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");	if (s == NULL)	  continue;	sz = bfd_section_size (is->the_bfd, s);	msg = xmalloc ((size_t) sz + 1);	if (! bfd_get_section_contents (is->the_bfd, s, msg, (file_ptr) 0, sz))	  einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",		 is->the_bfd);	msg[sz] = '\0';	ret = link_info.callbacks->warning (&link_info, msg,					    (const char *) NULL,					    is->the_bfd, (asection *) NULL,					    (bfd_vma) 0);	ASSERT (ret);	free (msg);	/* Clobber the section size, so that we don't waste copying the	   warning into the output file.  */	s->_raw_size = 0;      }  }}EOFfiif test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; thencat >>e${EMULATION_NAME}.c <<EOF/* Try to open a dynamic archive.  This is where we know that ELF   dynamic libraries have an extension of .so (or .sl on oddball systems   like hpux).  */static booleangld${EMULATION_NAME}_open_dynamic_archive (arch, search, entry)     const char *arch;     search_dirs_type *search;     lang_input_statement_type *entry;{  const char *filename;  char *string;  if (! entry->is_archive)    return false;  filename = entry->filename;  /* This allocates a few bytes too many when EXTRA_SHLIB_EXTENSION     is defined, but it does not seem worth the headache to optimize     away those two bytes of space.  */  string = (char *) xmalloc (strlen (search->name)			     + strlen (filename)			     + strlen (arch)#ifdef EXTRA_SHLIB_EXTENSION			     + strlen (EXTRA_SHLIB_EXTENSION)#endif			     + sizeof "/lib.so");  sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);#ifdef EXTRA_SHLIB_EXTENSION  /* Try the .so extension first.  If that fails build a new filename     using EXTRA_SHLIB_EXTENSION.  */  if (! ldfile_try_open_bfd (string, entry))    sprintf (string, "%s/lib%s%s%s", search->name,	     filename, arch, EXTRA_SHLIB_EXTENSION);#endif  if (! ldfile_try_open_bfd (string, entry))    {      free (string);      return false;    }  entry->filename = string;  /* We have found a dynamic object to include in the link.  The ELF     backend linker will create a DT_NEEDED entry in the .dynamic     section naming this file.  If this file includes a DT_SONAME     entry, it will be used.  Otherwise, the ELF linker will just use     the name of the file.  For an archive found by searching, like     this one, the DT_NEEDED entry should consist of just the name of     the file, without the path information used to find it.  Note     that we only need to do this if we have a dynamic object; an     archive will never be referenced by a DT_NEEDED entry.     FIXME: This approach--using bfd_elf_set_dt_needed_name--is not     very pretty.  I haven't been able to think of anything that is     pretty, though.  */  if (bfd_check_format (entry->the_bfd, bfd_object)      && (entry->the_bfd->flags & DYNAMIC) != 0)    {      ASSERT (entry->is_archive && entry->search_dirs_flag);      /* Rather than duplicating the logic above.  Just use the	 filename we recorded earlier.  */      filename = xstrdup (basename (entry->filename));      bfd_elf_set_dt_needed_name (entry->the_bfd, filename);    }  return true;}EOFficat >>e${EMULATION_NAME}.c <<EOF/* A variant of lang_output_section_find.  Used by place_orphan.  */static lang_output_section_statement_type *output_rel_find (){  lang_statement_union_type *u;  lang_output_section_statement_type *lookup;  for (u = lang_output_section_statement.head;       u != (lang_statement_union_type *) NULL;       u = lookup->next)    {      lookup = &u->output_section_statement;      if (strncmp (".rel", lookup->name, 4) == 0	  && lookup->bfd_section != NULL	  && (lookup->bfd_section->flags & SEC_ALLOC) != 0)	{	  return lookup;	}    }  return (lang_output_section_statement_type *) NULL;}EOFif test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; thencat >>e${EMULATION_NAME}.c <<EOF/* Place an orphan section.  We use this to put random SHF_ALLOC   sections in the right segment.  */struct orphan_save {  lang_output_section_statement_type *os;  asection **section;  lang_statement_union_type **stmt;};static booleangld${EMULATION_NAME}_place_orphan (file, s)     lang_input_statement_type *file;     asection *s;{  static struct orphan_save hold_text;  static struct orphan_save hold_rodata;  static struct orphan_save hold_data;  static struct orphan_save hold_bss;  static struct orphan_save hold_rel;  static struct orphan_save hold_interp;  static struct orphan_save hold_sdata;  static int count = 1;  struct orphan_save *place;  lang_statement_list_type *old;  lang_statement_list_type add;  etree_type *address;  const char *secname;  const char *outsecname;  const char *ps = NULL;  lang_output_section_statement_type *os;  secname = bfd_get_section_name (s->owner, s);  if (! config.unique_orphan_sections && ! unique_section_p (secname))    {      /* Look through the script to see where to place this section.  */      os = lang_output_section_find (secname);      if (os != NULL	  && os->bfd_section != NULL	  && ((s->flags ^ os->bfd_section->flags)	      & (SEC_LOAD | SEC_ALLOC)) == 0)

⌨️ 快捷键说明

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