From 21829a5b4ab0f21864e6e84fe585da365bab50c2 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 11 Feb 2026 23:48:04 -0800 Subject: [PATCH] zig libc: export all symbols weak Normally, libc goes into a static archive, making all symbols overrideable. However, Zig supports including the libc functions as part of the Zig Compilation Unit, so to support this use case we make all symbols weak. --- lib/c.zig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/c.zig b/lib/c.zig index 8b181dc118..b9f2a27eb7 100644 --- a/lib/c.zig +++ b/lib/c.zig @@ -15,17 +15,17 @@ pub const panic = if (builtin.is_test) else std.debug.no_panic; -/// It is incorrect to make this conditional on `builtin.is_test`, because it is possible that -/// libzigc is being linked into a different test compilation, as opposed to being tested itself. -pub const linkage: std.builtin.GlobalLinkage = .strong; - /// Determines the symbol's visibility to other objects. /// For WebAssembly this allows the symbol to be resolved to other modules, but will not /// export it to the host runtime. pub const visibility: std.builtin.SymbolVisibility = .hidden; pub inline fn symbol(comptime func: *const anyopaque, comptime name: []const u8) void { - @export(func, .{ .name = name, .linkage = linkage, .visibility = visibility }); + // Normally, libc goes into a static archive, making all symbols + // overridable. However, Zig supports including the libc functions as part + // of the Zig Compilation Unit, so to support this use case we make all + // symbols weak. + @export(func, .{ .name = name, .linkage = .weak, .visibility = visibility }); } /// Given a low-level syscall return value, sets errno and returns `-1`, or on