From f695ca08e3fc705bbca0e6dbde3164718727be00 Mon Sep 17 00:00:00 2001 From: Antti Harju Date: Wed, 14 Jan 2026 19:16:05 +0100 Subject: [PATCH] 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 Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30628 Reviewed-by: Andrew Kelley Co-authored-by: Antti Harju Co-committed-by: Antti Harju --- src/main.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main.zig b/src/main.zig index 3c9d3cb3ef..fc8cd2ea49 100644 --- 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 {