Skip to content

Commit ea5bb77

Browse files
author
Julian Lettner
committed
Fix TSan symbol lookup on Windows
1 parent a3ccdd2 commit ea5bb77

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

stdlib/public/Concurrency/ThreadSanitizer.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,34 @@
1616

1717
#include "TaskPrivate.h"
1818

19+
#if defined(_WIN32)
20+
#define NOMINMAX
21+
#include <windows.h>
22+
#else
1923
#include <dlfcn.h>
24+
#endif
2025

2126
using TSanFunc = void(void *);
2227

28+
namespace {
29+
static TSanFunc *loadSymbol(const char *name) {
30+
#if defined(_WIN32)
31+
return (TSanFunc *)GetProcAddress(GetModuleHandle(NULL), name);
32+
#else
33+
return (TSanFunc *)dlsym(RTLD_DEFAULT, name);
34+
#endif
35+
}
36+
}
37+
2338
void swift::_swift_tsan_acquire(void *addr) {
24-
static auto ptr = (TSanFunc *)dlsym(RTLD_DEFAULT, "__tsan_acquire");
39+
static auto ptr = loadSymbol("__tsan_acquire");
2540
if (ptr) {
2641
ptr(addr);
2742
}
2843
}
2944

3045
void swift::_swift_tsan_release(void *addr) {
31-
static auto ptr = (TSanFunc *)dlsym(RTLD_DEFAULT, "__tsan_release");
46+
static auto ptr = loadSymbol("__tsan_release");
3247
if (ptr) {
3348
ptr(addr);
3449
}

0 commit comments

Comments
 (0)