From 1072f82acbe976222851bdd357f52dd9659d73d3 Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Mon, 9 Jan 2023 21:20:16 +0100 Subject: [PATCH] wasm-linker: Fix symbol name on undefined symbol When emitting errors for undefined symbols, rather than unconditionally always using the name from an import, we must verify it's a symbol type that could have such an import. e.g. undefined data symbols do not have a corresponding import. For this reason we must use the regular name. --- src/link/Wasm.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 377d526249..12bb90ea64 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -824,7 +824,9 @@ fn checkUndefinedSymbols(wasm: *const Wasm) !void { } else wasm.name; const import_name = if (undef.file) |file_index| name: { const obj = wasm.objects.items[file_index]; - const name_index = obj.findImport(symbol.tag.externalType(), symbol.index).name; + const name_index = if (symbol.tag == .function) name_index: { + break :name_index obj.findImport(symbol.tag.externalType(), symbol.index).name; + } else symbol.name; break :name obj.string_table.get(name_index); } else wasm.string_table.get(wasm.imports.get(undef).?.name); log.err("could not resolve undefined symbol '{s}'", .{import_name});