安装依赖环境
brew install riscv-gnu-toolchain
riscv64-unknown-elf-gcc --version
makefile
all:
riscv64-unknown-elf-gcc -g hello.c -o hello.out
#预处理
e:
riscv64-unknown-elf-gcc -E -P hello.c -o hello.e
#编译
s:
riscv64-unknown-elf-gcc -S hello.c
#汇编
c:
riscv64-unknown-elf-gcc -c hello.c
run:all
./hello.o
clean:
rm -f hello.out hello.o hello.S hello.e
c代码
#include <stdio.h>
#define FORMAT_STRING "%s"
#define MESSAGE "hello world\n"
int main() {
printf(FORMAT_STRING, MESSAGE);
return 0;
}
file hello.o
hello.o: ELF 64-bit LSB relocatable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), not stripped
file hello.out
hello.out: ELF 64-bit LSB executable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), statically linked, with debug_info, not stripped
剥离二进制文件:
riscv64-unknown-elf-strip --strip-all hello.out
剥离之后
hello.out: ELF 64-bit LSB executable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), statically linked, stripped
解释:
relocatable:
not stripped:
statically linked:
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。