[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-discuss] How to run cross-compiled binaries using Qemu user space

From: Libo Zhou
Subject: [Qemu-discuss] How to run cross-compiled binaries using Qemu user space emulation
Date: Mon, 2 Sep 2019 18:21:42 +0800

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 

$ 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 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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]