Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the MSVC provided Address Sanitizer runtime when building for MSVC #702

Closed
3 tasks done
dpaoliello opened this issue Dec 7, 2023 · 3 comments
Closed
3 tasks done
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@dpaoliello
Copy link

dpaoliello commented Dec 7, 2023

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: rust-lang/rust#118521

Mentors or Reviewers

Mentor: @wesleywiser

Process

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

  • File an issue describing the proposal.
  • 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.
  • 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 dpaoliello added major-change A proposal to make a major change to rustc T-compiler Add this label so rfcbot knows to poll the compiler team labels Dec 7, 2023
@rustbot
Copy link
Collaborator

rustbot commented Dec 7, 2023

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 rustbot added the to-announce Announce this issue on triage meeting label Dec 7, 2023
@wesleywiser
Copy link
Member

@rustbot second

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Dec 12, 2023
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Dec 14, 2023
@apiraino
Copy link
Contributor

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

@rustbot rustbot added major-change-accepted A major change proposal that was accepted to-announce Announce this issue on triage meeting and removed final-comment-period The FCP has started, most (if not all) team members are in agreement labels Dec 28, 2023
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Dec 28, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 3, 2024
Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag

This enables address sanitizer for x86_64-pc-windows-msvc and i686-pc-windows-msvc targets when linked with the MSVC linker (link.exe) by leveraging the `/INFERASANLIBS` option to automatically find and link in Microsoft's address sanitizer runtime: <https://learn.microsoft.com/en-us/cpp/sanitizers/asan-runtime?view=msvc-170>

Implements rust-lang/compiler-team#702
Fixes rust-lang#89339 (for MSVC targets using the MSVC linker only)
Supercedes rust-lang#89369

Successful x86_64-msvc build showing the sanitizer tests working: https://github.com/rust-lang/rust/actions/runs/7228346880/job/19697628258?pr=118521
compiler-errors added a commit to compiler-errors/rust that referenced this issue Jan 4, 2024
Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag

This enables address sanitizer for x86_64-pc-windows-msvc and i686-pc-windows-msvc targets when linked with the MSVC linker (link.exe) by leveraging the `/INFERASANLIBS` option to automatically find and link in Microsoft's address sanitizer runtime: <https://learn.microsoft.com/en-us/cpp/sanitizers/asan-runtime?view=msvc-170>

Implements rust-lang/compiler-team#702
Fixes rust-lang#89339 (for MSVC targets using the MSVC linker only)
Supercedes rust-lang#89369

Successful x86_64-msvc build showing the sanitizer tests working: https://github.com/rust-lang/rust/actions/runs/7228346880/job/19697628258?pr=118521
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 4, 2024
Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag

This enables address sanitizer for x86_64-pc-windows-msvc and i686-pc-windows-msvc targets when linked with the MSVC linker (link.exe) by leveraging the `/INFERASANLIBS` option to automatically find and link in Microsoft's address sanitizer runtime: <https://learn.microsoft.com/en-us/cpp/sanitizers/asan-runtime?view=msvc-170>

Implements rust-lang/compiler-team#702
Fixes rust-lang#89339 (for MSVC targets using the MSVC linker only)
Supercedes rust-lang#89369

Successful x86_64-msvc build showing the sanitizer tests working: https://github.com/rust-lang/rust/actions/runs/7228346880/job/19697628258?pr=118521
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 4, 2024
Rollup merge of rust-lang#118521 - dpaoliello:asan, r=wesleywiser

Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag

This enables address sanitizer for x86_64-pc-windows-msvc and i686-pc-windows-msvc targets when linked with the MSVC linker (link.exe) by leveraging the `/INFERASANLIBS` option to automatically find and link in Microsoft's address sanitizer runtime: <https://learn.microsoft.com/en-us/cpp/sanitizers/asan-runtime?view=msvc-170>

Implements rust-lang/compiler-team#702
Fixes rust-lang#89339 (for MSVC targets using the MSVC linker only)
Supercedes rust-lang#89369

Successful x86_64-msvc build showing the sanitizer tests working: https://github.com/rust-lang/rust/actions/runs/7228346880/job/19697628258?pr=118521
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests

4 participants