Bug 51135 - [4.7 Regression] SIGSEGV during exception cleanup on win32
Summary: [4.7 Regression] SIGSEGV during exception cleanup on win32
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.7.0
: P1 major
Target Milestone: 4.7.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-15 04:15 UTC by Christopher Gurnee
Modified: 2011-12-16 18:46 UTC (History)
6 users (show)

See Also:
Host:
Target: mingw32
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-12-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Gurnee 2011-11-15 04:15:24 UTC
It looks like __thiscall is now the default calling convention for member functions (where possible) for win32 targets. This seems to have broken exception cleanup. 

This seg faults when executed (and compiled by mingw-32):

===============
struct except {
  virtual ~except() {}
};

int main() {
  try {
    throw except();
  } catch(except) {
  }
}
===============

The seg fault occurs after the catch block is exited, and except::~except() is called by the runtime. I think __gxx_exception_cleanup (in libstdc++-v3/libsupc++/eh_throw.cc) is still trying to call except::~except() using the old calling convention, resulting in a seg fault on any access to 'this'.

-Chris
Comment 1 Paolo Carlini 2011-12-05 14:52:58 UTC
This badly requires a target maintainer.
Comment 2 Dave Korn 2011-12-05 15:10:54 UTC
Doesn't reproduce on Cygwin, and I don't have a current mingw cross compiler handy.  It would be best if Kai can look at this as I'm up to my neck in ada at the moment, if he hasn't found time in the next four or five days I'll try and investigate.
Comment 3 Kai Tietz 2011-12-05 15:17:34 UTC
Well, this seems to be caused by member exceptionDestructor in __cxa_exception structure.  As a destructor has also __thiscall convention, we need to specify it here for 32-bit Windows target.

I am just about to test a patch for it.
Comment 4 Kai Tietz 2011-12-12 13:29:14 UTC
Author: ktietz
Date: Mon Dec 12 13:29:10 2011
New Revision: 182238

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182238
Log:
Correct bug-number in ChangeLog.

        PR libstdc++/51135
        * libsupc++/cxxabi.h (__cxxabi_dtor_type): New type.
        (__cxa_throw): Use it for destructor-argument.
        * libsupc++/eh_throw.cc (__cxa_throw): Likewise.
        * libsupc++/unwind-cxx.h (__cxa_exception): Change type of member
        exceptionDestructor to __cxxabi_dtor_type.
        * config/os/mingw32-w64/os_defines.h (_GLIBCXX_USE_THISCALL_ON_DTOR):
        Define.
        (__cxa_dtor_type): Declare target secific type variant.
        * config/os/mingw32/os_defines.h: Likewise.

Modified:
    trunk/libstdc++-v3/ChangeLog
Comment 5 Kai Tietz 2011-12-12 13:31:16 UTC
Fixed at revision 182237.
Comment 6 paolo@gcc.gnu.org 2011-12-12 17:34:24 UTC
Author: paolo
Date: Mon Dec 12 17:34:19 2011
New Revision: 182250

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182250
Log:
2011-12-12  Paolo Carlini  <paolo.carlini@oracle.com>

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

	PR libstdc++/51135
	* libsupc++/cxxabi.h (__cxa_dtor_type): New type.
	(__cxa_throw): Use it for destructor-argument.
	* libsupc++/eh_throw.cc (__cxa_throw): Likewise.
	* libsupc++/unwind-cxx.h (__cxa_exception): Change type of member
	exceptionDestructor to __cxa_dtor_type.
	* config/os/mingw32-w64/os_defines.h (_GLIBCXX_USE_THISCALL_ON_DTOR):
	Define.
	(__cxa_dtor_type): Declare target secific type variant.
	* config/os/mingw32/os_defines.h: Likewise.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/config/os/mingw32-w64/os_defines.h
    trunk/libstdc++-v3/config/os/mingw32/os_defines.h
    trunk/libstdc++-v3/libsupc++/cxxabi.h
    trunk/libstdc++-v3/libsupc++/eh_throw.cc
    trunk/libstdc++-v3/libsupc++/unwind-cxx.h
Comment 7 Paolo Carlini 2011-12-12 17:38:08 UTC
Patch reverted.
Comment 8 Kai Tietz 2011-12-16 18:43:11 UTC
Author: ktietz
Date: Fri Dec 16 18:43:06 2011
New Revision: 182410

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182410
Log:
        PR libstdc++/51135
        * libsupc++/unwind-cxx.h (__cxa_exception): Mark
        exceptionDestructor by _GLIBCXX_CDTOR_CALLABI.
        * libsupc++/eh_throw.cc (__cxa_throw): Mark destructor
        function argument by _GLIBCXX_CDTOR_CALLABI.
        * libsupc++/cxxabi.h (__cxa_throw): Likewise.
        (_GLIBCXX_CDTOR_CALLABI): Add empty default
        definition.
        * config/os/mingw32-w64/os_defines.h (_GLIBCXX_CDTOR_CALLABI): Define
        for IA-32 target as __thiscall.
        * config/os/mingw32/os_defines.h (_GLIBCXX_CDTOR_CALLABI): Likewise.


Modified:
    trunk/libstdc++-v3/config/os/mingw32-w64/os_defines.h
    trunk/libstdc++-v3/config/os/mingw32/os_defines.h
    trunk/libstdc++-v3/libsupc++/cxxabi.h
    trunk/libstdc++-v3/libsupc++/eh_throw.cc
    trunk/libstdc++-v3/libsupc++/unwind-cxx.h
Comment 9 Kai Tietz 2011-12-16 18:46:36 UTC
Fixed at revision 182410.