[llvm] r273302 - [build] Make sure to link main executable with pthreads

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 21 14:28:56 PDT 2016


Looks like this broke the ocaml binding:

http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/37461/steps/test/logs/stdio

On 21 June 2016 at 15:34, Artem Belevich via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: tra
> Date: Tue Jun 21 14:34:40 2016
> New Revision: 273302
>
> URL: http://llvm.org/viewvc/llvm-project?rev=273302&view=rev
> Log:
> [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
>
> Modified:
>     llvm/trunk/cmake/config-ix.cmake
>     llvm/trunk/cmake/modules/AddLLVM.cmake
>     llvm/trunk/tools/llvm-config/CMakeLists.txt
>
> Modified: llvm/trunk/cmake/config-ix.cmake
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/config-ix.cmake?rev=273302&r1=273301&r2=273302&view=diff
> ==============================================================================
> --- llvm/trunk/cmake/config-ix.cmake (original)
> +++ llvm/trunk/cmake/config-ix.cmake Tue Jun 21 14:34:40 2016
> @@ -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
>
> Modified: llvm/trunk/cmake/modules/AddLLVM.cmake
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=273302&r1=273301&r2=273302&view=diff
> ==============================================================================
> --- llvm/trunk/cmake/modules/AddLLVM.cmake (original)
> +++ llvm/trunk/cmake/modules/AddLLVM.cmake Tue Jun 21 14:34:40 2016
> @@ -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_na
>    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)
>
> Modified: llvm/trunk/tools/llvm-config/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-config/CMakeLists.txt?rev=273302&r1=273301&r2=273302&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-config/CMakeLists.txt (original)
> +++ llvm/trunk/tools/llvm-config/CMakeLists.txt Tue Jun 21 14:34:40 2016
> @@ -14,7 +14,13 @@ foreach(l ${LLVM_SYSTEM_LIBS_LIST})
>    if(MSVC)
>      set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}.lib")
>    else()
> -    set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
> +    if (l MATCHES "^-")
> +      # If it's an option, pass it without changes.
> +      set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}")
> +    else()
> +      # Otherwise assume it's a library name we need to link with.
> +      set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
> +    endif()
>    endif()
>  endforeach()
>  string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}")
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list