File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ once_cell = "1"
16
16
cc = { version = " 1.0" , features = [" parallel" ] }
17
17
18
18
[features ]
19
+ default = [" link_libfuzzer" ]
20
+ link_libfuzzer = []
19
21
arbitrary-derive = [" arbitrary/derive" ]
20
22
21
23
[workspace ]
Original file line number Diff line number Diff line change @@ -61,6 +61,29 @@ And finally, run the fuzzer:
61
61
$ ./target/debug/fuzzed
62
62
```
63
63
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
+
64
87
## Updating libfuzzer from upstream
65
88
66
89
```
Original file line number Diff line number Diff line change 1
- fn main ( ) {
1
+ fn build_and_link_libfuzzer ( ) {
2
2
println ! ( "cargo:rerun-if-env-changed=CUSTOM_LIBFUZZER_PATH" ) ;
3
3
if let Ok ( custom) = :: std:: env:: var ( "CUSTOM_LIBFUZZER_PATH" ) {
4
4
println ! ( "cargo:rerun-if-changed={custom}" ) ;
@@ -38,3 +38,9 @@ fn main() {
38
38
build. compile ( "libfuzzer.a" ) ;
39
39
}
40
40
}
41
+
42
+ fn main ( ) {
43
+ if cfg ! ( feature = "link_libfuzzer" ) {
44
+ build_and_link_libfuzzer ( ) ;
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments