public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard.sandiford@arm.com>
To: gcc-patches@gcc.gnu.org
Cc: richard.earnshaw@arm.com, marcus.shawcroft@arm.com,
	kyrylo.tkachov@arm.com
Subject: [committed] aarch64: Add a couple of extra stack-protector tests
Date: Wed, 23 Sep 2020 19:23:44 +0100	[thread overview]
Message-ID: <mpt4knofj2n.fsf@arm.com> (raw)

These tests were inspired by corresponding arm ones.  They already pass.

Tested on aarch64-linux-gnu and aarch64_be-elf, pushed to master.

Richard


gcc/testsuite/
	* gcc.target/aarch64/stack-protector-3.c: New test.
	* gcc.target/aarch64/stack-protector-4.c: Likewise.
---
 .../gcc.target/aarch64/stack-protector-3.c    | 45 +++++++++++++++++++
 .../gcc.target/aarch64/stack-protector-4.c    |  6 +++
 2 files changed, 51 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/stack-protector-3.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/stack-protector-4.c

diff --git a/gcc/testsuite/gcc.target/aarch64/stack-protector-3.c b/gcc/testsuite/gcc.target/aarch64/stack-protector-3.c
new file mode 100644
index 00000000000..909e26c4c0a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/stack-protector-3.c
@@ -0,0 +1,45 @@
+/* { dg-do run } */
+/* { dg-require-effective-target fstack_protector } */
+/* { dg-options "-fstack-protector-all -O2" } */
+
+extern volatile long *stack_chk_guard_ptr;
+
+void __attribute__ ((noipa))
+f (void)
+{
+  volatile int x;
+  /* Munging the contents of __stack_chk_guard should trigger a
+     stack-smashing failure for this function.  */
+  *stack_chk_guard_ptr += 1;
+}
+
+#define CHECK(REG) "\tcmp\tx0, " #REG "\n\tbeq\t1f\n"
+
+asm (
+"	.pushsection .data\n"
+"	.align	3\n"
+"stack_chk_guard_ptr:\n"
+#if __ILP32__
+"	.word	__stack_chk_guard\n"
+#else
+"	.xword	__stack_chk_guard\n"
+#endif
+"	.weak	__stack_chk_guard\n"
+"__stack_chk_guard:\n"
+"	.word	0xdead4321\n"
+"	.word	0xbeef8765\n"
+"	.text\n"
+"	.type	__stack_chk_fail, %function\n"
+"__stack_chk_fail:\n"
+"	mov	x0, #0\n"
+"	b	exit\n"
+"	.size	__stack_chk_fail, .-__stack_chk_fail\n"
+"	.popsection"
+);
+
+int
+main (void)
+{
+  f ();
+  __builtin_abort ();
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/stack-protector-4.c b/gcc/testsuite/gcc.target/aarch64/stack-protector-4.c
new file mode 100644
index 00000000000..6334dd00908
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/stack-protector-4.c
@@ -0,0 +1,6 @@
+/* { dg-do run } */
+/* { dg-require-effective-target fstack_protector } */
+/* { dg-require-effective-target fpic } */
+/* { dg-options "-fstack-protector-all -O2 -fpic" } */
+
+#include "stack-protector-3.c"

                 reply	other threads:[~2020-09-23 18:23 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=mpt4knofj2n.fsf@arm.com \
    --to=richard.sandiford@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=kyrylo.tkachov@arm.com \
    --cc=marcus.shawcroft@arm.com \
    --cc=richard.earnshaw@arm.com \
    /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).