]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Fix vector cfi notes for stack-clash protection
authorRaphael Moreira Zinsly <rzinsly@ventanamicro.com>
Wed, 21 Aug 2024 21:08:54 +0000 (18:08 -0300)
committerRaphael Moreira Zinsly <rzinsly@ventanamicro.com>
Thu, 22 Aug 2024 13:26:04 +0000 (10:26 -0300)
The stack-clash code is generating wrong cfi directives in
riscv_v_adjust_scalable_frame because REG_CFA_DEF_CFA has a different
encoding than REG_FRAME_RELATED_EXPR, this patch fixes the offset sign
in prologue and starts using REG_CFA_DEF_CFA in the epilogue.

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_v_adjust_scalable_frame): Add
epilogue code for stack-clash and fix prologue cfi note.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/stack-check-cfa-3.c: Fix the expected output.

gcc/config/riscv/riscv.cc
gcc/testsuite/gcc.target/riscv/stack-check-cfa-3.c

index f266c45ed4d9c5c7723335bc10ddb8c37326dca4..8538d405f505bbf0a3d7f833d40c1a873ce739e0 100644 (file)
@@ -7974,8 +7974,22 @@ riscv_v_adjust_scalable_frame (rtx target, poly_int64 offset, bool epilogue)
 
   /* If doing stack clash protection then we use a loop to allocate and probe
      the stack.  */
-  if (flag_stack_clash_protection && !epilogue)
+  if (flag_stack_clash_protection)
     {
+      if (epilogue)
+       {
+         insn = emit_insn (gen_add3_insn (target, target, adjust_size));
+
+         if (!frame_pointer_needed)
+           {
+             add_reg_note (insn, REG_CFA_DEF_CFA,
+                       plus_constant (Pmode, stack_pointer_rtx, -offset));
+             RTX_FRAME_RELATED_P (insn) = 1;
+           }
+
+         return;
+       }
+
       HOST_WIDE_INT min_probe_threshold
        = (1 << param_stack_clash_protection_guard_size) - STACK_CLASH_CALLER_GUARD;
 
@@ -8008,7 +8022,7 @@ riscv_v_adjust_scalable_frame (rtx target, poly_int64 offset, bool epilogue)
       if (!frame_pointer_needed)
        {
          add_reg_note (insn, REG_CFA_DEF_CFA,
-                       plus_constant (Pmode, stack_pointer_rtx, -offset));
+                       plus_constant (Pmode, stack_pointer_rtx, offset));
          RTX_FRAME_RELATED_P (insn) = 1;
        }
 
index e45f7bb7df51b2218bc6a55ad97eaa3dfb7a07ca..225dfae661d2594395568e287e61d5cc9fe07db9 100644 (file)
@@ -10,4 +10,5 @@
 
 /* { dg-final { scan-assembler-times {mv\tt3,sp} 1 } } */
 /* { dg-final { scan-assembler-times {\.cfi_def_cfa [0-9]+, 0} 1 } } */
-/* { dg-final { scan-assembler-times {\.cfi_escape 0xf,0xa,0x72,0,0x92,0xa2,0x38,0,0x9,0xec,0x1e,0x22} 1 } } */
+/* { dg-final { scan-assembler-times {\.cfi_escape 0xf,0x9,0x72,0,0x92,0xa2,0x38,0,0x3a,0x1e,0x22} 1 } } */
+/* { dg-final { scan-assembler-times {\.cfi_escape 0xf,0xa,0x72,0,0x92,0xa2,0x38,0,0x9,0xf6,0x1e,0x22} 1 } } */