Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -106,6 +106,7 @@ 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 @@ 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) Index: src/CMakeLists.txt =================================================================== --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -47,7 +47,9 @@ # 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) Index: test/CMakeLists.txt =================================================================== --- test/CMakeLists.txt +++ test/CMakeLists.txt @@ -10,6 +10,7 @@ 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!") Index: test/lit.cfg =================================================================== --- test/lit.cfg +++ test/lit.cfg @@ -199,6 +199,12 @@ 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 @@ 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 @@ link_flags += shlex.split(link_flags_str) # Configure extra compiler flags. +if not enable_threads: + compile_flags += ['-DLIBCXXABI_HAS_NO_THREADS=1'] san = lit_config.params.get('llvm_use_sanitizer', None) if san is None: Index: test/lit.site.cfg.in =================================================================== --- test/lit.site.cfg.in +++ test/lit.site.cfg.in @@ -6,6 +6,7 @@ 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. Index: test/test_exception_storage.cpp =================================================================== --- test/test_exception_storage.cpp +++ test/test_exception_storage.cpp @@ -56,7 +56,10 @@ #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 ) Index: test/test_guard.cpp =================================================================== --- test/test_guard.cpp +++ test/test_guard.cpp @@ -7,10 +7,14 @@ // //===----------------------------------------------------------------------===// +#include "../src/config.h" #include "cxxabi.h" #include + +#if !LIBCXXABI_HAS_NO_THREADS #include +#endif // Ensure that we initialize each variable once and only once. namespace test1 { @@ -72,6 +76,7 @@ } } +#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 @@ 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 }