From patchwork Thu Nov 9 01:55:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 163200 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b129:0:b0:403:3b70:6f57 with SMTP id q9csp164879vqs; Wed, 8 Nov 2023 17:56:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFM/K86lh9QqW9QNHmX5pZ8FkOENpkgG5sRda/8F5ztv8mtWuQZqz2Mg5bvTZr6mpI8Vw9M X-Received: by 2002:ad4:5281:0:b0:66d:593e:7722 with SMTP id v1-20020ad45281000000b0066d593e7722mr100003qvr.3.1699494996021; Wed, 08 Nov 2023 17:56:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699494996; cv=pass; d=google.com; s=arc-20160816; b=YVHS9HiqV/O9+1zocXy8+2udNXcifLY14LTwwEyEZbPnsaQruYFLC1u3VPpptnbhAg SCg3Tdcxk8oS48Bacfe7lKbI0arc5JSf7LOus/gXcZHSR1jvIrWN1RGmW6hYFyuzzVLO HMa8iI+cMdWLKFRAQv7vqKuzwM4s1Q2HpBD8LDFLLU1GHguK17Z5FTcLQFHrjV9Qbo7Z tDelcdWt4PCFz+Oaav/4SxEXz0BRM8Jb5BtUlswSf2ejZwV0DGl1ptKYYo4qKcp7vdiS 6DyJNPNcdcR+zSgSlEsq016cNqaab2rlHU8Jw+kx/lCwyaeP4loCvnEuM7oGyy1ZMTqV BlYw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :message-id:date:organization:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=IVB4qnLIfz6IJ7MHenZ4AhD+HQt2hFqgWsLcMY/uK0A=; fh=+uLa3m5dEsZWyE738VC4UtcvjxY1kYREGLuytVVwtpk=; b=mWg9PtmQpOXnoBsqapayEMevVnKihDDJiUiI69arCFGnl8D34SQkR6rsjxaxw+IOd3 Z1RyUS00Q8zC3wuCGT6ITe3gK+Kj5qiy99XuXuqLdE/8o8cFtTeQhecbY2QK9aFJxbE/ SR4RXQv4GJvewJRow6ibSvcZgI9yVpFYdY1zdH5NosA34AOxzxoIiNOeb9OsTWIpoTqu Oq18VjoQxir3XmvvQWO/5t4DiPvI9aPVQdO2QA1NH/UFank3X5Cyh0Rbba66uHwd28wD tuYalB6hqgeO+80SIX0PHcW33vAtRgMYVZmagg6fY46pbXwdeP14QPUWNbmNvSo/hEbO pDIA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=jXo9MK9L; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b6-20020a0cfe66000000b0065b26265ae5si2173946qvv.490.2023.11.08.17.56.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 17:56:35 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=jXo9MK9L; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C1E52386189A for ; Thu, 9 Nov 2023 01:56:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by sourceware.org (Postfix) with ESMTPS id 4B278385B512 for ; Thu, 9 Nov 2023 01:56:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B278385B512 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 4B278385B512 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699494966; cv=none; b=Q619krera6SYLdDy5RHycOLMGxbufijtziuwzoPCPaF659v1XBCFWKzdh7w0gMGWk/y8gSeOR+pepAe/nZ9shKFPaLmh5Nh0PHr27Ffm/tn78ue4VxyH9vKTNJgGdRW9NNhgR8gtQiHgzNPhGfbwMZr6uV1LRru72SHN00Q9p+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699494966; c=relaxed/simple; bh=j4GV4/seTg+Y+1bx18kPxhDNx9A7gNcADzfO+cv/3b4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jHJ/sO8VKFl53cyrevjJDqrBrgwFb3kxUSg9COpMnIGew5SWWHvowboTGHBCDw0asSCzZeSN6Fcr33+g7g0qjJO4ts0WjG6e7rDXJw8EmOIl0ac9oQE5y5cU1Y3qLeVujQdCofkTTkc3L7ctSHHr5CO91zLYdkz0k/GlxCdUryc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-5a877e0f0d8so13802367b3.1 for ; Wed, 08 Nov 2023 17:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1699494959; x=1700099759; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:date:organization:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=IVB4qnLIfz6IJ7MHenZ4AhD+HQt2hFqgWsLcMY/uK0A=; b=jXo9MK9LRmRVxio6Sv2w1KD7ZANAbu6nFzDxY8eEYusD2aCqwj0jR1AaxcS0Fy7m0y JrHt70DkGsoTNUMPtEG5bt+Hp0CkHCUBGTwmRJD2n3cpKN/a+87iTvmrwdB2m1kbe49+ +ALyiWnzq4e71erNLiqrvOKds4YdLDi+emeTQ3MpIsT09EpVSMar7C6g0qwm2eLO2WmI PQqJJJoG7MPXe3PgMC7VjS0Z66HsZqmRNXPwGXU65hrFmJiiNoYOtNaoWb9/ZAN5E3p+ wE3jf3se+02CRsmDXz1mMuUtwzOc0QAdGLdgVCI5+accYtdco9s9+xUohWXOT70WrrYK yLxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699494959; x=1700099759; h=mime-version:user-agent:message-id:date:organization:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IVB4qnLIfz6IJ7MHenZ4AhD+HQt2hFqgWsLcMY/uK0A=; b=wfRrLzzvazBQL9AYf0NLjuT5dcZ5+0DiFF/RZebyx7iAo2aAGmogAf6wacDFcTCfDw bvzBC6jedvPqbJ2e9zz7tVmmfKKd1RLdL7GLES4ml97UINep03F9gIrccYszogWugHxp TtIfu61Kf/56wAVfIEpYHk5I3flBHfjszkGG3fSm7SI8frn9sQC0I6RQQGktInvmXYgd VGdv5gN5pHlSgVxKRKTyxLP4/HAxAguginBAoaBWtQkrqCiMF9kUk0Rnkx42FVTYxqbM iZcooNtxgjjmqxe6z7iBnacDk15MSyqz2xdtB5UcVu/DuJCe0WbQdP6ISs35s0JHvbho YR1g== X-Gm-Message-State: AOJu0YxpkXkDObq4lZslPptPubiYqGU0+Gvo1iCDsVJzGamWeSpMES4P kqvDxiLMm4NrvgYihG3suWU//mcFfNTBUHQwBdaS1w== X-Received: by 2002:a0d:dbcc:0:b0:5a8:1a54:ba4b with SMTP id d195-20020a0ddbcc000000b005a81a54ba4bmr6103529ywe.13.1699494959674; Wed, 08 Nov 2023 17:55:59 -0800 (PST) Received: from free.home ([2804:7f1:2080:e9c8:ff5e:88e8:a900:d7b4]) by smtp.gmail.com with ESMTPSA id l17-20020a81d551000000b005b054a1ec5dsm7542148ywj.126.2023.11.08.17.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 17:55:59 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3A91torB2231594 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 8 Nov 2023 22:55:50 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: [PATCH] libsupc++: try cxa_thread_atexit_impl at runtime Organization: Free thinker, does not speak for AdaCore Date: Wed, 08 Nov 2023 22:55:50 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-13.4 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782049664966220382 X-GMAIL-MSGID: 1782049664966220382 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 platforms that support weak symbols. Regstrapped on x86_64-linux-gnu, also tested with gcc-13 on i686- and x86_64-, and with ac_cv_func___cxa_thread_atexit_impl=no, that, on a distro that lacks __cxa_thread_atexit in libc, forces the newly-added code to be exercised, and that enabled thread_local-order2.C to pass where the runtime libc has __cxa_thread_atexit_impl. Ok to install? for libstdc++-v3/ChangeLog * libsupc++/atexit_thread.cc [__GXX_WEAK__]: Add dynamic detection of __cxa_thread_atexit_impl. --- libstdc++-v3/libsupc++/atexit_thread.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/libsupc++/atexit_thread.cc b/libstdc++-v3/libsupc++/atexit_thread.cc index 9346d50f5dafe..cabd7c0a4a057 100644 --- a/libstdc++-v3/libsupc++/atexit_thread.cc +++ b/libstdc++-v3/libsupc++/atexit_thread.cc @@ -138,11 +138,24 @@ namespace { } } +#if __GXX_WEAK__ +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__ + if (__cxa_thread_atexit_impl) + return __cxa_thread_atexit_impl (dtor, obj, dso_handle); +#endif + // Do this initialization once. if (__gthread_active_p ()) {