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


The attached patches modify the collect2.c and tlink.c from egcs 1.1a 
so that the template repository now works with DJGPP. It should 
theoretically enable it with Win32 also, but I have no way of testing that. 
I'm sorry in advance the patches aren't against the current versions, but 
I don't have cvs nor the bandwith to download the weekly snapshots. 
I'm sure that will make it a bit of trouble it merge them in, but please 
consider them for inclusion into egcs anyway.

And before the subject comes up, the paperwork has just been sent to 
the address listed in the assignment contract section of the egcs 
website.

Here's my stab at a changelog:

collect2.c: Define HAVE_SPAWNVP for MSDOS and Win32 ports.
            Define _P_WAIT if not already defined.
            Include sys/wait.h when HAVE_SYS_WAIT_H is defined.
            Declare returnCode when HAVE_SYS_WAIT_H is defined.
            (collect_wait) Use returnCode when appropriate.
            (collect_execute) Use _spawnvp when appropriate.
            (main) For DJGPP, set flags for system().

tlink.c: Declare fixup_dirsep.
         (read_repo_file) Call fixup_dirsep before setting f->dir when 
appropriate.
         (recompile_files) Send commands to system() one at a time 
when appropriate.

Mark

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

*** bak/collect2.c	Thu Sep  3 17:05:08 1998
--- collect2.c	Wed Oct 28 13:04:50 1998
***************
*** 27,58 ****
  
  #include "config.h"
  #include "system.h"
  #include <signal.h>
  #include <sys/stat.h>
  
  #define COLLECT
  
  #include "demangle.h"
  #include "obstack.h"
  #include "gansidecl.h"
! #if defined(__CYGWIN32__) || defined(__DJGPP__)
  #include <process.h>
  #endif
  
  /* Obstack allocation and deallocation routines.  */
  #define obstack_chunk_alloc xmalloc
  #define obstack_chunk_free free
  
  #ifdef USG
  #define vfork fork
  #endif
  
! #ifdef __DJGPP__
! #define _P_NOWAIT P_NOWAIT
! #define _spawnvp spawnvp
  int	returnCode;
  #endif
  
  #ifndef WIFSIGNALED
  #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
  #endif
--- 27,72 ----
  
  #include "config.h"
  #include "system.h"
  #include <signal.h>
  #include <sys/stat.h>
  
+ #if defined(__MSDOS__) || defined(__WIN32__) || defined(__DJGPP__)
+ #define HAVE_SPAWNVP
+ #ifndef _P_WAIT
+ #define _P_WAIT P_WAIT
+ #endif /* _P_WAIT */
+ #endif
+ 
+ #if defined(__DJGPP__)
+ #define _spawnvp spawnvp
+ #endif
+ 
+ #if defined(HAVE_SYS_WAIT_H)
+ /* Pull in definitions of WIFSIGNALED, WTERMSIG, etc. for DJGPP at least */
+ #include <sys/wait.h>
+ #endif
+ 
  #define COLLECT
  
  #include "demangle.h"
  #include "obstack.h"
  #include "gansidecl.h"
! #if defined(__WIN32__) || defined(__DJGPP__)
  #include <process.h>
  #endif
  
  /* Obstack allocation and deallocation routines.  */
  #define obstack_chunk_alloc xmalloc
  #define obstack_chunk_free free
  
  #ifdef USG
  #define vfork fork
  #endif
  
! #ifdef HAVE_SPAWNVP
  int	returnCode;
  #endif
  
  #ifndef WIFSIGNALED
  #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
  #endif
***************
*** 935,946 ****
--- 949,964 ----
    char **ld2		= ld2_argv;
    char **object_lst	= (char **) xcalloc (sizeof (char *), argc);
    char **object		= object_lst;
    int first_file;
    int num_c_args	= argc+9;
  
