Faulty CMake option related to llvm_runtime (original) (raw)

January 16, 2025, 5:53am 1

I have encountered an issue related to llvm_runtime component compiler-rt. When linking a riscv32 assembly code with ld.lld, I got an error saying ld.lld: error: cannot open ....../libclang_rt.builtins.a: No such file or directory. After searching for previous issues like #87150, #72862, How to build libclang_rt.builtins.a?, it seems that the issue happens because of the lack of building “compiler-rt”.

After digging into the Clang Doc and the CMakeLists file, it turns out that CMake option -DLLVM_ENABLE_RUNTIMES=all will only build default runtimes “libcxx;libcxxabi;libunwind” rather than all supported runtimes “libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc;offload”. This can result in the possible omission of building the compiler-rt.

Since many people have encountered the issue due to this confusing “all” option, maybe we should add a “default” option for building “default runtimes”, and use “all” option to build “all supported runtimes”.

Also in the chapter “LLVM_ENABLE_RUNTIMES” of llvm doc CMake frequently used variables, the doc says that

The full list is:

libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc;offload

To enable all of them, use:

LLVM_ENABLE_RUNTIMES=all

which contradicts the llvm/CMakelists.txt

set(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind")
set(LLVM_SUPPORTED_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc;offload")
set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
  "Semicolon-separated list of runtimes to build, or \"all\" (${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")
if(LLVM_ENABLE_RUNTIMES STREQUAL "all")
  set(LLVM_ENABLE_RUNTIMES ${LLVM_DEFAULT_RUNTIMES})
endif()

I think it is an issue to be fixed.