Roberto Segebre

ExampleFind

Example post, written to show this format.

Actually Portable Executables

Justine Tunney’s Cosmopolitan libc builds one binary that runs on several operating systems. The essay is the part I keep sending to people.

https://justine.lol/ape.html

The page is Actually Portable Executables. It describes a binary format, built with Cosmopolitan libc, that runs on Linux, Mac, Windows, FreeBSD, OpenBSD, and NetBSD without an install step.

I keep coming back to it because most “write once, run anywhere” stories are runtimes. This one is a file. You copy it, you mark it executable or you double-click it, and the same bytes are a program on more than one kernel. The trick is a polyglot header: the file is a shell script, a Windows executable, and a Unix ELF, and each platform reads the part it understands.

That is a ridiculous idea that happens to work, which is my favorite kind of systems work. I do not ship portable executables in my day-to-day, and I am not suggesting anyone replace a normal build. The note I want is the stance. A program can be an artifact you hand to someone. The essay is specific about how the header is laid out, so it is also a good read if you like file formats and you want the mechanism rather than the slogan.