From f87b443af1f654d3363ce6a1081bdf7932ae354c Mon Sep 17 00:00:00 2001 From: Alex Rønne Petersen Date: Sun, 16 Feb 2025 06:29:08 +0100 Subject: link.MachO: Add support for the -x flag (discard local symbols). This can also be extended to ELF later as it means roughly the same thing there. This addresses the main issue in #21721 but as I don't have a macOS machine to do further testing on, I can't confirm whether zig cc is able to pass the entire cgo test suite after this commit. It can, however, cross-compile a basic program that uses cgo to x86_64-macos-none which previously failed due to lack of -x support. Unlike previously, the resulting symbol table does not contain local symbols (such as C static functions). I believe this satisfies the related donor bounty: https://ziglang.org/news/second-donor-bounty --- src/Compilation.zig | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/Compilation.zig') diff --git a/src/Compilation.zig b/src/Compilation.zig index c2b72c6b0f..bec6696c92 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1160,6 +1160,8 @@ pub const CreateOptions = struct { dead_strip_dylibs: bool = false, /// (Darwin) Force load all members of static archives that implement an Objective-C class or category force_load_objc: bool = false, + /// Whether local symbols should be discarded from the symbol table. + discard_local_symbols: bool = false, libcxx_abi_version: libcxx.AbiVersion = libcxx.AbiVersion.default, /// (Windows) PDB source path prefix to instruct the linker how to resolve relative /// paths when consolidating CodeView streams into a single PDB file. @@ -1585,6 +1587,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil .headerpad_max_install_names = options.headerpad_max_install_names, .dead_strip_dylibs = options.dead_strip_dylibs, .force_load_objc = options.force_load_objc, + .discard_local_symbols = options.discard_local_symbols, .pdb_source_path = options.pdb_source_path, .pdb_out_path = options.pdb_out_path, .entry_addr = null, // CLI does not expose this option (yet?) @@ -2665,6 +2668,7 @@ fn addNonIncrementalStuffToCacheManifest( man.hash.add(opts.headerpad_max_install_names); man.hash.add(opts.dead_strip_dylibs); man.hash.add(opts.force_load_objc); + man.hash.add(opts.discard_local_symbols); // COFF specific stuff man.hash.addOptional(opts.subsystem); -- cgit v1.2.3