Skip to content

Commit a827aa5

Browse files
authored
Fuzzer: Make --fuzz-preserve-imports-and-exports also preserve the start function (#8589)
The start may be needed for the ABI between the wasm and the outside. The point of preserve-imports-and-exports is to not break such ABIs (or at least have a chance of not doing so), so it doesn't seem like we need a new option here.
1 parent eb6c79d commit a827aa5

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

src/tools/fuzzing/fuzzing.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,8 +2381,12 @@ void TranslateToFuzzReader::modifyInitialFunctions() {
23812381
}
23822382

23832383
// Remove a start function - the fuzzing harness expects code to run only
2384-
// from exports.
2385-
wasm.start = Name();
2384+
// from exports. When preserving imports and exports, however, we need to
2385+
// keep any start method, as it may be important to keep the contract between
2386+
// the wasm and the outside.
2387+
if (!preserveImportsAndExports) {
2388+
wasm.start = Name();
2389+
}
23862390
}
23872391

23882392
void TranslateToFuzzReader::dropToLog(Function* func) {

src/tools/wasm-opt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ For more on how to optimize effectively, see
206206
[&](Options* o, const std::string& arguments) { fuzzOOB = false; })
207207
.add("--fuzz-preserve-imports-exports",
208208
"",
209-
"don't add imports and exports in -ttf mode",
209+
"don't add imports and exports in -ttf mode, and keep the start",
210210
WasmOptOption,
211211
Options::Arguments::Zero,
212212
[&](Options* o, const std::string& arguments) {

test/lit/fuzz-preserve-imports-exports.wast

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
;; PRESERVE: (import "a" "f" (func $ifunc
1919
;; PRESERVE: (import "a" "c" (tag $itag
2020

21+
;; The export is preserved.
2122
;; PRESERVE: (export "foo" (func $foo))
2223

24+
;; The start function is preserved.
25+
;; PRESERVE: (start $on_load)
26+
2327
;; And, without the flag, we do generate both imports and exports.
2428

2529
;; RUN: wasm-opt %s.dat --initial-fuzz=%s -all -ttf \
@@ -42,8 +46,14 @@
4246
(import "a" "e" (table $itable 10 20 funcref))
4347
(import "a" "f" (func $ifunc))
4448

49+
(start $on_load)
50+
4551
;; One existing export.
4652
(func $foo (export "foo")
4753
)
54+
55+
(func $on_load
56+
(call $ifunc)
57+
)
4858
)
4959

test/lit/help/wasm-opt.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
;; CHECK-NEXT: fuzzing
7171
;; CHECK-NEXT:
7272
;; CHECK-NEXT: --fuzz-preserve-imports-exports don't add imports and exports in
73-
;; CHECK-NEXT: -ttf mode
73+
;; CHECK-NEXT: -ttf mode, and keep the start
7474
;; CHECK-NEXT:
7575
;; CHECK-NEXT: --fuzz-import a module to use as an import in
7676
;; CHECK-NEXT: -ttf mode

0 commit comments

Comments
 (0)