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

📄 vms-ld.c

📁 gcc-you can use this code to learn something about gcc, and inquire further into linux,
💻 C
📖 第 1 页 / 共 2 页
字号:
  FILE *optfile;  char *cwd = getcwd (0, 1024);  char *optfilename;  devptr = strchr (cwd, ':');  devlen = (devptr - cwd) + 1;  strncpy (cwdev, cwd, devlen);  cwdev [devlen] = '\0';  search_dirs = xstrdup (system_search_dirs);  addarg ("link");  /* Pass to find args that have to be append first.  */  preprocess_args (&argc , argv);  /* Pass to find the rest of the args.  */  process_args (&argc , argv);  /* Create a temp file to hold args, otherwise we can easily exceed the VMS     command line length limits.  */  optfilename = alloca (strlen ("LDXXXXXX") + 1);  strcpy (optfilename, "LDXXXXXX");  optfd = mkstemp (optfilename);  getcwd (optfilefullname, 256, 1); /* VMS style cwd.  */  strcat (optfilefullname, optfilename);  strcat (optfilefullname, ".");  optfile = fdopen (optfd, "w");  /* Write out the IDENTIFICATION argument first so that it can be overridden     by an options file.  */  for (i = 1; i < argc; i++)    {      int arg_len = strlen (argv[i]);      if (arg_len > 6 && strncasecmp (argv[i], "IDENT=", 6) == 0)	{	  /* Comes from command line. If present will always appear before	     IDENTIFICATION=... and will override.  */	  if (!ident)	    ident = 1;	}      else if (arg_len > 15	       && strncasecmp (argv[i], "IDENTIFICATION=", 15) == 0)	{	  /* Comes from pragma Ident ().  */	  if (!ident)	    {	      fprintf (optfile, "case_sensitive=yes\n");	      fprintf (optfile, "IDENTIFICATION=\"%15.15s\"\n", &argv[i][15]);	      fprintf (optfile, "case_sensitive=NO\n");	      ident = 1;	    }	}    }  for (i = 1; i < argc; i++)    {      int arg_len = strlen (argv[i]);      if (strcmp (argv[i], "-o") == 0)	i++;      else if (arg_len > 2 && strncmp (argv[i], "-l", 2) == 0)	{	  const char *libname = expand_lib (&argv[i][2]);	  const char *ext;	  int len;	  if ((len = strlen (libname)) > 0)	    {	      char buff [256];	      if (len > 4 && strcasecmp (&libname [len-4], ".exe") == 0)		ext = "/shareable";	      else		ext = "/library";	      if (libname[0] == '[')		sprintf (buff, "%s%s", cwdev, libname);	      else		sprintf (buff, "%s", libname);	      fprintf (optfile, "%s%s\n", buff, ext);	    }	}      else if (strcmp (argv[i], "-v" ) == 0	       || strncmp (argv[i], "-g", 2 ) == 0	       || strcmp (argv[i], "-static" ) == 0	       || strcmp (argv[i], "-map" ) == 0	       || strcmp (argv[i], "-save-temps") == 0	       || strcmp (argv[i], "--noinhibit-exec") == 0	       || (arg_len > 2 && strncmp (argv[i], "-L", 2) == 0)	       || (arg_len >= 6 && strncmp (argv[i], "-share", 6) == 0))	;      else if (arg_len > 1 && argv[i][0] == '@')	{	  FILE *atfile;	  char *ptr, *ptr1;	  struct stat statbuf;	  char *buff;	  int len;	  if (stat (&argv[i][1], &statbuf))	    {	      fprintf (stderr, "Couldn't open linker response file: %s\n",		       &argv[i][1]);	      exit (1);	    }	  buff = xmalloc (statbuf.st_size + 1);	  atfile = fopen (&argv[i][1], "r");	  fgets (buff, statbuf.st_size + 1, atfile);	  fclose (atfile);	  len = strlen (buff);	  if (buff [len - 1] == '\n')	    {	      buff [len - 1] = 0;	      len--;	    }	  ptr = buff;	  do	  {	     ptr1 = strchr (ptr, ' ');	     if (ptr1)	       *ptr1 = 0;	     ptr = to_host_file_spec (ptr);	     if (ptr[0] == '[')	       fprintf (optfile, "%s%s\n", cwdev, ptr);	     else	       fprintf (optfile, "%s\n", ptr);	     ptr = ptr1 + 1;	  } while (ptr1);	}      /* Unix style file specs and VMS style switches look alike, so assume an	 arg consisting of one and only one slash, and that being first, is	 really a switch.  */      else if ((argv[i][0] == '/') && (strchr (&argv[i][1], '/') == 0))	addarg (argv[i]);      else if (arg_len > 4	       && strncasecmp (&argv[i][arg_len-4], ".OPT", 4) == 0)	{	  FILE *optfile1;	  char buff [256];	  optfile1 = fopen (argv[i], "r");	  while (fgets (buff, 256, optfile1))	    fputs (buff, optfile);	  fclose (optfile1);	}      else if (arg_len > 7 && strncasecmp (argv[i], "GSMATCH", 7) == 0)	fprintf (optfile, "%s\n", argv[i]);      else if (arg_len > 6 && strncasecmp (argv[i], "IDENT=", 6) == 0)	{	  /* Comes from command line and will override pragma.  */	  fprintf (optfile, "case_sensitive=yes\n");	  fprintf (optfile, "IDENT=\"%15.15s\"\n", &argv[i][6]);	  fprintf (optfile, "case_sensitive=NO\n");	  ident = 1;	}      else if (arg_len > 15	       && strncasecmp (argv[i], "IDENTIFICATION=", 15) == 0)	;      else	{	  /* Assume filename arg.  */	  const char *addswitch = "";	  char buff [256];	  int buff_len;	  int is_cld = 0;	  argv[i] = to_host_file_spec (argv[i]);	  arg_len = strlen (argv[i]);	  if (arg_len > 4 && strcasecmp (&argv[i][arg_len-4], ".exe") == 0)	    addswitch = "/shareable";	  if (arg_len > 4 && strcasecmp (&argv[i][arg_len-4], ".cld") == 0)	    {	      addswitch = "/shareable";	      is_cld = 1;	    }	  if (arg_len > 2 && strcasecmp (&argv[i][arg_len-2], ".a") == 0)	    addswitch = "/lib";	  if (arg_len > 4 && strcasecmp (&argv[i][arg_len-4], ".olb") == 0)	    addswitch = "/lib";	  if (argv[i][0] == '[')	    sprintf (buff, "%s%s%s\n", cwdev, argv[i], addswitch);	  else if (strchr (argv[i], ':'))	    sprintf (buff, "%s%s\n", argv[i], addswitch);	  else	    sprintf (buff, "%s%s%s\n", cwd, argv[i], addswitch);	  buff_len = strlen (buff);	  if (buff_len >= 15	      && strcasecmp (&buff[buff_len - 15], "vms-dwarf2eh.o\n") == 0)	    vmsdwarf2ehspec = xstrdup (buff);	  else if (buff_len >= 13	      && strcasecmp (&buff[buff_len - 13],"vms-dwarf2.o\n") == 0)	    vmsdwarf2spec = xstrdup (buff);	  else if (is_cld)	    {	      addarg (buff);	      addarg (",");	    }	  else	    fprintf (optfile, buff);	}    }#if 0  if (share)    fprintf (optfile, "symbol_vector=(main=procedure)\n");#endif  if (vmsdwarf2ehspec)    {      fprintf (optfile, "case_sensitive=yes\n");      fprintf (optfile, "cluster=DWARF2eh,,,%s", vmsdwarf2ehspec);      fprintf (optfile, "collect=DWARF2eh,eh_frame\n");      fprintf (optfile, "case_sensitive=NO\n");    }  if (debug && vmsdwarf2spec)    {      fprintf (optfile, "case_sensitive=yes\n");      fprintf (optfile, "cluster=DWARF2debug,,,%s", vmsdwarf2spec);      fprintf (optfile, "collect=DWARF2debug,debug_abbrev,debug_aranges,-\n");      fprintf (optfile, " debug_frame,debug_info,debug_line,debug_loc,-\n");      fprintf (optfile, " debug_macinfo,debug_pubnames,debug_str,-\n");      fprintf (optfile, " debug_zzzzzz\n");      fprintf (optfile, "case_sensitive=NO\n");    }  if (debug && share)    {      fprintf (optfile, "case_sensitive=yes\n");      fprintf (optfile, "symbol_vector=(-\n");      fprintf (optfile,	       "%s$DWARF2.DEBUG_ABBREV/$dwarf2.debug_abbrev=DATA,-\n",	       sharefilename);      fprintf (optfile,	       "%s$DWARF2.DEBUG_ARANGES/$dwarf2.debug_aranges=DATA,-\n",	       sharefilename);      fprintf (optfile, "%s$DWARF2.DEBUG_FRAME/$dwarf2.debug_frame=DATA,-\n",	       sharefilename);      fprintf (optfile, "%s$DWARF2.DEBUG_INFO/$dwarf2.debug_info=DATA,-\n",	       sharefilename);      fprintf (optfile, "%s$DWARF2.DEBUG_LINE/$dwarf2.debug_line=DATA,-\n",	       sharefilename);      fprintf (optfile, "%s$DWARF2.DEBUG_LOC/$dwarf2.debug_loc=DATA,-\n",	       sharefilename);      fprintf (optfile,	       "%s$DWARF2.DEBUG_MACINFO/$dwarf2.debug_macinfo=DATA,-\n",	       sharefilename);      fprintf (optfile,	       "%s$DWARF2.DEBUG_PUBNAMES/$dwarf2.debug_pubnames=DATA,-\n",	       sharefilename);      fprintf (optfile, "%s$DWARF2.DEBUG_STR/$dwarf2.debug_str=DATA,-\n",	       sharefilename);      fprintf (optfile, "%s$DWARF2.DEBUG_ZZZZZZ/$dwarf2.debug_zzzzzz=DATA)\n",	       sharefilename);      fprintf (optfile, "case_sensitive=NO\n");    }  fclose (optfile);  addarg (optfilefullname);  addarg ("/opt");  addarg (NULL);  if (verbose)    {      int i;      for (i = 0; i < link_arg_index; i++)	printf ("%s ", link_args [i]);      putchar ('\n');    }  {    int i;    int len = 0;    for (i = 0; link_args[i]; i++)      len = len + strlen (link_args[i]) + 1;    {      char *allargs = (char *) alloca (len + 1);      Descr cmd;      int status;      int status1 = 1;      for (i = 0; i < len + 1; i++)	allargs [i] = 0;      for (i = 0; link_args [i]; i++)	{	  strcat (allargs, link_args [i]);	  strcat (allargs, " ");	}      cmd.adr = allargs;      cmd.len = len;      cmd.mbz = 0;      i = LIB$SPAWN (&cmd, 0, 0, 0, 0, 0, &status);      if ((i & 1) != 1)	{	  LIB$SIGNAL (i);	  exit (1);	}      if (debug && !share)	{	  strcpy (allargs, "@gnu:[bin]set_exe ");	  strcat (allargs, exefilename);	  strcat (allargs, " /nodebug /silent");	  len = strlen (allargs);	  cmd.adr = allargs;	  cmd.len = len;	  cmd.mbz = 0;	  if (verbose)	    printf (allargs);	  i = LIB$SPAWN (&cmd, 0, 0, 0, 0, 0, &status1);	  if ((i & 1) != 1)	    {	      LIB$SIGNAL (i);	      exit (1);	    }	}      if (!save_temps)	remove (optfilefullname);      if ((status & 1) == 1 && (status1 & 1) == 1)	exit (0);      if (exefilename && inhibit_exec == 1)	remove (exefilename);      exit (1);    }  }}static char new_host_filespec [255];static char filename_buff [256];static inttranslate_unix (name, type)     char *name;     int type ATTRIBUTE_UNUSED;{  strcpy (filename_buff, name);  return 0;}static char *to_host_file_spec (filespec)     char *filespec;{  strcpy (new_host_filespec, "");  if (strchr (filespec, ']') || strchr (filespec, ':'))    strcpy (new_host_filespec, filespec);  else    {      decc$to_vms (filespec, translate_unix, 1, 1);      strcpy (new_host_filespec, filename_buff);    }  return new_host_filespec;}

⌨️ 快捷键说明

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