Static recompiler · GPL-2.0-or-later
Run AArch64 Linux programs natively on x86-64 and 32-bit ARM.
a64port turns a 64-bit ARM Linux binary into portable C, once. An ordinary C compiler then builds that C for your PC or for a 32-bit ARM board. The result is a native program: no emulator and no JIT run beside it.
# AArch64 binary in, x86-64 binary out
a64recomp prog-a64 emit/ --mod t --trusted --callret
CC=clang build-guest.sh emit/ --out bin/prog --opt -O2
bin/prog
How it works
-
1
Find the code
The driver walks every executable section from the entry point, function boundaries, dynamic symbols, switch tables and code pointers in data. Anything it cannot translate is reported, never skipped.
-
2
Translate to C
Each guest function becomes a C function. Calls become host calls, flags are computed only where they are read, and floating point stays bit-exact unless the host's result is provably the same.
-
3
Build for your host
The same C builds with clang for x86-64 or for ARMv7. A small runtime maps Linux system calls, threads, futexes and signals onto the host's.
| Host | What you get |
|---|---|
| x86-64 Linux | AArch64 Linux software running on a normal PC, at native speed of the translated code |
| 32-bit ARM Linux (ARMv7-A, NEON) | 64-bit ARM software on older 32-bit boards, which QEMU no longer supports |
| AArch64 Linux | a native rebuild of the same program |
Built for whole programs
-
Dynamic linking
The guest's own
ld.so, C library and C++ runtime are translated too. The loader maps the executable and the dynamic linker, and the translatedld.sodoes the rest. -
Threads, signals, sockets
One host thread per guest thread, real futexes, signal handlers, TCP,
epoll, timers and pipes, checked againstqemu-aarch64. -
64-bit on 32-bit hosts
A 64-bit process fits into a 32-bit one: one identity-mapped address range, system calls and structures translated field by field, atomics and exclusive accesses kept correct on a weakly ordered CPU.
-
Exact floating point
Every operation matches AArch64 bit for bit by default. A native fast path is used only when its result is provably identical.
-
Hand-written leaves
Replace the few hottest functions with C of your own, then check the replacement against the translated original on random states before it ships.
-
Bring your own binary
The repository contains no one else's program, firmware or library. You recompile software you are entitled to use.
Tested against the real thing
Every test runs the original AArch64 program under qemu-aarch64 and the
recompiled one natively, and compares the exit status and every byte of output. Two scripts in the repository
run the whole matrix.
| Program | What it exercises | x86-64 | ARMv7 |
|---|---|---|---|
| Lua 5.4.6 | interpreter, closures, coroutines, errors through longjmp, GC, floats, file I/O | identical | identical |
| SQLite 3.46.1 shell | file database with locking, transactions and rollback, window functions, JSON, VACUUM | identical | identical |
zlib 1.3.1 minigzip | compression at three levels, byte-identical output, round trips | identical | identical |
| 11 test programs | static glibc, threads under contention, signals, sockets, epoll, timers, arguments | identical | identical |
a64port was built for, and runs, a large commercial application: a dynamically linked C++ GUI program with hundreds of threads and real-time audio, on a 32-bit ARM board at the application's own frame rate. The paper describes that work.
Quick start
Needs g++ (C++20), clang, ld.lld and
qemu-aarch64. For ARMv7 builds also qemu-arm and an armhf sysroot.
1. Build the driver and run the self-test
git clone https://github.com/erhan-/a64port.git a64port && cd a64port
g++ -std=c++20 -O2 -Irepo/third_party/mk8-recomp \
repo/tools/recomp/a64recomp.cpp -o repo/tools/recomp/a64recomp
tests/run-tests.sh
2. Recompile a program for this PC
repo/tools/recomp/a64recomp my-program-a64 /tmp/emit --mod t --trusted --callret
CC=clang repo/tools/recomp/build-guest.sh /tmp/emit --out /tmp/my-program --opt -O2
/tmp/my-program
3. The same program for a 32-bit ARM board
CC=scripts/armv7-cc repo/tools/recomp/build-guest.sh /tmp/emit --out /tmp/my-program-arm --opt -O2
The tutorial in docs/TUTORIAL.md continues with dynamically linked applications, hooks for devices
a program expects, hand-written leaves and profiling.
The paper
Running a 64-bit ARM Application on 32-bit Hardware: Static Recompilation of a Real-Time DJ Player from AArch64 to ARMv7 describes how a64port runs a complete commercial application on a weaker 32-bit device: fitting a 64-bit process into 32 bits, the code generation changes and what they bought, and how hand-written replacements were tested against the original machine code.
Download the paper (PDF)Limits
- No fallback: an instruction the translator does not handle stops the program.
- Linux user-space programs only. The guest's own C library is translated, never replaced by the host's.
- Signals are delivered at system call boundaries; synchronous faults and
sigaltstackare not supported. - Guest addresses must fit below 4 GB on 32-bit hosts, which holds for non-PIE executables.
- The runtime builds with clang.