From 3b5806f2d91f68027d15789a8b267d5a9f8bfe6e Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Wed, 10 Dec 2025 21:17:46 -0800 Subject: [PATCH 1/6] Add x86_64-asan-windows-msvc target --- compiler/rustc_target/src/spec/mod.rs | 2 ++ .../src/spec/targets/x86_64_asan_windows_msvc.rs | 16 ++++++++++++++++ src/bootstrap/src/core/sanity.rs | 1 + 3 files changed, 19 insertions(+) create mode 100644 compiler/rustc_target/src/spec/targets/x86_64_asan_windows_msvc.rs diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index c76e345bb7b64..f1d2e22f1792d 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1800,6 +1800,8 @@ supported_targets! { ("x86_64-lynx-lynxos178", x86_64_lynx_lynxos178), ("x86_64-pc-cygwin", x86_64_pc_cygwin), + + ("x86_64-asan-windows-msvc", x86_64_asan_windows_msvc), } /// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]> diff --git a/compiler/rustc_target/src/spec/targets/x86_64_asan_windows_msvc.rs b/compiler/rustc_target/src/spec/targets/x86_64_asan_windows_msvc.rs new file mode 100644 index 0000000000000..d85fbcb2cb2fe --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/x86_64_asan_windows_msvc.rs @@ -0,0 +1,16 @@ +use crate::spec::{SanitizerSet, Target, TargetMetadata}; + +pub(crate) fn target() -> Target { + let mut base = super::x86_64_pc_windows_msvc::target(); + base.metadata = TargetMetadata { + description: Some("64-bit Windows with ASAN enabled by default".into()), + tier: Some(3), + host_tools: Some(false), + std: Some(true), + }; + base.options.default_sanitizers = SanitizerSet::ADDRESS; + + assert!(base.options.default_sanitizers.contains(SanitizerSet::ADDRESS)); + + base +} diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index 50d8154014bbc..81267793f7f23 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -42,6 +42,7 @@ const STAGE0_MISSING_TARGETS: &[&str] = &[ // just a dummy comment so the list doesn't get onelined "riscv64gc-unknown-redox", "hexagon-unknown-qurt", + "x86_64-asan-windows-msvc", ]; /// Minimum version threshold for libstdc++ required when using prebuilt LLVM From 5935819199a993ec89f45359e0ee1cf12e2ef617 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 11 Dec 2025 11:03:57 -0800 Subject: [PATCH 2/6] Add x86_64-asan-windows-msvc LLVM assembly test --- tests/assembly-llvm/targets/targets-pe.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/assembly-llvm/targets/targets-pe.rs b/tests/assembly-llvm/targets/targets-pe.rs index 2f4472ac74d9b..310886c54aa24 100644 --- a/tests/assembly-llvm/targets/targets-pe.rs +++ b/tests/assembly-llvm/targets/targets-pe.rs @@ -67,6 +67,9 @@ //@ revisions: x86_64_pc_windows_msvc //@ [x86_64_pc_windows_msvc] compile-flags: --target x86_64-pc-windows-msvc //@ [x86_64_pc_windows_msvc] needs-llvm-components: x86 +//@ revisions: x86_64_asan_windows_msvc +//@ [x86_64_asan_windows_msvc] compile-flags: --target x86_64-asan-windows-msvc +//@ [x86_64_asan_windows_msvc] needs-llvm-components: x86 //@ revisions: x86_64_unknown_uefi //@ [x86_64_unknown_uefi] compile-flags: --target x86_64-unknown-uefi //@ [x86_64_unknown_uefi] needs-llvm-components: x86 From 02e232fbe83b0be1c3f35f6e20c237073aec40b3 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 11 Dec 2025 12:57:17 -0800 Subject: [PATCH 3/6] Add documentation for x86_64-asan-windows-msvc --- src/doc/rustc/src/SUMMARY.md | 1 + src/doc/rustc/src/platform-support.md | 1 + .../x86_64-asan-windows-msvc.md | 58 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 832b5a69d47c4..f31b66551a23e 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -146,6 +146,7 @@ - [windows-gnullvm](platform-support/windows-gnullvm.md) - [\*-win7-windows-gnu](platform-support/win7-windows-gnu.md) - [\*-win7-windows-msvc](platform-support/win7-windows-msvc.md) + - [x86_64-asan-windows-msvc](platform-support/x86_64-asan-windows-msvc.md) - [x86_64-fortanix-unknown-sgx](platform-support/x86_64-fortanix-unknown-sgx.md) - [x86_64-pc-cygwin](platform-support/x86_64-pc-cygwin.md) - [x86_64-unknown-linux-none](platform-support/x86_64-unknown-linux-none.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index d772702df76e2..1886616699dad 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -425,6 +425,7 @@ target | std | host | notes [`wasm32-wasip3`](platform-support/wasm32-wasip3.md) | ✓ | WebAssembly with WASIp3 [`x86_64-apple-tvos`](platform-support/apple-tvos.md) | ✓ | | x86 64-bit tvOS [`x86_64-apple-watchos-sim`](platform-support/apple-watchos.md) | ✓ | | x86 64-bit Apple WatchOS simulator +[`x86_64-asan-windows-msvc`](platform-support/x86_64-asan-windows-msvc.md) | ✓ | | x86 64-bit Windows with AddressSanitizer [`x86_64-lynx-lynxos178`](platform-support/lynxos178.md) | | | x86_64 LynxOS-178 [`x86_64-pc-cygwin`](platform-support/x86_64-pc-cygwin.md) | ✓ | | 64-bit x86 Cygwin | [`x86_64-pc-nto-qnx710`](platform-support/nto-qnx.md) | ✓ | | x86 64-bit QNX Neutrino 7.1 RTOS with default network stack (io-pkt) | diff --git a/src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md b/src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md new file mode 100644 index 0000000000000..8de2931ca5bca --- /dev/null +++ b/src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md @@ -0,0 +1,58 @@ +# `x86_64-asan-windows-msvc` + +**Tier: 3** + +Target mirror `x86_64-pc-windows-msvc` with AddressSanitizer enabled by default. + +## Target maintainers + +[@ChrisDenton](https://github.com/ChrisDenton) +[@dpaoliello](https://github.com/dpaoliello) +[@eholk](https://github.com/eholk) +[@Fulgen301](https://github.com/Fulgen301) +[@lambdageek](https://github.com/lambdageek) +[@sivadeilra](https://github.com/sivadeilra) +[@wesleywiser](https://github.com/wesleywiser) + +## Requirements + +This target is for cross-compilation only. Host tools are not supported because +this target's primary use cases do not require the host tools to be instrumented +with AddressSanitizer. The standard library is fully supported. + +In all other aspects, this target is identical to `x86_64-pc-windows-msvc`. + +## Building the target + +This target can be built by adding it to the `target` list in `bootstrap.toml`. + +```toml +[build] +target = ["x86_64-asan-windows-msvc"] +``` + +## Building Rust programs + +Rust does not yet ship pre-compiled artifacts for this target. To compile for +this target, you will either need to build Rust with the target enabled (see +"Building the target" above), or build your own copy of `core` by using +`build-std` or similar. + +Compilation can be done with: + +```sh +rustc --target x86_64-asan-windows-msvc my_program.rs +``` + +## Testing + +Programs compiled for this target require `clang_rt.asan_dynamic-x86_64.dll` to +be available. This can be installed by using the Visual Studio Installer to +install the C++ AddressSanitizer component. Once installed, add the directory +containing the DLL to your `PATH`. + +## Cross-compilation toolchains and C code + +Architectural cross-compilation from one Windows host to a different Windows +platform is natively supported by the MSVC toolchain provided the appropriate +components are selected when using the VS Installer. From c62e6d0f17782c7f22031aac15162bd101697528 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 11 Dec 2025 14:14:41 -0800 Subject: [PATCH 4/6] Add a mention about the VS Developer Command Prompt --- src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md b/src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md index 8de2931ca5bca..405c2d0841df5 100644 --- a/src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md +++ b/src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md @@ -49,7 +49,8 @@ rustc --target x86_64-asan-windows-msvc my_program.rs Programs compiled for this target require `clang_rt.asan_dynamic-x86_64.dll` to be available. This can be installed by using the Visual Studio Installer to install the C++ AddressSanitizer component. Once installed, add the directory -containing the DLL to your `PATH`. +containing the DLL to your `PATH` or run your program from a Visual Studio +Developer Command Prompt. ## Cross-compilation toolchains and C code From bc86986b74c0b9d76a1d331a9cad39f946ee6688 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 11 Dec 2025 15:29:00 -0800 Subject: [PATCH 5/6] Update src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Aleksey Kliger (λgeek) --- src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md b/src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md index 405c2d0841df5..6d5bdd6f026d7 100644 --- a/src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md +++ b/src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md @@ -2,7 +2,7 @@ **Tier: 3** -Target mirror `x86_64-pc-windows-msvc` with AddressSanitizer enabled by default. +Target mirrors `x86_64-pc-windows-msvc` with AddressSanitizer enabled by default. ## Target maintainers From 541478e893cb09e75a106f9b2cd9c5ac25fbc7b5 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 11 Dec 2025 15:48:25 -0800 Subject: [PATCH 6/6] Add aarch64-asan-windows-msvc target --- compiler/rustc_target/src/spec/mod.rs | 1 + .../spec/targets/aarch64_asan_windows_msvc.rs | 16 ++++++++++ src/bootstrap/src/core/sanity.rs | 1 + src/doc/rustc/src/SUMMARY.md | 2 +- src/doc/rustc/src/platform-support.md | 2 +- ...n-windows-msvc.md => asan-windows-msvc.md} | 31 +++++++++++++------ tests/assembly-llvm/targets/targets-pe.rs | 3 ++ 7 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 compiler/rustc_target/src/spec/targets/aarch64_asan_windows_msvc.rs rename src/doc/rustc/src/platform-support/{x86_64-asan-windows-msvc.md => asan-windows-msvc.md} (64%) diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index f1d2e22f1792d..52f3155aa379d 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1802,6 +1802,7 @@ supported_targets! { ("x86_64-pc-cygwin", x86_64_pc_cygwin), ("x86_64-asan-windows-msvc", x86_64_asan_windows_msvc), + ("aarch64-asan-windows-msvc", aarch64_asan_windows_msvc), } /// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]> diff --git a/compiler/rustc_target/src/spec/targets/aarch64_asan_windows_msvc.rs b/compiler/rustc_target/src/spec/targets/aarch64_asan_windows_msvc.rs new file mode 100644 index 0000000000000..82c8c886e67d3 --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/aarch64_asan_windows_msvc.rs @@ -0,0 +1,16 @@ +use crate::spec::{SanitizerSet, Target, TargetMetadata}; + +pub(crate) fn target() -> Target { + let mut base = super::aarch64_pc_windows_msvc::target(); + base.metadata = TargetMetadata { + description: Some("64-bit Windows on ARM with ASAN enabled by default".into()), + tier: Some(3), + host_tools: Some(false), + std: Some(true), + }; + base.options.default_sanitizers = SanitizerSet::ADDRESS; + + assert!(base.options.default_sanitizers.contains(SanitizerSet::ADDRESS)); + + base +} diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index 81267793f7f23..7d68a683f3421 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -42,6 +42,7 @@ const STAGE0_MISSING_TARGETS: &[&str] = &[ // just a dummy comment so the list doesn't get onelined "riscv64gc-unknown-redox", "hexagon-unknown-qurt", + "aarch64-asan-windows-msvc", "x86_64-asan-windows-msvc", ]; diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index f31b66551a23e..c4e0ec90b5c84 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -146,7 +146,7 @@ - [windows-gnullvm](platform-support/windows-gnullvm.md) - [\*-win7-windows-gnu](platform-support/win7-windows-gnu.md) - [\*-win7-windows-msvc](platform-support/win7-windows-msvc.md) - - [x86_64-asan-windows-msvc](platform-support/x86_64-asan-windows-msvc.md) + - [\*-asan-windows-msvc](platform-support/asan-windows-msvc.md) - [x86_64-fortanix-unknown-sgx](platform-support/x86_64-fortanix-unknown-sgx.md) - [x86_64-pc-cygwin](platform-support/x86_64-pc-cygwin.md) - [x86_64-unknown-linux-none](platform-support/x86_64-unknown-linux-none.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 1886616699dad..1237b731cc431 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -425,7 +425,7 @@ target | std | host | notes [`wasm32-wasip3`](platform-support/wasm32-wasip3.md) | ✓ | WebAssembly with WASIp3 [`x86_64-apple-tvos`](platform-support/apple-tvos.md) | ✓ | | x86 64-bit tvOS [`x86_64-apple-watchos-sim`](platform-support/apple-watchos.md) | ✓ | | x86 64-bit Apple WatchOS simulator -[`x86_64-asan-windows-msvc`](platform-support/x86_64-asan-windows-msvc.md) | ✓ | | x86 64-bit Windows with AddressSanitizer +[`*-asan-windows-msvc`](platform-support/asan-windows-msvc.md) | ✓ | | 64-bit Windows with AddressSanitizer [`x86_64-lynx-lynxos178`](platform-support/lynxos178.md) | | | x86_64 LynxOS-178 [`x86_64-pc-cygwin`](platform-support/x86_64-pc-cygwin.md) | ✓ | | 64-bit x86 Cygwin | [`x86_64-pc-nto-qnx710`](platform-support/nto-qnx.md) | ✓ | | x86 64-bit QNX Neutrino 7.1 RTOS with default network stack (io-pkt) | diff --git a/src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md b/src/doc/rustc/src/platform-support/asan-windows-msvc.md similarity index 64% rename from src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md rename to src/doc/rustc/src/platform-support/asan-windows-msvc.md index 6d5bdd6f026d7..9fda789ea3014 100644 --- a/src/doc/rustc/src/platform-support/x86_64-asan-windows-msvc.md +++ b/src/doc/rustc/src/platform-support/asan-windows-msvc.md @@ -1,8 +1,11 @@ -# `x86_64-asan-windows-msvc` +# `*-asan-windows-msvc` **Tier: 3** -Target mirrors `x86_64-pc-windows-msvc` with AddressSanitizer enabled by default. +- `aarch64-asan-windows-msvc` +- `x86_64-asan-windows-msvc` + +These targets mirror `*-pc-windows-msvc` with AddressSanitizer enabled by default. ## Target maintainers @@ -20,7 +23,7 @@ This target is for cross-compilation only. Host tools are not supported because this target's primary use cases do not require the host tools to be instrumented with AddressSanitizer. The standard library is fully supported. -In all other aspects, this target is identical to `x86_64-pc-windows-msvc`. +In all other aspects, this target is identical to `*-pc-windows-msvc`. ## Building the target @@ -28,7 +31,10 @@ This target can be built by adding it to the `target` list in `bootstrap.toml`. ```toml [build] -target = ["x86_64-asan-windows-msvc"] +target = [ + "aarch64-asan-windows-msvc", + "x86_64-asan-windows-msvc" +] ``` ## Building Rust programs @@ -40,17 +46,24 @@ this target, you will either need to build Rust with the target enabled (see Compilation can be done with: +aarch64: +```sh +rustc --target aarch64-asan-windows-msvc my_program.rs +``` + + +x86_64: ```sh rustc --target x86_64-asan-windows-msvc my_program.rs ``` ## Testing -Programs compiled for this target require `clang_rt.asan_dynamic-x86_64.dll` to -be available. This can be installed by using the Visual Studio Installer to -install the C++ AddressSanitizer component. Once installed, add the directory -containing the DLL to your `PATH` or run your program from a Visual Studio -Developer Command Prompt. +Programs compiled for this target require the `clang_rt.asan_dynamic-*.dll` +corresponding to the target CPU architecture. This can be installed by using the +Visual Studio Installer to install the C++ AddressSanitizer component. Once +installed, add the directory containing the DLL to your `PATH` or run your +program from a Visual Studio Developer Command Prompt. ## Cross-compilation toolchains and C code diff --git a/tests/assembly-llvm/targets/targets-pe.rs b/tests/assembly-llvm/targets/targets-pe.rs index 310886c54aa24..4293cb28674d9 100644 --- a/tests/assembly-llvm/targets/targets-pe.rs +++ b/tests/assembly-llvm/targets/targets-pe.rs @@ -1,6 +1,9 @@ //@ add-minicore //@ assembly-output: emit-asm // ignore-tidy-linelength +//@ revisions: aarch64_asan_windows_msvc +//@ [aarch64_asan_windows_msvc] compile-flags: --target aarch64-asan-windows-msvc +//@ [aarch64_asan_windows_msvc] needs-llvm-components: arm //@ revisions: aarch64_pc_windows_msvc //@ [aarch64_pc_windows_msvc] compile-flags: --target aarch64-pc-windows-msvc //@ [aarch64_pc_windows_msvc] needs-llvm-components: aarch64