使用动态链接器与qemu-arm

5

我有一个非常简单的ARM可执行文件,是使用arm-linux-gnueabi工具链编译的。我可以使用qemu-arm无任何问题地执行它:

$ qemu-arm -L /usr/arm-linux-gnueabi/ ./a.out
Hello world !

即使没有任何参数,运行链接器也可以工作:

qemu-arm /usr/arm-linux-gnueabi/lib/ld-linux.so.3
Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]
You have invoked `ld.so', the helper program for shared library executables.
...

然而,如果我希望链接器运行我的可执行文件,情况如下:
$ qemu-arm -L /usr/arm-linux-gnueabi/ /usr/arm-linux-gnueabi/lib/ld-linux.so.3 a.out
a.out: error while loading shared libraries: a.out: cannot open shared object file

这里是 strace 的输出: https://pastebin.com/uJ7AhBdh

有什么想法,为什么会发生这种情况吗?


ldd a.out 的输出是什么?(在qemu中运行) - hek2mgl
我无法运行 ldd,但这里是 readelf -d a.out 的输出:https://pastebin.com/G6TBxddi - ttk203
似乎找不到 libc.so.6 - hek2mgl
你能发布 ld --verbose | grep SEARCH_DIR | tr -s '; ' \\012 的输出吗? - hek2mgl
1个回答

5

我无法在Ubuntu 20.04上重现该问题:

sudo apt install gcc-arm-linux-gnueabihf qemu-user
printf '
#include <stdio.h>
#include <stdlib.h>

int main() {
    puts("hello world");
    return EXIT_SUCCESS;
}
' >  hello_world.c
qemu-arm -L /usr/arm-linux-gnueabihf ./hello_world

以及 aarch64:

sudo apt install gcc-aarch64-linux-gnu qemu-user
aarch64-linux-gnu-gcc -ggdb3 -static -o hello_world hello_world.c
qemu-aarch64 -L /usr/aarch64-linux-gnu ./hello_world

两者都能正常运行。

您能否提供您精确的发行版版本?

关于GDB步骤调试相关内容:如何在QEMU用户模式下使用GDB逐步调试动态链接的可执行文件?


对于静态链接,您需要安装musl:apt install musl,然后运行aarch64-linux-gnu-gcc -ggdb3 -static -o hello_world hello_world.c - RandomDice 779

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接