[compiler-rt] r243418 - [asan] Set abort_on_error=1 by default on OS X
Kuba Brecka
kuba.brecka at gmail.com
Tue Jul 28 07:34:13 PDT 2015
Author: kuba.brecka
Date: Tue Jul 28 09:34:13 2015
New Revision: 243418
URL: http://llvm.org/viewvc/llvm-project?rev=243418&view=rev
Log:
[asan] Set abort_on_error=1 by default on OS X
This sets the default ASan flags to abort_on_error=1 on OS X. For unit tests and lit tests we set ASAN_OPTIONS back to abort_on_error=0 before running the tests (to avoid crashing). I added two tests that intentionally don't respect the default ASAN_OPTIONS to test the behavior of an empty ASAN_OPTIONS (on OS X we should crash, on Linux we should exit()).
Differential Revision: http://reviews.llvm.org/D7203
Added:
compiler-rt/trunk/test/asan/TestCases/Darwin/abort_on_error.cc
compiler-rt/trunk/test/asan/TestCases/Linux/abort_on_error.cc
Modified:
compiler-rt/trunk/lib/asan/asan_flags.inc
compiler-rt/trunk/lib/asan/tests/asan_test_main.cc
compiler-rt/trunk/test/asan/lit.cfg
Modified: compiler-rt/trunk/lib/asan/asan_flags.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_flags.inc?rev=243418&r1=243417&r2=243418&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_flags.inc (original)
+++ compiler-rt/trunk/lib/asan/asan_flags.inc Tue Jul 28 09:34:13 2015
@@ -78,7 +78,7 @@ ASAN_FLAG(bool, check_malloc_usable_size
ASAN_FLAG(bool, unmap_shadow_on_exit, false,
"If set, explicitly unmaps the (huge) shadow at exit.")
ASAN_FLAG(
- bool, abort_on_error, false,
+ bool, abort_on_error, SANITIZER_MAC,
"If set, the tool calls abort() instead of _exit() after printing the "
"error report.")
ASAN_FLAG(bool, print_stats, false,
Modified: compiler-rt/trunk/lib/asan/tests/asan_test_main.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_test_main.cc?rev=243418&r1=243417&r2=243418&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_test_main.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_test_main.cc Tue Jul 28 09:34:13 2015
@@ -11,11 +11,18 @@
//
//===----------------------------------------------------------------------===//
#include "asan_test_utils.h"
+#include "sanitizer_common/sanitizer_platform.h"
// Default ASAN_OPTIONS for the unit tests. Let's turn symbolication off to
// speed up testing (unit tests don't use it anyway).
extern "C" const char* __asan_default_options() {
+#if SANITIZER_MAC
+ // On Darwin, we default to `abort_on_error=1`, which would make tests run
+ // much slower. Let's override this and run lit tests with 'abort_on_error=0'.
+ return "symbolize=false:abort_on_error=0";
+#else
return "symbolize=false";
+#endif
}
int main(int argc, char **argv) {
Added: compiler-rt/trunk/test/asan/TestCases/Darwin/abort_on_error.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Darwin/abort_on_error.cc?rev=243418&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Darwin/abort_on_error.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Darwin/abort_on_error.cc Tue Jul 28 09:34:13 2015
@@ -0,0 +1,17 @@
+// Check that with empty ASAN_OPTIONS, ASan reports on OS X actually crash
+// the process (abort_on_error=1). See also Linux/abort_on_error.cc.
+
+// RUN: %clangxx_asan %s -o %t
+
+// Intentionally don't inherit the default ASAN_OPTIONS.
+// RUN: ASAN_OPTIONS="" not --crash %run %t 2>&1 | FileCheck %s
+// When we use lit's default ASAN_OPTIONS, we shouldn't crash.
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+#include <stdlib.h>
+int main() {
+ char *x = (char*)malloc(10 * sizeof(char));
+ free(x);
+ return x[5];
+ // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
+}
Added: compiler-rt/trunk/test/asan/TestCases/Linux/abort_on_error.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/abort_on_error.cc?rev=243418&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/abort_on_error.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/abort_on_error.cc Tue Jul 28 09:34:13 2015
@@ -0,0 +1,18 @@
+// Check that with empty ASAN_OPTIONS, ASan reports on Linux don't crash
+// the process (abort_on_error=0). See also Darwin/abort_on_error.cc.
+
+// RUN: %clangxx_asan %s -o %t
+
+// Intentionally don't inherit the default ASAN_OPTIONS.
+// RUN: ASAN_OPTIONS="" not run %t 2>&1 | FileCheck %s
+// When we use lit's default ASAN_OPTIONS, we shouldn't crash either. On Linux
+// lit doesn't set ASAN_OPTIONS anyway.
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+#include <stdlib.h>
+int main() {
+ char *x = (char*)malloc(10 * sizeof(char));
+ free(x);
+ return x[5];
+ // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
+}
Modified: compiler-rt/trunk/test/asan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/lit.cfg?rev=243418&r1=243417&r2=243418&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/lit.cfg (original)
+++ compiler-rt/trunk/test/asan/lit.cfg Tue Jul 28 09:34:13 2015
@@ -29,8 +29,11 @@ def push_dynamic_library_lookup_path(con
# Setup config name.
config.name = 'AddressSanitizer' + config.name_suffix
-# Setup default ASAN_OPTIONS
-config.environment['ASAN_OPTIONS'] = 'symbolize_vs_style=false'
+# Platform-specific default ASAN_OPTIONS for lit tests.
+if config.host_os == 'Darwin':
+ # On Darwin, we default to `abort_on_error=1`, which would make tests run
+ # much slower. Let's override this and run lit tests with 'abort_on_error=0'.
+ config.environment['ASAN_OPTIONS'] = 'abort_on_error=0'
# testFormat: The test format to use to interpret tests.
external_bash = (not sys.platform in ['win32'])
More information about the llvm-commits
mailing list