diff mbox

[PR,libstdc++/51135] : Fix [4.7 Regression] SIGSEGV during exception cleanup on win32

Message ID CAEwic4bO3Bb5WR6-U=6n6FPNoukjTJYowpzpjWb+-feSbzNyWA@mail.gmail.com
State New
Headers show

Commit Message

Kai Tietz Dec. 12, 2011, 11:11 a.m. UTC
Hi,

so as no other review happend, I changed patch as you suggested.

Tested for i686-w64-mingw32, and regression tested for
x86_64-unknown-linux-gnu.  Ok for apply?

Regards,
Kai

ChangeLog

2011-12-12  Kai Tietz  <ktietz@redhat.com>

	PR libstdc++/511135
	* libsupc++/cxxabi.h (__cxxabi_dtor_type): New type.
	(__cxa_throw): Use it for destructor-argument.
	* eh_throw.cc (__cxa_throw): Likewise.
	* unwind-cxx.h (__cxa_exception): Change type of member
	exceptionDestructor to __cxxabi_dtor_type.

Comments

Paolo Carlini Dec. 12, 2011, 11:16 a.m. UTC | #1
On 12/12/2011 12:11 PM, Kai Tietz wrote:
> Hi,
>
> so as no other review happend, I changed patch as you suggested.
Well, sorry for not noticing earlier, but here, as in many other cases, 
I think it would be much cleaner to have the pre-processor games in the 
mingw config header, define a macro name there (normally undefined) and 
then use it here.

Paolo.
Kai Tietz Dec. 12, 2011, 11:29 a.m. UTC | #2
2011/12/12 Paolo Carlini <paolo.carlini@oracle.com>:
> On 12/12/2011 12:11 PM, Kai Tietz wrote:
>>
>> Hi,
>>
>> so as no other review happend, I changed patch as you suggested.
>
> Well, sorry for not noticing earlier, but here, as in many other cases, I
> think it would be much cleaner to have the pre-processor games in the mingw
> config header, define a macro name there (normally undefined) and then use
> it here.
>
> Paolo.

Well, this was my initial attempt to solve it. The issue here is that
libsupc++ doesn't use the the os-header-file and I am not sure if it
is wise to introduce it here.  To add it to the cxxabi.h header, which
claims to reflect ABI issue, looks sensible as alternative to me here.

Kai
Paolo Carlini Dec. 12, 2011, 11:32 a.m. UTC | #3
On 12/12/2011 12:29 PM, Kai Tietz wrote:
> Well, this was my initial attempt to solve it. The issue here is that 
> libsupc++ doesn't use the the os-header-file
Are you sure? Should include bits/c++config.h, no?

Paolo.
Kai Tietz Dec. 12, 2011, 11:48 a.m. UTC | #4
2011/12/12 Paolo Carlini <paolo.carlini@oracle.com>:
> On 12/12/2011 12:29 PM, Kai Tietz wrote:
>>
>> Well, this was my initial attempt to solve it. The issue here is that
>> libsupc++ doesn't use the the os-header-file
>
> Are you sure? Should include bits/c++config.h, no?
>
> Paolo.

Well, I tested it, and I saw that the define in the os part for
libsupc++ weren't set.  By looking into this, this might be also
caused by not including in all .cc files using cxxabi.h before
bits/c++config.h.

Kai
Kai Tietz Dec. 12, 2011, 11:49 a.m. UTC | #5
2011/12/12 Kai Tietz <ktietz70@googlemail.com>:
> 2011/12/12 Paolo Carlini <paolo.carlini@oracle.com>:
>> On 12/12/2011 12:29 PM, Kai Tietz wrote:
>>>
>>> Well, this was my initial attempt to solve it. The issue here is that
>>> libsupc++ doesn't use the the os-header-file
>>
>> Are you sure? Should include bits/c++config.h, no?
>>
>> Paolo.
>
> Well, I tested it, and I saw that the define in the os part for
> libsupc++ weren't set.  By looking into this, this might be also
> caused by not including in all .cc files using cxxabi.h before
> bits/c++config.h.
>
> Kai

