Skip to content

Commit 35c16b9

Browse files
committed
add a flag
1 parent 703d8db commit 35c16b9

3 files changed

Lines changed: 49 additions & 10 deletions

File tree

scripts/fuzz_opt.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,12 @@ def optimize(name):
16191619

16201620
# get the output from the split modules, linking them using JS
16211621
# TODO run liftoff/turboshaft/etc.
1622-
linked_output = run_d8_wasm(primary, args=[secondary, exports_to_call])
1622+
args = [
1623+
secondary,
1624+
exports_to_call,
1625+
'--fuzz-split',
1626+
]
1627+
linked_output = run_d8_wasm(primary, args=args)
16231628
linked_output = fix_output(linked_output)
16241629

16251630
# see D8.can_compare_to_self: we cannot compare optimized outputs if

scripts/fuzz_shell.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,25 @@ if (!binary) {
4747
// passed a final parameter in the form of "exports:X,Y,Z" then we call
4848
// specifically the exports X, Y, and Z.
4949
var exportsToCall;
50-
if (argv.length > 0 && argv[argv.length - 1].startsWith('exports:')) {
51-
exportsToCall = argv[argv.length - 1].substr('exports:'.length).split(',');
52-
argv.pop();
50+
51+
// Passing --fuzz-split makes us treat the two input files as split off
52+
// from a single one, and we will run them as that single file (ignoring extra
53+
// exports from the second one, and from wasm-split itself). This allows us to
54+
// get the same behavior from split modules as before the split.
55+
var fuzzSplit = false;
56+
57+
while (argv.length > 0) {
58+
var last = argv[argv.length - 1];
59+
if (last.startsWith('exports:')) {
60+
exportsToCall = last.substr('exports:'.length).split(',');
61+
argv.pop();
62+
continue;
63+
} else if (last.startsWith('--fuzz-split')) {
64+
fuzzSplit = true;
65+
argv.pop();
66+
continue;
67+
}
68+
break;
5369
}
5470

5571
// If a second parameter is given, it is a second binary that we will link in
@@ -420,7 +436,7 @@ if (secondBinary) {
420436
// Compile and instantiate a wasm file. Receives the binary to build, and
421437
// whether it is the second one.
422438
function build(binary, second) {
423-
if (second) {
439+
if (fuzzSplit && second) {
424440
assert(secondBinary);
425441
// Provide the primary module's exports to the secondary.
426442
imports['primary'] = exports;
@@ -437,10 +453,10 @@ function build(binary, second) {
437453
}
438454

439455
// Do not add the second instance's exports to the list, as that would be
440-
// noticeable by calls to call-export-*. When fuzzing, we want the original
441-
// module's exports to be provided from the primary module, and it is the only
442-
// interface to the outside.
443-
if (second) {
456+
// noticeable by calls to call-export-*. When fuzzing wasm-split, we want the
457+
// original module's exports to be provided from the primary module, and it is
458+
// the only interface to the outside.
459+
if (fuzzSplit && second) {
444460
return;
445461
}
446462

@@ -462,7 +478,7 @@ function build(binary, second) {
462478
value = wrapExportForJSPI(value);
463479
exports[key] = value;
464480

465-
if (secondBinary && key.startsWith('__fuzz_split_')) {
481+
if (fuzzSplit && key.startsWith('__fuzz_split_')) {
466482
// We are fuzzing wasm-split, and this is a new export generated by
467483
// wasm-split. Do not note these exports as callable from call-export*,
468484
// as they do not match the original pre-split module.

test/lit/node/fuzz_shell_second.wast

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
(func $first (export "first") (result i32)
66
(i32.const 42)
77
)
8+
9+
(func $split (export "__fuzz_split_func") (result i32)
10+
(i32.const 999)
11+
)
812
)
913

1014
;; Build both files to binary.
@@ -18,6 +22,8 @@
1822
;;
1923
;; CHECK: [fuzz-exec] calling first
2024
;; CHECK: [fuzz-exec] note result: first => 42
25+
;; CHECK: [fuzz-exec] calling __fuzz_split_func
26+
;; CHECK: [fuzz-exec] note result: __fuzz_split_func => 999
2127
;; CHECK: [fuzz-exec] calling second
2228
;; CHECK: [fuzz-exec] note result: second => 1337
2329

@@ -29,4 +35,16 @@
2935
;; REVERSE: [fuzz-exec] note result: second => 1337
3036
;; REVERSE: [fuzz-exec] calling first
3137
;; REVERSE: [fuzz-exec] note result: first => 42
38+
;; REVERSE: [fuzz-exec] calling __fuzz_split_func
39+
;; REVERSE: [fuzz-exec] note result: __fuzz_split_func => 999
40+
41+
;; Run with --fuzz-split, which does not run exports from the second one,
42+
;; and also ignores exports starting with "__fuzz_split_"
43+
;;
44+
;; RUN: node %S/../../../scripts/fuzz_shell.js %t.wasm %t.second.wasm --fuzz-split | filecheck %s --check-prefix=WASM_SPLIT
45+
;;
46+
;; WASM_SPLIT: [fuzz-exec] calling first
47+
;; WASM_SPLIT: [fuzz-exec] note result: first => 42
48+
;; WASM_SPLIT-NOT: [fuzz-exec] calling second
49+
;; WASM_SPLIT-NOT: [fuzz-exec] calling __fuzz_split_func
3250

0 commit comments

Comments
 (0)