Building (parts of) LLVM for bare metal RISCV32

Dear all,

in our project, we need to build (parts of) libLLVM for bare metal RISCV32, to be precise for the rv32ima ISA. We need at least libLLVMSupport and libLLVMObject, since we build libomptarget and need to link against these.

When using the full-featured RISCV GNU Linux toolchain, I can successfully build LLVM, providing the mentioned libraries.

However, since we have a bare metal target in our project, we need to build things using the RISCV GNU Newlib toolchain. Here, I have several problems already at CMake configuration time.

Firstly, atomics support is needed. Even though our target architecture rv32ima has atomic instructions, there is no libatomic in the Newlib toolchain since that is not yet implemented. Hence, configuration fails with

-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB - Failed
-- Looking for __atomic_fetch_add_4 in atomic
-- Looking for __atomic_fetch_add_4 in atomic - not found

I can get around this by adding libatomic from the Linux toolchain, which however yields -- Looking for __atomic_load_8 in atomic - not found. Commenting out the corresponding CMake code (as a quick hack) and using -DLLVM_INCLUDE_BENCHMARKS=OFF to remove the pthread dependency from configuration makes configuration finish, but then the build crashes, seemingly related to missing threads support.

So I am a bit stuck at the moment. My question is: Does anybody have experience in building LLVM or at least the mentioned libLLVMSupport and libLLVMObject for a bare metal target, ideally RISCV32?

Any hints on what I could do would be greatly appreciated.

It would also help if someone could tell me how I can build only libLLVMSupport instead of all of LLVM, since this might need less dependencies.