aboutsummaryrefslogtreecommitdiff
path: root/src/link/Wasm.zig
diff options
context:
space:
mode:
authorLuuk de Gram <luuk@degram.dev>2024-02-28 19:02:16 +0100
committerLuuk de Gram <luuk@degram.dev>2024-02-29 15:52:43 +0100
commit202ed7330fdc55cce22bfa9d9b5da03776e871b4 (patch)
treeb0ef3791a3e10ea9e2b553cf2457f0a0fc079a27 /src/link/Wasm.zig
parent196ba706a05046b2209529744d2df47215819691 (diff)
downloadzig-202ed7330fdc55cce22bfa9d9b5da03776e871b4.tar.gz
zig-202ed7330fdc55cce22bfa9d9b5da03776e871b4.zip
fix memory leaks
Diffstat (limited to 'src/link/Wasm.zig')
-rw-r--r--src/link/Wasm.zig21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig
index 9a59484aa1..b9997cf883 100644
--- a/src/link/Wasm.zig
+++ b/src/link/Wasm.zig
@@ -33,7 +33,6 @@ const Object = @import("Wasm/Object.zig");
const Symbol = @import("Wasm/Symbol.zig");
const Type = @import("../type.zig").Type;
const TypedValue = @import("../TypedValue.zig");
-const Value = @import("../value.zig").Value;
const ZigObject = @import("Wasm/ZigObject.zig");
pub const Atom = @import("Wasm/Atom.zig");
@@ -72,7 +71,7 @@ files: std.MultiArrayList(File.Entry) = .{},
/// to support existing code.
/// TODO: Allow setting this through a flag?
host_name: []const u8 = "env",
-/// List of all symbols generated by Zig code.
+/// List of symbols generated by the linker.
synthetic_symbols: std.ArrayListUnmanaged(Symbol) = .{},
/// Maps atoms to their segment index
atoms: std.AutoHashMapUnmanaged(u32, Atom.Index) = .{},
@@ -179,10 +178,6 @@ undefs: std.AutoArrayHashMapUnmanaged(u32, SymbolLoc) = .{},
/// Undefined (and synthetic) symbols do not have an Atom and therefore cannot be mapped.
symbol_atom: std.AutoHashMapUnmanaged(SymbolLoc, Atom.Index) = .{},
-/// List of atom indexes of functions that are generated by the backend,
-/// rather than by the linker.
-synthetic_functions: std.ArrayListUnmanaged(Atom.Index) = .{},
-
pub const Alignment = types.Alignment;
pub const Segment = struct {
@@ -259,7 +254,7 @@ pub const InitFuncLoc = struct {
/// our own ctors.
file: File.Index,
/// Symbol index within the corresponding object file.
- index: u32,
+ index: Symbol.Index,
/// The priority in which the constructor must be called.
priority: u32,
@@ -270,7 +265,7 @@ pub const InitFuncLoc = struct {
/// Turns the given `InitFuncLoc` into a `SymbolLoc`
fn getSymbolLoc(loc: InitFuncLoc) SymbolLoc {
- return .{ .file = loc.file, .index = @enumFromInt(loc.index) };
+ return .{ .file = loc.file, .index = loc.index };
}
/// Returns true when `lhs` has a higher priority (e.i. value closer to 0) than `rhs`.
@@ -1411,9 +1406,9 @@ pub fn deinit(wasm: *Wasm) void {
archive.deinit(gpa);
}
- for (wasm.synthetic_functions.items) |atom_index| {
- const atom = wasm.getAtomPtr(atom_index);
- atom.deinit(gpa);
+ if (wasm.findGlobalSymbol("__wasm_init_tls")) |loc| {
+ const atom = wasm.symbol_atom.get(loc).?;
+ wasm.getAtomPtr(atom).deinit(gpa);
}
wasm.synthetic_symbols.deinit(gpa);
@@ -1441,7 +1436,7 @@ pub fn deinit(wasm: *Wasm) void {
wasm.exports.deinit(gpa);
wasm.string_table.deinit(gpa);
- wasm.synthetic_functions.deinit(gpa);
+ wasm.files.deinit(gpa);
}
pub fn updateFunc(wasm: *Wasm, mod: *Module, func_index: InternPool.Index, air: Air, liveness: Liveness) !void {
@@ -1763,7 +1758,7 @@ fn setupInitFunctions(wasm: *Wasm) !void {
}
log.debug("appended init func '{s}'\n", .{object.string_table.get(symbol.name)});
wasm.init_funcs.appendAssumeCapacity(.{
- .index = init_func.symbol_index,
+ .index = @enumFromInt(init_func.symbol_index),
.file = file_index,
.priority = init_func.priority,
});