This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt][builtins] Fix CMake builtin target flag
ClosedPublic

Authored by thieta on Feb 22 2022, 12:55 AM.

Details

Summary

clang-cl doesn't support -target <target>, instead it only supports
--target=<target> so building a RUNTIME configuration for clang-cl
ended up in never building builtins. Which in turn lead to clang-cl
not being able to find the runtime libraries because we depend
on the compiler_rt.builtins.lib being in the runtime dir for the
Driver to add it as a candidate.

I don't think this should have any downsides since most the code
these days are using --target=<target> instead of the old syntax.

Diff Detail

Event Timeline

thieta created this revision.Feb 22 2022, 12:55 AM
thieta requested review of this revision.Feb 22 2022, 12:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 22 2022, 12:55 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
mstorsjo accepted this revision.Feb 22 2022, 12:57 AM
mstorsjo added a subscriber: mstorsjo.

LGTM, I think --target= is the generally preferred/recommended form these days anyway.

Other than that, I'm not entirely sure I understand exactly how you configure your build, but this change should be fine regardless.

This revision is now accepted and ready to land.Feb 22 2022, 12:57 AM

Other than that, I'm not entirely sure I understand exactly how you configure your build, but this change should be fine regardless.

cmake -GNinja -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_ENABLE_RUNTIMES="compiler-rt" ..\llvm

and then

ninja builtins

before this change it didn't build the runtime library - after this change it does.

Other than that, I'm not entirely sure I understand exactly how you configure your build, but this change should be fine regardless.

cmake -GNinja -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_ENABLE_RUNTIMES="compiler-rt" ..\llvm

and then

ninja builtins

before this change it didn't build the runtime library - after this change it does.

Hmm, ok. This is in an environment that defaults to a LLVM_DEFAULT_TRIPLE of *-windows-msvc I presume, but at what point within the runtimes setup does it switch to calling with the clang-cl frontend instead of the regular clang?

Hmm, ok. This is in an environment that defaults to a LLVM_DEFAULT_TRIPLE of *-windows-msvc I presume, but at what point within the runtimes setup does it switch to calling with the clang-cl frontend instead of the regular clang?

Oh sorry - I guess it's a bit more complicated - it's a BOOTSTRAP build where the first stage is MSVC, then bootstrap defaults to pass clang-cl to the second stage, which I think is the recommended way to build LLVM on Windows (use clang-cl instead of clang).

But the same effect can be found by doing -DCMAKE_CXX_COMPILER=clang-cl to my example above.

Oh sorry - I guess it's a bit more complicated - it's a BOOTSTRAP build where the first stage is MSVC, then bootstrap defaults to pass clang-cl to the second stage, which I think is the recommended way to build LLVM on Windows (use clang-cl instead of clang).

But the same effect can be found by doing -DCMAKE_CXX_COMPILER=clang-cl to my example above.

Ok, that explains it a little. But with LLVM_ENABLE_RUNTIMES, it shouldn't (AFAIK) use CMAKE_CXX_COMPILER to build the runtimes (which indeed could be anything, MSVC or GCC), but instead should use the newly built clang - and that's where I'm surprised to see that it prefers the clang-cl frontend there too, instead of the clang one. Or does it set up compiler-rt via LLVM_ENABLE_PROJECTS in the second stage? That would explain it.

Ok, that explains it a little. But with LLVM_ENABLE_RUNTIMES, it shouldn't (AFAIK) use CMAKE_CXX_COMPILER to build the runtimes (which indeed could be anything, MSVC or GCC), but instead should use the newly built clang - and that's where I'm surprised to see that it prefers the clang-cl frontend there too, instead of the clang one. Or does it set up compiler-rt via LLVM_ENABLE_PROJECTS in the second stage? That would explain it.

I was curious and it took me a while to find - but it's selected here: https://github.com/llvm/llvm-project/blob/main/llvm/cmake/modules/LLVMExternalProjectUtils.cmake#L168

Ok, that explains it a little. But with LLVM_ENABLE_RUNTIMES, it shouldn't (AFAIK) use CMAKE_CXX_COMPILER to build the runtimes (which indeed could be anything, MSVC or GCC), but instead should use the newly built clang - and that's where I'm surprised to see that it prefers the clang-cl frontend there too, instead of the clang one. Or does it set up compiler-rt via LLVM_ENABLE_PROJECTS in the second stage? That would explain it.

I was curious and it took me a while to find - but it's selected here: https://github.com/llvm/llvm-project/blob/main/llvm/cmake/modules/LLVMExternalProjectUtils.cmake#L168

Thanks for the effort to dig that up! The patch is even more good to go then!

This revision was automatically updated to reflect the committed changes.