From 2cf1c1b96b4869a61d2bfb8d2e9725e2adacde17 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Thu, 18 Mar 2021 08:42:07 +0100 Subject: [PATCH] macho: honor verbose_link when linking with zld --- src/link/MachO.zig | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 4c5d405074..517fabaf3e 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -633,13 +633,15 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { if (!mem.eql(u8, the_object_path, full_out_path)) { try fs.cwd().copyFile(the_object_path, fs.cwd(), full_out_path, .{}); } - } else { + } else outer: { const use_zld = blk: { if (self.base.options.is_native_os and self.base.options.system_linker_hack) { + // If the user forces the use of ld64, make sure we are running native! break :blk false; } if (self.base.options.target.cpu.arch == .aarch64) { + // On aarch64, always use zld. break :blk true; } @@ -647,6 +649,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { self.base.options.output_mode == .Lib or self.base.options.linker_script != null) { + // Fallback to LLD in this handful of cases on x86_64 only. break :blk false; } @@ -674,7 +677,28 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { try input_files.append(comp.libcxxabi_static_lib.?.full_object_path); try input_files.append(comp.libcxx_static_lib.?.full_object_path); } - return zld.link(input_files.items, full_out_path); + + if (self.base.options.verbose_link) { + var argv = std.ArrayList([]const u8).init(self.base.allocator); + defer argv.deinit(); + + try argv.append("zig"); + try argv.append("ld"); + + try argv.ensureCapacity(input_files.items.len); + for (input_files.items) |f| { + argv.appendAssumeCapacity(f); + } + + try argv.append("-o"); + try argv.append(full_out_path); + + Compilation.dump_argv(argv.items); + } + + try zld.link(input_files.items, full_out_path); + + break :outer; } // Create an LLD command line and invoke it.