From c55b6c593b32c45947bd44fc5c38b4b5e01f4d66 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Sun, 12 Sep 2021 17:05:50 -0700 Subject: [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 --- .../WebAssemblyLowerEmscriptenEHSjLj.cpp | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'llvm/lib') 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(); assert(TPC && "Expected a TargetPassConfig"); auto &TM = TPC->getTM(); -- cgit v1.1