This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


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

Bug #1: Exceptions from .so lib not propogated to caller


Hello,

I have found a bug re: C++ exceptions not being properly propogated to
the caller when thrown from a shared library built with G++.
The same problem exists on both linux and Sun Solaris when I use g++.
However, when I use Sun's CC the problem does not exist.  gcc was built
using the --enable-shared configuration option.

The source code to recreate the problem is in the following four files.

The bug is that when an exception is "thrown" from a method found in a
shared library the exception is not propogated outside that method
and so the "try ... catch" structure does not get notification of the
exception.

This exception "try ... catch" works (i.e., no core dump).when all is
linked into ONE executable (no library)

(The following output was generated on a linus machine
#uname -a
Linux timestock.jpc.com.tw 2.2.5-15CLEsmp #1 SMP Mon May 3 04:48:56 CST
1999 i686 unknown)

---------------------------------------------------------

tsterror.h :
class TstException {
public:
        TstException() {};
       ~TstException() {};
};

---------------------------------------------------------

tstmethod.h :
void tstMethod ();

tstmethod.cpp :
#include "tsterror.h"
void tstMethod ()
{  throw TstException(); }

---------------------------------------------------------
#g++ -v --save-temps tstmethod.cpp -c -o tstmethod.o

Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs

gcc version 2.95.2 19991024 (release)
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/cpp -lang-c++ -v
-D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__
-Dunix -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__
-D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Acpu(i386)
-Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro -D__i686
-D__i686__ -D__pentiumpro -D__pentiumpro__ tstmethod.cpp tstmethod.ii
GNU CPP version 2.95.2 19991024 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:

/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3
/usr/local/include
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../i686-pc-linux-gnu/include
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/include
/usr/include
End of search list.
The following default directories have been omitted from the search
path:
End of omitted list.
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/cc1plus tstmethod.ii
-quiet -dumpbase tstmethod.cc -version -o tstmethod.s
GNU C++ version 2.95.2 19991024 (release) (i686-pc-linux-gnu) compiled
by GNU C version 2.95.2 19991024 (release).
 as -V -Qy -o tstmethod.o tstmethod.s
GNU assembler version 2.9.1 (i386-redhat-linux), using BFD version
2.9.1.0.23

# cat tstmethod.ii

# 1 "tstmethod.cpp"
# 1 "tsterror.h" 1



class TstException
{
private:

public:
        TstException() {};

       ~TstException() {};

};

# 1 "tstmethod.cpp" 2


void tstMethod ()
{
  throw TstException();
}

-----------------------------------------

tstmain.cpp  :
#include "tsterror.h"
#include "tstmethod.h"
// (commented out to reduce .ii output)#include <iostream.h>
int main (int argc, char *argv[])
{
  try {
    tstMethod();
    // (commented out to reduce .ii output) cout << "no error" << endl;
  }  catch (TstException e)
  {
      // (commented out to reduce .ii output) cout << "Exception" <<
endl;
  }
}

---------------------------------------------------------

# g++ -v --save-temps tstmain.cpp -c -o tstmain.o

Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs

gcc version 2.95.2 19991024 (release)
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/cpp -lang-c++ -v
-D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__
-Dunix -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__
-D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Acpu(i386)
-Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro -D__i686
-D__i686__ -D__pentiumpro -D__pentiumpro__ tstmain.cpp tstmain.ii
GNU CPP version 2.95.2 19991024 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:

/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3
/usr/local/include
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../i686-pc-linux-gnu/include
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/include
/usr/include
End of search list.
The following default directories have been omitted from the search
path:
End of omitted list.
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/cc1plus tstmain.ii
-quiet -dumpbase tstmain.cc -version -o tstmain.s
GNU C++ version 2.95.2 19991024 (release) (i686-pc-linux-gnu) compiled
by GNU C version 2.95.2 19991024 (release).
 as -V -Qy -o tstmain.o tstmain.s
GNU assembler version 2.9.1 (i386-redhat-linux), using BFD version
2.9.1.0.23

