Skip to content

Commit

Permalink
Merge pull request #106 from addisoncrump/main
Browse files Browse the repository at this point in the history
Make it possible to link to custom runtime in another dep
  • Loading branch information
fitzgen authored May 11, 2023
2 parents df3ac96 + 606e928 commit 1221c35
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ once_cell = "1"
cc = { version = "1.0", features = ["parallel"] }

[features]
default = ["link_libfuzzer"]
link_libfuzzer = []
arbitrary-derive = ["arbitrary/derive"]

[workspace]
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ And finally, run the fuzzer:
$ ./target/debug/fuzzed
```

### Linking to a local libfuzzer

When using `libfuzzer-sys`, you can provide your own `libfuzzer` runtime in two ways.

If you are developing a fuzzer, you can set the `CUSTOM_LIBFUZZER_PATH` environment variable to the path of your local
`libfuzzer` runtime, which will then be linked instead of building libfuzzer as part of the build stage of `libfuzzer-sys`.
For an example, to link to a prebuilt LLVM 16 `libfuzzer`, you could use:

```bash
$ export CUSTOM_LIBFUZZER_PATH=/usr/lib64/clang/16/lib/libclang_rt.fuzzer-x86_64.a
$ cargo fuzz run ...
```

Alternatively, you may also disable the default `link_libfuzzer` feature:

In `Cargo.toml`:
```toml
[dependencies]
libfuzzer-sys = { path = "../../libfuzzer", default-features = false }
```

Then link to your own runtime in your `build.rs`.

## Updating libfuzzer from upstream

```
Expand Down
8 changes: 7 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main() {
fn build_and_link_libfuzzer() {
println!("cargo:rerun-if-env-changed=CUSTOM_LIBFUZZER_PATH");
if let Ok(custom) = ::std::env::var("CUSTOM_LIBFUZZER_PATH") {
println!("cargo:rerun-if-changed={custom}");
Expand Down Expand Up @@ -38,3 +38,9 @@ fn main() {
build.compile("libfuzzer.a");
}
}

fn main() {
if cfg!(feature = "link_libfuzzer") {
build_and_link_libfuzzer();
}
}

0 comments on commit 1221c35

Please sign in to comment.