public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "slyfox at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/97485] New: std::call_once crashes at runtime on glibc if not linked to libpthread: Date: Mon, 19 Oct 2020 07:10:10 +0000 [thread overview] Message-ID: <bug-97485-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97485 Bug ID: 97485 Summary: std::call_once crashes at runtime on glibc if not linked to libpthread: Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: slyfox at gcc dot gnu.org Target Milestone: --- Initially bug was reported as a crash of llvm-tblgen tool: https://bugs.gentoo.org/749162. Small reproducer: $ cat a.cc #include <mutex> static std::once_flag of; static std::recursive_mutex * pm = nullptr; int main() { std::call_once(of, []() { pm = new std::recursive_mutex; }); } $ g++-10.2.0 a.cc -o a -ggdb3 && ./a terminate called after throwing an instance of 'std::system_error' what(): Unknown error -1 Aborted (core dumped) $ g++-10.2.0 a.cc -o a -pthread && ./a All gcc versions are affected (at least 6.5.0 and above). Backtrace: """ Reading symbols from ./a... (gdb) run Starting program: /tmp/a terminate called after throwing an instance of 'std::system_error' what(): Unknown error -1 Program received signal SIGABRT, Aborted. __GI_raise (sig=<optimized out>) at ../sysdeps/unix/sysv/linux/raise.c:49 49 return ret; (gdb) bt #0 __GI_raise (sig=<optimized out>) at ../sysdeps/unix/sysv/linux/raise.c:49 #1 0x00007ffff7a1c536 in __GI_abort () at abort.c:79 #2 0x00007ffff7dad961 in __gnu_cxx::__verbose_terminate_handler () at /usr/src/debug/sys-devel/gcc-11.0.0_pre9999/gcc-11.0.0_pre9999/libstdc++-v3/libsupc++/vterminate.cc:95 #3 0x00007ffff7ddcd9a in __cxxabiv1::__terminate (handler=<optimized out>) at /usr/src/debug/sys-devel/gcc-11.0.0_pre9999/gcc-11.0.0_pre9999/libstdc++-v3/libsupc++/eh_terminate.cc:48 #4 0x00007ffff7ddce05 in std::terminate () at /usr/src/debug/sys-devel/gcc-11.0.0_pre9999/gcc-11.0.0_pre9999/libstdc++-v3/libsupc++/eh_terminate.cc:58 #5 0x00007ffff7ddd098 in __cxxabiv1::__cxa_throw (obj=<optimized out>, tinfo=0x7ffff7f6f948 <typeinfo for std::system_error>, dest=0x7ffff7e0a570 <std::system_error::~system_error()>) at /usr/src/debug/sys-devel/gcc-11.0.0_pre9999/gcc-11.0.0_pre9999/libstdc++-v3/libsupc++/eh_throw.cc:95 #6 0x00007ffff7db0c7f in std::__throw_system_error (__i=-1) at /usr/src/debug/sys-devel/gcc-11.0.0_pre9999/build/x86_64-pc-linux-gnu/libstdc++-v3/include/ext/new_allocator.h:89 #7 0x000055555555531d in std::call_once<main()::<lambda()> >(std::once_flag &, struct {...} &&) (__once=..., __f=...) at /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include/g++-v10/mutex:743 #8 0x000055555555521a in main () at a.cc:7 """ https://stackoverflow.com/questions/8649828/what-are-the-correct-link-options-to-use-stdthread-in-gcc-under-linux suggests -pthread has to be used. Would it be feasible to convert this error as any of: 1. Link-time error that would complain about missing pthread_once symbol. 2. Successful run if libpthread is not present (probably not easy as libpthread can be loaded dynamically at a later point in program's runtime).
next reply other threads:[~2020-10-19 7:10 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-10-19 7:10 slyfox at gcc dot gnu.org [this message] 2020-10-19 7:14 ` [Bug libstdc++/97485] std::call_once crashes at runtime on glibc if not linked to libpthread: terminate called after throwing an instance of 'std::system_error': what(): Unknown error -1 slyfox at gcc dot gnu.org 2020-10-19 7:23 ` slyfox at gcc dot gnu.org 2020-10-19 12:56 ` redi at gcc dot gnu.org 2020-10-19 22:07 ` slyfox 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-97485-4@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).