[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
This commit is contained in:
Evgeniy Stepanov 2014-12-24 16:58:50 +00:00
parent ced288f822
commit cb2f6d4314
2 changed files with 15 additions and 1 deletions

View File

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

View File

@ -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 <assert.h>
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
@ -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