This is an archive of the discontinued LLVM Phabricator instance.

[lld][WebAssembly] Split __wasm_apply_relocs function in two
ClosedPublic

Authored by sbc100 on Dec 10 2020, 1:28 PM.

Details

Summary

We have two types of relocations that we apply on startup:

  1. Relocations that apply to wasm globals
  2. Relocations that apply to wasm memory

The first set of relocations use only the __memory_base import to
update a set of internal globals. Because wasm globals are thread local
these need to run on each thread. Memory relocations, like static
constructors, must only be run once.

To ensure global relocations run on all threads and because the only
depend on the immutable __memory_base import we can run them during
the WebAssembly start functions, instead of waiting until the
post-instantiation __wasm_call_ctors.

Diff Detail

Event Timeline

sbc100 created this revision.Dec 10 2020, 1:28 PM
sbc100 requested review of this revision.Dec 10 2020, 1:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 10 2020, 1:28 PM

Looks good! Can you add a test that uses __wasm_start?

lld/wasm/Writer.cpp
891–893
sbc100 updated this revision to Diff 311040.Dec 10 2020, 3:38 PM
  • feedback

Added a test. Once again I wish we had a good disassembler to make the test more readable.

tlively accepted this revision.Dec 10 2020, 4:53 PM

Nice!

lld/wasm/Writer.cpp
891

Still has an extra "a" in "create a synthetic functions" :)

This revision is now accepted and ready to land.Dec 10 2020, 4:53 PM
This revision was landed with ongoing or failed builds.Dec 10 2020, 5:07 PM
This revision was automatically updated to reflect the committed changes.