diff options
author | Heejin Ahn <aheejin@gmail.com> | 2021-09-12 17:05:50 -0700 |
---|---|---|
committer | Heejin Ahn <aheejin@gmail.com> | 2021-09-13 14:20:04 -0700 |
commit | c55b6c593b32c45947bd44fc5c38b4b5e01f4d66 (patch) | |
tree | 2d4037a29117d3b085020009b805b0339b3ff400 /llvm/lib | |
parent | b7b4ebbcfa463a7fae61dca7cec30c5b747bdec8 (diff) | |
download | llvm-c55b6c593b32c45947bd44fc5c38b4b5e01f4d66.zip llvm-c55b6c593b32c45947bd44fc5c38b4b5e01f4d66.tar.gz llvm-c55b6c593b32c45947bd44fc5c38b4b5e01f4d66.tar.bz2 |
[WebAssembly] Handle _setjmp and _longjmp in SjLj
In some platforms `_setjmp` and `_longjmp` are used instead of `setjmp`
and `longjmp`. This CL adds support for them.
Fixes https://github.com/emscripten-core/emscripten/issues/14999.
Reviewed By: dschuff
Differential Revision: https://reviews.llvm.org/D109669
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp index dd8909b..33a9c60 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp @@ -831,6 +831,33 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module &M) { Function *SetjmpF = M.getFunction("setjmp"); Function *LongjmpF = M.getFunction("longjmp"); + // In some platforms _setjmp and _longjmp are used instead. Change these to + // use setjmp/longjmp instead, because we laster detect these functions by + // their names. + Function *SetjmpF2 = M.getFunction("_setjmp"); + Function *LongjmpF2 = M.getFunction("_longjmp"); + if (SetjmpF2) { + if (SetjmpF) { + if (SetjmpF->getFunctionType() != SetjmpF2->getFunctionType()) + report_fatal_error("setjmp and _setjmp have different function types"); + } else { + SetjmpF = Function::Create(SetjmpF2->getFunctionType(), + GlobalValue::ExternalLinkage, "setjmp", M); + } + SetjmpF2->replaceAllUsesWith(SetjmpF); + } + if (LongjmpF2) { + if (LongjmpF) { + if (LongjmpF->getFunctionType() != LongjmpF2->getFunctionType()) + report_fatal_error( + "longjmp and _longjmp have different function types"); + } else { + LongjmpF = Function::Create(LongjmpF2->getFunctionType(), + GlobalValue::ExternalLinkage, "setjmp", M); + } + LongjmpF2->replaceAllUsesWith(LongjmpF); + } + auto *TPC = getAnalysisIfAvailable<TargetPassConfig>(); assert(TPC && "Expected a TargetPassConfig"); auto &TM = TPC->getTM<WebAssemblyTargetMachine>(); |