Skip to content

How to handle ref.null 0? #4542

@lum1n0us

Description

@lum1n0us

ref.null 0 is valid under the GC specification but invalid under the current specification(only allow externref and funcref). This means a Wasm runtime should report a validation error when loading a Wasm module that contains ref.null 0 if GC is not enabled. The same applies to wamrc.

But the latest version of wamrc will not report a validation error. This is because:

  • By design, unlike iwasm, wamrc is a full-feature component that uses execution switchers (command line options) instead of compilation flags to configure all supported features. So GC is always-on in wamrc.
  • wamrc will validate the ref.null opcode in WebAssembly modules under the GC specification by always enabling the compilation flag WASM_ENABLE_GC. Although there is a --enable-gc option in wamrc's command line options which is able to disable gc during execution, this option is not passed to the WebAssembly loader and is only used during and after AOT loading.
  • There should be an additional opcode validator in code generation (compilation) after WebAssembly loading in wamrc. However, in a specific case(WAMR JIT mode incorrectly outputs type_mismatch #4480), br 0 will skip all following opcodes, including ref.null 0.

In my opinion, there are still three options available to handle this ref.null 0.
a. pass command line options of wamrc to wasm loader. like an extra parameter in wasm_runtime_load().
b. add opcode validation in aot_validate_wasm()
c. in CMakeLists.txt of wamrc, make WASM_ENABLE_GC configurable.

From my perspective, options a. and b. are too burdensome since ref.null is the only opcode that currently requires extra attention. I prefer to use option c.

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