BorrowSanitizer
10 points by sanxiyn
10 points by sanxiyn
This seems extremely cool. I would love to see more blog posts on how the instrumentation works for a layman (me :-))
Yeah, especially on how you can encode enough information into the IR to do instrumentation as an LLVM pass. My assumption was that some of the information about borrowing was thrown away before it reaches LLVM, and LLVM can't currently take advantage of it for optimizations (but other, rustc-native optimizations might).
I think the BorrowSanitizer project goal proposal has a decent summary, though I'm not sure whether it quite qualifies as layman-friendly:
Much like AddressSanitizer, MemorySanitizer, and other LLVM-based tools, BorrowSanitizer inserts checks during compilation to detect errors at run-time. Its purpose is to find violations of Rust's newest Tree Borrows aliasing model, as well as accesses out-of-bounds and use-after-free errors.
BorrowSanitizer relies on changes to the Rust compiler, an LLVM instrumentation pass, and a runtime library. We modified the compiler to emit special "retag" intrinsics that indicate when references are created and updated. Our LLVM pass lowers these intrinsics into runtime calls that associate each pointer with "provenance" metadata (see provenance RFC #3559). We validate provenance before memory accesses to detect undefined behavior.
Some more information about the (proposed) implementation on the Rust side is provided in the pre-RFC and major change proposal, and there's a corresponding RFC for LLVM as well.