riscv-software-src / riscv-tools

RISC-V Tools (ISA Simulator and Tests)
1.14k stars 447 forks source link

Cannot able to run new executables packed with root file system. #188

Closed akashgj closed 6 years ago

akashgj commented 6 years ago

Cross-compiled a sample hello world C program using the compiler riscv64-unknown-linux-gnu-gcc and packed the generated executable file with the root file system of RISC-V Linux. The executable file is showing in the booted Linux. But when trying to execute the file It is showing

BusyBox v1.26.2 (2018-03-27 15:51:19 IST) built-in shell (ash)

hello

-/bin/ash: /bin/hello: not found

Please. Someone tell how to resolve the issue.

jim-wilson commented 6 years ago

That error usually means the interpreter is missing. For a dynamically linked program, that means the dynamic linker is missing. If you have a different glibc version in the cross compiler and the target filesystem, it might have a slightly different name, or be in a different directory, etc. You can get the dynamic linker name from a binary by doing objdump --full-contents --section .interp Then check to see if that file exists in your target root filesystem. The easiest way to work around this problem is to static link. Alternatively, you can make a toolchain sysroot from your target root file system, and then use that sysroot when building the cross compiler, to ensure that the glibc version in the cross compiler matches the glibc version in the target root file system.

You can get the same error from a shell script that specifies a nonexistent interpreter. E.g. if you create a shell script

!/bin/nonexistent

exit 0 make it executable and run it, then you will get an error saying the file is missing.

Bash gives a much better error for this case, which mentions that the interpreter is missing. ash unfortunately gives an ambiguous error that confuses people.

akashgj commented 6 years ago

Thanks for the help.