News for hackers. Stuff that matters.
Re:How Fat Does a Fat Binary Need to Be? by jart on Thursday February 11, 2021 @01:10PM (#26105041)
Author here. These binaries will re-exec themselves under Qemu if you run them on different architectures. So they truly are build-once run-anywhere.

I think improving performance on other architectures is great. There's nothing that inherently limits the Actually Portable Executable format from baking in native support for other architectures. It's simply a question of focus.

What Cosmopolitan does, it does really well. No other C library is able to target multiple operating systems and all the x86 microarchitectures. You can now easily distribute software that can be easily run on the vast majority of PCs and servers. Want it to do more? Consider becoming a sponsor. The impact the project is already having should be all the proof we need that it could be doing much more. In order for that to happen it needs your support.

Re:How Fat Does a Fat Binary Need to Be? by comex on Thursday February 11, 2021 @02:59PM (#26106336)
Fair enough. I'm not against your project. I realize that open-source projects have time/funding constraints and that you don't owe me anything.

By "baking in native support for other architectures", I guess you're thinking of an approach similar to Apple's "fat binaries", which are just multiple independent binaries built for different architectures bundled together? That's a good pragmatic option, and definitely the best choice size-wise for small programs. On the other hand, it lacks forwards-compatibility: you're limited to the set of architectures the original developer decided on. And for large programs, the cost of N copies of the program can add up.

Personally, I'm a fan of bytecode VMs such as WebAssembly. That way the binary can be truly architecture-independent, capable of supporting many different architectures or special architecture variants without bloating the size of the executable. On the other hand, if you wanted the binary to run out of the box with no dependencies, you would have to bundle an entire VM implementation into the binary for at least some architectures, and then you'd have your own share of "hello world" bloat. (I'm assuming there would be an option for the user to supply their own VM for less common architectures.)

I do wonder how small one can make a WebAssembly VM, if its design prioritizes minimal size over maximal speed, while still aiming to get reasonable speed (i.e. not an interpreter)…

Re:How Fat Does a Fat Binary Need to Be? by _roqj on Thursday February 11, 2021 @04:05PM (#26107170)
Check out Wasm3 which is the fastest WebAssembly interpreter, and since they recently adopted Cosmopolitan it's now the most universal one too. https://twitter.com/wasm3_engine/status/1354699030165676033 Cosmopolitan is designed to be complementary to visions like yours. If you believe bytecode is the future then Cosmopolitan can help your vision be successful by giving it the best performance and portability across PCs and servers.
Re:How Fat Does a Fat Binary Need to Be? by spockz on Friday February 12, 2021 @02:58AM (#26111566)
In order to solve the “forward” compatibility option you could have both Specialized binaries and a generic version in (wasm) bytecode. Then you can have all the performance optimisations you care about and retain compatibility with all platforms.

Optionally you could consider a binary that on first run (&prompt?) removes the binaries irrelevant to the current host.

Re:How Fat Does a Fat Binary Need to Be? by lhorie on Thursday February 11, 2021 @02:02PM (#26105687)
Semi off-topic, but having just come across this project, I just started looking back at some of your stuff and saw a comment about an ape chibicc fork. What's the state of that? Is it usable yet?
Re:How Fat Does a Fat Binary Need to Be? by jart on Thursday February 11, 2021 @02:49PM (#26106214)
It's usable but not polished yet. Lots of GNU extensions and an integrated assembler were added. You can read about them here: https://github.com/jart/cosmopolitan/blob/master/third_party... I have automated tests which do a two-stage build and test on every platform each time I run make, so it's going to stay stable. The two other things I want are an integrated linker and VLA parameters. Rui is helping me implement those. So I anticipate we can start distributing a APE build of complete chibicc toolchain very soon that you can use to build APE binaries on any platform.

Keep in mind this compiler doesn't optimize. So if you're OK taking a 2x performance hit, you're going to find that your code compiles significantly faster than GCC or Clang and you're going to have the convenience of the fact that the whole toolchain will be a single .com file that you can just scp on any server for a fully deterministic reproducible build experience. It's also the most readable and hackable compiler codebase I've ever seen, so if you've ever wanted to pull out the dragon book at try your hand at optimizing, you'll find that chibicc is fertile ground to do it.

Re:How Fat Does a Fat Binary Need to Be? by lhorie on Thursday February 11, 2021 @03:14PM (#26106525)
Very exciting stuff! I'll try to take it for a spin tonight :)
Re:How Fat Does a Fat Binary Need to Be? by jart on Thursday February 11, 2021 @03:37PM (#26106798)
Here's something you can paste into your Linux terminal to get started:

    git clone https://github.com/jart/cosmopolitan
    cd cosmopolitan
    make -j8
    o/third_party/chibicc/chibicc.com -include libc/integral/normalize.inc -o hello.com.dbg examples/hello.c o/cosmopolitan.a
    o/third_party/gcc/bin/x86_64-linux-musl-objcopy -SO binary hello.com.dbg hello.com
    ./hello.com
Re:How Fat Does a Fat Binary Need to Be? by eximius on Thursday February 11, 2021 @02:09PM (#26105771)
> Want it to do more? Consider becoming a sponsor.

How?

Re:How Fat Does a Fat Binary Need to Be? by jart on Thursday February 11, 2021 @02:15PM (#26105834)
https://github.com/sponsors/jart

Thank you Hacker News for your support!

Re:How Fat Does a Fat Binary Need to Be? by Jayschwa on Thursday February 11, 2021 @02:18PM (#26105866)