为什么我可以在我的 x86_64 机器上执行 RISC-V 二进制文件?

问题描述 投票:0回答:0

我使用 RISC-V 工具链从源代码编译了一个二进制文件

objdump_riscv
。在这里,我readelf它,显然,它是一个 RISC-V 二进制文件。

$ readelf -h ./objdump_riscv 
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:               0x10a2c
  Start of program headers:          64 (bytes into file)
  Start of section headers:          4704328 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         3
  Size of section headers:           64 (bytes)
  Number of section headers:         24
  Section header string table index: 23

我什至无法使用为 x86_64 编译的

objdump
反汇编它。

$ objdump -D ./objdump_riscv

./objdump_riscv:     file format elf64-little

objdump: can't disassemble for architecture UNKNOWN!

使用 QEMU x86_64:

$ qemu-x86_64 ./objdump_riscv 
qemu-x86_64: ./objdump_riscv: Invalid ELF image for this architecture

使用 QEMU RISCV:

 qemu-riscv64 ./objdump_riscv 
Usage: ./objdump_riscv <option(s)> <file(s)>
 Display information from object <file(s)>.
 At least one of the following switches must be given:
  -a, --archive-headers    Display archive header information
  -f, --file-headers       Display the contents of the overall file header
  -p, --private-headers    Display object format specific file header contents
  -h, --[section-]headers  Display the contents of the section headers
  -x, --all-headers        Display the contents of all headers
  -d, --disassemble        Display assembler contents of executable sections
  -D, --disassemble-all    Display assembler contents of all sections
  -S, --source             Intermix source code with disassembly
  -s, --full-contents      Display the full contents of all sections requested
  -g, --debugging          Display debug information in object file
  -G, --stabs              Display (in raw form) any STABS info in the file
  -t, --syms               Display the contents of the symbol table(s)
  -T, --dynamic-syms       Display the contents of the dynamic symbol table
  -r, --reloc              Display the relocation entries in the file
  -R, --dynamic-reloc      Display the dynamic relocation entries in the file
  -v, --version            Display this program's version number
  -i, --info               List object formats and architectures supported
  -H, --help               Display this information

所以它显然只在 RISC-V QEMU 上执行。我不小心尝试在我的机器上执行它,令我惊讶的是,它正常执行:

 ./objdump_riscv 
Usage: ./objdump_riscv <option(s)> <file(s)>
 Display information from object <file(s)>.
 At least one of the following switches must be given:
  -a, --archive-headers    Display archive header information
  -f, --file-headers       Display the contents of the overall file header
  -p, --private-headers    Display object format specific file header contents
  -h, --[section-]headers  Display the contents of the section headers
  -x, --all-headers        Display the contents of all headers
  -d, --disassemble        Display assembler contents of executable sections
  -D, --disassemble-all    Display assembler contents of all sections
  -S, --source             Intermix source code with disassembly
  -s, --full-contents      Display the full contents of all sections requested
  -g, --debugging          Display debug information in object file
  -G, --stabs              Display (in raw form) any STABS info in the file
  -t, --syms               Display the contents of the symbol table(s)
  -T, --dynamic-syms       Display the contents of the dynamic symbol table
  -r, --reloc              Display the relocation entries in the file
  -R, --dynamic-reloc      Display the dynamic relocation entries in the file
  -v, --version            Display this program's version number
  -i, --info               List object formats and architectures supported
  -H, --help               Display this information

Linux中是否存在仿真层导致其正常执行?

linux x86-64 elf riscv
© www.soinside.com 2019 - 2024. All rights reserved.