Skip to content

Commit 18b359f

Browse files
committed
[Threading][TSan] Fix builds where TSan isn't supported.
On builds where TSan isn't supported, don't include any code in ThreadSanitizer.cpp. rdar://110665213
1 parent 3f0018d commit 18b359f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

include/swift/Threading/ThreadSanitizer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
namespace swift {
2626

2727
#if defined(_WIN32) || defined(__wasi__) || !__has_include(<dlfcn.h>)
28+
29+
#define SWIFT_THREADING_TSAN_SUPPORT 0
30+
2831
namespace tsan {
2932

3033
inline bool enabled() { return false; }
@@ -34,6 +37,8 @@ template <typename T> T *release(T *ptr) { return ptr; }
3437
} // namespace tsan
3538
#else
3639

40+
#define SWIFT_THREADING_TSAN_SUPPORT 1
41+
3742
// If we're static linking to libswiftThreading.a, these symbols can come
3843
// from there. If, on the other hand, we're dynamically linked, we want
3944
// to get them from libswiftCore.dylib instead.

lib/Threading/ThreadSanitizer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
//===----------------------------------------------------------------------===//
1919

2020
#include "swift/Threading/ThreadSanitizer.h"
21+
22+
#if SWIFT_THREADING_TSAN_SUPPORT
23+
2124
#include "swift/shims/Visibility.h"
2225

2326
#include <cstdio>
@@ -50,7 +53,9 @@ void __tsan_on_initialize() {
5053
next_init();
5154
}
5255
}
53-
#endif
56+
#endif // __has_include(<dlfcn.h>)
5457

5558
} // namespace threading_impl
5659
} // namespace swift
60+
61+
#endif // SWIFT_THREADING_TSAN_SUPPORT

0 commit comments

Comments
 (0)