diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-01-01 19:11:57 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-01-01 19:49:08 -0700 |
| commit | d5c1e7f7b1381036f7d98c1944607cb0e1c0d4da (patch) | |
| tree | f78506c79713b855ed8f23426ce78e0e292e13ee /src/link/MachO.zig | |
| parent | eae6d45cded76dd027569c86a7cdd5bc9039664b (diff) | |
| download | zig-d5c1e7f7b1381036f7d98c1944607cb0e1c0d4da.tar.gz zig-d5c1e7f7b1381036f7d98c1944607cb0e1c0d4da.zip | |
link: accept the update arena in flush
This branch introduced an arena allocator for temporary allocations in
Compilation.update. Almost every implementation of flush() inside the
linker code was already creating a local arena that had the lifetime of
the function call. This commit passes the update arena so that all those
local ones can be deleted, resulting in slightly more efficient memory
usage with every compilation update.
While at it, this commit also removes the Compilation parameter from the
linker flush function API since a reference to the Compilation is now
already stored in `link.File`.
Diffstat (limited to 'src/link/MachO.zig')
| -rw-r--r-- | src/link/MachO.zig | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/link/MachO.zig b/src/link/MachO.zig index c0a259d982..cb26aa0ca3 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -315,13 +315,14 @@ pub fn open( return createEmpty(arena, comp, emit, options); } -pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void { - const gpa = self.base.comp.gpa; - const output_mode = self.base.comp.config.output_mode; +pub fn flush(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void { + const comp = self.base.comp; + const gpa = comp.gpa; + const output_mode = comp.config.output_mode; - if (output_mode == .Lib and self.base.comp.config.link_mode == .Static) { + if (output_mode == .Lib and comp.config.link_mode == .Static) { if (build_options.have_llvm) { - return self.base.linkAsArchive(comp, prog_node); + return self.base.linkAsArchive(arena, prog_node); } else { try comp.link_errors.ensureUnusedCapacity(gpa, 1); comp.link_errors.appendAssumeCapacity(.{ @@ -332,19 +333,17 @@ pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) li } switch (self.mode) { - .zld => return zld.linkWithZld(self, comp, prog_node), - .incremental => return self.flushModule(comp, prog_node), + .zld => return zld.linkWithZld(self, arena, prog_node), + .incremental => return self.flushModule(arena, prog_node), } } -pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void { +pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node) link.File.FlushError!void { const tracy = trace(@src()); defer tracy.end(); + const comp = self.base.comp; const gpa = comp.gpa; - var arena_allocator = std.heap.ArenaAllocator.init(gpa); - defer arena_allocator.deinit(); - const arena = arena_allocator.allocator(); if (self.llvm_object) |llvm_object| { try self.base.emitLlvmObject(arena, llvm_object, prog_node); |
