Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / Linux / activation-options.cpp
blob59c4d5c46e771399ba3fa178c04634d63b33ac9d
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
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
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
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
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
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
27 // RUN: echo "help=1" >%t.asan.options.ABCDE
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
33 // XFAIL: android
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>
43 #include <string>
45 #include "sanitizer/asan_interface.h"
47 typedef void (*Fn)();
49 int main(int argc, char *argv[]) {
50 std::string path = std::string(argv[0]) + "-so.so";
52 if (argc > 1 && strcmp(argv[1], "--fix-name") == 0) {
53 assert(strlen(argv[0]) > 5);
54 strcpy(argv[0], "ABCDE");
57 void *dso = dlopen(path.c_str(), RTLD_NOW);
58 if (!dso) {
59 fprintf(stderr, "dlopen failed: %s\n", dlerror());
60 return 1;
63 return 0;
65 #else // SHARED_LIB
66 // Empty: all we need is an ASan shared library constructor.
67 #endif // SHARED_LIB
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