From 2e800495a78a6d722eed5766bba1e2fe76f295bc Mon Sep 17 00:00:00 2001 From: Marco Vanotti Date: Fri, 28 Aug 2020 15:42:09 -0700 Subject: [PATCH] [clang] Enable -fsanitize=thread on Fuchsia. This CL modifies clang enabling using -fsanitize=thread on fuchsia. The change doesn't build the runtime for fuchsia, it just enables the instrumentation to be used. pair-programmed-with: mdempsky@google.com Change-Id: I816c4d240d1f15e9eae2803fb8ba3a7bf667ed51 Reviewed By: mcgrathr, phosek Differential Revision: https://reviews.llvm.org/D86822 --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 5 ++++- clang/lib/Driver/ToolChains/Fuchsia.cpp | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 39308f8ea5b7..8bbb642c2917 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -703,6 +703,8 @@ collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, else SharedRuntimes.push_back("scudo"); } + if (SanArgs.needsTsanRt() && SanArgs.linkRuntimes()) + SharedRuntimes.push_back("tsan"); if (SanArgs.needsHwasanRt() && SanArgs.linkRuntimes()) SharedRuntimes.push_back("hwasan"); } @@ -747,7 +749,8 @@ collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, if (SanArgs.linkCXXRuntimes()) StaticRuntimes.push_back("msan_cxx"); } - if (SanArgs.needsTsanRt() && SanArgs.linkRuntimes()) { + if (!SanArgs.needsSharedRt() && SanArgs.needsTsanRt() && + SanArgs.linkRuntimes()) { StaticRuntimes.push_back("tsan"); if (SanArgs.linkCXXRuntimes()) StaticRuntimes.push_back("tsan_cxx"); diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp index 94e025e3055a..781179be39a3 100644 --- a/clang/lib/Driver/ToolChains/Fuchsia.cpp +++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp @@ -95,6 +95,8 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA, std::string Dyld = D.DyldPrefix; if (SanArgs.needsAsanRt() && SanArgs.needsSharedRt()) Dyld += "asan/"; + if (SanArgs.needsTsanRt() && SanArgs.needsSharedRt()) + Dyld += "tsan/"; Dyld += "ld.so.1"; CmdArgs.push_back("-dynamic-linker"); CmdArgs.push_back(Args.MakeArgString(Dyld)); @@ -349,6 +351,7 @@ SanitizerMask Fuchsia::getSupportedSanitizers() const { Res |= SanitizerKind::Leak; Res |= SanitizerKind::SafeStack; Res |= SanitizerKind::Scudo; + Res |= SanitizerKind::Thread; return Res; }