mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
macho: unify flushing object path with other linkers
This commit is contained in:
parent
f572e5a0c4
commit
47c834e477
@ -792,11 +792,8 @@ pub const File = struct {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (base.options.object_format == .macho) {
|
try base.flushModule(comp, prog_node);
|
||||||
try base.cast(MachO).?.flushObject(comp, prog_node);
|
|
||||||
} else {
|
|
||||||
try base.flushModule(comp, prog_node);
|
|
||||||
}
|
|
||||||
const dirname = fs.path.dirname(full_out_path_z) orelse ".";
|
const dirname = fs.path.dirname(full_out_path_z) orelse ".";
|
||||||
break :blk try fs.path.join(arena, &.{ dirname, base.intermediary_basename.? });
|
break :blk try fs.path.join(arena, &.{ dirname, base.intermediary_basename.? });
|
||||||
} else null;
|
} else null;
|
||||||
|
|||||||
@ -436,7 +436,7 @@ pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) !v
|
|||||||
return error.TODOImplementWritingStaticLibFiles;
|
return error.TODOImplementWritingStaticLibFiles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try self.flushModule(comp, prog_node);
|
return self.flushModule(comp, prog_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) !void {
|
pub 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
|
|||||||
defer tracy.end();
|
defer tracy.end();
|
||||||
|
|
||||||
const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;
|
const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;
|
||||||
if (!use_stage1 and self.base.options.output_mode == .Obj)
|
|
||||||
return self.flushObject(comp, prog_node);
|
if (build_options.have_llvm and !use_stage1) {
|
||||||
|
if (self.llvm_object) |llvm_object| {
|
||||||
|
try llvm_object.flushModule(comp, prog_node);
|
||||||
|
|
||||||
|
llvm_object.destroy(self.base.allocator);
|
||||||
|
self.llvm_object = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var sub_prog_node = prog_node.start("MachO Flush", 0);
|
||||||
|
sub_prog_node.activate();
|
||||||
|
defer sub_prog_node.end();
|
||||||
|
|
||||||
var arena_allocator = std.heap.ArenaAllocator.init(self.base.allocator);
|
var arena_allocator = std.heap.ArenaAllocator.init(self.base.allocator);
|
||||||
defer arena_allocator.deinit();
|
defer arena_allocator.deinit();
|
||||||
@ -454,12 +465,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
|
|||||||
const directory = self.base.options.emit.?.directory; // Just an alias to make it shorter to type.
|
const directory = self.base.options.emit.?.directory; // Just an alias to make it shorter to type.
|
||||||
const full_out_path = try directory.join(arena, &[_][]const u8{self.base.options.emit.?.sub_path});
|
const full_out_path = try directory.join(arena, &[_][]const u8{self.base.options.emit.?.sub_path});
|
||||||
|
|
||||||
if (self.d_sym) |*d_sym| {
|
|
||||||
if (self.base.options.module) |module| {
|
|
||||||
try d_sym.dwarf.flushModule(&self.base, module);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there is no Zig code to compile, then we should skip flushing the output file because it
|
// If there is no Zig code to compile, then we should skip flushing the output file because it
|
||||||
// will not be part of the linker line anyway.
|
// will not be part of the linker line anyway.
|
||||||
const module_obj_path: ?[]const u8 = if (self.base.options.module) |module| blk: {
|
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
|
|||||||
|
|
||||||
const obj_basename = self.base.intermediary_basename orelse break :blk null;
|
const obj_basename = self.base.intermediary_basename orelse break :blk null;
|
||||||
|
|
||||||
try self.flushObject(comp, prog_node);
|
|
||||||
|
|
||||||
if (fs.path.dirname(full_out_path)) |dirname| {
|
if (fs.path.dirname(full_out_path)) |dirname| {
|
||||||
break :blk try fs.path.join(arena, &.{ dirname, obj_basename });
|
break :blk try fs.path.join(arena, &.{ dirname, obj_basename });
|
||||||
} else {
|
} else {
|
||||||
@ -491,9 +494,11 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
|
|||||||
}
|
}
|
||||||
} else null;
|
} else null;
|
||||||
|
|
||||||
var sub_prog_node = prog_node.start("MachO Flush", 0);
|
if (self.d_sym) |*d_sym| {
|
||||||
sub_prog_node.activate();
|
if (self.base.options.module) |module| {
|
||||||
defer sub_prog_node.end();
|
try d_sym.dwarf.flushModule(&self.base, module);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const is_lib = self.base.options.output_mode == .Lib;
|
const is_lib = self.base.options.output_mode == .Lib;
|
||||||
const is_dyn_lib = self.base.options.link_mode == .Dynamic and is_lib;
|
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
|
|||||||
self.cold_start = false;
|
self.cold_start = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flushObject(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) !void {
|
|
||||||
const tracy = trace(@src());
|
|
||||||
defer tracy.end();
|
|
||||||
|
|
||||||
if (build_options.have_llvm)
|
|
||||||
if (self.llvm_object) |llvm_object|
|
|
||||||
return llvm_object.flushModule(comp, prog_node);
|
|
||||||
|
|
||||||
return error.TODOImplementWritingObjFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn resolveSearchDir(
|
fn resolveSearchDir(
|
||||||
arena: Allocator,
|
arena: Allocator,
|
||||||
dir: []const u8,
|
dir: []const u8,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user