|
1 | 1 | ---
|
2 | 2 | title: "AddressSanitizer runtime"
|
3 | 3 | description: "Technical description of the AddressSanitizer runtime for Microsoft C/C++."
|
4 |
| -ms.date: 03/02/2021 |
| 4 | +ms.date: 09/14/2023 |
5 | 5 | helpviewer_keywords: ["AddressSanitizer runtime", "Address Sanitizer runtime", "clang_rt.asan", "Clang runtime", "Asan runtime"]
|
6 | 6 | ---
|
7 | 7 |
|
8 | 8 | # AddressSanitizer runtime
|
9 | 9 |
|
10 | 10 | The AddressSanitizer runtime library intercepts common memory allocation functions and operations to enable inspection of memory accesses. There are several different runtime libraries that support the various types of executables the compiler may generate. The compiler and linker automatically link the appropriate runtime libraries, as long as you pass the [`/fsanitize=address`](../build/reference/fsanitize.md) option at compile time. You can override the default behavior by using the **`/NODEFAULTLIB`** option at link time. For more information, see the section on [linking](./asan-building.md#linker) in the [AddressSanitizer language, build, and debugging reference](./asan-building.md).
|
11 | 11 |
|
12 |
| -Below is an inventory of runtime libraries for linking to the AddressSanitizer runtime, where *`{arch}`* is either *`i386`* or *`x86_64`*. |
| 12 | +Below is an inventory of runtime libraries for linking to the AddressSanitizer runtime, where *`{arch}`* is either *`i386`* or *`x86_64`*, as of Visual Studio 17.7 Preview 3. |
13 | 13 |
|
14 | 14 | > [!NOTE]
|
15 | 15 | > These libraries keep the Clang conventions for architecture names. The MSVC conventions are normally x86 and x64 rather than i386 and x86_64. They refer to the same architectures.
|
| 16 | +> |
16 | 17 |
|
17 |
| -| CRT option | DLL or EXE | DEBUG? | AddressSanitizer runtime binaries libraries | |
18 |
| -|--|--|--|--| |
19 |
| -| MT | EXE | NO | *`clang_rt.asan-{arch}`*, *`clang_rt.asan_cxx-{arch}`* | |
20 |
| -| MT | DLL | NO | *`clang_rt.asan_dll_thunk-{arch}`* | |
21 |
| -| MD | EITHER | NO | *`clang_rt.asan_dynamic-{arch}`*, *`clang_rt.asan_dynamic_runtime_thunk-{arch}`* | |
22 |
| -| MT | EXE | YES | *`clang_rt.asan_dbg-{arch}`*, *`clang_rt.asan_dbg_cxx-{arch}`* | |
23 |
| -| MT | DLL | YES | *`clang_rt.asan_dbg_dll_thunk-{arch}`* | |
24 |
| -| MD | EITHER | YES | *`clang_rt.asan_dbg_dynamic-{arch}`*, *`clang_rt.asan_dbg_dynamic_runtime_thunk-{arch}`* | |
| 18 | +| CRT option | AddressSanitizer runtime library (.lib) | Address runtime binary (.dll) |
| 19 | +|--|--|--| |
| 20 | +| MT or MTd | *`clang_rt.asan_dynamic-{arch}`*, *`clang_rt.asan_static_runtime_thunk-{arch}`* | *`clang_rt.asan_dynamic-{arch}`* |
| 21 | +| MD or MDd | *`clang_rt.asan_dynamic-{arch}`*, *`clang_rt.asan_dynamic_runtime_thunk-{arch}`* | *`clang_rt.asan_dynamic-{arch}`* |
25 | 22 |
|
26 | 23 | When compiling with `cl /fsanitize=address`, the compiler generates instructions to manage and check the [shadow bytes](./asan-shadow-bytes.md). Your program uses this instrumentation to check memory accesses on the stack, in the heap, or in the global scope. The compiler also produces metadata describing stack and global variables. This metadata enables the runtime to generate precise error diagnostics: function names, lines, and columns in your source code. Combined, the compiler checks and runtime libraries can precisely diagnose many types of [memory safety bugs](./asan-error-examples.md) if they're encountered at run-time.
|
27 | 24 |
|
| 25 | +### Previous versions |
| 26 | + |
| 27 | +Prior to Visual Studio 17.7 Preview 3, statically linked (**`/MT`** or **`/MTd`**) builds did not use a DLL dependency and instead fully statically linked in the AddressSanitizer runtime into the user's EXE. DLL projects would then load exports from the user's EXE to access ASan functionality. Additionally, dynamically linked projects (**`/MD`** or **`/MTd`**) used different libraries and DLLs depending on whether the project was configured for debug or release. These changes and their motivations are discussed further on the MSVC Blog: [MSVC Address Sanitizer – One DLL for all Runtime Configurations](https://devblogs.microsoft.com/cppblog/msvc-address-sanitizer-one-dll-for-all-runtime-configurations/). |
| 28 | + |
| 29 | +| CRT option | DLL or EXE | DEBUG? | AddressSanitizer runtime binaries libraries | Address runtime binary (.dll) |
| 30 | +|--|--|--|--|--| |
| 31 | +| MT | EXE | No | *`clang_rt.asan-{arch}`*, *`clang_rt.asan_cxx-{arch}`* | None |
| 32 | +| MT | DLL | No | *`clang_rt.asan_dll_thunk-{arch}`* | None |
| 33 | +| MD | Either | No | *`clang_rt.asan_dynamic-{arch}`*, *`clang_rt.asan_dynamic_runtime_thunk-{arch}`* | *`clang_rt.asan_dynamic-{arch}`* |
| 34 | +| MT | EXE | Yes | *`clang_rt.asan_dbg-{arch}`*, *`clang_rt.asan_dbg_cxx-{arch}`* | None |
| 35 | +| MT | DLL | Yes | *`clang_rt.asan_dbg_dll_thunk-{arch}`* | None |
| 36 | +| MD | Either | Yes | *`clang_rt.asan_dbg_dynamic-{arch}`*, *`clang_rt.asan_dbg_dynamic_runtime_thunk-{arch}`* | *`clang_rt.asan_dbg_dynamic-{arch}`* |
| 37 | + |
28 | 38 | ## Function interception
|
29 | 39 |
|
30 | 40 | The AddressSanitizer achieves function interception through many hot-patching techniques. These techniques are [best documented within the source code itself](https://github.com/llvm/llvm-project/blob/1a2eaebc09c6a200f93b8beb37130c8b8aab3934/compiler-rt/lib/interception/interception_win.cpp#L11).
|
|
0 commit comments