| author | |
| committer | |
| log | 09b46198ff8d64c9884a0cf13788855b4d4bbe2d |
| tree | da0ac067ec33e1cb5e3a1bdcd3438c1cb6514621 |
| parent | a600d4188025ae6ffc3fc5d6fa7572ef34438215 |
4 files changed, 21 insertions(+), 5 deletions(-)
src/Compilation.zig+15| ... | ... | @@ -919,6 +919,20 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 919 | 919 | } |
| 920 | 920 | }; |
| 921 | 921 | |
| 922 | const libc_stub_path: ?[]const u8 = if (options.target.isDarwin()) libc_stub: { | |
| 923 | // TODO consider other platforms than Darwin which require linking against libc here. | |
| 924 | const needs_libc_stub: bool = switch (options.output_mode) { | |
| 925 | .Obj => false, | |
| 926 | .Lib => if (options.link_mode) |mode| mode == .Dynamic else false, | |
| 927 | .Exe => true, | |
| 928 | }; | |
| 929 | if (needs_libc_stub) { | |
| 930 | break :libc_stub try options.zig_lib_directory.join(arena, &[_][]const u8{ | |
| 931 | "libc", "darwin", "libSystem.B.tbd", | |
| 932 | }); | |
| 933 | } else break :libc_stub null; | |
| 934 | } else null; | |
| 935 | ||
| 922 | 936 | const must_dynamic_link = dl: { |
| 923 | 937 | if (target_util.cannotDynamicLink(options.target)) |
| 924 | 938 | break :dl false; |
| ... | ... | @@ -1288,6 +1302,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1288 | 1302 | .use_lld = use_lld, |
| 1289 | 1303 | .use_llvm = use_llvm, |
| 1290 | 1304 | .system_linker_hack = darwin_options.system_linker_hack, |
| 1305 | .libc_stub_path = libc_stub_path, | |
| 1291 | 1306 | .link_libc = link_libc, |
| 1292 | 1307 | .link_libcpp = link_libcpp, |
| 1293 | 1308 | .link_libunwind = link_libunwind, |
src/link.zig+3| ... | ... | @@ -62,6 +62,9 @@ pub const Options = struct { |
| 62 | 62 | /// Darwin-only. If this is true, `use_llvm` is true, and `is_native_os` is true, this link code will |
| 63 | 63 | /// use system linker `ld` instead of the LLD. |
| 64 | 64 | system_linker_hack: bool, |
| 65 | /// Path to Zig-hosted libc stub file. | |
| 66 | /// On Darwin, this is a path to libSystem.B.tbd stub file. | |
| 67 | libc_stub_path: ?[]const u8, | |
| 65 | 68 | link_libc: bool, |
| 66 | 69 | link_libcpp: bool, |
| 67 | 70 | link_libunwind: bool, |
src/link/MachO.zig+1-3| ... | ... | @@ -848,9 +848,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { |
| 848 | 848 | try zld.link(positionals.items, full_out_path, .{ |
| 849 | 849 | .libs = libs.items, |
| 850 | 850 | .rpaths = rpaths.items, |
| 851 | .lib_system_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | |
| 852 | "libc", "darwin", "libSystem.B.tbd", | |
| 853 | }), | |
| 851 | .libc_stub_path = self.base.options.libc_stub_path.?, | |
| 854 | 852 | }); |
| 855 | 853 | |
| 856 | 854 | break :outer; |
src/link/MachO/Zld.zig+2-2| ... | ... | @@ -181,7 +181,7 @@ pub fn closeFiles(self: Zld) void { |
| 181 | 181 | const LinkArgs = struct { |
| 182 | 182 | libs: []const []const u8, |
| 183 | 183 | rpaths: []const []const u8, |
| 184 | lib_system_path: []const u8, | |
| 184 | libc_stub_path: []const u8, | |
| 185 | 185 | }; |
| 186 | 186 | |
| 187 | 187 | pub fn link(self: *Zld, files: []const []const u8, out_path: []const u8, args: LinkArgs) !void { |
| ... | ... | @@ -223,7 +223,7 @@ pub fn link(self: *Zld, files: []const []const u8, out_path: []const u8, args: L |
| 223 | 223 | try self.addRpaths(args.rpaths); |
| 224 | 224 | try self.parseInputFiles(files); |
| 225 | 225 | try self.parseLibs(args.libs); |
| 226 | try self.parseLibSystem(args.lib_system_path); | |
| 226 | try self.parseLibSystem(args.libc_stub_path); | |
| 227 | 227 | try self.resolveSymbols(); |
| 228 | 228 | try self.resolveStubsAndGotEntries(); |
| 229 | 229 | try self.updateMetadata(); |