-Zsanitizer without build.sanitizers=true? Thin sanitizer runtimes?

Hi all,

I'm trying to integrate rustc with sanitizers into our build system. This is not Cargo-based (it uses Buck) and we frequently end up with hybrid Rust/C++ executables. I'm trying to make santiizers work cross-language, primarily to help validate FFI bindings.

Firstly, I've built rustc against exactly the same version of llvm we're using for clang, so I'm expecting everything to be perfectly compatible. (I'm not completely sure this is a good assumption, but it's my working starting point.)

The build system currently supports sanitizers for C++; when you specify a sanitized flavor of build, it makes sure the right llvm compiler_rt library(ies) are on the link line.

Unfortunately, if I specify -Zsanitizer on the rustc command line, the Rust sanitizer runtime libraries clash with the raw llvm ones (lots of duplicate symbols).

I've thought of 3 solutions and tried 2:

  1. Attempt to always use the Rust sanitizer runtimes (:frowning:)
  2. Build the Rust toolchain without build.sanitizers=true (:thinking:)
  3. Make the Rust sanitizer runtime libs "thin" (ie, don't duplicate the llvm runtime code) (:man_shrugging:)

1: On the assumption that the Rust runtimes contain complete and identical code to the llvm santiizer runtime libs, I tried just omitting the latter - but that breaks with pure C++ builds (or something - it didn't work and I haven't dug into it yet).

2: I built rustc without build.sanitizers=true in config.toml. This "worked" to the extent that -Zsanitizer builds completed and generated a working executable - but I haven't managed to verify that sanitizer functionality is actually working. I did hack some unsafe code to pass a bad pointer to free() but it just had a raw segmentation violation rather than the diagnostic I'd expect. Is something not setting up a signal handler?

Nevertheless, the closest to working.

3: I'm thinking about adding a build option to include the sanitizer runtimes, but not populate them with llvm sanitizer objects. It looks like this is special-cased for macOS, but would it work generically? I haven't really worked out how it all fits together since there seems to be quite a lot of magic there.

Should I explore this more?

Thanks!

It looks like build.sanitizers = false works fine - all the support for -Zsanitizer= is there, there doesn't seem to be any more Rust-specific sanitizer setup needed. The only problem has been the stack overflow check stealing the SIGSEGV handler.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.