Skip to content

Commit 927f898

Browse files
authored
[Custom Descriptors] Enable fuzzing (#7796)
Enable fuzz_opt.py and clusterfuzz to use initial contents containing custom descriptors types and instructions and to generate new types that use custom descriptors. Enable custom descriptors when running V8. Do not yet allow the fuzzer to use initial contents containing br_on_cast_desc instructions, since V8 still has some bugs around those. Also do not yet generate new uses of custom descriptors instructions that were not present in the initial contents.
1 parent 1866114 commit 927f898

File tree

5 files changed

+24
-35
lines changed

5 files changed

+24
-35
lines changed

scripts/bundle_clusterfuzz.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
'-all',
108108
'--disable-shared-everything',
109109
'--disable-fp16',
110-
'--disable-custom-descriptors',
111110
'--disable-strings',
112111
]
113112

scripts/clusterfuzz/run.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
# The V8 flags we put in the "fuzzer flags" files, which tell ClusterFuzz how to
3535
# run V8. By default we apply all staging flags.
36-
FUZZER_FLAGS = '--wasm-staging'
36+
FUZZER_FLAGS = '--wasm-staging --experimental-wasm-custom-descriptors'
3737

3838
# Optional V8 flags to add to FUZZER_FLAGS, some of the time.
3939
OPTIONAL_FUZZER_FLAGS = [
@@ -92,7 +92,6 @@
9292
'-all',
9393
'--disable-shared-everything',
9494
'--disable-fp16',
95-
'--disable-custom-descriptors',
9695
'--disable-strings',
9796
]
9897

scripts/test/fuzzing.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@
9696
# it removes unknown imports
9797
'string-lifting.wast',
9898
'string-lifting-custom-module.wast',
99+
# TODO: V8 still has bugs in br_on_cast_desc
100+
'custom-descriptors.wast',
101+
'abstract-type-refining-desc.wast',
102+
'abstract-type-refining-tnh-exact-casts.wast',
103+
'precompute-desc.wast',
104+
'remove-unused-brs-desc.wast',
105+
'vacuum-desc.wast',
106+
'br_on_cast_desc.wast',
99107
# TODO: fuzzer support for stack switching
100108
'stack_switching.wast',
101109
'stack_switching_contnew.wast',
@@ -113,30 +121,6 @@
113121
'vacuum-stack-switching.wast',
114122
'cont.wast',
115123
'cont_simple.wast',
116-
# TODO: fuzzer support for custom descriptors
117-
'remove-unused-module-elements-refs-descriptors.wast',
118-
'custom-descriptors.wast',
119-
'br_on_cast_desc.wast',
120-
'ref.get_desc.wast',
121-
'ref.cast_desc.wast',
122-
'struct.new-desc.wast',
123-
'remove-unused-types-descriptors.wast',
124-
'unsubtyping-desc.wast',
125-
'type-merging-desc.wast',
126-
'heap2local-desc.wast',
127-
'minimize-rec-groups-desc.wast',
128-
'precompute-desc.wast',
129-
'gc-desc.wast',
130-
'optimize-instructions-desc.wast',
131-
'gto-desc.wast',
132-
'type-ssa-desc.wast',
133-
'abstract-type-refining-desc.wast',
134-
'abstract-type-refining-tnh-exact-casts.wast',
135-
'remove-unused-brs-desc.wast',
136-
'vacuum-desc.wast',
137-
'j2cl-merge-itables-desc.wast',
138-
'heap-store-optimization-desc.wast',
139-
'unused-descriptors.wast',
140124
# TODO: fix split_wast() on tricky escaping situations like a string ending
141125
# in \\" (the " is not escaped - there is an escaped \ before it)
142126
'string-lifting-section.wast',

src/tools/fuzzing/fuzzing.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,8 @@ void TranslateToFuzzReader::setupHeapTypes() {
446446

447447
// For GC, also generate random types.
448448
if (wasm.features.hasGC()) {
449-
// TODO: Support custom descriptors.
450-
auto features = wasm.features;
451-
features.setCustomDescriptors(false);
452449
auto generator = HeapTypeGenerator::create(
453-
random, features, upTo(fuzzParams->MAX_NEW_GC_TYPES));
450+
random, wasm.features, upTo(fuzzParams->MAX_NEW_GC_TYPES));
454451
auto result = generator.builder.build();
455452
if (auto* err = result.getError()) {
456453
Fatal() << "Failed to build heap types: " << err->reason << " at index "
@@ -3655,7 +3652,11 @@ Expression* TranslateToFuzzReader::makeCompoundRef(Type type) {
36553652
nester.add(values.size() - 1);
36563653
}
36573654
}
3658-
return builder.makeStructNew(heapType, values);
3655+
Expression* descriptor = nullptr;
3656+
if (auto descType = heapType.getDescriptorType()) {
3657+
descriptor = make(Type(*descType, Nullable, Exact));
3658+
}
3659+
return builder.makeStructNew(heapType, values, descriptor);
36593660
}
36603661
case HeapTypeKind::Array: {
36613662
auto element = heapType.getArray().element;
@@ -5576,9 +5577,11 @@ Type TranslateToFuzzReader::getSubType(Type type) {
55765577
auto subType = Type(heapType, nullability, exactness);
55775578
// We don't want to emit lots of uninhabitable types like (ref none), so
55785579
// avoid them with high probability. Specifically, if the original type was
5579-
// inhabitable then return that; avoid adding more uninhabitability.
5580+
// inhabitable then return that; avoid adding more uninhabitability. We can
5581+
// never add new uninhabitability outside of functions, where we cannot
5582+
// use casts to generate something valid.
55805583
if (GCTypeUtils::isUninhabitable(subType) &&
5581-
!GCTypeUtils::isUninhabitable(type) && !oneIn(20)) {
5584+
!GCTypeUtils::isUninhabitable(type) && (!funcContext || !oneIn(20))) {
55825585
return type;
55835586
}
55845587
return subType;

test/unit/test_cluster_fuzz.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,11 @@ def test_file_contents(self):
422422
fuzz_file = os.path.join(temp_dir.name, f'fuzz-binaryen-{i}.js')
423423

424424
# Add --fuzzing to allow legacy and standard EH to coexist
425-
cmd = [shared.V8, '--wasm-staging', '--fuzzing', fuzz_file]
425+
cmd = [shared.V8,
426+
'--wasm-staging',
427+
'--experimental-wasm-custom-descriptors',
428+
'--fuzzing',
429+
fuzz_file]
426430
proc = subprocess.run(cmd, stdout=subprocess.PIPE)
427431

428432
# An execution is valid if we exited without error, and if we

0 commit comments

Comments
 (0)