c++gccarmraspberry-pi2crosstool-ng

C++ Exceptions not being caught on Raspberry Pi when compiled with gcc-4.8.5 but works with gcc-4.6.4


Edit: this problem is not with my code, it has been tested on numerous other problems without issue. This is a gcc cross compilation problem.

I am cross compiling a large C++ program with g++ on Ubuntu x64 to run on a Raspberry Pi 2. When using gcc-4.6.4 everything seems to work. When using gcc-4.8.5, exceptions seems to be leaking through and causing the program to abort. I have tried a minimal example of exception catching using gcc-4.8.5 and the minimal case does seem to work properly. My actual program is far more complicated and it seems the exception catch is being lost somewhere.

Is there some g++ setting that I am missing that will improve exception handling?

I am compiling the toolchains with crosstools-ng 1.22

Edit: This is essentially what the code is doing:

//error_function may be deeper in the stack
void error_function()
{
    throw std::runtime_error("This is an error");
}

try
{
    error_function();
}
catch (std::exception&)
{
   //Not being caught
}

Solution

  • Turning off optimization by setting -O0 seems to fix the problem. This bug seems to be specific to gcc 4.8.5 ARMv6 hard float build.