Skip to content

Commit 666c9df

Browse files
authored
Fuzzer: Add invokes for initial functions (#7198)
This adds more of a chance to call code from initial content. This includes invokes of function imports, which we didn't do before.
1 parent 3b838f7 commit 666c9df

4 files changed

Lines changed: 108 additions & 94 deletions

File tree

src/tools/fuzzing/fuzzing.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,20 @@ void TranslateToFuzzReader::modifyInitialFunctions() {
16481648
// them.
16491649
}
16501650
}
1651+
1652+
// Add invocations, which can help execute the code here even if the function
1653+
// was not exported (or was exported but with a signature that traps
1654+
// immediately, like receiving a non-nullable ref, that the fuzzer can't
1655+
// provide from JS). Note we need to use a temp vector for iteration, as
1656+
// addInvocations modifies wasm.functions.
1657+
std::vector<Function*> funcs;
1658+
for (auto& func : wasm.functions) {
1659+
funcs.push_back(func.get());
1660+
}
1661+
for (auto* func : funcs) {
1662+
addInvocations(func);
1663+
}
1664+
16511665
// Remove a start function - the fuzzing harness expects code to run only
16521666
// from exports.
16531667
wasm.start = Name();
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
Metrics
22
total
3-
[exports] : 46
4-
[funcs] : 68
3+
[exports] : 65
4+
[funcs] : 85
55
[globals] : 18
66
[imports] : 4
77
[memories] : 1
88
[memory-data] : 24
9-
[table-data] : 22
9+
[table-data] : 24
1010
[tables] : 1
1111
[tags] : 0
12-
[total] : 9465
13-
[vars] : 215
14-
Binary : 671
15-
Block : 1531
16-
Break : 370
17-
Call : 366
18-
CallIndirect : 67
19-
Const : 1478
20-
Drop : 111
21-
GlobalGet : 766
22-
GlobalSet : 558
23-
If : 514
24-
Load : 173
25-
LocalGet : 729
26-
LocalSet : 550
27-
Loop : 202
28-
Nop : 133
29-
RefFunc : 22
30-
Return : 99
31-
Select : 84
32-
Store : 83
33-
Switch : 2
34-
Unary : 682
35-
Unreachable : 274
12+
[total] : 8396
13+
[vars] : 239
14+
Binary : 573
15+
Block : 1420
16+
Break : 276
17+
Call : 382
18+
CallIndirect : 56
19+
Const : 1258
20+
Drop : 124
21+
GlobalGet : 731
22+
GlobalSet : 531
23+
If : 468
24+
Load : 129
25+
LocalGet : 578
26+
LocalSet : 422
27+
Loop : 173
28+
Nop : 134
29+
RefFunc : 24
30+
Return : 122
31+
Select : 58
32+
Store : 57
33+
Switch : 6
34+
Unary : 605
35+
Unreachable : 269
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
Metrics
22
total
3-
[exports] : 43
4-
[funcs] : 56
3+
[exports] : 84
4+
[funcs] : 112
55
[globals] : 17
66
[imports] : 4
77
[memories] : 1
88
[memory-data] : 11
9-
[table-data] : 16
9+
[table-data] : 36
1010
[tables] : 1
1111
[tags] : 0
12-
[total] : 10611
13-
[vars] : 184
14-
Binary : 754
15-
Block : 1699
16-
Break : 397
17-
Call : 325
18-
CallIndirect : 112
19-
Const : 1783
20-
Drop : 101
21-
GlobalGet : 869
22-
GlobalSet : 657
23-
If : 549
24-
Load : 195
25-
LocalGet : 893
26-
LocalSet : 609
27-
Loop : 251
28-
Nop : 123
29-
RefFunc : 16
30-
Return : 78
31-
Select : 74
32-
Store : 84
33-
Switch : 3
34-
Unary : 730
35-
Unreachable : 309
12+
[total] : 7833
13+
[vars] : 292
14+
Binary : 578
15+
Block : 1340
16+
Break : 204
17+
Call : 414
18+
CallIndirect : 35
19+
Const : 1256
20+
Drop : 107
21+
GlobalGet : 698
22+
GlobalSet : 535
23+
If : 418
24+
Load : 134
25+
LocalGet : 502
26+
LocalSet : 331
27+
Loop : 149
28+
Nop : 87
29+
RefFunc : 36
30+
Return : 103
31+
Select : 49
32+
Store : 70
33+
Switch : 6
34+
Unary : 508
35+
Unreachable : 273
Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
Metrics
22
total
3-
[exports] : 3
4-
[funcs] : 3
3+
[exports] : 10
4+
[funcs] : 9
55
[globals] : 4
66
[imports] : 8
77
[memories] : 1
88
[memory-data] : 112
99
[table-data] : 0
1010
[tables] : 1
1111
[tags] : 1
12-
[total] : 630
13-
[vars] : 23
14-
ArrayNewFixed : 3
15-
AtomicCmpxchg : 1
16-
AtomicFence : 1
17-
AtomicNotify : 1
18-
Binary : 63
19-
Block : 60
20-
BrOn : 3
21-
Break : 8
22-
Call : 4
23-
CallRef : 3
24-
Const : 129
25-
DataDrop : 1
26-
Drop : 8
27-
GlobalGet : 21
28-
GlobalSet : 20
29-
I31Get : 1
30-
If : 12
12+
[total] : 553
13+
[vars] : 38
14+
ArrayCopy : 2
15+
ArrayLen : 4
16+
ArrayNew : 1
17+
ArrayNewFixed : 7
18+
Binary : 69
19+
Block : 55
20+
BrOn : 1
21+
Break : 1
22+
Call : 23
23+
Const : 107
24+
Drop : 7
25+
GlobalGet : 19
26+
GlobalSet : 18
27+
If : 17
3128
Load : 17
32-
LocalGet : 74
33-
LocalSet : 52
34-
Loop : 8
35-
MemoryFill : 1
36-
Nop : 4
37-
RefAs : 19
38-
RefFunc : 26
39-
RefI31 : 1
40-
RefIsNull : 1
41-
RefNull : 11
42-
Return : 2
43-
Select : 5
29+
LocalGet : 66
30+
LocalSet : 39
31+
Loop : 1
32+
Nop : 3
33+
RefAs : 13
34+
RefFunc : 9
35+
RefI31 : 2
36+
RefIsNull : 2
37+
RefNull : 7
38+
RefTest : 1
39+
Return : 5
40+
SIMDReplace : 1
41+
Select : 3
42+
Store : 1
43+
StringConst : 3
4444
StringEncode : 1
45-
StructGet : 3
46-
StructNew : 26
47-
Try : 1
48-
TryTable : 6
45+
StringMeasure : 1
46+
StructGet : 1
47+
StructNew : 15
48+
StructSet : 2
4949
TupleExtract : 1
50-
TupleMake : 2
51-
Unary : 20
52-
Unreachable : 10
50+
TupleMake : 3
51+
Unary : 16
52+
Unreachable : 9

0 commit comments

Comments
 (0)