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]

COLLECT2 patches v2


Here's my second version of collect2 patches taking into account the 
suggestions offered yesterday.

Changes:

collect2.c: Include prototypes for pexecute and pwait. Include sys/wait.h 
when HAVE_SYS_WAIT_H is defined.
            (collect_wait) Use pwait instead of wait.
            (collect_execute) Rewrite to use pexecute instead of execvp and 
_spawnvp and remove conditionized code.
            (main) For DJGPP, set flags for system() to act more like Unix.


I've attached a patch for gcc/Makefile.in to add pexecute.o to collect2's 
dependencies and a patch for gcc/collect2.c that makes the changes 
described above.

Comments are appreciated.

Mark

-- 
Mark Elbrecht snowball3@usa.net
http://members.xoom.com/snowball3/

*** Makefile.in.orig	Mon Nov 30 12:29:38 1998
--- Makefile.in	Fri Oct 30 12:32:20 1998
***************
*** 1289,1299 ****
  mbchar.o: mbchar.c $(CONFIG_H) system.h gansidecl.h mbchar.h
  
  collect2$(exeext): collect2.o tlink.o hash.o cplus-dem.o underscore.o \
! 	version.o choose-temp.o mkstemp.o $(LIBDEPS)
  # Don't try modifying collect2 (aka ld) in place--it might be linking this.
  	-rm -f collect2$(exeext)
  	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ collect2.o tlink.o hash.o \
! 	  cplus-dem.o underscore.o version.o choose-temp.o mkstemp.o $(LIBS)
  
  collect2.o : collect2.c $(CONFIG_H) system.h gansidecl.h gstab.h \
  	$(srcdir)/../include/obstack.h $(DEMANGLE_H)
--- 1289,1300 ----
  mbchar.o: mbchar.c $(CONFIG_H) system.h gansidecl.h mbchar.h
  
  collect2$(exeext): collect2.o tlink.o hash.o cplus-dem.o underscore.o \
! 	version.o choose-temp.o mkstemp.o pexecute.o $(LIBDEPS)
  # Don't try modifying collect2 (aka ld) in place--it might be linking this.
  	-rm -f collect2$(exeext)
  	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ collect2.o tlink.o hash.o \
! 	  cplus-dem.o underscore.o version.o choose-temp.o mkstemp.o \
!         pexecute.o $(LIBS)
  
  collect2.o : collect2.c $(CONFIG_H) system.h gansidecl.h gstab.h \
  	$(srcdir)/../include/obstack.h $(DEMANGLE_H)
*** collect2.c.orig	Sun Nov 29 08:49:14 1998
--- collect2.c	Fri Oct 30 12:20:08 1998
***************
*** 30,43 ****
  #include <signal.h>
  #include <sys/stat.h>
  
  #define COLLECT
  
  #include "demangle.h"
  #include "obstack.h"
  #include "gansidecl.h"
! #ifdef __CYGWIN32__
! #include <process.h>
! #endif
  
  /* Obstack allocation and deallocation routines.  */
  #define obstack_chunk_alloc xmalloc
--- 30,56 ----
  #include <signal.h>
  #include <sys/stat.h>
  
+ #if defined(HAVE_SYS_WAIT_H)
+ /* Defines WIFSIGNALED, WTERMSIG, etc. for DJGPP */
+ #include <sys/wait.h>
+ #endif
+ 
  #define COLLECT
  
  #include "demangle.h"
  #include "obstack.h"
  #include "gansidecl.h"
! 
! /* Prototypes for pexecute.c */
! extern int pexecute PROTO ((const char *, char * const *, const char *,
! 			    const char *, char **, char **, int));
! extern int pwait PROTO ((int, int *, int));
! 
! /* Flag arguments to pexecute.  */
! #define PEXECUTE_FIRST   1
! #define PEXECUTE_LAST    2
! #define PEXECUTE_SEARCH  4
! #define PEXECUTE_VERBOSE 8
  
  /* Obstack allocation and deallocation routines.  */
  #define obstack_chunk_alloc xmalloc
***************
*** 158,163 ****
--- 171,179 ----
  #define SCAN_LIBRARIES
  #endif
  
+ /* Pid of the process spawned by pexecute. */
+ int pid;
+ 
  #ifdef USE_COLLECT2
  int do_collecting = 1;
  #else
***************
*** 995,1000 ****
--- 1011,1021 ----
    int first_file;
    int num_c_args	= argc+9;
  
+ #ifdef __DJGPP__
+ /* These flags allow DJGPP's system() to act more Unix-like. */
+   __system_flags |= (__system_allow_multiple_cmds | __system_emulate_chdir);
+ #endif
+ 
  #ifdef DEBUG
    debug = 1;
  #endif
***************
*** 1644,1650 ****
  {
    int status;
  
!   wait (&status);
    if (status)
      {
        if (WIFSIGNALED (status))
--- 1665,1671 ----
  {
    int status;
  
!   pwait (pid, &status, 0);
    if (status)
      {
        if (WIFSIGNALED (status))
***************
*** 1678,1684 ****
  }
  
  
! /* Fork and execute a program, and wait for the reply.  */
  
  void
  collect_execute (prog, argv, redir)
--- 1699,1705 ----
  }
  
  
! /* Execute a program, and wait for the reply.  */
  
  void
  collect_execute (prog, argv, redir)
***************
*** 1686,1692 ****
       char **argv;
       char *redir;
  {
!   int pid;
  
    if (vflag || debug)
      {
--- 1707,1717 ----
       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)
      {
***************
*** 1713,1748 ****
    if (argv[0] == 0)
      fatal ("cannot find `%s'", prog);
  
! #ifndef __CYGWIN32__
!   pid = vfork ();
!   if (pid == -1)
!     {
! #ifdef vfork
!       fatal_perror ("fork");
! #else
!       fatal_perror ("vfork");
! #endif
!     }
  
!   if (pid == 0)			/* child context */
!     {
!       if (redir)
! 	{
! 	  unlink (redir);
! 	  if (freopen (redir, "a", stdout) == NULL)
! 	    fatal_perror ("redirecting stdout: %s", redir);
! 	  if (freopen (redir, "a", stderr) == NULL)
! 	    fatal_perror ("redirecting stderr: %s", redir);
! 	}
  
-       execvp (argv[0], argv);
-       fatal_perror ("executing %s", prog);
-     }
- #else
-   pid = _spawnvp (_P_NOWAIT, argv[0], argv);
    if (pid == -1)
!     fatal ("spawnvp failed");
! #endif
  }
  
  static void
--- 1738,1774 ----
    if (argv[0] == 0)
      fatal ("cannot find `%s'", prog);
  
!   if (redir)
!   {
!     unlink (redir);
!     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);
!   }
! 
!   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);
!   }
  
    if (pid == -1)
!     fatal_perror (errmsg_fmt, errmsg_arg);
  }
  
  static void

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