Hmm, strange.  cxxabi.h is supposed to include <bits/c++config.h>
itself.  I will retest

Kai
Jonathan Wakely Dec. 12, 2011, 11:50 a.m. UTC | #6
On 12 December 2011 11:29, Kai Tietz <ktietz70@googlemail.com> wrote:
> 2011/12/12 Paolo Carlini <paolo.carlini@oracle.com>:
>> On 12/12/2011 12:11 PM, Kai Tietz wrote:
>>>
>>> Hi,
>>>
>>> so as no other review happend, I changed patch as you suggested.
>>
>> Well, sorry for not noticing earlier, but here, as in many other cases, I
>> think it would be much cleaner to have the pre-processor games in the mingw
>> config header, define a macro name there (normally undefined) and then use
>> it here.
>>
>> Paolo.
>
> Well, this was my initial attempt to solve it. The issue here is that
> libsupc++ doesn't use the the os-header-file and I am not sure if it
> is wise to introduce it here.  To add it to the cxxabi.h header, which
> claims to reflect ABI issue, looks sensible as alternative to me here.

I think Paolo means:

#ifdef _GLIBCXX_USE_THISCALL_ON_DTOR
typedef void (__thiscall *__cxxabi_dtor_type) (void *);
#else
typedef void (*__cxxabi_dtor_type) (void *);
#endif

instead of testing __MINGW32__ and __i386__

Also, my suggestion of __cxxabi_dtor_type would be more consistent it
was spelled __cxa not __cxxabi (sorry, it was just a quick suggestion,
not a request to actually use that name!)
Paolo Carlini Dec. 12, 2011, 11:53 a.m. UTC | #7
On 12/12/2011 12:50 PM, Jonathan Wakely wrote:
> I think Paolo means:
>
> #ifdef _GLIBCXX_USE_THISCALL_ON_DTOR
> typedef void (__thiscall *__cxxabi_dtor_type) (void *);
> #else
> typedef void (*__cxxabi_dtor_type) (void *);
> #endif
>
> instead of testing __MINGW32__ and __i386__
This for sure, but I think we could as well move the whole thing in the 
config file, like:

     #ifndef _GLIBCXX_USE_THISCALL_ON_DTOR
     typedef void (*__cxxabi_dtor_type) (void *);
     #endif

Paolo.
Kai Tietz Dec. 12, 2011, 11:58 a.m. UTC | #8
2011/12/12 Paolo Carlini <paolo.carlini@oracle.com>:
> On 12/12/2011 12:50 PM, Jonathan Wakely wrote:
>>
>> I think Paolo means:
>>
>> #ifdef _GLIBCXX_USE_THISCALL_ON_DTOR
>> typedef void (__thiscall *__cxxabi_dtor_type) (void *);
>> #else
>> typedef void (*__cxxabi_dtor_type) (void *);
>> #endif
>>
>> instead of testing __MINGW32__ and __i386__
>
> This for sure, but I think we could as well move the whole thing in the
> config file, like:
>
>    #ifndef _GLIBCXX_USE_THISCALL_ON_DTOR
>
>    typedef void (*__cxxabi_dtor_type) (void *);
>    #endif
>
> Paolo.

Fine,  nevertheless the test in os-config file for __i386__ is
required, as just for IA 32-bit this calling convention is for
interest.  Neither x64 nor ARM etc requires it.

Kai
Paolo Carlini Dec. 12, 2011, 12:14 p.m. UTC | #9
On 12/12/2011 12:58 PM, Kai Tietz wrote:
> Fine, nevertheless the test in os-config file for __i386__ is 
> required, as just for IA 32-bit this calling convention is for 
> interest. Neither x64 nor ARM etc requires it.
So - just out of curiosity, ultimately you are responsible for the 
config files - why we do have separate mingw32 and mingw32-w64 configs?

