This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Add WASM_SEC_LAST_KNOWN to BinaryFormat section types list [NFC]
ClosedPublic

Authored by dschuff on Jun 6 2022, 3:46 PM.

Details

Summary

There are 3 places where we were using WASM_SEC_TAG as the "last" known
section type, which requires updating (or leaves a bug) when a new known
section type is added. Instead add a "last type" to the enum for this
purpose.

Diff Detail

Event Timeline

dschuff created this revision.Jun 6 2022, 3:46 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added subscribers: pmatos, asb, wingo and 4 others. · View Herald Transcript
dschuff requested review of this revision.Jun 6 2022, 3:46 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 6 2022, 3:46 PM
sbc100 accepted this revision.Jun 6 2022, 4:02 PM
This revision is now accepted and ready to land.Jun 6 2022, 4:02 PM
aheejin added inline comments.Jun 6 2022, 4:56 PM
llvm/include/llvm/BinaryFormat/Wasm.h
256
  • Does this pass clang-format? Because we don't have a space after ,.
  • 14 is not actually the last section known, because we don't have a section whose section code is 14. How about doing something like
WAS_SEC_LAST_KNOWN = WASM_SEC_TAG;

?

llvm/lib/ObjCopy/wasm/WasmReader.cpp
32–35

Why was this removed? It doesn't look like it's related to the last section thing.. It's just explaning custom sections have names already.

dschuff added inline comments.Jun 6 2022, 5:15 PM
llvm/lib/ObjCopy/wasm/WasmReader.cpp
32–35

Checking against WASM_SEC_LAST_KNOWN ensures that there can't be a new type of section that we don't explicitly handle here (because no types of known sections are explicitly handled or mentioned); any section known to sectionTypeToString will work.

dschuff updated this revision to Diff 434647.Jun 6 2022, 5:19 PM
  • review comments
dschuff added inline comments.Jun 6 2022, 5:21 PM
llvm/include/llvm/BinaryFormat/Wasm.h
256

ah, no it doesnt pass clang-format.
Also, agreed that LAST_KNOWN should match TAG rather than the one past-the-end. Fixed.

dschuff updated this revision to Diff 434650.Jun 6 2022, 5:23 PM
  • expand comment
aheejin added inline comments.Jun 6 2022, 5:24 PM
llvm/lib/ObjCopy/wasm/WasmReader.cpp
32–35

I'm not sure if I understand. Is this related to WASM_SEC_TAG -> WASM_LAST_SEC_KNOWN change in this PR? Or it's just an unrelated drive-by fix?

Checking against WASM_SEC_LAST_KNOWN ensures that there can't be a new type of section that we don't explicitly handle here (because no types of known sections are explicitly handled or mentioned);

I'm not sure what this means..

If the section type is CUSTOM, it has a name already.

Why is this deleted too? How is the custom section related to WASM_SEC_LAST_KNOWN?

dschuff added inline comments.Jun 6 2022, 5:34 PM
llvm/lib/ObjCopy/wasm/WasmReader.cpp
32–35

It is indirectly related.
The purpose of this block of code is to fill in the Name field of the WasmSection object for known sections (as the comment on line 27 explains). Suppose we add a new type of known section, WASM_SEC_NEW, and we update sectionTypeToString but forget to update this file. Before this CL, the behavior would be as described in the comment I'm deleting; this code would silently fail to give that section a name, which would mean it couldn't be selected by llvm-objdump. After this CL, everything would work, without needing any updates to this file (and if we forgot to update sectionTypeToString it would assert when encountering an unknown section type). So this comment was just to describe the somewhat surprising failure mode, and isn't necessary anymore.

aheejin accepted this revision.Jun 6 2022, 8:30 PM
aheejin added inline comments.
llvm/lib/ObjCopy/wasm/WasmReader.cpp
32–35

I see. My original question was why

If the section type is CUSTOM, it has a name already.

is related to this CL, but I see you moved that comment to elsewhere, so it hasn't really changed..

dschuff added inline comments.Jun 7 2022, 11:57 AM
llvm/lib/ObjCopy/wasm/WasmReader.cpp
32–35

Ah yeah that bit of explanation is still valuable. Thanks!

This revision was landed with ongoing or failed builds.Jun 7 2022, 12:07 PM
This revision was automatically updated to reflect the committed changes.