How to get C++ exceptions to work with PowerPC EABI
R. Diez
rdiezmail-gcc@yahoo.de
Wed Jul 6 13:27:00 GMT 2011
Hi there:
I have built a GCC 4.5.3 cross-compiler for an embedded PowerPC target, together with binutils-2.21 and newlib 1.19.0, and I cannot get C++ exceptions to work.
I wrote the following test code, but the 'throw' statement ends up calling 'abort' here:
try
{
throw 123;
}
catch ( const int a )
{
CONSOLE_OUTPUT( "Exception caught: %d", a );
}
catch ( ... )
{
CONSOLE_OUTPUT( "Catch all reached." );
}
The call stack looks like this:
abort() - abort.c:62
uw_init_context_1() - unwind-dw2.c:2891
_Unwind_RaiseException() - unwind-dw2.c:2891
__cxxabiv1::__cxa_throw() - eh_throw.cc:78
A similar problem was already described in this mailing list:
http://gcc.gnu.org/ml/gcc-help/2010-01/msg00004.html
However, the information provided there did not help me, as I don't have the necessary knowledge about the GCC internals to understand what's going on.
In my particular case, there is no operating system, so I have full control about what's going on. I can step through the generated assembly code with the debugger if necessary.
Inside main(), I can see the __eabi() call, which in turn calls __init(). I heard the C++ exception support is initialised there, but I don't know what I should provide for it to work properly. Maybe I'm discarding one section too many at the linker, although I did try to keep the .eh_frame ones. Or maybe I'm not initialising some global register properly in my start-up assembly code.
Can someone provide me with step-by-step instructions on how to setup the necessary C++ exception support framework? What could I be missing?
Please copy me on the answer, as I'm not subscribed to this list.
Many thanks,
R. Diez
More information about the Gcc-help
mailing list