Paolo.
Kai Tietz Dec. 12, 2011, 12:19 p.m. UTC | #10
2011/12/12 Paolo Carlini <paolo.carlini@oracle.com>:
> On 12/12/2011 12:58 PM, Kai Tietz wrote:
>>
>> Fine, nevertheless the test in os-config file for __i386__ is required, as
>> just for IA 32-bit this calling convention is for interest. Neither x64 nor
>> ARM etc requires it.
>
> So - just out of curiosity, ultimately you are responsible for the config
> files - why we do have separate mingw32 and mingw32-w64 configs?
>
> Paolo.

Well, this is mainly caused by different feature-set of runtimes. We
could solve things here also by probing for specific runtimes and so
using just on configure tree.

Kai
Paolo Carlini Dec. 12, 2011, 12:28 p.m. UTC | #11
On 12/12/2011 01:19 PM, Kai Tietz wrote:
> Well, this is mainly caused by different feature-set of runtimes. We
> could solve things here also by probing for specific runtimes and so
> using just on configure tree.
Ah, thus, it's *not* true that mingw32, at variance with mingw32-w64, is 
only used for i386? Anyway, as I said already, in the config files you 
can check all the macros you like ;)

Paolo.
diff mbox

Patch

Index: gcc/libstdc++-v3/libsupc++/cxxabi.h
===================================================================
--- gcc.orig/libstdc++-v3/libsupc++/cxxabi.h
+++ gcc/libstdc++-v3/libsupc++/cxxabi.h
@@ -51,6 +51,16 @@ 
 #include <bits/cxxabi_tweaks.h>
 #include <bits/cxxabi_forced.h>

+// On 32-bit IA native windows target is the used calling-convention
+// for class-member-functions of kind __thiscall.  As destructor is
+// also of kind class-member-function, we need to specify for this
+// target proper calling-convention on destructor-function-pointer.
+#if defined (__MINGW32__) && defined (__i386__)
+typedef void (__thiscall *__cxxabi_dtor_type) (void *);
+#else
+typedef void (*__cxxabi_dtor_type) (void *);
+#endif
+
 #ifdef __cplusplus
 namespace __cxxabiv1
 {
@@ -596,7 +606,7 @@  namespace __cxxabiv1

   // Throw the exception.
   void
-  __cxa_throw(void*, std::type_info*, void (*) (void *))
+  __cxa_throw(void*, std::type_info*, __cxxabi_dtor_type)
   __attribute__((__noreturn__));

   // Used to implement exception handlers.
Index: gcc/libstdc++-v3/libsupc++/eh_throw.cc
===================================================================
--- gcc.orig/libstdc++-v3/libsupc++/eh_throw.cc
+++ gcc/libstdc++-v3/libsupc++/eh_throw.cc
@@ -58,8 +58,8 @@  __gxx_exception_cleanup (_Unwind_Reason_


 extern "C" void
-__cxxabiv1::__cxa_throw (void *obj, std::type_info *tinfo,
-			 void (*dest) (void *))
+__cxxabiv1::__cxa_throw (void *obj, std::type_info *tinfo,
+			 __cxxabi_dtor_type dest)
 {
   // Definitely a primary.
   __cxa_refcounted_exception *header
Index: gcc/libstdc++-v3/libsupc++/unwind-cxx.h
===================================================================
--- gcc.orig/libstdc++-v3/libsupc++/unwind-cxx.h
+++ gcc/libstdc++-v3/libsupc++/unwind-cxx.h
@@ -51,7 +51,7 @@  struct __cxa_exception
 {
   // Manage the exception object itself.
   std::type_info *exceptionType;
-  void (*exceptionDestructor)(void *);
+  __cxxabi_dtor_type exceptionDestructor;

   // The C++ standard has entertaining rules wrt calling set_terminate
   // and set_unexpected in the middle of the exception cleanup process.