authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-15 21:26:55+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-16 12:06:58+02:00
log88d87d65061e7ac171cc23623a25e05b0278a872
tree1a5634cbfd88f74bee18082e36619ed15e004a37
parent4c83b11f71564e0de80f496f471ca6dfb83a95e3

stage2,macho: swap out inodes before checking for intermediary basename

This way we avoid the infamous SIGKILL on arm64 macos.

2 files changed, 7 insertions(+), 9 deletions(-)

src/link.zig+4-7
...@@ -352,11 +352,6 @@ pub const File = struct {...@@ -352,11 +352,6 @@ pub const File = struct {
352 }352 }
353 switch (base.tag) {353 switch (base.tag) {
354 .macho => if (base.file) |f| {354 .macho => if (base.file) |f| {
355 if (base.intermediary_basename != null) {
356 // The file we have open is not the final file that we want to
357 // make executable, so we don't have to close it.
358 return;
359 }
360 if (comptime builtin.target.isDarwin() and builtin.target.cpu.arch == .aarch64) {355 if (comptime builtin.target.isDarwin() and builtin.target.cpu.arch == .aarch64) {
361 if (base.options.target.cpu.arch == .aarch64) {356 if (base.options.target.cpu.arch == .aarch64) {
362 // XNU starting with Big Sur running on arm64 is caching inodes of running binaries.357 // XNU starting with Big Sur running on arm64 is caching inodes of running binaries.
...@@ -371,8 +366,10 @@ pub const File = struct {...@@ -371,8 +366,10 @@ pub const File = struct {
371 try emit.directory.handle.copyFile(emit.sub_path, emit.directory.handle, emit.sub_path, .{});366 try emit.directory.handle.copyFile(emit.sub_path, emit.directory.handle, emit.sub_path, .{});
372 }367 }
373 }368 }
374 f.close();369 if (base.intermediary_basename == null) {
375 base.file = null;370 f.close();
371 base.file = null;
372 }
376 },373 },
377 .coff, .elf, .plan9 => if (base.file) |f| {374 .coff, .elf, .plan9 => if (base.file) |f| {
378 if (base.intermediary_basename != null) {375 if (base.intermediary_basename != null) {
src/link/MachO.zig+3-2
...@@ -423,7 +423,7 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {...@@ -423,7 +423,7 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {
423 if (self.base.options.emit == null) {423 if (self.base.options.emit == null) {
424 if (build_options.have_llvm) {424 if (build_options.have_llvm) {
425 if (self.llvm_object) |llvm_object| {425 if (self.llvm_object) |llvm_object| {
426 return try llvm_object.flushModule(comp);426 try llvm_object.flushModule(comp);
427 }427 }
428 }428 }
429 return;429 return;
...@@ -1116,7 +1116,8 @@ pub fn flushObject(self: *MachO, comp: *Compilation) !void {...@@ -1116,7 +1116,8 @@ pub fn flushObject(self: *MachO, comp: *Compilation) !void {
1116 defer tracy.end();1116 defer tracy.end();
11171117
1118 if (build_options.have_llvm)1118 if (build_options.have_llvm)
1119 if (self.llvm_object) |llvm_object| return llvm_object.flushModule(comp);1119 if (self.llvm_object) |llvm_object|
1120 return llvm_object.flushModule(comp);
11201121
1121 return error.TODOImplementWritingObjFiles;1122 return error.TODOImplementWritingObjFiles;
1122}1123}