authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-06-15 20:15:01+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-06-16 17:16:56+02:00
log44b322ce6410a0fab7c3cbdfc35bb1530a31a304
tree107b1088c72cd6a08abf3f25f07ae49e676d4831
parente3db210cf1007f87930c97c072c54b2fb8ae0b8c
signaturelock-open Commit is signed but in an unrecognized format.

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.

2 files changed, 12 insertions(+), 2 deletions(-)

src/link/Wasm.zig+12-1
......@@ -1909,6 +1909,17 @@ pub fn addOrUpdateImport(
19091909 global_gop.value_ptr.* = loc;
19101910 try wasm.resolved_symbols.put(wasm.base.allocator, loc, {});
19111911 try wasm.undefs.putNoClobber(wasm.base.allocator, decl_name_index, loc);
1912 } else if (global_gop.value_ptr.*.index != symbol_index) {
1913 // We are not updating a symbol, but found an existing global
1914 // symbol with the same name. This means we always favor the
1915 // existing symbol, regardless whether it's defined or not.
1916 // We can also skip storing the import as we will not output
1917 // this symbol.
1918 return wasm.discarded.put(
1919 wasm.base.allocator,
1920 .{ .file = null, .index = symbol_index },
1921 global_gop.value_ptr.*,
1922 );
19121923 }
19131924
19141925 if (type_index) |ty_index| {
......@@ -1924,8 +1935,8 @@ pub fn addOrUpdateImport(
19241935 };
19251936 }
19261937 } else {
1938 // non-functions will not be imported from the runtime, but only resolved during link-time
19271939 symbol.tag = .data;
1928 return; // non-functions will not be imported from the runtime, but only resolved during link-time
19291940 }
19301941}
19311942
test/behavior/bugs/529.zig-1
......@@ -11,7 +11,6 @@ comptime {
1111const builtin = @import("builtin");
1212
1313test "issue 529 fixed" {
14 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
1514 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
1615 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1716 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO