From patchwork Fri Oct 8 11:23:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 45998 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B3F703857805 for ; Fri, 8 Oct 2021 11:25:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B3F703857805 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633692325; bh=bxUJU+9Zdqj3SFw64ir8EZHig0GL5S1UcSqkvzaYzwo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=T74sRj0c/2lxr+OQnGXge6eLF5/ye8pUZ5zgWZhsW1SfiA0XSVU2N6CNGaIUhN+1N AXNFacFg5u+M/2pY5N7SsJ4ft3Xgto6jev4vqb2d+tUeFXQoQ7ZDWtY3UlPSEj9Zk1 uRN8YreR7DHFAEmTlOynyIFUQpu5BfO8/LqnOgFg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 6E2DF3857807 for ; Fri, 8 Oct 2021 11:23:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E2DF3857807 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-165-5y9lmqXAPOatDHf_e4cHYg-1; Fri, 08 Oct 2021 07:23:45 -0400 X-MC-Unique: 5y9lmqXAPOatDHf_e4cHYg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D9363801AC3; Fri, 8 Oct 2021 11:23:22 +0000 (UTC) Received: from localhost (unknown [10.33.37.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87CFF60583; Fri, 8 Oct 2021 11:23:22 +0000 (UTC) Date: Fri, 8 Oct 2021 12:23:21 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Add wrapper for internal uses of std::terminate Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-13.8 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_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This adds an inline wrapper for std::terminate that doesn't add the declaration of std::terminate to namespace std. This allows the library to terminate without including all of . libstdc++-v3/ChangeLog: * include/bits/atomic_timed_wait.h: Remove unused header. * include/bits/c++config (std:__terminate): Define. * include/bits/semaphore_base.h: Remove and use __terminate instead of terminate. * include/bits/std_thread.h: Likewise. * libsupc++/eh_terminate.cc (std::terminate): Use qualified-id to call __cxxabiv1::__terminate. This avoids including a few thousand lines of just for one function declaration. Any objections or better ideas? commit 79cd06f3072fd8a68b8636f7d11bb42e62eaa6fa Author: Jonathan Wakely Date: Fri Oct 8 11:35:53 2021 libstdc++: Add wrapper for internal uses of std::terminate This adds an inline wrapper for std::terminate that doesn't add the declaration of std::terminate to namespace std. This allows the library to terminate without including all of . libstdc++-v3/ChangeLog: * include/bits/atomic_timed_wait.h: Remove unused header. * include/bits/c++config (std:__terminate): Define. * include/bits/semaphore_base.h: Remove and use __terminate instead of terminate. * include/bits/std_thread.h: Likewise. * libsupc++/eh_terminate.cc (std::terminate): Use qualified-id to call __cxxabiv1::__terminate. diff --git a/libstdc++-v3/include/bits/atomic_timed_wait.h b/libstdc++-v3/include/bits/atomic_timed_wait.h index 64c1ba62a3e..efbe3da8b6c 100644 --- a/libstdc++-v3/include/bits/atomic_timed_wait.h +++ b/libstdc++-v3/include/bits/atomic_timed_wait.h @@ -40,7 +40,6 @@ #include #ifdef _GLIBCXX_HAVE_LINUX_FUTEX -#include // std::terminate #include #endif diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config index 69343a25533..b76ffeb2562 100644 --- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -293,6 +293,15 @@ namespace std #if __cplusplus >= 201103L typedef decltype(nullptr) nullptr_t; #endif + + // This allows the library to terminate without including all of + // and without making the declaration of std::terminate visible to users. + __attribute__ ((__noreturn__, __always_inline__)) + inline void __terminate() _GLIBCXX_USE_NOEXCEPT + { + void terminate() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__noreturn__)); + terminate(); + } } #define _GLIBCXX_USE_DUAL_ABI diff --git a/libstdc++-v3/include/bits/semaphore_base.h b/libstdc++-v3/include/bits/semaphore_base.h index 2c8d7576894..afd636704e8 100644 --- a/libstdc++-v3/include/bits/semaphore_base.h +++ b/libstdc++-v3/include/bits/semaphore_base.h @@ -40,7 +40,6 @@ #endif // __cpp_lib_atomic_wait #ifdef _GLIBCXX_HAVE_POSIX_SEMAPHORE -# include // std::terminate # include // errno, EINTR, EAGAIN etc. # include // SEM_VALUE_MAX # include // sem_t, sem_init, sem_wait, sem_post etc. @@ -80,7 +79,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__err && (errno == EINTR)) continue; else if (__err) - std::terminate(); + std::__terminate(); else break; } @@ -97,7 +96,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION else if (__err && (errno == EAGAIN)) return false; else if (__err) - std::terminate(); + std::__terminate(); else break; } @@ -111,7 +110,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { auto __err = sem_post(&_M_semaphore); if (__err) - std::terminate(); + std::__terminate(); } } @@ -138,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION else if (errno == ETIMEDOUT || errno == EINVAL) return false; else - std::terminate(); + std::__terminate(); } else break; diff --git a/libstdc++-v3/include/bits/std_thread.h b/libstdc++-v3/include/bits/std_thread.h index 2a500bf1777..801033b00ad 100644 --- a/libstdc++-v3/include/bits/std_thread.h +++ b/libstdc++-v3/include/bits/std_thread.h @@ -35,7 +35,6 @@ #if __cplusplus >= 201103L #include -#include // std::terminate #include // std::basic_ostream #include // std::tuple #include // std::hash @@ -149,7 +148,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~thread() { if (joinable()) - std::terminate(); + std::__terminate(); } thread(const thread&) = delete; @@ -162,7 +161,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION thread& operator=(thread&& __t) noexcept { if (joinable()) - std::terminate(); + std::__terminate(); swap(__t); return *this; } diff --git a/libstdc++-v3/libsupc++/eh_terminate.cc b/libstdc++-v3/libsupc++/eh_terminate.cc index db6735f308e..a94f173bb2e 100644 --- a/libstdc++-v3/libsupc++/eh_terminate.cc +++ b/libstdc++-v3/libsupc++/eh_terminate.cc @@ -55,7 +55,7 @@ __cxxabiv1::__terminate (std::terminate_handler handler) throw () void std::terminate () throw() { - __terminate (get_terminate ()); + __cxxabiv1::__terminate (get_terminate ()); } #pragma GCC diagnostic ignored "-Wdeprecated-declarations"