public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH] libstdc++: Fix exceptions being generated when compiling with -fno-exceptions
@ 2015-04-15 14:15 Federico Lenarduzzi
  2015-04-15 14:56 ` Jonathan Wakely
  0 siblings, 1 reply; 7+ messages in thread
From: Federico Lenarduzzi @ 2015-04-15 14:15 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Thanks for comments.

I forgot to mention that this change came of working with the target
fragment file
for the generation of libraries with and without exceptions. After that, the
choice of the multilibs with or without exceptions will depend on the use the
-fno-excepcions flag at the moment of compilation of an application.

As you mentioned in the thread linked to this new flag, have the option
--disable-libstdcxx-verbose is very useful, especially in embedded software
development.

Now, If I have the below case: I'm developing two applications, the first not
want to have exception handling, therefore I would like to have the library
without verbose_terminate_handler () function and the second application handles
exceptions, with which I would like to have the library with the function
mentioned above.

To achieve this, I should have two copies compiled in different ways or
recompile all gcc to enable or disable this function.

The idea of this patch is that using this function not depends from a
configuration
flag but depends of a flag which participates in the selection of the
correct multilib.

I think it could be discuss, I would like read some opinions and
comments about this.



2015-04-14 16:27 GMT-03:00 Jonathan Wakely <jwakely.gcc@gmail.com>:

> On 14 April 2015 at 16:17, 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.
>
> I guess this makes sense, but you can just build with
> --disable-libstdcxx-verbose to have the same effect.
>
> > It also makes std::uncaught_exception() throw() return false if __EXCEPTIONS is not defined.
>
> This part seems like a good idea, but we'll also need to do it to the
> new uncaught_exceptions() function about to be added, so let's wait
> until that in committed first (which will be shortly after the 5.1
> release).
>
> The checks should use __cpp_exceptions not __EXCEPTIONS, see the current trunk.




-- 
Federico Lenarduzzi
Software Engineer

Taller Technologies Argentina
San Lorenzo 47, 3rd Floor, Office 5
Cordoba, Argentina
Phone: +54 351 4220701
Mobile: +54 358 4289083
Skype: federico.lenarduzzi1







-- 
Federico Lenarduzzi
Software Engineer

Taller Technologies Argentina
San Lorenzo 47, 3rd Floor, Office 5
Cordoba, Argentina
Phone: +54 351 4220701
Mobile: +54 358 4289083
Skype: federico.lenarduzzi1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] libstdc++: Fix exceptions being generated when compiling with -fno-exceptions
  2015-04-15 14:15 [PATCH] libstdc++: Fix exceptions being generated when compiling with -fno-exceptions Federico Lenarduzzi
@ 2015-04-15 14:56 ` Jonathan Wakely
  2015-04-16 14:21   ` Federico Lenarduzzi
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Wakely @ 2015-04-15 14:56 UTC (permalink / raw)
  To: Federico Lenarduzzi; +Cc: libstdc++, gcc-patches

On 15/04/15 11:15 -0300, Federico Lenarduzzi wrote:
>The idea of this patch is that using this function not depends from a
>configuration
>flag but depends of a flag which participates in the selection of the
>correct multilib.

OK, then I agree it's better to make it conditional on
__cpp_exceptions which can have different values for your different
multilibs, whereas _GLIBCXX_VERBOSE would be the same in all of them.

I have no objections to the change.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] libstdc++: Fix exceptions being generated when compiling with -fno-exceptions
  2015-04-15 14:56 ` Jonathan Wakely
@ 2015-04-16 14:21   ` Federico Lenarduzzi
  2015-04-16 14:33     ` Jonathan Wakely
  0 siblings, 1 reply; 7+ messages in thread
From: Federico Lenarduzzi @ 2015-04-16 14:21 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches

Jonathan,

I don't have commit access though, so if you could commit this for me
it'd be great.

Regards.

2015-04-15 11:55 GMT-03:00 Jonathan Wakely <jwakely@redhat.com>:
> On 15/04/15 11:15 -0300, Federico Lenarduzzi wrote:
>>
>> The idea of this patch is that using this function not depends from a
>> configuration
>> flag but depends of a flag which participates in the selection of the
>> correct multilib.
>
>
> OK, then I agree it's better to make it conditional on
> __cpp_exceptions which can have different values for your different
> multilibs, whereas _GLIBCXX_VERBOSE would be the same in all of them.
>
> I have no objections to the change.



-- 
Federico Lenarduzzi
Software Engineer

