wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

RFC: Use the target_features section to verify compatibility

Open lum1n0us opened this issue 4 months ago • 2 comments

The rough idea is to, at the very beginning of wasm loading, read the target_features section if present and compare its content with the current enabling feature flags. If they do not match, provide information to guide the user to recompile wasm modules or recompile iwasm and/or wamrc.

Since wasi-sdk (at least since version 25) generates the target_features section by default (without any additional options), this functionality is feasible.

Additionally, the current opcode verification will serve as assurance.

#  /opt/wabt-1.0.37/bin/wasm-objdump -j target_features -x 

Custom:
 - name: "target_features"
  - [+] bulk-memory
  - [+] bulk-memory-opt
  - [+] call-indirect-overlong
  - [+] extended-const
  - [+] multivalue
  - [+] mutable-globals
  - [+] nontrapping-fptoint
  - [+] reference-types
  - [+] sign-ext

lum1n0us avatar Aug 19 '25 07:08 lum1n0us

i feel it's an abuse for a runtime to change its behavior on target_features.

when we couldn't load a module, we might be able to provide a bit more useful information using target_features. but i don't think target_features should be treated as an authoritative information.

yamt avatar Aug 19 '25 08:08 yamt

Hmm..., the initial idea doesn't include using target_feature as a form of command line options, like --enable-gc or --enable-ref-type.

It is only intended as a checker to ensure that if target_feature highlights a feature, the feature is enabled during compilation by the related flags. It is somewhat similar to the feature flags of AOT.

lum1n0us avatar Aug 19 '25 10:08 lum1n0us