beos.em

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

EM
842
字号
# This shell script emits a C file. -*- C -*-# It does some substitutions.cat >e${EMULATION_NAME}.c <<EOF/* This file is part of GLD, the Gnu Linker.   Copyright 1995, 1996, 1997, 1998, 2000 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. */   #include "bfd.h"#include "sysdep.h"#include "bfdlink.h"#include "getopt.h"#include "libiberty.h"#include "ld.h"#include "ldmain.h"#include "ldgram.h"#include "ldexp.h"#include "ldlang.h"#include "ldfile.h"#include "ldemul.h"#include "ldlex.h"#include "ldmisc.h"#include "ldctor.h"#include "coff/internal.h"#include "../bfd/libcoff.h"#define TARGET_IS_${EMULATION_NAME}static 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}_before_allocation PARAMS ((void));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 **));#if 0 /* argument to qsort so don't prototype */static int sort_by_file_name PARAMS ((void *, void *));static int sort_by_section_name PARAMS ((void *, void *));#endifstatic lang_statement_union_type **sort_sections_1  PARAMS ((lang_statement_union_type **, lang_statement_union_type *, int,	   int (*)()));static void sort_sections PARAMS ((lang_statement_union_type *));static struct internal_extra_pe_aouthdr pe;static int dll;extern const char *output_filename;static voidgld_${EMULATION_NAME}_before_parse(){  output_filename = "a.exe";  ldfile_output_architecture = bfd_arch_${ARCH};}/* 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)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},   {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__", BEOS_EXE_IMAGE_BASE),#define DLLOFF 1  {&dll, sizeof(dll), 0, "__dll__"},  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),  D(MajorSubsystemVersion,"__major_subsystem_version__", 4),  D(MinorSubsystemVersion,"__minor_subsystem_version__", 0),  D(Subsystem,"__subsystem__", 3),  D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x2000000),  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 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" },      { "windows", 2, "_WinMainCRTStartup" },      { "wwindows", 2, "_wWinMainCRTStartup" },      { "console", 3, "_mainCRTStartup" },      { "wconsole", 3, "_wmainCRTStartup" },#if 0      /* The Microsoft linker does not recognize this.  */      { "os2", 5, "" },#endif      { "posix", 7, "___PosixProcessStartup"},      { 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')	{	  set_pe_name ("__subsystem__", v[i].value);	  /* If the subsystem is windows, we use a different entry	     point.  We also register the entry point as an undefined	     symbol. from lang_add_entry() The reason we do	     this is so that the user	     doesn't have to because they would have to use the -u	     switch if they were specifying an entry point other than	     _mainCRTStartup.  Specifically, if creating a windows	     application, entry point _WinMainCRTStartup must be	     specified.  What I have found for non console	     applications (entry not _mainCRTStartup) is that the .obj	     that contains mainCRTStartup is brought in since 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, adding -u with the entry point	     name specified forces the correct .obj to be used.  We	     can avoid making the user do this by always adding the	     entry point name as an undefined symbol.  */	  lang_add_entry (v[i].entry, 1);	  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);  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)	{	  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;    }  return 1;}/* 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)	init[IMAGEBASEOFF].value = BEOS_DLL_IMAGE_BASE;      else	init[IMAGEBASEOFF].value = BEOS_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_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();    }  /* Restore the pointer. */  stat_ptr = save;    if (pe.FileAlignment >      pe.SectionAlignment)    {      einfo ("%P: warning, file alignment > section alignment.\n");    }

⌨️ 快捷键说明

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