Live data from Hacker News

Zig Libc

ziglang.org

81–90 of 196 posts

Re: Zig Libc

#81

Earlier quoted context omitted.

This affects static libc only. If you pass -dynamic -lc then the libc functions are provided by the target system. Some systems only support dynamic libc, such as macOS. I think OpenBSD actually does support static libc though.

> I think OpenBSD actually does support static libc though. How does that work, with syscalls being unable to be called except from the system’s libc? I’d be a bit surprised if any binary’s embedded libc would support this model.

Not all of libc is syscalls. E.g. strlen() is zib libc but open() goes to system libc.

Re: Zig Libc

#83

Earlier quoted context omitted.

This affects static libc only. If you pass -dynamic -lc then the libc functions are provided by the target system. Some systems only support dynamic libc, such as macOS. I think OpenBSD actually does support static libc though.

> I think OpenBSD actually does support static libc though. How does that work, with syscalls being unable to be called except from the system’s libc? I’d be a bit surprised if any binary’s embedded libc would support this model.

> How does that work, with syscalls being unable to be called except from the system’s libc?

OpenBSD allows system calls being made from shared libraries whose names start with `libc.so.' and all static binaries, as long as they include an `openbsd.syscalls' section listing call sites.

Re: Zig Libc

#84

Earlier quoted context omitted.

This affects static libc only. If you pass -dynamic -lc then the libc functions are provided by the target system. Some systems only support dynamic libc, such as macOS. I think OpenBSD actually does support static libc though.

> I think OpenBSD actually does support static libc though. How does that work, with syscalls being unable to be called except from the system’s libc? I’d be a bit surprised if any binary’s embedded libc would support this model.

For static executables, “the system’s libc” is of course not a thing. To support those, OpenBSD requires them to include an exhaustive list of all addresses of syscall instructions in a predefined place[1].

(With that said, OpenBSD promises no stability if you choose to bypass libc. What it promises instead is that it will change things in incompatible ways that will hurt. It’s up to you whether the pain that thus results from supporting OpenBSD is worth it.)

[1] https://nullprogram.com/blog/2025/03/06/

Re: Zig Libc

#85

Earlier quoted context omitted.

This affects static libc only. If you pass -dynamic -lc then the libc functions are provided by the target system. Some systems only support dynamic libc, such as macOS. I think OpenBSD actually does support static libc though.

> I think OpenBSD actually does support static libc though. How does that work, with syscalls being unable to be called except from the system’s libc? I’d be a bit surprised if any binary’s embedded libc would support this model.

Sorry I got mixed up with FreeBSD: https://codeberg.org/ziglang/zig/issues/30981 (original github link has more information)

Re: Zig Libc

#87
post #86

There are so many scary parts of libc, this is a really exciting project

There are many useful functions too. Like "memfrob" and "strfry". I hope the Zig libc makes those available too

Just joking of course. Those are sadly only in glibc.. :)

Re: Zig Libc

#88
post #38

Earlier quoted context omitted.

Are you ok with the size of the budget these agencies control? Are you ok with it being headed by a guy who never has denied he took a $50k bribe from the FBI and wasn't even the initial target of an investigation? I would bet you $1000 that not one of the immigrants being rounded up were even accused of that kind of corruption and crimes. How is this not bald corruption and an insane way to spend tax dollars when pe…

The budget needs to increase because there are a lot of people in the country illegally and in order to get every single one of them out the agency needs to scale up. When people start obstructing officers and being violent that increases the required number of officers even more.

We don't need to get them all out, though. The vast majority are picking strawberries and working cheap construction jobs, not funneling drugs and guns.

I'm as concerned with getting them all out as I'm concerned with ticketing every jaywalker.

Re: Zig Libc

#89

This is very exciting for zig projects linking C libraries. Though I'm curious about the following case: Let's say I'm building a C program targeting Windows with MinGW & only using Zig as a cross compiler. Is there a way to still statically link MinGW's libc implementation or does this mean that's going away and I can only statically link ziglibc even if it looks like MinGW from the outside?

This use case is unchanged. If you specify -target x86_64-windows-gnu -lc then some libc functions are provided by Zig, some are provided by vendored mingw-w64 C files, and you don't need mingw-w64 installed separately; Zig provides everything. You can still pass --libc libc.txt to link against an externally provided libc, such as a separate mingw-w64 installation you have lying around, or even your own libc installa…

do you suspect it will be possible to implement printf??

while we're talking about printf, can i incept in you the idea of making an io.printf function that does print-then-flush?

Re: Zig Libc

#90
post #7
post #5

This strikes me as a very agent-friendly problem. Given a harness that enforces sufficiently-rigorous tests, I'm sure you could spin up an agent loop that methodically churns through these functions one by one, finishing in a few days.

Have you ever used an LLM with Zig? It will generate syntactically invalid code. Zig breaks so often and LLMs have such an eternally old knowledge cutoff that they only know old ass broken versions. The same goes for TLA+ and all the other obscure things people think would be great to use with LLMs, and they would, if there was as much training data as there was for JavaScript and Python.

i find claude does quite well with zig. this project is like > 95% claude, and it's an incredibly complicated codebase [0] (which is why i am not doing it by hand):

https://github.com/ityonemo/clr

[0] generates a dynamically loaded library which does sketchy shit to access the binary representation of datastructures in the zig compiler, and then transpiles the IR to zig code which has to be rerun to do the analysis.

Post reply on HN