[tsan] makefile machinery to build tsan-rt (linux-x86_64 only)

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@156822 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Makefile.mk b/lib/Makefile.mk
index 6d88013..e20d3c8 100644
--- a/lib/Makefile.mk
+++ b/lib/Makefile.mk
@@ -17,6 +17,7 @@
 SubDirs += asan
 SubDirs += interception
 SubDirs += profile
+SubDirs += tsan
 
 # FIXME: We don't currently support building an atomic library, and as it must
 # be a separate library from the runtime library, we need to remove its source
diff --git a/lib/tsan/CMakeLists.txt b/lib/tsan/CMakeLists.txt
new file mode 100644
index 0000000..acfb854
--- /dev/null
+++ b/lib/tsan/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Build for the AddressSanitizer runtime support library.
+
+file(GLOB TSAN_SOURCES "*.cc")
+
+if(CAN_TARGET_X86_64)
+  add_library(clang_rt.tsan-x86_64 STATIC ${TSAN_SOURCES})
+  set_target_properties(clang_rt.tsan-x86_64 PROPERTIES COMPILE_FLAGS "${TARGET_X86_64_CFLAGS}")
+endif()
diff --git a/lib/tsan/Makefile.mk b/lib/tsan/Makefile.mk
new file mode 100644
index 0000000..70fb610
--- /dev/null
+++ b/lib/tsan/Makefile.mk
@@ -0,0 +1,18 @@
+#===- lib/tsan/Makefile.mk ---------------------------------*- Makefile -*--===#
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+#===------------------------------------------------------------------------===#
+
+ModuleName := tsan
+SubDirs := rtl
+Sources :=
+ObjNames :=
+Dependencies :=
+
+Implementation := Generic
+
+TsanFunctions :=
diff --git a/lib/tsan/rtl/Makefile.mk b/lib/tsan/rtl/Makefile.mk
new file mode 100644
index 0000000..d5d6327
--- /dev/null
+++ b/lib/tsan/rtl/Makefile.mk
@@ -0,0 +1,23 @@
+#===- lib/tsan/rtl/Makefile.mk -----------------------------*- Makefile -*--===#
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+#===------------------------------------------------------------------------===#
+
+ModuleName := tsan
+SubDirs :=
+
+Sources := $(foreach file,$(wildcard $(Dir)/*.cc),$(notdir $(file)))
+AsmSources := $(foreach file,$(wildcard $(Dir)/*.S),$(notdir $(file)))
+ObjNames := $(Sources:%.cc=%.o) $(AsmSources:%.S=%.o)
+
+Implementation := Generic
+
+# FIXME: use automatic dependencies?
+Dependencies := $(wildcard $(Dir)/*.h)
+
+# Define a convenience variable for all the tsan functions.
+TsanFunctions += $(Sources:%.cc=%) $(AsmSources:%.S=%)
diff --git a/make/platform/clang_linux.mk b/make/platform/clang_linux.mk
index 3c799ef..7f38f07 100644
--- a/make/platform/clang_linux.mk
+++ b/make/platform/clang_linux.mk
@@ -47,6 +47,12 @@
 Arch.asan-x86_64 := x86_64
 endif
 
+# Configuration for TSAN runtime.
+ifeq ($(CompilerTargetArch),x86_64)
+Configs += tsan-x86_64
+Arch.tsan-x86_64 := x86_64
+endif
+
 endif
 
 ###
@@ -59,6 +65,7 @@
 CFLAGS.profile-x86_64 := $(CFLAGS) -m64
 CFLAGS.asan-i386 := $(CFLAGS) -m32
 CFLAGS.asan-x86_64 := $(CFLAGS) -m64
+CFLAGS.tsan-x86_64 := $(CFLAGS) -m64 -fPIE -fno-builtin
 
 # Use our stub SDK as the sysroot to support more portable building. For now we
 # just do this for the non-ASAN modules, because the stub SDK doesn't have
@@ -74,6 +81,7 @@
 FUNCTIONS.profile-x86_64 := GCDAProfiling
 FUNCTIONS.asan-i386 := $(AsanFunctions) $(InterceptionFunctions)
 FUNCTIONS.asan-x86_64 := $(AsanFunctions) $(InterceptionFunctions)
+FUNCTIONS.tsan-x86_64 := $(TsanFunctions) $(InterceptionFunctions)
 
 # Always use optimized variants.
 OPTIMIZED := 1