./hello_..."/>

用 riscv64- Linux -gnu-gcc 编译的 c 文件为啥能在 x8664 下运行?

24次阅读

共计 727 个字符,预计需要花费 2 分钟才能阅读完成。

就一个简单的 c 程序:

#include 
int main()
{printf("Hello, Worldn");
}

使用如下命令编译:

riscv64-linux-gnu-gcc --static hello.c -o hello_riscv64

居然可以直接运行

> ./hello_riscv64 
Hello, World

使用 qemu 也能运行:

> qemu-riscv64-static  hello_riscv64 
Hello, World

readelf 结果:

> readelf -h hello_riscv64 
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           RISC-V
  Version:                           0x1
  Entry point address:               0x1054c
  Start of program headers:          64 (bytes into file)
  Start of section headers:          501880 (bytes into file)
  Flags:                             0x5, RVC, double-float ABI
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         7
  Size of section headers:           64 (bytes)
  Number of section headers:         28
  Section header string table index: 27
正文完
 0