From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9C9943858C2D; Thu, 2 Nov 2023 15:07:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C9943858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1698937639; bh=1TEaCMVsDlhtSglPgt8aOHq7KTKde4h+QhQODAw00Ko=; h=From:To:Subject:Date:From; b=S+9Yi4nOVMa4YxPbWUCSNTe6BQC8u1WEt4k6HOspvwIaEF+1v/4Q3qVztAvIjU1zg GDbvHOfPk0cZtvAeaL9LJKjzJXrN9KZzuVUyntfFTNhE0vzUIqYGzv/LKPdmkwy9DA cOO5r55p3VgeRu9waIFkfkmfts5jbgDiYeLOQqXg= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/112351] New: libstdc++ locale init doesn't handle __gthread_once failure Date: Thu, 02 Nov 2023 15:07:19 +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: 13.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112351 Bug ID: 112351 Summary: libstdc++ locale init doesn't handle __gthread_once failure Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Target Milestone: --- pthread_once called through gthread_once can return "an error number" but t= he locale init code isn't prepared for that, instead leaving the object uninitialized: src/c++98/locale.cc: __c_locale locale::facet::_S_get_c_locale() { #ifdef __GTHREADS if (__gthread_active_p()) __gthread_once(&_S_once, _S_initialize_once); else #endif { if (!_S_c_locale) _S_initialize_once(); } return _S_c_locale; } OTOH similar code exists for C++11 locales which doesn't specifically handle errors but instead executes the non-threaded fallback code in that case: src/c++11/locale_init.cc: void locale::_S_initialize() { #ifdef __GTHREADS if (!__gnu_cxx::__is_single_threaded()) __gthread_once(&_S_once, _S_initialize_once); #endif if (__builtin_expect(!_S_classic, 0)) _S_initialize_once(); } Imagine an application overriding pthread_once (and other thread functions) with an implementation that "fails" before some intitialization is done (also imagine, just for curiosity, it wouldn't signal failure but success and do nothing in that case...). It would be nice to handle the situation consistently and either do the single-threaded "fallback" or abort on failure.=