Skip to content

Commit b052eea

Browse files
GleasonKjoker-eph
authored andcommitted
Fix -fuse-ld to be linker flag in feature detection check
Discovered an issue working in StableHLO when attempting to build with `-Wall -Werror`: openxla/stablehlo#137 Currently, if `LLVM_USE_LLD` and `-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -Wall -Werror"` are both specified for build, the build will error with: ``` -- Performing Test CXX_SUPPORTS_CUSTOM_LINKER - Failed CMake Error at /usr/local/google/home/gleasonk/Coding/llvm-build/lib/cmake/llvm/HandleLLVMOptions.cmake:309 (message): Host compiler does not support '-fuse-ld=lld' ... $ cat <build_dir>/CMakeFiles/CMakeError.log ... clang: error: argument unused during compilation: '-fuse-ld=lld' [-Werror,-Wunused-command-line-argument] ``` It looks like other repos have hit this same issue: - golang/go#41527 (mentioned in comment) - iree-org/iree#7450 This can be reproduced in llvm-project with the following build command: ``` # Compile command taken from https://mlir.llvm.org/getting_started/ # and modified for use case cmake -G Ninja ../llvm \ -DLLVM_ENABLE_PROJECTS=mlir \ -DLLVM_BUILD_EXAMPLES=ON \ -DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU" \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_ENABLE_ASSERTIONS=ON \ -DCMAKE_CXX_COMPILER=clang++ \ -DCMAKE_C_COMPILER=clang \ -DLLVM_ENABLE_LLD=ON \ -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -Wall -Werror" ``` Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D134206
1 parent f5fe92f commit b052eea

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,12 @@ if( LLVM_ENABLE_LLD )
302302
endif()
303303

304304
if( LLVM_USE_LINKER )
305-
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
306-
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fuse-ld=${LLVM_USE_LINKER}")
305+
append("-fuse-ld=${LLVM_USE_LINKER}"
306+
CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
307307
check_cxx_source_compiles("int main() { return 0; }" CXX_SUPPORTS_CUSTOM_LINKER)
308308
if ( NOT CXX_SUPPORTS_CUSTOM_LINKER )
309309
message(FATAL_ERROR "Host compiler does not support '-fuse-ld=${LLVM_USE_LINKER}'")
310310
endif()
311-
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
312-
append("-fuse-ld=${LLVM_USE_LINKER}"
313-
CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
314311
endif()
315312

316313
if( LLVM_ENABLE_PIC )

0 commit comments

Comments
 (0)