diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp --- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp @@ -469,6 +469,17 @@ CalleeFTy->isVarArg()); Function *F = Function::Create(FTy, GlobalValue::ExternalLinkage, "__invoke_" + Sig, M); + llvm::AttrBuilder B; + // Tell the linker that this function is expected to be imported from the + // 'env' module. + if (!F->hasFnAttribute("wasm-import-module")) { + B.addAttribute("wasm-import-module", "env"); + F->addAttributes(llvm::AttributeList::FunctionIndex, B); + } + if (!F->hasFnAttribute("wasm-import-name")) { + B.addAttribute("wasm-import-name", F->getName()); + F->addAttributes(llvm::AttributeList::FunctionIndex, B); + } InvokeWrappers[Sig] = F; return F; }