summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2014-11-24 22:42:03 +0000
committerEric Fiselier <eric@efcs.ca>2014-11-24 22:42:03 +0000
commit559f867af23c4bf53df1fdd2294450b86fb88c8e (patch)
tree97fd1d2a1b32c0fbb1350d868f805b6e1731ca12
parentc5de7b113b53a72ea02ea269d81151e8b3c3f9df (diff)
downloadbcm5719-llvm-559f867af23c4bf53df1fdd2294450b86fb88c8e.tar.gz
bcm5719-llvm-559f867af23c4bf53df1fdd2294450b86fb88c8e.zip
[libcxxabi] Refactor building and testing libc++abi without threads
Summary: This patch adds CMake support for building and testing libc++abi without threads. 1. Add `LIBCXXABI_ENABLE_THREADS` option to CMake. 2. Propagate `LIBCXXABI_ENABLE_THREADS` to lit via lit.site.cfg.in 3. Configure tests for `LIBCXXABI_ENABLE_THREADS=OFF Currently the test suite does not work when libc++abi is built without threads because that information does not propagate to the test suite. Reviewers: danalbert, mclow.lists, jroelofs Reviewed By: jroelofs Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D6393 llvm-svn: 222702
-rw-r--r--libcxxabi/CMakeLists.txt5
-rw-r--r--libcxxabi/src/CMakeLists.txt4
-rw-r--r--libcxxabi/test/CMakeLists.txt1
-rw-r--r--libcxxabi/test/lit.cfg12
-rw-r--r--libcxxabi/test/lit.site.cfg.in1
-rw-r--r--libcxxabi/test/test_exception_storage.cpp5
-rw-r--r--libcxxabi/test/test_guard.cpp8
7 files changed, 33 insertions, 3 deletions
diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index 1e472bf7a4b..c3262652704 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -106,6 +106,7 @@ option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode.
option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
+option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON)
# Default to building a shared library so that the default options still test
# the libc++abi that is being built. There are two problems with testing a
@@ -226,6 +227,10 @@ if (NOT LIBCXXABI_ENABLE_SHARED)
list(APPEND LIBCXXABI_COMPILE_FLAGS -D_LIBCPP_BUILD_STATIC)
endif()
+if (NOT LIBCXXABI_ENABLE_THREADS)
+ add_definitions(-DLIBCXXABI_HAS_NO_THREADS=1)
+endif()
+
# This is the _ONLY_ place where add_definitions is called.
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index 336785080ae..08920e2d0ce 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -47,7 +47,9 @@ include_directories("${LIBCXXABI_LIBCXX_INCLUDES}")
# Generate library list.
set(libraries ${LIBCXXABI_CXX_ABI_LIBRARIES})
append_if(libraries LIBCXXABI_HAS_C_LIB c)
-append_if(libraries LIBCXXABI_HAS_PTHREAD_LIB pthread)
+if (LIBCXXABI_ENABLE_THREADS)
+ append_if(libraries LIBCXXABI_HAS_PTHREAD_LIB pthread)
+endif()
if (LIBCXXABI_USE_LLVM_UNWINDER)
list(APPEND libraries unwind)
diff --git a/libcxxabi/test/CMakeLists.txt b/libcxxabi/test/CMakeLists.txt
index 1383cd71133..57468dcc849 100644
--- a/libcxxabi/test/CMakeLists.txt
+++ b/libcxxabi/test/CMakeLists.txt
@@ -10,6 +10,7 @@ set(LIBCXXABI_COMPILER ${CMAKE_CXX_COMPILER})
set(LIBCXXABI_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(LIBCXXABI_BINARY_DIR ${CMAKE_BINARY_DIR})
pythonize_bool(LIBCXXABI_ENABLE_SHARED)
+pythonize_bool(LIBCXXABI_ENABLE_THREADS)
pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
set(AUTO_GEN_COMMENT "## Autogenerated by libcxxabi configuration.\n# Do not edit!")
diff --git a/libcxxabi/test/lit.cfg b/libcxxabi/test/lit.cfg
index 2d7c4033027..20d5822c635 100644
--- a/libcxxabi/test/lit.cfg
+++ b/libcxxabi/test/lit.cfg
@@ -199,6 +199,12 @@ if enable_shared is None:
if enable_shared is None:
lit_config.fatal("enable_shared must be defined")
+enable_threads = lit_config.params.get('enable_threads', None)
+if enable_threads is None:
+ enable_threads = getattr(config, 'enable_threads', None)
+ if enable_threads is None:
+ lit_config.fatal('enable_threads must be defined')
+
llvm_unwinder = getattr(config, 'llvm_unwinder', None)
if llvm_unwinder is None:
lit_config.fatal("llvm_unwinder must be defined")
@@ -223,7 +229,9 @@ if link_flags_str is None:
elif sys.platform.startswith('linux'):
if not llvm_unwinder:
link_flags += ['-lgcc_eh']
- link_flags += ['-lc', '-lm', '-lpthread']
+ link_flags += ['-lc', '-lm']
+ if enable_threads:
+ link_flags += ['-lpthread']
if llvm_unwinder:
link_flags += ['-lunwind', '-ldl']
else:
@@ -236,6 +244,8 @@ if link_flags_str is not None:
link_flags += shlex.split(link_flags_str)
# Configure extra compiler flags.
+if not enable_threads:
+ compile_flags += ['-DLIBCXXABI_HAS_NO_THREADS=1']
# Always disable timed test when using LIT since the output gets lost and since
# using the timer requires <chrono> as a dependancy.
diff --git a/libcxxabi/test/lit.site.cfg.in b/libcxxabi/test/lit.site.cfg.in
index bb62387a230..9753e1d9123 100644
--- a/libcxxabi/test/lit.site.cfg.in
+++ b/libcxxabi/test/lit.site.cfg.in
@@ -6,6 +6,7 @@ config.python_executable = "@PYTHON_EXECUTABLE@"
config.enable_shared = @LIBCXXABI_ENABLE_SHARED@
config.libcxx_includes = "@LIBCXXABI_LIBCXX_INCLUDES@"
config.llvm_unwinder = @LIBCXXABI_USE_LLVM_UNWINDER@
+config.enable_threads = @LIBCXXABI_ENABLE_THREADS@
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
# Let the main config do the real work.
diff --git a/libcxxabi/test/test_exception_storage.cpp b/libcxxabi/test/test_exception_storage.cpp
index f1e2fb5e477..0d5deaa3735 100644
--- a/libcxxabi/test/test_exception_storage.cpp
+++ b/libcxxabi/test/test_exception_storage.cpp
@@ -56,7 +56,10 @@ int main ( int argc, char *argv [] ) {
#if LIBCXXABI_HAS_NO_THREADS
size_t thread_globals;
- retVal = thread_code(&thread_globals) != 0;
+ // Check that __cxa_get_globals() is not NULL.
+ if (thread_code(&thread_globals) == 0) {
+ retVal = 1;
+ }
#else
// Make the threads, let them run, and wait for them to finish
for ( int i = 0; i < NUMTHREADS; ++i )
diff --git a/libcxxabi/test/test_guard.cpp b/libcxxabi/test/test_guard.cpp
index 96af56a7be1..41ff79432b5 100644
--- a/libcxxabi/test/test_guard.cpp
+++ b/libcxxabi/test/test_guard.cpp
@@ -7,10 +7,14 @@
//
//===----------------------------------------------------------------------===//
+#include "../src/config.h"
#include "cxxabi.h"
#include <cassert>
+
+#if !LIBCXXABI_HAS_NO_THREADS
#include <thread>
+#endif
// Ensure that we initialize each variable once and only once.
namespace test1 {
@@ -72,6 +76,7 @@ namespace test3 {
}
}
+#if !LIBCXXABI_HAS_NO_THREADS
// A simple thread test of two threads racing to initialize a variable. This
// isn't guaranteed to catch any particular threading problems.
namespace test4 {
@@ -123,12 +128,15 @@ namespace test5 {
assert(run_count == 1);
}
}
+#endif /* LIBCXXABI_HAS_NO_THREADS */
int main()
{
test1::test();
test2::test();
test3::test();
+#if !LIBCXXABI_HAS_NO_THREADS
test4::test();
test5::test();
+#endif
}
OpenPOWER on IntegriCloud