Janne Blomqvist
2018-09-24 08:56:58 UTC
libgfortran has a recursion check in the error handling paths. This
works by checking the value of a static variable, and if it matches,
aborting immediately instead of continuing error processing.
Unfortunately, in a multi-threaded program, if two threads report an
error at the same time, this can trigger this check, and thus the
underlying reason for the error is never reported.
The downside is that without the recursion check, it might be possible
to get into some infinite recursion in the error handling. But by my
audit of the code, this shouldn't happen.
Regtested on x86_64-pc-linux-gnu, Ok for trunk?
libgfortran/ChangeLog:
2018-09-24 Janne Blomqvist <***@gcc.gnu.org>
* runtime/error.c (MAGIC): Remove.
(recursion_check): Remove function.
(os_error): Remove recursion_check call.
(runtime_error): Likewise.
(runtime_error_at): Likewise.
(internal_error): Likewise.
(generate_error_common): Likewise.
(notify_std): Likewise.
* runtime/minimal.c (MAGIC): Remove.
(recursion_check): Remove function.
(os_error): Remove recursion_check call.
(runtime_error): Likewise.
(runtime_error_at): Likewise.
(internal_error): Likewise.
---
libgfortran/runtime/error.c | 25 -------------------------
libgfortran/runtime/minimal.c | 22 ----------------------
2 files changed, 47 deletions(-)
diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c
index b07a4c0b12a..b6cbd14ff6d 100644
--- a/libgfortran/runtime/error.c
+++ b/libgfortran/runtime/error.c
@@ -330,25 +330,6 @@ show_locus (st_parameter_common *cmp)
}
-/* recursion_check()-- It's possible for additional errors to occur
- * during fatal error processing. We detect this condition here and
- * exit with code 4 immediately. */
-
-#define MAGIC 0x20DE8101
-
-static void
-recursion_check (void)
-{
- static int magic = 0;
-
- /* Don't even try to print something at this point */
- if (magic == MAGIC)
- sys_abort ();
-
- magic = MAGIC;
-}
-
-
#define STRERR_MAXSZ 256
/* os_error()-- Operating system error. We get a message from the
@@ -360,7 +341,6 @@ os_error (const char *message)
{
char errmsg[STRERR_MAXSZ];
struct iovec iov[5];
- recursion_check ();
iov[0].iov_base = (char*) "Operating system error: ";
iov[0].iov_len = strlen (iov[0].iov_base);
iov[1].iov_base = gf_strerror (errno, errmsg, STRERR_MAXSZ);
@@ -388,7 +368,6 @@ runtime_error (const char *message, ...)
va_list ap;
int written;
- recursion_check ();
iov[0].iov_base = (char*) "Fortran runtime error: ";
iov[0].iov_len = strlen (iov[0].iov_base);
va_start (ap, message);
@@ -417,7 +396,6 @@ runtime_error_at (const char *where, const char *message, ...)
struct iovec iov[4];
int written;
- recursion_check ();
iov[0].iov_base = (char*) where;
iov[0].iov_len = strlen (where);
iov[1].iov_base = (char*) "\nFortran runtime error: ";
@@ -473,7 +451,6 @@ internal_error (st_parameter_common *cmp, const char *message)
{
struct iovec iov[3];
- recursion_check ();
show_locus (cmp);
iov[0].iov_base = (char*) "Internal Error: ";
iov[0].iov_len = strlen (iov[0].iov_base);
@@ -674,7 +651,6 @@ generate_error_common (st_parameter_common *cmp, int family, const char *message
/* Return code, caller is responsible for terminating
the program if necessary. */
- recursion_check ();
show_locus (cmp);
struct iovec iov[3];
iov[0].iov_base = (char*) "Fortran runtime error: ";
@@ -766,7 +742,6 @@ notify_std (st_parameter_common *cmp, int std, const char * message)
if (!warning)
{
- recursion_check ();
show_locus (cmp);
iov[0].iov_base = (char*) "Fortran runtime error: ";
iov[0].iov_len = strlen (iov[0].iov_base);
diff --git a/libgfortran/runtime/minimal.c b/libgfortran/runtime/minimal.c
index b6d26fd2228..44ebd99af07 100644
--- a/libgfortran/runtime/minimal.c
+++ b/libgfortran/runtime/minimal.c
@@ -43,24 +43,6 @@ options_t options;
static int argc_save;
static char **argv_save;
-/* recursion_check()-- It's possible for additional errors to occur
- * during fatal error processing. We detect this condition here and
- * exit with code 4 immediately. */
-
-#define MAGIC 0x20DE8101
-
-static void
-recursion_check (void)
-{
- static int magic = 0;
-
- /* Don't even try to print something at this point */
- if (magic == MAGIC)
- sys_abort ();
-
- magic = MAGIC;
-}
-
/* os_error()-- Operating system error. We get a message from the
* operating system, show it and leave. Some operating system errors
@@ -69,7 +51,6 @@ recursion_check (void)
void
os_error (const char *message)
{
- recursion_check ();
printf ("Operating system error: ");
printf ("%s\n", message);
exit (1);
@@ -85,7 +66,6 @@ runtime_error (const char *message, ...)
{
va_list ap;
- recursion_check ();
printf ("Fortran runtime error: ");
va_start (ap, message);
vprintf (message, ap);
@@ -103,7 +83,6 @@ runtime_error_at (const char *where, const char *message, ...)
{
va_list ap;
- recursion_check ();
printf ("%s", where);
printf ("\nFortran runtime error: ");
va_start (ap, message);
@@ -136,7 +115,6 @@ iexport(runtime_warning_at);
void
internal_error (st_parameter_common *cmp, const char *message)
{
- recursion_check ();
printf ("Internal Error: ");
printf ("%s", message);
printf ("\n");
works by checking the value of a static variable, and if it matches,
aborting immediately instead of continuing error processing.
Unfortunately, in a multi-threaded program, if two threads report an
error at the same time, this can trigger this check, and thus the
underlying reason for the error is never reported.
The downside is that without the recursion check, it might be possible
to get into some infinite recursion in the error handling. But by my
audit of the code, this shouldn't happen.
Regtested on x86_64-pc-linux-gnu, Ok for trunk?
libgfortran/ChangeLog:
2018-09-24 Janne Blomqvist <***@gcc.gnu.org>
* runtime/error.c (MAGIC): Remove.
(recursion_check): Remove function.
(os_error): Remove recursion_check call.
(runtime_error): Likewise.
(runtime_error_at): Likewise.
(internal_error): Likewise.
(generate_error_common): Likewise.
(notify_std): Likewise.
* runtime/minimal.c (MAGIC): Remove.
(recursion_check): Remove function.
(os_error): Remove recursion_check call.
(runtime_error): Likewise.
(runtime_error_at): Likewise.
(internal_error): Likewise.
---
libgfortran/runtime/error.c | 25 -------------------------
libgfortran/runtime/minimal.c | 22 ----------------------
2 files changed, 47 deletions(-)
diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c
index b07a4c0b12a..b6cbd14ff6d 100644
--- a/libgfortran/runtime/error.c
+++ b/libgfortran/runtime/error.c
@@ -330,25 +330,6 @@ show_locus (st_parameter_common *cmp)
}
-/* recursion_check()-- It's possible for additional errors to occur
- * during fatal error processing. We detect this condition here and
- * exit with code 4 immediately. */
-
-#define MAGIC 0x20DE8101
-
-static void
-recursion_check (void)
-{
- static int magic = 0;
-
- /* Don't even try to print something at this point */
- if (magic == MAGIC)
- sys_abort ();
-
- magic = MAGIC;
-}
-
-
#define STRERR_MAXSZ 256
/* os_error()-- Operating system error. We get a message from the
@@ -360,7 +341,6 @@ os_error (const char *message)
{
char errmsg[STRERR_MAXSZ];
struct iovec iov[5];
- recursion_check ();
iov[0].iov_base = (char*) "Operating system error: ";
iov[0].iov_len = strlen (iov[0].iov_base);
iov[1].iov_base = gf_strerror (errno, errmsg, STRERR_MAXSZ);
@@ -388,7 +368,6 @@ runtime_error (const char *message, ...)
va_list ap;
int written;
- recursion_check ();
iov[0].iov_base = (char*) "Fortran runtime error: ";
iov[0].iov_len = strlen (iov[0].iov_base);
va_start (ap, message);
@@ -417,7 +396,6 @@ runtime_error_at (const char *where, const char *message, ...)
struct iovec iov[4];
int written;
- recursion_check ();
iov[0].iov_base = (char*) where;
iov[0].iov_len = strlen (where);
iov[1].iov_base = (char*) "\nFortran runtime error: ";
@@ -473,7 +451,6 @@ internal_error (st_parameter_common *cmp, const char *message)
{
struct iovec iov[3];
- recursion_check ();
show_locus (cmp);
iov[0].iov_base = (char*) "Internal Error: ";
iov[0].iov_len = strlen (iov[0].iov_base);
@@ -674,7 +651,6 @@ generate_error_common (st_parameter_common *cmp, int family, const char *message
/* Return code, caller is responsible for terminating
the program if necessary. */
- recursion_check ();
show_locus (cmp);
struct iovec iov[3];
iov[0].iov_base = (char*) "Fortran runtime error: ";
@@ -766,7 +742,6 @@ notify_std (st_parameter_common *cmp, int std, const char * message)
if (!warning)
{
- recursion_check ();
show_locus (cmp);
iov[0].iov_base = (char*) "Fortran runtime error: ";
iov[0].iov_len = strlen (iov[0].iov_base);
diff --git a/libgfortran/runtime/minimal.c b/libgfortran/runtime/minimal.c
index b6d26fd2228..44ebd99af07 100644
--- a/libgfortran/runtime/minimal.c
+++ b/libgfortran/runtime/minimal.c
@@ -43,24 +43,6 @@ options_t options;
static int argc_save;
static char **argv_save;
-/* recursion_check()-- It's possible for additional errors to occur
- * during fatal error processing. We detect this condition here and
- * exit with code 4 immediately. */
-
-#define MAGIC 0x20DE8101
-
-static void
-recursion_check (void)
-{
- static int magic = 0;
-
- /* Don't even try to print something at this point */
- if (magic == MAGIC)
- sys_abort ();
-
- magic = MAGIC;
-}
-
/* os_error()-- Operating system error. We get a message from the
* operating system, show it and leave. Some operating system errors
@@ -69,7 +51,6 @@ recursion_check (void)
void
os_error (const char *message)
{
- recursion_check ();
printf ("Operating system error: ");
printf ("%s\n", message);
exit (1);
@@ -85,7 +66,6 @@ runtime_error (const char *message, ...)
{
va_list ap;
- recursion_check ();
printf ("Fortran runtime error: ");
va_start (ap, message);
vprintf (message, ap);
@@ -103,7 +83,6 @@ runtime_error_at (const char *where, const char *message, ...)
{
va_list ap;
- recursion_check ();
printf ("%s", where);
printf ("\nFortran runtime error: ");
va_start (ap, message);
@@ -136,7 +115,6 @@ iexport(runtime_warning_at);
void
internal_error (st_parameter_common *cmp, const char *message)
{
- recursion_check ();
printf ("Internal Error: ");
printf ("%s", message);
printf ("\n");
--
2.17.1
2.17.1