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 {
792792 }),
793793 }
794794 }
795 if (base.options.object_format == .macho) {
796 try base.cast(MachO).?.flushObject(comp, prog_node);
797 } else {
798 try base.flushModule(comp, prog_node);
799 }
795 try base.flushModule(comp, prog_node);
796
800797 const dirname = fs.path.dirname(full_out_path_z) orelse ".";
801798 break :blk try fs.path.join(arena, &.{ dirname, base.intermediary_basename.? });
802799 } 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
436436 return error.TODOImplementWritingStaticLibFiles;
437437 }
438438 }
439 try self.flushModule(comp, prog_node);
439 return self.flushModule(comp, prog_node);
440440}
441441
442442pub 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
444444 defer tracy.end();
445445
446446 const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;
447 if (!use_stage1 and self.base.options.output_mode == .Obj)
448 return self.flushObject(comp, prog_node);
447
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
450461 var arena_allocator = std.heap.ArenaAllocator.init(self.base.allocator);
451462 defer arena_allocator.deinit();
......@@ -454,12 +465,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
454465 const directory = self.base.options.emit.?.directory; // Just an alias to make it shorter to type.
455466 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
463468 // If there is no Zig code to compile, then we should skip flushing the output file because it
464469 // will not be part of the linker line anyway.
465470 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
482487
483488 const obj_basename = self.base.intermediary_basename orelse break :blk null;
484489
485 try self.flushObject(comp, prog_node);
486
487490 if (fs.path.dirname(full_out_path)) |dirname| {
488491 break :blk try fs.path.join(arena, &.{ dirname, obj_basename });
489492 } else {
......@@ -491,9 +494,11 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
491494 }
492495 } else null;
493496
494 var sub_prog_node = prog_node.start("MachO Flush", 0);
495 sub_prog_node.activate();
496 defer sub_prog_node.end();
497 if (self.d_sym) |*d_sym| {
498 if (self.base.options.module) |module| {
499 try d_sym.dwarf.flushModule(&self.base, module);
500 }
501 }
497502
498503 const is_lib = self.base.options.output_mode == .Lib;
499504 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
11191124 self.cold_start = false;
11201125}
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
11331127fn resolveSearchDir(
11341128 arena: Allocator,
11351129 dir: []const u8,