exec format error on Raspberry Pi - 32-bit binary, 64-bit OS
Measured on a Raspberry Pi 5 running a 64-bit kernel (Linux 7.0.0-1023-raspi, uname -m =
aarch64).
What happens
A binary built for 32-bit ARM (armhf) does not run on a 64-bit Raspberry Pi OS:
$ ./mybinary
bash: ./mybinary: cannot execute binary file: Exec format error
The same message appears with the exec format error wording from other shells. The kernel
is refusing the file because its e_machine says 32-bit ARM and this kernel has no 32-bit
personality loaded for it.
Verified on the Pi 5 by taking a working aarch64 binary and setting e_machine to the 32-bit
ARM value — the kernel rejects it identically:
file: ELF 64-bit LSB pie executable, ARM, version 1 (SYSV), dynamically linked
bash: /tmp/arm32-true: cannot execute binary file: Exec format error (exit 126)
Confirm it in two commands
$ uname -m
aarch64 # the OS is 64-bit
$ file ./mybinary
ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV),
dynamically linked, interpreter /lib/ld-linux-armhf.so.3
^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^
32-bit, ARM 32-bit ARM loader
The pattern to look for is ELF 32-bit + ARM on a host whose uname -m is aarch64.
If instead you see ELF 64-bit ... ARM aarch64, the binary matches and your problem is
something else (usually a missing library, which reports differently).
The three combinations that matter
Host (uname -m) |
Binary says | Runs? |
|---|---|---|
aarch64 |
ELF 64-bit ... ARM aarch64 |
✅ yes |
aarch64 |
ELF 32-bit ... ARM, EABI5 |
❌ this article — needs a 32-bit userland |
armv7l |
ELF 64-bit ... ARM aarch64 |
❌ the reverse: 64-bit binary on a 32-bit OS |
armv7l vs aarch64 in uname -m is the quickest way to tell which OS image you flashed.
Raspberry Pi OS ships both; a card flashed with the 32-bit image reports armv7l.
The fixes, in order of preference
1. Use the arm64 build (correct)
Most projects publish an arm64/aarch64 artifact. On a Pi 4 or 5 with a 64-bit OS, that is
the build you want — it is also faster, because 64-bit ARM on those SoCs has more registers
and better instructions.
# check what you actually downloaded
file ./release-binary | grep -i aarch64
2. Rebuild from source on the Pi
If no arm64 build exists, compile on the target. Slower on a Pi, but correct on the first try:
sudo apt-get install -y build-essential
make # or: go build / cargo build --release
3. Install the 32-bit compatibility libraries
On a 64-bit OS you can add the armhf architecture, which gives you the 32-bit loader the binary expects:
sudo dpkg --add-architecture armhf
sudo apt-get update
sudo apt-get install -y libc6:armhf
This works for simple dynamically linked binaries. It does not make the kernel accept a 32-bit binary on hardware that has dropped 32-bit support — on a Pi 5 this route is a dead end for anything non-trivial, and rebuilding (option 1 or 2) is the real answer.
4. Emulate it (last resort)
sudo apt-get install -y qemu-user-static binfmt-support
Correctness yes, performance no: expect a large slowdown and, on a Pi, a hot CPU. For a one-off data conversion it is fine; for anything long-running, rebuild.
What does not help
| Attempt | Why |
|---|---|
chmod +x |
The file is already executable; the kernel rejected its machine type |
sudo ./mybinary |
Privileges do not change the instruction set |
Copying ld-linux-armhf.so.3 from another Pi |
The loader is a 32-bit program; the kernel still will not exec it |
| Re-flashing the same 64-bit image | The image was never the problem — the binary is |
Check before you download
Release pages often list several ARM variants with names that do not spell out the width:
myapp-linux-arm.tar.gz ← usually 32-bit armhf (ambiguous, check with file)
myapp-linux-arm64.tar.gz ← 64-bit
myapp-linux-aarch64.tar.gz ← 64-bit
myapp-linux-armv7.tar.gz ← 32-bit
After extracting, always:
file ./myapp | grep -E '32-bit|64-bit'
If it says 32-bit and your Pi runs a 64-bit OS, you have your answer before you run it.
For a second opinion on the binary itself, ELF Inspector reads the header in the browser and prints the class and machine — 32-bit ARM vs 64-bit AArch64 is one line apart, and that line is the whole problem.
The 32-bit rejection above was reproduced on a Raspberry Pi 5 (aarch64) by setting
e_machine to the 32-bit ARM value in a working binary. Raspberry Pi OS ships both 32-bit
and 64-bit images; uname -m tells you which one you are on.