diff options
author | Artem Belevich <tra@google.com> | 2016-06-21 19:34:40 +0000 |
---|---|---|
committer | Artem Belevich <tra@google.com> | 2016-06-21 19:34:40 +0000 |
commit | 1e67d66d5e91cf784f1606f5a22642581aa55762 (patch) | |
tree | 367fefc9ef60a56e61878e0c08ab679d2fbd613e /cmake | |
parent | 604d3935d1816f28479562be67c7f96b49c2a951 (diff) |
[build] Make sure to link main executable with pthreads
Otherwise it gets linked in by one of the dependencies of shared
libraries which may be too late and we end up with weird crashes in
std::call_once().
Differential Revision: http://reviews.llvm.org/D21478
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273302 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake')
-rwxr-xr-x | cmake/config-ix.cmake | 8 | ||||
-rw-r--r-- | cmake/modules/AddLLVM.cmake | 11 |
2 files changed, 17 insertions, 2 deletions
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake index 400ce32f835..b363a357c58 100755 --- a/cmake/config-ix.cmake +++ b/cmake/config-ix.cmake @@ -110,7 +110,13 @@ if( NOT PURE_WINDOWS ) endif() if(HAVE_LIBPTHREAD) - set(PTHREAD_LIB pthread) + # We want to find pthreads library and at the moment we do want to + # have it reported as '-l<lib>' instead of '-pthread'. + # TODO: switch to -pthread once the rest of the build system can deal with it. + set(CMAKE_THREAD_PREFER_PTHREAD TRUE) + set(THREADS_HAVE_PTHREAD_ARG Off) + find_package(Threads REQUIRED) + set(PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT}) endif() # Don't look for these libraries on Windows. Also don't look for them if we're diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake index 0f9d181216f..ba507ddb56d 100644 --- a/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake @@ -670,6 +670,12 @@ macro(add_llvm_executable name) if(NOT ARG_IGNORE_EXTERNALIZE_DEBUGINFO) llvm_externalize_debuginfo(${name}) endif() + if (PTHREAD_LIB) + # libpthreads overrides some standard library symbols, so main + # executable must be linked with it in order to provide consistent + # API for all shared libaries loaded by this executable. + target_link_libraries(${name} ${PTHREAD_LIB}) + endif() endmacro(add_llvm_executable name) function(export_executable_symbols target) @@ -953,7 +959,10 @@ function(add_unittest test_suite test_name) add_llvm_executable(${test_name} IGNORE_EXTERNALIZE_DEBUGINFO ${ARGN}) set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}) set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir}) - target_link_libraries(${test_name} gtest_main gtest) + # libpthreads overrides some standard library symbols, so main + # executable must be linked with it in order to provide consistent + # API for all shared libaries loaded by this executable. + target_link_libraries(${test_name} gtest_main gtest ${PTHREAD_LIB}) add_dependencies(${test_suite} ${test_name}) get_target_property(test_suite_folder ${test_suite} FOLDER) |