[PATCH] D40326: Fix static link on debian

Rafael Ávila de Espíndola via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 21 15:13:11 PST 2017


rafael created this revision.
Herald added a subscriber: mgorny.

On fedora based distros libpthread.a has a single .o file created with ld -r. That means that just one reference will pull the entire library.

On debian based systems that is not the case and we need whole archive when static linking.

Without this a static linked lld will crash on startup. It calls std::thread functions which try to call the corresponding pthread_* function but fail because they use a weak reference to pthread_* which is resolved to 0.


https://reviews.llvm.org/D40326

Files:
  cmake/config-ix.cmake


Index: cmake/config-ix.cmake
===================================================================
--- cmake/config-ix.cmake
+++ cmake/config-ix.cmake
@@ -124,7 +124,7 @@
   set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
   set(THREADS_HAVE_PTHREAD_ARG Off)
   find_package(Threads REQUIRED)
-  set(LLVM_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
+  set(LLVM_PTHREAD_LIB -Wl,--whole-archive ${CMAKE_THREAD_LIBS_INIT} -Wl,--no-whole-archive)
 endif()
 
 # Don't look for these libraries on Windows. Also don't look for them if we're


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40326.123858.patch
Type: text/x-patch
Size: 517 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171121/4c618d4d/attachment.bin>


More information about the llvm-commits mailing list