Hello,

I have coredump for exception handling in a c++ program using dynamic library. 
I wrote the minimal application using dlopen to load a libtest_so.so and
execute functions in so with dlsym. In the libtest_so.so I throw an exception
and try to catch it. 

Source code:
1) main application test_exception (test.cpp)  

#include <cstdio>
#include <dlfcn.h>

typedef void (*TFuncVoid)();

int main() {
    void* testlib = dlopen("./libtest_so.so", RTLD_NOW | RTLD_GLOBAL);

    TFuncVoid FFunc = 0;
    FFunc = TFuncVoid(dlsym(testlib, "ThrowCatchException"));
    if (FFunc) {
        try {
            FFunc();
        } catch (...) {
            printf("Catched in test.cpp. \n");
        }
    }

    return 0;
}

2) library libtest_so.so (test_so.cpp)

#include <cstdio>

extern "C" void ThrowCatchException() {
    try {
        throw 5;
    } catch (int) {
        printf("catch (int): la-la-la \n");
    } catch (...) {
        printf("catch (...): la-la-la \n");
    }
}

3) Commands for compiling the application:
g++44 -g -Wall -fPIC -fexceptions
-DNATIVE_INCLUDE_PATH="/usr/local/lib/gcc44/include/c++/" -I<include_path_1>
-I<include_path_2> -o CMakeFiles/test_exception.dir/test.cpp.o -c
<path_to_src>/test/test.cpp

g++44 -nostdlib /usr/lib/crt1.o /usr/lib/crti.o
/usr/local/lib/gcc44/gcc/x86_64-portbld-freebsd7.2/4.4.1/crtbegin.o -g -Wall
-fPIC -fexceptions -DNATIVE_INCLUDE_PATH="/usr/local/lib/gcc44/include/c++/"
-Wl,-E  CMakeFiles/test_exception.dir/test.cpp.o  -o test_exception  
/usr/local/lib/gcc44/gcc/x86_64-portbld-freebsd7.2/4.4.1/../../../libsupc++.a
/usr/local/lib/gcc44/gcc/x86_64-portbld-freebsd7.2/4.4.1/libgcc.a
/usr/local/lib/gcc44/gcc/x86_64-portbld-freebsd7.2/4.4.1/libgcc_eh.a -lc -lm
/usr/local/lib/gcc44/gcc/x86_64-portbld-freebsd7.2/4.4.1/crtend.o
/usr/lib/crtn.o

4) Commands for compiling the library:
g++44 -g -Wall -fPIC -fexceptions
-DNATIVE_INCLUDE_PATH="/usr/local/lib/gcc44/include/c++/" -I<include_path_1>
-I<include_path_2> -o CMakeFiles/test_so.dir/test_so.cpp.o -c
<path_to_src>/test_so.cpp

g++44 -fPIC -g -Wall -fexceptions
-DNATIVE_INCLUDE_PATH="/usr/local/lib/gcc44/include/c++/" -shared
-Wl,-soname,libtest_so.so -o libtest_so.so CMakeFiles/test_so.dir/test_so.cpp.o 

4) correct output (command ./test_exception):
"catch (int): la-la-la"

5) wrong result (command ./test_exception):
terminate called after throwing an instance of 'int'
Abort trap (core dumped)

6) my gcc configuration info (g++44 -v)
Using built-in specs.
Target: x86_64-portbld-freebsd7.2
Configured with: ./../gcc-4.4-20090616/configure --disable-nls
--with-system-zlib --with-libiconv-prefix=/usr/local --with-gmp=/usr/local
--program-suffix=44 --libdir=/usr/local/lib/gcc44
--libexecdir=/usr/local/libexec/gcc44
--with-gxx-include-dir=/usr/local/lib/gcc44/include/c++/ --disable-libgcj
--prefix=/usr/local --mandir=/usr/local/man --infodir=/usr/local/info/gcc44
--build=x86_64-portbld-freebsd7.2
Thread model: posix
gcc version 4.4.1 20090616 (prerelease) (GCC)


-- 
           Summary: coredump in exception handling (gcc44, FreeBSD 7.2)
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: skylanderr at gmail dot com
  GCC host triplet: x86_64-unknown-freebsd7.2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45209

Reply via email to