Skip to content
Open
Changes from 58 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
50ad754
go
kripken Oct 3, 2025
1063ccb
go
kripken Oct 3, 2025
60477e6
undo
kripken Oct 3, 2025
ed740fe
go
kripken Oct 3, 2025
b17e3c8
work
kripken Oct 3, 2025
26f0182
go
kripken Oct 3, 2025
3e9f640
go
kripken Oct 3, 2025
60347f1
go
kripken Oct 3, 2025
811f664
go
kripken Oct 3, 2025
0aa0965
go
kripken Oct 3, 2025
4b2b432
go
kripken Oct 3, 2025
3ae249e
go
kripken Oct 3, 2025
c96682d
go
kripken Oct 3, 2025
05060c9
go
kripken Oct 3, 2025
33727e8
go
kripken Oct 3, 2025
1aff0c1
FIX.prune
kripken Oct 3, 2025
7e75c16
FIX.prune
kripken Oct 3, 2025
9d738a4
typo
kripken Oct 3, 2025
53a5b4d
typo
kripken Oct 3, 2025
d60579a
Merge remote-tracking branch 'myself/prune.nondef' into add-fuzz-imports
kripken Oct 3, 2025
44aeb93
format
kripken Oct 3, 2025
31d8934
fix
kripken Oct 3, 2025
4b63f2b
CF.too
kripken Oct 6, 2025
4cc8e45
fix
kripken Oct 6, 2025
b49eaf6
fix
kripken Oct 6, 2025
05a296a
back
kripken Oct 6, 2025
86fc6e6
Merge remote-tracking branch 'origin/main' into add-fuzz-imports
kripken Oct 6, 2025
f2d6c1a
freqs
kripken Oct 6, 2025
5733260
clean
kripken Oct 6, 2025
f4f30e9
clean
kripken Oct 6, 2025
cb9a608
fix
kripken Oct 6, 2025
dc899d3
linkt
kripken Oct 6, 2025
180f102
go
kripken Oct 6, 2025
233cfcd
work
kripken Oct 6, 2025
063e909
fix
kripken Oct 6, 2025
ffe63c7
now
kripken Oct 6, 2025
80faed3
fix
kripken Oct 6, 2025
3b89ddc
fix
kripken Oct 6, 2025
34963c3
work
kripken Oct 6, 2025
52781b2
work
kripken Oct 7, 2025
3885f44
work
kripken Oct 7, 2025
9b471e2
work
kripken Oct 7, 2025
1dae57e
Merge remote-tracking branch 'origin/main' into add-fuzz-imports.2
kripken Oct 7, 2025
4031f8d
fix
kripken Oct 7, 2025
c2d3c38
feedback: simplify
kripken Oct 7, 2025
8a1c3f3
go?
kripken Oct 8, 2025
955fd88
work
kripken Oct 8, 2025
a357412
work
kripken Oct 8, 2025
d78a49e
work
kripken Oct 8, 2025
f8c88c1
work
kripken Oct 8, 2025
8a9ff6b
work
kripken Oct 8, 2025
8ecba1e
fix
kripken Oct 8, 2025
091a4f3
Merge remote-tracking branch 'origin/main' into add-fuzz-imports.3
kripken Oct 9, 2025
77af20a
fix
kripken Oct 9, 2025
88510da
fix
kripken Oct 9, 2025
ceff9ec
clean
kripken Oct 9, 2025
d1c2829
comments
kripken Oct 9, 2025
0f2cc01
comments
kripken Oct 9, 2025
807d072
lint
kripken Oct 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 88 additions & 10 deletions scripts/fuzz_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1783,13 +1783,13 @@ def ensure(self):
tar.close()


# Tests linking two wasm files at runtime, and that optimizations do not break
# anything. This is similar to Split(), but rather than split a wasm file into
# two and link them at runtime, this starts with two separate wasm files.
# Generates two wasm and tests interesting interactions between them. This is a
# little similar to Split(), but rather than split one wasm file into two and
# test that, we start with two.
class Two(TestCaseHandler):
# Run at relatively high priority, as this is the main place we check cross-
# module interactions.
frequency = 1
frequency = 1 # TODO: We may want even higher priority here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Higher than 1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.youtube.com/watch?v=4xgx4k83zzc

Seriously though, yes, "1" here means we use it with chance 100% when we pick it. But it still is limited by that chance to be picked out of the list in the first place. If e.g. we put it in the list twice, it would have double the chance it currently has.


