Thanks Tim, can you send me more info about how to do this?
Sure. Basically, binfmt_misc is a facility provided by the Linux
kernel. It lets you say something along the lines of "if I tell you to
run a program and the file has bytes X Y Z at offset N, run this
wrapper with the binary as an argument instead". I think the original
intent was to allow userland extension of the binary formats supported
(Java .jar files was the first time I heard of it), but it turns out
to be very useful for running non-native binaries if shenanigans are
There's a rough description of the syntax at
binfmt_misc - Wikipedia. The command I use for
AArch64 ELF is:
The weird bytes just happen to be enough to identify an AArch64 ELF
executable file. The "\xb7\x00" is the EM_AARCH64 encoding which you'd
want to change if you were an otherwise normal 64-bit ELF platform.
Possibly others if you output ELF32 or have other oddities. I'm happy
to help out if you can't work out what you need.
After that, as long as /home/tim/qemu-aarch64-wrapper can produce the
correct stdout/stdin/exitcode/filesystem effects you're good to go.
Mine's pretty trivial, just specifying a fixed sysroot and running
qemu on the given binary, but you could easily run a remote ssh and
gather its results, or run post-link black magic before handing off to
some simulator or hardware-connection.
Other than that, I just run "cmake -DCMAKE_TOOLCHAIN_FILE=Thing ..."
which points $CC at aarch64-linux-gnu-gcc instead of gcc (I've
attached my file here, just in case it's useful). I'm reasonably sure
the llvm-tblgen that gets executed while actually compiling LLVM is an
AArch64 binary, but it runs fine so who cares.
Actually, that last point may be a problem for you if your target
can't access the same filesystem. CMake has some kind of 2-step
TableGen that ought to allow you to build TableGen for the host while
generally cross-compiling everything else, but I've never really
bothered to work out how to use or trigger that I'm afraid.
Let me know if anything's unclear.
aarch64-toolchain.cmake (687 Bytes)