summaryrefslogtreecommitdiff
path: root/src/tools/wasm-opt.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-04-22 12:11:46 -0700
committerGitHub <noreply@github.com>2020-04-22 12:11:46 -0700
commit35a36b15e1bf16b78a6f3e174543681748295e81 (patch)
tree1a5dd5af79b064b73c9475948f077cdc93f47e49 /src/tools/wasm-opt.cpp
parentd8b414d22b032efc87dbceb50abef8bce5ce8266 (diff)
downloadbinaryen-35a36b15e1bf16b78a6f3e174543681748295e81.tar.gz
binaryen-35a36b15e1bf16b78a6f3e174543681748295e81.tar.bz2
binaryen-35a36b15e1bf16b78a6f3e174543681748295e81.zip
[fuzzing] wasm2c integration (#2772)
This adds support for fuzzing with wabt's wasm2c that @binji wrote. Basically we compile the wasm to C, then compile the C to a native executable with a custom main() to wrap around it. The executable should then print exactly the same as that wasm when run in either the binaryen interpreter or in a JS VM with our wrapper JS for that wasm. In other words, compiling the wasm to C is another way to run that wasm. The main reasons I want this are to fuzz wasm2c itself, and to have another option for fuzzing emcc. For the latter, we do fuzz wasm-opt quite a lot, but that doesn't fuzz the non-wasm-opt parts of emcc. And using wasm2c for that is nice since the starting point is always a wasm file, which means we can use tools like wasm-reduce and so forth, which can be integrated with this fuzzer. This also: Refactors the fuzzer harness a little to make it easier to add more "VMs" to run wasms in. Do not autoreduce when re-running a testcase, which I hit while developing this.
Diffstat (limited to 'src/tools/wasm-opt.cpp')
-rw-r--r--src/tools/wasm-opt.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/tools/wasm-opt.cpp b/src/tools/wasm-opt.cpp
index c4443bde4..6fd3b7c8d 100644
--- a/src/tools/wasm-opt.cpp
+++ b/src/tools/wasm-opt.cpp
@@ -37,6 +37,7 @@
#include "wasm-printing.h"
#include "wasm-s-parser.h"
#include "wasm-validator.h"
+#include "wasm2c-wrapper.h"
#define DEBUG_TYPE "opt"
@@ -87,6 +88,7 @@ int main(int argc, const char* argv[]) {
bool fuzzOOB = true;
std::string emitJSWrapper;
std::string emitSpecWrapper;
+ std::string emitWasm2CWrapper;
std::string inputSourceMapFilename;
std::string outputSourceMapFilename;
std::string outputSourceMapUrl;
@@ -185,6 +187,14 @@ int main(int argc, const char* argv[]) {
[&](Options* o, const std::string& arguments) {
emitSpecWrapper = arguments;
})
+ .add("--emit-wasm2c-wrapper",
+ "-esw",
+ "Emit a C wrapper file that can run the wasm after it is compiled "
+ "with wasm2c, useful for fuzzing",
+ Options::Arguments::One,
+ [&](Options* o, const std::string& arguments) {
+ emitWasm2CWrapper = arguments;
+ })
.add("--input-source-map",
"-ism",
"Consume source map from the specified file",
@@ -293,13 +303,18 @@ int main(int argc, const char* argv[]) {
outfile << generateJSWrapper(wasm);
outfile.close();
}
-
if (emitSpecWrapper.size() > 0) {
std::ofstream outfile;
outfile.open(emitSpecWrapper, std::ofstream::out);
outfile << generateSpecWrapper(wasm);
outfile.close();
}
+ if (emitWasm2CWrapper.size() > 0) {
+ std::ofstream outfile;
+ outfile.open(emitWasm2CWrapper, std::ofstream::out);
+ outfile << generateWasm2CWrapper(wasm);
+ outfile.close();
+ }
std::string firstOutput;