[test-suite] Fix stdthreadbug when building static

This patch adds necessary flags for the test stdthreadbug.cpp, so it can
be executed without error, when tests are compiled with -static flag.

Differential Revision: https://reviews.llvm.org/D52878

llvm-svn: 352385
diff --git a/SingleSource/UnitTests/C++11/CMakeLists.txt b/SingleSource/UnitTests/C++11/CMakeLists.txt
index 42d6ba9..87e50f2 100644
--- a/SingleSource/UnitTests/C++11/CMakeLists.txt
+++ b/SingleSource/UnitTests/C++11/CMakeLists.txt
@@ -1,3 +1,9 @@
 list(APPEND CXXFLAGS -std=c++11 -pthread)
 list(APPEND LDFLAGS -lstdc++ -pthread)
+
+file(GLOB Source RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.c *.cpp)
+if(${CMAKE_EXE_LINKER_FLAGS} MATCHES "-static")
+	list(APPEND LDFLAGS -Wl,--whole-archive -lpthread -Wl,--no-whole-archive)
+endif()
+
 llvm_singlesource()
diff --git a/SingleSource/UnitTests/C++11/Makefile b/SingleSource/UnitTests/C++11/Makefile
index 06f5509..eaecf19 100644
--- a/SingleSource/UnitTests/C++11/Makefile
+++ b/SingleSource/UnitTests/C++11/Makefile
@@ -6,6 +6,10 @@
 
 ifdef BENCHMARKING_ONLY
 PROGRAMS_TO_SKIP += stdthreadbug
+else
+ifeq (-static, $(findstring -static, $(TARGET_FLAGS)))
+LDFLAGS += -Wl,--whole-archive -lpthread -Wl,--no-whole-archive
+endif
 endif
 
 LDFLAGS += -lstdc++ -pthread