【问题标题】:Using dynamic linker with qemu-arm使用带有 qemu-arm 的动态链接器
【发布时间】:2019-02-21 08:42:53
【问题描述】:

我有一个使用arm-linux-gnueabi 工具链编译的非常简单的arm 可执行文件。我可以用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 中运行)
  • 我无法运行ldd,但这是readelf -d a.out 的输出:pastebin.com/G6TBxddi
  • 好像找不到libc.so.6
  • 你能把ld --verbose | grep SEARCH_DIR | tr -s '; ' \\012的输出贴出来吗?

标签: linux arm qemu


【解决方案1】:

我无法在 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 单步调试相关:How to GDB step debug a dynamically linked executable in QEMU user mode?

【讨论】:

    猜你喜欢
    • 2016-01-26
    • 2021-09-20
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-26
    相关资源
    最近更新 更多