This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
COLLECT2 patches (v3)
- To: egcs-patches at cygnus dot com, jason at cygnus dot com
- Subject: COLLECT2 patches (v3)
- From: "Mark E." <snowball3 at usa dot net>
- Date: Sat, 31 Oct 1998 10:34:23 +0000
These are my latest collect2 patches that generalize the code enough so
DJGPP can use the template repository. This patch corrects not closing the
redirect file previously opened. The patch is based on the Oct. 30th version
of collect2.c.
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) Now use pexecute instead of execvp and
_spawnvp. Remove conditionalized code.
(main) For DJGPP, set flags for system() to act more like Unix.
and here's the patch for collect2.c:
*** collect2.c.orig Sun Nov 29 08:49:14 1998
--- collect2.c Sat Oct 31 09:28:24 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,1775 ----
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);
! close(redir_handle);
! }
if (pid == -1)
! fatal_perror (errmsg_fmt, errmsg_arg);
}
static void
--
Mark Elbrecht snowball3@usa.net
http://members.xoom.com/snowball3/