public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc3.2 coredump in exception handling
@ 2003-04-24 19:52 Shen Wu
  2003-04-24 20:06 ` Phil Edwards
  2003-04-24 23:52 ` Benjamin Kosnik
  0 siblings, 2 replies; 5+ messages in thread
From: Shen Wu @ 2003-04-24 19:52 UTC (permalink / raw)
  To: gcc, libstdc++

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)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc3.2 coredump in exception handling
  2003-04-24 19:52 gcc3.2 coredump in exception handling Shen Wu
@ 2003-04-24 20:06 ` Phil Edwards
  2003-04-24 23:52 ` Benjamin Kosnik
  1 sibling, 0 replies; 5+ messages in thread
From: Phil Edwards @ 2003-04-24 20:06 UTC (permalink / raw)
  To: Shen Wu; +Cc: gcc, libstdc++

On Thu, Apr 24, 2003 at 02:52:42PM -0400, Shen Wu wrote:
> libsub.so:
>         g++ -g -Wall -c -o sub.o sub.cpp
>         g++ -shared -o libsub.so sub.o

For starters, see "Things that only look like bugs":

    http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#4_4_dlsym

and fix your makefile flags.  That may or may not be enough, but it should
get you farther along.

-- 
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace.  We seek
not your counsel, nor your arms.  Crouch down and lick the hand that feeds you;
and may posterity forget that ye were our countrymen.            - Samuel Adams

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc3.2 coredump in exception handling
  2003-04-24 19:52 gcc3.2 coredump in exception handling Shen Wu
  2003-04-24 20:06 ` Phil Edwards
@ 2003-04-24 23:52 ` Benjamin Kosnik
  1 sibling, 0 replies; 5+ messages in thread
From: Benjamin Kosnik @ 2003-04-24 23:52 UTC (permalink / raw)
  To: Shen Wu; +Cc: gcc, libstdc++


>Does anyone know what is special in Redhat gcc3.2.

You can see what's in Red Hat gcc by looking at the patches shipped with
the sources. Or, you can check out the Red Hat branch of the compiler,
from the gcc cvs repository, with the tag gcc-3_2-rhl8-branch.

Knock yourself out.

>Any help will be greatly appreciated.

You might want to look at what symbols are loaded, and from where. To do
this, you'll need to set LD_DEBUG=bindings and then try to do your
magic, capturing the output.

-benjamin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc3.2 coredump in exception handling
  2003-04-24 21:17 Shen Wu
@ 2003-04-24 23:27 ` Phil Edwards
  0 siblings, 0 replies; 5+ messages in thread
From: Phil Edwards @ 2003-04-24 23:27 UTC (permalink / raw)
  To: Shen Wu; +Cc: gcc, libstdc++

On Thu, Apr 24, 2003 at 03:07:19PM -0400, Shen Wu wrote:
> Thanks Phil, but it does not solve the problem.

*shrug*

-- 
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace.  We seek
not your counsel, nor your arms.  Crouch down and lick the hand that feeds you;
and may posterity forget that ye were our countrymen.            - Samuel Adams

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: gcc3.2 coredump in exception handling
@ 2003-04-24 21:17 Shen Wu
  2003-04-24 23:27 ` Phil Edwards
  0 siblings, 1 reply; 5+ messages in thread
From: Shen Wu @ 2003-04-24 21:17 UTC (permalink / raw)
  To: Phil Edwards; +Cc: gcc, libstdc++

Thanks Phil, but it does not solve the problem.

Shen

-----Original Message-----
From: Phil Edwards [mailto:phil@jaj.com]
Sent: Thursday, April 24, 2003 2:56 PM
To: Shen Wu
Cc: gcc@gcc.gnu.org; libstdc++@gcc.gnu.org
Subject: Re: gcc3.2 coredump in exception handling


On Thu, Apr 24, 2003 at 02:52:42PM -0400, Shen Wu wrote:
> libsub.so:
>         g++ -g -Wall -c -o sub.o sub.cpp
>         g++ -shared -o libsub.so sub.o

For starters, see "Things that only look like bugs":

    http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#4_4_dlsym

and fix your makefile flags.  That may or may not be enough, but it should
get you farther along.

-- 
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace.  We seek
not your counsel, nor your arms.  Crouch down and lick the hand that feeds you;
and may posterity forget that ye were our countrymen.            - Samuel Adams

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-04-24 21:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-24 19:52 gcc3.2 coredump in exception handling Shen Wu
2003-04-24 20:06 ` Phil Edwards
2003-04-24 23:52 ` Benjamin Kosnik
2003-04-24 21:17 Shen Wu
2003-04-24 23:27 ` Phil Edwards

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).