]> git.ipfire.org Git - thirdparty/gcc.git/commit
aarch64: Robustify stack tie handling
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 20 Jun 2023 20:48:38 +0000 (21:48 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Tue, 20 Jun 2023 20:48:38 +0000 (21:48 +0100)
commit580b74a79146e51268dd11192d3870645adb0bbb
tree046d76236fd6f9980e368ca4a99a1abc855bb440
parentf8f68c4ca622a24c2e8cf2b5f2f9fdcd47a7b369
aarch64: Robustify stack tie handling

The SVE handling of stack clash protection copied the stack
pointer to X11 before the probe and set up X11 as the CFA
for unwind purposes:

    /* This is done to provide unwinding information for the stack
       adjustments we're about to do, however to prevent the optimizers
       from removing the R11 move and leaving the CFA note (which would be
       very wrong) we tie the old and new stack pointer together.
       The tie will expand to nothing but the optimizers will not touch
       the instruction.  */
    rtx stack_ptr_copy = gen_rtx_REG (Pmode, STACK_CLASH_SVE_CFA_REGNUM);
    emit_move_insn (stack_ptr_copy, stack_pointer_rtx);
    emit_insn (gen_stack_tie (stack_ptr_copy, stack_pointer_rtx));

    /* We want the CFA independent of the stack pointer for the
       duration of the loop.  */
    add_reg_note (insn, REG_CFA_DEF_CFA, stack_ptr_copy);
    RTX_FRAME_RELATED_P (insn) = 1;

-fcprop-registers is now smart enough to realise that X11 = SP,
replace X11 with SP in the stack tie, and delete the instruction
created above.

This patch tries to prevent that by making stack_tie fussy about
the register numbers.  It fixes failures in
gcc.target/aarch64/sve/pcs/stack_clash*.c.

gcc/
* config/aarch64/aarch64.md (stack_tie): Hard-code the first
register operand to the stack pointer.  Require the second register
operand to have the number specified in a separate const_int operand.
* config/aarch64/aarch64.cc (aarch64_emit_stack_tie): New function.
(aarch64_allocate_and_probe_stack_space): Use it.
(aarch64_expand_prologue, aarch64_expand_epilogue): Likewise.
(aarch64_expand_epilogue): Likewise.
gcc/config/aarch64/aarch64.cc
gcc/config/aarch64/aarch64.md