[PATCH][GCC][AARCH64] Add tests for pointer authentication B-key
authorSam Tebbs <sam.tebbs@arm.com>
Wed, 5 Jun 2019 11:06:56 +0000 (11:06 +0000)
committerSam Tebbs <samtebbs@gcc.gnu.org>
Wed, 5 Jun 2019 11:06:56 +0000 (11:06 +0000)
gcc/testsuite/ChangeLog
* gcc.target/aarch64/return_address_sign_b_1.c: New file.
* gcc.target/aarch64/return_address_sign_b_2.c: New file.
* gcc.target/aarch64/return_address_sign_b_3.c: New file.
* gcc.target/aarch64/return_address_sign_builtin.c: New file.
* g++.target/aarch64/return_address_sign_ab_exception.C: New file.
* g++.target/aarch64/return_address_sign_b_exception.C: New file.

From-SVN: r271954

gcc/testsuite/ChangeLog
gcc/testsuite/g++.target/aarch64/return_address_sign_ab_exception.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/return_address_sign_b_exception.C [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/return_address_sign_b_1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/return_address_sign_b_2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/return_address_sign_b_3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/return_address_sign_builtin.c [new file with mode: 0644]

index 75a0f767ccf18e841625c62403697c85756afbaa..0d120c422a2f09bc29c36f5cfbc11c3521101093 100644 (file)
@@ -1,3 +1,12 @@
+2019-06-05  Sam Tebbs  <sam.tebbs@arm.com>
+
+       * gcc.target/aarch64/return_address_sign_b_1.c: New file.
+       * gcc.target/aarch64/return_address_sign_b_2.c: New file.
+       * gcc.target/aarch64/return_address_sign_b_3.c: New file.
+       * gcc.target/aarch64/return_address_sign_builtin.c: New file.
+       * g++.target/aarch64/return_address_sign_ab_exception.C: New file.
+       * g++.target/aarch64/return_address_sign_b_exception.C: New file.
+
 2019-06-05  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/90733
diff --git a/gcc/testsuite/g++.target/aarch64/return_address_sign_ab_exception.C b/gcc/testsuite/g++.target/aarch64/return_address_sign_ab_exception.C
new file mode 100644 (file)
index 0000000..520cd18
--- /dev/null
@@ -0,0 +1,30 @@
+/* { dg-do run } */
+/* { dg-options "--save-temps" } */
+
+__attribute__((target("branch-protection=pac-ret+leaf")))
+int foo_a () {
+  throw 22;
+}
+
+__attribute__((target("branch-protection=pac-ret+leaf+b-key")))
+int foo_b () {
+  throw 22;
+}
+
+int main (int argc, char** argv) {
+  try {
+    foo_a ();
+  } catch (...) {
+    try {
+      foo_b ();
+    } catch (...) {
+      return 0;
+    }
+  }
+  return 1;
+}
+
+/* { dg-final { scan-assembler-times "paciasp" 1 } } */
+/* { dg-final { scan-assembler-times "pacibsp" 1 } } */
+/* { dg-final { scan-assembler-times ".cfi_b_key_frame" 1 } } */
+
diff --git a/gcc/testsuite/g++.target/aarch64/return_address_sign_b_exception.C b/gcc/testsuite/g++.target/aarch64/return_address_sign_b_exception.C
new file mode 100644 (file)
index 0000000..eab2869
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do run } */
+/* { dg-options "-mbranch-protection=pac-ret+leaf+b-key --save-temps" } */
+
+int foo () {
+  throw 22;
+}
+
+int main (int argc, char** argv) {
+  try {
+    foo();
+  } catch (...) {
+    return 0;
+  }
+  return 1;
+}
+
+/* { dg-final { scan-assembler-times ".cfi_b_key_frame" 2 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/return_address_sign_b_1.c b/gcc/testsuite/gcc.target/aarch64/return_address_sign_b_1.c
new file mode 100644 (file)
index 0000000..32d788d
--- /dev/null
@@ -0,0 +1,52 @@
+/* Testing return address signing where no combined instructions used.  */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mbranch-protection=pac-ret+leaf+b-key" } */
+/* { dg-require-effective-target lp64 } */
+
+int foo (int);
+
+/* sibcall only.  */
+int __attribute__ ((target ("arch=armv8.3-a")))
+func1 (int a, int b)
+{
+  /* pacibsp */
+  return foo (a + b);
+  /* autibsp */
+}
+
+/* non-leaf function with sibcall.  */
+int __attribute__ ((target ("arch=armv8.3-a")))
+func2 (int a, int b)
+{
+  /* pacibsp */
+  if (a < b)
+    return b;
+
+  a = foo (b);
+
+  return foo (a);
+  /* autibsp */
+}
+
+/* non-leaf function, legacy arch.  */
+int __attribute__ ((target ("arch=armv8.2-a")))
+func3 (int a, int b, int c)
+{
+  /* pacibsp */
+  return a + foo (b) + c;
+  /* autibsp */
+}
+
+/* eh_return.  */
+void __attribute__ ((target ("arch=armv8.3-a")))
+func4 (long offset, void *handler, int *ptr, int imm1, int imm2)
+{
+  /* pacibsp */
+  *ptr = imm1 + foo (imm1) + imm2;
+  __builtin_eh_return (offset, handler);
+  /* autibsp */
+  return;
+}
+
+/* { dg-final { scan-assembler-times "pacibsp" 4 } } */
+/* { dg-final { scan-assembler-times "autibsp" 4 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/return_address_sign_b_2.c b/gcc/testsuite/gcc.target/aarch64/return_address_sign_b_2.c
new file mode 100644 (file)
index 0000000..9ed64ce
--- /dev/null
@@ -0,0 +1,18 @@
+/* Testing return address signing where combined instructions used.  */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mbranch-protection=pac-ret+leaf+b-key" } */
+/* { dg-require-effective-target lp64 } */
+
+int foo (int);
+int bar (int, int);
+
+int __attribute__ ((target ("arch=armv8.3-a")))
+func1 (int a, int b, int c)
+{
+  /* pacibsp */
+  return a + foo (b) + c;
+  /* retab */
+}
+
+/* { dg-final { scan-assembler-times "pacibsp" 1 } } */
+/* { dg-final { scan-assembler-times "retab" 1 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/return_address_sign_b_3.c b/gcc/testsuite/gcc.target/aarch64/return_address_sign_b_3.c
new file mode 100644 (file)
index 0000000..7183cc2
--- /dev/null
@@ -0,0 +1,22 @@
+/* Testing the disable of return address signing.  */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mbranch-protection=pac-ret+leaf+b-key" } */
+/* { dg-require-effective-target lp64 } */
+
+int bar (int, int);
+
+int __attribute__ ((target ("arch=armv8.3-a,branch-protection=pac-ret+b-key")))
+func1_leaf (int a, int b, int c, int d)
+{
+  return a + b + c + d;
+}
+
+int __attribute__ ((target ("arch=armv8.3-a,branch-protection=none")))
+func2_none (int a, int b, int c, int d)
+{
+  return c + bar (a, b) + d;
+}
+
+/* { dg-final { scan-assembler-not "pacibsp" } } */
+/* { dg-final { scan-assembler-not "autibsp" } } */
+/* { dg-final { scan-assembler-not "retab" } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/return_address_sign_builtin.c b/gcc/testsuite/gcc.target/aarch64/return_address_sign_builtin.c
new file mode 100644 (file)
index 0000000..0a01bfc
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-mbranch-protection=pac-ret+leaf+b-key" } */
+
+/* The correct pauth instruction should be generated no matter the return
+  address signing key/scope specified in the options.  */
+
+int foo() {
+  /* { dg-final { scan-assembler-times "pacia1716" 1 } } */
+  __builtin_aarch64_pacia1716(0, 0);
+  /* { dg-final { scan-assembler-times "pacib1716" 1 } } */
+  __builtin_aarch64_pacib1716(0, 0);
+  /* { dg-final { scan-assembler-times "autia1716" 1 } } */
+  __builtin_aarch64_autia1716(0, 0);
+  /* { dg-final { scan-assembler-times "autib1716" 1 } } */
+  __builtin_aarch64_autib1716(0, 0);
+}