6

I am trying to simulate a simple Hello world ARM example on my desktop computer. I tried both qemu and gem5. Both gives a similar error. They cannot find ld-linux-aarch64.so.1. Actually I cannot find it either. If I could find it, I will show it with -L (in qemu) or --redirects (in gem5).

The file is:

armhello: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=23a21b7a545ac510923b6b3713d2bbee092f820a, for GNU/Linux 3.7.0, not stripped

It is compiled with: aarch64-linux-gnu-gcc

I am trying to run it in qemu with:

qemu-aarch64 armhello

I got this error:

/lib/ld-linux-aarch64.so.1: No such file or directory

I try to run it in gem5 with: (simpleARM.py points to my executable (named as armhello))

build/ARM/gem5.opt configs/tutorial/simpleARM.py

I got this error:

panic: panic condition fd < 0 occurred: Failed to open file /lib/ld-linux-aarch64.so.1.

How can I solve this?

Note: I know it works when compiled --static. But I need to run more complex binaries that are dynamically linked and I cannot change those. This is just an example.

cervX
  • 85
  • 1
  • 1
  • 6
  • 1
    ld-linux-aarch64.so.1 is the dynamic linker for the guest binary. If you have a dynamically linked guest binary then you need to tell the emulator about not just the binary itself but also the dynamic linker and all the dynamic libraries that the guest binary links to (usually by passing it an option to tell it about a directory which has all the libraries in the usual places they would be on the real filesystem of the guest). – Peter Maydell Oct 27 '20 at 11:05

2 Answers2

3

For gem5 you can use --redirects and --interp-dir: How to run a dynamically linked executable syscall emulation mode se.py in gem5?

For qemu you need -L: Using dynamic linker with qemu-arm

Ciro Santilli
  • 3,693
  • 1
  • 18
  • 44
  • Thank you for your answer. I can run the simple hello world example now. I am not sure how to use --redirect with more complex binary. I understand it "redirects" /lib to some path we decide. It works with `ld-linux-aarch64.so.1`. But for example, I have a shared object that is linked during compilation. This shared object is `libarmnn.so.22` and it is located at `/home/username/armnn/build`. How can I show this path to gem5 so that it can access it? – cervX Oct 27 '20 at 20:44
  • @cervX `--redirect` transforms `=` for all file accesses. The guest searches for lib at a given path. So you have to determine the shared library path the guest will try to use, e.g. [with `readelf`](https://unix.stackexchange.com/questions/120015/how-to-find-out-the-dynamic-libraries-executables-loads-when-run/220110#220110) or from error messages, and then use a prefix that does the correct redirection. It depends on how exactly you link. If a full path is used for .so, you might not need any redirect. – Ciro Santilli Oct 28 '20 at 08:34
  • I see. I overcame the issue using --env option of gem5. I'll leave this comment for future reference. – cervX Oct 29 '20 at 03:21
3

same problem on x86_64 machine docker build with an arm64 docker image:

FROM multiarch/qemu-user-static:x86_64-aarch64 as qemu

FROM alpine

COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin/
RUN apk update
#  add this line to resolve
RUN apk add libc6-compat
张馆长
  • 1,321
  • 10
  • 11
  • I have no idea how you figured this out, but this worked for my issue (running a arm64-compiled binary, on an arm64 container, on an amd64 host (a 2017 Macbook Pro). Thank you!! I only needed to add a `RUN apk update` before the `add` – Nico Villanueva Oct 25 '22 at 14:29