PR target/91441 - Turn off -fsanitize=kernel-address if TARGET_ASAN_SHADOW_OFFSET...
authorKito Cheng <kito.cheng@sifive.com>
Mon, 19 Aug 2019 03:21:44 +0000 (03:21 +0000)
committerKito Cheng <kito@gcc.gnu.org>
Mon, 19 Aug 2019 03:21:44 +0000 (03:21 +0000)
 - -fsanitize=kernel-address will call targetm.asan_shadow_offset ()
   at asan_shadow_offset, so it will crash if TARGET_ASAN_SHADOW_OFFSET
   is not implemented, that's mean -fsanitize=kernel-address is not
   supported for target without TARGET_ASAN_SHADOW_OFFSET implementation.

gcc/ChangeLog:

PR target/91441
* toplev.c (process_options): Check TARGET_ASAN_SHADOW_OFFSET is
implemented for -fsanitize=kernel-address, and merge check logic
with -fsanitize=address.

testsuite/ChangeLog:

PR target/91441
* gcc.target/riscv/pr91441.c: New.

From-SVN: r274631

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/riscv/pr91441.c [new file with mode: 0644]
gcc/toplev.c

index bf0dbe0fb16cc6659409ceafc21af599b26da59f..fb32bb1c308ac5fbad7901889e569ef4849c0a6a 100644 (file)
@@ -1,3 +1,10 @@
+2019-08-19  Kito Cheng  <kito.cheng@sifive.com>
+
+       PR target/91441
+       * toplev.c (process_options): Check TARGET_ASAN_SHADOW_OFFSET is
+       implemented for -fsanitize=kernel-address, and merge check logic
+       with -fsanitize=address.
+
 2019-08-18  Iain Sandoe  <iain@sandoe.co.uk>
 
        * config/rs6000/darwin.h (TARGET_OS_CPP_BUILTINS): Add asserts
index dc44897e743bbc7895ae426d4e53af0cd4166fee..96f259e5688a69668a3006b0fefaa50a9dbeefbe 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-19  Kito Cheng  <kito.cheng@sifive.com>
+
+       PR target/91441
+       * gcc.target/riscv/pr91441.c: New.
+
 2019-08-18  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/91485
diff --git a/gcc/testsuite/gcc.target/riscv/pr91441.c b/gcc/testsuite/gcc.target/riscv/pr91441.c
new file mode 100644 (file)
index 0000000..593a297
--- /dev/null
@@ -0,0 +1,10 @@
+/* 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=address' and '-fsanitize=kernel-address' are not supported for this target" "" { target *-*-* } 0 } */
index 7e0b9216dea6c3c7e18261ea36ae2bc66c52f459..ddbb8b4943687e8d371fc97b2f65524988b9aeb9 100644 (file)
@@ -1744,7 +1744,7 @@ process_options (void)
   /* Address Sanitizer needs porting to each target architecture.  */
 
   if ((flag_sanitize & SANITIZE_ADDRESS)
-      && !FRAME_GROWS_DOWNWARD)
+      && (!FRAME_GROWS_DOWNWARD || targetm.asan_shadow_offset == NULL))
     {
       warning_at (UNKNOWN_LOCATION, 0,
                  "%<-fsanitize=address%> and %<-fsanitize=kernel-address%> "
@@ -1752,14 +1752,6 @@ process_options (void)
       flag_sanitize &= ~SANITIZE_ADDRESS;
     }
 
-  if ((flag_sanitize & SANITIZE_USER_ADDRESS)
-      && targetm.asan_shadow_offset == NULL)
-    {
-      warning_at (UNKNOWN_LOCATION, 0,
-                 "%<-fsanitize=address%> not supported for this target");
-      flag_sanitize &= ~SANITIZE_ADDRESS;
-    }
-
  /* Do not use IPA optimizations for register allocation if profiler is active
     or patchable function entries are inserted for run-time instrumentation
     or port does not emit prologue and epilogue as RTL.  */