Skip to content

Rust should not link sanitizer runtimes unconditionally #64629

Closed
@choller

Description

@choller

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:

link_sanitizer_runtime::<B>(cmd, sess, codegen_results, tmpdir, cnum);

[1] https://github.com/llvm-mirror/clang/blob/7dbdcfcb827c68b0c380de289a2d7526666b8771/lib/Driver/ToolChains/CommonArgs.cpp#L645

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesA-sanitizersArea: Sanitizers for correctness and code qualityC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions