@@ -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.
4949var 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.
422438function 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.
0 commit comments