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)...@@ -15,17 +15,17 @@ pub const panic = if (builtin.is_test)
15else15else
16 std.debug.no_panic;16 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
22/// Determines the symbol's visibility to other objects.18/// Determines the symbol's visibility to other objects.
23/// For WebAssembly this allows the symbol to be resolved to other modules, but will not19/// For WebAssembly this allows the symbol to be resolved to other modules, but will not
24/// export it to the host runtime.20/// export it to the host runtime.
25pub const visibility: std.builtin.SymbolVisibility = .hidden;21pub const visibility: std.builtin.SymbolVisibility = .hidden;
2622
27pub inline fn symbol(comptime func: *const anyopaque, comptime name: []const u8) void {23pub 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 });
29}29}
3030
31/// Given a low-level syscall return value, sets errno and returns `-1`, or on31/// Given a low-level syscall return value, sets errno and returns `-1`, or on