From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 9A2113858C54 for ; Wed, 6 Dec 2023 13:52:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A2113858C54 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9A2113858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701870773; cv=none; b=TNmuVwDjCg/7/c49weWDTkronygqpiBDMQToGnQd4JKMhYODoRy2tRCJmNjzRmjrY1KWJSttdK33nhplEvwaIq1NuOltaJJm73vtmFBdr4YYr3/l0y2wSTefAYFWFDDaUN+dgmmIZLm4Xc1oHiUMYQ8Nt3SVtsh5KOLaBj6LMew= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701870773; c=relaxed/simple; bh=1g+O/z662oNVvrlQh2HUibHkltqQVMZTQRwScDAZz5o=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=w+InRIZfKAH+YnTLB7K70TJf5wiXCKF+5tHj5uichc35F7Uagx7Evu9omxg6+9WCPc2hS+sWEQV/wBJFDnsWXlhKQuDr6K19pl0Zi5e9RPoDHXtKvXaevZ+XuJFAkFMZST1phslXaWn5nUqoLiEaEIkjPV5dI0TZLLdAKXGjjs8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701870770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qvV/LuB127F5kXT/wA0tl2PIKF0zxfJhso2soJxOiWg=; b=Xflro7tMzL9cugt3u5mDmj3UIiaz/HHErFMXBO41f6p2/Dv9pF7ALC0wRDCxPDJSUz8X9Y ixr4mmHiI7OZaIPEMCoIbuu7UFZ50qTce6jPsaiCW6MAdiHC7gwpC9mZv8w119R0a4/xAb oTPn2QQ31SQd1dbR/46P9Yn13zKmzow= Received: from mail-yw1-f199.google.com (mail-yw1-f199.google.com [209.85.128.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-144-ayVTknwANH2qTjLmwmJ8pQ-1; Wed, 06 Dec 2023 08:52:49 -0500 X-MC-Unique: ayVTknwANH2qTjLmwmJ8pQ-1 Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-5ce16bc121aso110375567b3.1 for ; Wed, 06 Dec 2023 05:52:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701870768; x=1702475568; 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=qvV/LuB127F5kXT/wA0tl2PIKF0zxfJhso2soJxOiWg=; b=w+HKPa/x6zaeBI0Z/tIHQAiPBXwBwNyHmFLoFfmDnIQv6E+7wX5fiTl+oxGcyhOmow NdnArsnlDgz6IPriuhNz90Q0CtxLE4ErUBhyFkUQdePfzdnT2IidhGHWANw+QDFaciOG qHza56bJOk11zXzgJ3fFDGmDLBsxBiT3L+fG5El94oYFuX0Iiy/e7PxtOExlfswhd2zn MOiszHgPtpsa0sKggMGbhK2tBgcq/J77FPnjhyeQPArPDZNdYrixHEncflkBQ0Weiju4 FhYFyfbLup7PKCLT3E87U2qFVI0lEEVh2qrJuJeRuIKb4sm3kLcj9pOnhU/a63KOnfic 5ZIg== X-Gm-Message-State: AOJu0YwgYO7KXdvs0NZV7FkPJAifF7JqFYtVestJAkBPnPNig4VziyDN Rg79oZsLdPGCq8yKPk5DmZLP3mjDKd3b3WWNskUkEaS1mmdyKpRkPliBNG7EkCm4wF9a+tNzowq 6bz/akMH91qhvgSDRpVnMkuezBsHIPH4= X-Received: by 2002:a81:7e49:0:b0:5d6:c70f:7798 with SMTP id p9-20020a817e49000000b005d6c70f7798mr731650ywn.35.1701870767882; Wed, 06 Dec 2023 05:52:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEk7QJPbVVQTPQv8PMgNwUoBG4iZZyFxFticoRr7yZO7pq8EvF/sw+rah2oIc2cP1ucEdPcoiC1G5rkA8f82uE= X-Received: by 2002:a81:7e49:0:b0:5d6:c70f:7798 with SMTP id p9-20020a817e49000000b005d6c70f7798mr731640ywn.35.1701870767587; Wed, 06 Dec 2023 05:52:47 -0800 (PST) MIME-Version: 1.0 References: <87sf4fbjis.fsf@euler.schwinge.homeip.net> In-Reply-To: <87sf4fbjis.fsf@euler.schwinge.homeip.net> From: Jonathan Wakely Date: Wed, 6 Dec 2023 13:52:36 +0000 Message-ID: Subject: Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime To: Thomas Schwinge Cc: Alexandre Oliva , gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org, David Edelsohn X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 12:30, Thomas Schwinge wrot= e: > > 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_C= DTOR_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)(void = *), - void *obj, void *dso_handle) + void *obj, [[maybe_unused]] void *dso_hand= le) _GLIBCXX_NOTHROW { #if __GXX_WEAK__ > > ... 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: erro= r: unused parameter =E2=80=98dso_handle=E2=80=99 [-Werror=3Dunused-paramete= r] > 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 error= s) > 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 error= s) > 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 error= s) > 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/Hu= rd. > > > > diff --git a/libstdc++-v3/libsupc++/atexit_thread.cc b/libstdc++-v3/lib= supc++/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)(v= oid *), > > - 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 2= 01, 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 >