From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 84A2B3858020; Mon, 19 Oct 2020 07:10:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 84A2B3858020 From: "slyfox at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: slyfox at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Oct 2020 07:10:10 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97485 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 static std::once_flag of; static std::recursive_mutex * pm =3D nullptr; int main() { std::call_once(of, []() { pm =3D 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=3D) at ../sysdeps/unix/sysv/linux/raise.c:49 49 return ret; (gdb) bt #0 __GI_raise (sig=3D) 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=3D) 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=3D, tinfo=3D0x7ffff7f6f948 , dest=3D0x7ffff7e0a570 ) 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=3D-1) at /usr/src/debug/sys-devel/gcc-11.0.0_pre9999/build/x86_64-pc-linux-gnu/libst= dc++-v3/include/ext/new_allocator.h:89 #7 0x000055555555531d in std::call_once >(std::once_fla= g &, struct {...} &&) (__once=3D..., __f=3D...) 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-optio= ns-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 libpth= read can be loaded dynamically at a later point in program's runtime).=