簡體   English   中英

盡管有 CONFIG_COMPAT,但在 aarch64 上運行 32 位 ARM 二進制文件不起作用

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

我有一台 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

基於先前的問題,我檢查了內核是否是使用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!

隨着 32 位 ARM 芯片被逐步淘汰,這個問題變得更加重要。 我,我喜歡看到新的 64 位硬件支持舊的 32 位二進制文​​件。 不是很重要,但很方便。 我拿出了我的舊 Raspberry Pi Zero(32 位)和 Raspberry Pi 3B+(64 位),並第一次在 3B+ 上安裝了 64 位操作系統,盡管有錯誤等警告,並做了一些編譯。 沒有特殊的 make 參數。 只是普通的普通 32 位編譯。 在 32 位和 64 位上運行良好。 控制器和虛擬機將運行 32 位架構很多年。 4GB 內存限制很痛苦,是的。 但對於小型應用程序來說,這不是問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM