| ... | ... | @@ -600,27 +600,34 @@ fn resolveSymbolsInObject(wasm: *Wasm, object_index: u16) !void { |
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | if (existing_sym.isUndefined() and symbol.isUndefined()) { |
| 603 | | const existing_name = if (existing_loc.file) |file_index| blk: { |
| 604 | | const obj = wasm.objects.items[file_index]; |
| 605 | | const name_index = obj.findImport(symbol.tag.externalType(), existing_sym.index).module_name; |
| 606 | | break :blk obj.string_table.get(name_index); |
| 607 | | } else blk: { |
| 608 | | const name_index = wasm.imports.get(existing_loc).?.module_name; |
| 609 | | break :blk wasm.string_table.get(name_index); |
| 610 | | }; |
| 603 | // only verify module/import name for function symbols |
| 604 | if (symbol.tag == .function) { |
| 605 | const existing_name = if (existing_loc.file) |file_index| blk: { |
| 606 | const obj = wasm.objects.items[file_index]; |
| 607 | const name_index = obj.findImport(symbol.tag.externalType(), existing_sym.index).module_name; |
| 608 | break :blk obj.string_table.get(name_index); |
| 609 | } else blk: { |
| 610 | const name_index = wasm.imports.get(existing_loc).?.module_name; |
| 611 | break :blk wasm.string_table.get(name_index); |
| 612 | }; |
| 611 | 613 | |
| 612 | | const module_index = object.findImport(symbol.tag.externalType(), symbol.index).module_name; |
| 613 | | const module_name = object.string_table.get(module_index); |
| 614 | | if (!mem.eql(u8, existing_name, module_name)) { |
| 615 | | log.err("symbol '{s}' module name mismatch. Expected '{s}', but found '{s}'", .{ |
| 616 | | sym_name, |
| 617 | | existing_name, |
| 618 | | module_name, |
| 619 | | }); |
| 620 | | log.err(" first definition in '{s}'", .{existing_file_path}); |
| 621 | | log.err(" next definition in '{s}'", .{object.name}); |
| 622 | | return error.ModuleNameMismatch; |
| 614 | const module_index = object.findImport(symbol.tag.externalType(), symbol.index).module_name; |
| 615 | const module_name = object.string_table.get(module_index); |
| 616 | if (!mem.eql(u8, existing_name, module_name)) { |
| 617 | log.err("symbol '{s}' module name mismatch. Expected '{s}', but found '{s}'", .{ |
| 618 | sym_name, |
| 619 | existing_name, |
| 620 | module_name, |
| 621 | }); |
| 622 | log.err(" first definition in '{s}'", .{existing_file_path}); |
| 623 | log.err(" next definition in '{s}'", .{object.name}); |
| 624 | return error.ModuleNameMismatch; |
| 625 | } |
| 623 | 626 | } |
| 627 | |
| 628 | // both undefined so skip overwriting existing symbol and discard the new symbol |
| 629 | try wasm.discarded.put(wasm.base.allocator, location, existing_loc); |
| 630 | continue; |
| 624 | 631 | } |
| 625 | 632 | |
| 626 | 633 | if (existing_sym.tag == .global) { |
| ... | ... | @@ -646,8 +653,10 @@ fn resolveSymbolsInObject(wasm: *Wasm, object_index: u16) !void { |
| 646 | 653 | } |
| 647 | 654 | } |
| 648 | 655 | |
| 649 | | // when both symbols are weak, we skip overwriting |
| 650 | | if (existing_sym.isWeak() and symbol.isWeak()) { |
| 656 | // when both symbols are weak, we skip overwriting unless the existing |
| 657 | // symbol is weak and the new one isn't, in which case we *do* overwrite it. |
| 658 | if (existing_sym.isWeak() and symbol.isWeak()) blk: { |
| 659 | if (existing_sym.isUndefined() and !symbol.isUndefined()) break :blk; |
| 651 | 660 | try wasm.discarded.put(wasm.base.allocator, location, existing_loc); |
| 652 | 661 | continue; |
| 653 | 662 | } |
| ... | ... | @@ -1935,7 +1944,9 @@ fn setupStart(wasm: *Wasm) !void { |
| 1935 | 1944 | return error.MissingSymbol; |
| 1936 | 1945 | }; |
| 1937 | 1946 | |
| 1938 | | const symbol_loc = wasm.globals.get(symbol_name_offset).?; |
| 1947 | const symbol_loc = wasm.globals.get(symbol_name_offset) orelse { |
| 1948 | log.err("Entry symbol '{s}' not found", .{entry_name}); |
| 1949 | }; |
| 1939 | 1950 | const symbol = symbol_loc.getSymbol(wasm); |
| 1940 | 1951 | if (symbol.tag != .function) { |
| 1941 | 1952 | log.err("Entry symbol '{s}' is not a function", .{entry_name}); |