1 | // 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 | // Fails with debug checks: https://bugs.llvm.org/show_bug.cgi?id=46862 |
5 | // XFAIL: !compiler-rt-optimized |
6 | |
7 | // RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so |
8 | // RUN: %clangxx -O0 %s -c -o %t.o |
9 | // RUN: %clangxx_asan -O0 %t.o %libdl -o %t |
10 | |
11 | // RUN: rm -f %t.asan.options.activation-options.cpp.tmp |
12 | // RUN: rm -f %t.asan.options.ABCDE |
13 | // RUN: echo "help=1" >%t.asan.options.activation-options.cpp.tmp |
14 | |
15 | // RUN: %env_asan_opts=start_deactivated=1 \ |
16 | // RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b %run %t 2>&1 | \ |
17 | // RUN: FileCheck %s --check-prefix=CHECK-HELP --check-prefix=CHECK-FOUND |
18 | |
19 | // RUN: %env_asan_opts=start_deactivated=1 \ |
20 | // RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options not %run %t 2>&1 | \ |
21 | // RUN: FileCheck %s --check-prefix=CHECK-NO-HELP --check-prefix=CHECK-MISSING |
22 | |
23 | // RUN: %env_asan_opts=start_deactivated=1 \ |
24 | // RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b not %run %t --fix-name 2>&1 | \ |
25 | // RUN: FileCheck %s --check-prefix=CHECK-NO-HELP --check-prefix=CHECK-MISSING |
26 | |
27 | // RUN: echo "help=1" >%t.asan.options.ABCDE |
28 | |
29 | // RUN: %env_asan_opts=start_deactivated=1 \ |
30 | // RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b %run %t --fix-name 2>&1 | \ |
31 | // RUN: FileCheck %s --check-prefix=CHECK-HELP --check-prefix=CHECK-FOUND |
32 | |
33 | // XFAIL: android |
34 | |
35 | #if !defined(SHARED_LIB) |
36 | #include <assert.h> |
37 | #include <dlfcn.h> |
38 | #include <stdio.h> |
39 | #include <stdlib.h> |
40 | #include <string.h> |
41 | #include <unistd.h> |
42 | |
43 | #include <string> |
44 | |
45 | #include "sanitizer/asan_interface.h" |
46 | |
47 | typedef void (*Fn)(); |
48 | |
49 | int main(int argc, char *argv[]) { |
50 | std::string path = std::string(argv[0]) + "-so.so" ; |
51 | |
52 | if (argc > 1 && strcmp(s1: argv[1], s2: "--fix-name" ) == 0) { |
53 | assert(strlen(argv[0]) > 5); |
54 | strcpy(dest: argv[0], src: "ABCDE" ); |
55 | } |
56 | |
57 | void *dso = dlopen(file: path.c_str(), RTLD_NOW); |
58 | if (!dso) { |
59 | fprintf(stderr, format: "dlopen failed: %s\n" , dlerror()); |
60 | return 1; |
61 | } |
62 | |
63 | return 0; |
64 | } |
65 | #else // SHARED_LIB |
66 | // Empty: all we need is an ASan shared library constructor. |
67 | #endif // SHARED_LIB |
68 | |
69 | // CHECK-HELP: Available flags for {{.*}}Sanitizer: |
70 | // CHECK-NO-HELP-NOT: Available flags for {{.*}}Sanitizer: |
71 | // CHECK-FOUND-NOT: Failed to read options |
72 | // CHECK-MISSING: Failed to read options |
73 | |