diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp @@ -25,12 +25,14 @@ #include "interception/interception.h" #include "tsan_interceptors.h" #include "tsan_interface.h" +#include "tsan_interface_ann.h" #include "tsan_platform.h" #include "tsan_suppressions.h" #include "tsan_rtl.h" #include "tsan_mman.h" #include "tsan_fd.h" +#include #include using namespace __tsan; @@ -2660,6 +2662,20 @@ } #endif +static void InitializeSwiftTaskRuntimeHooks() { + // void swift_task_set_tsan_hooks(TSanFunc *acquire, TSanFunc *release) + using TSanFunc = void(void *addr); + using SetHooksFunc = void(TSanFunc *acquire, TSanFunc *release); + + auto set_hooks = + (SetHooksFunc *)dlsym(RTLD_DEFAULT, "swift_task_set_tsan_hooks"); + (void)dlerror(); // Cleanup error message in case of failure + + if (set_hooks) { + set_hooks(__tsan_acquire, __tsan_release); + } +} + // Define default implementation since interception of libdispatch is optional. SANITIZER_WEAK_ATTRIBUTE void InitializeLibdispatchInterceptors() {} @@ -2681,6 +2697,7 @@ InitializeCommonInterceptors(); InitializeSignalInterceptors(); InitializeLibdispatchInterceptors(); + InitializeSwiftTaskRuntimeHooks(); #if !SANITIZER_MAC // We can not use TSAN_INTERCEPT to get setjmp addr,