From 1839b755ddf0993ab1fd962028b21986097e3ccd Mon Sep 17 00:00:00 2001 From: Wenju He Date: Mon, 6 Apr 2026 07:18:36 +0800 Subject: [PATCH] [runtimes] Skip custom linker validation for gpu/offload targets (#189933) This fixes `Host compiler does not support '-fuse-ld=lld'` error when cross-build libclc for gpu target. Cmake configure command is: -DRUNTIMES_amdgcn-amd-amdhsa-llvm_LLVM_ENABLE_RUNTIMES=libclc \ -DLLVM_RUNTIME_TARGETS="amdgcn-amd-amdhsa-llvm" libclc targets only support offload target cross-build and can't link host executable. The configuration error is false positive for offload. This PR adds a baseline test to first check if the target can link executable. If it fails (typical for gpu/offload), we skip the custom linker validation. --- llvm/cmake/modules/HandleLLVMOptions.cmake | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake index f645de127768..5f1d68762c03 100644 --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -429,14 +429,20 @@ if( LLVM_ENABLE_LLD ) endif() if( LLVM_USE_LINKER ) + check_cxx_source_compiles("int main() { return 0; }" _CAN_LINK_EXECUTABLE) + mark_as_advanced(_CAN_LINK_EXECUTABLE) append("-fuse-ld=${LLVM_USE_LINKER}" CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) - check_cxx_source_compiles("int main() { return 0; }" CXX_SUPPORTS_CUSTOM_LINKER) - if ( NOT CXX_SUPPORTS_CUSTOM_LINKER ) - message(FATAL_ERROR "Host compiler does not support '-fuse-ld=${LLVM_USE_LINKER}'. " - "Please make sure that '${LLVM_USE_LINKER}' is installed and " - "that your host compiler can compile a simple program when " - "given the option '-fuse-ld=${LLVM_USE_LINKER}'.") + if(_CAN_LINK_EXECUTABLE) + check_cxx_source_compiles("int main() { return 0; }" CXX_SUPPORTS_CUSTOM_LINKER) + if ( NOT CXX_SUPPORTS_CUSTOM_LINKER ) + message(FATAL_ERROR "Host compiler does not support '-fuse-ld=${LLVM_USE_LINKER}'. " + "Please make sure that '${LLVM_USE_LINKER}' is installed and " + "that your host compiler can compile a simple program when " + "given the option '-fuse-ld=${LLVM_USE_LINKER}'.") + endif() + else() + message(STATUS "Skipping custom linker check: offload target cannot link executable") endif() endif()