1// RUN: rm -rf %t-dir
2// RUN: mkdir %t-dir
3
4// RUN: %clangxx_tsan -O1 -fno-builtin %s -DLIB -fPIC -fno-sanitize=thread -shared -o %t-dir/libignore_lib1.so
5// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t-dir/executable
6// RUN: echo running w/o suppressions:
7// RUN: %deflake %run %t-dir/executable | FileCheck %s --check-prefix=CHECK-NOSUPP
8// RUN: echo running with suppressions:
9// RUN: %env_tsan_opts=suppressions='%s.supp' %run %t-dir/executable 2>&1 | FileCheck %s --check-prefix=CHECK-WITHSUPP
10
11// Tests that interceptors coming from a dynamically loaded library specified
12// in called_from_lib suppression are ignored.
13
14// REQUIRES: stable-runtime
15// UNSUPPORTED: target=powerpc64le{{.*}}
16// FIXME: This test regularly fails on powerpc64 LE possibly starting with
17// r279664. Re-enable the test once the problem(s) have been fixed.
18
19#ifndef LIB
20
21#include <dlfcn.h>
22#include <stdlib.h>
23#include <stdio.h>
24#include <errno.h>
25#include <libgen.h>
26#include <string>
27
28int main(int argc, char **argv) {
29 std::string lib = std::string(dirname(argv[0])) + "/libignore_lib1.so";
30 void *h = dlopen(lib.c_str(), RTLD_GLOBAL | RTLD_NOW);
31 if (h == 0)
32 exit(status: printf(format: "failed to load the library (%d)\n", errno));
33 void (*f)() = (void(*)())dlsym(handle: h, name: "libfunc");
34 if (f == 0)
35 exit(status: printf(format: "failed to find the func (%d)\n", errno));
36 f();
37}
38
39#else // #ifdef LIB
40
41#include "ignore_lib_lib.h"
42
43#endif // #ifdef LIB
44
45// CHECK-NOSUPP: WARNING: ThreadSanitizer: data race
46// CHECK-NOSUPP: OK
47
48// CHECK-WITHSUPP-NOT: WARNING: ThreadSanitizer: data race
49// CHECK-WITHSUPP: OK
50
51

source code of compiler-rt/test/tsan/ignore_lib1.cpp