linux - 尽管有 CONFIG_COMPAT,但在 aarch64 上运行 32 位 ARM 二进制文件不起作用

标签 linux arm arm64

我有一台 64 位 ARM 机器,我想在它上面运行 32 位 ARM 二进制文件。作为测试用例,我使用 arm-linux-gnueabihf-gcc 为 32 位 ARM 构建了一个小的 hello world工具链。 file显示为:

root@ubuntu:/home/ubuntu# file hello
hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=61ffe5e22117a6d4c2ae37a1f4c76617d3e5facc, not stripped

但是尝试运行它会产生:
root@ubuntu:/home/ubuntu# ./hello
bash: ./hello: cannot execute binary file: Exec format error

基于 a prior question , 我检查内核是否是用 CONFIG_COMPAT 构建的选项,它是:
root@ubuntu:/home/ubuntu# grep CONFIG_COMPAT= /boot/config-$(uname -r)
CONFIG_COMPAT=y

我还验证了 armhf已添加架构,并且 armhf存在加载器的版本。请注意,加载程序本身也不会运行:
root@ubuntu:/home/ubuntu# dpkg --print-foreign-architectures
armhf
root@ubuntu:/home/ubuntu# dpkg -l libc6:armhf
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version       Architecture Description
+++-==============-=============-============-=================================
ii  libc6:armhf    2.30-0ubuntu2 armhf        GNU C Library: Shared libraries
root@ubuntu:/home/ubuntu# file /lib/arm-linux-gnueabihf/ld-2.30.so 
/lib/arm-linux-gnueabihf/ld-2.30.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=dff2b536287d61ddca68f3e001e14b7c235bbf68, stripped
root@ubuntu:/home/ubuntu# /lib/arm-linux-gnueabihf/ld-2.30.so
bash: /lib/arm-linux-gnueabihf/ld-2.30.so: cannot execute binary file: Exec format error

其他相关系统信息:
root@ubuntu:/home/ubuntu# cat /proc/cpuinfo 
processor       : 0
BogoMIPS        : 400.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics cpuid asimdrdm
CPU implementer : 0x43
CPU architecture: 8
CPU variant     : 0x1
CPU part        : 0x0af
CPU revision    : 2

root@ubuntu:/home/ubuntu# uname -a
Linux ubuntu 5.3.0-24-generic #26-Ubuntu SMP Thu Nov 14 01:14:25 UTC 2019 aarch64 aarch64 aarch64 GNU/Linux

在这一点上,我没有什么可以尝试的了。知道如何让内核识别这些二进制文件并运行它们吗?

最佳答案

好吧,不幸的是,这里的潜在问题似乎不在软件中。我们使用的 CPU Cavium ThunderX2 是少数不支持 aarch32 的 64 位 ARM 芯片之一。引自 WikiChip :

  • 仅支持 64 位 AArch64 执行状态。不支持 32 位 AArch32。

  • 所以,这就解释了为什么它不能运行 32 位 ARM 二进制文件。我仍然相当确定其他 64 位 ARM 芯片,如 Cortex-A57,能够做到这一点。

    更新:较旧的 32 位 ARM 二进制文件确实可以在具有支持它的 CPU 的 aarch64 上运行,如下所示在 AWS ARM a1.metal 实例上:
    ubuntu@ip-172-31-12-156:~$ cat /proc/cpuinfo | tail
    
    processor   : 15
    BogoMIPS    : 166.66
    Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
    CPU implementer : 0x41
    CPU architecture: 8
    CPU variant : 0x0
    CPU part    : 0xd08
    CPU revision    : 3
    
    ubuntu@ip-172-31-12-156:~$ uname -a
    Linux ip-172-31-12-156 4.15.0-1054-aws #56-Ubuntu SMP Thu Nov 7 16:18:50 UTC 2019 aarch64 aarch64 aarch64 GNU/Linux
    ubuntu@ip-172-31-12-156:~$ dpkg --print-foreign-architectures
    armhf
    ubuntu@ip-172-31-12-156:~$ file hello_hf
    hello_hf: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 3.2.0, BuildID[sha1]=c95f0c46dfab925db53506751d7677156e334e5c, not stripped
    ubuntu@ip-172-31-12-156:~$ ./hello_hf
    hello, world!
    

    关于linux - 尽管有 CONFIG_COMPAT,但在 aarch64 上运行 32 位 ARM 二进制文件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59379848/

    相关文章:

    linux - Linux下如何通过删除某些字符之间的内容来批量重命名文件名

    linux - 使用 Wine 在 Linux Mint 上安装 Visual Studio 2015

    qemu - 如何获取qemu机器 "virt"的PERIPHBASE?

    c# - 如何在 dotnet 应用程序中创建导航菜单?

    linux - 操作系统中 Admin-Guest 登录部分的编码

    apache - 针对 ARM 问题交叉编译 Apache

    c - 使用 gnu gcc 编译器定义类型

    c - 哪个是初始堆栈指针的正确值?

    ios - 6.7.0 版中 arm64 Google AdMob 架构的 undefined symbol

    assembly - fcvtzs d0,d0 真的是 AArch64 SIMD 指令吗?