[gccsdk] Bug in exception handling in GCC4

John Tytgat John.Tytgat at aaug.net
Mon Nov 23 16:14:36 PST 2009

In message <BLU146-W28E323E3403C6D3F760427F09E0 at phx.gbl>
          alan buckley <alan_baa at hotmail.com> wrote:

> I've managed to reduce the code sample I posted
> a while ago about a crash in the GCC4 compiler
> to a lot fewer lines.
> The below program will crash rather than
> successfully catch the thrown exception.
> The line that seems to cause the error is
> char buffer[size];
> If I comment out the line it works correctly.
> #include <iostream>
> void throw_test()
> {
>  std::cout << "in throw test" << std::endl;
>  unsigned int size = 2;
>  throw 1;
>  char buffer[size];
> }
> int main(int argc, char *argv[])
> {
>  try
>  {
>   throw_test();
>  } catch(int err)
>  {
>   std::cout << "Got thrown int as expected\n" << std::endl;
>  }
> }
> Is there anyone who can have a look at this for me?
> I got no response from the previous example, but hopefully
> I've reduced the example to be small enough so someone
> can have a quick look at it.

I think I know what the problem is.  The "char buffer[size]" results
in claiming local memory and the state before gets saved using
__gcc_alloca_save() and restored using __gcc_alloca_restore() (this is one
of our arm-unknown-riscos target specific changes to deal with APCS-32).

It looks like this badly clashes when the runtime exception is issued and
probably we have this issue when we moved from setjmp/longjmp exception
implementation to the DWARF based one (i.e. when configure
--enable-sjlj-exceptions option changed from yes to no).

I don't know if this is a fundamental problem or just something missing in
the unwind exception code to deal with this.

Alan, could you please log this in our Bugzilla citing this excellent small
example file and possibly pointing to this mail thread as well ? This helps
us not to forget this issue when we have a moment of spare time to look
after gccsdk issues.

John Tytgat, in his comfy chair at home                                 BASS
John.Tytgat at aaug.net                             ARM powered, RISC OS driven

More information about the gcc mailing list