LLVM 9 发行说明明确表示RISC-V支持从实验性提升为正式性。
事实上,在我的 Fedora 31 机器上,LLVM 9 Fedora 软件包确实支持 RISC-V:
$ llvm-objdump --version | grep riscv
riscv32 - 32-bit RISC-V
riscv64 - 64-bit RISC-V
另外,我可以使用 LLVM 工具链创建 RISC-V 二进制代码:
$ clang --target=riscv64 -march=rv64gc rotate.s -c -o rotate.o
$ file rotate.o
rotate.o: ELF 64-bit LSB relocatable, UCB RISC-V, version 1 (SYSV), not stripped
虽然它不包含 RISC-V 目标的 libc:
$ clang --target=riscv64 -march=rv64gc hello-world.c -o hello-world
hello-world.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
但是,您实际上并不需要 - 您可以直接为您的 hello world 调用系统调用,例如:
$ clang --target=riscv64 -march=rv64gc hello.s -c -o hello.o
$ ld.lld hello.o -o hello
$ spike --isa=RV64gc ~/local/riscv/pk/riscv64-unknown-elf/bin/pk ./hello
bbl loader
Hello World
我不使用 clang 进行链接,因为似乎我无法说服 clang-fuse-ld
除此之外使用另一个链接器/usr/bin/ld
.