Skip to content

Commit 1221c35

Browse files
authored
Merge pull request #106 from addisoncrump/main
Make it possible to link to custom runtime in another dep
2 parents df3ac96 + 606e928 commit 1221c35

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ once_cell = "1"
1616
cc = { version = "1.0", features = ["parallel"] }
1717

1818
[features]
19+
default = ["link_libfuzzer"]
20+
link_libfuzzer = []
1921
arbitrary-derive = ["arbitrary/derive"]
2022

2123
[workspace]

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,29 @@ And finally, run the fuzzer:
6161
$ ./target/debug/fuzzed
6262
```
6363

64+
### Linking to a local libfuzzer
65+
66+
When using `libfuzzer-sys`, you can provide your own `libfuzzer` runtime in two ways.
67+
68+
If you are developing a fuzzer, you can set the `CUSTOM_LIBFUZZER_PATH` environment variable to the path of your local
69+
`libfuzzer` runtime, which will then be linked instead of building libfuzzer as part of the build stage of `libfuzzer-sys`.
70+
For an example, to link to a prebuilt LLVM 16 `libfuzzer`, you could use:
71+
72+
```bash
73+
$ export CUSTOM_LIBFUZZER_PATH=/usr/lib64/clang/16/lib/libclang_rt.fuzzer-x86_64.a
74+
$ cargo fuzz run ...
75+
```
76+
77+
Alternatively, you may also disable the default `link_libfuzzer` feature:
78+
79+
In `Cargo.toml`:
80+
```toml
81+
[dependencies]
82+
libfuzzer-sys = { path = "../../libfuzzer", default-features = false }
83+
```
84+
85+
Then link to your own runtime in your `build.rs`.
86+
6487
## Updating libfuzzer from upstream
6588

6689
```

build.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
fn main() {
1+
fn build_and_link_libfuzzer() {
22
println!("cargo:rerun-if-env-changed=CUSTOM_LIBFUZZER_PATH");
33
if let Ok(custom) = ::std::env::var("CUSTOM_LIBFUZZER_PATH") {
44
println!("cargo:rerun-if-changed={custom}");
@@ -38,3 +38,9 @@ fn main() {
3838
build.compile("libfuzzer.a");
3939
}
4040
}
41+
42+
fn main() {
43+
if cfg!(feature = "link_libfuzzer") {
44+
build_and_link_libfuzzer();
45+
}
46+
}

0 commit comments

Comments
 (0)