PR target/96307: Fix KASAN option checking.
authorKito Cheng <kito.cheng@sifive.com>
Mon, 5 Oct 2020 06:01:04 +0000 (14:01 +0800)
committerKito Cheng <kito.cheng@sifive.com>
Fri, 6 Nov 2020 03:08:52 +0000 (11:08 +0800)
 - Disable kasan if target is unsupported and -fasan-shadow-offset= is not
   given, no matter `--param asan-stack=1` is given or not.

 - Moving KASAN option checking testcase to gcc.dg, those testcase could be
   useful for all other target which not support asan.

 - Verifed on riscv and x86.

gcc/ChangeLog:

PR target/96307
* toplev.c (process_options): Remove param_asan_stack checking for kasan
option checking.

gcc/testsuite/ChangeLog:

PR target/96307
* gcc.dg/pr96307.c: New.
* gcc.target/riscv/pr96260.c: Move this test case from here to ...
* gcc.dg/pr96260.c: ... here.
* gcc.target/riscv/pr91441.c: Move this test case from here to ...
* gcc.dg/pr91441.c: ... here.
* lib/target-supports.exp (check_effective_target_no_fsanitize_address):
New proc.

gcc/testsuite/gcc.dg/pr91441.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr96260.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr96307.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/pr91441.c [deleted file]
gcc/testsuite/gcc.target/riscv/pr96260.c [deleted file]
gcc/testsuite/lib/target-supports.exp
gcc/toplev.c

diff --git a/gcc/testsuite/gcc.dg/pr91441.c b/gcc/testsuite/gcc.dg/pr91441.c
new file mode 100644 (file)
index 0000000..4f7a8fb
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR target/91441 */
+/* { dg-do compile  } */
+/* { dg-require-effective-target no_fsanitize_address }*/
+/* { dg-options "--param asan-stack=1 -fsanitize=kernel-address" } */
+
+int *bar(int *);
+int *f( int a)
+{
+  return bar(&a);
+}
+/* { dg-warning ".'-fsanitize=kernel-address' with stack protection is not supported without '-fasan-shadow-offset=' for this target" "" { target *-*-* } 0 } */
diff --git a/gcc/testsuite/gcc.dg/pr96260.c b/gcc/testsuite/gcc.dg/pr96260.c
new file mode 100644 (file)
index 0000000..734832f
--- /dev/null
@@ -0,0 +1,10 @@
+/* PR target/96260 */
+/* { dg-do compile } */
+/* { dg-require-effective-target no_fsanitize_address }*/
+/* { dg-options "--param asan-stack=1 -fsanitize=kernel-address -fasan-shadow-offset=0x100000" } */
+
+int *bar(int *);
+int *f( int a)
+{
+  return bar(&a);
+}
diff --git a/gcc/testsuite/gcc.dg/pr96307.c b/gcc/testsuite/gcc.dg/pr96307.c
new file mode 100644 (file)
index 0000000..cd1c17c
--- /dev/null
@@ -0,0 +1,25 @@
+/* PR target/96307 */
+/* { dg-do compile } */
+/* { dg-require-effective-target no_fsanitize_address }*/
+/* { dg-additional-options "-fsanitize=kernel-address --param=asan-instrumentation-with-call-threshold=8" } */
+
+#include <limits.h>
+enum a {test1, test2, test3=INT_MAX};
+enum a a;
+enum a *b;
+
+void reset (void);
+
+void
+t()
+{
+  if (a != test2)
+    __builtin_abort ();
+  if (*b != test2)
+    __builtin_abort ();
+  reset ();
+  if (a != test1)
+    __builtin_abort ();
+  if (*b != test1)
+    __builtin_abort ();
+}
diff --git a/gcc/testsuite/gcc.target/riscv/pr91441.c b/gcc/testsuite/gcc.target/riscv/pr91441.c
deleted file mode 100644 (file)
index b55df5e..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-/* PR target/91441 */
-/* { dg-do compile  } */
-/* { dg-options "--param asan-stack=1 -fsanitize=kernel-address" } */
-
-int *bar(int *);
-int *f( int a)
-{
-  return bar(&a);
-}
-/* { dg-warning ".'-fsanitize=kernel-address' with stack protection is not supported without '-fasan-shadow-offset=' for this target" "" { target *-*-* } 0 } */
diff --git a/gcc/testsuite/gcc.target/riscv/pr96260.c b/gcc/testsuite/gcc.target/riscv/pr96260.c
deleted file mode 100644 (file)
index 229997f..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-/* PR target/96260 */
-/* { dg-do compile } */
-/* { dg-options "--param asan-stack=1 -fsanitize=kernel-address -fasan-shadow-offset=0x100000" } */
-
-int *bar(int *);
-int *f( int a)
-{
-  return bar(&a);
-}
index 8439720baea2fe61f1113f963493af9fb3f45679..08e96e12ee8fcb1853326f568aed8f20ab03ff86 100644 (file)
@@ -10582,3 +10582,14 @@ proc check_effective_target_movdir { } {
        }
     } "-mmovdiri -mmovdir64b" ]
 }
+
+# Return 1 if target is not support address sanitize, 1 otherwise.
+
+proc check_effective_target_no_fsanitize_address {} {
+    if ![check_no_compiler_messages fsanitize_address executable {
+       int main (void) { return 0; }
+    }] {
+       return 1;
+    }
+    return 0;
+}
index 20e231f4d2a47f142142832407541b9e70f13e81..e32dc285c1c95385ab6e841b9d54c0a8808b880c 100644 (file)
@@ -1843,7 +1843,6 @@ process_options (void)
 
   if ((flag_sanitize & SANITIZE_KERNEL_ADDRESS)
       && (targetm.asan_shadow_offset == NULL
-         && param_asan_stack
          && !asan_shadow_offset_set_p ()))
     {
       warning_at (UNKNOWN_LOCATION, 0,