As there’s been some discussions of uses of the latest toolchains here, I thought it might be helpful to share my notes from building recent GCC and LLVM on the VisionFive2 in the Debian image for native compilation - this is a quick summary, but I wrote up some more detailed notes here: GCC and LLVM builds on the VisionFive 2 Debian Image – Graham Markall
GCC
To build GCC 12.2, I first had to apply a small patch because RISC-V GCC seems not to quite be set up correctly for Debian multiarch:
diff --git a/gcc/config/riscv/t-linux b/gcc/config/riscv/t-linux
index 216d2776a18..f714026b3cc 100644
--- a/gcc/config/riscv/t-linux
+++ b/gcc/config/riscv/t-linux
@@ -1,3 +1,4 @@
# Only XLEN and ABI affect Linux multilib dir names, e.g. /lib32/ilp32d/
MULTILIB_DIRNAMES := $(patsubst rv32%,lib32,$(patsubst rv64%,lib64,$(MULTILIB_DIRNAMES)))
MULTILIB_OSDIRNAMES := $(patsubst lib%,../lib%,$(MULTILIB_DIRNAMES))
+MULTIARCH_DIRNAME = $(call if_multiarch,riscv64-linux-gnu)
I wasn’t sure how to add source repos in the Debian image, so I manually installed everything (and a bit more) that might be needed to build it:
sudo apt install \
libc6-dev m4 libtool gawk lzma xz-utils patchutils \
gettext texinfo locales-all sharutils procps \
dejagnu coreutils chrpath lsb-release time pkg-config \
libgc-dev libmpfr-dev libgmp-dev libmpc-dev \
flex yacc bison
Then to build and install (I have the 8GB RAM version, I don’t know if 4 threads is too many if you only have 4GB):
mkdir build-gcc-12.2.0
cd build-gcc-12.2.0
../gcc/configure \
--enable-languages=c,c++,fortran \
--prefix=/opt/gcc/12.2.0 \
--disable-multilib \
--with-arch=rv64gc \
--with-abi=lp64d
make -j4
make install
I only enabled C, C++, and Fortran, but I suspect some other languages might work (and others might not ).
Building too about 5.5 hours - I ran make check
too, and there don’t appear to be any significant issues.
LLVM
Dependency installation for LLVM 15.0.6 (again probably overkill, but these are all the deps specified in the LLVM 15 source package in Debian):
sudo apt install \
cmake ninja-build chrpath texinfo sharutils libelf-dev \
libffi-dev lsb-release patchutils diffstat xz-utils \
python3-dev libedit-dev libncurses5-dev swig \
python3-six python3-sphinx binutils-dev libxml2-dev \
libjsoncpp-dev pkg-config lcov procps help2man \
zlib1g-dev libjs-mathjax python3-recommonmark \
doxygen gfortran libpfm4-dev python3-setuptools \
libz3-dev libcurl4-openssl-dev libgrpc++-dev \
protobuf-compiler-grpc libprotobuf-dev \
protobuf-compiler
Building and installing:
mkdir build
cd build
cmake ../llvm -G Ninja \
-DCMAKE_INSTALL_PREFIX=/opt/llvm/15.0.6 \
-DLLVM_TARGETS_TO_BUILD=RISCV \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON
ninja -j 3
ninja install
To save time I only built the RISC-V target. I had to use 3 processes because it runs out of memory when linking with 4 processes and results in an OOM kill, even on the 8GB version.
Building LLVM took just under 4 hours. I haven’t run any tests but I’ve been using it for development purposes without bumping into any obvious issues.