From 96ac849e9dbfcd792f4da01d35a18a94e4c3e937 Mon Sep 17 00:00:00 2001 From: Amy Wishnousky Date: Tue, 18 Feb 2025 14:00:07 -0800 Subject: [PATCH 1/7] Add documentation for kernel-address and asan compatibility libraries. --- docs/build/reference/fsanitize.md | 7 ++++++- docs/sanitizers/asan-building.md | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/build/reference/fsanitize.md b/docs/build/reference/fsanitize.md index 7fd5128bb78..d3dea8d891f 100644 --- a/docs/build/reference/fsanitize.md +++ b/docs/build/reference/fsanitize.md @@ -12,19 +12,24 @@ Use the **`/fsanitize`** compiler options to enable sanitizers. ## Syntax > **`/fsanitize=address`**\ +> **`/fsanitize=kernel-address`**\ > **`/fsanitize=fuzzer`**\ > **`/fsanitize-address-use-after-return`**\ > **`/fno-sanitize-address-vcasan-lib`** +> **`/fsanitize-address-asan-compat-lib`** +> **`/fno-sanitize-address-asan-compat-lib`** ## Remarks The **`/fsanitize=address`** compiler option enables [AddressSanitizer](../../sanitizers/asan.md), a powerful compiler and runtime technology to uncover [hard-to-find bugs](../../sanitizers/asan.md#error-types). Support for the **`/fsanitize=address`** option is available starting in Visual Studio 2019 version 16.9. +The **`/fsanitize=kernel-address`** compiler option enables [Kernel AddressSanitizer (KASan)](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/kasan). KASan is the kernel-mode variant of AddressSanitizer, available starting in Visual Studio 2022 version 17.11. KASan is only supported on Windows 11 24H2 or Windows Server 2025 and higher, and requires building using a Windows SDK 10.0.26100.2161 and higher. Building with KASan also implies the **`/fsanitize-address-asan-compat-lib`** compiler option. + The **`/fsanitize=fuzzer`** compiler option enables experimental support for [LibFuzzer](https://llvm.org/docs/LibFuzzer.html). LibFuzzer is a coverage-guided fuzzing library that can be used to find bugs and crashes caused by user-provided input. We recommended you use **`/fsanitize=address`** with LibFuzzer. This option is useful for fuzzing tools such as OneFuzz. For more information, see the [OneFuzz documentation](https://www.microsoft.com/research/project/project-onefuzz/) and [OneFuzz GitHub project](https://github.com/microsoft/onefuzz). Support for the **`/fsanitize=fuzzer`** option is available starting in Visual Studio 2022 version 17.0. The **`/fsanitize`** option doesn't allow comma-separated syntax, for example: **`/fsanitize=address,fuzzer`**. These options must be specified individually. -The **`/fsanitize-address-use-after-return`** and **`/fno-sanitize-address-vcasan-lib`** compiler options, and the [`/INFERASANLIBS` (Use inferred sanitizer libs)](./inferasanlibs.md) and **`/INFERASANLIBS:NO`** linker options offer support for advanced users. For more information, see [AddressSanitizer build and language reference](../../sanitizers/asan-building.md). +The **`/fsanitize-address-use-after-return`**, **`/fno-sanitize-address-vcasan-lib`**, **`/fsanitize-address-asan-compat-lib`**, and **`/fno-sanitize-address-asan-compat-lib`** compiler options, and the [`/INFERASANLIBS` (Use inferred sanitizer libs)](./inferasanlibs.md) and **`/INFERASANLIBS:NO`** linker options offer support for advanced users. For more information, see [AddressSanitizer build and language reference](../../sanitizers/asan-building.md). ### To set the **`/fsanitize=address`** compiler option in the Visual Studio development environment diff --git a/docs/sanitizers/asan-building.md b/docs/sanitizers/asan-building.md index e1255cb13f7..eb650221193 100644 --- a/docs/sanitizers/asan-building.md +++ b/docs/sanitizers/asan-building.md @@ -106,6 +106,14 @@ The dual stack frame in the heap remains after the return from the function that Stack frames are allocated in the heap and remain after functions return. The runtime uses garbage collection to asynchronously free these fake call-frame objects, after a certain time interval. Addresses of locals get transferred to persistent frames in the heap. It's how the system can detect when any locals get used after the defining function returns. For more information, see the [algorithm for stack use after return](https://github.com/google/sanitizers/wiki/AddressSanitizerUseAfterReturn) as documented by Google. +### ASan intrinsic compatibility library + +When building with ASan, the compiler replaces intrinsic functions (like, `memset`) with function calls provided by the ASan runtime library (like, `__asan_memset`) that will complete the same operation while also providing the memory safety checks characteristic of ASan. For user-mode ASan, the compiler and runtime are updated in lock-step as both are provided by Visual Studio. [Kernel-mode ASan (KASan)](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/kasan) is part of the Windows OS, so will update on a different cadence than the compiler. To avoid any issues with new compilers using new intrinsics that the installed version of KASan does not support, there is a compatibility library (`asan_compat.lib`) that can be linked to in order to avoid link-time issues. When using `asan_compat.lib`, the program will behave as though the unsupported ASan intrinsics are not in use. Linking with a newer runtime library that supports the new ASan intrinsics will supercede the versions provided by `asan_compat.lib`. This decision is made at link time, so it is imperative to link with the KASan library provided by the Windows SDK that matches the OS version you are targeting. + +To include this compatibility library as a default library, use the **`/fsanitize-address-asan-compat-lib`** compiler option. This option is automatically enabled when using **`/fsanitize=kernel-address`**. To opt-out of this compatibility library, use the **`/fno-sanitize-address-asan-compat-lib`** compiler option. + +While this option can be used to link a newer compiler with an older user-mode ASan runtime, this configuration is not currently supported. + ## Linker ### `/INFERASANLIBS[:NO]` linker option From ec9514eb65ce0d6bdac2023ac1deec6ac5803abc Mon Sep 17 00:00:00 2001 From: Amy Wishnousky Date: Tue, 18 Feb 2025 14:09:57 -0800 Subject: [PATCH 2/7] Add version info for fsanitize-address-asan-compat-lib option. --- docs/sanitizers/asan-building.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sanitizers/asan-building.md b/docs/sanitizers/asan-building.md index eb650221193..c401e03db9e 100644 --- a/docs/sanitizers/asan-building.md +++ b/docs/sanitizers/asan-building.md @@ -110,7 +110,7 @@ Stack frames are allocated in the heap and remain after functions return. The ru When building with ASan, the compiler replaces intrinsic functions (like, `memset`) with function calls provided by the ASan runtime library (like, `__asan_memset`) that will complete the same operation while also providing the memory safety checks characteristic of ASan. For user-mode ASan, the compiler and runtime are updated in lock-step as both are provided by Visual Studio. [Kernel-mode ASan (KASan)](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/kasan) is part of the Windows OS, so will update on a different cadence than the compiler. To avoid any issues with new compilers using new intrinsics that the installed version of KASan does not support, there is a compatibility library (`asan_compat.lib`) that can be linked to in order to avoid link-time issues. When using `asan_compat.lib`, the program will behave as though the unsupported ASan intrinsics are not in use. Linking with a newer runtime library that supports the new ASan intrinsics will supercede the versions provided by `asan_compat.lib`. This decision is made at link time, so it is imperative to link with the KASan library provided by the Windows SDK that matches the OS version you are targeting. -To include this compatibility library as a default library, use the **`/fsanitize-address-asan-compat-lib`** compiler option. This option is automatically enabled when using **`/fsanitize=kernel-address`**. To opt-out of this compatibility library, use the **`/fno-sanitize-address-asan-compat-lib`** compiler option. +To include this compatibility library as a default library, use the **`/fsanitize-address-asan-compat-lib`** compiler option. This option is automatically enabled when using **`/fsanitize=kernel-address`**. To opt-out of this compatibility library, use the **`/fno-sanitize-address-asan-compat-lib`** compiler option. These options are supported in Visual Studio 2022 17.14 Preview 2 and later. While this option can be used to link a newer compiler with an older user-mode ASan runtime, this configuration is not currently supported. From 9950b38528d2790134501ad2823e0861c09f1174 Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Tue, 18 Feb 2025 14:36:16 -0800 Subject: [PATCH 3/7] Update ASan building documentation for clarity I addressed some things (not all) that will generate acrolinx warnings. I made one change because what it was referring to wasn't clear to me, so I guessed. Did I get this right: Using **`/fsanitize-address-asan-compat-lib`** to link a newer compiler with an older user-mode ASan runtime isn't currently supported. --- docs/sanitizers/asan-building.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/sanitizers/asan-building.md b/docs/sanitizers/asan-building.md index c401e03db9e..3199bf376ed 100644 --- a/docs/sanitizers/asan-building.md +++ b/docs/sanitizers/asan-building.md @@ -7,7 +7,7 @@ helpviewer_keywords: ["ASan reference", "AddressSanitizer reference", "Address S --- # AddressSanitizer language, build, and debugging reference -The sections in this article describe the AddressSanitizer language specification, compiler options, and linker options. They also describe the options that control Visual Studio debugger integration specific to the AddressSanitizer. +This article describe the AddressSanitizer language specification, compiler options, linker options, and the options that control Visual Studio debugger integration specific to the AddressSanitizer. For more information on the AddressSanitizer runtime, see the [runtime reference](./asan-runtime.md). It includes information on intercepted functions and how to hook custom allocators. For more information on saving crash dumps from AddressSanitizer failures, see the [crash dump reference](./asan-offline-crash-dumps.md). @@ -108,11 +108,13 @@ Stack frames are allocated in the heap and remain after functions return. The ru ### ASan intrinsic compatibility library -When building with ASan, the compiler replaces intrinsic functions (like, `memset`) with function calls provided by the ASan runtime library (like, `__asan_memset`) that will complete the same operation while also providing the memory safety checks characteristic of ASan. For user-mode ASan, the compiler and runtime are updated in lock-step as both are provided by Visual Studio. [Kernel-mode ASan (KASan)](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/kasan) is part of the Windows OS, so will update on a different cadence than the compiler. To avoid any issues with new compilers using new intrinsics that the installed version of KASan does not support, there is a compatibility library (`asan_compat.lib`) that can be linked to in order to avoid link-time issues. When using `asan_compat.lib`, the program will behave as though the unsupported ASan intrinsics are not in use. Linking with a newer runtime library that supports the new ASan intrinsics will supercede the versions provided by `asan_compat.lib`. This decision is made at link time, so it is imperative to link with the KASan library provided by the Windows SDK that matches the OS version you are targeting. +When building with ASan, the compiler replaces intrinsic functions (like `memset`) with function calls provided by the ASan runtime library (like `__asan_memset`) that complete the same operation but also provide memory safety checks. For user-mode ASan, the compiler and runtime are updated together because Visual Studio provides both. [Kernel-mode ASan (KASan)](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/kasan) is part of the Windows OS, so it updates on a different cadence than the compiler. To avoid issues with a new compiler using new intrinsics that the installed version of KASan doesn't support, link the compatibility library (`asan_compat.lib`) to avoid link-time issues. When using `asan_compat.lib`, the program will behave as though the unsupported ASan intrinsics aren't used. Linking with a newer runtime library that supports the new ASan intrinsics supercedes the versions provided by `asan_compat.lib`. This decision is made at link time, so it is imperative to link with the KASan library provided by the Windows SDK that matches the OS version you are targeting. -To include this compatibility library as a default library, use the **`/fsanitize-address-asan-compat-lib`** compiler option. This option is automatically enabled when using **`/fsanitize=kernel-address`**. To opt-out of this compatibility library, use the **`/fno-sanitize-address-asan-compat-lib`** compiler option. These options are supported in Visual Studio 2022 17.14 Preview 2 and later. +The following options are supported in Visual Studio 2022 17.14 Preview 2 and later: +- To include this compatibility library as a default library, use the **`/fsanitize-address-asan-compat-lib`** compiler option. This option is automatically enabled when using **`/fsanitize=kernel-address`**.\ +- To opt-out of this compatibility library, use the **`/fno-sanitize-address-asan-compat-lib`** compiler option. -While this option can be used to link a newer compiler with an older user-mode ASan runtime, this configuration is not currently supported. +Using **`/fsanitize-address-asan-compat-lib`** to link a newer compiler with an older user-mode ASan runtime isn't currently supported. ## Linker From 91f601877e83a23acfd799c4722dcc1b0735fe2c Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Tue, 18 Feb 2025 14:41:17 -0800 Subject: [PATCH 4/7] Fix broken link in fsanitize documentation --- docs/build/reference/fsanitize.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/build/reference/fsanitize.md b/docs/build/reference/fsanitize.md index d3dea8d891f..6e9e8c94395 100644 --- a/docs/build/reference/fsanitize.md +++ b/docs/build/reference/fsanitize.md @@ -23,7 +23,7 @@ Use the **`/fsanitize`** compiler options to enable sanitizers. The **`/fsanitize=address`** compiler option enables [AddressSanitizer](../../sanitizers/asan.md), a powerful compiler and runtime technology to uncover [hard-to-find bugs](../../sanitizers/asan.md#error-types). Support for the **`/fsanitize=address`** option is available starting in Visual Studio 2019 version 16.9. -The **`/fsanitize=kernel-address`** compiler option enables [Kernel AddressSanitizer (KASan)](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/kasan). KASan is the kernel-mode variant of AddressSanitizer, available starting in Visual Studio 2022 version 17.11. KASan is only supported on Windows 11 24H2 or Windows Server 2025 and higher, and requires building using a Windows SDK 10.0.26100.2161 and higher. Building with KASan also implies the **`/fsanitize-address-asan-compat-lib`** compiler option. +The **`/fsanitize=kernel-address`** compiler option enables [Kernel AddressSanitizer (KASan)](/windows-hardware/drivers/devtest/kasan). KASan is the kernel-mode variant of AddressSanitizer, available starting in Visual Studio 2022 version 17.11. KASan is only supported on Windows 11 24H2 or Windows Server 2025 and higher, and requires building using a Windows SDK 10.0.26100.2161 and higher. Building with KASan also implies the **`/fsanitize-address-asan-compat-lib`** compiler option. The **`/fsanitize=fuzzer`** compiler option enables experimental support for [LibFuzzer](https://llvm.org/docs/LibFuzzer.html). LibFuzzer is a coverage-guided fuzzing library that can be used to find bugs and crashes caused by user-provided input. We recommended you use **`/fsanitize=address`** with LibFuzzer. This option is useful for fuzzing tools such as OneFuzz. For more information, see the [OneFuzz documentation](https://www.microsoft.com/research/project/project-onefuzz/) and [OneFuzz GitHub project](https://github.com/microsoft/onefuzz). Support for the **`/fsanitize=fuzzer`** option is available starting in Visual Studio 2022 version 17.0. From 55a91b986ec61d6a6ae9f46867fb1702dbe9a2b3 Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Tue, 18 Feb 2025 14:43:31 -0800 Subject: [PATCH 5/7] Fix broken link in ASan documentation --- docs/sanitizers/asan-building.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sanitizers/asan-building.md b/docs/sanitizers/asan-building.md index 3199bf376ed..ac0de8bdae9 100644 --- a/docs/sanitizers/asan-building.md +++ b/docs/sanitizers/asan-building.md @@ -108,7 +108,7 @@ Stack frames are allocated in the heap and remain after functions return. The ru ### ASan intrinsic compatibility library -When building with ASan, the compiler replaces intrinsic functions (like `memset`) with function calls provided by the ASan runtime library (like `__asan_memset`) that complete the same operation but also provide memory safety checks. For user-mode ASan, the compiler and runtime are updated together because Visual Studio provides both. [Kernel-mode ASan (KASan)](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/kasan) is part of the Windows OS, so it updates on a different cadence than the compiler. To avoid issues with a new compiler using new intrinsics that the installed version of KASan doesn't support, link the compatibility library (`asan_compat.lib`) to avoid link-time issues. When using `asan_compat.lib`, the program will behave as though the unsupported ASan intrinsics aren't used. Linking with a newer runtime library that supports the new ASan intrinsics supercedes the versions provided by `asan_compat.lib`. This decision is made at link time, so it is imperative to link with the KASan library provided by the Windows SDK that matches the OS version you are targeting. +When building with ASan, the compiler replaces intrinsic functions (like `memset`) with function calls provided by the ASan runtime library (like `__asan_memset`) that complete the same operation but also provide memory safety checks. For user-mode ASan, the compiler and runtime are updated together because Visual Studio provides both. [Kernel-mode ASan (KASan)](windows-hardware/drivers/devtest/kasan) is part of the Windows OS, so it updates on a different cadence than the compiler. To avoid issues with a new compiler using new intrinsics that the installed version of KASan doesn't support, link the compatibility library (`asan_compat.lib`) to avoid link-time issues. When using `asan_compat.lib`, the program will behave as though the unsupported ASan intrinsics aren't used. Linking with a newer runtime library that supports the new ASan intrinsics supercedes the versions provided by `asan_compat.lib`. This decision is made at link time, so it is imperative to link with the KASan library provided by the Windows SDK that matches the OS version you are targeting. The following options are supported in Visual Studio 2022 17.14 Preview 2 and later: - To include this compatibility library as a default library, use the **`/fsanitize-address-asan-compat-lib`** compiler option. This option is automatically enabled when using **`/fsanitize=kernel-address`**.\ From cad10fca478824bfcebf49e3640e51c26b79eedb Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Tue, 18 Feb 2025 14:49:58 -0800 Subject: [PATCH 6/7] Fix typos and improve clarity in ASan docs acrolinx --- docs/sanitizers/asan-building.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/sanitizers/asan-building.md b/docs/sanitizers/asan-building.md index ac0de8bdae9..bdab75809d2 100644 --- a/docs/sanitizers/asan-building.md +++ b/docs/sanitizers/asan-building.md @@ -7,7 +7,7 @@ helpviewer_keywords: ["ASan reference", "AddressSanitizer reference", "Address S --- # AddressSanitizer language, build, and debugging reference -This article describe the AddressSanitizer language specification, compiler options, linker options, and the options that control Visual Studio debugger integration specific to the AddressSanitizer. +This article describes the AddressSanitizer language specification, compiler options, linker options, and the options that control Visual Studio debugger integration specific to the AddressSanitizer. For more information on the AddressSanitizer runtime, see the [runtime reference](./asan-runtime.md). It includes information on intercepted functions and how to hook custom allocators. For more information on saving crash dumps from AddressSanitizer failures, see the [crash dump reference](./asan-offline-crash-dumps.md). @@ -58,7 +58,7 @@ void test3() { The [**`/fsanitize=address`**](../build/reference/fsanitize.md) compiler option instruments memory references in your code to catch memory safety errors at runtime. The instrumentation hooks loads, stores, scopes, `alloca`, and CRT functions. It can detect hidden bugs such as out-of-bounds, use-after-free, use-after-scope, and so on. For a nonexhaustive list of errors detected at runtime, see [AddressSanitizer error examples](./asan-error-examples.md). -**`/fsanitize=address`** is compatible with all existing C++ or C optimization levels (for example, **`/Od`**, **`/O1`**, **`/O2`**, and **`/O2 /GL`**). The code produced with this option works with static and dynamic CRTs (for example, **`/MD`**, **`/MDd`**, **`/MT`**, and **`/MTd`**). This compiler option can be used to create an .EXE or .DLL targeting x86 or x64. Debug information is required for optimal formatting of call stacks. This compiler option is not supported with profile guided optimization. +**`/fsanitize=address`** is compatible with all existing C++ or C optimization levels (for example, **`/Od`**, **`/O1`**, **`/O2`**, and **`/O2 /GL`**). The code produced with this option works with static and dynamic CRTs (for example, **`/MD`**, **`/MDd`**, **`/MT`**, and **`/MTd`**). This compiler option can be used to create an .EXE or .DLL targeting x86 or x64. Debug information is required for optimal formatting of call stacks. This compiler option isn't supported with profile guided optimization. For examples of code that demonstrates several kinds of error detection, see [AddressSanitizer error examples](asan-error-examples.md). @@ -108,7 +108,7 @@ Stack frames are allocated in the heap and remain after functions return. The ru ### ASan intrinsic compatibility library -When building with ASan, the compiler replaces intrinsic functions (like `memset`) with function calls provided by the ASan runtime library (like `__asan_memset`) that complete the same operation but also provide memory safety checks. For user-mode ASan, the compiler and runtime are updated together because Visual Studio provides both. [Kernel-mode ASan (KASan)](windows-hardware/drivers/devtest/kasan) is part of the Windows OS, so it updates on a different cadence than the compiler. To avoid issues with a new compiler using new intrinsics that the installed version of KASan doesn't support, link the compatibility library (`asan_compat.lib`) to avoid link-time issues. When using `asan_compat.lib`, the program will behave as though the unsupported ASan intrinsics aren't used. Linking with a newer runtime library that supports the new ASan intrinsics supercedes the versions provided by `asan_compat.lib`. This decision is made at link time, so it is imperative to link with the KASan library provided by the Windows SDK that matches the OS version you are targeting. +When building with ASan, the compiler replaces intrinsic functions (like `memset`) with function calls provided by the ASan runtime library (like `__asan_memset`) that complete the same operation but also provide memory safety checks. For user-mode ASan, the compiler and runtime are updated together because Visual Studio provides both. [Kernel-mode ASan (KASan)](windows-hardware/drivers/devtest/kasan) is part of the Windows OS, so it updates on a different cadence than the compiler. To avoid issues with a new compiler using new intrinsics that the installed version of KASan doesn't support, link the compatibility library (`asan_compat.lib`) to avoid link-time issues. When using `asan_compat.lib`, the program behaves as though the unsupported ASan intrinsics aren't used. Linking with a newer runtime library that supports the new ASan intrinsics supersedes the versions provided by `asan_compat.lib`. This decision is made at link time, so it's imperative to link with the KASan library provided by the Windows SDK that matches the OS version you're targeting. The following options are supported in Visual Studio 2022 17.14 Preview 2 and later: - To include this compatibility library as a default library, use the **`/fsanitize-address-asan-compat-lib`** compiler option. This option is automatically enabled when using **`/fsanitize=kernel-address`**.\ @@ -162,7 +162,7 @@ The library chosen depends on the compiler options, and is automatically linked | **`/MTd`** | *`libvcasand.lib`* | | **`/MDd`** | *`vcasand.lib`* | -However, if you compile using **`/Zl`** (Omit default library name), you must manually specify the library. If you don't, you'll get an unresolved external symbol link error. Here are some typical examples: +However, if you compile using **`/Zl`** (Omit default library name), you must manually specify the library. If you don't, you get an unresolved external symbol link error. Here are some typical examples: ```Output error LNK2001: unresolved external symbol __you_must_link_with_VCAsan_lib From b2fcee471180f21b9d1c87c11cd6341ca6993bf9 Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Tue, 18 Feb 2025 14:51:19 -0800 Subject: [PATCH 7/7] Fix broken link in ASan documentation --- docs/sanitizers/asan-building.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sanitizers/asan-building.md b/docs/sanitizers/asan-building.md index bdab75809d2..765cb85caa8 100644 --- a/docs/sanitizers/asan-building.md +++ b/docs/sanitizers/asan-building.md @@ -108,7 +108,7 @@ Stack frames are allocated in the heap and remain after functions return. The ru ### ASan intrinsic compatibility library -When building with ASan, the compiler replaces intrinsic functions (like `memset`) with function calls provided by the ASan runtime library (like `__asan_memset`) that complete the same operation but also provide memory safety checks. For user-mode ASan, the compiler and runtime are updated together because Visual Studio provides both. [Kernel-mode ASan (KASan)](windows-hardware/drivers/devtest/kasan) is part of the Windows OS, so it updates on a different cadence than the compiler. To avoid issues with a new compiler using new intrinsics that the installed version of KASan doesn't support, link the compatibility library (`asan_compat.lib`) to avoid link-time issues. When using `asan_compat.lib`, the program behaves as though the unsupported ASan intrinsics aren't used. Linking with a newer runtime library that supports the new ASan intrinsics supersedes the versions provided by `asan_compat.lib`. This decision is made at link time, so it's imperative to link with the KASan library provided by the Windows SDK that matches the OS version you're targeting. +When building with ASan, the compiler replaces intrinsic functions (like `memset`) with function calls provided by the ASan runtime library (like `__asan_memset`) that complete the same operation but also provide memory safety checks. For user-mode ASan, the compiler and runtime are updated together because Visual Studio provides both. [Kernel-mode ASan (KASan)](/windows-hardware/drivers/devtest/kasan) is part of the Windows OS, so it updates on a different cadence than the compiler. To avoid issues with a new compiler using new intrinsics that the installed version of KASan doesn't support, link the compatibility library (`asan_compat.lib`) to avoid link-time issues. When using `asan_compat.lib`, the program behaves as though the unsupported ASan intrinsics aren't used. Linking with a newer runtime library that supports the new ASan intrinsics supersedes the versions provided by `asan_compat.lib`. This decision is made at link time, so it's imperative to link with the KASan library provided by the Windows SDK that matches the OS version you're targeting. The following options are supported in Visual Studio 2022 17.14 Preview 2 and later: - To include this compatibility library as a default library, use the **`/fsanitize-address-asan-compat-lib`** compiler option. This option is automatically enabled when using **`/fsanitize=kernel-address`**.\