diff options
author | Sam Clegg <sbc@chromium.org> | 2020-03-31 21:45:57 -0700 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2020-04-01 16:33:33 -0700 |
commit | 296ccef70363df9195bc678ad5501dd44de7f8fb (patch) | |
tree | f59937fc7fa9aa1ab43c6f1b92a44197f4a3c423 | |
parent | f203100ebe22bf97a4268a562cdbef22d14db915 (diff) | |
download | llvm-296ccef70363df9195bc678ad5501dd44de7f8fb.zip llvm-296ccef70363df9195bc678ad5501dd44de7f8fb.tar.gz llvm-296ccef70363df9195bc678ad5501dd44de7f8fb.tar.bz2 |
[WebAssembly] EmscriptenEHSjLj: Mark __invoke_ functions as imported
This means the linker will be expect them be undefined at link time an
will generate imports from the `env` module rather than reporting
undefined externals.
Differential Revision: https://reviews.llvm.org/D77192
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp | 17 | ||||
-rw-r--r-- | llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll | 4 |
2 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp index 89265a3..c8878a4 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp @@ -344,6 +344,21 @@ static std::string getSignature(FunctionType *FTy) { return Sig; } +static void markAsImported(Function *F) { + // Tell the linker that this function is expected to be imported from the + // 'env' module. + if (!F->hasFnAttribute("wasm-import-module")) { + llvm::AttrBuilder B; + B.addAttribute("wasm-import-module", "env"); + F->addAttributes(llvm::AttributeList::FunctionIndex, B); + } + if (!F->hasFnAttribute("wasm-import-name")) { + llvm::AttrBuilder B; + B.addAttribute("wasm-import-name", F->getName()); + F->addAttributes(llvm::AttributeList::FunctionIndex, B); + } +} + // Returns __cxa_find_matching_catch_N function, where N = NumClauses + 2. // This is because a landingpad instruction contains two more arguments, a // personality function and a cleanup bit, and __cxa_find_matching_catch_N @@ -360,6 +375,7 @@ WebAssemblyLowerEmscriptenEHSjLj::getFindMatchingCatch(Module &M, Function *F = Function::Create( FTy, GlobalValue::ExternalLinkage, "__cxa_find_matching_catch_" + Twine(NumClauses + 2), &M); + markAsImported(F); FindMatchingCatches[NumClauses] = F; return F; } @@ -469,6 +485,7 @@ Function *WebAssemblyLowerEmscriptenEHSjLj::getInvokeWrapper(CallOrInvoke *CI) { CalleeFTy->isVarArg()); Function *F = Function::Create(FTy, GlobalValue::ExternalLinkage, "__invoke_" + Sig, M); + markAsImported(F); InvokeWrappers[Sig] = F; return F; } diff --git a/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll b/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll index cad6c4a..ad42cc5 100644 --- a/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll +++ b/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll @@ -308,6 +308,10 @@ attributes #0 = { returns_twice } attributes #1 = { noreturn } attributes #2 = { nounwind } attributes #3 = { allocsize(0) } +; CHECK: attributes #{{[0-9]+}} = { "wasm-import-module"="env" "wasm-import-name"="__invoke_void" } +; CHECK: attributes #{{[0-9]+}} = { "wasm-import-module"="env" "wasm-import-name"="__cxa_find_matching_catch_3" } +; CHECK: attributes #{{[0-9]+}} = { "wasm-import-module"="env" "wasm-import-name"="__invoke_i8*_i32_%struct.__jmp_buf_tag*" } +; CHECK: attributes #{{[0-9]+}} = { "wasm-import-module"="env" "wasm-import-name"="__invoke_void_%struct.__jmp_buf_tag*_i32" } ; CHECK: attributes #[[ALLOCSIZE_ATTR]] = { allocsize(1) } !llvm.dbg.cu = !{!2} |