krisb created this revision. krisb added reviewers: phosek, thakis, russell.gallop. Herald added subscribers: llvm-commits, cfe-commits, mgorny. Herald added projects: clang, LLVM.
(I'm trying to get a bootstrap self-build on Windows, where lld is used as a linker for the stage2.) I assume BOOTSTRAP_LLVM_ENABLE_LLD works the same way as LLVM_ENABLE_LLD, but enables to use just-built lld for the next stage. The issue with LLVM_ENABLE_LLD is that it just passes -fuse-ld=lld to compiler/linker options which makes sense only for those platforms where cmake invokes a compiler driver for linking. On Windows cmake invokes a linker directly and requires CMAKE_LINKER option to be specified otherwise it defaults CMAKE_LINKER to be link.exe. Passing CMAKE_LINKER is easy for 1-stage builds, but it's notquite handy to do for multistage builds, because it's not possible to know for sure where to find just-built lld. This patch allows BOOTSTRAP_LLVM_ENABLE_LLD to set CMAKE_LINKER in the case of building for host Windows. It also skips adding '-fuse-ld=lld' to make lld-link not warning about 'unknown argument'. The latter part is taken from https://reviews.llvm.org/D69030 with additional checks that CMAKE_LINKER doesn't contain a path to another compiler. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D80873 Files: clang/CMakeLists.txt llvm/cmake/modules/HandleLLVMOptions.cmake Index: llvm/cmake/modules/HandleLLVMOptions.cmake =================================================================== --- llvm/cmake/modules/HandleLLVMOptions.cmake +++ llvm/cmake/modules/HandleLLVMOptions.cmake @@ -264,7 +264,15 @@ set(LLVM_USE_LINKER "lld") endif() -if( LLVM_USE_LINKER ) +# cmake defaults to invoke a linker directly on Windows, so skip adding +# '-fuse-ld' flag in this case. +if( LINKER_IS_LLD_LINK AND ( NOT CMAKE_LINKER OR CMAKE_LINKER MATCHES "lld-link" )) + set(IS_FUSE_LD_FLAG_NEEDED FALSE) +else() + set(IS_FUSE_LD_FLAG_NEEDED TRUE) +endif() + +if( LLVM_USE_LINKER AND IS_FUSE_LD_FLAG_NEEDED ) set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fuse-ld=${LLVM_USE_LINKER}") check_cxx_source_compiles("int main() { return 0; }" CXX_SUPPORTS_CUSTOM_LINKER) Index: clang/CMakeLists.txt =================================================================== --- clang/CMakeLists.txt +++ clang/CMakeLists.txt @@ -745,6 +745,14 @@ -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/${C_COMPILER} -DCMAKE_ASM_COMPILER_ID=Clang) + # cmake requires CMAKE_LINKER to be specified in case of MSVC or it defaults + # the linker to be link.exe. + if(BOOTSTRAP_LLVM_ENABLE_LLD) + if(MSVC AND NOT BOOTSTRAP_CMAKE_SYSTEM_NAME) + set(${CLANG_STAGE}_LINKER -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link.exe) + endif() + endif() + if(BOOTSTRAP_CMAKE_SYSTEM_NAME) set(${CLANG_STAGE}_CONFIG -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config) set(${CLANG_STAGE}_TABLEGEN
Index: llvm/cmake/modules/HandleLLVMOptions.cmake =================================================================== --- llvm/cmake/modules/HandleLLVMOptions.cmake +++ llvm/cmake/modules/HandleLLVMOptions.cmake @@ -264,7 +264,15 @@ set(LLVM_USE_LINKER "lld") endif() -if( LLVM_USE_LINKER ) +# cmake defaults to invoke a linker directly on Windows, so skip adding +# '-fuse-ld' flag in this case. +if( LINKER_IS_LLD_LINK AND ( NOT CMAKE_LINKER OR CMAKE_LINKER MATCHES "lld-link" )) + set(IS_FUSE_LD_FLAG_NEEDED FALSE) +else() + set(IS_FUSE_LD_FLAG_NEEDED TRUE) +endif() + +if( LLVM_USE_LINKER AND IS_FUSE_LD_FLAG_NEEDED ) set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fuse-ld=${LLVM_USE_LINKER}") check_cxx_source_compiles("int main() { return 0; }" CXX_SUPPORTS_CUSTOM_LINKER) Index: clang/CMakeLists.txt =================================================================== --- clang/CMakeLists.txt +++ clang/CMakeLists.txt @@ -745,6 +745,14 @@ -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/${C_COMPILER} -DCMAKE_ASM_COMPILER_ID=Clang) + # cmake requires CMAKE_LINKER to be specified in case of MSVC or it defaults + # the linker to be link.exe. + if(BOOTSTRAP_LLVM_ENABLE_LLD) + if(MSVC AND NOT BOOTSTRAP_CMAKE_SYSTEM_NAME) + set(${CLANG_STAGE}_LINKER -DCMAKE_LINKER=${LLVM_RUNTIME_OUTPUT_INTDIR}/lld-link.exe) + endif() + endif() + if(BOOTSTRAP_CMAKE_SYSTEM_NAME) set(${CLANG_STAGE}_CONFIG -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config) set(${CLANG_STAGE}_TABLEGEN
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits