Skip to content

Commit bad716f

Browse files
committed
[Threading][TSan] Rearrange things again.
We need ThreadSanitizer.cpp in libswiftCore for the runtime case, but we also need it in libswiftThreading for non-runtime cases. rdar://1106655213
1 parent 8ed8a28 commit bad716f

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

lib/Threading/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ add_swift_host_library(swiftThreading STATIC
1010
Linux.cpp
1111
Pthreads.cpp
1212
Win32.cpp
13-
Errors.cpp)
13+
Errors.cpp
14+
ThreadSanitizer.cpp)

stdlib/public/runtime/ThreadSanitizer.cpp lib/Threading/ThreadSanitizer.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@
2525
namespace swift {
2626
namespace threading_impl {
2727

28-
SWIFT_RUNTIME_EXPORT bool _swift_tsan_enabled = false;
29-
SWIFT_RUNTIME_EXPORT void (*_swift_tsan_acquire)(const void *) = nullptr;
30-
SWIFT_RUNTIME_EXPORT void (*_swift_tsan_release)(const void *) = nullptr;
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;
3134

3235
#if __has_include(<dlfcn.h>)
3336
#include <dlfcn.h>
3437

3538
// The TSan library code will call this function when it starts up
36-
SWIFT_RUNTIME_EXPORT
39+
extern "C" SWIFT_ATTRIBUTE_FOR_EXPORTS
3740
void __tsan_on_initialize() {
3841
_swift_tsan_enabled = true;
3942
_swift_tsan_acquire = (void (*)(const void *))dlsym(RTLD_DEFAULT,

stdlib/public/Threading/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/modules")
55
include(AddSwiftStdlib)
66

7+
# This should *not* include ThreadSanitizer.cpp, as that is part of libswiftCore
78
add_swift_target_library(swiftThreading OBJECT_LIBRARY
89
"${SWIFT_SOURCE_DIR}/lib/Threading/C11.cpp"
910
"${SWIFT_SOURCE_DIR}/lib/Threading/Linux.cpp"

stdlib/public/runtime/CMakeLists.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,16 @@ set(swift_runtime_sources
7676
SwiftDtoa.cpp
7777
SwiftTLSContext.cpp
7878
ThreadingError.cpp
79-
ThreadSanitizer.cpp
8079
Tracing.cpp
8180
AccessibleFunction.cpp
8281
Win32.cpp)
8382

83+
# We pull this in separately here because other dylibs will need it, but only
84+
# will have the __tsan_on_initialize called, and on Darwin, RTLD_NEXT can't be
85+
# used to call subsequence dylibs' copies of that.
86+
set(swift_runtime_threading_sources
87+
${SWIFT_SOURCE_DIR}/lib/Threading/ThreadSanitizer.cpp)
88+
8489
set(swift_runtime_backtracing_sources
8590
Backtrace.cpp
8691
CrashHandlerMacOS.cpp
@@ -133,6 +138,7 @@ add_swift_target_library(swiftRuntime OBJECT_LIBRARY
133138
${swift_runtime_sources}
134139
${swift_runtime_objc_sources}
135140
${swift_runtime_leaks_sources}
141+
${swift_runtime_threading_sources}
136142
C_COMPILE_FLAGS
137143
${swift_runtime_library_compile_flags}
138144
LINK_FLAGS ${swift_runtime_linker_flags}

0 commit comments

Comments
 (0)