Skip to content

Add support for easily fuzzing cg_gcc with rustlantis#688

Merged
antoyo merged 1 commit intorust-lang:masterfrom
FractalFir:fuzz_support
May 28, 2025
Merged

Add support for easily fuzzing cg_gcc with rustlantis#688
antoyo merged 1 commit intorust-lang:masterfrom
FractalFir:fuzz_support

Conversation

@FractalFir
Copy link
Copy Markdown
Contributor

This PR adds a new y command: ./y.sh fuzz.

This command clones the rustlantis repo, and uses it to generate Rust programs to fuzz cg_gcc with.

It takes in 3 optional arguments: search space start(--start), search space length(--count), and the parallelism(--jobs / -j).

By default, the fuzzer will search the first 100 programs(this takes about a minute, and functions as a small test for more obscure semantics of rust, like NaN handling).

The script compiles programs with LLVM debug mode and GCC release mode, and then compares the result of their execution. If a compiler error occurs, or there is a runtime difference between the two backends, a message will be displayed, and the problematic source file will be copied over to either target/fuzz/compiletime_error or target/fuzz/runtime_error.

The fuzzer script respects CG_RUSTFLAGS, which should allow us to test things like software floating point emulation, or 128 bit intiger emulation. We can also enable UB checks.

Limitations

rustlantis does not support 32 bit systems without patches , so we can't fuzz on 32 bit platforms.

Additonally, on platforms not supported by LLVM, we have nothing to compare to. We could compare against debug GCC runs, but that may miss things.

We might consider adding support for cross compilation / emulation, and compare scripts run on x86_64 with scripts run elsewhere.

@FractalFir
Copy link
Copy Markdown
Contributor Author

UGH, it looks like I anciently included some unrelated changes.

@FractalFir FractalFir force-pushed the fuzz_support branch 7 times, most recently from cac3ac1 to f62130e Compare May 28, 2025 11:19
@FractalFir
Copy link
Copy Markdown
Contributor Author

Hopefully, should be good to review now.

Copy link
Copy Markdown
Contributor

@antoyo antoyo left a comment

Choose a reason for hiding this comment

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

Thanks for your work!

Here's a first review:

Comment thread build_system/src/fuzz.rs Outdated
Comment thread build_system/src/fuzz.rs Outdated
Comment thread build_system/src/fuzz.rs
Comment thread build_system/src/fuzz.rs Outdated
Comment thread build_system/src/fuzz.rs
Comment thread build_system/src/fuzz.rs
Comment thread build_system/src/fuzz.rs
Comment thread build_system/src/fuzz.rs
Comment thread build_system/src/fuzz.rs
@FractalFir
Copy link
Copy Markdown
Contributor Author

Fixed the issues + added a few more detailed comments. Should be OK to review again now.

Copy link
Copy Markdown
Contributor

@antoyo antoyo left a comment

Choose a reason for hiding this comment

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

One nitpick.
After that, I can merge it.
Thanks for the good work!
This command is going to be very useful.

Comment thread build_system/src/fuzz.rs Outdated
@FractalFir
Copy link
Copy Markdown
Contributor Author

Should be all ready for merge now.

@antoyo antoyo merged commit 967fc29 into rust-lang:master May 28, 2025
38 checks passed
@antoyo
Copy link
Copy Markdown
Contributor

antoyo commented May 28, 2025

Thanks a lot for the amazing work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants