[libcxxabi] r222702 - [libcxxabi] Refactor building and testing libc++abi without threads

Eric Fiselier eric at efcs.ca
Mon Nov 24 14:42:03 PST 2014


Author: ericwf
Date: Mon Nov 24 16:42:03 2014
New Revision: 222702

URL: http://llvm.org/viewvc/llvm-project?rev=222702&view=rev
Log:
[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

Modified:
    libcxxabi/trunk/CMakeLists.txt
    libcxxabi/trunk/src/CMakeLists.txt
    libcxxabi/trunk/test/CMakeLists.txt
    libcxxabi/trunk/test/lit.cfg
    libcxxabi/trunk/test/lit.site.cfg.in
    libcxxabi/trunk/test/test_exception_storage.cpp
    libcxxabi/trunk/test/test_guard.cpp

Modified: libcxxabi/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=222702&r1=222701&r2=222702&view=diff
==============================================================================
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Mon Nov 24 16:42:03 2014
@@ -106,6 +106,7 @@ option(LIBCXXABI_ENABLE_ASSERTIONS "Enab
 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)

Modified: libcxxabi/trunk/src/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/CMakeLists.txt?rev=222702&r1=222701&r2=222702&view=diff
==============================================================================
--- libcxxabi/trunk/src/CMakeLists.txt (original)
+++ libcxxabi/trunk/src/CMakeLists.txt Mon Nov 24 16:42:03 2014
@@ -47,7 +47,9 @@ include_directories("${LIBCXXABI_LIBCXX_
 # 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)

Modified: libcxxabi/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/CMakeLists.txt?rev=222702&r1=222701&r2=222702&view=diff
==============================================================================
--- libcxxabi/trunk/test/CMakeLists.txt (original)
+++ libcxxabi/trunk/test/CMakeLists.txt Mon Nov 24 16:42:03 2014
@@ -10,6 +10,7 @@ set(LIBCXXABI_COMPILER ${CMAKE_CXX_COMPI
 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!")

Modified: libcxxabi/trunk/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/lit.cfg?rev=222702&r1=222701&r2=222702&view=diff
==============================================================================
--- libcxxabi/trunk/test/lit.cfg (original)
+++ libcxxabi/trunk/test/lit.cfg Mon Nov 24 16:42:03 2014
@@ -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.

Modified: libcxxabi/trunk/test/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/lit.site.cfg.in?rev=222702&r1=222701&r2=222702&view=diff
==============================================================================
--- libcxxabi/trunk/test/lit.site.cfg.in (original)
+++ libcxxabi/trunk/test/lit.site.cfg.in Mon Nov 24 16:42:03 2014
@@ -6,6 +6,7 @@ config.python_executable     = "@PYTHON_
 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.

Modified: libcxxabi/trunk/test/test_exception_storage.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/test_exception_storage.cpp?rev=222702&r1=222701&r2=222702&view=diff
==============================================================================
--- libcxxabi/trunk/test/test_exception_storage.cpp (original)
+++ libcxxabi/trunk/test/test_exception_storage.cpp Mon Nov 24 16:42:03 2014
@@ -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 )

Modified: libcxxabi/trunk/test/test_guard.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/test_guard.cpp?rev=222702&r1=222701&r2=222702&view=diff
==============================================================================
--- libcxxabi/trunk/test/test_guard.cpp (original)
+++ libcxxabi/trunk/test/test_guard.cpp Mon Nov 24 16:42:03 2014
@@ -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
 }





More information about the cfe-commits mailing list