This looks like a recent regression, it didn't fail sometime early February, if
I remember correctly.  Test somewhat reduced from a libtool testsuite test.

CXX=g++

cat >lib.h <<\EOF
#include <exception>
#include <string>
class libexc : public std::exception {
public:
  libexc (std::string str) : message (str) { }
  ~libexc () throw () { }
  virtual const char *what () const throw ()
  {
    return message.c_str ();
  }
private:
  std::string message;
};
int libfoo () throw (libexc);
EOF

cat >lib.cpp <<\EOF
#include <iostream>
#include "lib.h"

int libbar (void) throw (libexc)
{
  throw libexc ("exception in library");
}

int libfoo (void) throw (libexc)
{
  try {
    libbar ();
  }
  catch (libexc e) {
    std::cerr << "caught inside lib: " << e.what () << '\n';
    throw libexc ("exception from library");
  }
  return 0;
}
EOF

cat >main.cpp <<\EOF
#include "lib.h"

int exceptions_in_lib (void)
{
  try {
    libfoo ();
  }
  catch (libexc e) {
    return 0;
  }
  return 1;
}

int main (void)
{
  if (exceptions_in_lib ())
    return 1;
  return 0;
}
EOF

$CXX -O2 -c main.cpp
$CXX -O2 -c lib.cpp  -fPIC -DPIC
$CXX  -fPIC -DPIC -shared  lib.o -O2 -Wl,-soname -Wl,liba.so.1 -o liba.so.1
ln -sf liba.so.1 liba.so
$CXX -O2 -o main main.o -L. -la
LD_LIBRARY_PATH=`pwd` ./main

leads to:

caught inside lib: exception in library
terminate called after throwing an instance of 'libexc'
  what():  exception from library
./script: line 73: 24698 Aborted                 (core dumped)
LD_LIBRARY_PATH=`pwd` ./main

Happens with

$ gcc -v
Using built-in specs.
COLLECT_GCC=/opt/bin/gcc
COLLECT_LTO_WRAPPER=/opt/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc/configure -C --enable-maintainer-mode --prefix=/opt
LDFLAGS_FOR_TARGET=-Wl,--as-needed --with-boot-ldflags=-Wl,--as-needed
--with-stage1-ldflags=-Wl,--as-needed --enable-lto --without-cloog
--without-ppl  --enable-languages=c,c++,fortran,java,lto,objc,obj-c++
--enable-gold LD=/opt/bin/ld LD_FOR_TARGET=/opt/bin/ld
Thread model: posix
gcc version 4.5.0 20100329 (experimental) (GCC) 

where ld is

$ /opt/bin/ld -v
GNU gold (GNU Binutils 2.20.51.20100319) 1.9


as well as

$ gcc -v
Using built-in specs.
COLLECT_GCC=/opt/bin/gcc
COLLECT_LTO_WRAPPER=/opt/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc/configure -C --enable-maintainer-mode --prefix=/opt
LDFLAGS_FOR_TARGET=-Wl,--as-needed --with-boot-ldflags=-Wl,--as-needed
--with-stage1-ldflags=-Wl,--as-needed --enable-lto --without-cloog
--without-ppl  --enable-languages=c,c++,fortran,java,lto,objc,obj-c++
Thread model: posix
gcc version 4.5.0 20100329 (experimental) (GCC)


-- 
           Summary: exception handling broken across shared libaries
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: wrong-code, EH
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rwild at gcc dot gnu dot org
  GCC host triplet: x86_64-unknown-linux-gnu


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

Reply via email to