Live data from Hacker News

Cosmopolitan Libc: build-once run-anywhere C library

justine.lol

131–140 of 171 posts

Re: Cosmopolitan Libc: build-once run-anywhere C library

#131
post #28

Earlier quoted context omitted.

Cosmopolitan doesn't use the "red zone" because these binaries boot on bare metal and operating system code can't assume a red zone. GCC supports this. Otherwise the Linux Kernel wouldn't work, since it's compiled the same way. So invoking call from inline asm is perfectly safe. The only real issue is that the called function can't assume the stack is 16-byte aligned. But that's fine, since Cosmo only using asm(call)…

Well you edited the compile command on the page just now to add -mno-red-zone, but it wasn't there before. So do you mean it is safe as long as -mno-red-zone is used? Even then, I am not quite sure: redzone is just an example of one of the assumptions that might be violated when calls are made from an asm block, but at least some gcc devs are on record saying that calls from inline asm are not supported: the main pro…

Agree. This is a great little micro-optimization, but definitely requires some compiler support to do safely (on the other hand, compiler devs should want to support it, because it's a great little micro-optimization, so I don't think that it would be _too_ hard to add).

Note that one way to get the code size wins for the caller in a compiler-blessed way is to use an alternative calling convention, like Clang's preserve_most; this isn't as good as explicitly providing a clobber list, but allows a library to provide a stable interface.

Re: Cosmopolitan Libc: build-once run-anywhere C library

#132
post #83

This project sounds amazing and very interesting! I have one question: how does it work on bare metal? I tried to look for an explanation in the documentation but I couldn't find anything. The specific questions I have are: 1) How does this interact with a boot loader like GRUB? Or does it come with its own boot loader? But in this case, shouldn't this go in a specific location on the boot disk? 2) How does it handle…

Author here. Bare metal so far has been a "we built it because we could" kind of feature, so please be warned it's not as polished. Here's a quick tutorial. Basically, ape/ape.S is a traditional BIOS bootloader. It also embeds a GRUB stub, which basically just switches back to the real mode BIOS bootloader entrypoint. So it should work with or without GRUB. The boot sector loads the rest of your executable of disk an…

Thank you, so if I understood correctly, I should write the binary starting from the boot sector, and it can overflow and go on subsequent sectors too, because ape/ape.S will be at the beginning of the binary, and so the boot sector will have the necessary bits in place to load the rest of the program in memory. Am I right? Can't wait to try it!

Re: Cosmopolitan Libc: build-once run-anywhere C library

#135
post #44

Earlier quoted context omitted.

Author here. That's not an inherent limitation. See https://justine.lol/apelife/index.html for an example of a GUI + TUI that's built using Cosmopolitan. The reason why I said what you quoted, is I'm simply trying to calibrate expectations. I don't view desktop GUIs as a productive area of focus, because there's such a lack of consensus surrounding the APIs that requires, and web browsers do a great job. As for sizeo…

Thanks for the informative reply. > and web browsers do a great job. Suppose one had a native linux game that uses POSIX, OpenGL and SDL. Is there any hope?

Now I want to see somebody better at C than me try smashing cosmopolitan and the C version of Dear Imgui together and see what happens.

Re: Cosmopolitan Libc: build-once run-anywhere C library

#136

Earlier quoted context omitted.

> Cosmopolitan only depends on stable kernel ABIs with long term stability promises Unfortunately, on macOS a stable kernel ABI does not exist. macOS has had kernel ABI breakage before, even recently, and they explicitly warn against making your own system calls. On Windows things are more stable but that's only because Windows cares about backwards compatibility to the point of preserving the behavior of even the mo…

Ntdll is the kernel ABI on windows; it is stable, and cosmopolitan uses it. Not sure what you mean by ‘on Windows thing are more stable’; syscall numbers change all the time. See https://j00ru.vexillium.org/syscalls/nt/64/

Microsoft documents ntdll as subject to change and makes no promises not to break it. When I was at MS it was advised not to use it for things that ship outside Windows. They had automated scripts to flag such a use.

In practice it is pretty stable, and many use it. Many things cannot be changed without causing massive internal refactors and app compat issues. But it is regarded as internal.

Re: Cosmopolitan Libc: build-once run-anywhere C library

#137

