x86_64 Ubuntu 20.04 如何运行 aarch64 ELF 可执行文件?

x86_64 Ubuntu 20.04 如何运行 aarch64 ELF 可执行文件?

我根据以下 Dockerfile 构建一个 Docker 容器:

FROM ubuntu:20.04
RUN apt-get update && apt-get -y install clang gcc-aarch64-linux-gnu

我在 x86_64 macOS v10.15.7 主机系统上,这意味着 Docker 容器将看到 x86_64 CPU,我通过在容器内运行以下命令来确认这一点:

$ lscpu
Architecture: x86_64
# remaining output omitted for brevity

然后我使用容器内部的以下命令编译并运行 aarch64 汇编程序:

$ clang -nostdlib -fno-integrated-as -target aarch64-linux-gnu -s hello_world.s -o hello_world.out

$ file hello_world.out
hello_world.out: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, BuildID[sha1]=a4622c2802958a4c37ae82ec21f510e9f823ca4a, stripped

$ ./hello_world.out
Hello world!

我的问题是:这是如何工作的?如何在 x86_64 Ubuntu 上运行 aarch64 ELF 文件?QEMU 未安装,那么是什么提供了 aarch64-to-x86_64 仿真层?这可能是 Docker 或底层 macOS 主机系统的某些功能吗?

相关内容