29
29
#include < unistd.h>
30
30
#include < unordered_map>
31
31
#include < vector>
32
-
33
- #if (defined __APPLE__ && defined __MACH__)
34
32
#include < dlfcn.h>
35
- #endif
36
33
37
34
#include " omp-tools.h"
38
35
53
50
#define KMP_FALLTHROUGH () ((void )0 )
54
51
#endif
55
52
56
- static int runOnTsan;
57
53
static int hasReductionCallback;
58
54
59
55
namespace {
@@ -148,7 +144,6 @@ static ArcherFlags *archer_flags;
148
144
// See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
149
145
// tsan detects these exact functions by name.
150
146
extern " C" {
151
- #if (defined __APPLE__ && defined __MACH__)
152
147
static void (*AnnotateHappensAfter)(const char *, int , const volatile void *);
153
148
static void (*AnnotateHappensBefore)(const char *, int , const volatile void *);
154
149
static void (*AnnotateIgnoreWritesBegin)(const char *, int );
@@ -157,37 +152,7 @@ static void (*AnnotateNewMemory)(const char *, int, const volatile void *,
157
152
size_t );
158
153
static void (*__tsan_func_entry)(const void *);
159
154
static void (*__tsan_func_exit)(void );
160
-
161
- static int RunningOnValgrind () {
162
- int (*fptr)();
163
-
164
- fptr = (int (*)())dlsym (RTLD_DEFAULT, " RunningOnValgrind" );
165
- // If we found RunningOnValgrind other than this function, we assume
166
- // Annotation functions present in this execution and leave runOnTsan=1
167
- // otherwise we change to runOnTsan=0
168
- if (!fptr || fptr == RunningOnValgrind)
169
- runOnTsan = 0 ;
170
- return 0 ;
171
- }
172
- #else
173
- void __attribute__ ((weak))
174
- AnnotateHappensAfter(const char *file, int line, const volatile void *cv) {}
175
- void __attribute__ ((weak))
176
- AnnotateHappensBefore(const char *file, int line, const volatile void *cv) {}
177
- void __attribute__ ((weak))
178
- AnnotateIgnoreWritesBegin(const char *file, int line) {}
179
- void __attribute__ ((weak)) AnnotateIgnoreWritesEnd(const char *file, int line) {
180
- }
181
- void __attribute__ ((weak))
182
- AnnotateNewMemory(const char *file, int line, const volatile void *cv,
183
- size_t size) {}
184
- int __attribute__ ((weak)) RunningOnValgrind() {
185
- runOnTsan = 0 ;
186
- return 0 ;
187
- }
188
- void __attribute__ ((weak)) __tsan_func_entry(const void *call_pc) {}
189
- void __attribute__ ((weak)) __tsan_func_exit(void ) {}
190
- #endif
155
+ static int (*RunningOnValgrind)(void );
191
156
}
192
157
193
158
// This marker is used to define a happens-before arc. The race detector will
@@ -1078,6 +1043,14 @@ static void ompt_tsan_mutex_released(ompt_mutex_t kind, ompt_wait_id_t wait_id,
1078
1043
1079
1044
#define SET_CALLBACK (event ) SET_CALLBACK_T(event, event)
1080
1045
1046
+ #define findTsanFunction (f, fSig ) \
1047
+ do { \
1048
+ if (NULL == (f = fSig dlsym (RTLD_DEFAULT, #f))) \
1049
+ printf (" Unable to find TSan function " #f " .\n " ); \
1050
+ } while (0 )
1051
+
1052
+ #define findTsanFunctionSilent (f, fSig ) f = fSig dlsym (RTLD_DEFAULT, #f)
1053
+
1081
1054
static int ompt_tsan_initialize(ompt_function_lookup_t lookup, int device_num,
1082
1055
ompt_data_t *tool_data) {
1083
1056
const char *options = getenv (" TSAN_OPTIONS" );
@@ -1099,13 +1072,6 @@ static int ompt_tsan_initialize(ompt_function_lookup_t lookup, int device_num,
1099
1072
exit (1 );
1100
1073
}
1101
1074
1102
- #if (defined __APPLE__ && defined __MACH__)
1103
- #define findTsanFunction (f, fSig ) \
1104
- do { \
1105
- if (NULL == (f = fSig dlsym (RTLD_DEFAULT, #f))) \
1106
- printf (" Unable to find TSan function " #f " .\n " ); \
1107
- } while (0 )
1108
-
1109
1075
findTsanFunction (AnnotateHappensAfter,
1110
1076
(void (*)(const char *, int , const volatile void *)));
1111
1077
findTsanFunction (AnnotateHappensBefore,
@@ -1117,7 +1083,6 @@ static int ompt_tsan_initialize(ompt_function_lookup_t lookup, int device_num,
1117
1083
(void (*)(const char *, int , const volatile void *, size_t )));
1118
1084
findTsanFunction (__tsan_func_entry, (void (*)(const void *)));
1119
1085
findTsanFunction (__tsan_func_exit, (void (*)(void )));
1120
- #endif
1121
1086
1122
1087
SET_CALLBACK (thread_begin);
1123
1088
SET_CALLBACK (thread_end);
@@ -1181,10 +1146,9 @@ ompt_start_tool(unsigned int omp_version, const char *runtime_version) {
1181
1146
// an implementation of the Annotation interface is available in the
1182
1147
// execution or disable the tool (by returning NULL).
1183
1148
1184
- runOnTsan = 1 ;
1185
- RunningOnValgrind ();
1186
- if (!runOnTsan) // if we are not running on TSAN, give a different tool the
1187
- // chance to be loaded
1149
+ findTsanFunctionSilent (RunningOnValgrind, (int (*)(void )));
1150
+ if (!RunningOnValgrind) // if we are not running on TSAN, give a different
1151
+ // tool the chance to be loaded
1188
1152
{
1189
1153
if (archer_flags->verbose )
1190
1154
std::cout << " Archer detected OpenMP application without TSan "
0 commit comments