[PATCH] [compiler-rt] Turn abort_on_error=1 by default on OS X (part 1/2)
Kuba Brecka
kuba.brecka at gmail.com
Tue Jan 27 17:32:25 PST 2015
> why can't you write `ASAN_FLAG(bool, abort_on_error, (SANITIZER_MAC == 1), "....")`
Updated.
> However, if you really want to override ASAN_OPTIONS to use "abort_on_error=true", this change might be OK, provided that you unconditionally overwrite ASAN_OPTIONS from config.environment with this value.
Updated.
Thanks for the suggestions!
http://reviews.llvm.org/D7203
Files:
lib/asan/asan_flags.inc
lib/asan/tests/asan_test_main.cc
test/asan/TestCases/Darwin/abort_on_error-darwin.cc
test/asan/TestCases/Linux/abort_on_error-linux.cc
test/asan/lit.cfg
Index: lib/asan/asan_flags.inc
===================================================================
--- lib/asan/asan_flags.inc
+++ lib/asan/asan_flags.inc
@@ -78,7 +78,7 @@
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 == 1),
"If set, the tool calls abort() instead of _exit() after printing the "
"error report.")
ASAN_FLAG(bool, print_stats, false,
Index: lib/asan/tests/asan_test_main.cc
===================================================================
--- lib/asan/tests/asan_test_main.cc
+++ lib/asan/tests/asan_test_main.cc
@@ -12,6 +12,15 @@
//===----------------------------------------------------------------------===//
#include "asan_test_utils.h"
+#if defined(__APPLE__)
+extern "C" {
+// On OS X, let's override abort_on_error=0 to make unit tests not abort().
+const char* __asan_default_options() {
+ return "abort_on_error=0";
+}
+} // extern "C"
+#endif
+
int main(int argc, char **argv) {
testing::GTEST_FLAG(death_test_style) = "threadsafe";
testing::InitGoogleTest(&argc, argv);
Index: test/asan/TestCases/Darwin/abort_on_error-darwin.cc
===================================================================
--- test/asan/TestCases/Darwin/abort_on_error-darwin.cc
+++ test/asan/TestCases/Darwin/abort_on_error-darwin.cc
@@ -0,0 +1,16 @@
+// 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-linux.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
+
+#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}}
+ // CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
+}
Index: test/asan/TestCases/Linux/abort_on_error-linux.cc
===================================================================
--- test/asan/TestCases/Linux/abort_on_error-linux.cc
+++ test/asan/TestCases/Linux/abort_on_error-linux.cc
@@ -0,0 +1,16 @@
+// 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-darwin.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
+
+#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}}
+ // CHECK: {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
+}
Index: test/asan/lit.cfg
===================================================================
--- test/asan/lit.cfg
+++ test/asan/lit.cfg
@@ -148,8 +148,12 @@
# Default test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']
+# Tests now inherit ASAN_OPTIONS, let's have it empty by default.
+config.environment["ASAN_OPTIONS"] = ""
+
if config.host_os == 'Darwin':
config.suffixes.append('.mm')
+ config.environment["ASAN_OPTIONS"] = "abort_on_error=0"
# AddressSanitizer tests are currently supported on Linux, Darwin and
# FreeBSD only.
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7203.18869.patch
Type: text/x-patch
Size: 3333 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150128/e49fdaef/attachment.bin>
More information about the llvm-commits
mailing list