1 // RUN: rm -rf %t-dir
2 // RUN: mkdir %t-dir
3 
4 // RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %t-dir/libignore_lib3.so
5 // RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t-dir/executable
6 // RUN: %env_tsan_opts=suppressions='%s.supp' %deflake %run %t-dir/executable | FileCheck %s
7 
8 // Tests that unloading of a library matched against called_from_lib suppression
9 // causes program crash (this is not supported).
10 
11 // Some aarch64 kernels do not support non executable write pages
12 // REQUIRES: stable-runtime
13 
14 #ifndef LIB
15 
16 #include <dlfcn.h>
17 #include <stdlib.h>
18 #include <stdio.h>
19 #include <errno.h>
20 #include <libgen.h>
21 #include <string>
22 
main(int argc,char ** argv)23 int main(int argc, char **argv) {
24   std::string lib = std::string(dirname(argv[0])) + "/libignore_lib3.so";
25   void *h = dlopen(lib.c_str(), RTLD_GLOBAL | RTLD_NOW);
26   dlclose(h);
27   fprintf(stderr, "OK\n");
28 }
29 
30 #else  // #ifdef LIB
31 
libfunc()32 extern "C" void libfunc() {
33 }
34 
35 #endif  // #ifdef LIB
36 
37 // CHECK: ThreadSanitizer: library {{.*}} that was matched against called_from_lib suppression 'ignore_lib3.so' is unloaded
38 // CHECK-NOT: OK
39 
40