ARM Linux executable mysteriously runs on x86_64

后端 未结 1 1911
醉梦人生
醉梦人生 2021-02-20 18:20

I\'m using the Docker container (thewtex/cross-compiler-linux-armv7) to cross-compile a simple \"Hello World\" Linux user space C program on an x86_64

1条回答
  •  自闭症患者
    2021-02-20 19:24

    There is a mechanism in the Linux kernel called binfmt_misc that can be used to associate arbitrary interpreters with executables. This association can either be based on a magic byte sequence at the beginning of the executable itself, or its file extension (e.g., wine automatically registers itself for *.exe files). Interpreters are registered in the kernel by writing to the /proc/sys/fs/binfmt_misc/ sysfs.

    On Fedora, the systemd-binfmt service is responsible for the interpreter registration. It reads a set of configuration files from the /usr/lib/binfmt.d directory and performs the necessary writes to the sysfs. In the context of the above question, installation of the qemu emulator-suite will place the corresponding configuration files in this directory. For ARM this file is called qemu-arm and has the following content:

    enabled
    interpreter /usr/bin/qemu-arm
    flags: 
    offset 0
    magic 7f454c4601010100000000000000000002002800
    mask ffffffffffffff00fffffffffffffffffeffffff
    

    This allows to transparently execute statically linked ARM executables on Linux. Thanks to Mark Plotnick for pointing this mechanism out.

    0 讨论(0)
提交回复
热议问题