authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-11 23:48:04-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-12 13:14:51-08:00
log21829a5b4ab0f21864e6e84fe585da365bab50c2
treee9eb069a0989c8179b5c988fe306fbff5b5219c1
parentf5d5dbd1668b9fc7347b017563e2e951f3156c1e

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.

1 files changed, 5 insertions(+), 5 deletions(-)

lib/c.zig+5-5
......@@ -15,17 +15,17 @@ pub const panic = if (builtin.is_test)
1515else
1616 std.debug.no_panic;
1717
18/// It is incorrect to make this conditional on `builtin.is_test`, because it is possible that
19/// libzigc is being linked into a different test compilation, as opposed to being tested itself.
20pub const linkage: std.builtin.GlobalLinkage = .strong;
21
2218/// Determines the symbol's visibility to other objects.
2319/// For WebAssembly this allows the symbol to be resolved to other modules, but will not
2420/// export it to the host runtime.
2521pub const visibility: std.builtin.SymbolVisibility = .hidden;
2622
2723pub inline fn symbol(comptime func: *const anyopaque, comptime name: []const u8) void {
28 @export(func, .{ .name = name, .linkage = linkage, .visibility = visibility });
24 // Normally, libc goes into a static archive, making all symbols
25 // overridable. However, Zig supports including the libc functions as part
26 // of the Zig Compilation Unit, so to support this use case we make all
27 // symbols weak.
28 @export(func, .{ .name = name, .linkage = .weak, .visibility = visibility });
2929}
3030
3131/// Given a low-level syscall return value, sets errno and returns `-1`, or on