Skip to content

Allow using prebuilt sanitizer librariesΒ #943

@jakos-sec

Description

@jakos-sec

Proposal

In the efforts of the Rust goal Rust Stabilization of MemorySanitizer and ThreadSanitizer Support, we are looking for a solution to distribute prebuilt sanitizer instrumented standard libraries. This was requested by previous reviews, in order to stabilize sanitizers that require all code to be instrumented since otherwise they generate false positives (like the MemorySanitizer and ThreadSanitizer). Currently the only way to realistically use those is with -Z build-std, but if we stabilize the sanitizers, it is odd to still be dependent on another unstable flag.

We should therefore have an easier way to use stabilized sanitizers with sanitizer instrumented standard libraries without build-std by providing the instrumented standard library artifacts through e.g. rustup. I've originally approached the infra team but was directed to first addressing the necessary compiler changes before looking into distributing the artifacts (#t-infra/bootstrap > 2025H2 Goal Review @ πŸ’¬).

Together with some of the code that eholk provided me, I made a prototype in a local branch with 2 commits.

The high-level design proposal looks like this:

Currently rustc has a single --sysroot that allows to set the entire sysroot but there is no way to toggle between different standard library variants there.

We could have a structure inside that looks something like this:

.../lib/rustlib/
└── x86_64-unknown-linux-gnu/
    β”œβ”€β”€ lib/          # The default standard library
    β”œβ”€β”€ lib-asan/     # The variant built with AddressSanitizer
    └── lib-msan/     # The variant built with MemorySanitizer

In order to do so, we would need: A) compiler support to enable the variant required and B) bootstrap support in order to provide the variants through rustup.

In order to allow build-std to use -Zsanitizer=address without using the prebuilt artifacts, I introduced the rustc flag -Zsanitizer-use-prebuilt-library, which once the artifacts are shipped should default to yes and set to no by cargo when using build-std.

Some more context can also be found here.

Mentors or Reviewers

Mentor/Reviewer: rcvalle

Process

The main points of the Major Change Process are as follows:

  • File an issue describing the proposal.
  • A compiler team member who is knowledgeable in the area can second by writing @rustbot second or kickoff a team FCP with @rfcbot fcp $RESOLUTION.
  • Once an MCP is seconded, the Final Comment Period begins.
    • Final Comment Period lasts for 10 days after all outstanding concerns are solved.
    • Outstanding concerns will block the Final Comment Period from finishing. Once all concerns are resolved, the 10 day countdown is restarted.
    • If no concerns are raised after 10 days since the resolution of the last outstanding concern, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Caution

Concerns (2 active)

Managed by @rustbotβ€”see help for details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerAdd this label so rfcbot knows to poll the compiler teamhas-concernsThere are active concernsmajor-changeA proposal to make a major change to rustcto-announceAnnounce this issue on triage meeting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions