This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Elide data segments for .bss sections
ClosedPublic

Authored by tlively on Oct 14 2019, 6:03 PM.

Details

Summary

WebAssembly memories are zero-initialized, so when module does not
import its memory initializing .bss sections is guaranteed to be a
no-op. To reduce binary size and initialization time, .bss sections
are simply not emitted into the final binary unless the memory is
imported.

Event Timeline

tlively created this revision.Oct 14 2019, 6:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 14 2019, 6:03 PM
sbc100 accepted this revision.Oct 14 2019, 8:13 PM

Great!

lld/wasm/OutputSections.cpp
219

You find this easier to read than:

for (auto S : segments) 
  if (!seg->isImplicit)
    return true;
return false;

?

Maybe I just need get of board with the kids and accept the C++ lambda future that we now live in? I mean it is kinda cool.

Is there something like python's any() builtin in stl that might make this more readable?

This revision is now accepted and ready to land.Oct 14 2019, 8:13 PM
ruiu added a subscriber: ruiu.Oct 15 2019, 2:27 AM
ruiu added inline comments.
lld/wasm/OutputSections.cpp
219

Yeah, in lld the for loops such as the one Sam suggested are used more often than the higher-order predicate function. Rewriting this with for is perhaps more preferable.

lld/wasm/OutputSegment.h
35

isBss is I think more straightforward name, and I believe we use that variable name in ELF too.

tlively marked 2 inline comments as done.Oct 15 2019, 11:39 AM
tlively added inline comments.
lld/wasm/OutputSections.cpp
219

I agree the for loop is more readable, and it's a real shame that all the nice functional programming idioms are so ugly in C++. Will fix.

lld/wasm/OutputSegment.h
35

Sounds good to me.

This revision was automatically updated to reflect the committed changes.
tlively marked an inline comment as done.