[PATCH] D40559: Wasm entrypoint changes #2 (export entrypoint in "start" section) APPLY AFTER D40724

Nicholas Wilson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 6 03:19:09 PST 2017


ncw added a comment.

In https://reviews.llvm.org/D40559#946128, @sbc100 wrote:

> Sadly I think we are blocked on: https://github.com/WebAssembly/design/issues/1160.
>
> Once your --no-entry change lands and this is rebased on top this change should be very small right?   Maybe we could land it behind a flag then to make this behaviour optional?  --use-wasm-start?
>
> Out of interest, do you have a use case where you strongly prefer this over calling the function explicitly from the host side?


Because of fact that syscalls can't work until after WebAssembly instantiation (in order to get the Memory), you're right that the "start" block is actually less useful than I'd thought :(

However, the changes here to `--entry` are still worth doing, I think.

I reckon, now that we have `--undefined`, the semantics of the default behaviour that Emscripten wants is actually `--undefined=_start_wasm` rather than `--entry _start_wasm`.

- Change the default value for `--entry` to be `--no-entry` rather than `--entry _start`
- Make the following change to the Clang driver, to use `--undefined` so that the symbol is exported, but not set as the Wasm entrypoint:

  diff --git a/lib/Driver/ToolChains/WebAssembly.cpp b/lib/Driver/ToolChains/WebAssembly.cpp
  index 8ae1b6c2f5..d0888fc5b7 100644
  --- a/lib/Driver/ToolChains/WebAssembly.cpp
  +++ b/lib/Driver/ToolChains/WebAssembly.cpp
  @@ -51,7 +51,7 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
     ToolChain.AddFilePathLibArgs(Args, CmdArgs);
   
     if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles))
  -    CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.o")));
  +    CmdArgs.push_back("--undefined=_start_wasm");
   
     AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);

(Here, I'm using `_start_wasm` instead of `_start`, which is a new symbol I've submitted in a patch to upstream Musl. It's like `_start`, but it runs the libc static initialisers without then running main. The name is flexible - we just need libc and Clang to agree on a symbol name that has that behaviour, and there isn't any existing conventional name for such a symbol.)


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D40559





More information about the llvm-commits mailing list