[compiler-rt] [CMake] [compiler-rt] fix architecture checks in runtime builds (PR #66374)

Sebastian Poeplau via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 9 03:17:18 PST 2023


sebastianpoeplau wrote:

@llvm-beanz 

> This is effectively the same problem that the `test_compile_only` macro was added to solve. There are a bunch of cases in compiler-rt where you can only verify that the compile works not the compile+link.

There is actually code in `crt-config-ix.cmake` and `builtin-config-ix.cmake` that sets `test_compile_only` to true, but if I remember correctly this happens too late in the runtimes build to have an effect (see below for details on my setup).

> Can you share more about your configuration that’s leading you to this failure?

Sure. We build Clang and compiler-rt+libunwind via `LLVM_ENABLE_RUNTIMES` on x86_64 Linux. The toolchain is supposed to be independent of any host GCC installation and therefore configured to use compiler-rt and libunwind by default (via `CLANG_DEFAULT_RTLIB/UNWINDLIB`), which implies that Clang isn't fully functional yet by the time we build the runtimes. There is code to handle this case in `compiler-rt/CMakeLists.txt`, but I still had the problem that the crt objects weren't built even with explicit `COMPILER_RT_BUILD_CRT=ON`. It turned out that this was due to the target check failing to link, hence this PR.

> CMake has changed and evolved _a lot_ since I wrote a lot of the hacky mess that drives this all, so some of these decisions should probably be revisited.

I'm just a regular CMake user, not an expert :cry: What are the recent changes that would be useful in this context?

@petrhosek 

> Have you tried using `COMPILER_RT_DEFAULT_TARGET_ONLY`?

I think I shied away from it because we wanted to build the 32-bit runtimes as well. Is there a good way to achieve this with `COMPILER_RT_DEFAULT_TARGET_ONLY`, apart from two separate builds?

I should also say that we're hitting the limits of `LLVM_ENABLE_RUNTIMES` in some other contexts, especially when it comes to bare-metal targets, where we'd like to build an embedded libc between the compiler and the runtimes. So we're considering separate builds anyway, which would also make it easier to build with `COMPILER_RT_DEFAULT_TARGET_ONLY`.

https://github.com/llvm/llvm-project/pull/66374


More information about the llvm-commits mailing list