[cfe-dev] LibC++ v4.0 testing and exceptions

Tim Northover via cfe-dev cfe-dev at lists.llvm.org
Thu Feb 9 19:51:46 PST 2017


On 9 February 2017 at 09:21, Martin J. O'Riordan
<martin.oriordan at movidius.com> wrote:
> 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
needed.

There's a rough description of the syntax at
https://en.wikipedia.org/wiki/Binfmt_misc. The command I use for
AArch64 ELF is:

echo ':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\x
ff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/home/tim/bin/qemu-aarch64-wrapper:'
> /proc/sys/fs/binfmt_misc/register

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.

Tim.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: aarch64-toolchain.cmake
Type: text/x-cmake
Size: 687 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170209/6c217503/attachment.bin>


More information about the cfe-dev mailing list