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

📄 pe.em

📁 俄罗斯高人Mamaich的Pocket gcc编译器(运行在PocketPC上)的全部源代码。
💻 EM
📖 第 1 页 / 共 4 页
字号:
# This shell script emits a C file. -*- C -*-# It does some substitutions.if [ -z "$MACHINE" ]; then  OUTPUT_ARCH=${ARCH}else  OUTPUT_ARCH=${ARCH}:${MACHINE}firm -f e${EMULATION_NAME}.c(echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)cat >>e${EMULATION_NAME}.c <<EOF/* This file is part of GLD, the Gnu Linker.   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002   Free Software Foundation, Inc.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  *//* For WINDOWS_NT *//* The original file generated returned different default scripts depending   on whether certain switches were set, but these switches pertain to the   Linux system and that particular version of coff.  In the NT case, we   only determine if the subsystem is console or windows in order to select   the correct entry point by default. */#define TARGET_IS_${EMULATION_NAME}/* Do this before including bfd.h, so we prototype the right functions.  */#ifdef TARGET_IS_arm_epoc_pe#define bfd_arm_pe_allocate_interworking_sections \	bfd_arm_epoc_pe_allocate_interworking_sections#define bfd_arm_pe_get_bfd_for_interworking \	bfd_arm_epoc_pe_get_bfd_for_interworking#define bfd_arm_pe_process_before_allocation \	bfd_arm_epoc_pe_process_before_allocation#endif#include "bfd.h"#include "sysdep.h"#include "bfdlink.h"#include "getopt.h"#include "libiberty.h"#include "ld.h"#include "ldmain.h"#include "ldexp.h"#include "ldlang.h"#include "ldfile.h"#include "ldemul.h"#include <ldgram.h>#include "ldlex.h"#include "ldmisc.h"#include "ldctor.h"#include "coff/internal.h"/* FIXME: This is a BFD internal header file, and we should not be   using it here.  */#include "../bfd/libcoff.h"#include "deffile.h"#include "pe-dll.h"#include <ctype.h>/* Permit the emulation parameters to override the default section   alignment by setting OVERRIDE_SECTION_ALIGNMENT.  FIXME: This makes   it seem that include/coff/internal.h should not define   PE_DEF_SECTION_ALIGNMENT.  */#if PE_DEF_SECTION_ALIGNMENT != ${OVERRIDE_SECTION_ALIGNMENT:-PE_DEF_SECTION_ALIGNMENT}#undef PE_DEF_SECTION_ALIGNMENT#define PE_DEF_SECTION_ALIGNMENT ${OVERRIDE_SECTION_ALIGNMENT}#endif#if defined(TARGET_IS_i386pe)#define DLL_SUPPORT#endif#if defined(TARGET_IS_shpe) || defined(TARGET_IS_mipspe) || defined(TARGET_IS_armpe)#define DLL_SUPPORT#endif#if defined(TARGET_IS_i386pe) || ! defined(DLL_SUPPORT)#define	PE_DEF_SUBSYSTEM		3#else#undef NT_EXE_IMAGE_BASE#undef PE_DEF_SECTION_ALIGNMENT#undef PE_DEF_FILE_ALIGNMENT#define NT_EXE_IMAGE_BASE		0x00010000#ifdef TARGET_IS_armpe#define PE_DEF_SECTION_ALIGNMENT	0x00001000#define	PE_DEF_SUBSYSTEM		9#else#define PE_DEF_SECTION_ALIGNMENT	0x00000400#define	PE_DEF_SUBSYSTEM		2#endif#define PE_DEF_FILE_ALIGNMENT		0x00000200#endifstatic void gld_${EMULATION_NAME}_set_symbols PARAMS ((void));static void gld_${EMULATION_NAME}_after_open PARAMS ((void));static void gld_${EMULATION_NAME}_before_parse PARAMS ((void));static void gld_${EMULATION_NAME}_after_parse PARAMS ((void));static void gld_${EMULATION_NAME}_before_allocation PARAMS ((void));static asection *output_prev_sec_find  PARAMS ((lang_output_section_statement_type *));static boolean gld_${EMULATION_NAME}_place_orphan  PARAMS ((lang_input_statement_type *, asection *));static char *gld_${EMULATION_NAME}_get_script PARAMS ((int *));static int gld_${EMULATION_NAME}_parse_args PARAMS ((int, char **));static void gld_${EMULATION_NAME}_finish PARAMS ((void));static boolean gld_${EMULATION_NAME}_open_dynamic_archive  PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));static void gld_${EMULATION_NAME}_list_options PARAMS ((FILE *));static void set_pe_name PARAMS ((char *, long));static void set_pe_subsystem PARAMS ((void));static void set_pe_value PARAMS ((char *));static void set_pe_stack_heap PARAMS ((char *, char *));#ifdef DLL_SUPPORTstatic boolean pe_undef_cdecl_match  PARAMS ((struct bfd_link_hash_entry *, PTR));static void pe_fixup_stdcalls PARAMS ((void));static int make_import_fixup PARAMS ((arelent *, asection *));static void pe_find_data_imports PARAMS ((void));#endifstatic boolean pr_sym PARAMS ((struct bfd_hash_entry *, PTR string));static boolean gld_${EMULATION_NAME}_unrecognized_file  PARAMS ((lang_input_statement_type *));static boolean gld_${EMULATION_NAME}_recognized_file  PARAMS ((lang_input_statement_type *));static int gld_${EMULATION_NAME}_find_potential_libraries  PARAMS ((char *, lang_input_statement_type *));static struct internal_extra_pe_aouthdr pe;static int dll;static int support_old_code = 0;static char * thumb_entry_symbol = NULL;static lang_assignment_statement_type *image_base_statement = 0;#ifdef DLL_SUPPORTstatic int pe_enable_stdcall_fixup = -1; /* 0=disable 1=enable */static char *pe_out_def_filename = NULL;static char *pe_implib_filename = NULL;static int pe_enable_auto_image_base = 0;static char *pe_dll_search_prefix = NULL;#endifextern const char *output_filename;static voidgld_${EMULATION_NAME}_before_parse(){  const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");  if (arch)    {      ldfile_output_architecture = arch->arch;      ldfile_output_machine = arch->mach;      ldfile_output_machine_name = arch->printable_name;    }  else    ldfile_output_architecture = bfd_arch_${ARCH};  output_filename = "${EXECUTABLE_NAME:-a.exe}";#ifdef DLL_SUPPORT  config.dynamic_link = true;  config.has_shared = 1;  link_info.pei386_auto_import = -1;#if (PE_DEF_SUBSYSTEM == 9) || (PE_DEF_SUBSYSTEM == 2)#if defined TARGET_IS_mipspe || defined TARGET_IS_armpe  lang_add_entry ("WinMainCRTStartup", 1);#else  lang_add_entry ("_WinMainCRTStartup", 1);#endif#endif#endif}/* PE format extra command line options.  *//* Used for setting flags in the PE header. */#define OPTION_BASE_FILE		(300  + 1)#define OPTION_DLL			(OPTION_BASE_FILE + 1)#define OPTION_FILE_ALIGNMENT		(OPTION_DLL + 1)#define OPTION_IMAGE_BASE		(OPTION_FILE_ALIGNMENT + 1)#define OPTION_MAJOR_IMAGE_VERSION	(OPTION_IMAGE_BASE + 1)#define OPTION_MAJOR_OS_VERSION		(OPTION_MAJOR_IMAGE_VERSION + 1)#define OPTION_MAJOR_SUBSYSTEM_VERSION	(OPTION_MAJOR_OS_VERSION + 1)#define OPTION_MINOR_IMAGE_VERSION	(OPTION_MAJOR_SUBSYSTEM_VERSION + 1)#define OPTION_MINOR_OS_VERSION		(OPTION_MINOR_IMAGE_VERSION + 1)#define OPTION_MINOR_SUBSYSTEM_VERSION	(OPTION_MINOR_OS_VERSION + 1)#define OPTION_SECTION_ALIGNMENT	(OPTION_MINOR_SUBSYSTEM_VERSION + 1)#define OPTION_STACK                    (OPTION_SECTION_ALIGNMENT + 1)#define OPTION_SUBSYSTEM                (OPTION_STACK + 1)#define OPTION_HEAP			(OPTION_SUBSYSTEM + 1)#define OPTION_SUPPORT_OLD_CODE		(OPTION_HEAP + 1)#define OPTION_OUT_DEF			(OPTION_SUPPORT_OLD_CODE + 1)#define OPTION_EXPORT_ALL		(OPTION_OUT_DEF + 1)#define OPTION_EXCLUDE_SYMBOLS		(OPTION_EXPORT_ALL + 1)#define OPTION_KILL_ATS			(OPTION_EXCLUDE_SYMBOLS + 1)#define OPTION_STDCALL_ALIASES		(OPTION_KILL_ATS + 1)#define OPTION_ENABLE_STDCALL_FIXUP	(OPTION_STDCALL_ALIASES + 1)#define OPTION_DISABLE_STDCALL_FIXUP	(OPTION_ENABLE_STDCALL_FIXUP + 1)#define OPTION_IMPLIB_FILENAME		(OPTION_DISABLE_STDCALL_FIXUP + 1)#define OPTION_THUMB_ENTRY		(OPTION_IMPLIB_FILENAME + 1)#define OPTION_WARN_DUPLICATE_EXPORTS	(OPTION_THUMB_ENTRY + 1)#define OPTION_IMP_COMPAT		(OPTION_WARN_DUPLICATE_EXPORTS + 1)#define OPTION_ENABLE_AUTO_IMAGE_BASE	(OPTION_IMP_COMPAT + 1)#define OPTION_DISABLE_AUTO_IMAGE_BASE	(OPTION_ENABLE_AUTO_IMAGE_BASE + 1)#define OPTION_DLL_SEARCH_PREFIX	(OPTION_DISABLE_AUTO_IMAGE_BASE + 1)#define OPTION_NO_DEFAULT_EXCLUDES	(OPTION_DLL_SEARCH_PREFIX + 1)#define OPTION_DLL_ENABLE_AUTO_IMPORT	(OPTION_NO_DEFAULT_EXCLUDES + 1)#define OPTION_DLL_DISABLE_AUTO_IMPORT	(OPTION_DLL_ENABLE_AUTO_IMPORT + 1)#define OPTION_ENABLE_EXTRA_PE_DEBUG	(OPTION_DLL_DISABLE_AUTO_IMPORT + 1)#define OPTION_EXCLUDE_LIBS		(OPTION_ENABLE_EXTRA_PE_DEBUG + 1)static struct option longopts[] = {  /* PE options */  {"base-file", required_argument, NULL, OPTION_BASE_FILE},  {"dll", no_argument, NULL, OPTION_DLL},  {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},  {"heap", required_argument, NULL, OPTION_HEAP},  {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},  {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},  {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},  {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},  {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},  {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},  {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},  {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},  {"stack", required_argument, NULL, OPTION_STACK},  {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},  {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},  {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},#ifdef DLL_SUPPORT  /* getopt allows abbreviations, so we do this to stop it from treating -o     as an abbreviation for this option */  {"output-def", required_argument, NULL, OPTION_OUT_DEF},  {"output-def", required_argument, NULL, OPTION_OUT_DEF},  {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},  {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},  {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},	  {"kill-at", no_argument, NULL, OPTION_KILL_ATS},  {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},  {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},  {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},  {"out-implib", required_argument, NULL, OPTION_IMPLIB_FILENAME},  {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},  /* getopt() allows abbreviations, so we do this to stop it from     treating -c as an abbreviation for these --compat-implib.  */  {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},  {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},  {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},  {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},  {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},  {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},  {"enable-auto-import", no_argument, NULL, OPTION_DLL_ENABLE_AUTO_IMPORT},  {"disable-auto-import", no_argument, NULL, OPTION_DLL_DISABLE_AUTO_IMPORT},  {"enable-extra-pe-debug", no_argument, NULL, OPTION_ENABLE_EXTRA_PE_DEBUG},#endif  {NULL, no_argument, NULL, 0}};/* PE/WIN32; added routines to get the subsystem type, heap and/or stack   parameters which may be input from the command line */typedef struct{  void *ptr;  int size;  int value;  char *symbol;  int inited;} definfo;#define D(field,symbol,def)  {&pe.field,sizeof(pe.field), def, symbol,0}static definfo init[] ={  /* imagebase must be first */#define IMAGEBASEOFF 0  D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE),#define DLLOFF 1  {&dll, sizeof(dll), 0, "__dll__", 0},  D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT),  D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT),  D(MajorOperatingSystemVersion,"__major_os_version__", 4),  D(MinorOperatingSystemVersion,"__minor_os_version__", 0),  D(MajorImageVersion,"__major_image_version__", 1),  D(MinorImageVersion,"__minor_image_version__", 0),#ifdef TARGET_IS_armpe  D(MajorSubsystemVersion,"__major_subsystem_version__", 3),#else  D(MajorSubsystemVersion,"__major_subsystem_version__", 4),#endif  D(MinorSubsystemVersion,"__minor_subsystem_version__", 0),  D(Subsystem,"__subsystem__", ${SUBSYSTEM}),  D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x200000),  D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000),  D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000),  D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000),  D(LoaderFlags,"__loader_flags__", 0x0),  { NULL, 0, 0, NULL, 0 }};static voidgld_${EMULATION_NAME}_list_options (file)     FILE * file;{  fprintf (file, _("  --base_file <basefile>             Generate a base file for relocatable DLLs\n"));  fprintf (file, _("  --dll                              Set image base to the default for DLLs\n"));  fprintf (file, _("  --file-alignment <size>            Set file alignment\n"));  fprintf (file, _("  --heap <size>                      Set initial size of the heap\n"));  fprintf (file, _("  --image-base <address>             Set start address of the executable\n"));  fprintf (file, _("  --major-image-version <number>     Set version number of the executable\n"));  fprintf (file, _("  --major-os-version <number>        Set minimum required OS version\n"));  fprintf (file, _("  --major-subsystem-version <number> Set minimum required OS subsystem version\n"));  fprintf (file, _("  --minor-image-version <number>     Set revision number of the executable\n"));  fprintf (file, _("  --minor-os-version <number>        Set minimum required OS revision\n"));  fprintf (file, _("  --minor-subsystem-version <number> Set minimum required OS subsystem revision\n"));  fprintf (file, _("  --section-alignment <size>         Set section alignment\n"));  fprintf (file, _("  --stack <size>                     Set size of the initial stack\n"));  fprintf (file, _("  --subsystem <name>[:<version>]     Set required OS subsystem [& version]\n"));  fprintf (file, _("  --support-old-code                 Support interworking with old code\n"));  fprintf (file, _("  --thumb-entry=<symbol>             Set the entry point to be Thumb <symbol>\n"));#ifdef DLL_SUPPORT  fprintf (file, _("  --add-stdcall-alias                Export symbols with and without @nn\n"));  fprintf (file, _("  --disable-stdcall-fixup            Don't link _sym to _sym@nn\n"));  fprintf (file, _("  --enable-stdcall-fixup             Link _sym to _sym@nn without warnings\n"));  fprintf (file, _("  --exclude-symbols sym,sym,...      Exclude symbols from automatic export\n"));  fprintf (file, _("  --exclude-libs lib,lib,...         Exclude libraries from automatic export\n"));	  fprintf (file, _("  --export-all-symbols               Automatically export all globals to DLL\n"));  fprintf (file, _("  --kill-at                          Remove @nn from exported symbols\n"));  fprintf (file, _("  --out-implib <file>                Generate import library\n"));  fprintf (file, _("  --output-def <file>                Generate a .DEF file for the built DLL\n"));  fprintf (file, _("  --warn-duplicate-exports           Warn about duplicate exports.\n"));  fprintf (file, _("  --compat-implib                    Create backward compatible import libs;\n\                                       create __imp_<SYMBOL> as well.\n"));  fprintf (file, _("  --enable-auto-image-base           Automatically choose image base for DLLs\n\                                       unless user specifies one\n"));  fprintf (file, _("  --disable-auto-image-base          Do not auto-choose image base. (default)\n"));  fprintf (file, _("  --dll-search-prefix=<string>       When linking dynamically to a dll without an\n\                                       importlib, use <string><basename>.dll \n\                                       in preference to lib<basename>.dll \n"));  fprintf (file, _("  --enable-auto-import               Do sophistcated linking of _sym to \n\                                       __imp_sym for DATA references\n"));  fprintf (file, _("  --disable-auto-import              Do not auto-import DATA items from DLLs\n"));  fprintf (file, _("  --enable-extra-pe-debug            Enable verbose debug output when building\n\                                       or linking to DLLs (esp. auto-import)\n"));#endif}static voidset_pe_name (name, val)     char *name;     long val;{  int i;  /* Find the name and set it. */  for (i = 0; init[i].ptr; i++)    {      if (strcmp (name, init[i].symbol) == 0)	{	  init[i].value = val;	  init[i].inited = 1;	  return;	}    }  abort();}static voidset_pe_subsystem (){  const char *sver;  int len;  int i;  static const struct    {      const char *name;      const int value;      const char *entry;    }  v[] =    {      { "native", 1, "NtProcessStartup" },#if defined TARGET_IS_mipspe || defined TARGET_IS_armpe      { "windows", 2, "WinMainCRTStartup" },#else      { "windows", 2, "WinMainCRTStartup" },#endif      { "console", 3, "mainCRTStartup" },#if 0      /* The Microsoft linker does not recognize this.  */      { "os2", 5, "" },#endif      { "posix", 7, "__PosixProcessStartup"},      { "wince", 9, "_WinMainCRTStartup" },      { 0, 0, 0 }    };  sver = strchr (optarg, ':');  if (sver == NULL)    len = strlen (optarg);  else    {      char *end;      len = sver - optarg;      set_pe_name ("__major_subsystem_version__",		   strtoul (sver + 1, &end, 0));      if (*end == '.')	set_pe_name ("__minor_subsystem_version__",		     strtoul (end + 1, &end, 0));      if (*end != '\0')	einfo (_("%P: warning: bad version number in -subsystem option\n"));    }  for (i = 0; v[i].name; i++)    {      if (strncmp (optarg, v[i].name, len) == 0	  && v[i].name[len] == '\0')	{	  const char *initial_symbol_char;	  const char *entry;	  set_pe_name ("__subsystem__", v[i].value);	  initial_symbol_char = ${INITIAL_SYMBOL_CHAR};	  if (*initial_symbol_char == '\0')	    entry = v[i].entry;	  else	    {	      char *alc_entry;	      /* lang_add_entry expects its argument to be permanently		 allocated, so we don't free this string.  */	      alc_entry = xmalloc (strlen (initial_symbol_char)				   + strlen (v[i].entry)				   + 1);	      strcpy (alc_entry, initial_symbol_char);	      strcat (alc_entry, v[i].entry);	      entry = alc_entry;	    }	  lang_add_entry (entry, 0);	  return;	}    }  einfo (_("%P%F: invalid subsystem type %s\n"), optarg);}static voidset_pe_value (name)     char *name;{  char *end;  set_pe_name (name,  strtoul (optarg, &end, 0));  if (end == optarg)    einfo (_("%P%F: invalid hex number for PE parameter '%s'\n"), optarg);  optarg = end;}static voidset_pe_stack_heap (resname, comname)     char *resname;     char *comname;{  set_pe_value (resname);

⌨️ 快捷键说明

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