1 // RUN: %clangxx_tsan -O1 %s -DBUILD_SO -fPIC -shared -o %t-so.so
2 // RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t && %run %t 2>&1 | FileCheck %s
4 // dl_iterate_phdr doesn't exist on OS X.
21 static int callback(struct dl_phdr_info
*info
, size_t size
, void *data
) {
22 if (info
->dlpi_name
[0] == '\0')
23 info
->dlpi_name
= "/proc/self/exe";
24 return !strcmp(info
->dlpi_name
, "non existent module");
27 void *thread(void *unused
) {
28 for (int i
= 0; i
< 1000; i
++) {
29 barrier_wait(&barrier
);
30 dl_iterate_phdr(callback
, 0);
35 int main(int argc
, char *argv
[]) {
36 barrier_init(&barrier
, 2);
37 std::string path
= std::string(argv
[0]) + std::string("-so.so");
39 pthread_create(&th
, 0, thread
, 0);
40 for (int i
= 0; i
< 1000; i
++) {
41 barrier_wait(&barrier
);
42 void *lib
= dlopen(path
.c_str(), RTLD_NOW
);
44 printf("error in dlopen: %s\n", dlerror());
50 fprintf(stderr
, "DONE\n");
56 // CHECK-NOT: WARNING: ThreadSanitizer: data race