[llvm] [runtimes] Skip linker validation in per-target runtime sub-builds (PR #189933)
Wenju He via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 15:47:19 PDT 2026
https://github.com/wenju-he updated https://github.com/llvm/llvm-project/pull/189933
>From 8f88097508f5269c74dd58ade79ea18bd0104721 Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Wed, 1 Apr 2026 12:34:06 +0200
Subject: [PATCH 1/2] [runtimes] Skip linker validation in per-target runtime
sub-builds
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 has the risk of skipping linker check for non-offload
cross-build. The risk is low because
- we can assume just-built clang works with -fuse-ld.
- if user specifies invalid custom linker. Link fail will appear in
build step.
---
llvm/cmake/modules/HandleLLVMOptions.cmake | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index f645de1277687..db247215a17bc 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -431,12 +431,17 @@ endif()
if( LLVM_USE_LINKER )
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}'.")
+ # Skip linker validation in per-target runtime sub-builds since GPU/offload
+ # targets cannot link test executables via the cross-compiler. For other
+ # targets, linker configuration errors will be caught later at build time.
+ if(NOT LLVM_RUNTIMES_TARGET)
+ 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()
endif()
endif()
>From 4c2cab66306d69fdb74094630b27a0245dd5c6f6 Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Fri, 3 Apr 2026 00:42:47 +0200
Subject: [PATCH 2/2] baseline test if target supports linking executable
---
llvm/cmake/modules/HandleLLVMOptions.cmake | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index db247215a17bc..5f1d68762c038 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -429,12 +429,11 @@ 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)
- # Skip linker validation in per-target runtime sub-builds since GPU/offload
- # targets cannot link test executables via the cross-compiler. For other
- # targets, linker configuration errors will be caught later at build time.
- if(NOT LLVM_RUNTIMES_TARGET)
+ 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}'. "
@@ -442,6 +441,8 @@ if( LLVM_USE_LINKER )
"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()
More information about the llvm-commits
mailing list