[Qemu-discuss] How to run cross-compiled binaries using Qemu user space emulation
I am trying to run C programs compiled for MIPS32 big-endian architecture on an x86_64 host. And I am using Ubuntu 18.04 LTS. I installed the prebuilt cross compiler using the following command: $ sudo apt install gcc-mips-linux-gnu Then, I built Qemu from source with the commands below: $ cd qemu-4.1.0 $ mkdir build $ cd build $ ../configure --interp-prefiix=/usr/mips-linux-gnu --target-list=mips-linux-user # if I don't set up the prefix then I will get a /lib/ld.so.1 not found error later $ make -j4 # my machine has 4 cpu's After that, I went into the qemu binary directory, and created a very simple C program: $ cd mips-linux-user $ echo "int main(void) { return 0; }" > test.c $ mips-linux-gnu-gcc test.c -o test # cross-compile MIPS on x86_64 I checked the filetype of my MIPS ELF using the command: $ file test test: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld., for GNU/Linux 3.2.0, BuildID[sha1]=02eaa87216ede002d62050f205d5764b68fabdf6, not stripped After running with the command: $ ./qemu-mips -strace test Then I got a segmentation fault, and here is the strace log: 10255 brk(NULL) = 0x00412000 10255 mmap2(NULL,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0) = 0x7f7c8000 10255 uname(0x7fffe8c8) = 0 10255 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory) 10255 access("/etc/ld.so.preload",R_OK) = -1 errno=2 (No such file or directory) 10255 openat(AT_FDCWD,"/etc/ld.so.cache",O_RDONLY|O_CLOEXEC) = 3 10255 fstat64(3,0x7fffe518) = 0 10255 mmap2(NULL,106802,PROT_READ,MAP_PRIVATE,3,0) = 0x7f7ad000 10255 close(3) = 0 --- SIGSEGV {si_signo=SIGSEGV, si_code=1, si_addr=0x2392d008} --- qemu: uncaught target signal 11 (Segmentation fault) - core dumped [1]10255 segmentation fault (core dumped) ./qemu-mips -strace test I am sorry if my question sounds too rookie, but I am having trouble getting things to work. Any help would be appreciated. Thanks, Libo
[Qemu-discuss] How to run cross-compiled binaries using Qemu user space emulation?
I am trying to run C programs compiled for MIPS32 big-endian architecture on an x86_64 host. And I am using Ubuntu 18.04 LTS. I installed the prebuilt cross compiler using the following command: $ sudo apt install gcc-mips-linux-gnu Then, I built Qemu from source with the commands below: $ cd qemu-4.1.0 $ mkdir build $ cd build $ ../configure --interp-prefiix=/usr/mips-linux-gnu --target-list=mips-linux-user # if I don't set up the prefix then I will get a /lib/ld.so.1 not found error later $ make -j4 # my machine has 4 cpu's After that, I went into the qemu binary directory, and created a very simple C program: $ cd mips-linux-user $ echo "int main(void) { return 0; }" > test.c $ mips-linux-gnu-gcc test.c -o test # cross-compile MIPS on x86_64 I checked the filetype of my MIPS ELF using the command: $ file test test: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld., for GNU/Linux 3.2.0, BuildID[sha1]=02eaa87216ede002d62050f205d5764b68fabdf6, not stripped After running with the command: $ ./qemu-mips -strace test Then I got a segmentation fault, and here is the strace log: 10255 brk(NULL) = 0x00412000 10255 mmap2(NULL,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0) = 0x7f7c8000 10255 uname(0x7fffe8c8) = 0 10255 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory) 10255 access("/etc/ld.so.preload",R_OK) = -1 errno=2 (No such file or directory) 10255 openat(AT_FDCWD,"/etc/ld.so.cache",O_RDONLY|O_CLOEXEC) = 3 10255 fstat64(3,0x7fffe518) = 0 10255 mmap2(NULL,106802,PROT_READ,MAP_PRIVATE,3,0) = 0x7f7ad000 10255 close(3) = 0 --- SIGSEGV {si_signo=SIGSEGV, si_code=1, si_addr=0x2392d008} --- qemu: uncaught target signal 11 (Segmentation fault) - core dumped [1]10255 segmentation fault (core dumped) ./qemu-mips -strace test I am sorry if my question sounds too rookie, but I am having trouble getting things to work. Any help would be appreciated. Thanks, Libo
Re: [Qemu-discuss] How to run cross-compiled binaries using Qemu user space emulation
The solution is: $ cd /usr/mips-linux-gnu $ sudo mkdir etc $ sudo ldconfig -C etc/ld.so.cache -r . (Credit: Aleksandar Markovic at Qemu-devel) -- Original -- From: "Libo Zhou";; Send time: Monday, Sep 2, 2019 6:21 PM To: "qemu-discuss"; Subject: How to run cross-compiled binaries using Qemu user space emulation I am trying to run C programs compiled for MIPS32 big-endian architecture on an x86_64 host. And I am using Ubuntu 18.04 LTS. I installed the prebuilt cross compiler using the following command: $ sudo apt install gcc-mips-linux-gnu Then, I built Qemu from source with the commands below: $ cd qemu-4.1.0 $ mkdir build $ cd build $ ../configure --interp-prefiix=/usr/mips-linux-gnu --target-list=mips-linux-user # if I don't set up the prefix then I will get a /lib/ld.so.1 not found error later $ make -j4 # my machine has 4 cpu's After that, I went into the qemu binary directory, and created a very simple C program: $ cd mips-linux-user $ echo "int main(void) { return 0; }" > test.c $ mips-linux-gnu-gcc test.c -o test # cross-compile MIPS on x86_64 I checked the filetype of my MIPS ELF using the command: $ file test test: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld., for GNU/Linux 3.2.0, BuildID[sha1]=02eaa87216ede002d62050f205d5764b68fabdf6, not stripped After running with the command: $ ./qemu-mips -strace test Then I got a segmentation fault, and here is the strace log: 10255 brk(NULL) = 0x00412000 10255 mmap2(NULL,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0) = 0x7f7c8000 10255 uname(0x7fffe8c8) = 0 10255 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory) 10255 access("/etc/ld.so.preload",R_OK) = -1 errno=2 (No such file or directory) 10255 openat(AT_FDCWD,"/etc/ld.so.cache",O_RDONLY|O_CLOEXEC) = 3 10255 fstat64(3,0x7fffe518) = 0 10255 mmap2(NULL,106802,PROT_READ,MAP_PRIVATE,3,0) = 0x7f7ad000 10255 close(3) = 0 --- SIGSEGV {si_signo=SIGSEGV, si_code=1, si_addr=0x2392d008} --- qemu: uncaught target signal 11 (Segmentation fault) - core dumped [1]10255 segmentation fault (core dumped) ./qemu-mips -strace test I am sorry if my question sounds too rookie, but I am having trouble getting things to work. Any help would be appreciated. Thanks, Libo
Re: [Qemu-discuss] How to run cross-compiled binaries using Qemuuser space emulation?
Hi Peter, Thanks for your reply. Creating a dummy ld.so.cache in ${sysroot}/etc/ did the trick for me. It was missing. Cheers, Libo -- Original message -- From: "Peter Maydell"; Sendtime: Tuesday, Sep 3, 2019 4:17 PM To: "Libo Zhou"; Cc: "qemu-discuss"; Subject: Re: [Qemu-discuss] How to run cross-compiled binaries using Qemuuser space emulation? On Mon, 2 Sep 2019 at 11:34, Libo Zhou wrote: > > I am trying to run C programs compiled for MIPS32 big-endian architecture on > an x86_64 host. And I am using Ubuntu 18.04 LTS. > Then I got a segmentation fault, and here is the strace log: > > > 10255 brk(NULL) = 0x00412000 > 10255 mmap2(NULL,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0) = > 0x7f7c8000 > 10255 uname(0x7fffe8c8) = 0 > 10255 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or > directory) > 10255 access("/etc/ld.so.preload",R_OK) = -1 errno=2 (No such file or > directory) > 10255 openat(AT_FDCWD,"/etc/ld.so.cache",O_RDONLY|O_CLOEXEC) = 3 > 10255 fstat64(3,0x7fffe518) = 0 > 10255 mmap2(NULL,106802,PROT_READ,MAP_PRIVATE,3,0) = 0x7f7ad000 > 10255 close(3) = 0 > --- SIGSEGV {si_signo=SIGSEGV, si_code=1, si_addr=0x2392d008} --- > qemu: uncaught target signal 11 (Segmentation fault) - core dumped > [1]10255 segmentation fault (core dumped) ./qemu-mips -strace test You're running into a bug in the guest ld.so (dynamic linker). Here it is reading the host's /etc/ld.so.cache, but the problem is that the guest ld.so can't cope with finding a ld.so.cache for the "wrong" endianness, and it segfaults. You can work around this by: * using QEMU inside a chroot which provides a complete guest-binary filesystem * ensuring that there is at least a dummy /etc/ld.so.cache in the 'sysroot' where QEMU looks first for files for the guest (I think an empty file will do.) Usually the sysroot directory is specified via the -L option to QEMU (you seem to be specifying it via configure, but the configure --interp-prefix option is just setting the default value for the runtime -L option, so you don't have to do that.) thanks -- PMM
[Qemu-discuss] What is inside in_asm log exactly
I have noticed that I can log some useful information using the "-d" switch. I tried logging in_asm out of curiosity and found out that there is a massive amount of assembly in the log (10,000+ lines). The assembly generated by gcc doesn't have so many lines (10+ lines).
[Qemu-discuss] Why my mails are not sent to the list sometimes
This happens very rarely, but it is now becoming problematic. I've been waiting for some responses for days, only to finally realize my mails were not sent to the list. What would be the possible reason for that? I can still receive the list emails. Well, what if this one can't go to the list? -_-|||
Initialize data memory in user space emulation
Hi all, I need a way to manipulate data saved in a reserved memory region in linux user space emulation. I found the -B option very promising. Documentation says it is useful when the address region required by guest applications is reserved on the host. But how can I initialize that memory with data?