This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Problems with exception handling in conjunction with shared objects
- To: <bug-gcc at gnu dot org>
- Subject: Problems with exception handling in conjunction with shared objects
- From: "Ori Amitzur" <ori at uxsrvc dot tti-telecom dot com>
- Date: Tue, 28 Sep 1999 14:59:55 +0200
- Reply-To: <ori at uxsrvc dot tti-telecom dot com>
I am using g++ 2.95 on AIX 4.3 powerpc. I created a shared object that
contains
the following code:
// File shared.cxx
class Contained {
public:
~Contained() {}
};
class Container {
public:
Container() {
throw 5;
}
private:
Contained _contained;
};
void Throw()
{
Container c;
}
The executable contains the following code:
// File main.cxx
#include <iostream.h>
extern void Throw();
int main(int,char **)
{
try {
Throw();
} catch (int &i) {
cout << "Caught " << i << endl;
}
return 0;
}
This code causes Illegal Instruction with coredump.
I found that the following prerequisists must be fulfilled for the problem
to occure:
1. The exception is thrown in a shared object
2. The exception is thrown in a constrctor of an object (the Container
object)
3. "Container" contains an object that has a destructor (the Contained)
4. The exception is caught in the executable (main)
I am compiling the source code using g++ -c XXX.cxx
XXX stands either for shared or main.
I am creating the shared object using
g++ -o libshared.so -shared -Xlinker -G shared.o
I am creating the executable using g++ -o exe -Xlinker -brtl -lshared main.o
A similar problem occurs if the file shared.cxx contains the following code:
// File shared.cxx
#include <iostream.h>
void Throw()
{
try {
throw 5;
} catch (int &i) {
cout << i << " caught" << endl;
}
}
In this case program always crashes.
It seems to me like a bug. Any other ideas ?
Ori Amitzur