I just spent 30 minutes reading about this. I'm so shocked that I'm logging in to comment after 5 years of lurking.
Justine has built a c library that allows you compile a binary once and have it run it on any os or baremetal. The SAME binary. Quite frankly, that sentence doesn't even make sense to me.
Agreed, this is the best programming-related thing I've seen on the internet in a long time. It reminds me of when I was a teenager, excited to become a computer programmer. Then I grew up and joined the real world workforce and it was all far less exciting than I imagined.
The coolest thing about this Actually Portable Executable is that once there's a compiler and linker built with it, I can play around with writing C on Windows without having to faff about with WSL or MinGW or learning what makes MSVC different from the C I learned in university and coded in my first job before I became a Java/JavaScript/Python/etc programmer. When I discovered Go I thought I had discovered the better C that just worked everywhere, but the idea of having plain old C that also just works everywhere is very appealing.
I like Go for the same reason, but I have an irrational fear that someday I might be in a life or death situation and should program my way out using a bare bones computer without Internet; So I keep tabs on C occasionally.
αcτµαlly pδrταblε εxεcµταblε has now piqued my interest, So I might actually indulge in C programming for fun again after all. Thanks Justine.
I think it's really cool project; but could you explain why it's important that a binary works everywhere for you? I don't really get the enthusiasm for this sort of thing.
Maybe I have a blind spot or something or I've just been in Unix-land for too long.
I think the UNIX thing is the blind spot. People who run Linux or BSD don't seem so bothered to recompile for their own platform, safe in the knowledge that it will almost certainly just work.
But on Windows, trying to get open source software written in C to compile has been a pain for decades. There have been some attempts to make it work (notably Cygwin, and now MSYS2), but it can still be challenging, especially with programs that were never designed to be compiled for non-UNIX (or non-Linux!) targets.
Having a C library that is designed from the ground up to target multiple operating systems, and an executable format that means the first compile is the only compile, that takes away a lot of toil that programmers normally have when trying to build their own abstractions around each platform's C library. I guess from UNIX land you could see the benefit as removing the need for autoconf or platform ifdefs.
Agreed. This single sentence at the end of αcτµαlly pδrταblε εxεcµταblε page:
> I believe the best chance we have of doing that [writing software that stands the test of time with minimal toil], is by gluing together the binary interfaces that've already achieved a decades-long consensus, and ignoring the APIs.
...it's a kind of thought I don't think I could ever come up with. Mind blown.
I agree, I got to the page on actually portable executable, and had to read it a few times to make sure I was grokking it properly. This is just sheer cleverness, THIS is the stuff that should be on hacker news!
It's hard to grok cause there are no words to describe it.
When people say that something is cross-platform, they usually mean
a) that the software will build on multiple platforms
b) there is some sort of vm which runs the executable (jvm, beam, wasm)
This is the SAME binary. Running everywhere. Could be super-useful as an archival format for mission critical code. sqlite comes to mind.
Maybe it's late at night, but I'm struggling to find a suitable word for the project that is better than portable or cross-platform.
Literally, I can't find a better word than the project name - "actually portable executable."
@author - if you're reading this please set up something for a few bucks a month on your github sponsors. I don't think I have any use for the library, but this is so outrageous it deserves something more than imaginary internet points.
Thanks for the links. The discussion on the first one is interesting, it wasn't clear to me from the original doc that the UNIX version needs to overwrite itself to get to the ELF header. That's a bit unfortunate, because it means you can't share the program again after you ran it the first time on BSD or Linux. Still very clever, though. I imagine there could be a "repackage for distribution" switch added to put the MZ header back again.
I did the research and what we've accomplished here, while imperfect, is the best of all worlds solution. I like to think of it as an installer that takes a few microseconds, because it only needs to change 64 bytes. I've been considering adding a CLI flag where you can say ./foo.com --restore and it'll put the original 64 byte header back in place. Perhaps one day we can change the Linux, BSD, and XNU kernels so they can recognize the APE executable format. But until that happens we've got a great shell script hack that's now required by POSIX which is exceedingly fast and works on pretty much all systems stretching back decades.
Everything she does has this level of jaw-dropping amazingness. Between her and Fabrice Bellard i don't know many people who consistently get my chin to hit the table.
I hope that Cosmopolitan becomes mainstream, so much more software could have that It Just Works quality.
Understood (with my apologies, I mistakenly assumed
it was on topic).
FWIW, I like and agree with the things I was referencing, I didn't mean it in any way as a jab or provocation. I shall endeavor to do a better job staying on the topic of the article in question.
Strong agree; someone needs to give her like a million dollars a year salary and unlimited resources to explore whatever she wants for life, just to see what she comes up with.
It's funny because the high-level introductions to C I would read as a kid before I really knew much about computing would almost always start out by explaining that one of the biggest strengths of C was its portability, and how it allowed you to write the same code that worked on every platform. Of course I came to learn that's true only in a sense that has no connection to practical reality, this looks like an exception.
Could you please explain to someone from the web domain with very little experience with compiled C programs why this is significantly better than, say, distributing a python program? Python runs on all the platforms mentioned. Or alternatively requiring compilation from source?
The python script/program ultimately depends on a Python interpreter which currently has to be distributed as a different binary for every platform.
So in the end, the difference is purely where the platform-differentiated compilation happens for VM & interpreted languages like Java & Python.
This would instead allow you to ship a single Python executable that simply works everywhere. Whether with a bundled-in script/program, or just the interpreter.
That sort of malware already exists. This does simplify making it by a lot, because now it can much more easily ensure its portability without external communication.
I really don't understand internals ibut I've often downloaded cygwin exe file for commands like grep, tail, etc.. Are you telling me that is no longer required?
On linux, I downloaded the printvideo binary and played a friggin crab video on my terminal after just a chmod. I don't have any other OS to confirm, but it sure looks like it if someone compiles/links coreutils against this.
Wow, that cosmopolitan C library is absolutely awesome. The ABI specialization is extremely interesting. Never seen anything like that before. I thought compilers did that. I don't understand why they couldn't properly optimize memcpy.
I wonder how it handles system calls. Let me check the source...
That malware for OS X that does nothing (so far) from the news earlier this week also has one multi-arch binary for all modern Apple notebook architectures (AMD64 and ARM64)
I would suggest India because it's a microcosm. Go north to the Himalayas and you can feel the majesty. Head to the west to the slums of Mumbai and you will understand poverty. Maybe go learn to meditate out there at a vipassana center. Visit Agra and the goggle at the opulence of the Taj Mahal. Then head to Varanasi and experience the rawness. Maybe you'll even see a miracle or two if you're lucky. Go to Hampi and see giant boulders stacked on top of each other like lego and be bewildered. Stay in a palace just for the hell of it. Take a motorcycle through small villages and be greeted by the children who've never seen anyone so pale or so dark. Sleep in a tent in the deserts of Rajasthan. Visit the holy places and wonder at the peacefulness.
But then again, India isn't for everyone, but it does have everything.
I'm Indian, so I'll add a few, particularly about some areas that are likely to be less well known to foreigners who may mainly have read or been told about the most popular tourist areas, such as the Golden Triangle (Delhi/Agra/Rajasthan), Goa and Kerala:
Go to parts of central India, e.g. Madhya Pradesh (MP).
It's a big state. Lived there for some years. Apart from the usual touristic areas, of which there are some, try to check out the central Indian deciduous forests, comprising sal, teak, and many other species. (India has huge biodiversity.) I really enjoyed the many hikes I did in those forests.
It has those deciduous forests I mentioned, with fauna that include tigers, gaur (Indian bison - the world's largest bovid), dhole (Indian wild dog), barasingha (swamp deer with 12-tined horns), etc.
Marble Rocks - sheer marble cliffs on both sides of the Narmada river near Jabalpur (MP). They offer boat rides down that stretch, so you can see the cliffs from up close. Seen it.
In South India, less well known places include the "hill stations" (resorts) such as Kodaikanal, Coonoor (5-7000+ feet high, with a cooler climate, and mountain forests and orchards), many less frequented and less crowded beaches, etc. Temples are well known but there are a huge number of them, large and small, many with interesting architecture. Many wildlife sanctuaries in South India too. Seen wild elephants on hikes from the mountains to the plains. Bison too, many times, from nearby. They're huge, but peaceful, unless disturbed. Cape Comorin (Kanya Kumari), the southernmost tip of the Indian peninsula, where the Arabian Sea, Indian Ocean and Bay of Bengal meet. Multi-colored sands there.
Seen some of the above.
The Western Ghats, a long mountain range down the western side of India, right from Mumbai to almost Kankyakumari, including the states of Maharashtra, Goa, Karnataka and Kerala/TamilNadu. Lived in parts of it for some years. It's a biodiversity hotspot, with both deciduous and rain forests.
I've had the T20, the T30, the T41, the T60p, and the X200. The build quality has just been going down. I have a T60 with a busted fan with no screen, think anti-tablet, as a server right now. The X200 had to be sent in for repairs a few times, luckily under warranty, while the T41 keeps going (others have been retired). And before the service was incredible, now it just seems to take longer and longer (well, as of 2 years ago as far as I know).
In 2011, I was shopping for a new laptop and wanted to get something with an SSD, but the X-series was more expensive than an MBA. After a tirade about Apple, I finally gave in despite reservations about no trackpoint and durability. I just don't treat my hardware very well. Regarding durability, I've had this thing protect me while I got clipped by a truck, dropped it off a motorcycle, and had it fall several times. A few dents, but it keeps on going. And the trackpoint, well, I've just learned to live without. C'est la vie. The keyboard works, gotten used to it.
I'm still waiting for something better than the MBA that doesn't cost an arm and a leg. Carbon for $1200 + the honor of having to recompile kernels to get less battery life than other OS's just doesn't cut it anymore. This new one ain't it either.
Loyalty is misguided nowadays. They don't build them like they used to.
Justine has built a c library that allows you compile a binary once and have it run it on any os or baremetal. The SAME binary. Quite frankly, that sentence doesn't even make sense to me.
Check out https://storage.googleapis.com/justine/cosmopolitan/index.ht...
As far as I'm concerned, this is literal magic. Look at the magic numbers: https://github.com/jart/cosmopolitan/blob/37a4c70c3634862d8d...
I could go on, but there's no binary portability comparison with any other language. And she has made some pretty neat optimizations.
Back in the day, I saw some pretty neat stuff with the ELF format, but this takes the cake.
Wow.
Edit: I'm editing because this is just so bloody absurd.
https://storage.googleapis.com/justine/printimage.html
$ ./printimage.com someimage.jpg
Like wow. And also video.
https://storage.googleapis.com/justine/printvideo.html
I'm struggling to put my shock into words. I've been around.
There's engineering. There's academia.
But this falls into straight-up wizardry.