[rust-dev] Using Rust with LLVM's Sanitizers

Hey all, As you are probably aware, we use LLVM for code generation and optimization. It is a large project, and one of its cooler features is the variety of "sanitizers" it provides (http://clang.llvm.org/docs/index.html#using-clang-as-a-compiler). These are not clang-specific, but indeed can be used with Rust! For example, to use AddressSanitizer (asan) on my system, I do: rustc --passes asan,asan-module --link-args "/usr/bin/../lib/clang/3.4/lib/linux/libclang_rt.asan-x86_64.a" foo.rs I got the path to the necessary asan library by looking at "clang -v -fsanitize=address foo.c" For example, the following program: use std::libc::{free,malloc}; fn main() { unsafe { let p = malloc(42); free(p); free(p); } } Outputs https://gist.github.com/cmr/8800111 Similarly, you can use ThreadSanitizer (tsan) by using `--passes tsan` and replacing asan with tsan in the link-args. Also useful is msan (for detecting uninitialized reads) and tsan (for detecting data races). One caveat is that although LLVM will happily run all of the sanitizer passes for you, you can actually only use one at a time (you will see this when you try to link the multiple *san libraries together). Now, these aren't going to be as useful in Rust given its focus on safety, but they can still be useful when debugging unsafe code, writing bindings, etc. Any time valgrind would be useful, often one of the sanitizers can be used with less overhead. Cheers, cmr