[Openmp-commits] [openmp] 789bfdc - [OMPT] Use __tsan_init to detect TSan binaries rather than RunningOnValgrind (#128357)

via Openmp-commits openmp-commits at lists.llvm.org
Tue Feb 25 14:35:35 PST 2025


Author: Paul Floyd
Date: 2025-02-25T23:35:32+01:00
New Revision: 789bfdc3e60cad3b8aa6798ed06d24ad62a4bc1d

URL: https://github.com/llvm/llvm-project/commit/789bfdc3e60cad3b8aa6798ed06d24ad62a4bc1d
DIFF: https://github.com/llvm/llvm-project/commit/789bfdc3e60cad3b8aa6798ed06d24ad62a4bc1d.diff

LOG: [OMPT] Use __tsan_init to detect TSan binaries rather than RunningOnValgrind (#128357)

Switch to using __tsan_init rather than RunningOnValgrind as the means
for detecting TSan instumented binaries. RunningOnValgrind is present in
other libraries (such as Google perftools tcmalloc). An exe that links
with a tcmalloc static library and exports symbols with -rdynamic will
appear to be TSan instrumented even when it is not resulting in "Unable
to fint TSan function ..." messages.

Fixes issue #122319.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/openmp/tools/archer/ompt-tsan.cpp b/openmp/tools/archer/ompt-tsan.cpp
index d7658077e83ae..bb60fc6b603f4 100644
--- a/openmp/tools/archer/ompt-tsan.cpp
+++ b/openmp/tools/archer/ompt-tsan.cpp
@@ -166,9 +166,6 @@ DECLARE_TSAN_FUNCTION(AnnotateNewMemory, const char *, int,
                       const volatile void *, size_t)
 DECLARE_TSAN_FUNCTION(__tsan_func_entry, const void *)
 DECLARE_TSAN_FUNCTION(__tsan_func_exit)
-
-// RunningOnValgrind is used to detect absence of TSan and must intentionally be a nullptr.
-static int (*RunningOnValgrind)(void);
 }
 
 // This marker is used to define a happens-before arc. The race detector will
@@ -1252,13 +1249,15 @@ ompt_start_tool(unsigned int omp_version, const char *runtime_version) {
 
   // The OMPT start-up code uses dlopen with RTLD_LAZY. Therefore, we cannot
   // rely on dlopen to fail if TSan is missing, but would get a runtime error
-  // for the first TSan call. We use RunningOnValgrind to detect whether
+  // for the first TSan call. We use __tsan_init to detect whether
   // an implementation of the Annotation interface is available in the
   // execution or disable the tool (by returning NULL).
 
-  findTsanFunctionSilent(RunningOnValgrind, (int (*)(void)));
-  if (!RunningOnValgrind) // if we are not running on TSAN, give a 
diff erent
-                          // tool the chance to be loaded
+  void (*__tsan_init)(void) = nullptr;
+
+  findTsanFunctionSilent(__tsan_init, (void (*)(void)));
+  if (!__tsan_init) // if we are not running on TSAN, give a 
diff erent
+                    // tool the chance to be loaded
   {
     if (archer_flags->verbose)
       std::cout << "Archer detected OpenMP application without TSan; "


        


More information about the Openmp-commits mailing list