zld: extract path to libc in the linker proper

This commit is contained in:
Jakub Konka 2021-06-24 12:56:28 +02:00
parent bc78b02c04
commit b55a3cefa4
3 changed files with 3 additions and 19 deletions

View File

@ -919,20 +919,6 @@ 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;
@ -1302,7 +1288,6 @@ 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,

View File

@ -62,9 +62,6 @@ 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,

View File

@ -848,7 +848,9 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
try zld.link(positionals.items, full_out_path, .{
.libs = libs.items,
.rpaths = rpaths.items,
.libc_stub_path = self.base.options.libc_stub_path.?,
.libc_stub_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{
"libc", "darwin", "libSystem.B.tbd",
}),
});
break :outer;