Description
I've noticed today that apparently Rust adds sanitizer runtimes such as the ASan runtime during linking and I found this runtime inside a static archive.
As far as I know, these runtimes should not be part of static archives or DSOs, they should only be linked when creating an executable. Adding them to DSOs causes two runtimes to exist when loading the DSO into an ASan binary (we had this problem longer ago in mozilla-central and it was fixed in Clang, see [1]). Adding the runtime to static archives causes linker problems when linking the archive to a C++ binary built with ASan because Clang will add the ASan runtime a second time when linking the executable. For some reason this worked before (maybe if the runtimes used are exactly identical the linker will deduplicate them) but today during building with Rust nightly I got duplicate symbol errors indicating two conflicting ASan RTs.
From what I can tell, Rust should not link these runtimes except if it is producing an executable. The respective code is called here independent of crate_type
:
rust/src/librustc_codegen_ssa/back/link.rs
Line 1376 in ea3ba36