def handle(self, wasm):
# Generate a second wasm file, unless we were given one (useful during
Expand Down Expand Up @@ -1843,9 +1843,41 @@ def handle(self, wasm):
print(f'warning: no calls in output. output:\n{output}')
assert calls_in_output == len(exports), exports

# Merge the files and run them that way. The result should be the same,
# even if we optimize. TODO: merge (no pun intended) the rest of Merge
# into here.
merged = abspath('merged.wasm')
run([in_bin('wasm-merge'), wasm, 'primary', second_wasm, 'secondary',
'-o', merged, '--rename-export-conflicts', '-all'])

# Usually also optimize the merged module. Optimizations are very
# interesting here, because after merging we can safely do even closed-
# world optimizations, making very aggressive changes that should still
# behave the same as before merging.
if random.random() < 0.8:
merged_opt = abspath('merged.opt.wasm')
opts = get_random_opts()
run([in_bin('wasm-opt'), merged, '-o', merged_opt, '-all'] + opts)
merged = merged_opt

if not wasm_notices_export_changes(merged):
# wasm-merge combines exports, which can alter their indexes and
# lead to noticeable differences if the wasm is sensitive to such
# things. We only compare the output if that is not an issue.
merged_output = run_bynterp(merged, args=['--fuzz-exec-before', '-all'])

self.compare_to_merged_output(output, merged_output)

# The rest of the testing here depends on being to optimize the
# two modules independently, which closed-world can break.
if CLOSED_WORLD:
return

# Fix up the normal output for later comparisons.
output = fix_output(output)

# Optimize at least one of the two.
# We can optimize and compare the results. Optimize at least one of
# the two.
wasms = [wasm, second_wasm]
for i in range(random.randint(1, 2)):
wasm_index = random.randint(0, 1)
Expand All @@ -1859,7 +1891,7 @@ def handle(self, wasm):
optimized_output = run_bynterp(wasms[0], args=['--fuzz-exec-before', f'--fuzz-exec-second={wasms[1]}'])
optimized_output = fix_output(optimized_output)

compare(output, optimized_output, 'Two')
compare(output, optimized_output, 'Two-Opt')

# If we can, also test in V8. We also cannot compare if there are NaNs
# (as optimizations can lead to different outputs), and we must
Expand All @@ -1885,10 +1917,56 @@ def handle(self, wasm):

compare(output, optimized_output, 'Two-V8')

def can_run_on_wasm(self, wasm):
# We cannot optimize wasm files we are going to link in closed world
# mode.
return not CLOSED_WORLD
def compare_to_merged_output(self, output, merged_output):
# Comparing the original output from two files to the output after
# merging them is not trivial. First, remove the extra logging that
# --fuzz-exec-second adds.
output = output.replace('[fuzz-exec] running second module\n', '')

# Fix up both outputs.
output = fix_output(output)
merged_output = fix_output(merged_output)

# Finally, align the export names. We merged with
# --rename-export-conflicts, so that all exports remain exported,
# allowing a full comparison, but we do need to handle the different
# names. We do so by matching the export names in the logging.
output_lines = output.splitlines()
merged_output_lines = merged_output.splitlines()

if len(output_lines) != len(merged_output_lines):
# The line counts don't even match. Just compare them, which will
# emit a nice error for that.
compare(output, merged_output, 'Two-Counts')
assert False, 'we should have errored on the line counts'

for i in range(len(output_lines)):
a = output_lines[i]
b = merged_output_lines[i]
if a == b:
continue
if a.startswith(FUZZ_EXEC_CALL_PREFIX):
# Fix up
# [fuzz-exec] calling foo/bar
# for different foo/bar. Just copy the original.
assert b.startswith(FUZZ_EXEC_CALL_PREFIX)
merged_output_lines[i] = output_lines[i]
elif a.startswith(FUZZ_EXEC_NOTE_RESULT):
# Fix up
# [fuzz-exec] note result: foo/bar => 42
# for different foo/bar. We do not want to copy the result here,
# which might differ (that would be a bug we want to find).
assert b.startswith(FUZZ_EXEC_NOTE_RESULT)
assert a.count(' => ') == 1
assert b.count(' => ') == 1
a_prefix, a_result = a.split(' => ')
b_prefix, b_result = b.split(' => ')
# Copy a's prefix with b's result.
merged_output_lines[i] = a_prefix + ' => ' + b_result

merged_output = '\n'.join(merged_output_lines)

compare(output, merged_output, 'Two-Merged')


# Test --fuzz-preserve-imports-exports, which never modifies imports or exports.
Expand Down
Loading