mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
I keep trying to fix the tsan symbol dance, avoiding duplicate symbols for initializing the tsan acquire and release function pointers. The idea this time was to expose an API from the runtime to return the function pointers for the compatibility library. This won't work because the compatibility library would need to backdeploy to a version of the library that doesn't have those symbols, so it would fail to link. Now, if I really wanted to increment the counter again, an idea might be to pull the swift_tsan_acquire/swift_tsan_release symbols out of the Swift concurrency runtime and make them into a toolchain static library which would get linked by the driver when doing an ASAN build. The sanitizer libraries are already shipped like this, so it wouldn't be too weird to do this.
49 lines
1.7 KiB
C++
49 lines
1.7 KiB
C++
//===--- ThreadSanitizer.cpp ----------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Thread Sanitizer support for the Swift Task runtime.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "Concurrency/TaskPrivate.h"
|
|
#include "swift/Basic/Lazy.h"
|
|
|
|
#include <dlfcn.h>
|
|
|
|
namespace {
|
|
using TSanFunc = void(void *);
|
|
} // anonymous namespace
|
|
|
|
// Note: We can't use a proper interface to get the `__tsan_acquire` and
|
|
// `__tsan_release` from the public/Concurrency/ThreadSanitizer.cpp.
|
|
// Unfortunately, we can't do this because there is no interface in the runtimes
|
|
// we are backdeploying to. So we're stuck using this lazy dlsym game.
|
|
// Number of times I've tried to fix this: 3
|
|
|
|
void swift::_swift_tsan_acquire(void *addr) {
|
|
const auto backdeploy_tsan_acquire =
|
|
reinterpret_cast<TSanFunc *>(SWIFT_LAZY_CONSTANT(dlsym(RTLD_DEFAULT, "__tsan_acquire")));
|
|
if (backdeploy_tsan_acquire) {
|
|
backdeploy_tsan_acquire(addr);
|
|
SWIFT_TASK_DEBUG_LOG("tsan_acquire on %p", addr);
|
|
}
|
|
}
|
|
|
|
void swift::_swift_tsan_release(void *addr) {
|
|
const auto backdeploy_tsan_release =
|
|
reinterpret_cast<TSanFunc *>(SWIFT_LAZY_CONSTANT(dlsym(RTLD_DEFAULT, "__tsan_release")));
|
|
if (backdeploy_tsan_release) {
|
|
backdeploy_tsan_release(addr);
|
|
SWIFT_TASK_DEBUG_LOG("tsan_release on %p", addr);
|
|
}
|
|
}
|