* [PATCH] libgomp: fix hang on fatal error
@ 2022-10-14 17:04 Andrew Stubbs
2022-10-19 13:27 ` Jakub Jelinek
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Stubbs @ 2022-10-14 17:04 UTC (permalink / raw)
To: gcc-patches, Jakub Jelinek
[-- Attachment #1: Type: text/plain, Size: 305 bytes --]
This patch fixes a problem in which fatal errors inside mutex-locked
regions (i.e. basically anything in the plugin) will cause it to hang up
trying to take the lock to clean everything up.
Using abort() instead of exit(1) bypasses the atexit handlers and solves
the problem.
OK for mainline?
Andrew
[-- Attachment #2: 221014-abort-libgomp.patch --]
[-- Type: text/plain, Size: 512 bytes --]
libgomp: fix hang on fatal error
Don't try to clean up if a fatal error occurs in libgomp. Typically the
cleanup is not reentrant so we end up hung on a lock.
libgomp/ChangeLog:
* error.c (gomp_vfatal): Use abort instead of exit.
diff --git a/libgomp/error.c b/libgomp/error.c
index 50ed85eedb1..25548c14a82 100644
--- a/libgomp/error.c
+++ b/libgomp/error.c
@@ -77,7 +77,7 @@ void
gomp_vfatal (const char *fmt, va_list list)
{
gomp_verror (fmt, list);
- exit (EXIT_FAILURE);
+ abort ();
}
void
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libgomp: fix hang on fatal error
2022-10-14 17:04 [PATCH] libgomp: fix hang on fatal error Andrew Stubbs
@ 2022-10-19 13:27 ` Jakub Jelinek
2022-10-19 16:08 ` Jakub Jelinek
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2022-10-19 13:27 UTC (permalink / raw)
To: Andrew Stubbs; +Cc: gcc-patches
On Fri, Oct 14, 2022 at 06:04:06PM +0100, Andrew Stubbs wrote:
> This patch fixes a problem in which fatal errors inside mutex-locked regions
> (i.e. basically anything in the plugin) will cause it to hang up trying to
> take the lock to clean everything up.
>
> Using abort() instead of exit(1) bypasses the atexit handlers and solves the
> problem.
>
> OK for mainline?
>
> Andrew
> libgomp: fix hang on fatal error
>
> Don't try to clean up if a fatal error occurs in libgomp. Typically the
> cleanup is not reentrant so we end up hung on a lock.
>
> libgomp/ChangeLog:
>
> * error.c (gomp_vfatal): Use abort instead of exit.
>
> diff --git a/libgomp/error.c b/libgomp/error.c
> index 50ed85eedb1..25548c14a82 100644
> --- a/libgomp/error.c
> +++ b/libgomp/error.c
> @@ -77,7 +77,7 @@ void
> gomp_vfatal (const char *fmt, va_list list)
> {
> gomp_verror (fmt, list);
> - exit (EXIT_FAILURE);
> + abort ();
> }
>
> void
I don't like this, abort has quite different user visible behavior
from exit, e.g. the former often dumps core.
I believe in most places libgomp handles this by releasing locks before
calling gomp_{,v}fatal:
gomp_mutex_unlock (®ister_lock);
gomp_fatal ("Out of memory allocating %lu bytes", (unsigned long) size);
gomp_mutex_unlock (&devicep->lock);
gomp_fatal ("Copying of %s object [%p..%p) to %s object [%p..%p) failed",
src, srcaddr, srcaddr + size, dst, dstaddr, dstaddr + size);
etc.
I could live with a gomp_fatal/gomp_vfatal alternative that would
use _exit/_Exit (but not sure if it is supported on all targets where
libgomp is) for uses where releasing locks is for whatever reason
not an option.
Jakub
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libgomp: fix hang on fatal error
2022-10-19 13:27 ` Jakub Jelinek
@ 2022-10-19 16:08 ` Jakub Jelinek
0 siblings, 0 replies; 3+ messages in thread
From: Jakub Jelinek @ 2022-10-19 16:08 UTC (permalink / raw)
To: Andrew Stubbs, gcc-patches
On Wed, Oct 19, 2022 at 03:27:52PM +0200, Jakub Jelinek via Gcc-patches wrote:
> > --- a/libgomp/error.c
> > +++ b/libgomp/error.c
> > @@ -77,7 +77,7 @@ void
> > gomp_vfatal (const char *fmt, va_list list)
> > {
> > gomp_verror (fmt, list);
> > - exit (EXIT_FAILURE);
> > + abort ();
> > }
> >
> > void
>
> I don't like this, abort has quite different user visible behavior
> from exit, e.g. the former often dumps core.
>
> I believe in most places libgomp handles this by releasing locks before
> calling gomp_{,v}fatal:
> gomp_mutex_unlock (®ister_lock);
> gomp_fatal ("Out of memory allocating %lu bytes", (unsigned long) size);
>
> gomp_mutex_unlock (&devicep->lock);
> gomp_fatal ("Copying of %s object [%p..%p) to %s object [%p..%p) failed",
> src, srcaddr, srcaddr + size, dst, dstaddr, dstaddr + size);
>
> etc.
> I could live with a gomp_fatal/gomp_vfatal alternative that would
> use _exit/_Exit (but not sure if it is supported on all targets where
> libgomp is) for uses where releasing locks is for whatever reason
> not an option.
Or yet another possibility would be not use gomp_fatal from within the
plugins, but use gomp_error instead and through possibly adjusted plugin
APIs tell libgomp that there was a fatal error and let libgomp unlock
anything that needs unlocking and exit (EXIT_FAILURE); afterwards.
Jakub
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-19 16:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-14 17:04 [PATCH] libgomp: fix hang on fatal error Andrew Stubbs
2022-10-19 13:27 ` Jakub Jelinek
2022-10-19 16:08 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).