From: Jonathan Wakely <jwakely@redhat.com>
To: Federico Lenarduzzi <federico.lenarduzzi@tallertechnologies.com>
Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] libstdc++: Fix exceptions being generated when compiling with -fno-exceptions
Date: Mon, 27 Apr 2015 21:06:00 -0000 [thread overview]
Message-ID: <20150427210628.GS3618@redhat.com> (raw)
In-Reply-To: <1429024679-17856-1-git-send-email-federico.lenarduzzi@tallertechnologies.com>
[-- Attachment #1: Type: text/plain, Size: 1070 bytes --]
On 14/04/15 12:17 -0300, Federico Lenarduzzi wrote:
>When the libstdc++ is compiled, the compiler sets the std::terminate_handler function with __verbose_terminate_handler() or std::abort() depending on _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE being true or false.
>
>However, even if we compile with -fno-exceptions, the compiler will use __verbose_terminate_handler(), which uses exceptions. Therefore, the library is not fully exception-free.
>
>This patch adds a check for __EXCEPTIONS to the #if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE condition. If __EXCEPTIONS is defined, the compiler will use __verbose_terminate_handler() as a termination function; otherwise it'll use std::abort() which doesn't have exceptions. It also makes std::uncaught_exception() throw() return false if __EXCEPTIONS is not defined.
I've committed this slightly revised version using __cpp_exceptions
instead, and changing the new std::uncaught_exceptions() function too.
Tested x86_64-linux and powerpc64le-linux, and also built with
--enable-libstdcxx-flags=-fno-exceptions on x86_64-linux.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1795 bytes --]
commit 80bc538bd64c7f6b9a21ec5d1a3bc5b08bc8770b
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Apr 27 14:04:50 2015 +0100
2015-04-27 Federico Lenarduzzi <federico.lenarduzzi@tallertechnologies.com>
Jonathan Wakely <jwakely@redhat.com>
* libsupc++/eh_catch.cc (uncaught_exception, uncaught_exceptions):
Return false or zero if the library is built without exceptions.
* libsupc++/eh_term_handler.cc: Disable verbose terminate handler if
the library is built without exceptions.
diff --git a/libstdc++-v3/libsupc++/eh_catch.cc b/libstdc++-v3/libsupc++/eh_catch.cc
index 723ae56..44fde79 100644
--- a/libstdc++-v3/libsupc++/eh_catch.cc
+++ b/libstdc++-v3/libsupc++/eh_catch.cc
@@ -136,13 +136,21 @@ __cxxabiv1::__cxa_end_catch ()
bool
std::uncaught_exception() throw()
{
+#if __cpp_exceptions
__cxa_eh_globals *globals = __cxa_get_globals ();
return globals->uncaughtExceptions != 0;
+#else
+ return false;
+#endif
}
int
std::uncaught_exceptions() throw()
{
+#if __cpp_exceptions
__cxa_eh_globals *globals = __cxa_get_globals ();
return globals->uncaughtExceptions;
+#else
+ return 0;
+#endif
}
diff --git a/libstdc++-v3/libsupc++/eh_term_handler.cc b/libstdc++-v3/libsupc++/eh_term_handler.cc
index 46acee8..0d6ea2b 100644
--- a/libstdc++-v3/libsupc++/eh_term_handler.cc
+++ b/libstdc++-v3/libsupc++/eh_term_handler.cc
@@ -32,7 +32,7 @@
--disable-libstdcxx-verbose and rebuilding the library.
In a freestanding environment, we default to this latter approach. */
-#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE
+#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE && __cpp_exceptions
/* The current installed user handler. */
std::terminate_handler __cxxabiv1::__terminate_handler =
__gnu_cxx::__verbose_terminate_handler;
next prev parent reply other threads:[~2015-04-27 21:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-14 15:18 Federico Lenarduzzi
2015-04-14 19:27 ` Jonathan Wakely
2015-04-27 21:06 ` Jonathan Wakely [this message]
2015-04-15 14:15 Federico Lenarduzzi
2015-04-15 14:56 ` Jonathan Wakely
2015-04-16 14:21 ` Federico Lenarduzzi
2015-04-16 14:33 ` 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=20150427210628.GS3618@redhat.com \
--to=jwakely@redhat.com \
--cc=federico.lenarduzzi@tallertechnologies.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).