简体   繁体   English

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

[英]Running 32-bit ARM binary on aarch64 not working despite CONFIG_COMPAT

I've got a 64-bit ARM machine that I'd like to run 32-bit ARM binaries on.我有一台 64 位 ARM 机器,我想在它上面运行 32 位 ARM 二进制文件。 As a test case I've built a small hello world for 32-bit ARM using the arm-linux-gnueabihf-gcc toolchain.作为测试用例,我使用arm-linux-gnueabihf-gcc工具链为 32 位 ARM 构建了一个小型 hello world。 file shows it as: 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

But trying to run it produces:但是尝试运行它会产生:

root@ubuntu:/home/ubuntu# ./hello
bash: ./hello: cannot execute binary file: Exec format error

Based on a prior question , I checked whether the kernel was built with the CONFIG_COMPAT option, and it was:基于先前的问题,我检查了内核是否是使用CONFIG_COMPAT选项构建的,它是:

root@ubuntu:/home/ubuntu# grep CONFIG_COMPAT= /boot/config-$(uname -r)
CONFIG_COMPAT=y

I also verified that the armhf architecture has been added and that the armhf version of the loader is present.我还验证了armhf架构已添加并且加载程序的armhf版本存在。 Note that the loader itself doesn't run either:请注意,加载程序本身也不会运行:

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

Other relevant system info:其他相关系统信息:

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

I'm running out of things to try at this point.在这一点上,我没有什么可以尝试的了。 Any idea how to get the kernel to recognize these binaries and run them?知道如何让内核识别这些二进制文件并运行它们吗?

Ok, it looks like the underlying problem here is not in software, unfortunately.好吧,不幸的是,这里的潜在问题似乎不在软件中。 The CPU we're using, the Cavium ThunderX2, is one of the few 64-bit ARM chips that does not have aarch32 support.我们正在使用的CPU,在Cavium公司ThunderX2,是具有aarch32支持少数的64位ARM芯片。 Quoting from WikiChip :引用自WikiChip

  • Only the 64-bit AArch64 execution state is support.仅支持 64 位 AArch64 执行状态。 No 32-bit AArch32 support.不支持 32 位 AArch32。

So, this explains why it's not able to run 32-bit ARM binaries.所以,这就解释了为什么它不能运行 32 位 ARM 二进制文件。 I'm still fairly sure that other 64-bit ARM chips, like the Cortex-A57, are able to do this.我仍然相当确定其他 64 位 ARM 芯片,如 Cortex-A57,能够做到这一点。

Update: older 32-bit ARM binaries do indeed work on aarch64 with a CPU that supports it, as shown below on an AWS ARM a1.metal instance:更新:较旧的 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!

This question has become more relevant as 32bit ARM chips are being phased out.随着 32 位 ARM 芯片被逐步淘汰,这个问题变得更加重要。 Me, I like to see old 32 bit binaries supported on new 64 bit hardware.我,我喜欢看到新的 64 位硬件支持旧的 32 位二进制文​​件。 Not so important, but convenient.不是很重要,但很方便。 I took out my old Raspberry Pi Zero (32 bit) and Raspberry Pi 3B+ (64 bit) and for the first time installed a 64 bit OS on the 3B+ despite warnings of bugs and such and did some compiling.我拿出了我的旧 Raspberry Pi Zero(32 位)和 Raspberry Pi 3B+(64 位),并第一次在 3B+ 上安装了 64 位操作系统,尽管有错误等警告,并做了一些编译。 No special make parameters.没有特殊的 make 参数。 Just plain ordinary 32 bit compiling.只是普通的普通 32 位编译。 Runs fine on 32 bit and 64 bit.在 32 位和 64 位上运行良好。 Controllers and VMs will be running 32 bit architecture for many more years.控制器和虚拟机将运行 32 位架构很多年。 4GB memory limit is a pain yes. 4GB 内存限制很痛苦,是的。 But for small apps its not a problem.但对于小型应用程序来说,这不是问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM