pe.em

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

EM
1,678
字号
  optarg = end;}static voidset_pe_stack_heap (resname, comname)     char *resname;     char *comname;{  set_pe_value (resname);    if (*optarg == ',')    {      optarg++;      set_pe_value (comname);    }  else if (*optarg)    einfo (_("%P%F: strange hex info for PE parameter '%s'\n"), optarg);}static intgld_${EMULATION_NAME}_parse_args(argc, argv)     int argc;     char **argv;{  int longind;  int optc;  int prevoptind = optind;  int prevopterr = opterr;  int wanterror;  static int lastoptind = -1;  if (lastoptind != optind)    opterr = 0;  wanterror = opterr;  lastoptind = optind;  optc = getopt_long_only (argc, argv, "-", longopts, &longind);  opterr = prevopterr;  switch (optc)    {    default:      if (wanterror)	xexit (1);      optind =  prevoptind;      return 0;    case OPTION_BASE_FILE:      link_info.base_file = (PTR) fopen (optarg, FOPEN_WB);      if (link_info.base_file == NULL)	{	  /* xgettext:c-format */	  fprintf (stderr, _("%s: Can't open base file %s\n"),		   program_name, optarg);	  xexit (1);	}      break;      /* PE options */    case OPTION_HEAP:       set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");      break;    case OPTION_STACK:       set_pe_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");      break;    case OPTION_SUBSYSTEM:      set_pe_subsystem ();      break;    case OPTION_MAJOR_OS_VERSION:      set_pe_value ("__major_os_version__");      break;    case OPTION_MINOR_OS_VERSION:      set_pe_value ("__minor_os_version__");      break;    case OPTION_MAJOR_SUBSYSTEM_VERSION:      set_pe_value ("__major_subsystem_version__");      break;    case OPTION_MINOR_SUBSYSTEM_VERSION:      set_pe_value ("__minor_subsystem_version__");      break;    case OPTION_MAJOR_IMAGE_VERSION:      set_pe_value ("__major_image_version__");      break;    case OPTION_MINOR_IMAGE_VERSION:      set_pe_value ("__minor_image_version__");      break;    case OPTION_FILE_ALIGNMENT:      set_pe_value ("__file_alignment__");      break;    case OPTION_SECTION_ALIGNMENT:      set_pe_value ("__section_alignment__");      break;    case OPTION_DLL:      set_pe_name ("__dll__", 1);      break;    case OPTION_IMAGE_BASE:      set_pe_value ("__image_base__");      break;    case OPTION_SUPPORT_OLD_CODE:      support_old_code = 1;      break;    case OPTION_THUMB_ENTRY:      thumb_entry_symbol = optarg;      break;#ifdef DLL_SUPPORT    case OPTION_OUT_DEF:      pe_out_def_filename = xstrdup (optarg);      break;    case OPTION_EXPORT_ALL:      pe_dll_export_everything = 1;      break;    case OPTION_EXCLUDE_SYMBOLS:      pe_dll_add_excludes (optarg);      break;    case OPTION_KILL_ATS:      pe_dll_kill_ats = 1;      break;    case OPTION_STDCALL_ALIASES:      pe_dll_stdcall_aliases = 1;      break;    case OPTION_ENABLE_STDCALL_FIXUP:      pe_enable_stdcall_fixup = 1;      break;    case OPTION_DISABLE_STDCALL_FIXUP:      pe_enable_stdcall_fixup = 0;      break;    case OPTION_IMPLIB_FILENAME:      pe_implib_filename = xstrdup (optarg);      break;    case OPTION_WARN_DUPLICATE_EXPORTS:      pe_dll_warn_dup_exports = 1;      break;    case OPTION_IMP_COMPAT:      pe_dll_compat_implib = 1;      break;    case OPTION_ENABLE_AUTO_IMAGE_BASE:      pe_enable_auto_image_base = 1;      break;    case OPTION_DISABLE_AUTO_IMAGE_BASE:      pe_enable_auto_image_base = 0;      break;    case OPTION_DLL_SEARCH_PREFIX:      pe_dll_search_prefix = xstrdup( optarg );      break;    case OPTION_NO_DEFAULT_EXCLUDES:      pe_dll_do_default_excludes = 0;      break;#endif    }  return 1;}#ifdef DLL_SUPPORTstatic unsigned long strhash (const char *str){  const unsigned char *s;  unsigned long hash;  unsigned int c;  unsigned int len;  hash = 0;  len = 0;  s = (const unsigned char *) str;  while ((c = *s++) != '\0')    {      hash += c + (c << 17);      hash ^= hash >> 2;      ++len;    }  hash += len + (len << 17);  hash ^= hash >> 2;  return hash;}/* Use the output file to create a image base for relocatable DLLs. */static unsigned longcompute_dll_image_base (const char *ofile){  unsigned long hash = strhash (ofile);  return 0x60000000 | ((hash << 16) & 0x0FFC0000);}#endif/* Assign values to the special symbols before the linker script is   read.  */static voidgld_${EMULATION_NAME}_set_symbols (){  /* Run through and invent symbols for all the     names and insert the defaults. */  int j;  lang_statement_list_type *save;  if (!init[IMAGEBASEOFF].inited)    {      if (link_info.relocateable)	init[IMAGEBASEOFF].value = 0;      else if (init[DLLOFF].value || link_info.shared)#ifdef DLL_SUPPORT	init[IMAGEBASEOFF].value = (pe_enable_auto_image_base) ?	  compute_dll_image_base (output_filename) : NT_DLL_IMAGE_BASE;#else	init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;#endif      else	init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;    }  /* Don't do any symbol assignments if this is a relocateable link.  */  if (link_info.relocateable)    return;  /* Glue the assignments into the abs section */  save = stat_ptr;  stat_ptr = &(abs_output_section->children);  for (j = 0; init[j].ptr; j++)    {      long val = init[j].value;      lang_assignment_statement_type *rv;      rv = lang_add_assignment (exp_assop ('=' ,init[j].symbol, exp_intop (val)));      if (init[j].size == sizeof(short))	*(short *)init[j].ptr = val;      else if (init[j].size == sizeof(int))	*(int *)init[j].ptr = val;      else if (init[j].size == sizeof(long))	*(long *)init[j].ptr = val;      /* This might be a long long or other special type.  */      else if (init[j].size == sizeof(bfd_vma))	*(bfd_vma *)init[j].ptr = val;      else	abort();      if (j == IMAGEBASEOFF)	image_base_statement = rv;    }  /* Restore the pointer. */  stat_ptr = save;    if (pe.FileAlignment >      pe.SectionAlignment)    {      einfo (_("%P: warning, file alignment > section alignment.\n"));    }}/* This is called after the linker script and the command line options   have been read.  */static voidgld_${EMULATION_NAME}_after_parse (){  /* The Windows libraries are designed for the linker to treat the     entry point as an undefined symbol.  Otherwise, the .obj that     defines mainCRTStartup is brought in because it is the first     encountered in libc.lib and it has other symbols in it which will     be pulled in by the link process.  To avoid this, we act as     though the user specified -u with the entry point symbol.     This function is called after the linker script and command line     options have been read, so at this point we know the right entry     point.  This function is called before the input files are     opened, so registering the symbol as undefined will make a     difference.  */  if (! link_info.relocateable && entry_symbol != NULL)    ldlang_add_undef (entry_symbol);}#ifdef DLL_SUPPORTstatic struct bfd_link_hash_entry *pe_undef_found_sym;static booleanpe_undef_cdecl_match (h, string)  struct bfd_link_hash_entry *h;  PTR string;{  int sl = strlen (string);  if (h->type == bfd_link_hash_defined      && strncmp (h->root.string, string, sl) == 0      && h->root.string[sl] == '@')  {    pe_undef_found_sym = h;    return false;  }  return true;}static voidpe_fixup_stdcalls (){  static int gave_warning_message = 0;  struct bfd_link_hash_entry *undef, *sym;  char *at;  for (undef = link_info.hash->undefs; undef; undef=undef->next)    if (undef->type == bfd_link_hash_undefined)    {      at = strchr (undef->root.string, '@');      if (at)      {	/* The symbol is a stdcall symbol, so let's look for a cdecl	   symbol with the same name and resolve to that */	char *cname = xstrdup (undef->root.string);	at = strchr (cname, '@');	*at = 0;	sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);	if (sym && sym->type == bfd_link_hash_defined)	{	  undef->type = bfd_link_hash_defined;	  undef->u.def.value = sym->u.def.value;	  undef->u.def.section = sym->u.def.section;	  if (pe_enable_stdcall_fixup == -1)	    {	      einfo (_("Warning: resolving %s by linking to %s\n"),		     undef->root.string, cname);	      if (! gave_warning_message)		{		  gave_warning_message = 1;		  einfo(_("Use --enable-stdcall-fixup to disable these warnings\n"));		  einfo(_("Use --disable-stdcall-fixup to disable these fixups\n"));		}	    }	}      }      else      {	/* The symbol is a cdecl symbol, so we look for stdcall	   symbols - which means scanning the whole symbol table */	pe_undef_found_sym = 0;	bfd_link_hash_traverse (link_info.hash, pe_undef_cdecl_match,				(PTR) undef->root.string);	sym = pe_undef_found_sym;	if (sym)	{	  undef->type = bfd_link_hash_defined;	  undef->u.def.value = sym->u.def.value;	  undef->u.def.section = sym->u.def.section;	  if (pe_enable_stdcall_fixup == -1)	    {	      einfo (_("Warning: resolving %s by linking to %s\n"),		     undef->root.string, sym->root.string);	      if (! gave_warning_message)		{		  gave_warning_message = 1;		  einfo(_("Use --enable-stdcall-fixup to disable these warnings\n"));		  einfo(_("Use --disable-stdcall-fixup to disable these fixups\n"));		}	    }	}      }    }}#endif /* DLL_SUPPORT */static voidgld_${EMULATION_NAME}_after_open (){  /* Pass the wacky PE command line options into the output bfd.     FIXME: This should be done via a function, rather than by     including an internal BFD header.  */    if (!coff_data (output_bfd)->pe)    einfo (_("%F%P: PE operations on non PE file.\n"));  pe_data (output_bfd)->pe_opthdr = pe;  pe_data (output_bfd)->dll = init[DLLOFF].value;#ifdef DLL_SUPPORT  if (pe_enable_stdcall_fixup) /* -1=warn or 1=disable */    pe_fixup_stdcalls ();  pe_process_import_defs(output_bfd, &link_info);  if (link_info.shared)    pe_dll_build_sections (output_bfd, &link_info);#ifndef TARGET_IS_i386pe#ifndef TARGET_IS_armpe  else    pe_exe_build_sections (output_bfd, &link_info);#endif#endif#endif#if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)  if (strstr (bfd_get_target (output_bfd), "arm") == NULL)    {      /* The arm backend needs special fields in the output hash structure.	 These will only be created if the output format is an arm format,	 hence we do not support linking and changing output formats at the	 same time.  Use a link followed by objcopy to change output formats.  */      einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");      return;    }  {    /* Find a BFD that can hold the interworking stubs.  */    LANG_FOR_EACH_INPUT_STATEMENT (is)      {	if (bfd_arm_pe_get_bfd_for_interworking (is->the_bfd, & link_info))	  break;      }  }#endif  {    /* This next chunk of code tries to detect the case where you have       two import libraries for the same DLL (specifically,       symbolically linking libm.a and libc.a in cygwin to       libcygwin.a).  In those cases, it's possible for function       thunks from the second implib to be used but without the       head/tail objects, causing an improper import table.  We detect       those cases and rename the "other" import libraries to match       the one the head/tail come from, so that the linker will sort       things nicely and produce a valid import table. */

⌨️ 快捷键说明

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