Reputation: 11
I compiled a #include<stdio.h> int main() { printf("hello world\n"); return 0; }
program with riscv64-unknown-linux-gnu-gcc ./test.c -o test
on my x86_64-Ubuntu22.04 host, then I put this executable into the shared folder mnt. When I execute ./test
I just get -/bin/sh: ./test: not found
from terminal. Isn't it just a piece of binary code without shared lib?
My options of qemu startup are qemu-system-riscv64 -nographic -m 256M -machine virt -kernel ~/linux-kernel/arch/riscv/boot/Image -append \"root=/dev/vda rw console=ttyS0\" -drive file=rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -fsdev local,security_model=passthrough,id=fsdev0,path=./host_mnt -device virtio-9p pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare
. And I create my ext4 rootfs
just with dd and busybox
. Here are the basic commands I used.
$ qemu-img create rootfs.img 8g
$ mkfs.ext4 rootfs.img
$ mkdir rootfs
$ sudo mount -o loop rootfs.img rootfs
$ cd rootfs
$ sudo cp -r ../busyboxsource/_install/* .
$ sudo mkdir proc sys dev etc etc/init.d
$ cd etc/init.d/
$ sudo touch rcS
$ sudo vi rcS
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
/sbin/mdev -s
mount -t 9p -o trans=virtio,version=9p2000.L hostshare /mnt
$ sudo chmod +x rcS
$ sudo umount rootfs
(creating rootfs finished)
And the versions of riscv64-unknown-linux-gnu-gcc, QEMU and linux kernel(in qemu) are:
riscv64-unknown-linux-gnu-gcc (g2ee5e430018) 12.2.0
QEMU emulator version 8.0.0 (v8.0.0)
v6.0.0
I am confused why the elf compiled on host can not be executed inside qemu. Is it because my rootfs
is created with busybox
and not based on, say, ubuntu rootfs
, or something else? I can offer more information about my environment if needed. I'd appreciate it if anyone can explain this for me.
Thanks!
I tried ldd test
on host and got not a dynamic executable
.
I will try to build rootfs based on ubuntu if this is the reason.
Upvotes: 1
Views: 435