From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] libstdc++: Add wrapper for internal uses of std::terminate
Date: Mon, 11 Oct 2021 20:38:13 +0100 [thread overview]
Message-ID: <YWSSpQUHZeZ+GkWT@redhat.com> (raw)
In-Reply-To: <YWAqKUuGWh7rg/jR@redhat.com>
On 08/10/21 12:23 +0100, Jonathan Wakely wrote:
>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 <exception>.
>
>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 <exception> 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 <exception> just for one
>function declaration. Any objections or better ideas?
I've pushed this to trunk now.
>commit 79cd06f3072fd8a68b8636f7d11bb42e62eaa6fa
>Author: Jonathan Wakely <jwakely@redhat.com>
>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 <exception>.
>
> 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 <exception> 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 <bits/chrono.h>
>
> #ifdef _GLIBCXX_HAVE_LINUX_FUTEX
>-#include <exception> // std::terminate
> #include <sys/time.h>
> #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 <exception>
>+ // 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 <exception> // std::terminate
> # include <cerrno> // errno, EINTR, EAGAIN etc.
> # include <limits.h> // SEM_VALUE_MAX
> # include <semaphore.h> // 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 <bits/c++config.h>
>
>-#include <exception> // std::terminate
> #include <iosfwd> // std::basic_ostream
> #include <tuple> // std::tuple
> #include <bits/functional_hash.h> // 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"
next prev parent reply other threads:[~2021-10-11 19:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-08 11:23 Jonathan Wakely
2021-10-11 19:38 ` Jonathan Wakely [this message]
2021-10-13 9:44 ` [committed] libstdc++: Ensure language linkage of std::__terminate() Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YWSSpQUHZeZ+GkWT@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).