diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index c76e345bb7b64..52f3155aa379d 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1800,6 +1800,9 @@ 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), + ("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/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..7d68a683f3421 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -42,6 +42,8 @@ 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", ]; /// Minimum version threshold for libstdc++ required when using prebuilt LLVM diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 832b5a69d47c4..c4e0ec90b5c84 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) + - [\*-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 d772702df76e2..1237b731cc431 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 +[`*-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/asan-windows-msvc.md b/src/doc/rustc/src/platform-support/asan-windows-msvc.md new file mode 100644 index 0000000000000..9fda789ea3014 --- /dev/null +++ b/src/doc/rustc/src/platform-support/asan-windows-msvc.md @@ -0,0 +1,72 @@ +# `*-asan-windows-msvc` + +**Tier: 3** + +- `aarch64-asan-windows-msvc` +- `x86_64-asan-windows-msvc` + +These targets mirror `*-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 `*-pc-windows-msvc`. + +## Building the target + +This target can be built by adding it to the `target` list in `bootstrap.toml`. + +```toml +[build] +target = [ + "aarch64-asan-windows-msvc", + "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: + +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 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 + +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. diff --git a/tests/assembly-llvm/targets/targets-pe.rs b/tests/assembly-llvm/targets/targets-pe.rs index 2f4472ac74d9b..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 @@ -67,6 +70,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