Hello
I’m trying to compile llvm for the open-source GPGPU project vortex. I followed the instruction in "README.vortex " located in the https://github.com/vortexgpgpu/pocl.git to build llvm.
I build RiscV GNU Toolchain first as "README.vortex " say with the following command:
- git clone --depth=1 --recursive https://github.com/riscv-collab/riscv-gnu-toolchain.git
- mkdir build && cd build
- export CPATH=$TOOLDIR/GNU/include
- export LIBRARY_PATH=$TOOLDIR/GNU/lib
- ../configure --prefix=$TOOLDIR/riscv32-gnu-toolchain --with-cmodel=medany --with-arch=rv32imf --with-abi=ilp32f
#../configure --prefix=$TOOLDIR/riscv64-gnu-toolchain --with-cmodel=medany --with-arch=rv64imafd --with-abi=lp64d
- make -j32
- make -j32 build-qemu
And build LLVM for Vortex with following commands:
- git clone --recursive --branch vortex https://github.com/vortexgpgpu/llvm.git
- cd llvm
- mkdir build && cd build
- export LLVM_PREFIX=$TOOLDIR/llvm-vortex
- export RISCV_TOOLCHAIN_PATH=$TOOLDIR/riscv64-gnu-toolchain
- cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$LLVM_PREFIX -DLLVM_ENABLE_PROJECTS="clang;lld" -DBUILD_SHARED_LIBS=True -DLLVM_TARGETS_TO_BUILD="RISCV" -DLLVM_ABI_BREAKING_CHECKS=FORCE_OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DDEFAULT_SYSROOT=$RISCV_TOOLCHAIN_PATH/riscv32-unknown-elf -DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" ../llvm
- make -j32
- make install
But I encountered a problem in the step
## Sanity test your new RISC-V LLVM.
- echo -e '#include <stdio.h>\n int main(void) { printf("Hello world!\\n"); return 0; }' > hello.c
- clang hello.c
- qemu-riscv32 hello
The error log showed as follows:
ld.lld: error: unable to find library -lclang_rt.builtins-riscv32
clang-16: error: ld.lld command failed with exit code 1 (use -v to see invocation)
It seems that lld cannot find a runtime library named clang_rt.builtins-riscv32. So I recompiled llvm with
-DLLVM_ENABLE_RUNTIMES="compiler-rt"
-DCOMPILER_RT_BAREMETAL_BUILD=ON
added. But it only generated a libclang_rt.builtins.a in llvm-vortex/lib/clang/16/lib/riscv32-unknown-elf only. But what I need is libclang_rt.builtins-riscv32.a in llvm-vortex/lib/clang/16/lib/baremetal since I run
clang -### hello.c
and it returns
clang version 16.0.6 (git@github.com:vortexgpgpu/llvm.git 5828d24a5b9270b7538854d28fa4cc14827da89c)
Target: riscv32-unknown-unknown-elf
Thread model: posix
InstalledDir: /home/soc_szq/share/vortex/toolchain/out/tools/llvm-vortex/bin
"/home/soc_szq/share/vortex/toolchain/out/tools/llvm-vortex/bin/clang-16" "-cc1" "-triple" "riscv32-unknown-unknown-elf" "-emit-obj" "-mrelax-all" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "hello.c" "-mrelocation-model" "static" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-fno-verbose-asm" "-mconstructor-aliases" "-nostdsysteminc" "-target-cpu" "generic-rv32" "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+c" "-target-feature" "-e" "-target-feature" "-f" "-target-feature" "-d" "-target-feature" "-h" "-target-feature" "-zihintpause" "-target-feature" "-zfhmin" "-target-feature" "-zfh" "-target-feature" "-zfinx" "-target-feature" "-zdinx" "-target-feature" "-zhinxmin" "-target-feature" "-zhinx" "-target-feature" "-zba" "-target-feature" "-zbb" "-target-feature" "-zbc" "-target-feature" "-zbs" "-target-feature" "-zbkb" "-target-feature" "-zbkc" "-target-feature" "-zbkx" "-target-feature" "-zknd" "-target-feature" "-zkne" "-target-feature" "-zknh" "-target-feature" "-zksed" "-target-feature" "-zksh" "-target-feature" "-zkr" "-target-feature" "-zkn" "-target-feature" "-zks" "-target-feature" "-zkt" "-target-feature" "-zk" "-target-feature" "-zmmul" "-target-feature" "-v" "-target-feature" "-zvl32b" "-target-feature" "-zvl64b" "-target-feature" "-zvl128b" "-target-feature" "-zvl256b" "-target-feature" "-zvl512b" "-target-feature" "-zvl1024b" "-target-feature" "-zvl2048b" "-target-feature" "-zvl4096b" "-target-feature" "-zvl8192b" "-target-feature" "-zvl16384b" "-target-feature" "-zvl32768b" "-target-feature" "-zvl65536b" "-target-feature" "-zve32x" "-target-feature" "-zve32f" "-target-feature" "-zve64x" "-target-feature" "-zve64f" "-target-feature" "-zve64d" "-target-feature" "-zicbom" "-target-feature" "-zicboz" "-target-feature" "-zicbop" "-target-feature" "-svnapot" "-target-feature" "-svpbmt" "-target-feature" "-svinval" "-target-feature" "-xventanacondops" "-target-feature" "-xtheadvdot" "-target-feature" "-experimental-zihintntl" "-target-feature" "-experimental-zca" "-target-feature" "-experimental-zcd" "-target-feature" "-experimental-zcf" "-target-feature" "-experimental-zvfh" "-target-feature" "-experimental-zawrs" "-target-feature" "-experimental-ztso" "-target-feature" "+relax" "-target-feature" "-save-restore" "-target-abi" "ilp32" "-msmall-data-limit" "8" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-fcoverage-compilation-dir=/home/soc_szq/share/vortex/toolchain/out/tools/riscv-llvm-test" "-resource-dir" "/home/soc_szq/share/vortex/toolchain/out/tools/llvm-vortex/lib/clang/16" "-isysroot" "/home/soc_szq/share/vortex/toolchain/out/tools/riscv32-gnu-toolchain/riscv32-unknown-elf" "-internal-isystem" "/home/soc_szq/share/vortex/toolchain/out/tools/llvm-vortex/lib/clang/16/include" "-internal-isystem" "/home/soc_szq/share/vortex/toolchain/out/tools/riscv32-gnu-toolchain/riscv32-unknown-elf/include" "-fdebug-compilation-dir=/home/soc_szq/share/vortex/toolchain/out/tools/riscv-llvm-test" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-faddrsig" "-o" "/tmp/hello-f898cd.o" "-x" "c" "hello.c"
"/home/soc_szq/share/vortex/toolchain/out/tools/llvm-vortex/bin/ld.lld" "/tmp/hello-f898cd.o" "-Bstatic" "-L/home/soc_szq/share/vortex/toolchain/out/tools/riscv32-gnu-toolchain/riscv32-unknown-elf/lib" "-L/home/soc_szq/share/vortex/toolchain/out/tools/riscv32-gnu-toolchain/riscv32-unknown-elf/lib" "-L/home/soc_szq/share/vortex/toolchain/out/tools/llvm-vortex/lib/clang/16/lib/baremetal" "-lc" "-lm" "-lclang_rt.builtins-riscv32" "-o" "a.out"
I wonder whether libclang_rt.builtins.a is the libclang_rt.builtins-riscv32.a I need with just a different name.
Besides, I may also need clang_rt.crtbegin-riscv32.o and clang_rt.crtend-riscv32.o since I found them in the prebuild toolchain repositories of vortex.
So how could I build compiler-rt for riscv32 with a dedicated library named libclang_rt.builtins-riscv32.a.
Thanks a lot.