Skip to content

[OMPT] Set default values for tsan function pointers #93568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions openmp/tools/archer/ompt-tsan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <dlfcn.h>
#include <inttypes.h>
#include <iostream>
#include <list>
Expand All @@ -29,7 +30,6 @@
#include <unistd.h>
#include <unordered_map>
#include <vector>
#include <dlfcn.h>

#include "omp-tools.h"

Expand Down Expand Up @@ -146,18 +146,28 @@ void __attribute__((weak)) __tsan_flush_memory() {}
static ArcherFlags *archer_flags;

#ifndef TsanHappensBefore

template <typename... Args> static void __ompt_tsan_func(Args...) {}

#define DECLARE_TSAN_FUNCTION(name, ...) \
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 .
// 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)

// RunningOnValgrind is used to detect absence of TSan and must intentionally be a nullptr.
static int (*RunningOnValgrind)(void);
}

Expand Down Expand Up @@ -1142,7 +1152,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)

Expand Down
Loading