This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gcc/collect2.c patch


> These are going to need a little work.

I've attached my reworked version. Here is a ChangeLog:

* gcc/config/i386/xm-djgpp.h (COLLECT2_INIT_SYS_DEPENDANT): 
New macro.
* gcc/collect2.c (main): Use it.
  (pexecute_pid): New variable. Holds return value from call to pexecute.
  (collect2_execute): Rework to use pexecute instead of fork.
  (collect2_wait): Use pwait() instead of wait().


--- 
Mark Elbrecht, snowball3@usa.net
http://snowball.digitalspace.net/

*** gcc/collect2.c.orig	Thu Mar 18 07:29:02 1999
--- gcc/collect2.c	Wed Mar 24 11:10:34 1999
*************** struct obstack temporary_obstack;
*** 225,230 ****
--- 225,233 ----
  struct obstack permanent_obstack;
  char * temporary_firstobj;
  
+ /* Holds the return value of pexecute.  */
+ int pexecute_pid;
+ 
  /* Defined in the automatically-generated underscore.c.  */
  extern int prepends_underscore;
  
*************** main (argc, argv)
*** 999,1004 ****
--- 1002,1012 ----
    int first_file;
    int num_c_args	= argc+9;
  
+ /* Perform system dependant initialization, if neccessary.  */
+ #if defined (COLLECT2_INIT_SYS_DEPENDANT)
+ COLLECT2_INIT_SYS_DEPENDANT;
+ #endif
+ 
  #ifdef HAVE_LC_MESSAGES
    setlocale (LC_MESSAGES, "");
  #endif
*************** collect_wait (prog)
*** 1661,1667 ****
  {
    int status;
  
!   wait (&status);
    if (status)
      {
        if (WIFSIGNALED (status))
--- 1669,1675 ----
  {
    int status;
  
!   pwait (pexecute_pid, &status, 0);
    if (status)
      {
        if (WIFSIGNALED (status))
*************** do_wait (prog)
*** 1695,1701 ****
  }
  
  
! /* Fork and execute a program, and wait for the reply.  */
  
  void
  collect_execute (prog, argv, redir)
--- 1703,1709 ----
  }
  
  
! /* Execute a program, and wait for the reply.  */
  
  void
  collect_execute (prog, argv, redir)
*************** collect_execute (prog, argv, redir)
*** 1703,1709 ****
       char **argv;
       char *redir;
  {
!   int pid;
  
    if (vflag || debug)
      {
--- 1711,1721 ----
       char **argv;
       char *redir;
  {
!   char *errmsg_fmt;
!   char *errmsg_arg;
!   int redir_handle = -1;
!   int stdout_save = -1;
!   int stderr_save = -1;
  
    if (vflag || debug)
      {
*************** collect_execute (prog, argv, redir)
*** 1730,1753 ****
    if (argv[0] == 0)
      fatal ("cannot find `%s'", prog);
  
!   pid = vfork ();
!   if (pid == -1)
!     fatal_perror (VFORK_STRING);
  
!   if (pid == 0)			/* child context */
      {
!       if (redir)
! 	{
! 	  unlink (redir);
! 	  if (freopen (redir, "a", stdout) == NULL)
! 	    fatal_perror ("freopen stdout %s", redir);
! 	  if (freopen (redir, "a", stderr) == NULL)
! 	    fatal_perror ("freopen stderr %s", redir);
! 	}
  
!       execvp (argv[0], argv);
!       fatal_perror ("execvp %s", prog);
      }
  }
  
  static void
--- 1742,1782 ----
    if (argv[0] == 0)
      fatal ("cannot find `%s'", prog);
  
!   if (redir)
!     {
!       /* Open response file.  */
!       redir_handle = open (redir, O_WRONLY | O_TRUNC | O_CREAT);
! 
!       /* Duplicate the stdout and stderr file handles
!          so they can be restored later.  */
!       stdout_save = dup (STDOUT_FILENO);
!       if (stdout_save == -1)
!         fatal_perror ("redirecting stdout: %s", redir);
!       stderr_save = dup (STDERR_FILENO);
!       if (stderr_save == -1)
!         fatal_perror ("redirecting stdout: %s", redir);
  
!       /* Redirect stdout & stderr to our response file.  */
!       dup2(redir_handle, STDOUT_FILENO);
!       dup2(redir_handle, STDERR_FILENO);
!     }
! 
!   pexecute_pid = pexecute(argv[0], argv, argv[0], NULL,
!                      &errmsg_fmt, &errmsg_arg,
!                      (PEXECUTE_FIRST | PEXECUTE_LAST | PEXECUTE_SEARCH));
! 
!   if (redir)
      {
!       /* Restore stdout and stderr to their previous settings.  */
!       dup2 (stdout_save, STDOUT_FILENO);
!       dup2 (stderr_save, STDERR_FILENO);
  
!       /* Close reponse file.  */
!       close (redir_handle);
      }
+ 
+  if (pexecute_pid == -1)
+    fatal_perror (errmsg_fmt, errmsg_arg);
  }
  
  static void
*** gcc/config/i386/xm-djgpp.h.orig	Wed Mar 17 23:23:50 1999
--- gcc/config/i386/xm-djgpp.h	Wed Mar 24 11:10:16 1999
*************** Boston, MA 02111-1307, USA.  */
*** 34,36 ****
--- 34,41 ----
  
  #define LIBSTDCXX "-lstdcxx"
  
+ /* System dependant initialization for collect2
+    to tell system() to act like Unix.  */
+ #define COLLECT2_INIT_SYS_DEPENDANT \
+ do {__system_flags |= (__system_allow_multiple_cmds | __system_emulate_chdir); } while (0)
+ 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]