From 2098f8ec2f82310104d1e3eb0a3ac0003e78600a Mon Sep 17 00:00:00 2001 From: Sam Tebbs Date: Wed, 5 Jun 2019 11:06:56 +0000 Subject: [PATCH] [PATCH][GCC][AARCH64] Add tests for pointer authentication B-key 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 | 9 ++++ .../return_address_sign_ab_exception.C | 30 +++++++++++ .../aarch64/return_address_sign_b_exception.C | 17 ++++++ .../aarch64/return_address_sign_b_1.c | 52 +++++++++++++++++++ .../aarch64/return_address_sign_b_2.c | 18 +++++++ .../aarch64/return_address_sign_b_3.c | 22 ++++++++ .../aarch64/return_address_sign_builtin.c | 16 ++++++ 7 files changed, 164 insertions(+) create mode 100644 gcc/testsuite/g++.target/aarch64/return_address_sign_ab_exception.C create mode 100644 gcc/testsuite/g++.target/aarch64/return_address_sign_b_exception.C create mode 100644 gcc/testsuite/gcc.target/aarch64/return_address_sign_b_1.c create mode 100644 gcc/testsuite/gcc.target/aarch64/return_address_sign_b_2.c create mode 100644 gcc/testsuite/gcc.target/aarch64/return_address_sign_b_3.c create mode 100644 gcc/testsuite/gcc.target/aarch64/return_address_sign_builtin.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 75a0f767ccf..0d120c422a2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2019-06-05 Sam Tebbs + + * 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 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 index 00000000000..520cd180bee --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/return_address_sign_ab_exception.C @@ -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 index 00000000000..eab2869e004 --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/return_address_sign_b_exception.C @@ -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 index 00000000000..32d788ddf3f --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/return_address_sign_b_1.c @@ -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 index 00000000000..9ed64ce0591 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/return_address_sign_b_2.c @@ -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 index 00000000000..7183cc2f2b1 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/return_address_sign_b_3.c @@ -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 index 00000000000..0a01bfc9da4 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/return_address_sign_builtin.c @@ -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); +} -- 2.30.2