Bug 33874 - (cygwin/mingw) sjlj exception handling corrupts stack
Summary: (cygwin/mingw) sjlj exception handling corrupts stack
Status: RESOLVED DUPLICATE of bug 19774
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2007-10-23 20:29 UTC by DoSu Lim
Modified: 2007-10-23 20:48 UTC (History)
4 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description DoSu Lim 2007-10-23 20:29:11 UTC
# On g++-sjlj.exe (GCC) 4.2.1-sjlj (mingw32 sjlj-unwind)
# g++ -v
Using built-in specs.
Target: mingw32
Configured with: ../gcc-4.2.1/configure --with-gcc --enable-libgomp --host=mingw32 --build=mingw32 --target=mingw32 --program-suffix=-sjlj --with-arch=i486 --with-tune=generic --disable-werror --prefix=/mingw --with-local-prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,fortran,objc,obj-c++,ada --disable-win32-registry --enable-sjlj-exceptions --enable-libstdcxx-debug --enable-cxx-flags=-fno-function-sections -fno-data-sections --enable-version-specific-runtime-libs --disable-bootstrap
Thread model: win32
gcc version 4.2.1-sjlj (mingw32 sjlj-unwind)
# And
# On g++ (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) // sjlj-EH
# g++ -v
Configured with: /usr/build/package/orig/test.respin/gcc-3.4.4-3/configure --verbose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,d,f77,pascal,java,objc --enable-nls --without-included-gettext --enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptions --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: posix
gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)

The test case below shows
that Gcc sjlj exception handling corrupts stack and can make the process crash
when the stack frame 
  contains VLA(variable length array) or alloca()'ed variables 
  and has no catch handler for the exception being handled.

And this is my solution for this bug
	==> http://home.paran.com/darkxun/libcyn/GccBugFix.html
I'm not offending you guys. Just wanted to make a prof that it is my own work (not plagiarized).

#include <stdio.h>
static int __seq = 0;
struct Temp {
    int    _i;
    Temp() : _i(__seq++) { fprintf(stderr,"%d\n", _i);  }
    virtual ~Temp()      { fprintf(stderr,"%d\n", _i);  }

void problem( void(*func)() )
    int N=5;
    Temp temp[N];


void problem( void(*func)() );
void bugger() {
    throw "anything";

int main()
    try {
        problem( bugger );
    catch(...) {}

#using static problem.o
    g++ -o problem.o problem.cc -c
    g++ main.cc problem.o
#or shared problem.dll
    g++ -o problem.dll problem.cc -shared
    g++ main.cc problem.dll
Comment 1 Andrew Pinski 2007-10-23 20:48:43 UTC

*** This bug has been marked as a duplicate of 19774 ***