[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

llvm-svn: 243418
This commit is contained in:
Kuba Brecka 2015-07-28 14:34:13 +00:00
parent 918f8ab7c6
commit 873855e291
5 changed files with 48 additions and 3 deletions

View File

@ -78,7 +78,7 @@ ASAN_FLAG(bool, check_malloc_usable_size, true,
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,

View File

@ -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) {

View File

@ -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}}
}

View File

@ -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}}
}

View File

@ -29,8 +29,11 @@ def push_dynamic_library_lookup_path(config, new_path):
# 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'])