+ #ifdef __DJGPP__
+   __system_flags |= (__system_allow_multiple_cmds | __system_emulate_chdir);
+ #endif
+ 
  #ifdef DEBUG
    debug = 1;
  #endif
  
    /* Parse command line early for instances of -debug.  This allows
       the debug flag to be set before functions like find_a_file()
***************
*** 1569,1581 ****
  
  int
  collect_wait (prog)
       char *prog;
  {
    int status;
! #ifdef __DJGPP__
    status=returnCode;
  #else
    wait (&status);
  #endif
    if (status)
      {
--- 1587,1599 ----
  
  int
  collect_wait (prog)
       char *prog;
  {
    int status;
! #ifdef HAVE_SPAWNVP
    status=returnCode;
  #else
    wait (&status);
  #endif
    if (status)
      {
***************
*** 1649,1661 ****
    /* If we cannot find a program we need, complain error.  Do this here
       since we might not end up needing something that we could not find.  */
  
    if (argv[0] == 0)
      fatal ("cannot find `%s'", prog);
  
! #if !defined(__CYGWIN32__) && !defined(__DJGPP__)
    pid = vfork ();
    if (pid == -1)
      {
  #ifdef vfork
        fatal_perror ("fork");
  #else
--- 1667,1679 ----
    /* If we cannot find a program we need, complain error.  Do this here
       since we might not end up needing something that we could not find.  */
  
    if (argv[0] == 0)
      fatal ("cannot find `%s'", prog);
  
! #ifndef HAVE_SPAWNVP
    pid = vfork ();
    if (pid == -1)
      {
  #ifdef vfork
        fatal_perror ("fork");
  #else
***************
*** 1675,1692 ****
  	}
  
        execvp (argv[0], argv);
        fatal_perror ("executing %s", prog);
      }
  #else
! #ifdef __DJGPP__
!   returnCode=
! #endif
!   pid = _spawnvp (_P_NOWAIT, argv[0], argv);
!   if (pid == -1)
      fatal ("spawnvp failed");
  #endif
  }
  
  static void
  fork_execute (prog, argv)
       char *prog;
--- 1693,1727 ----
  	}
  
        execvp (argv[0], argv);
        fatal_perror ("executing %s", prog);
      }
  #else
!   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);
!   }
! 
!   returnCode = _spawnvp(_P_WAIT, argv[0], argv);
! 
!   if (redir)
!   {
!     /* Restore stdout and stderr to console */
!     if (freopen("CON", "a", stdout) == NULL)
!       fatal_perror("redirecting stdout: %s", "CON (console)");
!     if (freopen("CON", "a", stderr) == NULL)
!       fatal_perror ("redirecting stderr: %s", "CON (console)");
!   }
! 
!   if (returnCode == -1)
      fatal ("spawnvp failed");
+ 
  #endif
  }
  
  static void
  fork_execute (prog, argv)
       char *prog;
*** bak/tlink.c	Wed May  6 12:56:54 1998
--- tlink.c	Wed Oct 28 12:51:32 1998
***************
*** 72,83 ****
--- 72,101 ----
    struct hash_entry root;
    const char *mangled;
  } demangled;
  
  static struct hash_table symbol_table;
  
