aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuuk de Gram <luuk@degram.dev>2023-06-15 20:15:01 +0200
committerLuuk de Gram <luuk@degram.dev>2023-06-16 17:16:56 +0200
commit44b322ce6410a0fab7c3cbdfc35bb1530a31a304 (patch)
tree107b1088c72cd6a08abf3f25f07ae49e676d4831 /src
parente3db210cf1007f87930c97c072c54b2fb8ae0b8c (diff)
downloadzig-44b322ce6410a0fab7c3cbdfc35bb1530a31a304.tar.gz
zig-44b322ce6410a0fab7c3cbdfc35bb1530a31a304.zip
wasm-linker: correctly resolve undefined functions
We now resolve undefined symbols during incremental-compilation where we discard the current symbol if we detect we found an existing symbol which is not the one currently being updated. The symbol will always be discarded in favor of the existing symbol in such a case.
Diffstat (limited to 'src')
-rw-r--r--src/link/Wasm.zig13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig
index f593f95c3d..60944ff981 100644
--- a/src/link/Wasm.zig
+++ b/src/link/Wasm.zig
@@ -1909,6 +1909,17 @@ pub fn addOrUpdateImport(
global_gop.value_ptr.* = loc;
try wasm.resolved_symbols.put(wasm.base.allocator, loc, {});
try wasm.undefs.putNoClobber(wasm.base.allocator, decl_name_index, loc);
+ } else if (global_gop.value_ptr.*.index != symbol_index) {
+ // We are not updating a symbol, but found an existing global
+ // symbol with the same name. This means we always favor the
+ // existing symbol, regardless whether it's defined or not.
+ // We can also skip storing the import as we will not output
+ // this symbol.
+ return wasm.discarded.put(
+ wasm.base.allocator,
+ .{ .file = null, .index = symbol_index },
+ global_gop.value_ptr.*,
+ );
}
if (type_index) |ty_index| {
@@ -1924,8 +1935,8 @@ pub fn addOrUpdateImport(
};
}
} else {
+ // non-functions will not be imported from the runtime, but only resolved during link-time
symbol.tag = .data;
- return; // non-functions will not be imported from the runtime, but only resolved during link-time
}
}