authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-06-14 14:12:12+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-17 16:38:59-07:00
log47c834e477657113bccaaad32e91148ff837f1a4
treea27092b5235683994850f13364aaf3061282cc86
parentf572e5a0c4e4ff34566533131b3423688a439863

macho: unify flushing object path with other linkers


2 files changed, 21 insertions(+), 30 deletions(-)

src/link.zig+2-5
...@@ -792,11 +792,8 @@ pub const File = struct {...@@ -792,11 +792,8 @@ pub const File = struct {
792 }),792 }),
793 }793 }
794 }794 }
795 if (base.options.object_format == .macho) {795 try base.flushModule(comp, prog_node);
796 try base.cast(MachO).?.flushObject(comp, prog_node);796
797 } else {
798 try base.flushModule(comp, prog_node);
799 }
800 const dirname = fs.path.dirname(full_out_path_z) orelse ".";797 const dirname = fs.path.dirname(full_out_path_z) orelse ".";
801 break :blk try fs.path.join(arena, &.{ dirname, base.intermediary_basename.? });798 break :blk try fs.path.join(arena, &.{ dirname, base.intermediary_basename.? });
802 } else null;799 } else null;
src/link/MachO.zig+19-25
...@@ -436,7 +436,7 @@ pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) !v...@@ -436,7 +436,7 @@ pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) !v
436 return error.TODOImplementWritingStaticLibFiles;436 return error.TODOImplementWritingStaticLibFiles;
437 }437 }
438 }438 }
439 try self.flushModule(comp, prog_node);439 return self.flushModule(comp, prog_node);
440}440}
441441
442pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) !void {442pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) !void {
...@@ -444,8 +444,19 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -444,8 +444,19 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
444 defer tracy.end();444 defer tracy.end();
445445
446 const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;446 const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;
447 if (!use_stage1 and self.base.options.output_mode == .Obj)447
448 return self.flushObject(comp, prog_node);448 if (build_options.have_llvm and !use_stage1) {
449 if (self.llvm_object) |llvm_object| {
450 try llvm_object.flushModule(comp, prog_node);
451
452 llvm_object.destroy(self.base.allocator);
453 self.llvm_object = null;
454 }
455 }
456
457 var sub_prog_node = prog_node.start("MachO Flush", 0);
458 sub_prog_node.activate();
459 defer sub_prog_node.end();
449460
450 var arena_allocator = std.heap.ArenaAllocator.init(self.base.allocator);461 var arena_allocator = std.heap.ArenaAllocator.init(self.base.allocator);
451 defer arena_allocator.deinit();462 defer arena_allocator.deinit();
...@@ -454,12 +465,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -454,12 +465,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
454 const directory = self.base.options.emit.?.directory; // Just an alias to make it shorter to type.465 const directory = self.base.options.emit.?.directory; // Just an alias to make it shorter to type.
455 const full_out_path = try directory.join(arena, &[_][]const u8{self.base.options.emit.?.sub_path});466 const full_out_path = try directory.join(arena, &[_][]const u8{self.base.options.emit.?.sub_path});
456467
457 if (self.d_sym) |*d_sym| {
458 if (self.base.options.module) |module| {
459 try d_sym.dwarf.flushModule(&self.base, module);
460 }
461 }
462
463 // If there is no Zig code to compile, then we should skip flushing the output file because it468 // If there is no Zig code to compile, then we should skip flushing the output file because it
464 // will not be part of the linker line anyway.469 // will not be part of the linker line anyway.
465 const module_obj_path: ?[]const u8 = if (self.base.options.module) |module| blk: {470 const module_obj_path: ?[]const u8 = if (self.base.options.module) |module| blk: {
...@@ -482,8 +487,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -482,8 +487,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
482487
483 const obj_basename = self.base.intermediary_basename orelse break :blk null;488 const obj_basename = self.base.intermediary_basename orelse break :blk null;
484489
485 try self.flushObject(comp, prog_node);
486
487 if (fs.path.dirname(full_out_path)) |dirname| {490 if (fs.path.dirname(full_out_path)) |dirname| {
488 break :blk try fs.path.join(arena, &.{ dirname, obj_basename });491 break :blk try fs.path.join(arena, &.{ dirname, obj_basename });
489 } else {492 } else {
...@@ -491,9 +494,11 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -491,9 +494,11 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
491 }494 }
492 } else null;495 } else null;
493496
494 var sub_prog_node = prog_node.start("MachO Flush", 0);497 if (self.d_sym) |*d_sym| {
495 sub_prog_node.activate();498 if (self.base.options.module) |module| {
496 defer sub_prog_node.end();499 try d_sym.dwarf.flushModule(&self.base, module);
500 }
501 }
497502
498 const is_lib = self.base.options.output_mode == .Lib;503 const is_lib = self.base.options.output_mode == .Lib;
499 const is_dyn_lib = self.base.options.link_mode == .Dynamic and is_lib;504 const is_dyn_lib = self.base.options.link_mode == .Dynamic and is_lib;
...@@ -1119,17 +1124,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -1119,17 +1124,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
1119 self.cold_start = false;1124 self.cold_start = false;
1120}1125}
11211126
1122pub fn flushObject(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) !void {
1123 const tracy = trace(@src());
1124 defer tracy.end();
1125
1126 if (build_options.have_llvm)
1127 if (self.llvm_object) |llvm_object|
1128 return llvm_object.flushModule(comp, prog_node);
1129
1130 return error.TODOImplementWritingObjFiles;
1131}
1132
1133fn resolveSearchDir(1127fn resolveSearchDir(
1134 arena: Allocator,1128 arena: Allocator,
1135 dir: []const u8,1129 dir: []const u8,