wasabi
wasabi copied to clipboard
Reuse inserted locals for stack value duplication
Currently, Wasabi inserts a fresh local (quite primitively) for every stack value it needs to duplicate. This causes some binaries with large functions to contain tons of locals after instrumentation. E.g., binary 9b3a05f8927a35b011f23eae30c9f11f8dcae299f3f400d7960a8aa20cec7a27.wasm
from WasmBench contains a function with >50k locals after instrumentation, which trips wasm-validate
from WABT with the error
error: function local count exceeds maximum value
A workaround is to optimize the instrumented files with wasm-opt
from Binaryen, i.e. run wasm-opt -Os <instrumented.wasm> -o <instrumented-smaller.wasm>
It's not the best implementation but if anyone wants some look at my band-aid fix at this issue look at this commit https://github.com/jakobgetz/wasabi/commit/adede4588ebed6d40af15b29307855696c228111.
I would prefer to not modify the wasabi_wasm
AST for the use-case inside Wasabi's instrumentation (i.e., I would prefer to pull out temp_local_map
from ast.rs
into add_hoooks/mod.rs
). If you want to do that, feel free to submit a PR, but otherwise let's just leave this issue open, until I find the time to fix it properly.
I agree about keeping the issue open! I just left the comment as a pointer to some potential user who needs quick and dirty fix.