RFC: Use the target_features section to verify compatibility
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
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.
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.