lang/ldc: fix build with LLVM_DEFAULT=19

When building lang/ldc with LLVM_DEFAULT=19, linking ldc-profdata fails with:

  FAILED: bin/ldc-profdata
  : && /usr/local/llvm19/bin/clang++ -O2 -pipe -fPIC -fstack-protector-strong -fno-strict-aliasing -DDMDV2 -O2 -pipe -fPIC -fstack-protector-strong -fno-strict-aliasing   -DNDEBUG -fstack-protector-strong     -Xlinker --dependency-file=tools/CMakeFiles/ldc-profdata.dir/link.d tools/CMakeFiles/ldc-profdata.dir/ldc-profdata/llvm-profdata-19.1.cpp.o -o bin/ldc-profdata  -lLLVM-19  -L/usr/local/llvm19/lib && :
  ld: error: undefined symbol: pthread_create
  >>> referenced by llvm-profdata-19.1.cpp
  >>>               tools/CMakeFiles/ldc-profdata.dir/ldc-profdata/llvm-profdata-19.1.cpp.o:(std::__1::future<void> std::__1::__make_async_assoc_state[abi:sn190107]<void, std::__1::__async_func<std::__1::function<void ()>>>(std::__1::__async_func<std::__1::function<void ()>>&&))
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)

This is because the link command line is missing -lpthread. For the
tools/ subdirectory, use the CMAKE_THREAD_LIBS_INIT macro to fix the
target_link_libraries() directive.

PR:		284344
Approved by:	acm (maintainer)
MFH:		2025Q1
This commit is contained in:
Dimitry Andric 2025-01-25 17:45:16 +01:00
parent 562276ce0e
commit c580801b31

View file

@ -0,0 +1,11 @@
--- tools/CMakeLists.txt.orig 2024-12-15 13:48:09 UTC
+++ tools/CMakeLists.txt
@@ -37,7 +37,7 @@ if(LDC_BUNDLE_LLVM_TOOLS)
COMPILE_FLAGS "${LLVM_CXXFLAGS} ${LDC_CXXFLAGS}"
LINK_FLAGS "${SANITIZE_LDFLAGS}"
)
- target_link_libraries(ldc-profdata ${LLVM_LIBRARIES} ${CMAKE_DL_LIBS} ${LLVM_LDFLAGS})
+ target_link_libraries(ldc-profdata ${LLVM_LIBRARIES} ${CMAKE_DL_LIBS} ${LLVM_LDFLAGS} ${CMAKE_THREAD_LIBS_INIT})
install(TARGETS ldc-profdata DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
# Set path to executable, used by the lit testsuite.