TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

95 pointsby moonlighterabout 4 years ago

7 comments

dangabout 4 years ago
I understand the love these incredible projects are getting on HN right now, but this one was discussed a couple months ago:<p><i>Cosmopolitan Libc: build-once run-anywhere C library</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=25556286" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=25556286</a> - Dec 2020 (166 comments)<p>and the current related thread is still high on the front page—long may it reign:<p><i>Show HN: Redbean – Single-file distributable web server</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26271117" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26271117</a> - Feb 2021 (182 comments)<p>There are also these related threads:<p><i>Actually Portable Executable</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26273960" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26273960</a> - Feb 2021 (133 comments)<p><i>αcτµαlly pδrταblε εxεcµταblε</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=24256883" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=24256883</a> - Aug 2020 (286 comments)<p><i>How Fat Does a Fat Binary Need to Be?</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26103769" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26103769</a> - Feb 2021 (68 comments)<p>Others?
guenthertabout 4 years ago
&quot;That&#x27;s a huge improvement in generated code size. The above two compiles used the same gcc flags&quot;<p>It would have been awfully nice to state the version of the compiler and the flags being used. With gcc 10 on Linux&#x2F;AMD64, libc 4.15.0, I get with &#x27;-Os&#x27;:<p><pre><code> --8&lt;-- strlcpy: .LFB5: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rdi, %rbp movq %rsi, %rdi pushq %rbx .cfi_def_cfa_offset 24 .cfi_offset 3, -24 movq %rdx, %rbx subq $24, %rsp .cfi_def_cfa_offset 48 movq %rsi, 8(%rsp) call strlen testq %rbx, %rbx movq 8(%rsp), %rsi je .L1 leaq -1(%rbx), %rdx movq %rbp, %rdi cmpq %rax, %rdx cmova %rax, %rdx movq %rdx, %rcx movq %rdx, %rcx rep movsb movb $0, 0(%rbp,%rd .L1ubq $24, %rsp .cfi_def_cfa_offset 48 movq %rsi, 8(%rsp) call strlen testq %rbx, %rbx movq 8(%rsp), %rsi je .L1 leaq -1(%rbx), %rdx movq %rbp, %rdi cmpq %rax, %rdx cmova %rax, %rdx movq %rdx, %rcx cmova %rax, %rdx movq %rdx, %rcx addq $24, %rsp .cfi_def_cfa_offset 24 popq %rbx .cfi_def_cfa_offset 16 popq %rbp .cfi_def_cfa_offset 8 ret .cfi_endproc --&gt;8-- </code></pre> Which doesn&#x27;t seem so bad.
评论 #26279833 未加载
lostmsuabout 4 years ago
I missed an opportunity to ask in the previous thread: what would it take to link an app in a different language (say, Rust) with this library? Is it enough to just build an object file, that has libc functions assuming LP64 ABI as unresolved exports?
musicaleabout 4 years ago
Related:<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26273960" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26273960</a><p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26271117" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26271117</a>
gbrown_about 4 years ago
Previous discussion <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=25556286" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=25556286</a>
Gysabout 4 years ago
Run anywhere x86 ;-)
评论 #26279618 未加载
d33lioabout 4 years ago
This seems incredibly ideal for writing malware &#x2F; rats?