Hello, I am trying to bootstrap building runtimes and builtins (libc, libcxx, libcxxabi, libunwind, compiler-rt)
for RISC-V baremetal target (riscv64-unknown-elf)
.
For libcxx, libcxxabi and libunwind I followed the instructions as described in Building libc++ — libc++ documentation. Basically, I set the CMake variable LLVM_ENABLE_RUNTIMES="libc;libcxx;libcxxabi;libunwind;compiler-rt"
.
cmake -G Ninja \
-DCMAKE_INSTALL_PREFIX=/path/to/install \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_TARGETS_TO_BUILD=RISCV \
-DLLVM_DEFAULT_TARGET_TRIPLE=riscv64-unknown-elf \
-DLLVM_ENABLE_PROJECTS=clang \
-DLLVM_ENABLE_RUNTIMES="libc;libcxx;libcxxabi;libunwind;compiler-rt"
/path/to/llvm-project/llvm
I am running into different errors for each runtimes project:
- For libc:
CMake Error at libc/cmake/modules/LLVMLibCArchitectures.cmake:82 (message):
libc build: Invalid or unknown libc compiler target triple:
riscv64-unknown-unknown-elf
I tried setting -DLLVM_RUNTIMES_TARGET=riscv64-unknown-elf
but still get the same errors.
- For libcxx:
-- LLVM default target triple: riscv64-unknown-elf
-- Using libc++ testing configuration: libcxx/test/configs/llvm-libc++-shared.cfg.in
-- ABI list file not generated for configuration riscv64-unknown-elf.libcxxabi.v1.stable.exceptions.nonew, `check-cxx-abilist` will not be available.
-- Configuring done
CMake Error at libcxx/src/CMakeLists.txt:272 (add_custom_command):
Error evaluating generator expression:
$<TARGET_PROPERTY:libcxx-abi-shared,IMPORTED_LIBNAME>
Target "libcxx-abi-shared" not found
- For compiler-rt: For this, I built riscv-gnu-toolchain and tried passing it as sysroot for the build using the CMake variable
-DRUNTIMES_CMAKE_ARGS="-DCMAKE_SYSROOT=/path/to/riscv-gnu-toolchain/riscv64-unknown-elf
.
FAILED: CMakeFiles/clang_rt.builtins-riscv64.dir/enable_execute_stack.c.o
build/llvm/./bin/clang --target=riscv64-unknown-elf --sysroot=riscv-gnu-toolchain/riscv64-unknown-elf -DVISIBILITY_HIDDEN -O3 -DNDEBUG -DCOMPILER_RT_HAS_FLOAT16 -std=c11 -fPIC -fno-builtin -fvisibility=hidden -fomit-frame-pointer -MD -MT CMakeFiles/clang_rt.builtins-riscv64.dir/enable_execute_stack.c.o -MF CMakeFiles/clang_rt.builtins-riscv64.dir/enable_execute_stack.c.o.d -o CMakeFiles/clang_rt.builtins-riscv64.dir/enable_execute_stack.c.o -c compiler-rt/lib/builtins/enable_execute_stack.c
compiler-rt/lib/builtins/enable_execute_stack.c:12:10: fatal error: 'sys/mman.h' file not found
#include <sys/mman.h>
And other errors such as:
error: unknown type name 'pthread_mutex_t'
error: use of undeclared identifier 'PTHREAD_MUTEX_INITIALIZER'
error: call to undeclared function 'pthread_setspecific'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
pthread_setspecific(emutls_pthread_key, (void *)value);
My questions are:
- Are the instructions in Building libc++ — libc++ documentation sufficient to build libcxx, libcxxabi and libunwind?
- Where will the runtimes build pick up the required headers, libs, etc from? Are we supposed to provide it a sysroot? How should we specify the sysroot?
- Am I missing any other CMake flags that need to be set?
Tagging @petrhosek for attention as per our recent RISC-V sync up call.
Thanks,
Mandeep