Hacker News new | ask | show | jobs
by TimTheTinker 13 days ago
Yes, polyglot binaries are a straightforward extension of the notion of polyglot source code to binary executable files. But APE/Cosmopolitan takes this to insane levels:

- a fully cross-platform libc with cross-platform support built into the output binary, integrated into clang and gcc toolchains

- not just cross-platform, but also cross-architecture: output binaries work unmodified on both AMD64 and ARM64 architectures

- sheer number of executable format compatibilities: it's a polyglot across macOS, linux, windows, 3 BSDs, and a bootable BIOS target

- polyglot not just for executable outputs, but also for PKZIP. You can open and modify an executable using common zip file editors. And post-hoc zipped-in data can be accessed/modified by code in the executable using interfaces in cosmopolitan libc

- Zip polyglot can be used to create portable embeddable code-packaged interpreters where the code being interpreted is loaded/executed from zipped-in data. One example: RedBean is a very high-performance APE-packaged web server that serves data in its zip archive and hosts web service code from Lua scripts in its zip archive. Built-in library enables Lua code to store/retrieve data from zipped-in SQLite databases.

The comparison to the demoscene and IOCCC is apt, but this is at another level because it's all production-ready. The Llamafile format is an APE binary compiled with Cosmopolitan libc with model weights zipped into it.

1 comments

APE is too much of a hack to be called "production-ready". It works, but there really is not much guarantee it will continue to do so.
There's an "ape loader" that speeds up loading the executable on various platforms -- that will guarantee it continues to work, as it can evolve with the platform to continue support for binary format.