Can Old Arm32 Binary Files Be Run on Aarch64 Kernel

Can old ARM32 binary files be run on AARCH64 kernel?

Thank you moonbutt74. You had provided an useful clue for me to seek the solution to that issue.

To enable the support of running ARM32-Linux programs on AARCH64 kernel, the option in the kernel should be selected:

  1. run make menuconfig ARCH=arm64
  2. go to the option and select it:

Userspace binary formats
---> Kernel support for 32-bit EL0


  1. recompile the kernel by running make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

  2. run the recompiled kernel with ramdisk and qemu-system-aarch64.

  3. the "Hello, World!" programs in (ARM32 and AARCH64) can be executed successfully !!

The screenshot of "make menuconfig ARCH=arm64"

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

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. Quoting from WikiChip:

  • Only the 64-bit AArch64 execution state is support. No 32-bit AArch32 support.

So, this explains why it's not able to run 32-bit ARM binaries. I'm still fairly sure that other 64-bit ARM chips, like the Cortex-A57, are able to do this.

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:

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!

run 32bit elf on aarch64

As the linked post suggests, this requires CONFIG_COMPAT to be enabled in the kernel. On the other hand I would be surprised if your kernel didn't have it -- the Debian 4.9.0-4 kernel I have from doing that tutorial does set CONFIG_COMPAT. You can check whether your kernel has it enabled by looking at the config file for it which will be in /boot/ in the guest. If it's missing then you need a new kernel, and nothing else will help.

However in your case you do have CONFIG_COMPAT, and some executables work. The difference between the ones that work and the ones that don't is that the working ones are EABI, and the non-working ones are OABI. OABI is an old and obsolete ABI for 32-bit Arm Linux binaries (the "O" stands for "old", and it's been a bad choice for a decade or so...) and it is not supported by the 64-bit kernel's CONFIG_COMPAT. You'll need to rebuild those binaries from source as EABI binaries if you want to run them under a 64-bit kernel.

How can i emulate an x86 32 bits program on an ARM host?

x86_64-linux-gnux32-gcc is not what you want for building 32-bit programs. This is actually a 64-bit compiler that targets the x32 ABI, a scheme to have 64-bit code that needs only 32 bits for pointers. It never really caught on and is fairly obscure these days, so I'm not surprised that qemu wouldn't support it.

The x86_64 target of gcc supports building 32-bit programs as well, using the -m32 option. So you ought to be able to build your 32-bit Hello World with

x86_64-linux-gnu-gcc test1.c -o test1_32 -m32

(You might have to separately install 32-bit x86 libraries to successfully cross compile.)

Then to run it, use qemu-i386 instead of qemu-x86_64.

build kernel with aarch64-linux-gnu-gcc

looks like a PATH issue. what happens when you just type "aarch64-linux-gnu-gcc "in your shell? does it find the compiler?



Related Topics



Leave a reply



Submit