Skip to content

Commit 97d2ffd

Browse files
kripkenradekdoulik
authored andcommitted
Fuzzer: Allow using initial content with V8 (WebAssembly#6327)
One problem was that spec testcases had exports with names that are not valid to write as JS exports.name. For example an export with a - in the name would end up as exports.foo-bar etc. Since WebAssembly#6310 that is fixed as we do not emit such JS (we use the generic fuzz_shell.js script which iterates over the keys in exports with exports[name]). Also fix a few trivial fuzzer issues that initial content uncovered: - Ignore a wat file with invalid utf-8. - Print string literals in the same way from JS as from C++. - Enable the stringref flag in V8. - Remove tag imports (the same as we do for global and function and other imports).
1 parent d272c1f commit 97d2ffd

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

scripts/fuzz_opt.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ def is_git_repo():
311311
'exception-handling.wast',
312312
'translate-eh-old-to-new.wast',
313313
'rse-eh.wast',
314+
# Non-UTF8 strings trap in V8
315+
'string-lowering.wast',
314316
]
315317

316318

@@ -756,10 +758,7 @@ def run(self, wasm, extra_d8_flags=[]):
756758
return run_vm([shared.V8, FUZZ_SHELL_JS] + shared.V8_OPTS + extra_d8_flags + ['--', wasm])
757759

758760
def can_run(self, wasm):
759-
# INITIAL_CONTENT is disallowed because some initial spec testcases
760-
# have names that require mangling, see
761-
# https://github.com/WebAssembly/binaryen/pull/3216
762-
return not INITIAL_CONTENTS
761+
return True
763762

764763
def can_compare_to_self(self):
765764
# With nans, VM differences can confuse us, so only very simple VMs

scripts/fuzz_shell.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ function printed(x, y) {
4747
// JS has just one null. Print that out rather than typeof null which is
4848
// 'object', below.
4949
return 'null';
50-
} else if (typeof x !== 'number' && typeof x !== 'string') {
50+
} else if (typeof x === 'string') {
51+
// Emit a string in the same format as the binaryen interpreter.
52+
return 'string("' + x + '")';
53+
} else if (typeof x !== 'number') {
5154
// Something that is not a number or string, like a reference. We can't
5255
// print a reference because it could look different after opts - imagine
5356
// that a function gets renamed internally (that is, the problem is that

scripts/test/shared.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ def has_shell_timeout():
260260
'--experimental-wasm-typed-funcref',
261261
'--experimental-wasm-memory64',
262262
'--experimental-wasm-extended-const',
263+
'--experimental-wasm-stringref',
263264
'--wasm-final-types',
264265
]
265266

src/tools/fuzzing/fuzzing.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,15 @@ void TranslateToFuzzReader::setupGlobals() {
433433
}
434434

435435
void TranslateToFuzzReader::setupTags() {
436+
// As in modifyInitialFunctions(), we can't allow tag imports as it would trap
437+
// when the fuzzing infrastructure doesn't know what to provide.
438+
for (auto& tag : wasm.tags) {
439+
if (tag->imported()) {
440+
tag->module = tag->base = Name();
441+
}
442+
}
443+
444+
// Add some random tags.
436445
Index num = upTo(3);
437446
for (size_t i = 0; i < num; i++) {
438447
addTag();

0 commit comments

Comments
 (0)