aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorAlex Rønne Petersen <alex@alexrp.com>2025-02-16 06:29:08 +0100
committerAlex Rønne Petersen <alex@alexrp.com>2025-02-22 06:35:19 +0100
commitf87b443af1f654d3363ce6a1081bdf7932ae354c (patch)
treef4b242f4e9463026e1b53cab879fd21acbbb2e9a /src/Compilation.zig
parenta7467b9bb2aa667a8d34bc8b678ce35fcb19ebd4 (diff)
downloadzig-f87b443af1f654d3363ce6a1081bdf7932ae354c.tar.gz
zig-f87b443af1f654d3363ce6a1081bdf7932ae354c.zip
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
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig4
1 files changed, 4 insertions, 0 deletions
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);