2015/6/1

【QEMU】在X86 PC上執行其他平台(如ARM)程式

情境:要在X86 PC上透過QEMU模擬器執行ARM的程式。

先透過file指令確認執行程式的格式內容為ARM平台所用
$ file hello
hello: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=d7efe6f9528e036c383501d6fc0dd1ca6fc880b1, not stripped

qemu最後面加上要執行的程式即可,中間options視需求加入適當的參數
usage: qemu-arm [options] program [arguments...]

先直接執行看看
$ qemu-arm ./hello
/lib/ld-linux.so.3: No such file or directory

qemu不知道去哪裡載入loader,手動指定路徑後再執行看看
$ qemu-arm /usr/arm-linux-gnueabi/lib/ld-2.19.so ./hello
./hello: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory

這時loader需要載入相關library,手動指定動態鏈結檔目錄再執行看看
$ qemu-arm /usr/arm-linux-gnueabi/lib/ld-2.19.so --library-path /usr/arm-linux-gnueabi/lib ./hello
Hello World

這時應該就可以看到正確執行結果了!