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
11 // REQUIRES: stable-runtime
12 // UNSUPPORTED: target=powerpc64le{{.*}}
13 // FIXME: This test occasionally fails on powerpc64 LE possibly starting with
14 // r279664. Re-enable the test once the problem(s) have been fixed.
16 // Previously the test episodically failed with:
17 // ThreadSanitizer: called_from_lib suppression '/libignore_lib1.so$' is
18 // matched against 2 libraries: '/libignore_lib1.so' and '/libignore_lib1.so'
19 // This was caused by non-atomicity of reading of /proc/self/maps.
21 // ReadProcMaps() on NetBSD does not handle >=1MB of memory layout information
22 // UNSUPPORTED: target={{.*netbsd.*}}
40 # define TSAN_MAP_ANON MAP_ANON
42 # define TSAN_MAP_ANON MAP_ANONYMOUS
45 void *thr(void *arg
) {
46 // This thread creates lots of separate mappings in /proc/self/maps before
47 // the ignored library.
48 for (int i
= 0; i
< 10000; i
++) {
50 barrier_wait(&barrier
);
51 mmap(0, 4096, PROT_READ
, TSAN_MAP_ANON
| MAP_PRIVATE
| MAP_32BIT
, -1 , 0);
52 mmap(0, 4096, PROT_WRITE
, TSAN_MAP_ANON
| MAP_PRIVATE
| MAP_32BIT
, -1 , 0);
57 int main(int argc
, char **argv
) {
58 barrier_init(&barrier
, 2);
60 pthread_create(&th
, 0, thr
, 0);
61 barrier_wait(&barrier
);
62 std::string lib
= std::string(dirname(argv
[0])) + "/libignore_lib1.so";
63 void *h
= dlopen(lib
.c_str(), RTLD_GLOBAL
| RTLD_NOW
);
65 exit(printf("failed to load the library (%d)\n", errno
));
66 void (*f
)() = (void(*)())dlsym(h
, "libfunc");
68 exit(printf("failed to find the func (%d)\n", errno
));
75 #include "ignore_lib_lib.h"
79 // CHECK-NOSUPP: WARNING: ThreadSanitizer: data race
82 // CHECK-WITHSUPP-NOT: WARNING: ThreadSanitizer: data race