[Openmp-commits] [openmp] [OMPT] Set default values for tsan function pointers (PR #93568)
via Openmp-commits
openmp-commits at lists.llvm.org
Tue May 28 10:38:50 PDT 2024
https://github.com/jprotze updated https://github.com/llvm/llvm-project/pull/93568
>From 1c7f35cb363e60825c1c1714c11fe5bab9b5816f Mon Sep 17 00:00:00 2001
From: zhangfenglei <zhangfenglei at huawei.com>
Date: Tue, 28 May 2024 14:56:23 +0800
Subject: [PATCH 1/2] [OMPT] Set default values for tsan function pointers
Avoid calling NULL function pointers in cases where
ompt_start_tool succeeds but those tsan functions
do not really exist.
---
openmp/tools/archer/ompt-tsan.cpp | 32 +++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/openmp/tools/archer/ompt-tsan.cpp b/openmp/tools/archer/ompt-tsan.cpp
index de77e25db2d39..4d577d231703c 100644
--- a/openmp/tools/archer/ompt-tsan.cpp
+++ b/openmp/tools/archer/ompt-tsan.cpp
@@ -19,6 +19,7 @@
#include <cassert>
#include <cstdlib>
#include <cstring>
+#include <dlfcn.h>
#include <inttypes.h>
#include <iostream>
#include <list>
@@ -29,7 +30,6 @@
#include <unistd.h>
#include <unordered_map>
#include <vector>
-#include <dlfcn.h>
#include "omp-tools.h"
@@ -146,18 +146,27 @@ void __attribute__((weak)) __tsan_flush_memory() {}
static ArcherFlags *archer_flags;
#ifndef TsanHappensBefore
+
+template <typename... Args> static void __tsan_func(Args...) {}
+
+#define DECLARE_TSAN_FUNCTION(name, ...) \
+ static void (*name)(__VA_ARGS__) = __tsan_func<__VA_ARGS__>;
+
// Thread Sanitizer is a tool that finds races in code.
// See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
// tsan detects these exact functions by name.
extern "C" {
-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);
+DECLARE_TSAN_FUNCTION(AnnotateHappensAfter, const char *, int,
+ const volatile void *)
+DECLARE_TSAN_FUNCTION(AnnotateHappensBefore, const char *, int,
+ const volatile void *)
+DECLARE_TSAN_FUNCTION(AnnotateIgnoreWritesBegin, const char *, int)
+DECLARE_TSAN_FUNCTION(AnnotateIgnoreWritesEnd, const char *, int)
+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)
+
static int (*RunningOnValgrind)(void);
}
@@ -1142,7 +1151,10 @@ static void ompt_tsan_mutex_released(ompt_mutex_t kind, ompt_wait_id_t wait_id,
#define findTsanFunction(f, fSig) \
do { \
- if (NULL == (f = fSig dlsym(RTLD_DEFAULT, #f))) \
+ void *fp = dlsym(RTLD_DEFAULT, #f); \
+ if (fp) \
+ f = fSig fp; \
+ else \
printf("Unable to find TSan function " #f ".\n"); \
} while (0)
>From 86029b9e3bb5a5ea049d140fa9ca0ec644b880bb Mon Sep 17 00:00:00 2001
From: Joachim <protze at rz.rwth-aachen.de>
Date: Tue, 28 May 2024 19:38:43 +0200
Subject: [PATCH 2/2] Apply suggestions from code review
---
openmp/tools/archer/ompt-tsan.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/openmp/tools/archer/ompt-tsan.cpp b/openmp/tools/archer/ompt-tsan.cpp
index 4d577d231703c..d7658077e83ae 100644
--- a/openmp/tools/archer/ompt-tsan.cpp
+++ b/openmp/tools/archer/ompt-tsan.cpp
@@ -147,10 +147,10 @@ static ArcherFlags *archer_flags;
#ifndef TsanHappensBefore
-template <typename... Args> static void __tsan_func(Args...) {}
+template <typename... Args> static void __ompt_tsan_func(Args...) {}
#define DECLARE_TSAN_FUNCTION(name, ...) \
- static void (*name)(__VA_ARGS__) = __tsan_func<__VA_ARGS__>;
+ static void (*name)(__VA_ARGS__) = __ompt_tsan_func<__VA_ARGS__>;
// Thread Sanitizer is a tool that finds races in code.
// See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
@@ -167,6 +167,7 @@ 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);
}
More information about the Openmp-commits
mailing list