# cat tstmain.ii

# 1 "tstmain.cpp"
# 1 "tsterror.h" 1



class TstException
{
private:

public:
        TstException() {};

       ~TstException() {};

};

# 1 "tstmain.cpp" 2

# 1 "tstmethod.h" 1
void tstMethod ();
# 2 "tstmain.cpp" 2

int main (int argc, char *argv[])
{
  try {
    tstMethod();
  }
  catch (TstException e) {

  }
}

---------------------------------------------------------

Build the library:

# g++ -v --save-temps -shared tstmethod.o -o libtstg.so

Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs

gcc version 2.95.2 19991024 (release)
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/collect2 -m elf_i386
-shared -o libtstg.so /usr/lib/crti.o
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/crtbeginS.o
-L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2 -L/usr/local/lib
tstmethod.o -lstdc++ -lm -lgcc -lc -lgcc
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/crtendS.o
/usr/lib/crtn.o


-------------------------------------------------------------------------------------

Build program:

# g++ -v --save-temps tstmain.o -o tstmain.exe -L. -ltstg

Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs

gcc version 2.95.2 19991024 (release)
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/collect2 -m elf_i386
-dynamic-linker /lib/ld-linux.so.2 -o tstmain.exe /usr/lib/crt1.o
/usr/lib/crti.o
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/crtbegin.o -L.
-L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2 -L/usr/local/lib
tstmain.o -ltstg -lstdc++ -lm -lgcc -lc -lgcc
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/crtend.o /usr/lib/crtn.o

------------------------------------------------------------------------

The program output is: "Aborted (core dumped)" and the stack traceback
from the core dump is:

Core was generated by `tstmain.exe'.
Program terminated with signal 6, Aborted.
Reading symbols from /usr/share/chinese/xa+cv/wrap.so...done.
Reading symbols from
/jpc/leslie/new-cgifw/test/lib-exc/./libtst.so...done.
Reading symbols from /usr/lib/libstdc++-libc6.1-2.so.3...done.
Reading symbols from /lib/libm.so.6...done.
Reading symbols from /lib/libc.so.6...done.
Reading symbols from /lib/libdl.so.2...done.
Reading symbols from /lib/ld-linux.so.2...done.
#0  0x400a4111 in __kill ()
(gdb) bt
#0  0x400a4111 in __kill ()
#1  0x400a3d66 in raise (sig=6) at ../sysdeps/posix/raise.c:27
#2  0x400a5447 in abort () at ../sysdeps/generic/abort.c:88
#3  0x40052c5b in __default_terminate ()
#4  0x40052c7c in __terminate ()
#5  0x40053574 in throw_helper (eh=0x40068144, pc=0x4001b4f5,
    my_udata=0xbffff748, offset_p=0xbffff744)
#6  0x4005372c in __throw ()
#7  0x4001b4f6 in tstMethod () at tstmethod.cpp:6
#8  0x8048b0b in main (argc=1, argv=0xbffff844) at tstmain.cpp:7
#9  0x4009dcb3 in __libc_start_main (main=0x8048b00 <main>, argc=1,
    argv=0xbffff844, init=0x80488f8 <_init>, fini=0x8048cf4 <_fini>,
    rtld_fini=0x4000a350 <_dl_fini>, stack_end=0xbffff83c)
    at ../sysdeps/generic/libc-start.c:78

-------------------------------------------------------------------------

Thanks in advance for your attention.  Any idea when this might get
fixed?  There is just simply no work-around :(  I think I have included
everything you ask for.  Please let me know if there is more that I can
help with :)

Sincerely,

Leslie

--
// Leslie Ruskin
// EMail: Shanti@TheHelm
// http://members.tripod.com/~sattva/
// Jade Pacific Corporation
// 7F #58, Min-Chuan E. Road, Sec 3, Taipei, Taiwan
// TEL: (886)(2)2515-0253 x428   FAX: (886)(2)2504-5078
// U.S.A. Fax (703) 940-5515
// U.S.A. Voice Mail Box 1(661)420-9511

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