aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Compilation.zig15
-rw-r--r--src/link.zig3
-rw-r--r--src/link/MachO.zig4
-rw-r--r--src/link/MachO/Zld.zig4
4 files changed, 21 insertions, 5 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index ea878056ae..c9b6162bd9 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -919,6 +919,20 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
}
};
+ const libc_stub_path: ?[]const u8 = if (options.target.isDarwin()) libc_stub: {
+ // TODO consider other platforms than Darwin which require linking against libc here.
+ const needs_libc_stub: bool = switch (options.output_mode) {
+ .Obj => false,
+ .Lib => if (options.link_mode) |mode| mode == .Dynamic else false,
+ .Exe => true,
+ };
+ if (needs_libc_stub) {
+ break :libc_stub try options.zig_lib_directory.join(arena, &[_][]const u8{
+ "libc", "darwin", "libSystem.B.tbd",
+ });
+ } else break :libc_stub null;
+ } else null;
+
const must_dynamic_link = dl: {
if (target_util.cannotDynamicLink(options.target))
break :dl false;
@@ -1288,6 +1302,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
.use_lld = use_lld,
.use_llvm = use_llvm,
.system_linker_hack = darwin_options.system_linker_hack,
+ .libc_stub_path = libc_stub_path,
.link_libc = link_libc,
.link_libcpp = link_libcpp,
.link_libunwind = link_libunwind,
diff --git a/src/link.zig b/src/link.zig
index bae468d075..4e1b38d07b 100644
--- a/src/link.zig
+++ b/src/link.zig
@@ -62,6 +62,9 @@ pub const Options = struct {
/// Darwin-only. If this is true, `use_llvm` is true, and `is_native_os` is true, this link code will
/// use system linker `ld` instead of the LLD.
system_linker_hack: bool,
+ /// Path to Zig-hosted libc stub file.
+ /// On Darwin, this is a path to libSystem.B.tbd stub file.
+ libc_stub_path: ?[]const u8,
link_libc: bool,
link_libcpp: bool,
link_libunwind: bool,
diff --git a/src/link/MachO.zig b/src/link/MachO.zig
index 76b59e896b..89e0c9a84a 100644
--- a/src/link/MachO.zig
+++ b/src/link/MachO.zig
@@ -848,9 +848,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
try zld.link(positionals.items, full_out_path, .{
.libs = libs.items,
.rpaths = rpaths.items,
- .lib_system_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
- "libc", "darwin", "libSystem.B.tbd",
- }),
+ .libc_stub_path = self.base.options.libc_stub_path.?,
});
break :outer;
diff --git a/src/link/MachO/Zld.zig b/src/link/MachO/Zld.zig
index 6945b00179..564da387c3 100644
--- a/src/link/MachO/Zld.zig
+++ b/src/link/MachO/Zld.zig
@@ -181,7 +181,7 @@ pub fn closeFiles(self: Zld) void {
const LinkArgs = struct {
libs: []const []const u8,
rpaths: []const []const u8,
- lib_system_path: []const u8,
+ libc_stub_path: []const u8,
};
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
try self.addRpaths(args.rpaths);
try self.parseInputFiles(files);
try self.parseLibs(args.libs);
- try self.parseLibSystem(args.lib_system_path);
+ try self.parseLibSystem(args.libc_stub_path);
try self.resolveSymbols();
try self.resolveStubsAndGotEntries();
try self.updateMetadata();