+ #if defined(__WIN32__) || (defined(__MSDOS__) && !defined(__DJGPP__))
+ #define FIXUP_DIRSEP
+ #define FIXUP_NO_MULTI_CMDS
+ 
+ char * fixup_dirsep(char *dir)
+ {
+   char *p = dir;
+   while (*p != '\0')
+   {
+     if (*p == '/')
+       *p = '\\';
+ 
+     p++;
+   }
+   return dir;
+ }
+ #endif
+ 
  static struct hash_entry *
  symbol_hash_newfunc (entry, table, string)
       struct hash_entry *entry;
       struct hash_table *table;
       const char *string;
  {
***************
*** 377,389 ****
        switch (c)
  	{
  	case 'A':
  	  f->args = pfgets (stream);
  	  break;
  	case 'D':
! 	  f->dir = pfgets (stream);
  	  break;
  	case 'M':
  	  f->main = pfgets (stream);
  	  break;
  	case 'P':
  	  freadsym (stream, f, 2);
--- 395,411 ----
        switch (c)
  	{
  	case 'A':
  	  f->args = pfgets (stream);
  	  break;
  	case 'D':
! #ifndef FIXUP_DIRSEP
!           f->dir = pfgets (stream);
! #else
!           f->dir = fixup_dirsep(pfgets (stream));
! #endif
  	  break;
  	case 'M':
  	  f->main = pfgets (stream);
  	  break;
  	case 'P':
  	  freadsym (stream, f, 2);
***************
*** 447,466 ****
--- 469,508 ----
  	  fprintf (output, "%s\n", line);
  	}
        fclose (stream);
        fclose (output);
        rename (outname, f->root.string);
  
+ #ifndef FIXUP_NO_MULTI_CMDS
        obstack_grow (&temporary_obstack, "cd ", 3);
        obstack_grow (&temporary_obstack, f->dir, strlen (f->dir));
        obstack_grow (&temporary_obstack, "; ", 2);
        obstack_grow (&temporary_obstack, c_file_name, strlen (c_file_name));
        obstack_1grow (&temporary_obstack, ' ');
        obstack_grow (&temporary_obstack, f->args, strlen (f->args));
        obstack_1grow (&temporary_obstack, ' ');
        command = obstack_copy0 (&temporary_obstack, f->main, strlen (f->main));
+ #else
+       obstack_grow (&temporary_obstack, "cd ", 3);
+       obstack_grow (&temporary_obstack, f->dir, strlen (f->dir));
+       command = obstack_copy0 (&temporary_obstack, f->main, strlen (f->main));
+ 
+       if (tlink_verbose >= 3)
+ 	fprintf (stderr, "%s\n", command);
+ 
+       if (system (command) != 0)
+ 	return 0;
+ 
+       obstack_free (&temporary_obstack, temporary_firstobj);
+       obstack_grow (&temporary_obstack, c_file_name, strlen (c_file_name));
+       obstack_1grow (&temporary_obstack, ' ');
+       obstack_grow (&temporary_obstack, f->args, strlen (f->args));
+       obstack_1grow (&temporary_obstack, ' ');
+ 
+       command = obstack_copy0 (&temporary_obstack, f->main, strlen (f->main));
+ #endif
  
        if (tlink_verbose)
  	fprintf (stderr, "collect: recompiling %s\n", f->main);
        if (tlink_verbose >= 3)
  	fprintf (stderr, "%s\n", command);
  
***************
*** 609,625 ****
  	 files, assume that everything on the command line could be.  */
        if (read_repo_files (ld_argv))
  	while (exit && i++ < MAX_ITERATIONS)
  	  {
  	    if (tlink_verbose >= 3)
  	      dump_file (ldout);
! 	    demangle_new_symbols ();
  	    if (! scan_linker_output (ldout))
! 	      break;
  	    if (! recompile_files ())
! 	      break;
  	    if (tlink_verbose)
  	      fprintf (stderr, "collect: relinking\n");
  	    exit = tlink_execute ("ld", ld_argv, ldout);
  	  }
      }
  
--- 651,667 ----
  	 files, assume that everything on the command line could be.  */
        if (read_repo_files (ld_argv))
  	while (exit && i++ < MAX_ITERATIONS)
  	  {
  	    if (tlink_verbose >= 3)
  	      dump_file (ldout);
!             demangle_new_symbols ();
  	    if (! scan_linker_output (ldout))
!               break;
  	    if (! recompile_files ())
!               break;
  	    if (tlink_verbose)
  	      fprintf (stderr, "collect: relinking\n");
  	    exit = tlink_execute ("ld", ld_argv, ldout);
  	  }
      }
  

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