Blame SOURCES/gcc34-ice-hack.patch

6693b3
2004-01-23  Jakub Jelinek  <jakub@redhat.com>
6693b3
6693b3
	* system.h (ICE_EXIT_CODE): Define.
6693b3
	* gcc.c (execute): Don't free first string early, but at the end
6693b3
	of the function.  Call retry_ice if compiler exited with
6693b3
	ICE_EXIT_CODE.
6693b3
	(retry_ice): New function.
6693b3
	* diagnostic.c (diagnostic_count_diagnostic,
6693b3
	diagnostic_action_after_output, error_recursion): Exit with
6693b3
	ICE_EXIT_CODE instead of FATAL_EXIT_CODE.
6693b3
6693b3
--- gcc/system.h.jj	2004-01-19 17:29:30.000000000 +0100
6693b3
+++ gcc/system.h	2004-01-21 11:53:41.000000000 +0100
6693b3
@@ -153,6 +153,10 @@ extern int errno;
6693b3
 # endif
6693b3
 #endif
6693b3
 
6693b3
+#ifndef ICE_EXIT_CODE
6693b3
+# define ICE_EXIT_CODE 27
6693b3
+#endif
6693b3
+
6693b3
 #ifdef HAVE_UNISTD_H
6693b3
 # include <unistd.h>
6693b3
 #endif
6693b3
--- gcc/gcc.c.jj	2004-01-21 11:45:20.000000000 +0100
6693b3
+++ gcc/gcc.c	2004-01-21 11:56:46.000000000 +0100
6693b3
@@ -352,6 +352,9 @@ static void init_gcc_specs (struct obsta
6693b3
 #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
6693b3
 static const char *convert_filename (const char *, int, int);
6693b3
 #endif
6693b3
+#if !(defined (__MSDOS__) || defined (OS2) || defined (VMS))
6693b3
+static void retry_ice (const char *prog, const char **argv);
6693b3
+#endif
6693b3
 
6693b3
 static const char *if_exists_spec_function (int, const char **);
6693b3
 static const char *if_exists_else_spec_function (int, const char **);
6693b3
@@ -2753,7 +2756,7 @@ execute (void)
6693b3
       if (commands[i].pid == -1)
6693b3
 	pfatal_pexecute (errmsg_fmt, errmsg_arg);
6693b3
 
6693b3
-      if (string != commands[i].prog)
6693b3
+      if (i && string != commands[i].prog)
6693b3
 	free ((void *) string);
6693b3
     }
6693b3
 
6693b3
@@ -2831,6 +2834,17 @@ See %s for instructions.",
6693b3
 	      else if (WIFEXITED (status)
6693b3
 		       && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
6693b3
 		{
6693b3
+#if !(defined (__MSDOS__) || defined (OS2) || defined (VMS))
6693b3
+		  /* For ICEs in cc1, cc1obj, cc1plus see if it is
6693b3
+		     reproducible or not.  */
6693b3
+		  char *p;
6693b3
+		  if (WEXITSTATUS (status) == ICE_EXIT_CODE
6693b3
+		      && j == 0
6693b3
+		      && (p = strrchr (commands[j].argv[0], DIR_SEPARATOR))
6693b3
+		      && ! strncmp (p + 1, "cc1", 3))
6693b3
+		    retry_ice (commands[j].prog, commands[j].argv);
6693b3
+#endif
6693b3
+
6693b3
 		  if (WEXITSTATUS (status) > greatest_status)
6693b3
 		    greatest_status = WEXITSTATUS (status);
6693b3
 		  ret_code = -1;
6693b3
@@ -2842,6 +2856,10 @@ See %s for instructions.",
6693b3
 	      break;
6693b3
 	    }
6693b3
       }
6693b3
+
6693b3
+    if (commands[0].argv[0] != commands[0].prog)
6693b3
+      free ((PTR) commands[0].argv[0]);
6693b3
+
6693b3
     return ret_code;
6693b3
   }
6693b3
 }
6693b3
@@ -5809,6 +5827,224 @@ give_switch (int switchnum, int omit_fir
6693b3
   switches[switchnum].validated = 1;
6693b3
 }
6693b3
 
6693b3
+#if !(defined (__MSDOS__) || defined (OS2) || defined (VMS))
6693b3
+#define RETRY_ICE_ATTEMPTS 2
6693b3
+
6693b3
+static void
6693b3
+retry_ice (const char *prog, const char **argv)
6693b3
+{
6693b3
+  int nargs, out_arg = -1, quiet = 0, attempt;
6693b3
+  int pid, retries, sleep_interval;
6693b3
+  const char **new_argv;
6693b3
+  char *temp_filenames[RETRY_ICE_ATTEMPTS * 2 + 2];
6693b3
+
6693b3
+  if (input_filename == NULL || ! strcmp (input_filename, "-"))
6693b3
+    return;
6693b3
+
6693b3
+  for (nargs = 0; argv[nargs] != NULL; ++nargs)
6693b3
+    /* Only retry compiler ICEs, not preprocessor ones.  */
6693b3
+    if (! strcmp (argv[nargs], "-E"))
6693b3
+      return;
6693b3
+    else if (argv[nargs][0] == '-' && argv[nargs][1] == 'o')
6693b3
+      {
6693b3
+	if (out_arg == -1)
6693b3
+	  out_arg = nargs;
6693b3
+	else
6693b3
+	  return;
6693b3
+      }
6693b3
+    /* If the compiler is going to output any time information,
6693b3
+       it might varry between invocations.  */
6693b3
+    else if (! strcmp (argv[nargs], "-quiet"))
6693b3
+      quiet = 1;
6693b3
+    else if (! strcmp (argv[nargs], "-ftime-report"))
6693b3
+      return;
6693b3
+
6693b3
+  if (out_arg == -1 || !quiet)
6693b3
+    return;
6693b3
+
6693b3
+  memset (temp_filenames, '\0', sizeof (temp_filenames));
6693b3
+  new_argv = alloca ((nargs + 3) * sizeof (const char *));
6693b3
+  memcpy (new_argv, argv, (nargs + 1) * sizeof (const char *));
6693b3
+  new_argv[nargs++] = "-frandom-seed=0";
6693b3
+  new_argv[nargs] = NULL;
6693b3
+  if (new_argv[out_arg][2] == '\0')
6693b3
+    new_argv[out_arg + 1] = "-";
6693b3
+  else
6693b3
+    new_argv[out_arg] = "-o-";
6693b3
+
6693b3
+  for (attempt = 0; attempt < RETRY_ICE_ATTEMPTS + 1; ++attempt)
6693b3
+    {
6693b3
+      int fd;
6693b3
+      int status;
6693b3
+
6693b3
+      temp_filenames[attempt * 2] = make_temp_file (".out");
6693b3
+      temp_filenames[attempt * 2 + 1] = make_temp_file (".err");
6693b3
+
6693b3
+      if (attempt == RETRY_ICE_ATTEMPTS)
6693b3
+        {
6693b3
+	  int i;
6693b3
+	  int fd1, fd2;
6693b3
+	  struct stat st1, st2;
6693b3
+	  size_t n, len;
6693b3
+	  char *buf;
6693b3
+
6693b3
+	  buf = xmalloc (8192);
6693b3
+
6693b3
+	  for (i = 0; i < 2; ++i)
6693b3
+	    {
6693b3
+	      fd1 = open (temp_filenames[i], O_RDONLY);
6693b3
+	      fd2 = open (temp_filenames[2 + i], O_RDONLY);
6693b3
+
6693b3
+	      if (fd1 < 0 || fd2 < 0)
6693b3
+		{
6693b3
+		  i = -1;
6693b3
+		  close (fd1);
6693b3
+		  close (fd2);
6693b3
+		  break;
6693b3
+		}
6693b3
+
6693b3
+	      if (fstat (fd1, &st1) < 0 || fstat (fd2, &st2) < 0)
6693b3
+		{
6693b3
+		  i = -1;
6693b3
+		  close (fd1);
6693b3
+		  close (fd2);
6693b3
+		  break;
6693b3
+		}
6693b3
+
6693b3
+	      if (st1.st_size != st2.st_size)
6693b3
+		{
6693b3
+		  close (fd1);
6693b3
+		  close (fd2);
6693b3
+		  break;
6693b3
+		}
6693b3
+
6693b3
+	      len = 0;
6693b3
+	      for (n = st1.st_size; n; n -= len)
6693b3
+		{
6693b3
+		  len = n;
6693b3
+		  if (len > 4096)
6693b3
+		    len = 4096;
6693b3
+
6693b3
+		  if (read (fd1, buf, len) != (int) len
6693b3
+		      || read (fd2, buf + 4096, len) != (int) len)
6693b3
+		    {
6693b3
+		      i = -1;
6693b3
+		      break;
6693b3
+		    }
6693b3
+
6693b3
+		  if (memcmp (buf, buf + 4096, len) != 0)
6693b3
+		    break;
6693b3
+		}
6693b3
+
6693b3
+	      close (fd1);
6693b3
+	      close (fd2);
6693b3
+
6693b3
+	      if (n)
6693b3
+		break;
6693b3
+	    }
6693b3
+
6693b3
+	  free (buf);
6693b3
+	  if (i == -1)
6693b3
+	    break;
6693b3
+
6693b3
+	  if (i != 2)
6693b3
+	    {
6693b3
+	      notice ("The bug is not reproducible, so it is likely a hardware or OS problem.\n");
6693b3
+	      break;
6693b3
+	    }
6693b3
+
6693b3
+          fd = open (temp_filenames[attempt * 2], O_RDWR);
6693b3
+	  if (fd < 0)
6693b3
+	    break;
6693b3
+	  write (fd, "//", 2);
6693b3
+	  for (i = 0; i < nargs; i++)
6693b3
+	    {
6693b3
+	      write (fd, " ", 1);
6693b3
+	      write (fd, new_argv[i], strlen (new_argv[i]));
6693b3
+	    }
6693b3
+	  write (fd, "\n", 1);
6693b3
+	  new_argv[nargs] = "-E";
6693b3
+	  new_argv[nargs + 1] = NULL;
6693b3
+        }
6693b3
+
6693b3
+      /* Fork a subprocess; wait and retry if it fails.  */
6693b3
+      sleep_interval = 1;
6693b3
+      pid = -1;
6693b3
+      for (retries = 0; retries < 4; retries++)
6693b3
+	{
6693b3
+	  pid = fork ();
6693b3
+	  if (pid >= 0)
6693b3
+	    break;
6693b3
+	  sleep (sleep_interval);
6693b3
+	  sleep_interval *= 2;
6693b3
+	}
6693b3
+
6693b3
+      if (pid < 0)
6693b3
+	break;
6693b3
+      else if (pid == 0)
6693b3
+	{
6693b3
+	  if (attempt != RETRY_ICE_ATTEMPTS)
6693b3
+	    fd = open (temp_filenames[attempt * 2], O_RDWR);
6693b3
+	  if (fd < 0)
6693b3
+	    exit (-1);
6693b3
+	  if (fd != 1)
6693b3
+	    {
6693b3
+	      close (1);
6693b3
+	      dup (fd);
6693b3
+	      close (fd);
6693b3
+	    }
6693b3
+
6693b3
+	  fd = open (temp_filenames[attempt * 2 + 1], O_RDWR);
6693b3
+	  if (fd < 0)
6693b3
+	    exit (-1);
6693b3
+	  if (fd != 2)
6693b3
+	    {
6693b3
+	      close (2);
6693b3
+	      dup (fd);
6693b3
+	      close (fd);
6693b3
+	    }
6693b3
+
6693b3
+	  if (prog == new_argv[0])
6693b3
+	    execvp (prog, (char *const *) new_argv);
6693b3
+	  else
6693b3
+	    execv (new_argv[0], (char *const *) new_argv);
6693b3
+	  exit (-1);
6693b3
+	}
6693b3
+
6693b3
+      if (waitpid (pid, &status, 0) < 0)
6693b3
+	break;
6693b3
+
6693b3
+      if (attempt < RETRY_ICE_ATTEMPTS
6693b3
+	  && (! WIFEXITED (status) || WEXITSTATUS (status) != ICE_EXIT_CODE))
6693b3
+	{
6693b3
+	  notice ("The bug is not reproducible, so it is likely a hardware or OS problem.\n");
6693b3
+	  break;
6693b3
+	}
6693b3
+      else if (attempt == RETRY_ICE_ATTEMPTS)
6693b3
+	{
6693b3
+	  close (fd);
6693b3
+	  if (WIFEXITED (status)
6693b3
+	      && WEXITSTATUS (status) == SUCCESS_EXIT_CODE)
6693b3
+	    {
6693b3
+	      notice ("Preprocessed source stored into %s file, please attach this to your bugreport.\n",
6693b3
+		      temp_filenames[attempt * 2]);
6693b3
+	      /* Make sure it is not deleted.  */
6693b3
+	      free (temp_filenames[attempt * 2]);
6693b3
+	      temp_filenames[attempt * 2] = NULL;
6693b3
+	      break;
6693b3
+	    }
6693b3
+	}
6693b3
+    }
6693b3
+
6693b3
+  for (attempt = 0; attempt < RETRY_ICE_ATTEMPTS * 2 + 2; attempt++)
6693b3
+    if (temp_filenames[attempt])
6693b3
+      {
6693b3
+	unlink (temp_filenames[attempt]);
6693b3
+	free (temp_filenames[attempt]);
6693b3
+      }
6693b3
+}
6693b3
+#endif
6693b3
+
6693b3
 /* Search for a file named NAME trying various prefixes including the
6693b3
    user's -B prefix and some standard ones.
6693b3
    Return the absolute file name found.  If nothing is found, return NAME.  */
6693b3
--- gcc/diagnostic.c.jj	2003-10-01 12:09:21.000000000 +0200
6693b3
+++ gcc/diagnostic.c	2004-01-21 11:54:47.000000000 +0100
6693b3
@@ -272,14 +272,14 @@ diagnostic_action_after_output (diagnost
6693b3
 	real_abort ();
6693b3
 
6693b3
       fnotice (stderr, bug_report_request, bug_report_url);
6693b3
-      exit (FATAL_EXIT_CODE);
6693b3
+      exit (ICE_EXIT_CODE);
6693b3
 
6693b3
     case DK_FATAL:
6693b3
       if (context->abort_on_error)
6693b3
 	real_abort ();
6693b3
 
6693b3
       fnotice (stderr, "compilation terminated.\n");
6693b3
-      exit (FATAL_EXIT_CODE);
6693b3
+      exit (ICE_EXIT_CODE);
6693b3
 
6693b3
     default:
6693b3
       real_abort ();
6693b3
@@ -571,7 +571,7 @@ error_recursion (diagnostic_context *con
6693b3
   fnotice (stderr,
6693b3
 	   "Internal compiler error: Error reporting routines re-entered.\n");
6693b3
   fnotice (stderr, bug_report_request, bug_report_url);
6693b3
-  exit (FATAL_EXIT_CODE);
6693b3
+  exit (ICE_EXIT_CODE);
6693b3
 }
6693b3
 
6693b3
 /* Report an internal compiler error in a friendly manner.  This is