Skip to content

wasm-dis should run validation #3545

Open

Description

@martianboy

We recently allowed printing expression contents with respect to features in the Print pass (#3537) and we needed that as part of enabling multi-table modules in the Binaryen IR (#3517). But after I updated the tests, I noticed there's a difference between .from-wast and .fromBinary test files, in that .from-wast files were generated correctly with the correct features, but .fromBinary files were always generated with all features disabled.

Now, for .fromBinary tests we use wasm-as to compile a .wasm binary, and then use wasm-dis to check the text output. But since wasm-dis does not have the feature options, the only way it can print with features is if the module has a features section, wasm-as does not have an option to emit.

Two solutions are possible in my view:

  1. Add feature options to wasm-dis, so we have the flexibility to print with the desired features.
  2. Allow tools like wasm-as and wasm-split to emit a features section, so the features are read and applied while parsing the binary in wasm-dis.

Activity

  1. tlively commented on Feb 4, 2021

    @tlively
    Member

    Option 1 would probably be the least surprising for users.

  2. added a commit that references this issue on Feb 5, 2021
    9b7c903
  3. kripken commented on Feb 5, 2021

    @kripken
    Member

    Does wasm-dis not assume all features are present, so that it can always print a module? If so, isn't it an option to ignore the difference between the from-text and from-binary results in the test suite? I agree the difference is a little odd, but if it's just in the test suite, and it's not causing a risk of us missing actual bugs, I'm not that worried.

  4. martianboy commented on Feb 5, 2021

    @martianboy
    ContributorAuthor

    @kripken No wasm-dis is not assuming all features. In fact it does not assume any features unless a features section is present in the binary. Otherwise there wouldn't be a difference between .from-wast and .fromBinary tests at all.

  5. kripken commented on Feb 5, 2021

    @kripken
    Member

    Oh, you're right @martianboy ... what confused me is that wasm-dis works on a file using features but without a features section. It works because we don't run the validator...

    In that case, I think we should enable all features in wasm-dis, as that seems simplest?

  6. martianboy commented on Feb 6, 2021

    @martianboy
    ContributorAuthor

    @kripken Yeah sure that works. I made PR #3548 that adds feature options, but if you think that's overkill, I can simply apply all features to the module right after parsing.

  7. kripken commented on Feb 8, 2021

    @kripken
    Member

    I think it would be better to enable them all. My mental model is that wasm-dis can disassemble any input module, no matter the features, so it should "just work".

    @tlively what do you think?

  8. added a commit that references this issue on Feb 8, 2021
    3be78fd
  9. kripken commented on Feb 8, 2021

    @kripken
    Member

    @tlively you merged the PR that closed this. Personally I'd prefer the other option, but I don't feel strongly.

    But as mentioned above I think that PR plus fixing validation in wasm-dis will lead to a bad result. That is, right now wasm-dis can disassembly anything because it does not validate. If we make it validate, then people will need to start to write wasm-dis -all on modules without a feature section - which is most modules in the wild. Or am I missing something?

  10. reopened this on Feb 8, 2021
  11. tlively commented on Feb 8, 2021

    @tlively
    Member

    Oops, sorry about that. I hadn't seen your most recent comment. I agree that wasm-dis should be able to disassemble any module by default, regardless of the features used. My mental model for the feature flags was that they control how the output is printed in cases like call_indirect, not that they should limit what modules wasm-dis accepts as input. I think we can avoid the bad outcome you described by continuing to have wasm-dis not run validation. What do you think about that solution? Is it important that we start validating in wasm-dis?

  12. kripken commented on Feb 8, 2021

    @kripken
    Member

    wasm-dis not validating is a bug, I think 😄 I guess we could redefine it as a feature (/workaround), but I suspect it will hurt us eventually when we are surprised to not get a validation error.

    I guess we can leave it alone for now, as the bug is quite old and has not been noticed until now. I opened #3556 to at least document the issue in the code.

  13. changed the title [-].fromBinary tests are always executed with MVP features[/-] [+]wasm-dis should run validation[/+] on Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions