ncrewrite tool
ncrewrite is a tool that can convert a glibc-based dynamically-linked executable or library that works under NaCl to one that works with the native Linux glibc, and back again.
ncrewrite rewrites the alignment instructions that nacl-gcc inserts before indirect jumps into no-ops, so
and $0xffffffe0, %reg jmp *%reg
becomes
nop; nop; nop jmp *%reg
The resulting executable will then work with libraries where indirect jump targets (i.e. function entry points and function call return addresses) are not 32-byte-aligned, such as the normal Linux libc.so.
This trick helps avoid the problems associated with cross-compilation. A lot of build systems expect to be able to run the executables they build. By putting ncrewrite --nop into a gcc wrapper, the executables built will be directly runnable.
This means that the Python build now runs to completion when building with nacl-glibc; it no longer segfaults when trying to run the python executable it has built outside of sel_ldr.
This is based on an idea I wrote down in a blog post earlier in the year. I originally intended to use ELF relocations to indicate which instructions needed to be rewritten. I later realised that this would not be necessary, because the NaCl validator can already reliably disassemble x86 code compiled for NaCl and find the indirect jumps that need to be changed.
