[PATCH] D108960: [WebAssembly] Add Wasm SjLj support

Heejin Ahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 31 17:28:45 PDT 2021


aheejin added inline comments.


================
Comment at: llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp:11
+/// This file lowers exception-related instructions and setjmp/longjmp function
+/// calls to use Emscripten's library functions. The pass uses JavaScript's try
+/// and catch mechanism in case of Emscripten EH/SjLj and Wasm EH intrinsics in
----------------
dschuff wrote:
> aheejin wrote:
> > dschuff wrote:
> > > Eventually it might be nice to make it possible to use wasm SJLJ without needing emscripten, which should be feasible since it doesn't need JS. I guess that would mean moving or copying some library functions out of emscripten proper, and maybe refactoring the code or something. It doesn't have to be soon though.
> > What this uses from Emscripten is just a couple of C library functions, mainly `saveSetjmp` and `testSetjmp` in https://github.com/emscripten-core/emscripten/blob/main/system/lib/compiler-rt/emscripten_setjmp.c. It doesn't need JS. Also it needs `__wasm_longjmp` which calls our Clang builtin. These functions have to be somewhere. If not Emscripten, where do you suggest? We can construct these functions in LLVM but not sure what the benefit for that is..?
> I guess I'm not saying we should move it "out" of emscripten, per se. Probably the "right" place for this kind of thing would be a language runtime library. e.g. if this were for C++, libc++abi would probably be the right place. Unfortunately C doesn't have a "low-level" library like C++ does, so in a standalone toolchain (i.e. other than emscripten) it might likely go in libc, or in some other toolchain-specific library that gets linked into every build. In emscripten, it looks like we just add an extra file to compiler-rt, and compiler-rt is in the emscripten repo. If e.g. wasi wanted to support SJLJ they might put it in the lower layer of wasi-libc or something. In that case it might make sense to move those functions into their own file. Then wasi-libc could just copy that whole file without getting the other emscripten code.
Yeah that makes sense. By the way that emscripten_setjmp.c is already pretty an isolated addition to compiler-rt; that single file contains all SjLj related stuff. It both contains Emscripten SjLj stuff that calls a JS function (`emscripten_longjmp`) and Wasm SjLj stuff like `__wasm_longjmp`, but I think fixing that and moving that file to somewhere else wouldn't be a huge problem.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108960/new/

https://reviews.llvm.org/D108960



More information about the llvm-commits mailing list