Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Tiniest x86-64-Linux emulator (github.com/jart)
192 points by begoon on Nov 19, 2022 | hide | past | favorite | 23 comments


They also made cosmopolitan libc [0] which outputs a single binary that runs on many platforms.

> The above command fixes GCC so it outputs portable binaries that will run on every Linux distro in addition to Mac OS X, Windows NT, FreeBSD, OpenBSD, and NetBSD too. Your program will also boot on bare metal too. In other words, you've written a normal textbook C program, and thanks to Cosmopolitan's low-level linker magic, you've effectively created your own operating system which happens to run on all the existing ones as well.

Brought up recently here: "Debugging C with Cosmopolitan Libc" [1]

And introduced here "Cosmopolitan Libc: build-once run-anywhere C library" [2]

[0] https://justine.lol/cosmopolitan/index.html

[1] https://news.ycombinator.com/item?id=33312012

[2] https://news.ycombinator.com/item?id=25556286


Can you build cross platform libs? So like say you have python or java that calls out to some native code (ex: high performance math routines), but that native code is actually "cosmopolitan"/crossplatform?


Why not? The difference between an executable and a dynamic library is that an executable has one entry point but a dynamic library can have more than one.


man, jart's projects make me feel that 1/10x engineer


the only person that can compete with Fabrice Bellard


Fabrice is on a higher level (mainly by virtue of being older, possibly more numerate)



it's not for us mortals to judge the Gods


And "lower", too. He even created DVB-T signals from the monitor refresh frequency by tuning X11's specs.


Or 1/100. Crazy. But as said not sure I aware qemu is so small. Thanks.


The projects of even a normal dev make me feel 1/10x sometimes. Was told I might need ADHD meds to be productive. I haven't gotten to try any yet.


Biggest thing for me here is I didn't realise qemu-x86_64 was only 10mb!


> It'll be nice to know that any normal PC program we write will "just work" on Raspberry Pi and Apple ARM. All we have to do embed an ARM build of the emulator above within our x86 executables, and have them morph and re-exec appropriately, similar to how Cosmopolitan is already doing doing with qemu-x86_64, except that this wouldn't need to be installed beforehand. The tradeoff is that, if we do this, binaries will only be 10x smaller than Go's Hello World, instead of 100x smaller.

…No mention of the fact that an interpreter is typically at least 10x slower than native execution. The readme does say "we're still likely to add something like jit in the near future", but for now this isn't very practical.


Presumably apps which spend most of their time in system calls will not be noticeable slower.


Petty remark, comex.

Their pitch is "tiniest".


This project is interesting, but I looked at tests folder and there is not many tests despite software is so complex. Also I wonder, isn't it better to write tests in languages like Python?

Also, I don't see what's the use of Cosmopolitan Libc. In what situation does one need a CLI-only binary that can run on any system?


Author here. Right now it's being tested by running precompiled binaries. See https://github.com/jart/blink/tree/master/third_party/cosmo Most of these test binaries are sourced from the cosmopolitan repository, and many of those come from other projects like nsync, mbedtls, etc. I've recently started working on a unit testing method that's written in plain assembly, to hopefully catch more of the things that would show up in opcodes that compilers don't generate. See https://github.com/jart/blink/tree/master/test/asm


Having a copy of Perl, for example (https://computoid.com/APPerl/), on a USB stick means one could run scripts using the same version of Perl across multiple platforms, no need to wrestle with outdated instances.

Also, it's an awesome hack! C'mon, man, this is Hacker News!


That's beautifully worked.

    o//blink/blink
What's the double slash for?


There are specific comments already, but multiple successive slashes are treated as a single slash, in every case except when a path begins with exactly two slashes, in which case it's implementation dependent.

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1...


You can use it to configure the build mode: `build/bootstrap/make.com -j8 MODE=rel o/rel/blink/blink`; no MODE will build a default config. This is used across all cosmopolitan projects; for example, this is for redbean: https://redbean.dev/#source.


I'm not following. Is

    o//blink/blink
different from

    o/blink/blink

?


The MODE variable in the Makefile is undefined by default so "o/$(MODE)/" becomes "o//"




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: