This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Skip linker check if the LLVM_LINKER_SKIP_TEST is set
Needs ReviewPublic

Authored by psamolysov on May 31 2022, 6:52 AM.

Details

Summary

CMake has a set of 'CMAKE_<LANG>_COMPILER_WORKS' variables to skip checking
of the corresponding compiler during the configuration phase what is used by
LLVM to build runtimes: the llvm/runtimes/CMakeLists.txt file contains calls
of the llvm_ExternalProject_Add function to build the runtime components and
on these calls all the 'CMAKE_<LANG>_COMPILER_WORKS' variables are set to
'ON'.

The patch introduces a new similar variable 'LLVM_LINKER_SKIP_TEST' that is
used to skip checking of the used linker if the 'LLVM_USE_LINKER' variable
is set. The check should be skipped during building runtime components for
non-host environments: at this time the required libraries (libunwind,
builtins, crt, etc.) are not ready and the check will false positive fail.

Diff Detail

Event Timeline

psamolysov created this revision.May 31 2022, 6:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2022, 6:52 AM
Herald added a subscriber: mgorny. · View Herald Transcript
psamolysov requested review of this revision.May 31 2022, 6:52 AM

I think I rather would name the variable LLVM_LINKER_SKIP_TEST or something like that. I don't like the cmake variable name and since it's not something upstream we are adding I think I rather use a more descriptive name.

That said - I am a bit confused as to why this is not working correctly? Can you show how it fails when you need to set this variable?

Colleagues, I propose this change to make the runtime components buildable with a "not-ready yet" lld linker and libraries. One disadvantage I see, when the LLVM_USE_LINKER is not set, the CMake issues warnings about the unused variable LLVM_LINKER_WORKS.

psamolysov added a comment.EditedMay 31 2022, 7:05 AM

@thieta A problem occurs when I try to build LLVM with runtime components for RISCV, for example, and in fact, CMake cross-compiles the components in this case. So, If I set -DLLVM_ENABLE_LLD=ON, the following errors are issued due to LLVM's attempt to check the linker:

ld.lld: error: cannot open crtbeginS.o: No such file or directory
ld.lld: error: cannot open crtendS.o: No such file or directory

This is because the crt components have not been built yet and what the build system is actually doing is building the runtime components.

What about the more prescriptive name, thank you for the advice. I'm going to change the variable name to LLVM_LINKER_SKIP_TEST.

Rename LLVM_LINKER_WORKS to LLVM_LINKER_SKIP_TEST.

psamolysov retitled this revision from [CMake] Skip linker check if the LLVM_LINKER_WORKS is set to [CMake] Skip linker check if the LLVM_LINKER_SKIP_TEST is set.May 31 2022, 7:14 AM
psamolysov edited the summary of this revision. (Show Details)

Ping. Does this change make sense at all?

RKSimon resigned from this revision.Jun 19 2022, 2:55 AM

Sorry, I'm not sure I can help much with cmake

thieta resigned from this revision.Oct 6 2022, 12:42 AM
phosek added inline comments.Oct 6 2022, 1:05 AM
llvm/cmake/modules/HandleLLVMOptions.cmake
308

I think the underlying issue is that the source we're trying to compile here implicitly includes standard libraries. I think it'd be better to use a simpler one in combination with -nostdlib (ideally we would check if -nostdlib is supported first) which should avoid the issue altogether and is more correct.

psamolysov added inline comments.Oct 18 2022, 11:29 PM
llvm/cmake/modules/HandleLLVMOptions.cmake
308

@phosek Thank you very much for the comment. I'm not sure I get your idea correctly, this script tries to compile and link the simplest application: int main() { return 0; }. As I get, this use only startup routines (__start and its friends) from the standard library. Do you mean the script should link this not as an executable but as a static library or anything else?

ldionne resigned from this revision.Sep 8 2023, 8:02 AM