[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gcc m68k improvements
> |> btw: Andreas, do you know whether someone is working on making
> |> -fhandle-exceptions and -fPIC work together?
>
> I didn't know that it's broken. Can you give an example?
e.g.:
lib.cc:
--8<--------------
class ex {};
void f () { throw ex(); }
--8<--------------
main.cc
--8<--------------
class ex {};
extern void f();
int main () {
try {
f();
} catch (ex &e) {
}
return 0;
}
--8<--------------
c++ -fPIC -fhandle-exceptions -c lib.cc
gcc -fPIC -shared -o libtest.so lib.o
c++ main.cc -L. -ltest
./a.out
Segmentation fault
the cause for the crash is the stack unwinding in the compiler-generated
__throw function, which does something like:
void __throw ()
{
// 1. set return address on stack to &label
// 2. the return will now jump to label ...
return;
label:
// 3. unwind stack and call exception handlers ...
}
the problem with this approach is that the "return" in __throw() will restore
the global offset register (ebx on i386) which was set up at function entry
and the unwinding code (3.) uses the garbled global offset register and
crashes...
ciao,
Kay.
--
Kay Roemer roemer@informatik.uni-frankfurt.de
http://www.uni-frankfurt.de/~roemer/
"Is there intelligent life on earth?" (Frank Drake, SETI)