From patchwork Mon Nov 6 11:52:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 161956 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2599927vqu; Mon, 6 Nov 2023 03:52:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAeU5oiTfXgF0WJLhQX9kmSvrmjozhUXHhDB8YVMh0HHiVOl70oqRmInzxfyB4JTrcq/hK X-Received: by 2002:a05:622a:1a16:b0:41e:280d:4e28 with SMTP id f22-20020a05622a1a1600b0041e280d4e28mr36144656qtb.40.1699271552792; Mon, 06 Nov 2023 03:52:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699271552; cv=pass; d=google.com; s=arc-20160816; b=Px64o4BY5mq56NGDG3i4YYINv00vj1fXD43zPApIgjhhoYcZ9BgGScZ4p5ssbE6NU3 JTS1UPV83ho/mjmc9Rtinl3fndWKy0XI7Y2tLEzWBLGmX0fFDpUmh5643FdaoagMQRtu jranGaIvUxoXs1BW7RmkLvV4K22jEbdAd/EgqLd1vypnmS7YaIHf6kAx/fFKqMQzgpm9 v4TmP+rw7hcJKUXXP6QU4dDjC1SzAI7XXpT6mHaKPaDr1O2EXJFHckhbDgDnjcrX0BoI fYGgyji37o3GeSgFOXQicQ5AV4+8hu9+1w44+S3gWOHthBrHcbXsrLpIzk2cdEaUWI4q hwKg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:errors-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:subject:cc:to:from:date:dkim-signature:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=+6oKAlVXkJ4Hod0po6yEs/l+VD9FJaYBqcfwM2vcn+w=; fh=qHeY7xWpDBX8i0oBQeHwS6lVwPNWhz7Nvl4vsUbGNts=; b=F8BCmKOb7iAks4scWKdbpoDVlw39RjFHIbvoNppKhg4gdGa9zqalP8LSVn/rfwi6NL 6aTH3xNsusCq8eQdV6fwpRoDiQiPZrpYyTQEAztFf7yV+1UmC1o6oscCFJ+xAljuyElC VTCX22nmmysXdVMgXzsoRMxaxLhWA/08oIxO2yvzyXzkIKiIllgyYgBE4gVNhTCAy86/ Vq9yH0HEdOrjxYPwWsUSk5+qTIGF/0crKlxBRy+gs1N+j46p7ba4hB1nr8qrbuLNjjUD T/espr1gQMI1qhdh+cu4pvWy58X2zSbLOEFCWz6v78M8qjUpsE8ls5LmGHE1nTPDHwid jFLw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=canIUwes; dkim=neutral (no key) header.i=@suse.de; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z18-20020a05622a061200b004180bc0da71si5298298qta.71.2023.11.06.03.52.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:52:32 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=canIUwes; dkim=neutral (no key) header.i=@suse.de; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F584385842C for ; Mon, 6 Nov 2023 11:52:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 525FE3858D33; Mon, 6 Nov 2023 11:52:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 525FE3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 525FE3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.220.28 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699271530; cv=none; b=WZ027eWkCJFLR//ixHfWXBrvfE4Ly1HUD6ke8ZHEHfr83DWlJYSGVhoGpU+ITGPPbCjwP4VeLIyToqxJjwwYsi8tFI4ktAN/1WhCBJjGg5mUbFhrhh7qPr13hsOh8WbXVPZASnjyaONbH6+yLLgXHueolU+4nk9TPhEIomvsmzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699271530; c=relaxed/simple; bh=SKQp/biwyCXE5fxvYXTfEV1nl3J1bFfJ0MAd/pRB1do=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:MIME-Version; b=Qg8t8lz24Be2QMOdsh6fO+gPytf1vrQt8KYnFNqCYmWlwZ91hLXllySBPee/TdiRWL+vsPcPnxe8/prgz0H3PBt2i+Mju4l9ejtwdbBQstWvFOvXt9/iZimk/Os7gSGZNfoFlTKo1sWnkp7BJ7/yVr8KInYaiVNtC8K/WiEA3TI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 4A3CE21907; Mon, 6 Nov 2023 11:52:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1699271528; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=+6oKAlVXkJ4Hod0po6yEs/l+VD9FJaYBqcfwM2vcn+w=; b=canIUwes6QdCCVNjFivDnOv9au1H9xwmzg1w3Rpm7lVN3FtQ4G0nNhk6HIZMbOaZ8qRtUS vzNYRabqwViB5uAT6OaxlZoagOC4Va53rQy4t2lY+FF/Twu3QwZi/SFFJmOhfSn8vIc8tT C1142NZBiWFSOdBs/qEj16x90n5V8uU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1699271528; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=+6oKAlVXkJ4Hod0po6yEs/l+VD9FJaYBqcfwM2vcn+w=; b=tcpOdvFhXfhhywhBFPEofgbVKhtgoQOHL3Hw0Wt6wl0cxhNl8TclOze3KrKJbD+qhLbwMN zRFxOqaegZ1uPOCQ== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 0F68A2C2E6; Mon, 6 Nov 2023 11:52:08 +0000 (UTC) Date: Mon, 6 Nov 2023 11:52:08 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: libstdc++@gcc.gnu.org, jwakely@redhat.com Subject: [PATCH] libstdc++/112351 - deal with __gthread_once failure during locale init User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Message-Id: <20231106115232.8F584385842C@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781815367893133966 X-GMAIL-MSGID: 1781815367893133966 The following makes the C++98 locale init path follow the way the C++11 performs initialization. This way we deal with pthread_once failing, falling back to non-threadsafe initialization which, given we initialize from the library, should be serialized by the dynamic loader already. Bootstrapped and tested on x86_64-unknown-linux-gnu, OK for trunk? And GCC 13 branch? Thanks, Richard. PR libstdc++/112351 libstdc++-v3/ * src/c++98/locale.cc (locale::facet::_S_get_c_locale): Always perform non-threadsafe init when threadsafe init failed. --- libstdc++-v3/src/c++98/locale.cc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/src/c++98/locale.cc b/libstdc++-v3/src/c++98/locale.cc index d308140bab7..e9bec1db3b6 100644 --- a/libstdc++-v3/src/c++98/locale.cc +++ b/libstdc++-v3/src/c++98/locale.cc @@ -216,12 +216,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifdef __GTHREADS if (__gthread_active_p()) __gthread_once(&_S_once, _S_initialize_once); - else #endif - { - if (!_S_c_locale) - _S_initialize_once(); - } + if (__builtin_expect (!_S_c_locale, 0)) + _S_initialize_once(); return _S_c_locale; }