public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Sandiford <rsandifo@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/vendors/ARM/heads/CVE-2023-4039/gcc-9)] aarch64: Simplify probe of final frame allocation
Date: Tue, 12 Sep 2023 15:24:20 +0000 (GMT)	[thread overview]
Message-ID: <20230912152421.00F543858412@sourceware.org> (raw)

https://gcc.gnu.org/g:f2684e63652bb251d22c79e40081c646df1f36b6

commit f2684e63652bb251d22c79e40081c646df1f36b6
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Tue Aug 8 01:57:26 2023 +0100

    aarch64: Simplify probe of final frame allocation
    
    Previous patches ensured that the final frame allocation only needs
    a probe when the size is strictly greater than 1KiB.  It's therefore
    safe to use the normal 1024 probe offset in all cases.
    
    The main motivation for doing this is to simplify the code and
    remove the number of special cases.
    
    gcc/
            * config/aarch64/aarch64.c (aarch64_allocate_and_probe_stack_space):
            Always probe the residual allocation at offset 1024, asserting
            that that is in range.
    
    gcc/testsuite/
            * gcc.target/aarch64/stack-check-prologue-17.c: Expect the probe
            to be at offset 1024 rather than offset 0.
            * gcc.target/aarch64/stack-check-prologue-18.c: Likewise.

Diff:
---
 gcc/config/aarch64/aarch64.c                               | 12 ++++--------
 gcc/testsuite/gcc.target/aarch64/stack-check-prologue-17.c |  2 +-
 gcc/testsuite/gcc.target/aarch64/stack-check-prologue-18.c |  7 +++++--
 3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 1e8467fdd03f..705f719a2eaa 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -5695,16 +5695,12 @@ aarch64_allocate_and_probe_stack_space (rtx temp1, rtx temp2,
      are still safe.  */
   if (residual)
     {
-      HOST_WIDE_INT residual_probe_offset = guard_used_by_caller;
+      gcc_assert (guard_used_by_caller + byte_sp_alignment <= size);
+
       /* If we're doing final adjustments, and we've done any full page
 	 allocations then any residual needs to be probed.  */
       if (final_adjustment_p && rounded_size != 0)
 	min_probe_threshold = 0;
-      /* If doing a small final adjustment, we always probe at offset 0.
-	 This is done to avoid issues when the final adjustment is smaller
-	 than the probing offset.  */
-      else if (final_adjustment_p && rounded_size == 0)
-	residual_probe_offset = 0;
 
       aarch64_sub_sp (temp1, temp2, residual, frame_related_p);
       if (residual >= min_probe_threshold)
@@ -5715,8 +5711,8 @@ aarch64_allocate_and_probe_stack_space (rtx temp1, rtx temp2,
 		     HOST_WIDE_INT_PRINT_DEC " bytes, probing will be required."
 		     "\n", residual);
 
-	    emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
-					     residual_probe_offset));
+	  emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
+					   guard_used_by_caller));
 	  emit_insn (gen_blockage ());
 	}
     }
diff --git a/gcc/testsuite/gcc.target/aarch64/stack-check-prologue-17.c b/gcc/testsuite/gcc.target/aarch64/stack-check-prologue-17.c
index 0d8a25d73a24..f0ec1389771d 100644
--- a/gcc/testsuite/gcc.target/aarch64/stack-check-prologue-17.c
+++ b/gcc/testsuite/gcc.target/aarch64/stack-check-prologue-17.c
@@ -33,7 +33,7 @@ int test1(int z) {
 **	...
 **	str	x30, \[sp\]
 **	sub	sp, sp, #1040
-**	str	xzr, \[sp\]
+**	str	xzr, \[sp, #?1024\]
 **	cbnz	w0, .*
 **	bl	g
 **	...
diff --git a/gcc/testsuite/gcc.target/aarch64/stack-check-prologue-18.c b/gcc/testsuite/gcc.target/aarch64/stack-check-prologue-18.c
index 82447d20fff5..71d33ba34e9e 100644
--- a/gcc/testsuite/gcc.target/aarch64/stack-check-prologue-18.c
+++ b/gcc/testsuite/gcc.target/aarch64/stack-check-prologue-18.c
@@ -8,8 +8,9 @@ void g();
 ** test1:
 **	...
 **	str	x30, \[sp\]
+**	...
 **	sub	sp, sp, #4064
-**	str	xzr, \[sp\]
+**	str	xzr, \[sp, #?1024\]
 **	cbnz	w0, .*
 **	bl	g
 **	...
@@ -49,8 +50,9 @@ int test1(int z) {
 ** test2:
 **	...
 **	str	x30, \[sp\]
+**	...
 **	sub	sp, sp, #1040
-**	str	xzr, \[sp\]
+**	str	xzr, \[sp, #?1024\]
 **	cbnz	w0, .*
 **	bl	g
 **	...
@@ -77,6 +79,7 @@ int test2(int z) {
 ** test3:
 **	...
 **	str	x30, \[sp\]
+**	...
 **	sub	sp, sp, #1024
 **	cbnz	w0, .*
 **	bl	g

                 reply	other threads:[~2023-09-12 15:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230912152421.00F543858412@sourceware.org \
    --to=rsandifo@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).