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(...@@ -1909,6 +1909,17 @@ pub fn addOrUpdateImport(
1909 global_gop.value_ptr.* = loc;1909 global_gop.value_ptr.* = loc;
1910 try wasm.resolved_symbols.put(wasm.base.allocator, loc, {});1910 try wasm.resolved_symbols.put(wasm.base.allocator, loc, {});
1911 try wasm.undefs.putNoClobber(wasm.base.allocator, decl_name_index, loc);1911 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 );
1912 }1923 }
19131924
1914 if (type_index) |ty_index| {1925 if (type_index) |ty_index| {
...@@ -1924,8 +1935,8 @@ pub fn addOrUpdateImport(...@@ -1924,8 +1935,8 @@ pub fn addOrUpdateImport(
1924 };1935 };
1925 }1936 }
1926 } else {1937 } else {
1938 // non-functions will not be imported from the runtime, but only resolved during link-time
1927 symbol.tag = .data;1939 symbol.tag = .data;
1928 return; // non-functions will not be imported from the runtime, but only resolved during link-time
1929 }1940 }
1930}1941}
19311942
test/behavior/bugs/529.zig-1
...@@ -11,7 +11,6 @@ comptime {...@@ -11,7 +11,6 @@ comptime {
11const builtin = @import("builtin");11const builtin = @import("builtin");
1212
13test "issue 529 fixed" {13test "issue 529 fixed" {
14 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
15 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO14 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
16 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO15 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
17 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO16 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO