diff mbox

[2/2] Libsanitizer merge from upstream r253555.

Message ID 5652C4CE.7020409@partner.samsung.com
State New
Headers show

Commit Message

max Nov. 23, 2015, 7:48 a.m. UTC
This patch reflects to corresponding compiler changes. In particular, it 
just enables -fsanitize-recover=address switch and migrates two small 
testcases from upstream. I don't backport other stress tests because 
they are heavy and have unstable output.

-Maxim

Comments

Jakub Jelinek Nov. 23, 2015, 8:19 a.m. UTC | #1
On Mon, Nov 23, 2015 at 10:48:30AM +0300, Maxim Ostapenko wrote:
> Index: gcc/testsuite/c-c++-common/asan/halt_on_error-1.c
> ===================================================================
> --- gcc/testsuite/c-c++-common/asan/halt_on_error-1.c	(revision 0)
> +++ gcc/testsuite/c-c++-common/asan/halt_on_error-1.c	(working copy)
> @@ -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, 11);

Please use ten + 1 instead of 11 here.
With -fsanitize=address, there will be padding immediately after the
variable, therefore otherwise (if the compiler does not see we are
running into undefined behavior) the testcase might be ok.

> --- gcc/testsuite/c-c++-common/asan/halt_on_error-2.c	(revision 0)
> +++ gcc/testsuite/c-c++-common/asan/halt_on_error-2.c	(working copy)
> @@ -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, 11);

Likewise.

Otherwise OK for trunk.

	Jakub
diff mbox

Patch

gcc/testsuite/ChangeLog:

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.

gcc/ChangeLog:

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.

Index: gcc/asan.c
===================================================================
--- gcc/asan.c	(revision 230597)
+++ gcc/asan.c	(working copy)
@@ -2533,10 +2533,12 @@ 
 {
   gimple *g = gsi_stmt (*iter);
   location_t loc = gimple_location (g);
+  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;
 
-  bool recover_p
-    = (flag_sanitize & 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);
   bool is_scalar_access = (flags & ASAN_CHECK_SCALAR_ACCESS) != 0;
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 230597)
+++ gcc/doc/invoke.texi	(working copy)
@@ -6111,8 +6111,10 @@ 
 
 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: gcc/opts.c
===================================================================
--- gcc/opts.c	(revision 230597)
+++ gcc/opts.c	(working copy)
@@ -941,11 +941,8 @@ 
 	      "-fsanitize=address and -fsanitize=kernel-address "
 	      "are incompatible with -fsanitize=thread");
 
-  /* Error recovery is not allowed for ASan and TSan.  */
+  /* Error recovery is not allowed for LSan and TSan.  */
 
-  if (opts->x_flag_sanitize_recover & SANITIZE_USER_ADDRESS)
-    error_at (loc, "-fsanitize-recover=address is not supported");
-
   if (opts->x_flag_sanitize_recover & SANITIZE_THREAD)
     error_at (loc, "-fsanitize-recover=thread is not supported");
 
Index: gcc/testsuite/c-c++-common/asan/halt_on_error-1.c
===================================================================
--- gcc/testsuite/c-c++-common/asan/halt_on_error-1.c	(revision 0)
+++ gcc/testsuite/c-c++-common/asan/halt_on_error-1.c	(working copy)
@@ -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, 11);
+  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).*" } */
Index: gcc/testsuite/c-c++-common/asan/halt_on_error-2.c
===================================================================
--- gcc/testsuite/c-c++-common/asan/halt_on_error-2.c	(revision 0)
+++ gcc/testsuite/c-c++-common/asan/halt_on_error-2.c	(working copy)
@@ -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, 11);
+  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).*" } */