This is an archive of the discontinued LLVM Phabricator instance.

[WASM] Avoid passing uninit section indices when not creating code or data sections
ClosedPublic

Authored by guiand on Jun 11 2020, 5:26 PM.

Details

Summary

Currently, section indices may be passed uninitialized by value if writing the section fails. Removes section indices form class initialization and returns them from the write{Code,Data}Section function calls instead.

Diff Detail

Event Timeline

guiand created this revision.Jun 11 2020, 5:26 PM

How about one of these two options:

  1. initialing CodeSectionIndex and DataSectionIndex to 0 in the class declaration? (and in reset() I guess too?). You can treat 0 as invalid for both of them.
  1. Remove CodeSectionIndex and DataSectionIndex completely from the class and just return the index value from writeCodeSection and writeDataSection (again with 0 meaning none).

Either of those I think would be fine.

sbc100 added a comment.EditedJun 11 2020, 6:44 PM

Did you see this happening in practice? Did msan catch it?

The second option sounds good to me! I'll make the change tomorrow.

I've been working on stricter msan checks to flag uninit data crossing function boundaries (as it's UB in C++). You can find that change pending at https://reviews.llvm.org/D81699.

guiand updated this revision to Diff 270435.Jun 12 2020, 9:51 AM
guiand edited the summary of this revision. (Show Details)

Updated with returning the indices from the writeSection functions.

sbc100 accepted this revision.Jun 12 2020, 10:34 AM

Thanks!

This revision is now accepted and ready to land.Jun 12 2020, 10:34 AM

I guess its not easy to write a test for this since its a use of uninitialized data which can be non-deterministic?

Yeah, but I think the current check-clang tests (under msan once the changes go through) will be useful for that.

This change should be ready to land. Do you have commit access to llvm?

Ah, no I don't have commit access yet. Would you mind helping me land this? Thanks so much!

This revision was automatically updated to reflect the committed changes.

Thanks, Sam!