libsanitizer merge from upstream r253555, compiler part.
authorMax Ostapenko <m.ostapenko@partner.samsung.com>
Mon, 23 Nov 2015 09:15:13 +0000 (11:15 +0200)
committerMaxim Ostapenko <chefmax@gcc.gnu.org>
Mon, 23 Nov 2015 09:15:13 +0000 (11:15 +0200)
gcc/

* opts.c (finish_options): Allow -fsanitize-recover=address for
userspace sanitization.
* asan.c (asan_expand_check_ifn): Redefine recover_p.
* doc/invoke.texi (fsanitize-recover): Update documentation.

gcc/testsuite/

* c-c++-common/asan/halt_on_error-1.c: New test.
* c-c++-common/asan/halt_on_error-2.c: Likewise.

From-SVN: r230741

gcc/ChangeLog
gcc/asan.c
gcc/doc/invoke.texi
gcc/opts.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/asan/halt_on_error-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/asan/halt_on_error-2.c [new file with mode: 0644]

index 7b0545f33d779f2714cc2fd9922a7f02758a49a7..16bb1aa32211c9e1cb40d55b41a8d57aa1ec602b 100644 (file)
@@ -1,3 +1,10 @@
+2015-11-23  Maxim Ostapenko  <m.ostapenko@partner.samsung.com>
+
+       * opts.c (finish_options): Allow -fsanitize-recover=address for
+       userspace sanitization.
+       * asan.c (asan_expand_check_ifn): Redefine recover_p.
+       * doc/invoke.texi (fsanitize-recover): Update documentation.
+
 2015-11-23  Tom de Vries  <tom@codesourcery.com>
 
        * omp-low.c (build_receiver_ref): Mark by_ref mem_ref as non-trapping.
index 0df5e3234b5d7f3d6ebbef291fcffa0f93b85dc9..6d9a8030fa2ff6fd3360233287900c97571dafbe 100644 (file)
@@ -2533,9 +2533,11 @@ asan_expand_check_ifn (gimple_stmt_iterator *iter, bool use_calls)
 {
   gimple *g = gsi_stmt (*iter);
   location_t loc = gimple_location (g);
-
-  bool recover_p
-    = (flag_sanitize & flag_sanitize_recover & SANITIZE_KERNEL_ADDRESS) != 0;
+  bool recover_p;
+  if (flag_sanitize & SANITIZE_USER_ADDRESS)
+    recover_p = (flag_sanitize_recover & SANITIZE_USER_ADDRESS) != 0;
+  else
+    recover_p = (flag_sanitize_recover & SANITIZE_KERNEL_ADDRESS) != 0;
 
   HOST_WIDE_INT flags = tree_to_shwi (gimple_call_arg (g, 0));
   gcc_assert (flags < ASAN_CHECK_LAST);
index 7cef176fdc989c481186bf190ffd83b4dd855376..53f1fe2a9a60384a89d74b165f6742c3cecaa127 100644 (file)
@@ -6111,8 +6111,10 @@ and program then exits with a non-zero exit code.
 
 Currently this feature only works for @option{-fsanitize=undefined} (and its suboptions
 except for @option{-fsanitize=unreachable} and @option{-fsanitize=return}),
-@option{-fsanitize=float-cast-overflow}, @option{-fsanitize=float-divide-by-zero} and
-@option{-fsanitize=kernel-address}.  For these sanitizers error recovery is turned on by default.
+@option{-fsanitize=float-cast-overflow}, @option{-fsanitize=float-divide-by-zero},
+@option{-fsanitize=kernel-address} and @option{-fsanitize=address}.
+For these sanitizers error recovery is turned on by default, except @option{-fsanitize=address},
+for which this feature is experimental.
 @option{-fsanitize-recover=all} and @option{-fno-sanitize-recover=all} is also
 accepted, the former enables recovery for all sanitizers that support it,
 the latter disables recovery for all sanitizers that support it.
index 4345cc886edcf1f8b85703591c4e314c9b9b828c..874c84fec5b07b3c09515a9e33b10226aeeb2b48 100644 (file)
@@ -941,10 +941,7 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
              "-fsanitize=address and -fsanitize=kernel-address "
              "are incompatible with -fsanitize=thread");
 
-  /* Error recovery is not allowed for ASan and TSan.  */
-
-  if (opts->x_flag_sanitize_recover & SANITIZE_USER_ADDRESS)
-    error_at (loc, "-fsanitize-recover=address is not supported");
+  /* Error recovery is not allowed for LSan and TSan.  */
 
   if (opts->x_flag_sanitize_recover & SANITIZE_THREAD)
     error_at (loc, "-fsanitize-recover=thread is not supported");
index 939520f8596909b47f23cebaad880bc009a50b15..8781283f6060ee742f1bf698ad71d8de533ce97c 100644 (file)
@@ -1,3 +1,8 @@
+2015-11-23  Maxim Ostapenko  <m.ostapenko@partner.samsung.com>
+
+       * c-c++-common/asan/halt_on_error-1.c: New test.
+       * c-c++-common/asan/halt_on_error-2.c: Likewise.
+
 2015-11-23  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/68482
diff --git a/gcc/testsuite/c-c++-common/asan/halt_on_error-1.c b/gcc/testsuite/c-c++-common/asan/halt_on_error-1.c
new file mode 100644 (file)
index 0000000..b015e96
--- /dev/null
@@ -0,0 +1,23 @@
+/* Test recovery mode.  */
+/* { dg-do run } */
+/* { dg-options "-fsanitize-recover=address" } */
+/* { dg-set-target-env-var ASAN_OPTIONS "halt_on_error=false" } */
+
+#include <string.h>
+
+volatile int ten = 10;
+
+int main() {
+  char x[10];
+  memset(x, 0, ten + 1);
+  asm volatile ("" : : : "memory");
+  volatile int res = x[ten];
+  x[ten] = res + 3;
+  res = x[ten];
+  return 0;
+}
+
+/* { dg-output "WRITE of size 11 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r).*" } */
+/* { dg-output "\[^\n\r]*READ of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r).*" } */
+/* { dg-output "\[^\n\r]*WRITE of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r).*" } */
+/* { dg-output "\[^\n\r]*READ of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r).*" } */
diff --git a/gcc/testsuite/c-c++-common/asan/halt_on_error-2.c b/gcc/testsuite/c-c++-common/asan/halt_on_error-2.c
new file mode 100644 (file)
index 0000000..4527889
--- /dev/null
@@ -0,0 +1,24 @@
+/* Test recovery mode.  */
+/* { dg-do run } */
+/* { dg-options "-fsanitize-recover=address" } */
+/* { dg-set-target-env-var ASAN_OPTIONS "halt_on_error=true" } */
+/* { dg-shouldfail "asan" } */
+
+#include <string.h>
+
+volatile int ten = 10;
+
+int main() {
+  char x[10];
+  memset(x, 0, ten + 1);
+  asm volatile ("" : : : "memory");
+  volatile int res = x[ten];
+  x[ten] = res + 3;
+  res = x[ten];
+  return 0;
+}
+
+/* { dg-output "WRITE of size 11 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r).*" } */
+/* { dg-prune-output "\[^\n\r]*READ of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r).*" } */
+/* { dg-prune-output "\[^\n\r]*WRITE of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r).*" } */
+/* { dg-prune-output "\[^\n\r]*READ of size 1 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r).*" } */