The 32-bit program cannot be executed with RISC-V Spike. Can't Execute 32-Bit Program on RV64 Hot

633 views Asked by At

The following software has been built, installed, and passes. RISCV-GNU-TOOLS (both 64, 32bit), Spike, Riscv-PK (32bit). If you try to execute the C language program with RISCV32 and execute it in Spike, you will get an error as follows. What should I do? The environment is ubuntu-20.04, 64 bit.

$ riscv32-unknown-linux-gnu-gcc -static fib.c -o fib
$spike $riscvpk/bin/pk fib
Error: cannot execute 32-bit program on RV64 hart

What I did to make 32bit support.

sudo dpkg --add-arrhitecture i386
sudo apt-get update
sudo apt-get install libc6: i386 libncurses5: i386 libstdc ++ 6: i386
sudo apt-get Install gcc-multilib
#~/.bashrc
# RISC-V gnu-tools 64bit
export PATH=${PATH}:/opt/riscv/bin
# RISC-V gnu-tools 32bit
export PATH=${PATH}:/opt/riscv32/bin
# RISC-V spike
export RISCV=/opt/riscv32-tools/toolchain
export PATH=$PATH:$RISCV/bin
# RISC-V pk
export riscvpk=/opt/riscv32/bin/riscv32-unknown-linux-gnu
export PATH=$PATH:$riscvpk/bin

1

There are 1 answers

0
Celuk On

For running 32 bit riscv binaries, you need to add --isa=RV32IMAFDC flag while running spike command. (Depending on your used extensions, e.g. also it can be --isa=RV32IM)

spike --isa=RV32IMAFDC $riscvpk/bin/pk fib