blob: 1a1ad3f8c4991468c835cb5414f1aa5c33a248de [file] [log] [blame]
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08001// Test for ASAN_OPTIONS=start_deactivated=1 mode.
2// Main executable is uninstrumented, but linked to ASan runtime. The shared
3// library is instrumented.
4
5// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so
6// RUN: %clangxx -O0 %s -c -o %t.o
7// RUN: %clangxx_asan -O0 %t.o %libdl -o %t
8
9// RUN: rm -f %t.asan.options.activation-options.cc.tmp
10// RUN: rm -f %t.asan.options.ABCDE
11// RUN: echo "help=1" >%t.asan.options.activation-options.cc.tmp
12
13// RUN: %env_asan_opts=start_deactivated=1 \
14// RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b %run %t 2>&1 | \
15// RUN: FileCheck %s --check-prefix=CHECK-HELP --check-prefix=CHECK-FOUND
16
17// RUN: %env_asan_opts=start_deactivated=1 \
18// RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options not %run %t 2>&1 | \
19// RUN: FileCheck %s --check-prefix=CHECK-NO-HELP --check-prefix=CHECK-MISSING
20
21// RUN: %env_asan_opts=start_deactivated=1 \
22// RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b not %run %t --fix-name 2>&1 | \
23// RUN: FileCheck %s --check-prefix=CHECK-NO-HELP --check-prefix=CHECK-MISSING
24
25// RUN: echo "help=1" >%t.asan.options.ABCDE
26
27// RUN: %env_asan_opts=start_deactivated=1 \
28// RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b %run %t --fix-name 2>&1 | \
29// RUN: FileCheck %s --check-prefix=CHECK-HELP --check-prefix=CHECK-FOUND
30
31// XFAIL: arm-linux-gnueabi
32// XFAIL: android
33
34#if !defined(SHARED_LIB)
35#include <assert.h>
36#include <dlfcn.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40#include <unistd.h>
41
42#include <string>
43
44#include "sanitizer/asan_interface.h"
45
46typedef void (*Fn)();
47
48int main(int argc, char *argv[]) {
49 std::string path = std::string(argv[0]) + "-so.so";
50
51 if (argc > 1 && strcmp(argv[1], "--fix-name") == 0) {
52 assert(strlen(argv[0]) > 5);
53 strcpy(argv[0], "ABCDE");
54 }
55
56 void *dso = dlopen(path.c_str(), RTLD_NOW);
57 if (!dso) {
58 fprintf(stderr, "dlopen failed: %s\n", dlerror());
59 return 1;
60 }
61
62 return 0;
63}
64#else // SHARED_LIB
65// Empty: all we need is an ASan shared library constructor.
66#endif // SHARED_LIB
67
68// CHECK-HELP: Available flags for {{.*}}Sanitizer:
69// CHECK-NO-HELP-NOT: Available flags for {{.*}}Sanitizer:
70// CHECK-FOUND-NOT: Failed to read options
71// CHECK-MISSING: Failed to read options