This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH AArch64]: Add constraint letter for stack_protect_test pattern)


On Wed, Sep 17, 2014 at 03:50:55PM +0100, pinskia@gmail.com wrote:
>
>
> > On Sep 17, 2014, at 7:43 AM, James Greenhalgh <james.greenhalgh@arm.com> wrote:
> >
> >
> >> On Wed, Sep 17, 2014 at 09:30:31AM +0100, Richard Earnshaw wrote:
> >> "=&r" is correct for an early-clobbered scratch.
> >>
> >> R.
> >
> > In that case...
> >
> > How is the attached patch for trunk? I've bootstrapped it on AArch64
> > with -fstack-protector-strong and -frename-registers in the BOOT_CFLAGS
> > without seeing any issues.

> There is nothing aarch64 specific about this testcase so I would place them
> under gcc.dg and add the extra marker which says this testcase requires stack
> protector.

That sounds reasonable to me. Updated as attached, along with Jakub's
suggestions.

>   And maybe even use compile instead of just assemble too.

Compile is weaker than assemble. Assemble takes you up to an object file,
which is as far as we need to go.

Thanks,
James

---

gcc/

2014-09-18  James Greenhalgh  <james.greenhalgh@arm.com>

	* config/aarch64/aarch64.md (stack_protect_test_<mode>): Mark
	scratch register as an output to placate register renaming.

gcc/testsuite/

2014-09-18  James Greenhalgh  <james.greenhalgh@arm.com>

	* gcc.dg/ssp-3.c: New.
	* gcc.dg/ssp-4.c: Likewise.
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index c60038a9015d614f40f6d9e3fd228ad3e2b247a8..f15a516bb0559c86bea7512f91d60dc179ec9149 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -4031,7 +4031,7 @@ (define_insn "stack_protect_test_<mode>"
 	(unspec:PTR [(match_operand:PTR 1 "memory_operand" "m")
 		     (match_operand:PTR 2 "memory_operand" "m")]
 	 UNSPEC_SP_TEST))
-   (clobber (match_scratch:PTR 3 "&r"))]
+   (clobber (match_scratch:PTR 3 "=&r"))]
   ""
   "ldr\t%<w>3, %x1\;ldr\t%<w>0, %x2\;eor\t%<w>0, %<w>3, %<w>0"
   [(set_attr "length" "12")
diff --git a/gcc/testsuite/gcc.dg/ssp-3.c b/gcc/testsuite/gcc.dg/ssp-3.c
new file mode 100644
index 0000000..98c12da
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ssp-3.c
@@ -0,0 +1,16 @@
+/* { dg-do assemble } */
+/* { dg-options "-fstack-protector-strong -O1 -frename-registers" } */
+/* { dg-require-effective-target fstack_protector } */
+
+extern int bar (const char *s, int *argc);
+extern int baz (const char *s);
+
+char
+foo (const char *s)
+{
+  int argc;
+  int ret;
+  if ( !bar (s, &argc))
+    ret = baz (s);
+  return *s;
+}
diff --git a/gcc/testsuite/gcc.dg/ssp-4.c b/gcc/testsuite/gcc.dg/ssp-4.c
new file mode 100644
index 0000000..402033c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ssp-4.c
@@ -0,0 +1,18 @@
+/* { dg-do assemble } */
+/* { dg-options "-fstack-protector-strong -O1 -frename-registers" } */
+/* { dg-require-effective-target fstack_protector } */
+
+typedef unsigned int uint32_t;
+struct ctx
+{
+  uint32_t A;
+};
+
+void *
+buffer_copy (const struct ctx *ctx, void *resbuf)
+{
+  uint32_t buffer[4];
+  buffer[0] = (ctx->A);
+  __builtin_memcpy (resbuf, buffer, sizeof (buffer));
+  return resbuf;
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]