This is an archive of the discontinued LLVM Phabricator instance.

Don't use Wasm function sections for more than one function
ClosedPublic

Authored by ncw on Dec 1 2017, 10:38 AM.

Details

Summary

Fixes Bugzilla https://bugs.llvm.org/show_bug.cgi?id=35467

If a Wasm function section is created with more than one symbol, WasmObjectWriter fails with the following message: "function sections must contain one function each".

Currently, if a C++ file contains multiple static initialisers, they'll all be put in the same function section, triggering the error.

I think this change here is safe - it seems to be a spurious optimisation. In fact, I'm not even sure how it's intended to optimise the output...?

Diff Detail

Repository
rC Clang

Event Timeline

ncw created this revision.Dec 1 2017, 10:38 AM
sunfish accepted this revision.Dec 1 2017, 10:55 AM

I think that was copied from LinuxTargetInfo before we figured out our current object file strategy. On native platforms, it's an icache optimization, because startup functions are all called around the same time, and then never used again. However, this doesn't really apply to WebAssembly. It is possible that WebAssembly may eventually want to put everything called during startup at the beginning, so that clever browser engines can start running code even before the whole module is downloaded, however the optimization here wouldn't be sufficient. So this change looks good.

This revision is now accepted and ready to land.Dec 1 2017, 10:55 AM
ncw added a comment.Dec 5 2017, 8:04 AM

Thanks for the review @sunfish (and for the other input you've given). Could you land this for me Dan, as I don't have commit access? Thanks.

This revision was automatically updated to reflect the committed changes.