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

📄 pe.em

📁 俄罗斯高人Mamaich的Pocket gcc编译器(运行在PocketPC上)的全部源代码。
💻 EM
📖 第 1 页 / 共 4 页
字号:
  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, 0);      break;    case OPTION_EXCLUDE_LIBS:      pe_dll_add_excludes (optarg, 1);      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;    case OPTION_DLL_ENABLE_AUTO_IMPORT:      link_info.pei386_auto_import = 1;      break;    case OPTION_DLL_DISABLE_AUTO_IMPORT:      link_info.pei386_auto_import = 0;      break;    case OPTION_ENABLE_EXTRA_PE_DEBUG:      pe_dll_extra_pe_debug = 1;      break;#endif    }  return 1;}#ifdef DLL_SUPPORTstatic unsigned longstrhash (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.name != NULL)    ldlang_add_undef (entry_symbol.name);}/* pe-dll.c directly accesses pe_data_import_dll,   so it must be defined outside of #ifdef DLL_SUPPORT.   Note - this variable is deliberately not initialised.   This allows it to be treated as a common varaible, and only   exist in one incarnation in a multiple target enabled linker.  */char * pe_data_import_dll;#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;  sl = strlen (string); /* silence compiler warning */  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;  if (pe_dll_extra_pe_debug)    {      printf ("%s\n", __FUNCTION__);    }  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"));		}	    }	}      }    }}static intmake_import_fixup (rel, s)  arelent *rel;  asection *s;{  struct symbol_cache_entry *sym = *rel->sym_ptr_ptr;  if (pe_dll_extra_pe_debug)    {      printf ("arelent: %s@%#lx: add=%li\n", sym->name,              (long) rel->address, (long) rel->addend);    }  {    int addend = 0;    if (!bfd_get_section_contents(s->owner, s, &addend, rel->address, sizeof(addend)))      {        einfo (_("%C: Cannot get section contents - auto-import exception\n"),               s->owner, s, rel->address);      }    if (addend == 0)      pe_create_import_fixup (rel);    else      {        einfo (_("%C: variable '%T' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.\n"),               s->owner, s, rel->address, sym->name);        einfo ("%X");      }  }  return 1;}static voidpe_find_data_imports (){  struct bfd_link_hash_entry *undef, *sym;  for (undef = link_info.hash->undefs; undef; undef=undef->next)    {      if (undef->type == bfd_link_hash_undefined)        {          /* C++ symbols are *long* */          char buf[4096];          if (pe_dll_extra_pe_debug)            {              printf ("%s:%s\n", __FUNCTION__, undef->root.string);            }          sprintf (buf, "__imp_%s", undef->root.string);          sym = bfd_link_hash_lookup (link_info.hash, buf, 0, 0, 1);          if (sym && sym->type == bfd_link_hash_defined)            {             if (link_info.pei386_auto_import == -1)               info_msg (_("Info: resolving %s by linking to %s (auto-import)\n"),                      undef->root.string, buf);              {                bfd *b = sym->u.def.section->owner;                asymbol **symbols;                int nsyms, symsize, i;                symsize = bfd_get_symtab_upper_bound (b);                symbols = (asymbol **) xmalloc (symsize);                nsyms = bfd_canonicalize_symtab (b, symbols);                for (i = 0; i < nsyms; i++)                  {                    if (memcmp(symbols[i]->name, "__head_",                             sizeof ("__head_") - 1))                      continue;                    if (pe_dll_extra_pe_debug)                      {                        printf ("->%s\n", symbols[i]->name);                      }                    pe_data_import_dll = (char*) (symbols[i]->name +                                                  sizeof ("__head_") - 1);                    break;                  }              }              pe_walk_relocs_of_symbol (&link_info, undef->root.string,                                        make_import_fixup);              /* let's differentiate it somehow from defined */              undef->type = bfd_link_hash_defweak;              /* we replace original name with __imp_ prefixed, this                 1) may trash memory 2) leads to duplicate symbol generation.                 Still, IMHO it's better than having name poluted. */              undef->root.string = sym->root.string;              undef->u.def.value = sym->u.def.value;              undef->u.def.section = sym->u.def.section;            }        }    }}#endif /* DLL_SUPPORT */static booleanpr_sym (h, string)  struct bfd_hash_entry *h;  PTR string ATTRIBUTE_UNUSED;{  if (pe_dll_extra_pe_debug)    {      printf("+%s\n",h->string);    }  return true;}static voidgld_${EMULATION_NAME}_after_open (){

⌨️ 快捷键说明

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