9 ms·
Zig got a new ELF linker and it's fast
- edoceo 1y agoAnd it fixes a bug about debug output. Seems like a bigger deal than fast.
- dustbunny 1y agoZig honestly blows my mind. I think it's clearly the best next gen language because of the build system alone.
- chris_armstrong 1y agoIf I recall correctly, this is one of the final pieces that allows zig to be used as a fully self-contained cross-compiling C toolchain (once its linker is enabled for more platforms / formats)
- olivia-banks 1y agoI might be misunderstanding, but I don’t think that's quite accurate. As I understand it, Zig ships a Clang frontend and wraps it with precompiled sysroots. Unless they're developing an LLVM backend, I'm not sure how it could serve as a completely self-contained toolchain.
- stock_toaster 1y agoZig does have its own native x86_64 backend for debug compilation. ref: https://ziglang.org/devlog/2025/#2025-06-08 https://ziglang.org/devlog/2025/#2025-06-08
- olivia-banks 1y agoThey're also getting an aarch64 backend soon (or has it already landed)? Really looking forward to this one for development on my Mac! My point was that Zig uses their backends (which includes their homegrown ones), but since `zig cc` is a wrapper around Clang, it always goes through the `LLVM` path and sidesteps the Zig backend(s).
- stock_toaster 1y agoAh. I see what you are saying now. I believe you are correct.
- chris_armstrong 1y agozig has a cross-compiler frontend (zig cc) which can be used as a drop-in replacement for a custom sysroot + binutils + gcc for several platforms. I've used it to build OCaml cross-compilers that only depend on zig itself (https://www.chrisarmstrong.dev/posts/ocaml-cross-compilation-an-experiment https://www.chrisarmstrong.dev/posts/ocaml-cross-compilation...). There are other projects that have used it in a similar way too. [1] https://actually.fyi/posts/zig-makes-rust-cross-compilation-just-work/ https://actually.fyi/posts/zig-makes-rust-cross-compilation-... [2] https://jcbhmr.com/2024/07/19/zig-cc-cmake/ https://jcbhmr.com/2024/07/19/zig-cc-cmake/
- olivia-banks 1y agoInteresting. OCaml cross compilation scared me the one time I considered it, so it's nice to know this is an option. I will be pedantic and say it isn't a replacement for a custom sysroot/binutils/whatnot, since it really just papers over those user-facing details by shipping a prebuilt collection of sysroots and using LLD. They sorta get this for free since they need it for cross-compiling Zig code anyways.
- olivia-banks 1y agoThe more I hear about Zig, the more I appreciate it. Its vertically integrated stack (with the custom linker and code-generation backends) stands out to me as a really compelling feature that enables interesting optimizations. The compiler is also much easier to interact with in a consistent way compared to C. I've been using it as an experimental backend for my language project with great results.
- scuff3d 1y agoI've been writing Zig since the beginning of the year. Just playing around with some small stuff really. I want to love the language. It does so much right, but there's something about it just feels off to me. And then the recent Io change really bugged me.
- deagle50 1y agoI have the same feeling, and my best guess is that it's the intentional (and imo arbitrary) friction that has been sprinkled into the language. And camelCase.
- scuff3d 1y agoLol. Funny enough I actually like camel case because I've spent so much time in Java. Yeah, I can see that. It's also difficult to put my finger on, but for a language that claims to be simple it seems to make a lot of things needlessly complicated. I'm also not loving how everything is deeply nested structs so I have to do struct.doThefirstThing.doTheSecondThing.doTheThirdThing().etc() all the time.
- olivia-banks 1y agoI agree with the "off" part. I've thought maybe it's the syntax? It's unclear, but I'm just hoping the feeling will go away! I find the IO changes to be strange, it's almost as if Zig is encoding an effect system a-la Haskell (i.e. this function will have an allocation/IO side effect).
- squirrellous 1y agoBetween mold and this, the linker space appears to be going through a renaissance. Does anyone know if it’s reasonably easy to use elf2 as a standalone linker in a c/c++ toolchain? Or is it specially built just for Zig?
- olivia-banks 1y agoLooking in the source tree, it doesn't look like it has it's own entry point. Zig is heading in the direction of a very verticall integrated compilation stack (I believe this is where most of the speed up comes from), so I'm not really sure of the utility with using it outside of the Zig world. https://github.com/jacobly0/zig/tree/4508c2543508e04253471e143323e43c915ae3fa/src/link https://github.com/jacobly0/zig/tree/4508c2543508e04253471e1... https://github.com/jacobly0/zig/blob/4508c2543508e04253471e143323e43c915ae3fa/src/link.zig https://github.com/jacobly0/zig/blob/4508c2543508e04253471e1...
- altfredd 1y ago> this is where most of the speed up comes from I might be mistaken, but the brief look at code shows that the speed up appears to come from combination of async architecture (the selling point of Mold) and intelligent usage of PUNCH_HOLE/INSERT_RANGE fallocate() operations. Surprisingly enough PUNCH_HOLE and friends have already matured to be production ready, with viable support from ext4 and xfs filesystem. The possibilities!
- olivia-banks 1y agoI stand corrected! It would be interesting to try and use the Zig linker for something else, would be a neat weekend project.
- dmit 1y ago> Between mold and this, the linker space appears to be going through a renaissance. No kidding. There are also https://github.com/davidlattimore/wild https://github.com/davidlattimore/wild and https://github.com/kubkon/bold https://github.com/kubkon/bold.
- esbranson 1y agoJust going to mention the book Linkers and Loaders by John R. Levine, I'm not sure if there's anything comparable to it.
- brcmthrowaway 1y agoCrafting Interpreters?
- deciduously 1y agoWhile also a great book, there is very little overlap in content to Linkers and Loaders.
- rstat1 1y agoI don't really have much interest in Zig the language, but Zig as a standalone C/C++ compiler is pretty great. I'm using it as a cross-compiler for linux-arm64 because its much simpler to download a single archive and extract it somewhere than to waste a bunch of time on guessing how each different Linux distro does ARM64 cross compilers (or doesn't in the case of Fedora).
- wild_egg 1y agoThis is exactly how I've been using it the last couple years and it's incredibly nice.
- wolvesechoes 1y agoSame for me. The more Zig-the-language is hyped, the more I see it doesn't bring anything of interest. Zig-the-toolchain, on the other hand, is neat.
- davemp 1y agoI’ve been using it for an embedded project to target arm thumb and the typical x86-64 hosts that communicate with a protobuf based protocol. It’s absurdly convenient to be able to just give windows users the repo, zig binary, and tell them to run ‘zig build’.
- L0Wigh 1y agoSeems like we spoke too soon. Latest results shows that it's not as great as it seems