aboutsummaryrefslogtreecommitdiff
path: root/src/link.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-11-20 17:23:44 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-11-20 17:23:44 -0700
commit4e5a88b28882eda156a46ecc7f70887a7bc0b49b (patch)
tree1ccdc54fdb432ff72692e9f10f4f0640ef6869cd /src/link.zig
parenta699d678b2c81dcf333a4f4bb84676836849a618 (diff)
downloadzig-4e5a88b28882eda156a46ecc7f70887a7bc0b49b.tar.gz
zig-4e5a88b28882eda156a46ecc7f70887a7bc0b49b.zip
stage2: default dynamic libraries to be linked as needed
After this change, the default for dynamic libraries (`-l` or `--library`) is to only link them if they end up being actually used. With the Zig CLI, the new options `-needed-l` or `--needed-library` can be used to force link against a dynamic library. With `zig cc`, this behavior can be overridden with `-Wl,--no-as-needed` (and restored with `-Wl,--as-needed`). Closes #10164
Diffstat (limited to 'src/link.zig')
-rw-r--r--src/link.zig18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/link.zig b/src/link.zig
index e023453284..c5ccbc70c9 100644
--- a/src/link.zig
+++ b/src/link.zig
@@ -18,6 +18,22 @@ const wasi_libc = @import("wasi_libc.zig");
const Air = @import("Air.zig");
const Liveness = @import("Liveness.zig");
+pub const SystemLib = struct {
+ needed: bool = false,
+};
+
+pub fn hashAddSystemLibs(
+ hh: *Cache.HashHelper,
+ hm: std.StringArrayHashMapUnmanaged(SystemLib),
+) void {
+ const keys = hm.keys();
+ hh.add(keys.len);
+ hh.addListOfBytes(keys);
+ for (hm.values()) |value| {
+ hh.add(value.needed);
+ }
+}
+
pub const producer_string = if (builtin.is_test) "zig test" else "zig " ++ build_options.version;
pub const Emit = struct {
@@ -121,7 +137,7 @@ pub const Options = struct {
objects: []const []const u8,
framework_dirs: []const []const u8,
frameworks: []const []const u8,
- system_libs: std.StringArrayHashMapUnmanaged(void),
+ system_libs: std.StringArrayHashMapUnmanaged(SystemLib),
wasi_emulated_libs: []const wasi_libc.CRTFile,
lib_dirs: []const []const u8,
rpath_list: []const []const u8,