I'm posting this in case it can help someone.
I've modified the nice LLVM-embedded-toolchain-for-Arm project so that it builds a standalone clang/llvm+picolibc toolchain for riscv32
(tested on linux only, might work or not on windows).
I'm using it with the CH32V307, without too much issue so far (see below). Better to use clang if you do a mix of c++ & rust.
The modification is very small, the original project is very well done
https://github.com/mean00/LLVM-embedded-toolchain-for-rv32.gitIt is experimental, but works nicely so far for me, including lto.
Some notes :
It should be mostly a drop-in replacement for gcc with the following :
- you need to add --target=riscv32 to your cflags i.e.
-march=rv32imac -mabi=ilp32 =>
--target=riscv32 -march=rv32imac -mabi=ilp32
- Clang linker script is mostly compatible with gcc/ld one, but you may have to tweak it a bit.
- There is tiny compatibility between gcc & clang, like removing .func and .endfunc in asm files. Nothing painful.
- The above toolchain does not contain the fast interrupt stuff, i think you can get by with asm("mret")+ naked or something similar so that it works everywhere without every toolchain (not looked into it deeply yet).
- You still have to use gnu-gdb to debug
- The generated code size is similar to the one with gcc 12 + picolibc
Your typical build script is :
mkdir build && cd build && cmake -G Ninja && ninja && ninja package-llvm-toolchain
/!\ You may have to create a symlink : ln -s $PWD/build/_deps/llvmproject-src/llvm/lib lib
Notice : It takes a while to build