From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 957DE3858D39; Wed, 6 Dec 2023 12:30:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 957DE3858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 957DE3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=68.232.141.98 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701865846; cv=none; b=ZnK2uH0kwvftFmekKIAS7PtgXpSTKmfDlXskZdGRwdK8UfddaWpMNuM8wQdyRfFv26NzTePDCPJ1lvHOSfnQBzZD1/sUeq3YEItphfSAurcLG2zL7uALCCuN18yNvMrLSMgm+1HP0U19SC5ibuAeHge4vRGddABsj9VitLE8wFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701865846; c=relaxed/simple; bh=Qhz7qXE0En71w9ELw/e299S26lXgMHaFd0O65411uVA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=SZh5j4vQG4psp9T62MQGhKCRk3wC8lcs2Lb/RI5amX88OeklZ5u4p+8dQ0B/CP0NOF99Vu2XVCQllF0PUa3XvZCaxA501uhhSv5MM/f3ZxQvONQrHMipHNKm9O+x5ejnno+DshHGqTs1lFVxuHrF5Tuu9Twn85KfieAJEjosCJA= ARC-Authentication-Results: i=1; server2.sourceware.org X-CSE-ConnectionGUID: UbraJg6wQWuc4fzY4pqeEg== X-CSE-MsgGUID: z3tW+NotRFWHcWo9mbqhHg== X-IronPort-AV: E=Sophos;i="6.04,255,1695715200"; d="scan'208";a="27553660" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 06 Dec 2023 04:30:43 -0800 IronPort-SDR: GaMFI/jlRK9lZ3TYQ1OFogObfb1PCjaxa8aAdQhzyX8OpvOdgivLcuUWS2zbQeCx6SkMSzT+1o 5+JCmuw9xHckhsX1v306m6QeVTxW80grp9pkLcZXjKiv79gXphmWHHUcIRT1e0VYXsmRughYJZ famYYzwvsW7LFNex9EZQuS6Yz4r85fvGchxv6AtmldIbzmoisym8oAsCIefjJXehmEH5UelI9y wKUXSk0F+Oufq4b6pJ07T+uEEDPLvMT96WuANF14KJeqAybX4BRMYRPgal8WvF5BL8VfGoEzyV 5s4= From: Thomas Schwinge To: Alexandre Oliva CC: , , David Edelsohn Subject: Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime In-Reply-To: References: User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/28.2 (x86_64-pc-linux-gnu) Date: Wed, 6 Dec 2023 13:30:35 +0100 Message-ID: <87sf4fbjis.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-14.mgc.mentorg.com (139.181.222.14) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,SPF_HELO_PASS,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 List-Id: Hi Alexandre! On 2023-12-06T02:28:42-0300, Alexandre Oliva wrote: > 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. Need something like: --- libstdc++-v3/libsupc++/atexit_thread.cc +++ libstdc++-v3/libsupc++/atexit_thread.cc @@ -164,2 +164,4 @@ __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDT= OR_CALLABI *dtor)(void *), return __cxa_thread_atexit_impl (dtor, obj, dso_handle); +#else + (void) dso_handle; #endif ... to avoid: [...]/source-gcc/libstdc++-v3/libsupc++/atexit_thread.cc: In function = =E2=80=98int __cxxabiv1::__cxa_thread_atexit(void (*)(void*), void*, void*)= =E2=80=99: [...]/source-gcc/libstdc++-v3/libsupc++/atexit_thread.cc:151:51: error:= unused parameter =E2=80=98dso_handle=E2=80=99 [-Werror=3Dunused-parameter] 151 | void *obj, void *dso_handle) | ~~~~~~^~~~~~~~~~ cc1plus: all warnings being treated as errors make[4]: *** [atexit_thread.lo] Error 1 With that, GCC/nvptx then is back to: UNSUPPORTED: g++.dg/tls/thread_local6.C -std=3Dc++98 PASS: g++.dg/tls/thread_local6.C -std=3Dc++14 (test for excess errors) PASS: g++.dg/tls/thread_local6.C -std=3Dc++14 execution test PASS: g++.dg/tls/thread_local6.C -std=3Dc++17 (test for excess errors) PASS: g++.dg/tls/thread_local6.C -std=3Dc++17 execution test PASS: g++.dg/tls/thread_local6.C -std=3Dc++20 (test for excess errors) PASS: g++.dg/tls/thread_local6.C -std=3Dc++20 execution test Gr=C3=BC=C3=9Fe Thomas > 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/libsu= pc++/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)(voi= d *), > - 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 ()) > { ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstra=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955