Index: wasm/LTO.cpp =================================================================== --- wasm/LTO.cpp +++ wasm/LTO.cpp @@ -72,10 +72,11 @@ BitcodeCompiler::~BitcodeCompiler() = default; static void undefine(Symbol *S) { - if (isa(S)) - replaceSymbol(S, S->getName(), 0); + if (auto F = dyn_cast(S)) + replaceSymbol(F, F->getName(), 0, F->getFile(), + F->FunctionType); else if (isa(S)) - replaceSymbol(S, S->getName(), 0); + replaceSymbol(S, S->getName(), 0, S->getFile()); else llvm_unreachable("unexpected symbol kind"); } Index: wasm/SymbolTable.cpp =================================================================== --- wasm/SymbolTable.cpp +++ wasm/SymbolTable.cpp @@ -201,7 +201,9 @@ Symbol *SymbolTable::addDefinedFunction(StringRef Name, uint32_t Flags, InputFile *File, InputFunction *Function) { - LLVM_DEBUG(dbgs() << "addDefinedFunction: " << Name << "\n"); + LLVM_DEBUG(dbgs() << "addDefinedFunction: " << Name << " [" + << (Function ? toString(Function->Signature) : "none") + << "]\n"); Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name, File); @@ -214,8 +216,12 @@ if (Function) checkFunctionType(S, File, &Function->Signature); - if (shouldReplace(S, File, Flags)) - replaceSymbol(S, Name, Flags, File, Function); + if (shouldReplace(S, File, Flags)) { + const WasmSignature *OldSig = cast(S)->FunctionType; + auto NewSym = replaceSymbol(S, Name, Flags, File, Function); + if (!NewSym->FunctionType) + NewSym->FunctionType = OldSig; + } return S; } @@ -263,7 +269,8 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef Name, uint32_t Flags, InputFile *File, const WasmSignature *Sig) { - LLVM_DEBUG(dbgs() << "addUndefinedFunction: " << Name << "\n"); + LLVM_DEBUG(dbgs() << "addUndefinedFunction: " << Name << + " [" << (Sig ? toString(*Sig) : "none") << "]\n"); Symbol *S; bool WasInserted;