summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-07-24 07:12:14 -0700
committerGitHub <noreply@github.com>2020-07-24 07:12:14 -0700
commit1f231c39e52eab712eda9bcbf540752b813b567d (patch)
treebb62be99536072fe917c47395c776d20224bcc63
parent0efd168824ac58abaf8ac484460a43241882dc93 (diff)
downloadbinaryen-1f231c39e52eab712eda9bcbf540752b813b567d.tar.gz
binaryen-1f231c39e52eab712eda9bcbf540752b813b567d.tar.bz2
binaryen-1f231c39e52eab712eda9bcbf540752b813b567d.zip
Wasm2c fuzz support: only emit a call to the hang limit function if present (#2977)
It may not be present while reducing a testcase, if the reducer removed it.
-rw-r--r--src/tools/wasm2c-wrapper.h9
-rw-r--r--test/unit/input/empty.wasmbin0 -> 8 bytes
-rw-r--r--test/unit/test_wasm2c.py21
3 files changed, 28 insertions, 2 deletions
diff --git a/src/tools/wasm2c-wrapper.h b/src/tools/wasm2c-wrapper.h
index 55eed0c35..b3205c6fe 100644
--- a/src/tools/wasm2c-wrapper.h
+++ b/src/tools/wasm2c-wrapper.h
@@ -85,9 +85,14 @@ int main(int argc, char** argv) {
// wasm traps, and emitting a single one helps compilation speed into wasm as
// compile times are O(size * num_setjmps).
for (size_t curr = 0;; curr++) {
- // Always call the hang limit initializer before each export.
+ )";
+ if (wasm.getExportOrNull("hangLimitInitializer")) {
+ ret += R"(
+ // If present, call the hang limit initializer before each export.
(*Z_hangLimitInitializerZ_vv)();
-
+)";
+ }
+ ret += R"(
// Prepare to call the export, so we can catch traps.
if (WASM_RT_SETJMP(g_jmp_buf) != 0) {
puts("exception!");
diff --git a/test/unit/input/empty.wasm b/test/unit/input/empty.wasm
new file mode 100644
index 000000000..d8fc92d02
--- /dev/null
+++ b/test/unit/input/empty.wasm
Binary files differ
diff --git a/test/unit/test_wasm2c.py b/test/unit/test_wasm2c.py
new file mode 100644
index 000000000..bcdab355b
--- /dev/null
+++ b/test/unit/test_wasm2c.py
@@ -0,0 +1,21 @@
+from scripts.test import shared
+from . import utils
+
+
+class Wasm2CTest(utils.BinaryenTestCase):
+ def test_wrapper(self):
+ # the wrapper C code should only call the hang limit initializer if
+ # that is present.
+ empty_wasm = self.input_path('empty.wasm')
+ args = [empty_wasm, '--emit-wasm2c-wrapper=output.c']
+ shared.run_process(shared.WASM_OPT + args)
+ with open('output.c') as f:
+ normal_output = f.read()
+ # running with ttf generates a new wasm for fuzzing, which always
+ # includes the hang limit initializer function
+ shared.run_process(shared.WASM_OPT + args + ['-ttf'])
+ with open('output.c') as f:
+ ttf_output = f.read()
+ hang_limit_name = 'hangLimitInitializer'
+ self.assertIn(hang_limit_name, ttf_output)
+ self.assertNotIn(hang_limit_name, normal_output)