[PATCH 1/4] aarch64: fix return address access with pac [PR94891][PR94791]

Kyrylo Tkachov Kyrylo.Tkachov@arm.com
Wed Jul 8 13:17:13 GMT 2020



> -----Original Message-----
> From: Gcc-patches <gcc-patches-bounces@gcc.gnu.org> On Behalf Of
> Szabolcs Nagy
> Sent: 26 June 2020 15:44
> To: gcc-patches@gcc.gnu.org
> Cc: fweimer@redhat.com; Richard Earnshaw <Richard.Earnshaw@arm.com>;
> Daniel Kiss <Daniel.Kiss@arm.com>
> Subject: Re: [PATCH 1/4] aarch64: fix return address access with pac
> [PR94891][PR94791]
> 
> The 06/05/2020 17:51, Szabolcs Nagy wrote:
> > This is a big hammer fix for __builtin_return_address (PR target/94891)
> > returning signed addresses (sometimes, depending on wether lr happens
> > to be signed or not at the time of call which depends on optimizations),
> > and similarly -pg may pass signed return address to _mcount
> > (PR target/94791).
> >
> > At the time of return address expansion we don't know if it's signed or
> > not so it is done unconditionally.
> >
> > I wonder if allocate_initial_value for the lr reg may solve this better
> > such that get_hard_reg_initial_val just gives the right (unsigned) value?
> >
> > 2020-06-04  Szabolcs Nagy  <szabolcs.nagy@arm.com>
> >
> > 	* config/aarch64/aarch64-protos.h (aarch64_return_addr_rtx):
> Declare.
> > 	* config/aarch64/aarch64.c (aarch64_return_addr_rtx): New.
> > 	(aarch64_return_addr): Use aarch64_return_addr_rtx.
> > 	* config/aarch64/aarch64.h (PROFILE_HOOK): Likewise.
> 
> ping.
> 

This looks ok to me.
Thanks,
Kyrill

> (this fixes a correctness bug in pac-ret, tested with no regressions).
> 
> > ---
> >  gcc/config/aarch64/aarch64-protos.h |  1 +
> >  gcc/config/aarch64/aarch64.c        | 20 +++++++++++++++++++-
> >  gcc/config/aarch64/aarch64.h        |  2 +-
> >  3 files changed, 21 insertions(+), 2 deletions(-)
> >
> > diff --git a/gcc/config/aarch64/aarch64-protos.h
> b/gcc/config/aarch64/aarch64-protos.h
> > index 9e43adb7db0..723d9ba6ac6 100644
> > --- a/gcc/config/aarch64/aarch64-protos.h
> > +++ b/gcc/config/aarch64/aarch64-protos.h
> > @@ -578,6 +578,7 @@ int aarch64_vec_fpconst_pow_of_2 (rtx);
> >  rtx aarch64_eh_return_handler_rtx (void);
> >  rtx aarch64_mask_from_zextract_ops (rtx, rtx);
> >  const char *aarch64_output_move_struct (rtx *operands);
> > +rtx aarch64_return_addr_rtx (void);
> >  rtx aarch64_return_addr (int, rtx);
> >  rtx aarch64_simd_gen_const_vector_dup (machine_mode,
> HOST_WIDE_INT);
> >  bool aarch64_simd_mem_operand_p (rtx);
> > diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
> > index 6352d4ff78a..6a2f85c4af7 100644
> > --- a/gcc/config/aarch64/aarch64.c
> > +++ b/gcc/config/aarch64/aarch64.c
> > @@ -10819,6 +10819,24 @@ aarch64_initial_elimination_offset (unsigned
> from, unsigned to)
> >    return cfun->machine->frame.frame_size;
> >  }
> >
> > +
> > +/* Get return address without mangling.  */
> > +
> > +rtx
> > +aarch64_return_addr_rtx (void)
> > +{
> > +  rtx val = get_hard_reg_initial_val (Pmode, LR_REGNUM);
> > +  /* Note: aarch64_return_address_signing_enabled only
> > +     works after cfun->machine->frame.laid_out is set,
> > +     so here we don't know if the return address will
> > +     be signed or not.  */
> > +  rtx lr = gen_rtx_REG (Pmode, LR_REGNUM);
> > +  emit_move_insn (lr, val);
> > +  emit_insn (GEN_FCN (CODE_FOR_xpaclri) ());
> > +  return lr;
> > +}
> > +
> > +
> >  /* Implement RETURN_ADDR_RTX.  We do not support moving back to a
> >     previous frame.  */
> >
> > @@ -10827,7 +10845,7 @@ aarch64_return_addr (int count, rtx frame
> ATTRIBUTE_UNUSED)
> >  {
> >    if (count != 0)
> >      return const0_rtx;
> > -  return get_hard_reg_initial_val (Pmode, LR_REGNUM);
> > +  return aarch64_return_addr_rtx ();
> >  }
> >
> >
> > diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
> > index 2be52fd4d73..f11941bbc86 100644
> > --- a/gcc/config/aarch64/aarch64.h
> > +++ b/gcc/config/aarch64/aarch64.h
> > @@ -1112,7 +1112,7 @@ typedef struct
> >  #define PROFILE_HOOK(LABEL)
> 	\
> >    {									\
> >      rtx fun, lr;							\
> > -    lr = get_hard_reg_initial_val (Pmode, LR_REGNUM);
> 	\
> > +    lr = aarch64_return_addr_rtx ();					\
> >      fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_NAME);
> 	\
> >      emit_library_call (fun, LCT_NORMAL, VOIDmode, lr, Pmode);
> 	\
> >    }
> > --
> > 2.17.1
> >
> 
> --


More information about the Gcc-patches mailing list