This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Problem with shared libraries, exceptions, and global constructors
- From: Bernd Schmidt <bernds at redhat dot com>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 18 Aug 2003 18:21:24 +0100 (BST)
- Subject: Problem with shared libraries, exceptions, and global constructors
Consider this test:
bernds@tesuji:~/bug> cat bug1.cc
void foo ()
{
try {
throw 1;
}
catch (...)
{
}
}
bernds@tesuji:~/bug> cat bug2.cc
#include <cstdlib>
extern int foo ();
int z = foo ();
bernds@tesuji:~/bug> cat main.cc
int main ()
{
return 0;
}
bernds@tesuji:~/bug> cat bug.sh
g++ -fpic -shared bug1.cc -o libbug1.so
g++ -fpic -shared bug2.cc -o libbug2.so
g++ main.cc -L. -lbug1 -lbug2 -Wl,-rpath -Wl,.
Running the executable produces
terminate called after throwing an instance of 'i'
Aborted
This depends on the link order of the shared libraries; it runs without
aborting if you reverse the order of libbug1.so and libbug2.so.
What seems to happen is that we call the initialization code of
libbug2.so before that of libbug1.so; so we call the constructor for "z"
(and, in turn, foo() in libbug1.so) before the exception handling for
libbug1.so has been set up with a call to register_frame_info.
I've been staring at this for a while, and I can't see a good way to fix
this. Suggestions?
Bernd