public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/96817] __cxa_guard_acquire unsafe against dynamically loaded pthread Date: Thu, 27 Aug 2020 14:02:46 +0000 [thread overview] Message-ID: <bug-96817-4-LEITjWqVfn@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-96817-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96817 Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Last reconfirmed| |2020-08-27 Status|UNCONFIRMED |NEW --- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> --- Something like this should work with the latest glibc: --- a/libstdc++-v3/libsupc++/guard.cc +++ b/libstdc++-v3/libsupc++/guard.cc @@ -252,7 +252,22 @@ namespace __cxxabiv1 # ifdef _GLIBCXX_USE_FUTEX // If __atomic_* and futex syscall are supported, don't use any global // mutex. +#if __has_include(<sys/single_threaded.h>) + // Prefer to rely on __libc_single_threaded instead of __gthread_active_p + if (__libc_single_threaded) + { + int *gi = (int *) (void *) g; + if (*gi == 0) + { + *gi = _GLIBCXX_GUARD_PENDING_BIT; + return 1; + } + else + throw_recursive_init_exception(); + } +#else if (__gthread_active_p ()) +#endif { int *gi = (int *) (void *) g; const int guard_bit = _GLIBCXX_GUARD_BIT; @@ -390,7 +405,17 @@ namespace __cxxabiv1 #ifdef _GLIBCXX_USE_FUTEX // If __atomic_* and futex syscall are supported, don't use any global // mutex. +#if __has_include(<sys/single_threaded.h>) + // Prefer to rely on __libc_single_threaded instead of __gthread_active_p + if (__libc_single_threaded) + { + int *gi = (int *) (void *) g; + *gi = _GLIBCXX_GUARD_BIT; + return; + } +#else if (__gthread_active_p ()) +#endif { int *gi = (int *) (void *) g; const int guard_bit = _GLIBCXX_GUARD_BIT;
next prev parent reply other threads:[~2020-08-27 14:02 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-08-27 12:32 [Bug libstdc++/96817] New: " yshuiv7 at gmail dot com 2020-08-27 12:48 ` [Bug libstdc++/96817] " yshuiv7 at gmail dot com 2020-08-27 12:48 ` redi at gcc dot gnu.org 2020-08-27 12:53 ` yshuiv7 at gmail dot com 2020-08-27 12:58 ` rguenth at gcc dot gnu.org 2020-08-27 13:05 ` yshuiv7 at gmail dot com 2020-08-27 13:06 ` yshuiv7 at gmail dot com 2020-08-27 13:15 ` redi at gcc dot gnu.org 2020-08-27 13:23 ` redi at gcc dot gnu.org 2020-08-27 13:26 ` yshuiv7 at gmail dot com 2020-08-27 13:34 ` redi at gcc dot gnu.org 2020-08-27 14:02 ` redi at gcc dot gnu.org [this message] 2020-08-27 14:04 ` redi at gcc dot gnu.org 2020-09-25 18:11 ` redi at gcc dot gnu.org 2020-09-25 19:55 ` redi at gcc dot gnu.org 2020-09-25 20:37 ` yshuiv7 at gmail dot com 2020-09-25 20:40 ` yshuiv7 at gmail dot com 2020-09-26 19:41 ` cvs-commit at gcc dot gnu.org 2020-10-25 9:27 ` rimvydas.jas at gmail dot com 2020-10-25 22:08 ` redi at gcc dot gnu.org 2020-11-04 15:34 ` cvs-commit at gcc dot gnu.org 2020-11-04 15:36 ` redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-96817-4-LEITjWqVfn@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).