This is an interesting, and potentially compelling argument that WebAssembly binaries and runtime actually aren’t the future of compile-once-run-anywhere systems software: these support syscalls, sockets, and stdin/stdout —- all of which requires platform-specific glue code to achieve using WebAssembly and standard libc (or JS).

WebAsm is not performance competitive:

"We find that the mean slowdown of WebAssembly vs. native across SPEC benchmarks is 1.55× for Chrome and 1.45× for Firefox, with peak slowdowns of 2.5× in Chrome and 2.08× in Firefox."

https://arxiv.org/pdf/1901.09056.pdf

Re: Cosmopolitan Libc: build-once run-anywhere C library

#138

Earlier quoted context omitted.

I have the same experience. Stack Overflow is not great when you try to achive something novel or do something new from scratch.

What is a way to fix this? Is this some part of an endless long-cycle of adoption for social networks over some kind of crossing-the-chasm style adoption curve? Or is there a structural way to fix it? Stackoverflow is better than its predecessors, but clearly is much less valuable now than for its first few 5 years or so.

It's not just that social networks go bad the way cheese goes bad, but also that any "social network" business becomes opposed to the interests of its user base at the moment it becomes a "sustainable" business (e.g. the users would want 100% of the surplus to go to improving the system, but management, employees, investors and such won't agree)

Once you are #1 in the Google Economy there are many reasons to say "why try harder?" Questions might have better answers some place else but there is no one site that threatens the SO hegemony. Also, a site like SO has a proven compatibility with Google SEO -- if you made any big changes to a site like that there is a high risk that your traffic would drop catastrophically.

What I would do:

StackOverflow Q/A are all available by a "cc-by-sa" license, so it would be a good starting place for something better: an "antisocial" project curated by a small group of people. Take the top 0.1% of questions from SO and only the best answer and strip away the "socialjunk" (e.g. see "chartjunk") and you are starting to get there.

A system like that could justify itself it were your own personal knowledge base, but to make something generally useful I'd expect to curate 100 questions a day for 3 months or so: about 10,000 questions in all.

There are a number of methods that could speed up that curation a lot, not least of which is that you'll find some authors who consistently write great answers and others who consistently get upvoted with mediocre answers, etc. No amount of analytics will make up for zero manual curation work, you could be maybe 5x as productive once you've curated 10,000 questions and developed some automation.

Re: Cosmopolitan Libc: build-once run-anywhere C library

#139

Earlier quoted context omitted.

I reached the same conclusion about stackoverflow. Is there an incentive from the real world to answer questions because so many beginner try it?

Is there an incentive from the real world to answer questions Apparently so - if you look at the “Customer Questions and Answers” section of Amazon product pages, there is a remarkably high proportion of answers like, “I don’t know, I haven’t opened it yet” and “I’m not sure, I bought it as a gift”.

No, that is sleazy as anything “growth hacking” from Amazon.

If you bought product X and some months or years later “Sam” posts a question on Amazon that isn’t answered, Amazon will send you an email with a subject line that is a variation of “Sam has a question for you about Product X, can you help?” and the body would be something along the lines of “Dear foo, Sam wants to know if ? Click here to respond to Sam and help her out!”

In that context, you can easily see why people reply with such otherwise useless “answers.” When someone personally asks you a question you don’t know the answer to, responding with “sorry, I bought it for my husband as a gift and I don’t know,” is not just perfectly valid, it’s also the polite thing to do. But that answer is posted to the website in the genera Q&A as of you had viewed the question and then instead of passing on a question you had no answer for, you chose to reply with a useless answer.

Re: Cosmopolitan Libc: build-once run-anywhere C library

#140

Earlier quoted context omitted.

Is there an incentive from the real world to answer questions Apparently so - if you look at the “Customer Questions and Answers” section of Amazon product pages, there is a remarkably high proportion of answers like, “I don’t know, I haven’t opened it yet” and “I’m not sure, I bought it as a gift”.

Occasionally AMZN will send out questions others have asked about products to you in the form of an email if you have previously purchased the same product. Some people mistake those for questions directly asked to them instead of realizing where their answer will be posted. StackOverflow doesn't do that AFAIK.

See my other reply. It’s not fair to even say the user is making a mistake; it’s Amazon purposely manipulating users into thinking they’re being personally asked a question to game their way into getting more answers.
Post reply on HN