From: "Kewen.Lin" <linkw@linux.ibm.com>
To: Peter Bergner <bergner@linux.ibm.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
Segher Boessenkool <segher@kernel.crashing.org>,
David Edelsohn <dje.gcc@gmail.com>
Subject: Re: [PATCH] rs6000: Compute rop_hash_save_offset for non-Altivec compiles [PR115389]
Date: Thu, 13 Jun 2024 13:35:56 +0800 [thread overview]
Message-ID: <4a8bf020-b15f-3929-6a13-6c0981784895@linux.ibm.com> (raw)
In-Reply-To: <b32349da-4463-4411-88e9-cbee37e11c4f@linux.ibm.com>
Hi Peter,
on 2024/6/8 12:06, Peter Bergner wrote:
> We currently only compute the offset for the ROP hash save location in
> the stack frame for Altivec compiles. For non-Altivec compiles when we
> emit ROP mitigation instructions, we use a default offset of zero which
> corresponds to the backchain save location which will get clobbered on
> any call. The fix is to compute the ROP hash save location for all
> compiles.
Thanks for fixing this.
>
> This passed bootstrap and regtesting on powerpc64le-linux.
> Ok for trunk and backports after some burn-in time?
>
> Peter
>
>
> gcc/
> PR target/115389
> * config/rs6000/rs6000-logue.cc (rs6000_stack_info): Compute
> rop_hash_save_offset for non-Altivec compiles.
>
> gcc/testsuite/
> PR target/115389
> * gcc.target/powerpc/pr115389.c: New test.
>
> diff --git a/gcc/config/rs6000/rs6000-logue.cc b/gcc/config/rs6000/rs6000-logue.cc
> index d61a25a5126..cfa8a67a5f3 100644
> --- a/gcc/config/rs6000/rs6000-logue.cc
> +++ b/gcc/config/rs6000/rs6000-logue.cc
> @@ -826,7 +826,14 @@ rs6000_stack_info (void)
> info->ehrd_offset -= info->rop_hash_size;
> }
> else
> - info->ehrd_offset = info->gp_save_offset - ehrd_size;
> + {
> + info->ehrd_offset = info->gp_save_offset - ehrd_size;
> +
> + /* Adjust for ROP protection. */
> + info->rop_hash_save_offset
> + = info->gp_save_offset - info->rop_hash_size;
> + info->ehrd_offset -= info->rop_hash_size;
> + }
I understand this is just copied from the if arm, but if I read this right, it can be
simplified as:
diff --git a/gcc/config/rs6000/rs6000-logue.cc b/gcc/config/rs6000/rs6000-logue.cc
index bd5d56ba002..2559c974c6e 100644
--- a/gcc/config/rs6000/rs6000-logue.cc
+++ b/gcc/config/rs6000/rs6000-logue.cc
@@ -817,17 +817,14 @@ rs6000_stack_info (void)
gcc_assert (info->altivec_size == 0
|| info->altivec_save_offset % 16 == 0);
- /* Adjust for AltiVec case. */
- info->ehrd_offset = info->altivec_save_offset - ehrd_size;
-
- /* Adjust for ROP protection. */
info->rop_hash_save_offset
= info->altivec_save_offset - info->rop_hash_size;
- info->ehrd_offset -= info->rop_hash_size;
}
else
- info->ehrd_offset = info->gp_save_offset - ehrd_size;
+ info->rop_hash_save_offset = info->gp_save_offset - info->rop_hash_size;
+ info->ehrd_offset = info->rop_hash_save_offset - ehrd_size;
info->ehcr_offset = info->ehrd_offset - ehcr_size;
info->cr_save_offset = reg_size; /* first word when 64-bit. */
info->lr_save_offset = 2*reg_size;
, both if and else have info->rop_hash_save_offset as the base for offset computation further.
>
> info->ehcr_offset = info->ehrd_offset - ehcr_size;
> info->cr_save_offset = reg_size; /* first word when 64-bit. */
> diff --git a/gcc/testsuite/gcc.target/powerpc/pr115389.c b/gcc/testsuite/gcc.target/powerpc/pr115389.c
> new file mode 100644
> index 00000000000..a091ee8a1be
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/pr115389.c
> @@ -0,0 +1,17 @@
> +/* PR target/115389 */
> +/* { dg-do assemble } */
> +/* { dg-options "-O2 -mdejagnu-cpu=power10 -mrop-protect -mno-vsx -mno-altivec -mabi=no-altivec -save-temps" } */
I'd expect -mabi=no-altivec is default for -mno-altivec, but specifying it explicitly
looks fine to me. :)
BR,
Kewen
> +/* { dg-require-effective-target rop_ok } */
> +
> +/* Verify we do not emit invalid offsets for our ROP insns. */
> +
> +extern void foo (void);
> +long
> +bar (void)
> +{
> + foo ();
> + return 0;
> +}
> +
> +/* { dg-final { scan-assembler-times {\mhashst\M} 1 } } */
> +/* { dg-final { scan-assembler-times {\mhashchk\M} 1 } } */
next prev parent reply other threads:[~2024-06-13 5:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-08 4:06 Peter Bergner
2024-06-13 2:14 ` [PING][PATCH] " Peter Bergner
2024-06-13 5:35 ` Kewen.Lin [this message]
2024-06-13 13:24 ` [PATCH] " Peter Bergner
2024-06-14 2:26 ` Kewen.Lin
2024-06-14 3:26 ` Peter Bergner
2024-06-14 17:05 ` Peter Bergner
2024-06-17 2:10 ` Kewen.Lin
2024-06-17 2:31 ` Peter Bergner
2024-06-17 2:40 ` Kewen.Lin
2024-06-17 12:57 ` Peter Bergner
2024-06-18 2:55 ` Kewen.Lin
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=4a8bf020-b15f-3929-6a13-6c0981784895@linux.ibm.com \
--to=linkw@linux.ibm.com \
--cc=bergner@linux.ibm.com \
--cc=dje.gcc@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=segher@kernel.crashing.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).