This is an archive of the discontinued LLVM Phabricator instance.

Fix -fuse-ld to be linker flag in feature detection check
ClosedPublic

Authored by GleasonK on Sep 19 2022, 12:11 PM.

Details

Summary

Discovered an issue working in StableHLO when attempting to build with -Wall -Werror:
https://github.com/openxla/stablehlo/pull/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:

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"

Diff Detail

Event Timeline

GleasonK created this revision.Sep 19 2022, 12:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 19 2022, 12:11 PM
GleasonK requested review of this revision.Sep 19 2022, 12:11 PM

I have similar issues, but I use -DLLVM_ENABLE_WERROR=ON.

I have similar issues, but I use -DLLVM_ENABLE_WERROR=ON.

That is what I ended up doing in https://github.com/openxla/stablehlo/pull/137 (LLVM_ENABLE_WERROR / LLVM_ENABLE_WARNINGS), which unblocked me. Based on conversation with Mehdi in that thread I figured I would still propose this fix, since it was strange for -fuse-ld to end up in the cxx flags instead of linker flags.

It looks like check_cxx_source_compiles picks up changes to CMAKE_EXE_LINKER_FLAGS, since setting a nonsense value like -DLLVM_USE_LINKER=notalinker will still error on this line.

mehdi_amini accepted this revision.Sep 19 2022, 10:05 PM
This revision is now accepted and ready to land.Sep 19 2022, 10:05 PM

I guess you need me to land this for you?

Yes, thanks. I just tried and got 403 from the remote.

This revision was automatically updated to reflect the committed changes.