rust-fuzz / libfuzzer

Rust bindings and utilities for LLVM’s libFuzzer
Apache License 2.0
210 stars 44 forks source link

Add env var to select c++ std lib #56

Closed jfoote closed 4 years ago

jfoote commented 4 years ago

Apologies in advance for this hack job.

As part of https://github.com/bytecodealliance/wasmtime/issues/611 I am building wasmtime fuzz targets in the google/oss-fuzz build container. This environment supplies the LLVM c++ standard library rather than the GCC one. It is specified in CXXFLAGS and presumably linked in the version of libfuzzer they supplied (libFuzzingEngine.a).

It looks like rust-fuzz/libfuzzer currently links the GCC standard library when using an external libfuzzer library, which causes a linker error when linking in the oss-fuzz compilation environment.

This PR adds an environment variable that lets the user select whether they'd like to link the GCC c++ standard library (the default, for backward compatibility), the installed (LLVM) c++ standard library, or not link one at all. If you'd rather control this another way or do something different please feel free.

I wasn't able to easily test rust-fuzz/libfuzzer with the wasmtime fuzz targets due to an incompatibility with the arbitrary crate; I didn't attempt to resolve this as part of this PR. I smoke-tested this change by using an old version of libfuzzer, before arbitrary was upgraded (actually https://github.com/rust-fuzz/libfuzzer/commit/0c4507533a79e85e1984f59765bdd35fbdaa7f1b, the last functional commit made to rust-fuzz/libfuzzer-sys, which is what I was developing against before I realized it was deprecated : ).

Please let me know how you'd like to proceed -- thanks!

jfoote commented 4 years ago

Thanks @fitzgen! Fixed. Your patch works verbatim.

fitzgen commented 4 years ago

Published 0.2.1 with this change!