Home | History | Annotate | Download | only in lit_tests
      1 // Check that if the list of shared libraries changes between the two race
      2 // reports, the second report occurring in a new shared library is still
      3 // symbolized correctly.
      4 
      5 // RUN: %clangxx_tsan -O1 %p/SharedLibs/load_shared_lib-so.cc \
      6 // RUN:     -fPIC -shared -o %t-so.so
      7 // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s
      8 
      9 #include <dlfcn.h>
     10 #include <pthread.h>
     11 #include <stdio.h>
     12 
     13 #include <string>
     14 
     15 int GLOB = 0;
     16 
     17 void *write_glob(void *unused) {
     18   GLOB++;
     19   return NULL;
     20 }
     21 
     22 void race_two_threads(void *(*access_callback)(void *unused)) {
     23   pthread_t t1, t2;
     24   pthread_create(&t1, NULL, access_callback, NULL);
     25   pthread_create(&t2, NULL, access_callback, NULL);
     26   pthread_join(t1, NULL);
     27   pthread_join(t2, NULL);
     28 }
     29 
     30 int main(int argc, char *argv[]) {
     31   std::string path = std::string(argv[0]) + std::string("-so.so");
     32   race_two_threads(write_glob);
     33   // CHECK: write_glob
     34   void *lib = dlopen(path.c_str(), RTLD_NOW);
     35     if (!lib) {
     36     printf("error in dlopen(): %s\n", dlerror());
     37     return 1;
     38   }
     39   void *(*write_from_so)(void *unused);
     40   *(void **)&write_from_so = dlsym(lib, "write_from_so");
     41   race_two_threads(write_from_so);
     42   // CHECK: write_from_so
     43   return 0;
     44 }
     45