Open mk12 opened 4 months ago
Note that for "real" code, you should use std.log
.
Edit: That said, it seems like std.log.defaultLog
also uses std.Progress
. So you'd have to supply your own logFn
to get completely around pulling that in, I suppose.
@alexrp Ah good point. I had hoped -fsingle-threaded
would eliminate anything to do with locking but I guess it doesn't get rid of the global variable. However even using std.io.getStdErr directly I'm still seeing the mutex:
pub fn main() void{
@import("std").io.getStdErr().writer().writeAll("Hello\n") catch unreachable;
}
Same binary size, same otool and nm output.
Ok, that I can't explain. That seems odd.
I guess this is why the mutex global variable is not completely eliminated though:
Zig Version
0.14.0-dev.130+cb308ba3a
Steps to Reproduce and Observed Behavior
Environment
I'm on macOS Sonoma 14.5 on MacBook Pro with the Apple M1 Pro chip.
Reproduce
Hello world in C compiled with clang is 33K:
Hello world in Zig is 51K:
Investigation
Here's my theory. The hello-c binary has no
__DATA
segment:On the other hand, hello-zig has an 80 byte
__DATA
segment, pushing the final__LINKEDIT
segment to offset 0xc000 for 16K page alignment:I'm not sure about the other sections, but let's look at
__data
for hello-c:And for hello-zig:
That
_Progress.stderr_mutex.0
looks suspicious to me. I believe it comes from here: https://github.com/ziglang/zig/blob/cb308ba3ac2d7e3735d1cb42ef085edb1e6db723/lib/std/Progress.zig#L1388But I'm not using std.Progress anywhere so I don't know how it makes it into the final binary.
Expected Behavior
Zig should be able to match the binary size of C/clang.