This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
(3/8) i386-mingw32 fixes: libiberty
- To: egcs-bugs at cygnus dot com
- Subject: (3/8) i386-mingw32 fixes: libiberty
- From: Mumit Khan <khan at xraylith dot wisc dot edu>
- Date: Sun, 21 Dec 1997 02:41:11 -0600
Patch for egcs toplevel to enable i386-mingw32 support. Note that the
copy of choose-temp.c in gcc doesn't need the same fixes due to the
improved auto-configuration of gcc-2.8.0.
Sat Nov 29 12:34:38 1997 Mumit Khan <khan@xraylith.wisc.edu>
Add mingw32 support (_WIN32 && !__CYGWIN32__). Some of the these
patches are slightly modifies versions of J.J.vanderHeijden's
<J.J.vanderHeijden@student.utwente.nl> work archived at
See <http://agnes.dida.physik.uni-essen.de/~janjaap/mingw32/>.
* pexecute.c (pexecute): New function for mingw32. Supports pipes.
(pwait): New function for mingw32 that fixes the status code from
MS CRTDLL to conform to the usual wait macros. Originally from
Jan-Jaap VanderHeijden <J.J.vanderHeijden@student.utwente.nl>.
* choose-temp.c: Change order of includes so that config.h can
define NO_SYS_FILE_H.
* config.table (i[3456]86-*-mingw32*): Support for i386-mingw32.
* config/mt-mingw32: New file.
* xmalloc.c (first_break): Not used for mingw32.
(xmalloc_set_program_name): Don't use sbrk on mingw32.
(xmalloc): Likewise.
(xrealloc): Likewise.
Index: egcs/libiberty/choose-temp.c
diff -c egcs/libiberty/choose-temp.c:1.1.1.1 egcs/libiberty/choose-temp.c:1.2
*** egcs/libiberty/choose-temp.c:1.1.1.1 Sat Dec 20 12:11:55 1997
--- egcs/libiberty/choose-temp.c Sat Dec 20 18:38:40 1997
***************
*** 22,38 ****
/* This file lives in at least two places: libiberty and gcc.
Don't change one without the other. */
- #ifndef NO_SYS_FILE_H
- #include <sys/types.h>
- #include <sys/file.h> /* May get R_OK, etc. on some systems. */
- #endif
-
- #ifndef R_OK
- #define R_OK 4
- #define W_OK 2
- #define X_OK 1
- #endif
-
#include <stdio.h> /* May get P_tmpdir. */
#ifdef IN_GCC
--- 22,27 ----
***************
*** 50,55 ****
--- 39,56 ----
#ifndef DIR_SEPARATOR
#define DIR_SEPARATOR '/'
#endif
+
+ #ifndef NO_SYS_FILE_H
+ #include <sys/types.h>
+ #include <sys/file.h> /* May get R_OK, etc. on some systems. */
+ #endif
+
+ #ifndef R_OK
+ #define R_OK 4
+ #define W_OK 2
+ #define X_OK 1
+ #endif
+
/* On MSDOS, write temp files in current dir
because there's no place else we can expect to use. */
Index: egcs/libiberty/config.table
diff -c egcs/libiberty/config.table:1.1.1.1 egcs/libiberty/config.table:1.2
*** egcs/libiberty/config.table:1.1.1.1 Sat Dec 20 12:11:55 1997
--- egcs/libiberty/config.table Sat Dec 20 18:38:41 1997
***************
*** 29,34 ****
--- 29,41 ----
# autoconfiguration scheme does not work.
frag=mt-vxworks5
;;
+
+ i[3456]86-*-mingw32*)
+ # Mingw32 does not require strerror.o from REQUIRED_OFILES.
+ # Worse: it will not compile it because of an incompatible sys_errlist
+ # definition.
+ frag=mt-mingw32
+ ;;
esac
# Try to handle funky case of solaris 2 -> sun 4.
Index: egcs/libiberty/pexecute.c
diff -c egcs/libiberty/pexecute.c:1.1.1.1 egcs/libiberty/pexecute.c:1.2
*** egcs/libiberty/pexecute.c:1.1.1.1 Sat Dec 20 12:11:56 1997
--- egcs/libiberty/pexecute.c Sat Dec 20 18:38:41 1997
***************
*** 223,236 ****
#if defined (_WIN32)
#include <process.h>
- extern int _spawnv ();
- extern int _spawnvp ();
#ifdef __CYGWIN32__
#define fix_argv(argvec) (argvec)
! #else
/* This is a kludge to get around the Microsoft C spawn functions' propensity
to remove the outermost set of double quotes from all arguments. */
--- 223,272 ----
#if defined (_WIN32)
#include <process.h>
#ifdef __CYGWIN32__
#define fix_argv(argvec) (argvec)
! extern int _spawnv ();
! extern int _spawnvp ();
!
! int
! pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags)
! const char *program;
! char * const *argv;
! const char *this_pname;
! const char *temp_base;
! char **errmsg_fmt, **errmsg_arg;
! int flags;
! {
! int pid;
!
! if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE)
! abort ();
! pid = (flags & PEXECUTE_SEARCH ? _spawnvp : _spawnv)
! (_P_NOWAIT, program, fix_argv(argv));
! if (pid == -1)
! {
! *errmsg_fmt = install_error_msg;
! *errmsg_arg = program;
! return -1;
! }
! return pid;
! }
!
! int
! pwait (pid, status, flags)
! int pid;
! int *status;
! int flags;
! {
! /* ??? Here's an opportunity to canonicalize the values in STATUS.
! Needed? */
! return cwait (status, pid, WAIT_CHILD);
! }
!
! #else /* ! __CYGWIN32__ */
/* This is a kludge to get around the Microsoft C spawn functions' propensity
to remove the outermost set of double quotes from all arguments. */
***************
*** 269,276 ****
return (const char * const *) argvec;
}
! #endif /* ! defined (__CYGWIN32__) */
int
pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags)
const char *program;
--- 305,328 ----
return (const char * const *) argvec;
}
! #include <io.h>
! #include <fcntl.h>
! #include <signal.h>
!
! /* mingw32 headers may not define the following. */
!
! #ifndef _P_WAIT
! # define _P_WAIT 0
! # define _P_NOWAIT 1
! # define _P_OVERLAY 2
! # define _P_NOWAITO 3
! # define _P_DETACH 4
!
! # define WAIT_CHILD 0
! # define WAIT_GRANDCHILD 1
! #endif
+ /* Win32 supports pipes */
int
pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags)
const char *program;
***************
*** 281,310 ****
int flags;
{
int pid;
- if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE)
- abort ();
pid = (flags & PEXECUTE_SEARCH ? _spawnvp : _spawnv)
(_P_NOWAIT, program, fix_argv(argv));
if (pid == -1)
{
*errmsg_fmt = install_error_msg;
*errmsg_arg = program;
return -1;
}
return pid;
}
int
pwait (pid, status, flags)
int pid;
int *status;
int flags;
{
/* ??? Here's an opportunity to canonicalize the values in STATUS.
Needed? */
! return _cwait (status, pid, WAIT_CHILD);
}
#endif /* _WIN32 */
--- 333,445 ----
int flags;
{
int pid;
+ int pdes[2], org_stdin, org_stdout;
+ int input_desc, output_desc;
+ int retries, sleep_interval;
+
+ /* Pipe waiting from last process, to be used as input for the next one.
+ Value is STDIN_FILE_NO if no pipe is waiting
+ (i.e. the next command is the first of a group). */
+ static int last_pipe_input;
+
+ /* If this is the first process, initialize. */
+ if (flags & PEXECUTE_FIRST)
+ last_pipe_input = STDIN_FILE_NO;
+
+ input_desc = last_pipe_input;
+
+ /* If this isn't the last process, make a pipe for its output,
+ and record it as waiting to be the input to the next process. */
+ if (! (flags & PEXECUTE_LAST))
+ {
+ if (_pipe (pdes, 256, O_BINARY) < 0)
+ {
+ *errmsg_fmt = "pipe";
+ *errmsg_arg = NULL;
+ return -1;
+ }
+ output_desc = pdes[WRITE_PORT];
+ last_pipe_input = pdes[READ_PORT];
+ }
+ else
+ {
+ /* Last process. */
+ output_desc = STDOUT_FILE_NO;
+ last_pipe_input = STDIN_FILE_NO;
+ }
+
+ if (input_desc != STDIN_FILE_NO)
+ {
+ org_stdin = dup (STDIN_FILE_NO);
+ dup2 (input_desc, STDIN_FILE_NO);
+ close (input_desc);
+ }
+
+ if (output_desc != STDOUT_FILE_NO)
+ {
+ org_stdout = dup (STDOUT_FILE_NO);
+ dup2 (output_desc, STDOUT_FILE_NO);
+ close (output_desc);
+ }
pid = (flags & PEXECUTE_SEARCH ? _spawnvp : _spawnv)
(_P_NOWAIT, program, fix_argv(argv));
+
+ if (input_desc != STDIN_FILE_NO)
+ {
+ dup2 (org_stdin, STDIN_FILE_NO);
+ close (org_stdin);
+ }
+
+ if (output_desc != STDOUT_FILE_NO)
+ {
+ dup2 (org_stdout, STDOUT_FILE_NO);
+ close (org_stdout);
+ }
+
if (pid == -1)
{
*errmsg_fmt = install_error_msg;
*errmsg_arg = program;
return -1;
}
+
return pid;
}
+ /* MS CRTDLL doesn't return enough information in status to decide if the
+ child exited due to a signal or not, rather it simply returns an
+ integer with the exit code of the child; eg., if the child exited with
+ an abort() call and didn't have a handler for SIGABRT, it simply returns
+ with status = 3. We fix the status code to conform to the usual WIF*
+ macros. Note that WIFSIGNALED will never be true under CRTDLL. */
+
int
pwait (pid, status, flags)
int pid;
int *status;
int flags;
{
+ int termstat;
+
+ pid = _cwait (&termstat, pid, WAIT_CHILD);
+
/* ??? Here's an opportunity to canonicalize the values in STATUS.
Needed? */
!
! /* cwait returns the child process exit code in termstat.
! A value of 3 indicates that the child caught a signal, but not
! which one. Since only SIGABRT, SIGFPE and SIGINT do anything, we
! report SIGABRT. */
! if (termstat == 3)
! *status = SIGABRT;
! else
! *status = (((termstat) & 0xff) << 8);
!
! return pid;
}
+
+ #endif /* ! defined (__CYGWIN32__) */
#endif /* _WIN32 */
Index: egcs/libiberty/xmalloc.c
diff -c egcs/libiberty/xmalloc.c:1.1.1.1 egcs/libiberty/xmalloc.c:1.2
*** egcs/libiberty/xmalloc.c:1.1.1.1 Sat Dec 20 12:11:56 1997
--- egcs/libiberty/xmalloc.c Sat Dec 20 18:38:41 1997
***************
*** 42,57 ****
/* The program name if set. */
static const char *name = "";
! /* The initial sbrk, set when the program name is set. */
static char *first_break = NULL;
void
xmalloc_set_program_name (s)
const char *s;
{
name = s;
if (first_break == NULL)
first_break = (char *) sbrk (0);
}
PTR
--- 42,63 ----
/* The program name if set. */
static const char *name = "";
! #if ! defined (_WIN32) || defined (__CYGWIN32__)
! /* The initial sbrk, set when the program name is set. Not used for win32
! ports other than cygwin32. */
static char *first_break = NULL;
+ #endif
void
xmalloc_set_program_name (s)
const char *s;
{
name = s;
+ #if ! defined (_WIN32) || defined (__CYGWIN32__)
+ /* Win32 ports other than cygwin32 don't have brk() */
if (first_break == NULL)
first_break = (char *) sbrk (0);
+ #endif /* ! _WIN32 || __CYGWIN32 __ */
}
PTR
***************
*** 65,70 ****
--- 71,77 ----
newmem = malloc (size);
if (!newmem)
{
+ #if ! defined (_WIN32) || defined (__CYGWIN32__)
extern char **environ;
size_t allocated;
***************
*** 76,81 ****
--- 83,94 ----
"\n%s%sCan not allocate %lu bytes after allocating %lu bytes\n",
name, *name ? ": " : "",
(unsigned long) size, (unsigned long) allocated);
+ #else
+ fprintf (stderr,
+ "\n%s%sCan not allocate %lu bytes\n",
+ name, *name ? ": " : "",
+ (unsigned long) size);
+ #endif /* ! _WIN32 || __CYGWIN32 __ */
xexit (1);
}
return (newmem);
***************
*** 96,101 ****
--- 109,115 ----
newmem = realloc (oldmem, size);
if (!newmem)
{
+ #ifndef __MINGW32__
extern char **environ;
size_t allocated;
***************
*** 107,112 ****
--- 121,132 ----
"\n%s%sCan not reallocate %lu bytes after allocating %lu bytes\n",
name, *name ? ": " : "",
(unsigned long) size, (unsigned long) allocated);
+ #else
+ fprintf (stderr,
+ "\n%s%sCan not reallocate %lu bytes\n",
+ name, *name ? ": " : "",
+ (unsigned long) size);
+ #endif /* __MINGW32__ */
xexit (1);
}
return (newmem);
Index: egcs/libiberty/config/mt-mingw32
diff -c /dev/null egcs/libiberty/config/mt-mingw32:1.2
*** /dev/null Sun Dec 21 02:10:48 1997
--- egcs/libiberty/config/mt-mingw32 Sun Dec 21 02:10:30 1997
***************
*** 0 ****
--- 1,27 ----
+ # Mingw32 target Makefile fragment.
+ # The autoconfiguration fails for a Mingw32 target, because of an
+ # incompatible definition of sys_errlist, which is imported from a DLL.
+ # Therefore, we compute the dependencies by hand.
+
+ HDEFINES = -DNO_SYS_PARAM_H -DNO_SYS_FILE_H
+ CONFIG_H = mgconfig.h
+ NEEDED_LIST = mgneeded-list
+
+ mgconfig.h: Makefile
+ if [ -f ../newlib/Makefile ]; then \
+ $(MAKE) $(FLAGS_TO_PASS) xconfig.h; \
+ cp xconfig.h mgconfig.h; \
+ else \
+ echo "#define NEED_sys_siglist 1" >>mgconfig.h; \
+ echo "#define NEED_strsignal 1" >>mgconfig.h; \
+ echo "#define NEED_psignal 1" >>mgconfig.h; \
+ echo "#define NEED_basename 1" >>mgconfig.h; \
+ fi
+
+ mgneeded-list: Makefile
+ if [ -f ../newlib/Makefile ]; then \
+ $(MAKE) $(FLAGS_TO_PASS) xneeded-list; \
+ cp xneeded-list mgneeded-list; \
+ else \
+ echo getopt.o vasprintf.o >mgneeded-list; \
+ fi
Regards,
Mumit -- khan@xraylith.wisc.edu
http://www.xraylith.wisc.edu/~khan/