This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gcc3.2 coredump in exception handling


Hi,

I have coredump for exception handling in a c++ program using dynamic library compiled with gcc3.2. 
We wrote the main program (mainapp) using dlopen to load a libsub.so and execute functions in so with dlsym.  
In the libsub.so we throw an exception and catch it the mainapp. We have gcc3.2, gcc3.2.1 and gcc3.2.2 
compiled natively with GNU GCC source and gcc3.2 coming with Redhat 8.0.

It coredump in gcc library for exception handling if we compile one of them in RH gcc3.2 and 
one in our own gcc3.2.x and run under our gcc3.2.x. It works fine in the same coredump case above 
if we run them under RH gcc3.2.  In addition, the program works fine if we compile mainapp and libsub.so 
using our gcc3.2.x in any combination such as we compile mainapp in gcc3.2 and libsub.so in gcc3.2.2 
or vice versa and run under any version of our gcc3.2.x. We also have the right result if we compile 
both of them in RH gcc3.2. There are some compatibility problems between our gcc3.2.x and gcc3.2 
in Redhat 8.0 and the problem only presented in the exception handling part not the other normal function calls.

Has anyone encounter the same problem? Does anyone know what is special in Redhat gcc3.2.

Any help will be greatly appreciated.

---Shen

I know the case is kind of complicated and I hope I mention it clear enough for you to understand it. 
All the detailed info is shown below.

1) mainapp.cpp (creates mainapp)

#include <dlfcn.h>
#include <iostream>

using namespace std;

typedef int (*intfunc) (int, int);
typedef int (*throwfunc) ();

int main()
{
    void*   pluginHandle = 0;
    char*   pluginLib = "./libsub.so";
    void*   gData = 0;
    int     result = 0;
    char*   error = 0;

    intfunc   func1;
    throwfunc func2;

    try {
        pluginHandle = dlopen(pluginLib, RTLD_LAZY);
        if (pluginHandle) {
            cout << "!! load dll success !!\n";

            gData = dlsym(pluginHandle, "gInt");
            if ((error = dlerror()) != NULL)  {
                cout << "dlsym(global1) failed with error<" << error << ">\n";
                return (-1);
            }
            cout << "\tthe global value is <" << *((int*)(gData)) << ">\n";

            func1 = (intfunc)dlsym(pluginHandle, "addInt");
            if ((error = dlerror()) != NULL)  {
                cout << "dlsym(addInt) failed with error<" << error << ">\n";
                return (-1);
            }
            result = (*func1)(5, 8);
            cout << "\tthe function call result is <" << result << ">\n\n";

            func2 = (throwfunc)dlsym(pluginHandle, "throwException");
            if ((error = dlerror()) != NULL)  {
                cout << "dlsym(throwException) failed with error<" << error << ">\n";
                return (-1);
            }
            result = (*func2)();

            dlclose(pluginHandle);
            pluginHandle = 0;
        } else {
            cout << "dlopen failed with error <" << dlerror() << ">\n";
            return (-1);
        }
    } catch (std::string& s) {
        cout << "Caught Exception <" << s << ">!" << endl << endl;

        if (pluginHandle) {
            dlclose(pluginHandle);
        }

        return (-1);
    }

    return 0;
}

2) sub.cpp which generates libsub.so 

#include <iostream>

int gInt = 5;

extern "C" {

int addInt(int a, int b)
{
    std::cout << "Enter addInt ...\n";
    return a + b;
}

int throwException()
    throw (std::string)
{
    throw std::string("Thrown from shared lib");
}

}

3) Makefile

all: libsub.so mainapp

libsub.so:
        g++ -g -Wall -c -o sub.o sub.cpp
        g++ -shared -o libsub.so sub.o

mainapp: libsub.so
        g++ -g -Wall -c -o mainapp.o mainapp.cpp
        g++ mainapp.o -L. -lsub -ldl -o mainapp

clean:
        rm -f *.o libsub.so mainapp core*


4) correct output:

!! load dll success !!
        the global value is <5>
Enter addInt ...
        the function call result is <13>

Caught Exception <Thrown from shared lib>!

5) wrong result
!! load dll success !!
        the global value is <5>
Enter addInt ...
        the function call result is <13>

Abort (core dumped)

6) Core stack:
#0  0x4013ba01 in __kill () at __kill:-1
#1  0x4013b7da in raise (sig=6) at ../sysdeps/posix/raise.c:27
#2  0x4013cf82 in abort () at ../sysdeps/generic/abort.c:88
#3  0x400b7924 in __cxxabiv1::__terminate(void (*)()) (handler=0x4013ce24 <abort>)
    at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:47
#4  0x400b7968 in std::terminate() ()
    at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:57
#5  0x400b7ab5 in __cxa_throw (obj=0x804ab60, tinfo=0x400c4344,
    dest=0x400c4344 <__cxxabiv1::__terminate_handler>)
    at ../../../../libstdc++-v3/libsupc++/eh_throw.cc:77
#6  0x40018ca5 in throwException () at sub.cpp:16
#7  0x08048d44 in main () at mainapp.cpp:45
#8  0x40129507 in __libc_start_main (main=0x8048b2c <main>, argc=1,
    ubp_av=0xbffff4d4, init=0x80488e4 <_init>, fini=0x8048f04 <_fini>,
    rtld_fini=0x4000dc14 <_dl_fini>, stack_end=0xbffff4cc)
    at ../sysdeps/generic/libc-start.c:129


7) our gcc3.2 configuration info (gcc -v)

Reading specs from /pcc/app/gcc3.2/lib/gcc-lib/i386-redhat-linux/3.2/specs
Configured with: ../configure --prefix=/pcc/app/gcc3.2 --mandir=/pcc/app/gcc3.2/share/man 
--infodir=/pcc/app/gcc3.2/share/info --enable-shared --enable-threads=posix --disable-checking 
--host=i386-redhat-linux --with-system-zlib --enable-languages=c,c++ --enable-__cxa_atexit
Thread model: posix
gcc version 3.2

8) Redhat 8.0 gcc3.2 info (gcc -v)

Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info 
--enable-shared --enable-threads=posix --disable-checking --host=i386-redhat-linux 
--with-system-zlib --enable-__cxa_atexit
Thread model: posix
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]