public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/43581] New: exception handling broken across shared libaries
@ 2010-03-29 18:46 rwild at gcc dot gnu dot org
2010-03-29 18:48 ` [Bug other/43581] [4.5 Regression] " pinskia at gcc dot gnu dot org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: rwild at gcc dot gnu dot org @ 2010-03-29 18:46 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug other/43581] [4.5 Regression] exception handling broken across shared libaries
2010-03-29 18:46 [Bug c++/43581] New: exception handling broken across shared libaries rwild at gcc dot gnu dot org
@ 2010-03-29 18:48 ` pinskia at gcc dot gnu dot org
2010-03-29 20:43 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-03-29 18:48 UTC (permalink / raw)
To: gcc-bugs
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |other
Summary|exception handling broken |[4.5 Regression] exception
|across shared libaries |handling broken across
| |shared libaries
Target Milestone|--- |4.5.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43581
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug other/43581] [4.5 Regression] exception handling broken across shared libaries
2010-03-29 18:46 [Bug c++/43581] New: exception handling broken across shared libaries rwild at gcc dot gnu dot org
2010-03-29 18:48 ` [Bug other/43581] [4.5 Regression] " pinskia at gcc dot gnu dot org
@ 2010-03-29 20:43 ` pinskia at gcc dot gnu dot org
2010-03-30 9:47 ` rguenth at gcc dot gnu dot org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-03-29 20:43 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2010-03-29 20:43 -------
This works for me with:
gcc version 4.5.0 20100326 (experimental) [trunk revision 157759] (GCC)
GNU ld (GNU Binutils for Debian) 2.18.0.20080103
GNU C Library stable release version 2.7, by Roland McGrath et al.
I tried with both 4.5's libstdc++ and with the default 4.3's.
Can you remove from the configure part --as-needed ? Since that is the major
difference between my build and yours.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
GCC host triplet|x86_64-unknown-linux-gnu |
GCC target triplet| |x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43581
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug other/43581] [4.5 Regression] exception handling broken across shared libaries
2010-03-29 18:46 [Bug c++/43581] New: exception handling broken across shared libaries rwild at gcc dot gnu dot org
2010-03-29 18:48 ` [Bug other/43581] [4.5 Regression] " pinskia at gcc dot gnu dot org
2010-03-29 20:43 ` pinskia at gcc dot gnu dot org
@ 2010-03-30 9:47 ` rguenth at gcc dot gnu dot org
2010-03-30 13:56 ` rguenth at gcc dot gnu dot org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-03-30 9:47 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2010-03-30 09:46 -------
Works for me as well. Building GCC with --as-needed is known to at least
break libjava big times (you can see that when testing).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43581
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug other/43581] [4.5 Regression] exception handling broken across shared libaries
2010-03-29 18:46 [Bug c++/43581] New: exception handling broken across shared libaries rwild at gcc dot gnu dot org
` (2 preceding siblings ...)
2010-03-30 9:47 ` rguenth at gcc dot gnu dot org
@ 2010-03-30 13:56 ` rguenth at gcc dot gnu dot org
2010-03-30 16:58 ` [Bug other/43581] [4.5 Regression] exception handling broken across shared libaries with -fuse-linker-plugin rwild at gcc dot gnu dot org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-03-30 13:56 UTC (permalink / raw)
To: gcc-bugs
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |WAITING
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43581
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug other/43581] [4.5 Regression] exception handling broken across shared libaries with -fuse-linker-plugin
2010-03-29 18:46 [Bug c++/43581] New: exception handling broken across shared libaries rwild at gcc dot gnu dot org
` (3 preceding siblings ...)
2010-03-30 13:56 ` rguenth at gcc dot gnu dot org
@ 2010-03-30 16:58 ` rwild at gcc dot gnu dot org
2010-03-30 20:29 ` [Bug lto/43581] " pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rwild at gcc dot gnu dot org @ 2010-03-30 16:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rwild at gcc dot gnu dot org 2010-03-30 16:58 -------
Bug also happens with
$ g++ -v
Using built-in specs.
COLLECT_GCC=/opt/bin/g++
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
--with-libelf=/opt --enable-lto --without-cloog --without-ppl --with-mpc=/opt
--enable-gold LD=/opt/bin/ld LD_FOR_TARGET=/opt/bin/ld
--enable-languages=c,c++,fortran,java,lto,objc,obj-c++
Thread model: posix
gcc version 4.5.0 20100329 (experimental) (GCC)
and
$ /opt/bin/ld -v
GNU gold (GNU Binutils 2.20.51.20100319) 1.9
$ /lib/libc.so.6
GNU C Library stable release version 2.7, by Roland McGrath et al.
But my overriding of LD_LIBRARY_PATH was bogus, as it was wrongly removing
/opt/lib64 which is where the just-installed libstdc++.so.6 lives. Sorry about
the testcase reduction error (libtool --mode=execute prepends to
LD_LIBRARY_PATH rather than overriding it).
I still see the original testsuite error, though only with '-flto
-fuse-linker-plugin' (adjusting bug title and keywords). So, from the original
error description, grab the source files, then
CXX='g++'
CXXFLAGS='-O2 -flto'
LDFLAGS=-fuse-linker-plugin
$CXX $CXXFLAGS -c main.cpp
$CXX $CXXFLAGS -c lib.cpp -fPIC
$CXX -fPIC -shared $CXXFLAGS $LDFLAGS lib.o -Wl,-soname -Wl,liba.so.1 -o
liba.so.1
ln -sf liba.so.1 liba.so
$CXX $CXXFLAGS $LDFLAGS -o main main.o -L. -la
LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH ./main
leads to
Aborted (core dumped)
with a backtrace of
#0 0x00007fc2ae066095 in raise () from /lib/libc.so.6
(gdb) bt
#0 0x00007fc2ae066095 in raise () from /lib/libc.so.6
#1 0x00007fc2ae067af0 in abort () from /lib/libc.so.6
#2 0x00007fc2ae6f94bd in uw_update_context_1 (context=0x7fff7fe51010,
fs=0x7fff7fe50e90) at ../../../gcc/libgcc/../gcc/unwind-pe.h:155
#3 0x00007fc2ae6f97d9 in uw_update_context (context=0x7fff7fe51010,
fs=0x7fff7fe50e90) at ../../../gcc/libgcc/../gcc/unwind-pe.h:155
#4 0x00007fc2ae6fa40b in _Unwind_RaiseException (exc=0x4030b0) at
../../../gcc/libgcc/../gcc/unwind-pe.h:155
#5 0x00007fc2ae7dba31 in __cxa_throw (obj=<value optimized out>, tinfo=<value
optimized out>, dest=<value optimized out>) at
../../../../gcc/libstdc++-v3/libsupc++/eh_throw.cc:78
#6 0x00007fc200000000 in ?? ()
#7 0x00007fff7fe51408 in ?? ()
#8 0x00007fff7fe513f8 in ?? ()
#9 0x0000000000403028 in ?? ()
#10 0x0000000000000000 in ?? ()
It even fails without -O2, the backtrace is then
#0 0x00007f44e1705095 in raise () from /lib/libc.so.6
#1 0x00007f44e1706af0 in abort () from /lib/libc.so.6
#2 0x00007f44e1e7b6ed in __gnu_cxx::__verbose_terminate_handler () at
../../../../gcc/libstdc++-v3/libsupc++/vterminate.cc:93
#3 0x00007f44e1e79906 in __cxxabiv1::__terminate (handler=<value optimized
out>) at ../../../../gcc/libstdc++-v3/libsupc++/eh_terminate.cc:39
#4 0x00007f44e1e79933 in std::terminate () at
../../../../gcc/libstdc++-v3/libsupc++/eh_terminate.cc:49
#5 0x00007f44e1e79a3e in __cxa_throw (obj=<value optimized out>, tinfo=<value
optimized out>, dest=<value optimized out>) at
../../../../gcc/libstdc++-v3/libsupc++/eh_throw.cc:83
#6 0x00007f44e1ecdac7 in libbar () from /tmp/a/liba.so.1
#7 0x00007f44e1ecdb5c in libfoo () from /tmp/a/liba.so.1
#8 0x00000000004010e2 in exceptions_in_lib ()
#9 0x000000000040116e in main ()
If I add -g to '-O2 -flto', the backtrace is
#0 0x00007fd0d5b75095 in raise () from /lib/libc.so.6
#1 0x00007fd0d5b76af0 in abort () from /lib/libc.so.6
#2 0x00007fd0d6207504 in execute_cfa_program (insn_ptr=0x7fd0d628aabd "",
insn_end=0x7fd0d628b717 "E", context=0x7fffc0cf93a0, fs=0x7fffc0cf9220) at
../../../gcc/libgcc/../gcc/unwind-pe.h:155
#3 0x00007fd0d6208a78 in uw_frame_state_for (context=0x7fffc0cf93a0,
fs=0x7fffc0cf9220) at ../../../gcc/libgcc/../gcc/unwind-pe.h:155
#4 0x00007fd0d6209416 in _Unwind_RaiseException (exc=0x4030b0) at
../../../gcc/libgcc/../gcc/unwind-pe.h:155
#5 0x00007fd0d62eaa31 in __cxa_throw (obj=<value optimized out>, tinfo=<value
optimized out>, dest=<value optimized out>) at
../../../../gcc/libstdc++-v3/libsupc++/eh_throw.cc:78
#6 0x00007fd0d633e57e in libbar () from /tmp/a/liba.so.1
#7 0x00007fffc0cf9788 in ?? ()
#8 0x0000000000403028 in ?? ()
#9 0x0000000000000000 in ?? ()
Without -fuse-linker-plugin, it passes for me.
I get a similar failure for exceptions from dlopen'ed modules, if you like I
can provide a testcase for that as well.
--
rwild at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |lto
Summary|[4.5 Regression] exception |[4.5 Regression] exception
|handling broken across |handling broken across
|shared libaries |shared libaries with -fuse-
| |linker-plugin
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43581
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug lto/43581] exception handling broken across shared libaries with -fuse-linker-plugin
2010-03-29 18:46 [Bug c++/43581] New: exception handling broken across shared libaries rwild at gcc dot gnu dot org
` (4 preceding siblings ...)
2010-03-30 16:58 ` [Bug other/43581] [4.5 Regression] exception handling broken across shared libaries with -fuse-linker-plugin rwild at gcc dot gnu dot org
@ 2010-03-30 20:29 ` pinskia at gcc dot gnu dot org
2010-03-31 9:23 ` rguenth at gcc dot gnu dot org
2010-03-31 18:50 ` rwild at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-03-30 20:29 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from pinskia at gcc dot gnu dot org 2010-03-30 20:29 -------
So this cannot be a regression.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |UNCONFIRMED
Component|other |lto
Summary|[4.5 Regression] exception |exception handling broken
|handling broken across |across shared libaries with
|shared libaries with -fuse- |-fuse-linker-plugin
|linker-plugin |
Target Milestone|4.5.0 |---
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43581
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug lto/43581] exception handling broken across shared libaries with -fuse-linker-plugin
2010-03-29 18:46 [Bug c++/43581] New: exception handling broken across shared libaries rwild at gcc dot gnu dot org
` (5 preceding siblings ...)
2010-03-30 20:29 ` [Bug lto/43581] " pinskia at gcc dot gnu dot org
@ 2010-03-31 9:23 ` rguenth at gcc dot gnu dot org
2010-03-31 18:50 ` rwild at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-03-31 9:23 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from rguenth at gcc dot gnu dot org 2010-03-31 09:22 -------
It is enough to build the shared library with -flto -fuse-linker-plugin.
You then get
/tmp> LD_LIBRARY_PATH=. ./main
terminate called after throwing an instance of 'libexc'
what(): exception in library
Aborted
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2010-03-31 09:22:54
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43581
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug lto/43581] exception handling broken across shared libaries with -fuse-linker-plugin
2010-03-29 18:46 [Bug c++/43581] New: exception handling broken across shared libaries rwild at gcc dot gnu dot org
` (6 preceding siblings ...)
2010-03-31 9:23 ` rguenth at gcc dot gnu dot org
@ 2010-03-31 18:50 ` rwild at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: rwild at gcc dot gnu dot org @ 2010-03-31 18:50 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from rwild at gcc dot gnu dot org 2010-03-31 18:49 -------
Here's the analogous test case from Libtool for dlopen'ed modules. Also passes
when -fuse-linker-plugin is removed from the link line for module.so.
CXX=g++
CXXFLAGS='-O2 -flto'
LDFLAGS='-fuse-linker-plugin'
cat >module.h <<\EOF
#include <exception>
#include <string>
class modexc : public std::exception {
public:
modexc (std::string str) : message (str) { }
~modexc () throw () { }
virtual const char *what () const throw ()
{
return message.c_str ();
}
private:
std::string message;
};
extern "C" int modfoo () throw (modexc);
EOF
cat >module.cpp <<\EOF
#include <iostream>
#include "module.h"
int modbar (void) throw (modexc)
{
throw modexc ("exception in module");
}
extern "C"
int modfoo (void) throw (modexc)
{
try {
modbar ();
}
catch (modexc e) {
std::cerr << "caught inside module: " << e.what () << '\n';
throw modexc ("exception from module");
}
return 0;
}
EOF
cat >main.cpp <<\EOF
#include <dlfcn.h>
#include <iostream>
#include <exception>
#include <string>
#include "module.h"
class exc : public std::exception {
public:
exc (std::string str) : message (str) { }
~exc () throw () { }
virtual const char *what () const throw ()
{
return message.c_str ();
}
private:
std::string message;
};
int exceptions_in_module (void)
{
std::cerr << "exceptions_in_module\n";
void *handle = dlopen ("module.so", RTLD_GLOBAL | RTLD_LAZY);
if (handle == NULL)
{
std::cerr << "dlopen failed: " << dlerror () << '\n';
return 1;
}
typedef int (*pfun) (void);
pfun pf = (pfun) dlsym (handle, "modfoo");
if (pf == NULL)
{
std::cerr << "dlsym failed: " << dlerror () << '\n';
return 1;
}
try {
(*pf) ();
}
catch (modexc e) {
std::cerr << "caught: " << e.what () << '\n';
if (dlclose (handle))
{
std::cerr << "dlclose failed: " << dlerror () << '\n';
return 1;
}
return 0;
}
return 1;
}
int main (void)
{
if (exceptions_in_module ())
return 1;
return 0;
}
EOF
$CXX $CXXFLAGS -c main.cpp
$CXX $CXXFLAGS -c module.cpp -fPIC -o module.o
$CXX $CXXFLAGS $LDFLAGS -fPIC -shared module.o -o module.so
$CXX $CXXFLAGS $LDFLAGS -o main main.o -Wl,--export-dynamic -ldl
LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH ./main
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43581
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-03-31 18:50 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-29 18:46 [Bug c++/43581] New: exception handling broken across shared libaries rwild at gcc dot gnu dot org
2010-03-29 18:48 ` [Bug other/43581] [4.5 Regression] " pinskia at gcc dot gnu dot org
2010-03-29 20:43 ` pinskia at gcc dot gnu dot org
2010-03-30 9:47 ` rguenth at gcc dot gnu dot org
2010-03-30 13:56 ` rguenth at gcc dot gnu dot org
2010-03-30 16:58 ` [Bug other/43581] [4.5 Regression] exception handling broken across shared libaries with -fuse-linker-plugin rwild at gcc dot gnu dot org
2010-03-30 20:29 ` [Bug lto/43581] " pinskia at gcc dot gnu dot org
2010-03-31 9:23 ` rguenth at gcc dot gnu dot org
2010-03-31 18:50 ` rwild at gcc dot gnu dot org
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).