From 3edf8c7a6cb912597bbc97ad97d554e6e4d96cdb Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Mon, 12 Sep 2022 21:35:28 +0200 Subject: [PATCH] wasm-linker: reset file pointer for incremental On each invocation of `flush()` the file pointer is moved. This means that rather than overwriting the binary file, we're appending to the file. With this commit, we're resetting said pointer to '0' and overwrite the existing binary in incremental mode. --- src/link/Wasm.zig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 14d864c330..6dd3bc56ff 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -2218,6 +2218,9 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod // We write the magic bytes at the end so they will only be written // if everything succeeded as expected. So populate with 0's for now. try binary_writer.writeAll(&[_]u8{0} ** 8); + // (Re)set file pointer to 0 + try wasm.base.file.?.setEndPos(0); + try wasm.base.file.?.seekTo(0); // Type section if (wasm.func_types.items.len != 0) {