Taller Technologies Argentina
San Lorenzo 47, 3rd Floor, Office 5
Cordoba, Argentina
Phone: +54 351 4220701
Mobile: +54 358 4289083
Skype: federico.lenarduzzi1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] libstdc++: Fix exceptions being generated when compiling with -fno-exceptions
  2015-04-16 14:21   ` Federico Lenarduzzi
@ 2015-04-16 14:33     ` Jonathan Wakely
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Wakely @ 2015-04-16 14:33 UTC (permalink / raw)
  To: Federico Lenarduzzi; +Cc: libstdc++, gcc-patches

On 16/04/15 11:20 -0300, Federico Lenarduzzi wrote:
>Jonathan,
>
>I don't have commit access though, so if you could commit this for me
>it'd be great.

Yes, but I'm waiting until I do the uncaught_exceptions() commit.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] libstdc++: Fix exceptions being generated when compiling with -fno-exceptions
  2015-04-14 15:18 Federico Lenarduzzi
  2015-04-14 19:27 ` Jonathan Wakely
@ 2015-04-27 21:06 ` Jonathan Wakely
  1 sibling, 0 replies; 7+ messages in thread
From: Jonathan Wakely @ 2015-04-27 21:06 UTC (permalink / raw)
  To: Federico Lenarduzzi; +Cc: libstdc++, gcc-patches

[-- 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;

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] libstdc++: Fix exceptions being generated when compiling with -fno-exceptions
  2015-04-14 15:18 Federico Lenarduzzi
@ 2015-04-14 19:27 ` Jonathan Wakely
  2015-04-27 21:06 ` Jonathan Wakely
  1 sibling, 0 replies; 7+ messages in thread
From: Jonathan Wakely @ 2015-04-14 19:27 UTC (permalink / raw)
  To: Federico Lenarduzzi; +Cc: libstdc++, gcc-patches

On 14 April 2015 at 16:17, 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.

I guess this makes sense, but you can just build with
--disable-libstdcxx-verbose to have the same effect.

> It also makes std::uncaught_exception() throw() return false if __EXCEPTIONS is not defined.

This part seems like a good idea, but we'll also need to do it to the
new uncaught_exceptions() function about to be added, so let's wait
until that in committed first (which will be shortly after the 5.1
release).

The checks should use __cpp_exceptions not __EXCEPTIONS, see the current trunk.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] libstdc++: Fix exceptions being generated when compiling with -fno-exceptions
@ 2015-04-14 15:18 Federico Lenarduzzi
  2015-04-14 19:27 ` Jonathan Wakely
  2015-04-27 21:06 ` Jonathan Wakely
  0 siblings, 2 replies; 7+ messages in thread
From: Federico Lenarduzzi @ 2015-04-14 15:18 UTC (permalink / raw)
  To: libstdc++, gcc-patches

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.

libstdc++-v3/
2015-04-14  Federico Lenarduzzi  <federico.lenarduzzi@tallertechnologies.com>

	* libsupc++/eh_catch.cc (std::uncaught_exception() throw()): Add an #else
	which returns false if __EXCEPTIONS is not defined.
	* libsupc++/eh_term_handler.cc: Add a check for __EXCEPTIONS to the #if.

---
 libstdc++-v3/libsupc++/eh_catch.cc        | 4 ++++
 libstdc++-v3/libsupc++/eh_term_handler.cc | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/libsupc++/eh_catch.cc b/libstdc++-v3/libsupc++/eh_catch.cc
index 43e875a..6b500f6 100644
--- a/libstdc++-v3/libsupc++/eh_catch.cc
+++ b/libstdc++-v3/libsupc++/eh_catch.cc
@@ -136,6 +136,10 @@ __cxxabiv1::__cxa_end_catch ()
 bool
 std::uncaught_exception() throw()
 {
+#ifdef __EXCEPTIONS  
   __cxa_eh_globals *globals = __cxa_get_globals ();
   return globals->uncaughtExceptions != 0;
+#else
+  return false;
+#endif
 }
diff --git a/libstdc++-v3/libsupc++/eh_term_handler.cc b/libstdc++-v3/libsupc++/eh_term_handler.cc
index c855360..0935193 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 && defined(__EXCEPTIONS)
 /* The current installed user handler.  */
 std::terminate_handler __cxxabiv1::__terminate_handler =
 	__gnu_cxx::__verbose_terminate_handler;
-- 
1.9.3

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-04-27 21:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-15 14:15 [PATCH] libstdc++: Fix exceptions being generated when compiling with -fno-exceptions Federico Lenarduzzi
2015-04-15 14:56 ` Jonathan Wakely
2015-04-16 14:21   ` Federico Lenarduzzi
2015-04-16 14:33     ` Jonathan Wakely
  -- strict thread matches above, loose matches on Subject: below --
2015-04-14 15:18 Federico Lenarduzzi
2015-04-14 19:27 ` Jonathan Wakely
2015-04-27 21:06 ` Jonathan Wakely

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).