authorgravatar for anttiharju@noreply.codeberg.orgAntti Harju <anttiharju@noreply.codeberg.org> 2026-01-14 19:16:05+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-14 19:16:05+01:00
logf695ca08e3fc705bbca0e6dbde3164718727be00
tree43842566238c87558dfca83e5cc1aa6309b32bf8
parentb99dc12ecece60caecf05d4b41495f6979f944d0

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>

1 files changed, 11 insertions(+), 0 deletions(-)

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