[cfe-commits] r156906 - in /cfe/trunk: lib/Driver/Tools.cpp runtime/compiler-rt/Makefile

Kostya Serebryany kcc at google.com
Tue May 15 23:36:00 PDT 2012


Author: kcc
Date: Wed May 16 01:36:00 2012
New Revision: 156906

URL: http://llvm.org/viewvc/llvm-project?rev=156906&view=rev
Log:
[tsan] add  ThreadSanitizer linker flags on Linux and also copy the tsan-rt into the appropriate place at build time

Modified:
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/runtime/compiler-rt/Makefile

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=156906&r1=156905&r2=156906&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed May 16 01:36:00 2012
@@ -1304,6 +1304,27 @@
   }
 }
 
+/// 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 @@
 
   // 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)) {

Modified: cfe/trunk/runtime/compiler-rt/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/runtime/compiler-rt/Makefile?rev=156906&r1=156905&r2=156906&view=diff
==============================================================================
--- cfe/trunk/runtime/compiler-rt/Makefile (original)
+++ cfe/trunk/runtime/compiler-rt/Makefile Wed May 16 01:36:00 2012
@@ -90,7 +90,7 @@
 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





More information about the cfe-commits mailing list