安装依赖环境

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:


putao
8 声望1 粉丝

推动世界向前发展,改善民生。


引用和评论

0 条评论