From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 9906F385840C for ; Wed, 6 Dec 2023 05:29:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9906F385840C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9906F385840C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::635 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701840546; cv=none; b=JP5xmdfrHj6JhfXor6RiYm5q3Q9Q7YOwcRZOp8Tehl/cj6DFSv2bI9Vd62oyoKMDAjIawgv63aGXhp+jVYNJnixfqZPDqfB/wCP0S9wQyK4x+1xV5JfzJnG5yUun7jh2sITqYhTZt6yNIzgWRQxBb8d5DRPhGWalV9K4nr/ojps= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701840546; c=relaxed/simple; bh=1mOPXvp38fCfcqgsqAZuegRALqSA0U91BSRTNmxId6o=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sPtMKxzI3e/OT2hB8gUlB/oMc2Vwc7R2kGnhJw+Ra933tdR5xGDjXXQp6eaS4Z/C+F8s5tsu0DN5wvDl05xBdCj0IJjeqICwViT6LS0PO/J2UxXHxCU58xpy/6Qdy3VEHoaEw+lRR93jT6Oeul062/1zuYlO29YZcVhSoQ8TA5I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1d0c4d84bf6so11282235ad.1 for ; Tue, 05 Dec 2023 21:29:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1701840543; x=1702445343; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=XCi8kuYhCSJIyPRy8FYF95W1UZ7JSsr5oSM7/1SZTzQ=; b=RX5hqgJ5gSIzCUL6zqqv/Oz9pgAmidKz9cmC7Fea0l2o5OgXBqFi9jF+/rJuo1ePuA mQFXcSvSkznqVNV/iXQ+F1Ld7Ht6Rrr9xX3lMNYsyPDiCCb3BRlWn/UlHU7Lw/Lz7tA9 5yFwzT5EsRbpOSJznUWQprK/I1FnuLXDPPBDWFntjeMaNRZMQm7xXLyThAIct+K17ZBw szPTe/RZVoMjBqu2rDkwj4SWdMPIqEvP2CPg+fiVDmchVaE0tW4VcOrQA2DnqYieRC/1 3MriVGik2/RfPZbohFvYxXTW4WNDFbhFIFCsdV4F4/4TiPt+Hxjfl28i9lyP7h7dFiAz K3Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701840543; x=1702445343; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XCi8kuYhCSJIyPRy8FYF95W1UZ7JSsr5oSM7/1SZTzQ=; b=AYJ6zrnjXn/bjnJEVvGXuLhG+bmm6vuLIDngSodOMFl06tI61j3ZzbdOo1d7joZwQF 9aLmKFUrBBEn0uCAVcCad8DfG6hKfnHV7jVxqROOvfPAr3WNpfvrwnq2k1QQc5mWt87m JpQavPOq19aOHsOuW4Z4dmiTZaYOI+fVcLVwzL7dOUPtOSyq18fXdahjRlV+tWtWXtgz MttiKNfI2awSLJNkXpNGFsft6b2Y0kNNkk0shIXBfKtATUVOqWeeiAN4LAzjB8FWbsp6 4UpID7lvZsq8g8Z1yXczjgLV0VYGHjxbMPSXP3MYFyQy3nC6DWeR7eCbHaWX3EETmHtG TU3g== X-Gm-Message-State: AOJu0YxMpUm1jiAsjj7MwJtfLkBpHFf5b/77owFiDWBThMRHJHb9q5Dw ibtcY+Qaqgf1vsqs7eZP4EI3dQ== X-Google-Smtp-Source: AGHT+IFiiUY21VpzI6qF3QtNS9zREzfRj0AUkBdSXyZWoR5S7TvWyq0nheoYFceIvR86kYRIgEh7JQ== X-Received: by 2002:a17:903:1c3:b0:1cc:3ac9:7189 with SMTP id e3-20020a17090301c300b001cc3ac97189mr210250plh.7.1701840542770; Tue, 05 Dec 2023 21:29:02 -0800 (PST) Received: from free.home ([2804:7f1:2080:aca2:351d:7322:a72d:ca58]) by smtp.gmail.com with ESMTPSA id jb7-20020a170903258700b001d05bb77b43sm8876035plb.19.2023.12.05.21.29.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 21:29:02 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3B65Sg6H237875 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 02:28:42 -0300 From: Alexandre Oliva To: David Edelsohn Cc: GCC Patches Subject: Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime Organization: Free thinker, does not speak for AdaCore References: Date: Wed, 06 Dec 2023 02:28:42 -0300 In-Reply-To: (Alexandre Oliva's message of "Tue, 05 Dec 2023 21:54:07 -0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,WEIRD_QUOTING 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 Dec 5, 2023, Alexandre Oliva wrote: > Maybe we should narrow it down to targets in which weak undefined > symbols are available with the expected semantics, and where the symbol > is known to have ever been defined in libc. On it... This patch reintroduces the weak symbol reference only on GNU systems, where they're most likely to be useful. If other systems could benefit, we can always add them later. > Or maybe a weak definition (or weak alias to a definition) in that file > would enable us to test whether the weak definition was preempted Uhh... 'cept libc wouldn't preempt from libstdc++; the opposite would occur, but that doesn't help. Regstrapped on x86_64-linux-gnu, also tested with ac_cv_func___cxa_thread_atexit_impl=no. Ok to (re)install? libsupc++: try cxa_thread_atexit_impl at runtime g++.dg/tls/thread_local-order2.C fails when the toolchain is built for a platform that lacks __cxa_thread_atexit_impl, even if the program is built and run using that toolchain on a (later) platform that offers __cxa_thread_atexit_impl. This patch adds runtime testing for __cxa_thread_atexit_impl on select platforms (GNU variants, for starters) that support weak symbols. for libstdc++-v3/ChangeLog * config/os/gnu-linux/os_defines.h (_GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL): Define. * libsupc++/atexit_thread.cc [__GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL] (__cxa_thread_atexit): Add dynamic detection of __cxa_thread_atexit_impl. --- libstdc++-v3/config/os/gnu-linux/os_defines.h | 5 +++++ libstdc++-v3/libsupc++/atexit_thread.cc | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/config/os/gnu-linux/os_defines.h b/libstdc++-v3/config/os/gnu-linux/os_defines.h index 87317031fcd71..a2e4baec069d5 100644 --- a/libstdc++-v3/config/os/gnu-linux/os_defines.h +++ b/libstdc++-v3/config/os/gnu-linux/os_defines.h @@ -60,6 +60,11 @@ # define _GLIBCXX_HAVE_FLOAT128_MATH 1 #endif +// Enable __cxa_thread_atexit to rely on a (presumably libc-provided) +// __cxa_thread_atexit_impl, if it happens to be defined, even if +// configure couldn't find it during the build. +#define _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL 1 + #ifdef __linux__ // The following libpthread properties only apply to Linux, not GNU/Hurd. diff --git a/libstdc++-v3/libsupc++/atexit_thread.cc b/libstdc++-v3/libsupc++/atexit_thread.cc index 9346d50f5dafe..aa4ed5312bfe3 100644 --- a/libstdc++-v3/libsupc++/atexit_thread.cc +++ b/libstdc++-v3/libsupc++/atexit_thread.cc @@ -138,11 +138,32 @@ namespace { } } +#if __GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL +extern "C" +int __attribute__ ((__weak__)) +__cxa_thread_atexit_impl (void (_GLIBCXX_CDTOR_CALLABI *func) (void *), + void *arg, void *d); +#endif + +// ??? We can't make it an ifunc, can we? extern "C" int __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *), - void *obj, void */*dso_handle*/) + void *obj, void *dso_handle) _GLIBCXX_NOTHROW { +#if __GXX_WEAK__ && _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL + if (__cxa_thread_atexit_impl) + // Rely on a (presumably libc-provided) __cxa_thread_atexit_impl, + // if it happens to be defined, even if configure couldn't find it + // during the build. _GLIBCXX_MAY_HAVE___CXA_THREAD_ATEXIT_IMPL + // may be defined e.g. in os_defines.h on platforms where some + // versions of libc have a __cxa_thread_atexit_impl definition, + // but whose earlier versions didn't. This enables programs build + // by toolchains compatible with earlier libc versions to still + // benefit from a libc-provided __cxa_thread_atexit_impl. + return __cxa_thread_atexit_impl (dtor, obj, dso_handle); +#endif + // Do this initialization once. if (__gthread_active_p ()) { -- Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ Free Software Activist GNU Toolchain Engineer More tolerance and less prejudice are key for inclusion and diversity Excluding neuro-others for not behaving ""normal"" is *not* inclusive