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.
This commit is contained in:
Luuk de Gram 2023-01-09 21:20:16 +01:00
parent 2339b25fd4
commit 1072f82acb
No known key found for this signature in database
GPG Key ID: A8CFE58E4DC7D664

View File

@ -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});