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]

Improve gcc.c's handling of fatal signals in subprocesses


If cc1 (for instance) segfaults, gcc will print out an unfriendly
error message:

gcc: Internal compiler error: program cc1 got fatal signal 11

We all know what that means, but we shouldn't be requiring users
to know.  Also, it should generate the "Please submit a bug report"
message.

Worse, if you're in -pipe mode and cc1 gives up halfway through a
large file, cpp will die with SIGPIPE, which gets you the same
complaint (this time "fatal signal 13").  This only happens as fallout
from some other catastrophe, and the error message is not helpful.

This patch changes the error message to

Internal error: Segmentation fault (program cc1)
Please submit a full bug report.
See <URL> for instructions.

But if the signal is SIGPIPE and there's already been an error,
nothing is printed.

The patch also removes the now-redundant SIGPIPE handler (which just
exited quietly) from tradcpp.c.  I believe cpplib used to have one of
these and it got taken out some time ago.

There is no portability concern, because strsignal is supplied by
libiberty if it's missing.

zw

	* gcc.c (execute): If a subprocess gets a fatal signal, report
	strsignal() of the signal number, and ask for a bug report.
	Do not do this for SIGPIPE if there's already been an error.

	* tradcpp.c: Don't include signal.h.  Don't catch SIGPIPE.
	Delete pipe_closed.

===================================================================
Index: gcc.c
--- gcc.c	2000/07/12 20:01:02	1.151
+++ gcc.c	2000/07/13 02:47:38
@@ -2653,22 +2653,35 @@ execute ()
 	  if (commands[j].pid == pid)
 	    {
 	      i++;
-	      if (status != 0)
+	      if (WIFSIGNALED (status))
 		{
-		  if (WIFSIGNALED (status))
-		    {
-		      fatal ("Internal compiler error: program %s got fatal signal %d",
-			     commands[j].prog, WTERMSIG (status));
-		      signal_count++;
-		      ret_code = -1;
-		    }
-		  else if (WIFEXITED (status)
-			   && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
-		    {
-		      if (WEXITSTATUS (status) > greatest_status)
-			greatest_status = WEXITSTATUS (status);
-		      ret_code = -1;
-		    }
+#ifdef SIGPIPE
+		  /* SIGPIPE is a special case.  It happens in -pipe mode
+		     when the compiler dies before the preprocessor is
+		     done, or the assembler dies before the compiler is
+		     done.  There's generally been an error already, and
+		     this is just fallout.  So don't generate another error
+		     unless we would otherwise have succeeded.  */
+		  if (WTERMSIG (status) == SIGPIPE
+		      && (signal_count || greatest_status >= MIN_FATAL_STATUS))
+		    ;
+		  else
+#endif
+		    fatal ("\
+Internal error: %s (program %s)\n\
+Please submit a full bug report.\n\
+See %s for instructions.",
+			   strsignal (WTERMSIG (status)), commands[j].prog,
+			   GCCBUGURL);
+		  signal_count++;
+		  ret_code = -1;
+		}
+	      else if (WIFEXITED (status)
+		       && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
+		{
+		  if (WEXITSTATUS (status) > greatest_status)
+		    greatest_status = WEXITSTATUS (status);
+		  ret_code = -1;
 		}
 #ifdef HAVE_GETRUSAGE
 	      if (report_times && ut + st != 0)
===================================================================
Index: tradcpp.c
--- tradcpp.c	2000/07/07 20:13:35	1.3
+++ tradcpp.c	2000/07/13 02:44:14
@@ -28,8 +28,6 @@ Foundation, 675 Mass Ave, Cambridge, MA 
 #include "version.h"
 #include "cppdefault.h"
 
-#include <signal.h>
-
 typedef unsigned char U_CHAR;
 
 /* Name under which this program was invoked.  */
@@ -387,7 +385,6 @@ U_CHAR *skip_to_end_of_comment PARAMS ((
 U_CHAR *skip_quoted_string     PARAMS ((U_CHAR *, U_CHAR *, int,
 					int *, int *, int *));
 
-void pipe_closed	PARAMS ((int));
 int main		PARAMS ((int, char **));
 
 /* Convenience.  Write U"string" to get an unsigned string constant.  */
@@ -457,16 +454,7 @@ int deps_column;
 /* Nonzero means -I- has been seen,
    so don't look for #include "foo" the source-file directory.  */
 int ignore_srcdir;
-
-/* Handler for SIGPIPE.  */
 
-void
-pipe_closed (dummy)
-     int dummy ATTRIBUTE_UNUSED;
-{
-  exit (FATAL_EXIT_CODE);
-}
-
 int
 main (argc, argv)
      int argc;
@@ -515,8 +503,6 @@ main (argc, argv)
   dump_macros = 0;
   no_output = 0;
 
-  signal (SIGPIPE, pipe_closed);
-
   max_include_len = cpp_GCC_INCLUDE_DIR_len + 7;  /* ??? */
 
   memset (pend_files, 0, argc * sizeof (char *));

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