From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id CE62E3858C54 for ; Wed, 6 Dec 2023 22:46:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CE62E3858C54 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 CE62E3858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701902804; cv=none; b=jYu03BitgZJSssYTmuSQGCrkph3KdmtLY+w61B1dQeSPBdADD9OuXVk4J38BKaoa2h34qXRUiUW/HxrnL7+0Qs84bz9qPx2jg/ajBfllvVdfTO7y6b4NUHHOhsksigRz58BFN5J+r3ZzYE8eEpV5plAb3JSjEDXTcip6lCeMvB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701902804; c=relaxed/simple; bh=mV0QeW0HVYa2HSZhZ83qUZHBlHhFx+sejHajLM018fw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jqRwhe+SDTGSS4RsPE+yvvWe37kWDPXdu/XVDNgUnj+b70+RhxUW89qB59+Q4jFYs/2rP3z/zcGuTAytjYRC+qjlatpNXJdtjOIp2HUlh8yII5k84LgMyX6FQEFQBl8yH3VeXNA4tqN3s2OIMZgeWdCoHUq8dTuMbp6ON9rm0qs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6ce939ecfc2so31516b3a.2 for ; Wed, 06 Dec 2023 14:46:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1701902802; x=1702507602; 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=L+Qi052EIpK6RI9mA4Jlr1CHgLL/4Kd1ANyPLlBXA9w=; b=guPu+WlL5fA5ReO/Yns1KlFx4aDD2V6qmjIur+zg42nP4SuDb2dOM276t9J9s9xQp5 Bg2azrSw4dXwDkFbMGuhHYbVEZ+X5Nf7hAas+c0z47WjGnremtFotwpurxfeojfsgR5H o3HTnCKh19gi3sjuZUNmbuxKVRwYx8lAEeVtJKQ+RwEZ/oU3Z4OXPx6DLnD0tIzHYEGi CVMD0IAnj4FDj7S+XqXHifYAOvV2mthN0DeAUTy/hoRWH6T4rN7OaC8pl8hQ9DaA6ugu Dx3TECdS4Aooxj5XGsnrriutX30W0LtEfXy0Uxo+4np6xB+blwT20vv+jlzIZrso3Onb lmdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701902802; x=1702507602; 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=L+Qi052EIpK6RI9mA4Jlr1CHgLL/4Kd1ANyPLlBXA9w=; b=H8sFtEsCOPVdqlDA7oC+gmA0zFoS8pVsFce5D+kWOu7Odx7os4H7qdf8UT8GGMFrqH jMz7arXGlywEOI/zGiE14D4gfkxenbHOaP8U5Q03eflz3SR7LehrWPPRpBTMlr2tt9Zf IwVudNS/I7RiRWUuKx7oyC1dQSfQOQSyUJsgSJGakpyZfHNIeqyhKh4RUzDTUkQFAeLc u72Wmqx6J9uTumc6vBURICV+A5+YYFKx8okz3ZSGYHItJTE52MmcWAjv5IUaQns6Kao+ 7GMX1QjLzG5rlrm8L3CAPiIntdOskDCsSauMoEybLsihwgaSCP0917XfHqJGJ5ThsE7I THzQ== X-Gm-Message-State: AOJu0YxE5ALLZqgFreDeJpoweYfZ7P+9GTuzWxVP3hjW5k3RUHhynE+9 NZ3F4eJr3/mOqq7V3AEDwTI0OA== X-Google-Smtp-Source: AGHT+IEx/ZBa/Mqhr+ZHMB3DaFixpw4WSkMUN0W8qxcE1GR7wsuMQac9kXbiHvbz3TTAYoDroYwJmw== X-Received: by 2002:a05:6a20:7f81:b0:18c:c37:35d4 with SMTP id d1-20020a056a207f8100b0018c0c3735d4mr1809736pzj.14.1701902801759; Wed, 06 Dec 2023 14:46:41 -0800 (PST) Received: from free.home ([2804:14c:4d1:44a5::1000]) by smtp.gmail.com with ESMTPSA id f28-20020aa79d9c000000b006ce91cdb1c4sm27098pfq.188.2023.12.06.14.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 14:46:41 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3B6MkVBQ258430 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 6 Dec 2023 19:46:32 -0300 From: Alexandre Oliva To: Jonathan Wakely Cc: Jonathan Wakely , Thomas Schwinge , gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org, David Edelsohn Subject: Re: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime Organization: Free thinker, does not speak for AdaCore References: <87sf4fbjis.fsf@euler.schwinge.homeip.net> Date: Wed, 06 Dec 2023 19:46:31 -0300 In-Reply-To: (Jonathan Wakely's message of "Wed, 6 Dec 2023 14:40:48 +0000") 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 6, 2023, Jonathan Wakely wrote: >> - void *obj, void *dso_handle) >> + void *obj, [[maybe_unused]] void *dso_handle) > The patch is OK with that change. Thanks, here's what I'm going to install. Regstrapped on x86_64-linux-gnu, with and without ac_cv_func___cxa_thread_atexit_impl=no, on a machine that has __cxa_thread_atexit_impl (but not __cxa_thread_atexit) in libc. 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 PR libstdc++/112858 * 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..28423344a0f34 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, [[maybe_unused]] 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