[PATCH] D135903: [wasm-ld] Add support for calling constructors in reactors.

Dan Gohman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 13 11:55:48 PDT 2022


sunfish created this revision.
sunfish added a reviewer: sbc100.
Herald added subscribers: pmatos, asb, dschuff.
Herald added a project: All.
sunfish requested review of this revision.
Herald added a subscriber: aheejin.
Herald added a project: LLVM.

With [WebAssembly/wasi-libc#328], we no longer want the behavior of
automatically inserting constructor calls on every command export.
The libc is now responsible for calling constructor calls in its 
`_start` entrypoint. So it makes sense to remove support for 
auto-wrapping command exports now.

      

At the same time, with [WebAssembly/wasi-libc#328], we are moving to
a place where users who had previously been building reactors and 
getting away with not running the constructors will suddenly have a
harder time doing so.

      

And as in [WebAssembly/wasi-libc#329], we're anticipating Wasm modules
being used in more environments where these invariants won't be as easy
to enforce.

      

So instead of removing the auto-wrapping *command* export code entirely,
convert into code to code that auto-wraps *reactor* exports. And give
it logic to call `__wasm_call_ctors` only if it hasn't been called yet.
That way, constructors will run automatically on the first export call,
so existing users won't be suddenly broken, and so reactors in general
won't be as tricky to use.

      

[WebAssembly/wasi-libc#328]: https://github.com/WebAssembly/wasi-libc/pull/328
[WebAssembly/wasi-libc#338]: https://github.com/WebAssembly/wasi-libc/pull/338
[WebAssembly/wasi-libc#329]: https://github.com/WebAssembly/wasi-libc/pull/329


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135903

Files:
  lld/test/wasm/command-exports-no-tors.s
  lld/test/wasm/command-exports.s
  lld/test/wasm/init-fini-gc.ll
  lld/test/wasm/init-fini-no-gc.ll
  lld/test/wasm/reactor-exports-no-tors.s
  lld/test/wasm/reactor-exports.s
  lld/wasm/Symbols.cpp
  lld/wasm/Symbols.h
  lld/wasm/Writer.cpp
  llvm/include/llvm/BinaryFormat/Wasm.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135903.467556.patch
Type: text/x-patch
Size: 15473 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221013/83dc42f3/attachment.bin>


More information about the llvm-commits mailing list