[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / lsan / TestCases / Linux / dso-unknown.cpp
blobc3eede705fee8310fc0f97b230a6bfb4e1458465
1 // Build a library with origin tracking and an executable w/o origin tracking.
2 // Test that origin tracking is enabled at runtime.
3 // RUN: %clangxx_lsan -O0 %s -DBUILD_SO -fPIC -shared -o %t-so.so
4 // RUN: %clangxx_lsan -O0 %s -ldl -o %t && not %run %t 2>&1 | FileCheck %s
5 // RUN: %clangxx_lsan -O0 %s -ldl -o %t -DSUPPRESS_LEAK && %run %t
7 #ifdef BUILD_SO
9 # include <stdlib.h>
11 extern "C" {
12 void *my_alloc(unsigned sz) { return malloc(sz); }
13 } // extern "C"
15 #else // BUILD_SO
17 # include <assert.h>
18 # include <dlfcn.h>
19 # include <stdlib.h>
20 # include <string>
22 # ifdef SUPPRESS_LEAK
23 extern "C" const char *__lsan_default_suppressions() {
24 return "leak:^<unknown module>$";
26 # endif
28 int main(int argc, char **argv) {
30 std::string path = std::string(argv[0]) + "-so.so";
32 dlerror();
34 void *handle = dlopen(path.c_str(), RTLD_LAZY);
35 assert(handle != 0);
36 typedef void *(*fn)(unsigned sz);
37 fn my_alloc = (fn)dlsym(handle, "my_alloc");
39 for (int i = 0; i < 100; ++i)
40 my_alloc(i);
42 dlclose(handle);
43 return 0;
46 #endif // BUILD_SO
48 // CHECK: Direct leak