-
Notifications
You must be signed in to change notification settings - Fork 0
LLVM FAQ
This document briefly describes issues that may occur during LLVM/Clang development for RISC-V target.
To build a binary for RISC-V with linux using Clang, you need to pass it the option --target=riscv64-unknown-linux. If after that you see erros, see this section.
Usually we use Ninja for speed and faster incremental rebuilds.
Basic pipeline is:
gdb clang++
<set breakpoint>
set follow-fork-mode child
r <additional flags> test.cppOR it is also possible to use -fintegrated-cc1 option:
gdb clang++
<set breakpoint>
r -fintegrated-cc1 <additional flags> test.cppTips:
- almost everything in LLVM has
dump()method, so it should be used as much as you can to understand what's going on - utilize the Text User Interface from GDB. To use it, simply type the
tui enable. To exit, usetui disableorCtrl+XandA(subsequently) - utilize useful LLVM/Clang command-line options:
-print-changed,-stop-after,-debug-only, etc.
Useful links:
One may encounter error for standard library headers missing when cross-compiling:
fatal error: 'iostream' file not found
1 | #include <iostream>
| ^~~~~~~~~~
1 error generated.The error means that the system doesn't see GCC cross-compiler from x86 to RISC-V (yes, even if you're using clang the GCC dependency is still there). You should either:
- Somehow install cross-compiler GCC in your system: set it in your
$PATH, OR -
Download or build GCC cross-compiler from x86 to RISC-V and pass two options for clang:
--gcc-toolchain=<path to GCC folder>and--sysroot=<path ot GCC folder>/sysroot. Your build command will look like:./build/bin/clang++ --target=riscv64-unknown-linux --gcc-toolchain=/home/<gcc path>/ --sysroot=<gcc path>/sysroot/ ./test.cpp
GCC folder should contain sysroot and riscv64-unknown-linux-gnu -- precompiled system libraries (for example libstdc++.so)
One may need to use llc to trigger certain pass, and then compile it to ELF format. To do so the following actions should be performed:
- Emit bitcode with clang:
./build/bin/clang --target=riscv64-unknown-linux-gnu -march=rv64g -emit-llvm -c ~/test.cpp - Use llc, but with some additional options:
./build/bin/llc -march=riscv64 -mcpu=generic-rv64 -mattr=+d -filetype=asm test.bc. Note that it is not always necessary to add these attributes. - Use clang again:
./build/bin/clang --target=riscv64-unknown-linux-gnu test.s
Note: it is possible you'll need to specify the --gcc-toolchain and --sysroot for clang in steps 1 and 3 above
GCC 13 introduced new GLIBC, which may work poorly on some of the systems. In case of such an error, try to compile with different (previous) GCC toolchain.