From a502c160cd51ce3de80b3be945245b7a91967a85 Mon Sep 17 00:00:00 2001 From: Michael Dusan Date: Sun, 14 Mar 2021 10:52:35 -0400 Subject: [PATCH] macho: fix various linker flags fix drivers: zig {cc,c++} - `-dynamiclib` is an alias to `-shared` - associate `-dynamiclib` with zig `.shared` semantics fix drivers: zig {cc,c++,build-lib,build-exe} - use `-dynamic` for {exe,dylib} - for dylib this fixes a regression - for exe this replaces incorrect use of `-static` --- src/clang_options_data.zig | 9 ++++++++- src/link/MachO.zig | 4 +--- tools/update_clang_options.zig | 4 ++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/clang_options_data.zig b/src/clang_options_data.zig index b1cb6c258c..d0f00625b7 100644 --- a/src/clang_options_data.zig +++ b/src/clang_options_data.zig @@ -2426,7 +2426,14 @@ flagpd1("dwarf-ext-refs"), sepd1("dylib_file"), flagpd1("dylinker"), flagpd1("dynamic"), -flagpd1("dynamiclib"), +.{ + .name = "dynamiclib", + .syntax = .flag, + .zig_equivalent = .shared, + .pd1 = true, + .pd2 = false, + .psl = false, +}, flagpd1("emit-ast"), flagpd1("emit-codegen-only"), flagpd1("emit-header-module"), diff --git a/src/link/MachO.zig b/src/link/MachO.zig index fe8fcd6281..52d434da2f 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -644,9 +644,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { try argv.append("defs"); } - if (is_dyn_lib) { - try argv.append("-static"); - } else { + if (is_exe_or_dyn_lib) { try argv.append("-dynamic"); } diff --git a/tools/update_clang_options.zig b/tools/update_clang_options.zig index f0dfe1639d..8c3eddf7cf 100644 --- a/tools/update_clang_options.zig +++ b/tools/update_clang_options.zig @@ -332,6 +332,10 @@ const known_options = [_]KnownOpt{ .name = "s", .ident = "strip", }, + .{ + .name = "dynamiclib", + .ident = "shared", + }, }; const blacklisted_options = [_][]const u8{};