When one try to run wasm-reduce
on macOS machine, they will see something like this:
wasm-reduce -v -f \
--timeout=15 \
--command="./predicate.sh" \
--test=test.wasm \
--working=working.wasm \
~/Downloads/wasm-collection-master/misc-valid/cv-wasm.wasm
|wasm-reduce
|input: /Users/pepyakin/Downloads/wasm-collection-master/misc-valid/cv-wasm.wasm
|test: test.wasm
|working: working.wasm
|expected result:
[ProgramResult] code: 32512 stdout:
[/ProgramResult]
|checking that command has different behavior on invalid binary
|! running command on an invalid module should give different results
[ProgramResult] code: 32512 stdout:
[/ProgramResult]
Fatal: |! stopping, as it is very unlikely reduction can succeed (use -f to ignore this check)
It took quite some to figure out why my predicate script always returns status code 32512! : ) Here is my story:
It turns out that exit code 32512 is returned when command not found. As I found out later, it is not my predicate script is not found but the some timeout
command which is used by wasm-reduce to cap the execution time of the predicate script.
Unfortunately, macOS comes without installed timeout
. Fortunately, it can easily be installed with brew: brew install coreutils
.
Since macOS comes with some of coreutils programs installed, all these programs installed with names prepended by g
(e.g timeout
is gtimeout
). Luckily, these are just aliases and programs with original names are installed in /usr/local/opt/coreutils/libexec/gnubin
. So it is sufficient to just export new PATH
that will use coreutils
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
Next, after I try to launch reducing again, I stopped by this issue:
|checking that command has different behavior on invalid binary
|checking that command has expected behavior on canonicalized (read-written) binary
|! failed to read and write the binary
[ProgramResult] code: 32512 stdout:
[/ProgramResult]
So it seems that wasm-reduce
trying to launch wasm-opt
but for some reason can't.
That's weird since wasm-opt
is on my PATH
and wasm-reduce
is launched from the same directory where wasm-opt
is placed. Looking at the code,
I was able to see that wasm-reduce
is only trying to search wasm-opt
at BINARYEN_ROOT
.
So adding another export
might help:
export BINARYEN_ROOT=~/dev/etc/binaryen
After that was done, I was able to launch reducing! Hope this will help for future reducers (incl. me).
Here is my predicate.sh
for the reference:
#!/bin/bash
target/release/wasm-stack-height test.wasm result.wasm 2>&1 || exit 1
wasm2wat result.wasm 2>&1 || exit 2
For future reference with those trying to run
wasm-reduce
and running into similar errors,BINARYEN_ROOT
is no longer the correct solution to pass the correct directory.wasm-reduce
now provides a flag ---b /path/to/binaryen/bin
-- as an argument to provide the location.