From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id E12223858D38; Wed, 6 Dec 2023 14:41:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E12223858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E12223858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701873664; cv=none; b=EVzFRUyeayzvTfcyctywEwqdmhwz+O8Li4kVEIUHoqwg13ADSgy9KysE2IuZ5IPmJXHCGkt4OAWKrPD+S2us4LfsfvbFdQMgVKnI3Xy+mZQgnKuj15VgBxJy/aIiWox+31vgiqEGfCZ/aDmgXcxrUJK71QmznLztM4n4uHepllA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701873664; c=relaxed/simple; bh=WOgv+EQL5lsi5xBtr1lVZJTPJGVvbHAzvk7RO/cVJVs=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=WVVZcHbynEgpX3jG6cojKbbfa0Ty0dStJkVSkY0od9TXWmfdXkBnWx5xKM9Lt2bZ7k3IaRjwx4lfeju01FYtnaSt/1bolldrhIEBFe22ZsOA0gzSx7CXbg8iLYOOmwbcwBFbbrRzbT8sjsNE+3wcVwrZGs4+zZ5yOuuAHHi79u8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40c0fc1cf3dso25712585e9.0; Wed, 06 Dec 2023 06:41:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701873660; x=1702478460; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4OY1cZDpUUBeDs6zuGCA0DkMnXk+VOCvPXwE5kMki+8=; b=DtO/5XCJBLf3dJ+mmNfBlE5P43FwPXqpUI50QVAmQt8R++j/IiCU7OU4ZIw0LQnRqZ YBf5j4R838c3c0rG3fM17rPrxswP4OEz+uqQhVHLjlQw+HI73C0gkEcQoihQqghK1whm UdsWHQBDdTzrSy5NnYM6evZ1nYKnl9zvzOpU3cvweObu3C061Hc3Hg++hXcgm43nfWke S6/KNmgQAxVESF9xjbQlxIonFOhWItccL3E9rpmmO5Hcd5Mvslc7T9bEnL5mPV2QYdHg bMONS1W0+ssFDBR0b/w5n9LiReoLbcLGnG1/LPGgrSdikrGFcS33Y16KHonhLWj6+mLT 9MHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701873660; x=1702478460; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4OY1cZDpUUBeDs6zuGCA0DkMnXk+VOCvPXwE5kMki+8=; b=MH6z3A2R8YPoRRIV0/atOi/ntYNEOjTBtUG78xKUt80P69UBFKMkIOq32VbumVd24o 5uW44/4HQGuo+SsPOT+wrS/K7DQwAs0Yr3ARbD5Jl4GZTMCjv6dB0QLxCMbSxfR5OlO8 LIud8XgNbmV6zJhkNbV5s9iu4LWGL6bMBOH1RvZcOT34c1WG9cu19uisdwI2JwcDje3H 0p6wHEDzBMyGnM5eVMdD9joAP/0o3LXh/7Cjf2wLxJKNWHqzwiqaffBbX8wJ1YZxQti7 BbiUXUZdVXoMrVFvzP0SiAdqPN26DjFMdwxwLYVbAotsF/K4Gti4sx/5fQHn237n6npt /yFg== X-Gm-Message-State: AOJu0YwouCgTZkBlKpRZt0GJFMSXAWqBWsAOTKhndmwfhDCbILg0uASe oeBGLtfmIQ1RUb4VkXeHdS7MKDyR7T82gcVR5Jg= X-Google-Smtp-Source: AGHT+IGDP4JuSpFYyl1jk/9ntx9eYuVlh11LgxaLiO0DD7EViE3I5bueEw7NaQzjw1lCR4bGbFkMwEFFdG0W2k1Uh4Q= X-Received: by 2002:a1c:6a17:0:b0:40c:2572:2035 with SMTP id f23-20020a1c6a17000000b0040c25722035mr128482wmc.88.1701873660170; Wed, 06 Dec 2023 06:41:00 -0800 (PST) MIME-Version: 1.0 References: <87sf4fbjis.fsf@euler.schwinge.homeip.net> In-Reply-To: From: Jonathan Wakely Date: Wed, 6 Dec 2023 14:40:48 +0000 Message-ID: Subject: Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime To: Jonathan Wakely Cc: Thomas Schwinge , Alexandre Oliva , gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org, David Edelsohn Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 List-Id: On Wed, 6 Dec 2023 at 13:53, Jonathan Wakely wrote: > > On Wed, 6 Dec 2023 at 12:30, Thomas Schwinge wr= ote: > > > > 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 fo= r > > > a platform that lacks __cxa_thread_atexit_impl, even if the program i= s > > > 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 selec= t > > > 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= _CDTOR_CALLABI *dtor)(void *), > > return __cxa_thread_atexit_impl (dtor, obj, dso_handle); > > +#else > > + (void) dso_handle; > > #endif > > I would prefer: > > --- a/libstdc++-v3/libsupc++/atexit_thread.cc > +++ b/libstdc++-v3/libsupc++/atexit_thread.cc > @@ -148,7 +148,7 @@ __cxa_thread_atexit_impl (void > (_GLIBCXX_CDTOR_CALLABI *func) (void *), > // ??? 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, [[maybe_unused]] void *dso_ha= ndle) > _GLIBCXX_NOTHROW > { > #if __GXX_WEAK__ The patch is OK with that change. > > > > > > > > ... to avoid: > > > > [...]/source-gcc/libstdc++-v3/libsupc++/atexit_thread.cc: In functi= on =E2=80=98int __cxxabiv1::__cxa_thread_atexit(void (*)(void*), void*, voi= d*)=E2=80=99: > > [...]/source-gcc/libstdc++-v3/libsupc++/atexit_thread.cc:151:51: er= ror: unused parameter =E2=80=98dso_handle=E2=80=99 [-Werror=3Dunused-parame= ter] > > 151 | void *obj, void *dso_handl= e) > > | ~~~~~~^~~~~~~~~= ~ > > 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 err= ors) > > 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 err= ors) > > 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 err= ors) > > 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/l= ibsupc++/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 bui= ld > > > + // 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 Gesellsc= haft: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955 > > >