[Openmp-commits] [PATCH] D103607: [OpenMP][Tools] Fix Archer for MACOS

Joachim Protze via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Jun 3 03:29:39 PDT 2021


protze.joachim created this revision.
protze.joachim added a reviewer: Hahnfeld.
protze.joachim added a project: OpenMP.
Herald added subscribers: guansong, yaxunl.
protze.joachim requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Archer uses weak symbol overloads of TSan functions to enable loading the tool even if the application is not built with TSan. For MACOS the tool collects the function pointer at runtime. 
When adding the function entry/exit markers, we missed to add the functions in the MACOS codepath.
This patch also replaces the repeated function lookup by a single initial function lookup.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103607

Files:
  openmp/tools/archer/ompt-tsan.cpp


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
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103607.349510.patch
Type: text/x-patch
Size: 3830 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210603/2a4aadd8/attachment.bin>


More information about the Openmp-commits mailing list