From cb2f6d431426240bba285f5202d522e36c2e2e8d Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Wed, 24 Dec 2014 16:58:50 +0000 Subject: [PATCH] [asan] Support ASAN_ACTIVATION_OPTIONS. This is mostly useful for testing, as the only other way of specifying activation options (Android system property) is system-wide and affects concurrently running tests. llvm-svn: 224824 --- compiler-rt/lib/asan/asan_activation.cc | 6 ++++++ .../test/asan/TestCases/Posix/start-deactivated.cc | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/asan/asan_activation.cc b/compiler-rt/lib/asan/asan_activation.cc index 010cf319bda2..0aca1cb4e86d 100644 --- a/compiler-rt/lib/asan/asan_activation.cc +++ b/compiler-rt/lib/asan/asan_activation.cc @@ -39,6 +39,12 @@ static struct AsanDeactivatedFlags { // Check if activation flags need to be overriden. // FIXME: Add diagnostic to check that activation flags string doesn't // contain any other flags. + if (const char *env = GetEnv("ASAN_ACTIVATION_OPTIONS")) { + cf.ParseFromString(env); + ParseFlagsFromString(&f, env); + } + + // Override from getprop asan.options. char buf[100]; GetExtraActivationFlags(buf, sizeof(buf)); cf.ParseFromString(buf); diff --git a/compiler-rt/test/asan/TestCases/Posix/start-deactivated.cc b/compiler-rt/test/asan/TestCases/Posix/start-deactivated.cc index 2280e2af03f3..e5e83066b278 100644 --- a/compiler-rt/test/asan/TestCases/Posix/start-deactivated.cc +++ b/compiler-rt/test/asan/TestCases/Posix/start-deactivated.cc @@ -5,11 +5,13 @@ // RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so // RUN: %clangxx -O0 %s -c -o %t.o // RUN: %clangxx_asan -O0 %t.o %libdl -o %t -// RUN: ASAN_OPTIONS=start_deactivated=1 not %run %t 2>&1 | FileCheck %s +// RUN: ASAN_OPTIONS=start_deactivated=1,allocator_may_return_null=0 \ +// RUN: ASAN_ACTIVATION_OPTIONS=allocator_may_return_null=1 not %run %t 2>&1 | FileCheck %s // XFAIL: arm-linux-gnueabi // XFAIL: armv7l-unknown-linux-gnueabihf #if !defined(SHARED_LIB) +#include #include #include #include @@ -43,12 +45,18 @@ int main(int argc, char *argv[]) { test_malloc_shadow(); // CHECK: =5= + // After this line ASan is activated and starts detecting errors. void *fn = dlsym(dso, "do_another_bad_thing"); if (!fn) { fprintf(stderr, "dlsym failed: %s\n", dlerror()); return 1; } + // Test that ASAN_ACTIVATION_OPTIONS=allocator_may_return_null=1 has effect. + void *p = malloc((unsigned long)-2); + assert(!p); + // CHECK: WARNING: AddressSanitizer failed to allocate 0xfff{{.*}} bytes + ((Fn)fn)(); // CHECK: AddressSanitizer: heap-buffer-overflow // CHECK: READ of size 1