riscv-software-src / riscv-tools

RISC-V Tools (ISA Simulator and Tests)
1.13k stars 446 forks source link

How could i install riscv32-unknown-elf binaries? #294

Open madhavasahu-sevya opened 4 years ago

madhavasahu-sevya commented 4 years ago

I have installed riscv-gnu-toolchain in my Ubuntu 18.04.3 and got riscv64-unknown-elf binaries. But i need to install riscv32-unknown-elf binaries. please suggest how can i do that? Thanks in advance.

jim-wilson commented 4 years ago

If you use --enable-multilib, then you can use a rv64 compiler as a rv32 compiler by adding -march=X -mabi=Y options. This is the way the toolchain is intended to be used.

But if you really need a rv32 compiler you can specify --with-arch=rv32gc or whatever architecture you want when configuring. You will also need to specify --with-abi=ilp32d or whatever abi you want.

madhavasahu-sevya commented 4 years ago

Hi, I tried with above mentioned inputs..

./configure --prefix=/home/system/Desktop/elf32-toolchain --with-arch=rv32gc --with-abi=ilp32d make

As a result, got the 32bit binaries. After executing a sample program, a linker error message coming. please find the attachment below. riscv32 elf bianry linking error

kito-cheng commented 4 years ago

Seems like you invoke riscv32-unknown-elf-gcc from pulp-toolchain instead of elf32-toolchiain? Try ./riscv32-unknown-elf-gcc -o sample sample.c at ~/Desktop/elf32-toolchain/bin again?

madhavasahu-sevya commented 4 years ago

@kito-cheng thank you very much. seems like it is the problem.after that done, i am getting below error. ../pk/elf.c:40: assertion failed: IS_ELF64(eh) as pk is built for 64bit. What is the exact command to build 32bit versions of pk?

jim-wilson commented 4 years ago

pk/elf.c does

if __riscv_xlen == 64

assert(IS_ELF64(eh));

else

assert(IS_ELF32(eh));

endif

so you should get a 32-bit pk if you use a riscv32 compiler to build it.

The toplevel build.sh has CC= CXX= build_project riscv-pk --prefix=$RISCV --host=riscv64-unknown-elf so using --host=riscv32-unknown-elf should work. There is no default support for building a 32-bit pk so you will have to hack the build to get it.