summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2012-05-16 06:36:00 +0000
committerKostya Serebryany <kcc@google.com>2012-05-16 06:36:00 +0000
commitf7efb0e7478da45bc7f2d24dbeb08406d2399591 (patch)
tree0ccac299492c800c41d91ccd47295a6446dfadbd
parent3940ce83438e2332ba541f4e65e700fbefe0c7a8 (diff)
[tsan] add ThreadSanitizer linker flags on Linux and also copy the tsan-rt into the appropriate place at build time
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156906 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Driver/Tools.cpp22
-rw-r--r--runtime/compiler-rt/Makefile2
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 887c64cff0..fcfee50859 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1304,6 +1304,27 @@ static void addAsanRTLinux(const ToolChain &TC, const ArgList &Args,
}
}
+/// If ThreadSanitizer is enabled, add appropriate linker flags (Linux).
+/// This needs to be called before we add the C run-time (malloc, etc).
+static void addTsanRTLinux(const ToolChain &TC, const ArgList &Args,
+ ArgStringList &CmdArgs) {
+ if (!Args.hasFlag(options::OPT_fthread_sanitizer,
+ options::OPT_fno_thread_sanitizer, false))
+ return;
+ if (!Args.hasArg(options::OPT_shared)) {
+ // LibTsan is "libclang_rt.tsan-<ArchName>.a" in the Linux library
+ // resource directory.
+ SmallString<128> LibTsan(TC.getDriver().ResourceDir);
+ llvm::sys::path::append(LibTsan, "lib", "linux",
+ (Twine("libclang_rt.tsan-") +
+ TC.getArchName() + ".a"));
+ CmdArgs.push_back(Args.MakeArgString(LibTsan));
+ CmdArgs.push_back("-lpthread");
+ CmdArgs.push_back("-ldl");
+ CmdArgs.push_back("-export-dynamic");
+ }
+}
+
static bool shouldUseFramePointer(const ArgList &Args,
const llvm::Triple &Triple) {
if (Arg *A = Args.getLastArg(options::OPT_fno_omit_frame_pointer,
@@ -5330,6 +5351,7 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA,
// Call this before we add the C run-time.
addAsanRTLinux(getToolChain(), Args, CmdArgs);
+ addTsanRTLinux(getToolChain(), Args, CmdArgs);
if (!Args.hasArg(options::OPT_nostdlib)) {
if (!Args.hasArg(options::OPT_nodefaultlibs)) {
diff --git a/runtime/compiler-rt/Makefile b/runtime/compiler-rt/Makefile
index 534168b484..6b23346ce5 100644
--- a/runtime/compiler-rt/Makefile
+++ b/runtime/compiler-rt/Makefile
@@ -90,7 +90,7 @@ RuntimeLibrary.linux.Configs += \
endif
ifeq ($(ARCH),x86_64)
RuntimeLibrary.linux.Configs += \
- full-x86_64 profile-x86_64 asan-x86_64
+ full-x86_64 profile-x86_64 asan-x86_64 tsan-x86_64
endif
endif