Index: openmp/tools/archer/ompt-tsan.cpp =================================================================== --- openmp/tools/archer/ompt-tsan.cpp +++ openmp/tools/archer/ompt-tsan.cpp @@ -148,49 +148,20 @@ // tsan detects these exact functions by name. extern "C" { #if (defined __APPLE__ && defined __MACH__) -static void AnnotateHappensAfter(const char *file, int line, - const volatile void *cv) { - void (*fptr)(const char *, int, const volatile void *); +static void (*AnnotateHappensAfter)(const char *, int, const volatile void *); +static void (*AnnotateHappensBefore)(const char *, int, const volatile void *); +static void (*AnnotateIgnoreWritesBegin)(const char *, int); +static void (*AnnotateIgnoreWritesEnd)(const char *, int); +static void (*AnnotateNewMemory)(const char *, int, const volatile void *, + size_t); +static void (*__tsan_func_entry)(const void *); +static void (*__tsan_func_exit)(void); - fptr = (void (*)(const char *, int, const volatile void *))dlsym( - RTLD_DEFAULT, "AnnotateHappensAfter"); - (*fptr)(file, line, cv); -} -static void AnnotateHappensBefore(const char *file, int line, - const volatile void *cv) { - void (*fptr)(const char *, int, const volatile void *); - - fptr = (void (*)(const char *, int, const volatile void *))dlsym( - RTLD_DEFAULT, "AnnotateHappensBefore"); - (*fptr)(file, line, cv); -} -static void AnnotateIgnoreWritesBegin(const char *file, int line) { - void (*fptr)(const char *, int); - - fptr = (void (*)(const char *, int))dlsym(RTLD_DEFAULT, - "AnnotateIgnoreWritesBegin"); - (*fptr)(file, line); -} -static void AnnotateIgnoreWritesEnd(const char *file, int line) { - void (*fptr)(const char *, int); - - fptr = (void (*)(const char *, int))dlsym(RTLD_DEFAULT, - "AnnotateIgnoreWritesEnd"); - (*fptr)(file, line); -} -static void AnnotateNewMemory(const char *file, int line, - const volatile void *cv, size_t size) { - void (*fptr)(const char *, int, const volatile void *, size_t); - - fptr = (void (*)(const char *, int, const volatile void *, size_t))dlsym( - RTLD_DEFAULT, "AnnotateNewMemory"); - (*fptr)(file, line, cv, size); -} static int RunningOnValgrind() { int (*fptr)(); fptr = (int (*)())dlsym(RTLD_DEFAULT, "RunningOnValgrind"); - if (fptr && fptr != RunningOnValgrind) + if (!fptr || fptr == RunningOnValgrind) runOnTsan = 0; return 0; } @@ -1043,6 +1014,24 @@ exit(1); } +#if (defined __APPLE__ && defined __MACH__) +#define findTsanFunction(f, fSig) \ + if (NULL == (f = fSig dlsym(RTLD_DEFAULT, #f))) \ + printf("Unable to find TSan function " #f ".\n") + + findTsanFunction(AnnotateHappensAfter, + (void (*)(const char *, int, const volatile void *))); + findTsanFunction(AnnotateHappensBefore, + (void (*)(const char *, int, const volatile void *))); + findTsanFunction(AnnotateIgnoreWritesBegin, (void (*)(const char *, int))); + findTsanFunction(AnnotateIgnoreWritesEnd, (void (*)(const char *, int))); + findTsanFunction( + AnnotateNewMemory, + (void (*)(const char *, int, const volatile void *, size_t))); + findTsanFunction(__tsan_func_entry, (void (*)(const void *))); + findTsanFunction(__tsan_func_exit, (void (*)(void))); +#endif + SET_CALLBACK(thread_begin); SET_CALLBACK(thread_end); SET_CALLBACK(parallel_begin); @@ -1066,6 +1055,7 @@ "to avoid false positive reports from the OpenMP runtime!\n"); if (archer_flags->ignore_serial) TsanIgnoreWritesBegin(); + return 1; // success }