Scroll to navigation

WASM-REDUCE(1) User Commands WASM-REDUCE(1)

NAME

wasm-reduce - Reduce a wasm file to a smaller one with the same behavior on a given command.

DESCRIPTION

================================================================================ wasm-reduce INFILE

Reduce a wasm file to a smaller one with the same behavior on a given command.

Typical usage:

wasm-reduce orig.wasm '--command=bash a.sh' --test t.wasm --working w.wasm

The original file orig.wasm is where we begin. We then repeatedly test a small reduction of it by writing that modification to the 'test file' (specified by '--test'), and we run the command, in this example 'bash a.sh'. That command should use the test file (and not the original file or any other one). Whenever the reduction works, we write that new smaller file to the 'working file' (specified by '--working'). The reduction 'works' if it correctly preserves the behavior of the command on the original input, specifically, that it has the same stdout and the result return code. Each time reduction works we continue to reduce from that point (and each time it fails, we go back and try something else).

As mentioned above, the command should run on the test file. That is, the first thing that wasm-reduce does on the example above is, effectively,

cp orig.wasm t.wasm bash a.sh

In other words, it copies the original to the test file, and runs the command. Whatever the command does, we will preserve as we copy progressively smaller files to t.wasm. As we make progress, the smallest file will be written to the working file, w.wasm, and when reduction is done you will find the final result there.

Comparison to creduce:

1. creduce requires the command to return 0. wasm-reduce is often used to reduce

crashes, which have non-zero return codes, so it is natural to allow any return code. As mentioned above, we preserve the return code as we reduce.

2. creduce ignores stdout. wasm-reduce preserves stdout as it reduces, as part

of the principle of preserving the original behavior of the command (if your stdout varies in uninteresting ways, your command can be a script that runs the real command and captures stdout to /dev/null, or filters it).

3. creduce tramples the original input file as it reduces. wasm-reduce never

modifies the input (to avoid mistakes that cause data loss). Instead, when reductions work we write to the 'working file' as mentioned above, and the final reduction will be there.

4. creduce runs the command in a temp directory. That is safer in general, but

it is not how the original command ran, and in particular forces additional work if you have multiple files (which, for wasm-reduce, is common, e.g. if the testcase is a combination of JavaScript and wasm). wasm-reduce runs the command in the current directory (of course, your command can be a script that changes directory to anywhere else).

More documentation can be found at

https://github.com/WebAssembly/binaryen/wiki/Fuzzing#reducing

================================================================================

wasm-reduce options: --------------------

The command to run on the test, that we want to reduce while keeping the command's output identical. We look at the command's return code and stdout here (TODO: stderr), and we reduce while keeping those unchanged.
Test file (this will be written to test, the given command should read it when we call it)
Working file (this will contain the current good state while doing temporary computations, and will contain the final best result at the end)
binaryen binaries location (bin/ directory)
Emit intermediate files as text, instead of binary (also make sure the test and working files have a .wat or .wast suffix)
Avoid nans when reducing
Verbose output mode
Keep debug info in binaries
Force the reduction attempt, ignoring problems that imply it is unlikely to succeed
A timeout to apply to each execution of the command, in seconds (default: 2)
Extra commandline flags to pass to wasm-opt while reducing. (default: --enable-all)
Save all intermediate working files, as $WORKING.0, .1, .2 etc

Tool options: -------------

Disable all non-MVP features
Enable all features
(deprecated - this flag does nothing)
Emit less verbose output and hide trivial warnings.
Parse wast files as Poppy IR for testing purposes.
Emit module names, even if not emitting the rest of the names section.
Enable sign extension operations
Disable sign extension operations
Enable atomic operations
Disable atomic operations
Enable mutable globals
Disable mutable globals
Enable nontrapping float-to-int operations
Disable nontrapping float-to-int operations
Enable SIMD operations and types
Disable SIMD operations and types
Enable bulk memory operations
Disable bulk memory operations
Enable memory.copy and memory.fill
Disable memory.copy and memory.fill
Enable LEB encoding of call-indirect (Ignored for compatibility as it has no effect on Binaryen)
Disable LEB encoding of call-indirect (Ignored for compatibility as it has no effect on Binaryen)
Enable exception handling operations
Disable exception handling operations
Enable tail call operations
Disable tail call operations
Enable reference types
Disable reference types
Enable multivalue functions
Disable multivalue functions
Enable garbage collection
Disable garbage collection
Enable memory64
Disable memory64
Enable relaxed SIMD
Disable relaxed SIMD
Enable extended const expressions
Disable extended const expressions
Enable strings
Disable strings
Enable multimemory
Disable multimemory
Enable stack switching
Disable stack switching
Enable shared-everything threads
Disable shared-everything threads
Enable float 16 operations
Disable float 16 operations
Enable custom descriptors (RTTs) and exact references
Disable custom descriptors (RTTs) and exact references
Enable multibyte array loads and stores
Disable multibyte array loads and stores
Enable acquire/release atomic memory operations
Disable acquire/release atomic memory operations
Enable custom page sizes
Disable custom page sizes
Enable wide arithmetic
Disable wide arithmetic
Enable compact import section
Disable compact import section
Deprecated compatibility flag
Deprecated compatibility flag
Disables validation, assumes inputs are correct
An argument passed along to optimization passes being run. Must be in the form KEY@VALUE. If KEY is the name of a pass then it applies to the closest instance of that pass before us. If KEY is not the name of a pass then it is a global option that applies to all pass instances that read it.
Assume code outside of the module does not inspect or interact with GC and function references, even if they are passed out. The outside may hold on to them and pass them back in, but not inspect their contents or call them.
Preserve the order of types from the input (useful for debugging and testing)
generate StackIR during writing
optimize StackIR during writing
print StackIR during writing

General options: ----------------

Output version information and exit
Show this help message and exit
Print debug information to stderr
August 2026 wasm-reduce 131