This is an archive of the discontinued LLVM Phabricator instance.

[lld][WebAssembly] Initialize bss segments using memory.fill
ClosedPublic

Authored by sbc100 on Oct 27 2021, 3:15 PM.

Details

Summary

Previously we were relying on the dynamic loader to take care of this
but it simple and correct for us to do it here instead.

Now we initialize bss segments as part of __wasm_init_memory at the
same time we initialize passive segments.

In addition, we extend the us of __wasm_init_memory outside of shared
memory situations. Specifically, it is now used to initialize bss
segments any time the memory is imported (but only when the bulk
memory features is available).

Diff Detail

Event Timeline

sbc100 created this revision.Oct 27 2021, 3:15 PM
sbc100 requested review of this revision.Oct 27 2021, 3:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 27 2021, 3:15 PM
sbc100 edited the summary of this revision. (Show Details)Oct 27 2021, 3:16 PM
sbc100 edited the summary of this revision. (Show Details)
sbc100 added a reviewer: tlively.
tlively accepted this revision.Oct 27 2021, 3:56 PM

Code LGTM, thanks!

lld/test/wasm/shared-memory-bss.s
62

I think it would be clearer to place these comments before the arguments to the memory.init and memory.fill instructions rather than immediately before the instructions themselves. Also, it would be helpful if you could insert similar comments for the other parts of the code to split it into more easily digestible pieces.

lld/wasm/Writer.cpp
969
This revision is now accepted and ready to land.Oct 27 2021, 3:56 PM

Actually I think we can use the memory.fill instruction in general.. since it might be available.

Oh yeah, I guess we could only do this if bulk memory is enabled.

sbc100 updated this revision to Diff 382872.Oct 27 2021, 6:22 PM
  • avoid bulk memory opterations when feature not available
sbc100 updated this revision to Diff 382874.Oct 27 2021, 6:26 PM
  • cleaner diff

Oh yeah, I guess we could only do this if bulk memory is enabled.

I think this works in all configurations now:

  1. imported memory + bulk-memory feature: memory.init
  2. imported memory - bulk-memory feature: include bss just like normal data
  3. Non-imported memory: elide bss completely
sbc100 edited the summary of this revision. (Show Details)Oct 27 2021, 6:28 PM
tlively added inline comments.Oct 28 2021, 9:48 AM
lld/wasm/Writer.cpp
549

There are still a bunch of other feature checks in the previous function. Would it make sense to break them out as well?

sbc100 added inline comments.Oct 28 2021, 10:39 AM
lld/wasm/Writer.cpp
549

Yes, I was thinking the same... or maybe try to give this function a better name? or move these checks into calculateImports/calculateExports?

sbc100 updated this revision to Diff 383110.Oct 28 2021, 11:54 AM
sbc100 marked an inline comment as done.
sbc100 edited the summary of this revision. (Show Details)
  • rename function and add comment
lld/wasm/Writer.cpp
549

I renamed this function and added a comment.

tlively accepted this revision.Oct 28 2021, 1:42 PM