Skip to content

Commit 1cac0be

Browse files
committed
[Driver] TSan runtime now has a link-time dependency on libdispatch
Previously, the TSan runtime only required libdispatch on Darwin, which required no explicit linker flags, because libdispatch is always provided by the system (libSystem). Now, the TSan runtime also has a link-time dependency on libdispatch on Linux, where libdispatch (and the blocks runtime) is just another library. We therefore need to specify them as additonal linker options.
1 parent 3ef1efd commit 1cac0be

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/Driver/UnixToolChains.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
278278
if (job.getKind() == LinkKind::Executable && context.OI.SelectedSanitizers) {
279279
Arguments.push_back(context.Args.MakeArgString(
280280
"-fsanitize=" + getSanitizerList(context.OI.SelectedSanitizers)));
281+
282+
// The TSan runtime depends on the blocks runtime and libdispatch.
283+
if (context.OI.SelectedSanitizers & SanitizerKind::Thread) {
284+
Arguments.push_back("-lBlocksRuntime");
285+
Arguments.push_back("-ldispatch");
286+
}
281287
}
282288

283289
if (context.Args.hasArg(options::OPT_profile_generate)) {

test/Driver/sanitizers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
// TSAN_watchOS_SIM: unsupported option '-sanitize=thread' for target 'i386-apple-watchos2.0'
8787
// TSAN_watchOS: unsupported option '-sanitize=thread' for target 'armv7k-apple-watchos2.0'
8888
// FUZZER_NONEXISTENT: unsupported option '-sanitize=fuzzer' for target 'x86_64-apple-macosx10.9'
89-
// TSAN_LINUX: -fsanitize=thread
89+
// TSAN_LINUX: -fsanitize=thread -lBlocksRuntime -ldispatch
9090
// TSAN_WINDOWS: unsupported option '-sanitize=thread' for target 'x86_64-unknown-windows-msvc'
9191

9292
// TSAN: -rpath @executable_path

0 commit comments

Comments
 (0)