5

I have a very simple arm executable compiled with the arm-linux-gnueabi toolchain. I can execute it with qemu-arm without any problem:

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

Running the linker without any argument seems to work as well:

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

However if I want the linker to run my executable, here is what happens:

$ 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

Here is the output of strace: https://pastebin.com/uJ7AhBdh

Any idea why this is happening ?

ttk203
  • 347
  • 5
  • 10

1 Answers1

5

I can't reproduce the problem on 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

and 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

both run fine.

Can you also provide your exact distro version?

Reletated for GDB step debug: How to GDB step debug a dynamically linked executable in QEMU user mode?

Ciro Santilli
  • 3,693
  • 1
  • 18
  • 44
  • for static linking, you need musl: `apt install musl`, then `aarch64-linux-gnu-gcc -ggdb3 -static -o hello_world hello_world.c` – RandomDice 779 May 23 '22 at 09:31