public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/95989] Segmentation fault compiling with static libraries and using jthread::request_stop Date: Thu, 19 Nov 2020 21:07:17 +0000 [thread overview] Message-ID: <bug-95989-4-mEKOJCsyC9@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-95989-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95989 --- Comment #16 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>: https://gcc.gnu.org/g:08b4d325711d5c6f68ac29443aba3fd7aa173ac8 commit r11-5183-g08b4d325711d5c6f68ac29443aba3fd7aa173ac8 Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu Nov 19 21:07:06 2020 +0000 libstdc++: Avoid calling undefined __gthread_self weak symbol [PR 95989] Since glibc 2.27 the pthread_self symbol has been defined in libc rather than libpthread. Because we only call pthread_self through a weak alias it's possible for statically linked executables to end up without a definition of pthread_self. This crashes when trying to call an undefined weak symbol. We can use the __GLIBC_PREREQ version check to detect the version of glibc where pthread_self is no longer in libpthread, and call it directly rather than through the weak reference. It would be better to check for pthread_self in libc during configure instead of hardcoding the __GLIBC_PREREQ check. That would be complicated by the fact that prior to glibc 2.27 libc.a didn't have the pthread_self symbol, but libc.so.6 did. The configure checks would need to try to link both statically and dynamically, and the result would depend on whether the static libc.a happens to be installed during configure (which could vary between different systems using the same version of glibc). Doing it properly is left for a future date, as that will be needed anyway after glibc moves all pthread symbols from libpthread to libc. When that happens we should revisit the whole approach of using weak symbols for pthread symbols. For the purposes of std::this_thread::get_id() we call pthread_self() directly when using glibc 2.27 or later. Otherwise, if __gthread_active_p() is true then we know the libpthread symbol is available so we call that. Otherwise, we are single-threaded and just use ((__gthread_t)1) as the thread ID. An undesirable consequence of this change is that code compiled prior to the change might inline the old definition of this_thread::get_id() which always returns (__gthread_t)1 in a program that isn't linked to libpthread. Code compiled after the change will use pthread_self() and so get a real TID. That could result in the main thread having different thread::id values in different translation units. This seems acceptable, as there are not expected to be many uses of thread::id in programs that aren't linked to libpthread. An earlier version of this patch also changed __gthread_self() to use __GLIBC_PREREQ(2, 27) and only use the weak symbol for older glibc. Tha might still make sense to do, but isn't needed by libstdc++ now. libstdc++-v3/ChangeLog: PR libstdc++/95989 * config/os/gnu-linux/os_defines.h (_GLIBCXX_NATIVE_THREAD_ID): Define new macro to get reliable thread ID. * include/bits/std_thread.h: (this_thread::get_id): Use new macro if it's defined. * testsuite/30_threads/jthread/95989.cc: New test. * testsuite/30_threads/this_thread/95989.cc: New test.
next prev parent reply other threads:[~2020-11-19 21:07 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-30 20:25 [Bug libstdc++/95989] New: " webrown.cpp at gmail dot com 2020-06-30 22:35 ` [Bug libstdc++/95989] " redi at gcc dot gnu.org 2020-06-30 22:59 ` antal.buss at ualberta dot ca 2020-06-30 23:21 ` redi at gcc dot gnu.org 2020-06-30 23:30 ` redi at gcc dot gnu.org 2020-06-30 23:39 ` redi at gcc dot gnu.org 2020-07-01 10:15 ` redi at gcc dot gnu.org 2020-07-01 13:28 ` fw at gcc dot gnu.org 2020-07-01 13:53 ` redi at gcc dot gnu.org 2020-07-06 12:38 ` fw at gcc dot gnu.org 2020-07-08 14:39 ` redi at gcc dot gnu.org 2020-07-08 15:36 ` redi at gcc dot gnu.org 2020-07-09 9:58 ` redi at gcc dot gnu.org 2020-11-11 17:26 ` redi at gcc dot gnu.org 2020-11-19 21:07 ` cvs-commit at gcc dot gnu.org [this message] 2020-11-20 13:49 ` cvs-commit at gcc dot gnu.org 2020-11-20 13:52 ` redi at gcc dot gnu.org 2021-09-21 13:42 ` ebotcazou at gcc dot gnu.org 2022-03-04 4:08 ` lightningdzeyenr at gmail dot com 2022-03-04 9:25 ` redi at gcc dot gnu.org 2022-03-09 4:27 ` lightningdzeyenr at gmail dot com 2023-03-03 19:10 ` cvs-commit at gcc dot gnu.org 2024-04-10 12:56 ` redi at gcc dot gnu.org 2024-04-10 17:32 ` pinskia 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-95989-4-mEKOJCsyC9@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).