[PATCH] D66356: [WebAssembly] Forbid use of EM_ASM with setjmp/longjmp

Guanzhong Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 16 10:56:00 PDT 2019


quantum created this revision.
quantum added reviewers: tlively, sbc100, jgravelle-google, kripken.
Herald added subscribers: llvm-commits, sunfish, aheejin, hiraditya, dschuff.
Herald added a project: LLVM.

We tried to support EM_ASM with setjmp/longjmp in binaryen. But with dynamic
linking thrown into the mix, the code is no longer understandable and cannot
be maintained. We also discovered more bugs in the EM_ASM handling code.

To ensure maintainability and correctness of the binaryen code, EM_ASM will
no longer be supported with setjmp/longjmp. This is probably fine since the
support was added recently and haven't be published.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66356

Files:
  llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp


Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -274,6 +274,7 @@
 
   bool areAllExceptionsAllowed() const { return EHWhitelistSet.empty(); }
   bool canLongjmp(Module &M, const Value *Callee) const;
+  bool isEmAsmCall(Module &M, const Value *Callee) const;
 
   void rebuildSSA(Function &F);
 
@@ -537,6 +538,22 @@
   return true;
 }
 
+bool WebAssemblyLowerEmscriptenEHSjLj::isEmAsmCall(Module &M,
+                                                   const Value *Callee) const {
+  Function *EmAsmConstIntF = M.getFunction("emscripten_asm_const_int");
+  Function *EmAsmConstDoubleF = M.getFunction("emscripten_asm_const_double");
+  Function *EmAsmConstIntSyncMainF =
+      M.getFunction("emscripten_asm_const_int_sync_on_main_thread");
+  Function *EmAsmConstDoubleSyncMainF =
+      M.getFunction("emscripten_asm_const_double_sync_on_main_thread");
+  Function *EmAsmConstAsyncMainF =
+      M.getFunction("emscripten_asm_const_async_on_main_thread");
+
+  return Callee == EmAsmConstIntF || Callee == EmAsmConstDoubleF ||
+         Callee == EmAsmConstIntSyncMainF ||
+         Callee == EmAsmConstDoubleSyncMainF || Callee == EmAsmConstAsyncMainF;
+}
+
 // Generate testSetjmp function call seqence with preamble and postamble.
 // The code this generates is equivalent to the following JavaScript code:
 // if (%__THREW__.val != 0 & threwValue != 0) {
@@ -983,6 +1000,10 @@
       const Value *Callee = CI->getCalledValue();
       if (!canLongjmp(M, Callee))
         continue;
+      if (isEmAsmCall(M, Callee))
+        report_fatal_error("Cannot use EM_ASM* with setjmp/longjmp in " +
+                               F.getName() + ". Please consider using EM_JS.",
+                           false);
 
       Value *Threw = nullptr;
       BasicBlock *Tail;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66356.215635.patch
Type: text/x-patch
Size: 2006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190816/728e2726/attachment.bin>


More information about the llvm-commits mailing list