From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTPS id 6ABC33858D37; Fri, 3 Mar 2023 08:18:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6ABC33858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D56BF11653A; Fri, 3 Mar 2023 03:18:45 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id eZw7Gv4gDoFq; Fri, 3 Mar 2023 03:18:45 -0500 (EST) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id 83660116536; Fri, 3 Mar 2023 03:18:45 -0500 (EST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3238IXda593313 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 3 Mar 2023 05:18:34 -0300 From: Alexandre Oliva To: Jonathan Wakely Cc: gcc-patches , "libstdc++" , Bernd Edlinger Subject: Re: [libstdc++] Use __gthread_join in jthread/95989 Organization: Free thinker, does not speak for AdaCore References: Errors-To: aoliva@lxoliva.fsfla.org Date: Fri, 03 Mar 2023 05:18:33 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,KAM_NUMSUBJECT,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Feb 17, 2023, Jonathan Wakely wrote: > The proper fix is to ensure the program has a non-weak reference to > pthread_join without extra help (or use a recent glibc where it always > works). Indeed! How about this? Regstrapped on x86_64-linux-gnu, also tested on arm-vx7r2 (gcc-12); verified that strong references are present in 95989.o, but not in libstdc++.a or .so. Ok to install? (nit: the static local in a ctor of a template class may make for multiple copies. Maybe a non-template always-inline function called by all instantiations would be better.) link pthread_join from std::thread ctor Like pthread_create, pthread_join may fail to be statically linked in absent strong uses, so add to user code strong references to both when std::thread objects are created. for libstdc++-v3/ChangeLog * include/bits/std_thread.h (std::thread ctor): Add strong reference to pthread_join. --- libstdc++-v3/include/bits/std_thread.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libstdc++-v3/include/bits/std_thread.h b/libstdc++-v3/include/bits/std_thread.h index adbd3928ff783..4bda350fa2c7b 100644 --- a/libstdc++-v3/include/bits/std_thread.h +++ b/libstdc++-v3/include/bits/std_thread.h @@ -145,6 +145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifdef GTHR_ACTIVE_PROXY // Create a reference to pthread_create, not just the gthr weak symbol. auto __depend = reinterpret_cast(&pthread_create); + static auto __attribute__((__used__)) __depend_join = &pthread_join; #else auto __depend = nullptr; #endif -- Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ Free Software Activist GNU Toolchain Engineer Disinformation flourishes because many people care deeply about injustice but very few check the facts. Ask me about