Skip to content

Add support for easily fuzzing cg_gcc with rustlantis #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025

Conversation

FractalFir
Copy link
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
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
Contributor Author

Hopefully, should be good to review now.

Copy link
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:

@FractalFir
Copy link
Contributor Author

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

Copy link
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.

@FractalFir
Copy link
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
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