[PATCH] D40614: Add .init_array support to Wasm LLD

Nicholas Wilson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 00:55:25 PST 2017


ncw added a comment.

@sunfish, I think that's an interesting idea. Here are some thoughts I've had:

Pros of building "composite start function" on link:

- Uses native WebAssembly information rather than custom section. That is a genuinely nice change.

Cons:

- Adds asymmetry to destructor handling, when it feels like they should be mirror features
- Won't work out of the box with musl (needless friction with upstream?)
- Less extensible to other sections. I don't expect any other sections to need this treatment, currently, but maybe other languages apart from C have initialisation concerns - like Haskell or Rust...? Sticking as close to ELF as possible for C sets a good precedent for making those other languages easy to integrate. If you're suggesting adapting Musl's startup to WebAssembly, are we going to have to adapt the runtimes of other languages too?
- Assumes that start functions can be run in any order, but that's actually not exactly the case.  In particular, libc does its own initialisation _before_ any user-defined constructors, so that thread-local storage and printf are usable in all user-supplied code. It's a bit cheeky of libc to get special privileges like that (by virtue of supplying the entrypoint, it's able to do its own initialisation first). There would have to be a way to force this behaviour to continue - but it wouldn't be insurmountable, you'd just to have some "loose" object file (eg. "crt2.o") that we could guarantee appears first on the link-line.

In https://reviews.llvm.org/D40614#939712, @ruiu wrote:

> I wonder if you can do everything in the loader. We can let lld create .init_array and .fini_array (which is default behavior) and make a change to the loader so that the loader executes each function pointer in .init_array and .fini_array sections, no?


I'm not sure what you mean by the "loader" - is that the runtime WebAssembly interpreter/AOT-compiler? At runtime, the "sections" don't exist anymore, they're only available here to the linker. At runtime, you're right we want the interpreter to execute each function, and that's only achievable in WebAssembly via the START function.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D40614





More information about the llvm-commits mailing list