[PATCH] D65783: [WebAssembly] Initialize memory in start function

Thomas Lively via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 3 18:20:07 PDT 2019


tlively added inline comments.


================
Comment at: lld/wasm/Writer.cpp:400
         break;
       case WASM_FEATURE_PREFIX_DISALLOWED:
         disallowed.insert({feature.Name, fileName});
----------------
aheejin wrote:
> This may not be related to this CL, but just wondering, what happens we explicitly enable a feature using `--feature=` option that's in the disallowed set in one of the objects? Do we error out?
Yes, that would be an error unless `--no-check-features` is also passed. `--feature=` is just a more explicit way of passing features and is not meant to be any more privileged than the target features sections in determining what is correct and safe.


================
Comment at: lld/wasm/Writer.cpp:709
+    writeU8(os, WASM_OPCODE_IF, "IF");
+    writeU8(os, WASM_TYPE_NORESULT, "blocktype");
+
----------------
aheejin wrote:
> - Before this change, how did we distinguish the main thread? (I don't know the full history of this feature, sorry)
> - Does this new code mean whichever thread that first runs this code becomes the main thread?
Before this change we relied on the runtime to manually invoke `__wasm_init_memory` or `__wasm_call_ctors` (which called `__wasm_init_memory`) on the main thread. With this change, the code is more robust because it doesn't require the runtime to call anything or even ensure that there is only one thread running during memory initialization.

Whichever thread runs first initializes the memory, but is not otherwise marked as the main thread or privileged in any way. If you instantiate a module on a number of threads at once it should not be possible to determine which one initialized the memory.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65783





More information about the llvm-commits mailing list