From c7e4c711fc5795e66f974316611922a0b962eb99 Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Sun, 6 Mar 2022 22:38:10 +0100 Subject: wasm: Fix incremental compilation - atoms may have relocations, so freeing them when we update the parent atom will cause segfaults. - Not all declarations will live in symbol_atom --- src/link/Wasm.zig | 6 +++--- src/link/Wasm/Atom.zig | 7 +------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index ca9d06e0ec..1288b27a81 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -504,7 +504,7 @@ pub fn updateFunc(self: *Wasm, module: *Module, func: *Module.Fn, air: Air, live const decl = func.owner_decl; assert(decl.link.wasm.sym_index != 0); // Must call allocateDeclIndexes() - decl.link.wasm.clear(self.base.allocator); + decl.link.wasm.clear(); var code_writer = std.ArrayList(u8).init(self.base.allocator); defer code_writer.deinit(); @@ -542,7 +542,7 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void { assert(decl.link.wasm.sym_index != 0); // Must call allocateDeclIndexes() - decl.link.wasm.clear(self.base.allocator); + decl.link.wasm.clear(); if (decl.isExtern()) { return self.addOrUpdateImport(decl); @@ -827,7 +827,7 @@ pub fn freeDecl(self: *Wasm, decl: *Module.Decl) void { assert(self.imports.remove(atom.symbolLoc())); } assert(self.resolved_symbols.swapRemove(atom.symbolLoc())); - assert(self.symbol_atom.remove(atom.symbolLoc())); + _ = self.symbol_atom.remove(atom.symbolLoc()); // not all decl's exist in symbol_atom atom.deinit(self.base.allocator); } diff --git a/src/link/Wasm/Atom.zig b/src/link/Wasm/Atom.zig index e89ed37123..a3e1c25190 100644 --- a/src/link/Wasm/Atom.zig +++ b/src/link/Wasm/Atom.zig @@ -62,14 +62,9 @@ pub fn deinit(self: *Atom, gpa: Allocator) void { /// Sets the length of relocations and code to '0', /// effectively resetting them and allowing them to be re-populated. -pub fn clear(self: *Atom, gpa: Allocator) void { +pub fn clear(self: *Atom) void { self.relocs.clearRetainingCapacity(); self.code.clearRetainingCapacity(); - - // locals will be re-generated - for (self.locals.items) |*local| { - local.deinit(gpa); - } } pub fn format(self: Atom, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { -- cgit v1.2.3