[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 10:57:07 PST 2015


Based on the recent discussion at https://groups.google.com/forum/#!topic/address-sanitizer/FGYgD_P_884 about what the default setting for abort_on_error should be, this patch is a change for OS X only and it makes abort_on_error=1 by default there. The benefit of this is that crashlogs are generated when an issue is reported. This is especially important for GUI apps, where you otherwise have no indication of a problem (currently the program just exits, which is just weird). On OS X, there are also other situation where users usually don't see stderr, e.g. background processes, and you could be completely unaware that ASan found an issue.

This sets `ASAN_DEFAULT_OPTIONS` to `abort_on_error=1` on OS X, which also means that the test suite needs to be modified accordingly. On OS X, the lit configuration is changed to set ASAN_OPTIONS back to `abort_on_error=0` before running the tests, and the individual test cases are changed to respect the default ASAN_OPTIONS environment variable and only append to it. 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()).

This is part 1 of the patch, I splitted the patch to be more readable. The second part contains modifications of existing tests.

http://reviews.llvm.org/D7203

Files:
  lib/asan/asan_flags.h
  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.h
===================================================================
--- lib/asan/asan_flags.h
+++ lib/asan/asan_flags.h
@@ -27,6 +27,10 @@
 // 4) overriden from env variable ASAN_OPTIONS.
 // 5) overriden during ASan activation (for now used on Android only).
 
+#if SANITIZER_MAC
+#define ASAN_DEFAULT_OPTIONS abort_on_error=1
+#endif
+
 namespace __asan {
 
 struct Flags {
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
@@ -150,6 +150,7 @@
 
 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.18828.patch
Type: text/x-patch
Size: 2379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150127/1fbe186c/attachment.bin>


More information about the llvm-commits mailing list