From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 79A513858020; Mon, 19 Oct 2020 07:23:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79A513858020 From: "slyfox at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [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 Date: Mon, 19 Oct 2020 07:23:50 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: Message-ID: In-Reply-To: References: 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:23:50 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97485 --- Comment #2 from Sergei Trofimovich --- AFAIU '-1' comes from https://gcc.gnu.org/git/?p=3Dgcc.git;a=3Dblob;f=3Dlibgcc/gthr-posix.h;h=3D9= 65247602acf11f81c5fa009c7ee48eb55cbacca;hb=3DHEAD#l696 696 static inline int 697 __gthread_once (__gthread_once_t *__once, void (*__func) (void)) 698 { 699 if (__gthread_active_p ()) 700 return __gthrw_(pthread_once) (__once, __func); 701 else 702 return -1; 703 } where '__gthread_active_p ()' returns false: (gdb) call __gthread_active_p() $2 =3D 0 That is defined in https://gcc.gnu.org/git/?p=3Dgcc.git;a=3Dblob;f=3Dlibgcc/gthr-posix.h;h=3D9= 65247602acf11f81c5fa009c7ee48eb55cbacca;hb=3DHEAD#l236 236 #ifdef __GLIBC__ 237 __gthrw2(__gthrw_(__pthread_key_create), 238 __pthread_key_create, 239 pthread_key_create) 240 # define GTHR_ACTIVE_PROXY __gthrw_(__pthread_key_create) 241 #elif defined (__BIONIC__) 242 # define GTHR_ACTIVE_PROXY __gthrw_(pthread_create) 243 #else 244 # define GTHR_ACTIVE_PROXY __gthrw_(pthread_cancel) 245 #endif 246=20 247 static inline int 248 __gthread_active_p (void) 249 { 250 static void *const __gthread_active_ptr 251 =3D __extension__ (void *) >HR_ACTIVE_PROXY; 252 return __gthread_active_ptr !=3D 0; 253 } Both of symbols are weak, unbound to libpthread and unversioned (for non-working case): $ g++-11.0.0 a.cc -o a && x86_64-pc-linux-gnu-nm -D a | fgrep -i pthread w __pthread_key_create w pthread_once $ g++-11.0.0 a.cc -o a -pthread && x86_64-pc-linux-gnu-nm -D a | fgrep -i pthread w __pthread_key_create@@GLIBC_2.2.5 w pthread_once@@GLIBC_2.2.5=