compiler-team icon indicating copy to clipboard operation
compiler-team copied to clipboard

Use the MSVC provided Address Sanitizer runtime when building for MSVC

Open dpaoliello opened this issue 7 months ago • 2 comments

Proposal

Address Sanitizer (aka ASAN) requires a "runtime library" to provide various functions used to inspect memory accesses. The code for this library is in LLVM, and Rust provides a custom build of the library for MacOS and Linux, but not Windows. Similarly, Microsoft provides a build of the library for use with its own compilers: https://learn.microsoft.com/en-us/cpp/sanitizers/asan-runtime?view=msvc-170

I am proposing that Rust also uses the Microsoft provided ASAN runtime library when building for MSVC.

Benefits:

  • Allows the use of ASAN on Windows (since LLVM's ASAN does not yet officially support Windows).
  • Simplifies the deployment of ASAN on Windows, as the Microsoft ASAN runtime library can be installed by a developer when installing the rest of the MSVC toolchain.

Drawbacks:

  • Does not enable ASAN on Windows when using the GNU or GNULLVM targets.
  • Does not allow Rust to customize how ASAN works for Windows.
  • The Microsoft ASAN library is deployed as a DLL, requiring it to be copied alongside the final binary or be on the PATH.
  • The interface between a compiler and an ASAN runtime is not guaranteed to be stable between versions, so future changes to LLVM or Microsoft's ASAN library may break this feature.

I have a prototype of this change working by utilizing the MSVC linker's /INFERASANLIBS option: https://github.com/rust-lang/rust/pull/118521

Mentors or Reviewers

Mentor: @wesleywiser

Process

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

  • [x] File an issue describing the proposal.
  • [x] A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • [x] Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

dpaoliello avatar Dec 07 '23 19:12 dpaoliello

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

Concerns or objections to the proposal should be discussed on Zulip and formally registered here by adding a comment with the following syntax:

@rustbot concern reason-for-concern 
<description of the concern> 

Concerns can be lifted with:

@rustbot resolve reason-for-concern 

See documentation at https://forge.rust-lang.org

cc @rust-lang/compiler @rust-lang/compiler-contributors

rustbot avatar Dec 07 '23 19:12 rustbot

@rustbot second

wesleywiser avatar Dec 12 '23 00:12 wesleywiser

@rustbot label -final-comment-period +major-change-accepted

apiraino avatar Dec 28 '23 10:12 apiraino