[llvm] [CMake] Set LLVM_USE_LINKER for external projects when using lld (PR #170401)
Zachary Fogg via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 2 18:15:15 PST 2025
https://github.com/zfogg created https://github.com/llvm/llvm-project/pull/170401
## Summary
When lld is in TOOLCHAIN_TOOLS, LLVMExternalProjectUtils sets CMAKE_LINKER to ld.lld for external projects. However, clang
does not use CMAKE_LINKER on Linux - it requires to be passed via linker flags.
This causes build failures when , because the runtimes build ends up using the system linker (e.g.,
) which cannot process LLVM bitcode in static archives:
Fix this by setting , which allows HandleLLVMOptions.cmake to properly append to the
linker flags.
## Test plan
- [x] Build LLVM with (previously failed, now succeeds)
- [ ] Verify runtimes link with lld instead of system linker
>From b4d3854a5658cb6b198714c0c36057ed0dd64269 Mon Sep 17 00:00:00 2001
From: Zachary Fogg <me at zfo.gg>
Date: Tue, 2 Dec 2025 21:13:35 -0500
Subject: [PATCH] [CMake] Set LLVM_USE_LINKER for external projects when using
lld
When lld is in TOOLCHAIN_TOOLS, LLVMExternalProjectUtils sets
CMAKE_LINKER to ld.lld for external projects. However, clang does not
use CMAKE_LINKER on Linux - it requires -fuse-ld=lld to be passed
via linker flags.
This causes build failures when LLVM_ENABLE_LTO is enabled, because
the runtimes build ends up using the system linker (e.g., /usr/bin/ld)
which cannot process LLVM bitcode in static archives:
/usr/bin/ld: libclangTidy.a: error adding symbols: file format not recognized
Fix this by setting LLVM_USE_LINKER=lld, which allows
HandleLLVMOptions.cmake to properly append -fuse-ld=lld to the
linker flags.
---
llvm/cmake/modules/LLVMExternalProjectUtils.cmake | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
index 975798a8c2636..bcd60f6336232 100644
--- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -242,6 +242,7 @@ function(llvm_ExternalProject_Add name source_dir)
list(APPEND compiler_args -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link${CMAKE_EXECUTABLE_SUFFIX})
elseif(NOT _cmake_system_name STREQUAL Darwin)
list(APPEND compiler_args -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/ld.lld${CMAKE_EXECUTABLE_SUFFIX})
+ list(APPEND compiler_args -DLLVM_USE_LINKER=lld)
endif()
endif()
if(llvm-ar IN_LIST TOOLCHAIN_TOOLS)
More information about the llvm-commits
mailing list