aarch64: fix return address access with pac [PR94891][PR94791]

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.

2020-07-13  Szabolcs Nagy  <szabolcs.nagy@arm.com>

gcc/ChangeLog:

	PR target/94891
	PR target/94791
	* 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.
This commit is contained in:
Szabolcs Nagy 2020-06-02 16:44:41 +01:00
parent 5834e96a08
commit 463a54e5d4
3 changed files with 21 additions and 2 deletions

View file

@ -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);

View file

@ -10825,6 +10825,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. */
@ -10833,7 +10851,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 ();
}
static void

View file

@ -1133,7 +1133,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); \
}