zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit f695ca08e3fc705bbca0e6dbde3164718727be00 (tree)
parent b99dc12ecece60caecf05d4b41495f6979f944d0
Author: Antti Harju <anttiharju@noreply.codeberg.org>
Date:   Wed, 14 Jan 2026 19:16:05 +0100

zig cc: Add support for `-exported_symbols_list` (#30628)

Resolves [unsupported linker arg: `-exported_symbols_list`](https://github.com/ziglang/zig/issues/24662)

This PR has been tested with https://github.com/anttiharju/compare-changes/pull/117 (via commits like https://github.com/anttiharju/nur-packages/commit/75b17b948e3046c198931fefce13661276789ff1) where the `zig cc` ([via this wrapper](https://github.com/anttiharju/compare-changes/blob/791129d4011f71b4b59110c79d07c73ed92c4308/.cargo/zcc/aarch64-apple-darwin.sh)) successfully builds a macOS binary (build would fail with zig 0.15.2):

Co-authored-by: Gunnar Wagenknecht <gunnar@wagenknecht.org>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30628
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Antti Harju <anttiharju@noreply.codeberg.org>
Co-committed-by: Antti Harju <anttiharju@noreply.codeberg.org>

Diffstat:
Msrc/main.zig | 11+++++++++++
1 file changed, 11 insertions(+), 0 deletions(-)

diff --git a/src/main.zig b/src/main.zig @@ -665,6 +665,7 @@ const usage_build_generic = \\ -weak_framework [name] (Darwin) link against framework and mark it and all referenced symbols as weak \\ -F[dir] (Darwin) add search path for frameworks \\ --export=[value] (WebAssembly) Force a symbol to be exported + \\ --exported_symbols_list [file] (Darwin) Force symbols in the file to be exported \\ \\Test Options: \\ --test-filter [text] Skip tests that do not match any filter @@ -2612,6 +2613,16 @@ fn buildOutputType( }; } else if (mem.eql(u8, arg, "--export")) { try linker_export_symbol_names.append(arena, linker_args_it.nextOrFatal()); + } else if (mem.eql(u8, arg, "-exported_symbols_list")) { + const exported_symbols_list = linker_args_it.nextOrFatal(); + const content = Io.Dir.cwd().readFileAlloc(io, exported_symbols_list, arena, .limited(10 * 1024 * 1024)) catch |err| { + fatal("unable to read exported symbols list '{s}': {s}", .{ exported_symbols_list, @errorName(err) }); + }; + var symbols_it = mem.splitScalar(u8, content, '\n'); + while (symbols_it.next()) |line| { + if (line.len == 0) continue; + try linker_export_symbol_names.append(arena, line); + } } else if (mem.eql(u8, arg, "--compress-debug-sections")) { const arg1 = linker_args_it.nextOrFatal(); linker_compress_debug_sections = std.meta.stringToEnum(std.zig.CompressDebugSections, arg1) orelse {