Compiling crate serde-derive with "-Z sanitizer=leak" fails
Compiling my crate that uses serde with RUSTFLAGS="-Z sanitizer=leak" results in:
error: Only executables, staticlibs, cdylibs, dylibs and rlibs can be compiled with `-Z sanitizer`
Verbose output shows:
Running `rustc --crate-name cubeb_core cubeb-core/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=61d1a8a7b2e564d0 -C extra-filename=-61d1a8a7b2e564d0 --out-dir /home/djg/Mozilla/cubeb-rs/target/debug/deps -C incremental=/home/djg/Mozilla/cubeb-rs/target/debug/incremental -L dependency=/home/djg/Mozilla/cubeb-rs/target/debug/deps --extern cubeb_sys=/home/djg/Mozilla/cubeb-rs/target/debug/deps/libcubeb_sys-f4b7e696cf674255.rlib --extern foreign_types=/home/djg/Mozilla/cubeb-rs/target/debug/deps/libforeign_types-9d464a343a654ec3.rlib --extern bitflags=/home/djg/Mozilla/cubeb-rs/target/debug/deps/libbitflags-709a54b1053b84e9.rlib -Z sanitizer=leak -L native=/home/djg/Mozilla/cubeb-rs/target/debug/build/cubeb-sys-52b952c542113788/out/lib -L native=/usr/lib64 -L native=/usr/lib64 -L native=/usr/lib64`
error: aborting due to previous error
error: Could not compile `serde_derive`.
Caused by:
process didn't exit successfully: `rustc --crate-name serde_derive /home/djg/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_derive-1.0.27/src/lib.rs --crate-type proc-macro --emit=dep-info,link -C prefer-dynamic -C debuginfo=2 --cfg feature="default" -C metadata=8e2449096591e6bb -C extra-filename=-8e2449096591e6bb --out-dir /home/djg/Mozilla/cubeb-rs/target/debug/deps -L dependency=/home/djg/Mozilla/cubeb-rs/target/debug/deps --extern syn=/home/djg/Mozilla/cubeb-rs/target/debug/deps/libsyn-b487ac40d22b413a.rlib --extern quote=/home/djg/Mozilla/cubeb-rs/target/debug/deps/libquote-2902a853682299e0.rlib --extern serde_derive_internals=/home/djg/Mozilla/cubeb-rs/target/debug/deps/libserde_derive_internals-dcd3ff49aa5d175c.rlib --cap-lints warn -Z sanitizer=leak` (exit code: 101)
Talking to @Firstyear,
proc-macrocrates should be ignored by sanitizer.Dan Glastonbury at 2018-02-14 06:16:48
Is there a workaround for this bug?
Yevhenii Reizner at 2018-04-07 18:39:05
IIRC you need a
--target: https://users.rust-lang.org/t/howto-sanitize-your-rust-code/9378Tatsuyuki Ishi at 2018-04-08 02:50:52
Regarding a fix for this (#63986) we'd need a way to conditionally check whether
--targetwas passed from the command line. Where does the value of this flag get passed through the compiler?Corey Farwell at 2020-12-11 14:51:24
What
--targetdoes, is to change behavior of cargo so that in no longer usesRUSTFLAGSfor builds scripts and procedural macros. In this case it is desirable, since otherwise those instrumented procedural macros are loaded into rustc (which to work would require either instrumented rustc or at least pre-loading the sanitizer runtime).I think there is little that can be done on rustc side (at best it could generate a warning or an error when building procedural macro crates). I think that improving the user experience here would most likely require implementing sanitizer options in cargo.
Tomasz Miąsko at 2020-12-11 20:18:39