[Openmp-commits] [PATCH] D142378: [OpenMP][Archer] Use dlsym rather than weak symbols for TSan annotations

Joachim Protze via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Jan 23 09:19:57 PST 2023


protze.joachim created this revision.
protze.joachim added reviewers: jdoerfert, Hahnfeld.
protze.joachim added a project: OpenMP.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
protze.joachim requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.

This is to fix issues reported for Ubuntu and possibly other platforms:
https://github.com/llvm/llvm-project/issues/45290

The latest comment on this issue points out that using dlsym rather than the weak symbol approach to call TSan annotation functions fixes the issue for Ubuntu.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142378

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
@@ -29,10 +29,7 @@
 #include <unistd.h>
 #include <unordered_map>
 #include <vector>
-
-#if (defined __APPLE__ && defined __MACH__)
 #include <dlfcn.h>
-#endif
 
 #include "omp-tools.h"
 
@@ -148,7 +145,6 @@
 // See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
 // tsan detects these exact functions by name.
 extern "C" {
-#if (defined __APPLE__ && defined __MACH__)
 static void (*AnnotateHappensAfter)(const char *, int, const volatile void *);
 static void (*AnnotateHappensBefore)(const char *, int, const volatile void *);
 static void (*AnnotateIgnoreWritesBegin)(const char *, int);
@@ -169,25 +165,6 @@
     runOnTsan = 0;
   return 0;
 }
-#else
-void __attribute__((weak))
-AnnotateHappensAfter(const char *file, int line, const volatile void *cv) {}
-void __attribute__((weak))
-AnnotateHappensBefore(const char *file, int line, const volatile void *cv) {}
-void __attribute__((weak))
-AnnotateIgnoreWritesBegin(const char *file, int line) {}
-void __attribute__((weak)) AnnotateIgnoreWritesEnd(const char *file, int line) {
-}
-void __attribute__((weak))
-AnnotateNewMemory(const char *file, int line, const volatile void *cv,
-                  size_t size) {}
-int __attribute__((weak)) RunningOnValgrind() {
-  runOnTsan = 0;
-  return 0;
-}
-void __attribute__((weak)) __tsan_func_entry(const void *call_pc) {}
-void __attribute__((weak)) __tsan_func_exit(void) {}
-#endif
 }
 
 // This marker is used to define a happens-before arc. The race detector will
@@ -1099,7 +1076,6 @@
     exit(1);
   }
 
-#if (defined __APPLE__ && defined __MACH__)
 #define findTsanFunction(f, fSig)                                              \
   do {                                                                         \
     if (NULL == (f = fSig dlsym(RTLD_DEFAULT, #f)))                            \
@@ -1117,7 +1093,7 @@
       (void (*)(const char *, int, const volatile void *, size_t)));
   findTsanFunction(__tsan_func_entry, (void (*)(const void *)));
   findTsanFunction(__tsan_func_exit, (void (*)(void)));
-#endif
+#undef findTsanFunction
 
   SET_CALLBACK(thread_begin);
   SET_CALLBACK(thread_end);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142378.491417.patch
Type: text/x-patch
Size: 2323 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230123/bbf84bd8/attachment-0001.bin>


More information about the Openmp-commits mailing list