From 88d87d65061e7ac171cc23623a25e05b0278a872 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 15 Apr 2022 21:26:55 +0200 Subject: [PATCH] stage2,macho: swap out inodes before checking for intermediary basename This way we avoid the infamous SIGKILL on arm64 macos. --- src/link.zig | 11 ++++------- src/link/MachO.zig | 5 +++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/link.zig b/src/link.zig index dbef400189..2d7e577b70 100644 --- a/src/link.zig +++ b/src/link.zig @@ -352,11 +352,6 @@ pub const File = struct { } switch (base.tag) { .macho => if (base.file) |f| { - if (base.intermediary_basename != null) { - // The file we have open is not the final file that we want to - // make executable, so we don't have to close it. - return; - } if (comptime builtin.target.isDarwin() and builtin.target.cpu.arch == .aarch64) { if (base.options.target.cpu.arch == .aarch64) { // XNU starting with Big Sur running on arm64 is caching inodes of running binaries. @@ -371,8 +366,10 @@ pub const File = struct { try emit.directory.handle.copyFile(emit.sub_path, emit.directory.handle, emit.sub_path, .{}); } } - f.close(); - base.file = null; + if (base.intermediary_basename == null) { + f.close(); + base.file = null; + } }, .coff, .elf, .plan9 => if (base.file) |f| { if (base.intermediary_basename != null) { diff --git a/src/link/MachO.zig b/src/link/MachO.zig index fa1ba2835a..a7437ed576 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -423,7 +423,7 @@ pub fn flush(self: *MachO, comp: *Compilation) !void { if (self.base.options.emit == null) { if (build_options.have_llvm) { if (self.llvm_object) |llvm_object| { - return try llvm_object.flushModule(comp); + try llvm_object.flushModule(comp); } } return; @@ -1116,7 +1116,8 @@ pub fn flushObject(self: *MachO, comp: *Compilation) !void { defer tracy.end(); if (build_options.have_llvm) - if (self.llvm_object) |llvm_object| return llvm_object.flushModule(comp); + if (self.llvm_object) |llvm_object| + return llvm_object.flushModule(comp); return error.TODOImplementWritingObjFiles; }