WASM-REDUCE(1)

๐Ÿ“ฆ
version 131 ยท 3 versions
, in ubuntu stonking

โœจ NAME โœจ

wasm-reduce โ€” reduce a wasm file to a smaller one with the same behavior on a given command ๐Ÿ’ซ

okay bestie, we're doing this. this is the manual page for wasm-reduce, from the User Commands section, and it's giving "shrink the wasm, keep the vibe exactly the same." no cap. ๐Ÿ’…


๐ŸŽ€ DESCRIPTION ๐ŸŽ€

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

Reduce a wasm file to a smaller one with the same behavior on a given command. That's literally the whole job. Iconic.

So the typical usage is this, and I want you to read it with me:

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

Here's the tea ๐Ÿต: orig.wasm is the original file โ€” that's where we start, our main character. Then we repeatedly test a small reduction of it by writing that modification to the 'test file' (that's the one you give with --test), and then we run the command โ€” in this example, bash a.sh. And hello, important: that command should use the test file, and not the original file or any other one, bestie. That's the whole contract.

Whenever a reduction works, we write that new smaller file to the 'working file' (the one you specify with --working). And what counts as "works"? A reduction works if it correctly preserves the behavior of the command on the original input โ€” specifically โšก that it has the same stdout and the same return code. Every time reduction works we keep reducing from that point (and every time it fails, we go back and try something else). It's giving persistence. ๐Ÿฆ‹

So, as mentioned above, the command should run on the test file. Which means the first thing wasm-reduce does in 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 gets written to the working file, w.wasm, and when reduction is done you will find the final result there. Your little baby wasm. ๐Ÿฅน

๐Ÿ†š 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 ๐Ÿ’…

  • --command, -cmd โ€” 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, -t โ€” Test file (this will be written to test, the given command should read it when we call it). ๐Ÿงช
  • --working, -w โ€” Working file (this will contain the current good state while doing temporary computations, and will contain the final best result at the end). ๐Ÿ’พ
  • --binaries, -b โ€” binaryen binaries location (bin/ directory). ๐Ÿ“‚
  • --text, -S โ€” Emit intermediate files as text, instead of binary (also make sure the test and working files have a .wat or .wast suffix). ๐Ÿ“
  • --denan โ€” Avoid nans when reducing. ๐Ÿšซ๐Ÿ”ข
  • --verbose, -v โ€” Verbose output mode. ๐Ÿ—ฃ๏ธ
  • --debugInfo, -g โ€” Keep debug info in binaries. ๐Ÿ›
  • --force, -f โ€” Force the reduction attempt, ignoring problems that imply it is unlikely to succeed. ๐Ÿ˜ค
  • --timeout, -to โ€” A timeout to apply to each execution of the command, in seconds (default: 2). โฐ
  • --extra-flags, -ef โ€” Extra commandline flags to pass to wasm-opt while reducing. (default: --enable-all) ๐Ÿšฉ
  • --save-all-working, -saw โ€” Save all intermediate working files, as $WORKING.0, .1, .2 etc. ๐Ÿ“š

๐Ÿงฐ Tool options ๐Ÿงฐ

  • --mvp-features, -mvp โ€” Disable all non-MVP features. ๐Ÿ”’
  • --all-features, -all โ€” Enable all features. ๐Ÿ”“
  • --detect-features โ€” (deprecated - this flag does nothing) ๐Ÿ’€
  • --quiet, -q โ€” Emit less verbose output and hide trivial warnings. ๐Ÿคซ
  • --experimental-poppy โ€” Parse wast files as Poppy IR for testing purposes. ๐ŸŒบ
  • --emit-module-names โ€” Emit module names, even if not emitting the rest of the names section. ๐Ÿท๏ธ
  • --enable-sign-ext โ€” Enable sign extension operations. โž•
  • --disable-sign-ext โ€” Disable sign extension operations. โž–
  • --enable-threads โ€” Enable atomic operations. ๐Ÿงต
  • --disable-threads โ€” Disable atomic operations. โœ‚๏ธ
  • --enable-mutable-globals โ€” Enable mutable globals. ๐ŸŒ
  • --disable-mutable-globals โ€” Disable mutable globals. ๐Ÿšซ
  • --enable-nontrapping-float-to-int โ€” Enable nontrapping float-to-int operations. ๐Ÿ”„
  • --disable-nontrapping-float-to-int โ€” Disable nontrapping float-to-int operations. ๐Ÿ›‘
  • --enable-simd โ€” Enable SIMD operations and types. ๐Ÿงฎ
  • --disable-simd โ€” Disable SIMD operations and types. โŒ
  • --enable-bulk-memory โ€” Enable bulk memory operations. ๐Ÿง 
  • --disable-bulk-memory โ€” Disable bulk memory operations. ๐Ÿšท
  • --enable-bulk-memory-opt โ€” Enable memory.copy and memory.fill. ๐Ÿ“ฆ
  • --disable-bulk-memory-opt โ€” Disable memory.copy and memory.fill. ๐Ÿ“ญ
  • --enable-call-indirect-overlong โ€” Enable LEB encoding of call-indirect (Ignored for compatibility as it has no effect on Binaryen). ๐Ÿคท
  • --disable-call-indirect-overlong โ€” Disable LEB encoding of call-indirect (Ignored for compatibility as it has no effect on Binaryen). ๐Ÿ™ƒ
  • --enable-exception-handling โ€” Enable exception handling operations. ๐Ÿšจ
  • --disable-exception-handling โ€” Disable exception handling operations. ๐Ÿงฏ
  • --enable-tail-call โ€” Enable tail call operations. ๐Ÿˆ
  • --disable-tail-call โ€” Disable tail call operations. ๐Ÿšซ๐Ÿˆ
  • --enable-reference-types โ€” Enable reference types. ๐Ÿ”—
  • --disable-reference-types โ€” Disable reference types. โ›“๏ธ๐Ÿ’ฅ
  • --enable-multivalue โ€” Enable multivalue functions. ๐ŸŽ
  • --disable-multivalue โ€” Disable multivalue functions. ๐Ÿ“ฆ
  • --enable-gc โ€” Enable garbage collection. ๐Ÿ—‘๏ธ
  • --disable-gc โ€” Disable garbage collection. ๐Ÿงน
  • --enable-memory64 โ€” Enable memory64. ๐Ÿ’ฝ
  • --disable-memory64 โ€” Disable memory64. ๐Ÿ’พ
  • --enable-relaxed-simd โ€” Enable relaxed SIMD. ๐Ÿ˜Œ
  • --disable-relaxed-simd โ€” Disable relaxed SIMD. ๐Ÿ˜ฌ
  • --enable-extended-const โ€” Enable extended const expressions. ๐Ÿงฎ
  • --disable-extended-const โ€” Disable extended const expressions. ๐Ÿงพ
  • --enable-strings โ€” Enable strings. ๐Ÿงถ
  • --disable-strings โ€” Disable strings. โœ‚๏ธ
  • --enable-multimemory โ€” Enable multimemory. ๐Ÿ—‚๏ธ
  • --disable-multimemory โ€” Disable multimemory. ๐Ÿ“
  • --enable-stack-switching โ€” Enable stack switching. ๐Ÿ”€
  • --disable-stack-switching โ€” Disable stack switching. ๐Ÿ›‘
  • --enable-shared-everything โ€” Enable shared-everything threads. ๐Ÿค
  • --disable-shared-everything โ€” Disable shared-everything threads. ๐Ÿ™…
  • --enable-fp16 โ€” Enable float 16 operations. 1๏ธโƒฃ6๏ธโƒฃ
  • --disable-fp16 โ€” Disable float 16 operations. ๐Ÿšซ
  • --enable-custom-descriptors โ€” Enable custom descriptors (RTTs) and exact references. ๐Ÿท๏ธ
  • --disable-custom-descriptors โ€” Disable custom descriptors (RTTs) and exact references. ๐Ÿšฏ
  • --enable-multibyte โ€” Enable multibyte array loads and stores. ๐Ÿ”ข
  • --disable-multibyte โ€” Disable multibyte array loads and stores. ๐Ÿšฑ
  • --enable-relaxed-atomics โ€” Enable acquire/release atomic memory operations. โš›๏ธ
  • --disable-relaxed-atomics โ€” Disable acquire/release atomic memory operations. ๐Ÿ”‹
  • --enable-custom-page-sizes โ€” Enable custom page sizes. ๐Ÿ“„
  • --disable-custom-page-sizes โ€” Disable custom page sizes. ๐Ÿ“ƒ
  • --enable-wide-arithmetic โ€” Enable wide arithmetic. โž—
  • --disable-wide-arithmetic โ€” Disable wide arithmetic. ๐Ÿงฎ
  • --enable-compact-imports โ€” Enable compact import section. ๐Ÿ—œ๏ธ
  • --disable-compact-imports โ€” Disable compact import section. ๐Ÿ”Ž
  • --enable-typed-function-references โ€” Deprecated compatibility flag. ๐Ÿ•ธ๏ธ
  • --disable-typed-function-references โ€” Deprecated compatibility flag. ๐Ÿ•ธ๏ธ
  • --no-validation, -n โ€” Disables validation, assumes inputs are correct. ๐Ÿ˜ณ
  • --pass-arg, -pa โ€” 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. ๐Ÿ”‘
  • --closed-world, -cw โ€” 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-type-order โ€” Preserve the order of types from the input (useful for debugging and testing). ๐Ÿ”ค
  • --generate-stack-ir โ€” generate StackIR during writing. ๐Ÿ—๏ธ
  • --optimize-stack-ir โ€” optimize StackIR during writing. โšก
  • --print-stack-ir โ€” print StackIR during writing. ๐Ÿ–จ๏ธ

๐Ÿ General options ๐Ÿ

  • --version โ€” Output version information and exit. ๐Ÿ“Œ
  • --help, -h โ€” Show this help message and exit. ๐Ÿ†˜
  • --debug, -d โ€” Print debug information to stderr. ๐Ÿž

friendly reminder bestie: this whole page came from wasm-reduce 131, dated August 2026. ๐Ÿซถ go forth and shrink responsibly, mwah ๐Ÿ’–๐Ÿฆ‹โœจ
๐Ÿ“ฆ where this page comes from