[PATCH] Fix aarch64 exception handling (PR c++/59813)

Segher Boessenkool segher@kernel.crashing.org
Sat May 11 16:49:00 GMT 2019


On Sat, May 11, 2019 at 09:38:22AM +0100, Richard Sandiford wrote:
> Jakub Jelinek <jakub@redhat.com> writes:
> > Previously, the mere existence of the addressable variables this_context
> > and cur_context prevented tail call on the early out
> > return _Unwind_RaiseException (exc);
> > but since r271013 the tailcall analysis figures that while those two
> > variables are there, they aren't touched before the possible tail call
> > site, so they can't be really live during the call.

Ah!  That explains why this never happened before.

> > This does a lot of register saving and restoring, which is not needed but is
> > not wrong-code (guess separate shrink wrapping would help here if
> > implemented for the target).

SWS does not handle eh_return:
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/shrink-wrap.c;h=57124db92c662bf52efc7ea94c274d9b4e234d04;hb=HEAD#l1780

But, a function calling eh_return will not get *any* shrink-wrapping:
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/shrink-wrap.c;h=57124db92c662bf52efc7ea94c274d9b4e234d04;hb=HEAD#l658

(it has done this since r179553, when shrink-wrapping was added).

Some targets run splitters for their eh_return and evilness like that.
It never was documented what the compiler expects the target to do with
eh_return, and what the limitations are, etc.

> > The only wrong-code is actually the
> > add sp, sp, x4 instruction though.  The previous instruction restored sp to
> > the value it had at the start of the function and then we should just tail
> > call.

But is that correct?  eh_return is supposed to adjust the stack?

And, what should other targets do?

> FWIW, I agree we should just fix the targets and not even use the
> workaround you posted later.  It won't be the first time that many
> targets have got something wrong due to lack of coverage.

eh_return isn't defined or documented very well.  That should be fixed...
Or maybe eh_return should just be removed.


Segher


> > --- gcc/config/aarch64/aarch64.c.jj	2019-05-02 12:18:40.004979690 +0200
> > +++ gcc/config/aarch64/aarch64.c	2019-05-09 20:08:00.774718003 +0200
> > @@ -5913,7 +5913,7 @@ aarch64_expand_epilogue (bool for_sibcal
> >      }
> >  
> >    /* Stack adjustment for exception handler.  */
> > -  if (crtl->calls_eh_return)
> > +  if (crtl->calls_eh_return && !for_sibcall)
> >      {
> >        /* We need to unwind the stack by the offset computed by
> >  	 EH_RETURN_STACKADJ_RTX.  We have already reset the CFA



More information about the Gcc-patches mailing list