riscv-software-src / riscv-tools

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

riscv32-unknown-elf-gcc : command not found #358

Closed davidwilley closed 2 years ago

davidwilley commented 2 years ago

I installed the the tool by executing build.sh. It displayed a message 'RISC-V Toolchain installation completed!' at the end. After that when I use 'riscv32-unknown-elf-gcc' it still says command not found.

I already have installed riscv-gnu-toolchain (https://github.com/riscv-collab/riscv-gnu-toolchain) and the command riscv64-unknown-elf-gcc works fine. By giving -march=rv32i -mabi=ilp32, I generated the elf file for a 32-bit virtual platform(VP) using riscv64 command. But the elf file does not seem to work on the virtual platform.

Why is riscv32-unknown-elf-gcc does not work in spite of building the toolchain?

Regards, David

jim-wilson commented 2 years ago

riscv-tools doesn't include a toolchain, unless perhaps you are using an very old out-of-date version of it. riscv-tools isn't actively maintained, and is unlikely to build anymore. riscv-gnu-toolchain is still maintained and should be OK. riscv-tools isn't very useful any more and probably should not be used.

riscv-gnu-toolchain by default will build a riscv64-unknown-elf-gcc compiler. If you want a riscv32-unknown-elf-gcc compiler, then you must build riscv-gnu-toolchain a second time using --with-arch=rv32gc --with-abi=ilp32d or similar configure options. Many people don't bother to build a riscv32 toolchain and just use the riscv64 toolchain with --march= and -mabi= options. The riscv64 compiler will generate 32-bit code by default, but you won't have libraries needed to link unless you use --enable-multilib and/or otherwise specify the library arch/abi versions you want to build. It is simpler to just use --with-arch and --with-abi when configuring to get a compiler that supports your target by default.

You didn't give any info about your virtual platform, or exactly how you generated your 32-bit elf file. I can't say what might be wrong without a lot more info. I can point out that you can use the "file" program on linux to check to see what kind of file you have. If it isn't an executable RISC-V 32-bit ELF file then it wasn't produced correctly.

davidwilley commented 2 years ago

Thank you for the explanation. I built the riscv32 toolchain and now riscv32-unknown-elf-gcc is executed. But I am getting another error which says "can't link double-float modules with soft-float modules"

You have already answered to this error in another issue. You have suggested to re-build toolchain with --enable-multilib option. (https://github.com/riscv-collab/riscv-gnu-toolchain/issues/836)

I executed /configure --prefix=/opt/riscv --enable-multilib and then make command. it says "make: Nothing to be done for 'all'." and the error "can't link double-float modules with soft-float modules" still persists.

I am using the virtual platform from this repository- (https://github.com/Minres/TGC-VP). The makefile used to generate elf file can be found under TGC-VP/fw/hello-world/ folder. Command used for elf file generation is given in the image below. image

jim-wilson commented 2 years ago

The easiest solution is to use the arch/abi option you need when you configure riscv-gnu-toolchain via the --with-arch= and --with-abi= option configure options.

Using --enable-multilib is an alternative solution that builds a small number of predetermined arch/abi combinations. However, --enable-multilib will only work for you if the arch/abi choice you want is one of the predetermined combinations. It may or may not be, and if it isn't, then you will get link errors. You can see if you have a multilib toolchain, and can see the arch/abi choices by running gcc with the --print-multi-lib option. If it prints arch/abi options then it is multilib, and those are the supported choices. If the arch/abi combination you need is not one of the defaults, there are multiple ways to add it. You can modify the riscv-gcc/gcc/config/riscv/t-elf-multilib file. Or you can use the --with-multilib-generator configure option which uses the same string documented in the t-elf-multilib file.

You might need to do "make clean" after reconfiguring to build it again. The build uses stamp files, and I don't think that configure will delete the stamp files. Also note that you should use different install dirs every time you build similar toolchains. There is a problem documented in the troubleshooting section of the riscv-gnu-toolchain README.md that mentions this can cause build problems if you try to install a toolchain overtop of one that was configured differently. Also, you can do builds in their own directory instead of in the source tree which makes it easy to have multiple builds. E.g. mkdir X-multilib-build, cd X-multilib-build, ../riscv-gnu-toolchain/configure ... and you get a toolchain built in the X-multilib-build dir. With different build dirs and install dirs you can experiment and see how configure options affect the resulting toolchain.

davidwilley commented 2 years ago

I could successfully generate the elf file by configuring riscv-gnu-toolchain via the --with-arch= and --with-abi= option. Thank you for your help!