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/Coff | |
| 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/Coff')
| -rw-r--r-- | src/link/Coff/lld.zig | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/link/Coff/lld.zig b/src/link/Coff/lld.zig index 3a833c40ae..914be5a443 100644 --- a/src/link/Coff/lld.zig +++ b/src/link/Coff/lld.zig @@ -17,14 +17,12 @@ const Allocator = mem.Allocator; const Coff = @import("../Coff.zig"); const Compilation = @import("../../Compilation.zig"); -pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) !void { +pub fn linkWithLLD(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node) !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(); const directory = self.base.emit.directory; // Just an alias to make it shorter to type. const full_out_path = try directory.join(arena, &[_][]const u8{self.base.emit.sub_path}); @@ -32,7 +30,7 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod // 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. const module_obj_path: ?[]const u8 = if (comp.module != null) blk: { - try self.flushModule(comp, prog_node); + try self.flushModule(arena, prog_node); if (fs.path.dirname(full_out_path)) |dirname| { break :blk try fs.path.join(arena, &.{ dirname, self.base.zcu_object_sub_path.? }); |
