Here's what that all means in rust terms [1]. I assume zig doing something similar.
LGTM
actually kind of sus. they should be able to do it in 10kloc. the cpu does most of the heavy lifting anyway. i certainly hope they aren't scheduling insns or doing something silly like that!
So yeah, writing shader in something else than Gl/SL, wgsl would make our life so much easier...
MuffinFlavored•23h ago
sakras•23h ago
mananaysiempre•22h ago
> All our bugs are belong to us.
> The compiler becomes trivial to build from source and to bootstrap with only a C compiler on the host system.
> We stop dealing with annoying problems introduced by Linux distributions and package managers such as Homebrew related to LLVM, Clang, and LLD. There have been and continue to be many.
> The Zig compiler binary goes from about 150 MiB to 5 MiB.
> Compilation speed is increased by orders of magnitude.
> [...]
https://github.com/ziglang/zig/issues/16270
remindmeagain•22h ago
forrestthewoods•22h ago
It’d be nice if Zig added a command to emit them more explicitly to use in non-Zig build systems. Would be awesome actually. Plz?
remindmeagain•22h ago
The closest thing I could find online is: https://stackoverflow.com/questions/78892396/how-to-link-to-...
forrestthewoods•21h ago
Windows is trivial to cross compile for because there is a single set of headers. And for DLLs Windows compiler like to generate an import lib. Which is basically a stub function for all exports.
Linux is stupid and sucks. Linux doesn’t have a single set of headers because programmers in the 80s didn’t know better. And Linux linking to a shared library expects you to have a full copy of the library you expect to exist at runtime. Which is fucking stupid and ass backwards. But I digress.
So. Why is Zig awesome for crosscompiling C++? Because Zig fixed Linux sucking ass. Zig moves mountains to generate thin “import libs” of the half dozen .so files you need to link against to run on Linux.
If you want to cross compile C++ for Linux all you need is clang++ executable, headers, and those stub .so files. Zig generates the libs implicitly as part of its zig cc build process. I’m asking for the half dozen (C) or dozen (C++) libs to be explicitly exportable by Zig. So that they can be trivially used in other build systems.
I’ve got a custom polyglot build system that leverages Zig. But I have to zig cc a hello_world.cpp and parse the output to get the paths to those libs. Which is annoying and janky.
Hopefully that helps?
remindmeagain•21h ago
rstat1•21h ago
I would argue that it does, but because its apparently illegal (obvious exaggeration alert) to package all the parts of a single entity together in one package, it just seems like it doesn't, where as on Windows there's a single package (the Windows SDK) that contains the majority of the relevant stuff.
I do however 100% agree with you on linking to shared libraries. The way Linux compilers handle that is fucking stupid.
forrestthewoods•21h ago
https://github.com/ziglang/zig/tree/master/lib/libc/include
There is one set of headers for Windows. One set for macOS. And a fucking kajillion different headers for Linux.
And of course glibc is a fucking dumpster fire that doesn’t let you trivially target and arbitrary version.
Grumble grumble
:(
TUSF•21h ago
None of this is Linux's fault. I'd argue this is both C's and GNU's fault. The need for a copy of the library, seems to be just a tooling convention. GCC's linker requires it, so others do the same thing. The executable itself doesn't need to know where a given symbol is in a shared library's memory at runtime (or even what shared library a symbol comes from, just that it's inside one of the libraries declared as needed in its dynamic section), because that's the (runtime) linker's job to figure out. Regardless, you don't actually need a full copy of the library—a stub will suffice.
I don't know a ton about compilers, but as far as I know, there's no reason clang's linker (LLD) couldn't just not require an existing copy of the shared library you're linking to. Can't do anything about requiring a version of the libc headers you need for every platform though.
forrestthewoods•20h ago
forrestthewoods•17h ago
flohofwoe•17h ago
https://github.com/ziglang/zig/issues/20875
E.g. LLVM will still be around one way or another, just not as deeply integrated as it is now.
donio•21h ago
LLVM takes 2 hours to build on the same host and zig (with the LLVM backend) is another 20 minutes. It will be awesome if that can be brought down to 2 minutes or less.
AndyKelley•20h ago
Building Zig with Zig:
Bootstrapping with only a C compiler dependency (not even make or shell!):donio•19h ago
Normally it's just Go with Go. Besides the Go compiler you need bash if you want to use the normal bootstrap script but not much else. You can build your way up from C by building an old enough version of Go that was still C based but that's not usually done these days.
> Executed in 11.67 secs
Nice!
cxr•20h ago
wiz21c•15h ago
rowanG077•13h ago
zozbot234•13h ago
tw061023•20h ago
It's especially funny when this happens in Rust, which is marketed as a "safer" alternative.
Would you like a segfault out of nowhere in safe Rust? The issue is still open after two years by the way: https://github.com/rust-lang/rust/issues/107975
pjmlp•17h ago
AndyKelley•17h ago
pjmlp•17h ago
AndyKelley•16h ago
pjmlp•16h ago
So maybe all those universities, companies and the LLVM project know kind of what they are doing.
- https://mlir.llvm.org/
- https://llvm.github.io/clangir/
- https://mlir.llvm.org/talks/
AndyKelley•16h ago
marcelroed•13h ago
pjmlp•11h ago
Mojo and Flang, were designed from scratch using MLIR, as there are many other newer languages on the LLVM ecosystem.
I see it as the field experience of folks that know a little bit more than I ever will about compiler design.
alexrp•16h ago
pjmlp•16h ago
alexrp•16h ago
pjmlp•11h ago
https://github.com/llvm/llvm-project/blob/main/flang/docs/Hi...
Maybe the work in Swift (SIL), Rust (MIR), Julia (SSAIR) that were partially the inspiration for MLIR, alongside work done at Google designing Tensorflow compiler?
The main goal being an IR that would accomodate all use cases of those high level IRs.
Here are the presentation talk slides at European LLVM Developers Meeting back in 2019,
https://llvm.org/devmtg/2019-04/slides/Keynote-ShpeismanLatt...
Also you can find many general purpose enough users around this listing,
https://mlir.llvm.org/users/
pklausler•8h ago
pjmlp•7h ago
C and C++ took over many of the use cases people where using Fortran for during those decades.
In 2025, while it is a general purpose language, its use is constrained to scientific computing and HPC.
Most wannabe CUDA replacements keep forgetting Fortran is one of the reasons scientific community ignored OpenCL.
pklausler•6h ago
saghm•16h ago
tux3•4h ago
The difference is zero, but the compiler thinks it is non-zero because it thinks they are unequal.
From there you turn it into type confusion through an array, and then whatever you want. Almost any wrong compiler assumption can be exploited. This particular way to do it has also been used several times to exploit bugs in Javscript engines.
ncruces•16h ago
I got involved in a discussion with a Rust guy when trying to get C with SIMD intrinsics into wasi-libc where something that the C standard explicitly state is “implementation defined” (and so, sane, as we're targeting a single implementation - LLVM) can't be trusted, because LLVM may turn it back into UB because “reasons.”
At this point Go and Zig made the right choice to dump it. I don't know about Rust.
https://github.com/WebAssembly/wasi-libc/pull/593
AndyKelley•15h ago
The issue is that frontends want to emit code that is as optimizeable as possible, so they opt into the complexity of specifying additional constraints, attributes, and guarantees, each of which risks triggering undefined behavior if the frontend has a bug and emits wrong information.
ncruces•11h ago
I was not the one making this claim:
> However, I believe that currently, there is no well-defined way to actually achieve this on the LLVM IR level. Using plain loads for this is UB (even if it may usually work out in practice, and I'm sure plenty of C code just does that).
My claim is that the below snippet is implemention defined (not UB):
Further, that this is actually defined by the implementation to do the correct thing, by any good faith reading of the standard:> The mapping functions for converting a pointer to an integer or an integer to a pointer are intended to be consistent with the addressing structure of the execution environment.
I further suggested laundering the pointer with something like the below, but was told it would amount to nothing, again the blame being put on LLVM:
I honestly don't know if LLVM or clang should be to blame. I was told LLVM IR and took it in good faith.AndyKelley•5h ago
A straightforward implementation of memchr, i.e. finding the index of a particular byte inside an array of bytes, looks like this:
This is trivial to lower to well-defined LLVM IR.But it's desirable to use tricks to make the function really fast, such as assuming that you can read up to the page boundary with SIMD instructions[1]. This is generally true on real world hardware, but this is incompatible with the pointer provenance memory model, which is load-bearing for important optimizations that C, C++, Rust, and Zig all rely on.
So if you want to do such tricks you have to do it in a black box that is exempt from the memory model rules. The Zig code I link to here is unsound because it does not do this. An optimization pass, whether it be implemented in Zig pipeline or LLVM pipeline, would be able to prove that it writes outside a pointer provenance, mark that particular control flow unreachable, and thereby cause undefined behavior if it happens.
This is not really LLVM's fault. This is a language shortcoming in C, C++, Rust, Zig, and probably many others. It's a fundamental conflict between the utility of pointer provenance rules, and the utility of ignoring that crap and just doing what you know the machine allows you to do.
[1]: https://github.com/ziglang/zig/blob/0.14.1/lib/std/mem.zig#L...
ethan_smith•11h ago