Skip to content
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

-fsanitize=fuzzer support #5484

Closed
jamii opened this issue May 30, 2020 · 2 comments · Fixed by #20725
Closed

-fsanitize=fuzzer support #5484

jamii opened this issue May 30, 2020 · 2 comments · Fixed by #20725
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@jamii
Copy link
Sponsor

jamii commented May 30, 2020

To use libfuzzer in C is as simple as:

clang -g -O1 -fsanitize=fuzzer mytarget.c

I was vaguely hoping that this would work out in zig:

jamie@machine:~/imp$ zig build-exe --main-pkg-path ./ -mllvm -fsanitize=fuzzer test/fuzz.zig
zig (LLVM option parsing): Unknown command line argument '-fsanitize=fuzzer'.  Try: 'zig (LLVM option parsing) --help'
zig (LLVM option parsing): Did you mean '--filetype=fuzzer'?

Am I just mangling the option syntax or is this something that would need specific support? I don't really understand at what level libfuzzer is plumbed into the clang pipeline.

@meme
Copy link
Contributor

meme commented Jun 24, 2020

This requires support on Zig's end. You can link against the ASan runtime libraries and expose an extern "C"-style LLVMFuzzerTestOneInput BUT there will be no instrumentation of the LLVM bitcode. The asan pass needs to be enabled to emit all the appropriate __sanitizer_* symbols which allow libFuzzer to understand code coverage of the fuzzed test cases.

See relevant PR for adding sanitizer support into Rust: rust-lang/rust#38699.

@meme
Copy link
Contributor

meme commented Jul 31, 2020

I am interested in this, and have started work on it. First, we need to get all the sanitizers into Zig, then I will begin implementing fuzzer instrumentation and coverage. Afterwards, we can make fuzzing a first-class citizen by adding, e.g. a fuzzing-specific entrypoint, like in libFuzzer. This means that users will be able to:

  1. Make stand-alone fuzzed programs
  2. Write fuzzing test cases for their Zig programs in an idiomatic way

PR is here.


Not to entirely hijack this issue, but I think the title should be changed to a feature request @jamii 😄

@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Oct 4, 2020
@andrewrk andrewrk added this to the 0.8.0 milestone Oct 4, 2020
@andrewrk andrewrk changed the title Using libfuzzer -fsanitize=fuzzer support Oct 4, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jul 9, 2023
@andrewrk andrewrk added the accepted This proposal is planned. label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants