1
# DP: Retry the build on an ice, save the calling options and preprocessed
2
# DP: source when the ice is reproducible.
4
2004-01-23 Jakub Jelinek <jakub@redhat.com>
6
* gcc.c (execute): Don't free first string early, but at the end
7
of the function. Call retry_ice if compiler exited with
9
(retry_ice): New function.
10
* diagnostic.c (diagnostic_count_diagnostic,
11
diagnostic_action_after_output, error_recursion): Exit with
12
ICE_EXIT_CODE instead of FATAL_EXIT_CODE.
14
#--- a/src/gcc/Makefile.in
15
#+++ b/src/gcc/Makefile.in
16
#@@ -181,6 +181,8 @@ SYSCALLS.c.X-warn = -Wno-strict-prototypes -Wno-error
17
# dfp.o-warn = -Wno-error
18
# # mips-tfile.c contains -Wcast-qual warnings.
19
# mips-tfile.o-warn = -Wno-error
21
#+gcc.o-warn = -Wno-error
23
# # All warnings have to be shut off in stage1 if the compiler used then
24
# # isn't gcc; configure determines that. WARN_CFLAGS will be either
25
Index: b/src/gcc/gcc.c
26
===================================================================
30
#if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
31
static const char *convert_filename (const char *, int, int);
33
+#if !(defined (__MSDOS__) || defined (OS2) || defined (VMS))
34
+static void retry_ice (const char *prog, const char **argv);
37
static const char *getenv_spec_function (int, const char **);
38
static const char *if_exists_spec_function (int, const char **);
43
- if (string != commands[i].prog)
44
+ if (i && string != commands[i].prog)
45
free (CONST_CAST (char *, string));
48
@@ -2824,6 +2827,16 @@
49
else if (WIFEXITED (status)
50
&& WEXITSTATUS (status) >= MIN_FATAL_STATUS)
52
+#if !(defined (__MSDOS__) || defined (OS2) || defined (VMS))
53
+ /* For ICEs in cc1, cc1obj, cc1plus see if it is
54
+ reproducible or not. */
56
+ if (WEXITSTATUS (status) == ICE_EXIT_CODE
58
+ && (p = strrchr (commands[0].argv[0], DIR_SEPARATOR))
59
+ && ! strncmp (p + 1, "cc1", 3))
60
+ retry_ice (commands[0].prog, commands[0].argv);
62
if (WEXITSTATUS (status) > greatest_status)
63
greatest_status = WEXITSTATUS (status);
69
+ if (commands[0].argv[0] != commands[0].prog)
70
+ free (CONST_CAST (char *, commands[0].argv[0]));
75
@@ -6034,6 +6050,227 @@
76
switches[switchnum].validated = true;
79
+#if !(defined (__MSDOS__) || defined (OS2) || defined (VMS))
80
+#define RETRY_ICE_ATTEMPTS 2
83
+retry_ice (const char *prog, const char **argv)
85
+ int nargs, out_arg = -1, quiet = 0, attempt;
86
+ int pid, retries, sleep_interval;
87
+ const char **new_argv;
88
+ char *temp_filenames[RETRY_ICE_ATTEMPTS * 2 + 2];
90
+ if (gcc_input_filename == NULL || ! strcmp (gcc_input_filename, "-"))
93
+ for (nargs = 0; argv[nargs] != NULL; ++nargs)
94
+ /* Only retry compiler ICEs, not preprocessor ones. */
95
+ if (! strcmp (argv[nargs], "-E"))
97
+ else if (argv[nargs][0] == '-' && argv[nargs][1] == 'o')
104
+ /* If the compiler is going to output any time information,
105
+ it might varry between invocations. */
106
+ else if (! strcmp (argv[nargs], "-quiet"))
108
+ else if (! strcmp (argv[nargs], "-ftime-report"))
111
+ if (out_arg == -1 || !quiet)
114
+ memset (temp_filenames, '\0', sizeof (temp_filenames));
115
+ new_argv = XALLOCAVEC (const char *, nargs + 3);
116
+ memcpy (new_argv, argv, (nargs + 1) * sizeof (const char *));
117
+ new_argv[nargs++] = "-frandom-seed=0";
118
+ new_argv[nargs] = NULL;
119
+ if (new_argv[out_arg][2] == '\0')
120
+ new_argv[out_arg + 1] = "-";
122
+ new_argv[out_arg] = "-o-";
124
+ for (attempt = 0; attempt < RETRY_ICE_ATTEMPTS + 1; ++attempt)
129
+ temp_filenames[attempt * 2] = make_temp_file (".out");
130
+ temp_filenames[attempt * 2 + 1] = make_temp_file (".err");
132
+ if (attempt == RETRY_ICE_ATTEMPTS)
136
+ struct stat st1, st2;
140
+ buf = XNEWVEC (char, 8192);
142
+ for (i = 0; i < 2; ++i)
144
+ fd1 = open (temp_filenames[i], O_RDONLY);
145
+ fd2 = open (temp_filenames[2 + i], O_RDONLY);
147
+ if (fd1 < 0 || fd2 < 0)
155
+ if (fstat (fd1, &st1) < 0 || fstat (fd2, &st2) < 0)
163
+ if (st1.st_size != st2.st_size)
171
+ for (n = st1.st_size; n; n -= len)
177
+ if (read (fd1, buf, len) != (int) len
178
+ || read (fd2, buf + 4096, len) != (int) len)
184
+ if (memcmp (buf, buf + 4096, len) != 0)
201
+ fnotice (stderr, "The bug is not reproducible, so it is"
202
+ " likely a hardware or OS problem.\n");
206
+ fd = open (temp_filenames[attempt * 2], O_RDWR);
209
+ write (fd, "//", 2);
210
+ for (i = 0; i < nargs; i++)
212
+ write (fd, " ", 1);
213
+ write (fd, new_argv[i], strlen (new_argv[i]));
215
+ write (fd, "\n", 1);
216
+ new_argv[nargs] = "-E";
217
+ new_argv[nargs + 1] = NULL;
220
+ /* Fork a subprocess; wait and retry if it fails. */
221
+ sleep_interval = 1;
223
+ for (retries = 0; retries < 4; retries++)
228
+ sleep (sleep_interval);
229
+ sleep_interval *= 2;
236
+ if (attempt != RETRY_ICE_ATTEMPTS)
237
+ fd = open (temp_filenames[attempt * 2], O_RDWR);
247
+ fd = open (temp_filenames[attempt * 2 + 1], O_RDWR);
257
+ if (prog == new_argv[0])
258
+ execvp (prog, CONST_CAST2 (char *const *, const char **, new_argv));
260
+ execv (new_argv[0], CONST_CAST2 (char *const *, const char **, new_argv));
264
+ if (waitpid (pid, &status, 0) < 0)
267
+ if (attempt < RETRY_ICE_ATTEMPTS
268
+ && (! WIFEXITED (status) || WEXITSTATUS (status) != ICE_EXIT_CODE))
270
+ fnotice (stderr, "The bug is not reproducible, so it is"
271
+ " likely a hardware or OS problem.\n");
274
+ else if (attempt == RETRY_ICE_ATTEMPTS)
277
+ if (WIFEXITED (status)
278
+ && WEXITSTATUS (status) == SUCCESS_EXIT_CODE)
280
+ fnotice (stderr, "Preprocessed source stored into %s file,"
281
+ " please attach this to your bugreport.\n",
282
+ temp_filenames[attempt * 2]);
283
+ /* Make sure it is not deleted. */
284
+ free (temp_filenames[attempt * 2]);
285
+ temp_filenames[attempt * 2] = NULL;
291
+ for (attempt = 0; attempt < RETRY_ICE_ATTEMPTS * 2 + 2; attempt++)
292
+ if (temp_filenames[attempt])
294
+ unlink (temp_filenames[attempt]);
295
+ free (temp_filenames[attempt]);
300
/* Search for a file named NAME trying various prefixes including the
301
user's -B prefix and some standard ones.
302
Return the absolute file name found. If nothing is found, return NAME. */
303
Index: b/src/gcc/diagnostic.c
304
===================================================================
305
--- a/src/gcc/diagnostic.c
306
+++ b/src/gcc/diagnostic.c
309
diagnostic_finish (context);
310
fnotice (stderr, "compilation terminated.\n");
311
- exit (FATAL_EXIT_CODE);
312
+ exit (ICE_EXIT_CODE);