Skip to content

Commit 3f0018d

Browse files
committed
[Threading][TSan] Fix linkage issue.
We need to pick up the `_swift_tsan_xxx` symbols from libswiftCore in most cases, but sometimes we're statically linked and in that case we want to use a local copy. rdar://1106655213
1 parent bad716f commit 3f0018d

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ function(add_swift_unittest test_dirname)
5858

5959
string(TOUPPER "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_THREADING_PACKAGE}" _threading_package)
6060
target_compile_definitions("${test_dirname}" PRIVATE
61-
"SWIFT_THREADING_${_threading_package}")
61+
"SWIFT_THREADING_${_threading_package}"
62+
"SWIFT_THREADING_STATIC")
6263

6364
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
6465
if(SWIFT_USE_LINKER)

include/swift/Threading/ThreadSanitizer.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,20 @@ template <typename T> T *release(T *ptr) { return ptr; }
3434
} // namespace tsan
3535
#else
3636

37+
// If we're static linking to libswiftThreading.a, these symbols can come
38+
// from there. If, on the other hand, we're dynamically linked, we want
39+
// to get them from libswiftCore.dylib instead.
40+
#if SWIFT_THREADING_STATIC
41+
#define SWIFT_THREADING_EXPORT extern "C"
42+
#else
43+
#define SWIFT_THREADING_EXPORT SWIFT_RUNTIME_EXPORT
44+
#endif
45+
3746
namespace threading_impl {
3847

39-
SWIFT_RUNTIME_EXPORT bool _swift_tsan_enabled;
40-
SWIFT_RUNTIME_EXPORT void (*_swift_tsan_acquire)(const void *ptr);
41-
SWIFT_RUNTIME_EXPORT void (*_swift_tsan_release)(const void *ptr);
48+
SWIFT_THREADING_EXPORT bool _swift_tsan_enabled;
49+
SWIFT_THREADING_EXPORT void (*_swift_tsan_acquire)(const void *ptr);
50+
SWIFT_THREADING_EXPORT void (*_swift_tsan_release)(const void *ptr);
4251

4352
} // namespace threading_impl
4453

lib/Threading/ThreadSanitizer.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@
2525
namespace swift {
2626
namespace threading_impl {
2727

28-
extern "C" SWIFT_ATTRIBUTE_FOR_EXPORTS
29-
bool _swift_tsan_enabled = false;
30-
extern "C" SWIFT_ATTRIBUTE_FOR_EXPORTS
31-
void (*_swift_tsan_acquire)(const void *) = nullptr;
32-
extern "C" SWIFT_ATTRIBUTE_FOR_EXPORTS
33-
void (*_swift_tsan_release)(const void *) = nullptr;
28+
SWIFT_THREADING_EXPORT bool _swift_tsan_enabled = false;
29+
SWIFT_THREADING_EXPORT void (*_swift_tsan_acquire)(const void *) = nullptr;
30+
SWIFT_THREADING_EXPORT void (*_swift_tsan_release)(const void *) = nullptr;
3431

3532
#if __has_include(<dlfcn.h>)
3633
#include <dlfcn.h>

0 commit comments

Comments
 (0)