From 743c980c52a1559f1f115105b8221adb1767995e Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Sat, 22 Feb 2025 15:25:46 +0100 Subject: [PATCH 1/3] [OMPT] Use a __tsan function to detect TSan binaries rather than RunningOnValgrind 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. --- openmp/tools/archer/ompt-tsan.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openmp/tools/archer/ompt-tsan.cpp b/openmp/tools/archer/ompt-tsan.cpp index d7658077e83ae..6cc8e370eb347 100644 --- a/openmp/tools/archer/ompt-tsan.cpp +++ b/openmp/tools/archer/ompt-tsan.cpp @@ -167,8 +167,8 @@ DECLARE_TSAN_FUNCTION(AnnotateNewMemory, const char *, int, 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); +// __tsan_init is used to detect absence of TSan and must intentionally be a nullptr. +static void (*__tsan_init)(void); } // This marker is used to define a happens-before arc. The race detector will @@ -1252,12 +1252,12 @@ 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 different + findTsanFunctionSilent(__tsan_init, (void (*)(void))); + if (!__tsan_init) // if we are not running on TSAN, give a different // tool the chance to be loaded { if (archer_flags->verbose) From b3d72227183acaf2ebf21cd4eaeada0f8d372fa9 Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Tue, 25 Feb 2025 20:57:20 +0100 Subject: [PATCH 2/3] Move the function pointer for __tsan_init from file static to function local. --- openmp/tools/archer/ompt-tsan.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openmp/tools/archer/ompt-tsan.cpp b/openmp/tools/archer/ompt-tsan.cpp index 6cc8e370eb347..ca5fe7b9ed331 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) - -// __tsan_init is used to detect absence of TSan and must intentionally be a nullptr. -static void (*__tsan_init)(void); } // This marker is used to define a happens-before arc. The race detector will @@ -1256,6 +1253,8 @@ ompt_start_tool(unsigned int omp_version, const char *runtime_version) { // an implementation of the Annotation interface is available in the // execution or disable the tool (by returning NULL). + void (*__tsan_init)(void) = nullptr; + findTsanFunctionSilent(__tsan_init, (void (*)(void))); if (!__tsan_init) // if we are not running on TSAN, give a different // tool the chance to be loaded From 32a02789c9b5af130366f69e2e96247075edcc8a Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Tue, 25 Feb 2025 21:18:20 +0100 Subject: [PATCH 3/3] Run clang-format on changed file --- openmp/tools/archer/ompt-tsan.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmp/tools/archer/ompt-tsan.cpp b/openmp/tools/archer/ompt-tsan.cpp index ca5fe7b9ed331..bb60fc6b603f4 100644 --- a/openmp/tools/archer/ompt-tsan.cpp +++ b/openmp/tools/archer/ompt-tsan.cpp @@ -1257,7 +1257,7 @@ ompt_start_tool(unsigned int omp_version, const char *runtime_version) { findTsanFunctionSilent(__tsan_init, (void (*)(void))); if (!__tsan_init) // if we are not running on TSAN, give a different - // tool the chance to be loaded + // tool the chance to be loaded { if (archer_flags->verbose) std::cout << "Archer detected OpenMP application without TSan; "