This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Check if the section order is correct
ClosedPublic

Authored by aheejin on Nov 26 2018, 6:08 PM.

Details

Summary

This patch checks if the section order is correct when reading a wasm
object file in WasmObjectFile and converting YAML to wasm object in
yaml2wasm. (It is not possible to check when reading YAML because it is
handled exclusively by the YAML reader.)

This checks the ordering of all known sections (core sections + known
custom sections). This also adds section ID DataCount section that will
be scheduled to be added in near future.

Diff Detail

Repository
rL LLVM

Event Timeline

aheejin created this revision.Nov 26 2018, 6:08 PM
aheejin updated this revision to Diff 175374.Nov 26 2018, 6:15 PM
  • Change function name + add comments
aheejin updated this revision to Diff 175375.Nov 26 2018, 6:17 PM
  • Comment fix

For reference there was a previous CL that tries to do something similar: https://reviews.llvm.org/D44024.

I see.. so why wasn't it landed? It says it was stalled because we couldn't decide whether or how to check custom section orderings and orderings between custom section vs. normal sections. Do we now have consensus on that? If so landing that CL makes more sense. If not, do you think now is a good time to re-discuss it? Or would landing this CL first and decide what to do with custom sections later makes sense?

The main motivation for this CL was, I had to delete code that was previously checking relative section orders in yaml2wasm because the previous code only checked if the section codes were monotonically increasing and the new event section had code 12, and you suggested we should reinstate it in a separate CL.

sbc100 added a comment.EditedNov 27 2018, 5:39 PM

I see.. so why wasn't it landed? It says it was stalled because we couldn't decide whether or how to check custom section orderings and orderings between custom section vs. normal sections. Do we now have consensus on that? If so landing that CL makes more sense. If not, do you think now is a good time to re-discuss it? Or would landing this CL first and decide what to do with custom sections later makes sense?

The main motivation for this CL was, I had to delete code that was previously checking relative section orders in yaml2wasm because the previous code only checked if the section codes were monotonically increasing and the new event section had code 12, and you suggested we should reinstate it in a separate CL.

I don't feel super strongly about it, but for completeness we do need to include custom sections in the ordering I think.

IIRC, I think i was hoping there would be a simpler way to do that the method proposed in D44024 but maybe t here isn't.

BTW, Is there any reason you decided to do this in libBinaryFormat over libObject?

D44024 is not simpler; actually it is more complicated because it checks more things than this, such as custom sections and whether the function section matches with the code section. If you think we should also include custom section checking in this CL, why don't we just land D44024?

The reason I added that in BinaryFormat is it uses wasm namespace while Object uses object namespace. I wanted put isValidSectionOrder function within wasm namespace.

D44024 is not simpler; actually it is more complicated because it checks more things than this, such as custom sections and whether the function section matches with the code section. If you think we should also include custom section checking in this CL, why don't we just land D44024?

Sure I'd be happy to see D44024 resurrected. I'll ping ncw@ and see if he has cycles to do that.

The reason I added that in BinaryFormat is it uses wasm namespace while Object uses object namespace. I wanted put isValidSectionOrder function within wasm namespace.

Right, but there is plenty of wasm-speciifc code in the object namespace. The code for wasm object file parsing, etc all lives in the object::WasmObjectFile() class. Its not clear to me in this case what the best home for such a function is.

aheejin updated this revision to Diff 177817.Dec 11 2018, 7:56 PM
  • Add custom section checking
aheejin marked an inline comment as done.Dec 11 2018, 8:00 PM

Also moved the checker to lib/Object.

include/llvm/Object/Wasm.h
311 ↗(On Diff #177817)

I copied this comments on orders (linking section should be after data section and reloc sections should be after linking section) from D44024. Are these still valid? If so, do you think we should specify them in Linking spec?

aheejin edited the summary of this revision. (Show Details)Dec 11 2018, 8:03 PM
aheejin updated this revision to Diff 177821.Dec 11 2018, 9:39 PM
  • Remove unused code
aheejin marked an inline comment as done.Dec 11 2018, 9:40 PM
aheejin added inline comments.
include/llvm/Object/Wasm.h
311 ↗(On Diff #177817)

Oh after deleting some code the comment location got weird. What I meant was the comments about relationship of data - "reloc" and "reloc" - "linking".

sbc100 added inline comments.Dec 14 2018, 8:57 AM
lib/Object/WasmObjectFile.cpp
278 ↗(On Diff #177821)

If this is only passing the section type, not the section name, I can't see how it can check the ordering for custom sections?

Should we move this change down in "parseSection" so it can access the name and ID of custom sections?

1454 ↗(On Diff #177821)

We also have "dylink" section which must come first before any other section.

tools/yaml2obj/CMakeLists.txt
2 ↗(On Diff #177821)

Is this change still needed?

aheejin marked 6 inline comments as done.Dec 14 2018, 3:54 PM
aheejin added inline comments.
include/llvm/Object/Wasm.h
311 ↗(On Diff #177817)

Are these explanations about data - "reloc" and "reloc" - "linking" ordering still correct?

lib/Object/WasmObjectFile.cpp
278 ↗(On Diff #177821)

Oh right, I forgot that... Moved the checking code into readSection. And also fixed it in yaml2wasm side too, in which case I didn't need to move the checking code into a function though.

tools/yaml2obj/CMakeLists.txt
2 ↗(On Diff #177821)

Nope. Deleted it, thanks.

aheejin updated this revision to Diff 178310.Dec 14 2018, 3:54 PM
aheejin marked 2 inline comments as done.
  • Address comments
aheejin updated this revision to Diff 178311.Dec 14 2018, 3:55 PM
  • Delete unused peakUint8
sbc100 added inline comments.Dec 14 2018, 4:00 PM
include/llvm/Object/Wasm.h
311 ↗(On Diff #177817)

Yup. They seem correct to me.

sbc100 accepted this revision.Dec 14 2018, 4:01 PM
This revision is now accepted and ready to land.Dec 14 2018, 4:01 PM
aheejin edited the summary of this revision. (Show Details)Dec 14 2018, 4:48 PM
This revision was automatically updated to reflect the committed changes.