[llvm] c172000 - [ASan][Windows] Fixing Windows shadow memory address for arm64 (#184902)

via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 6 12:57:41 PST 2026


Author: Zack Johnson
Date: 2026-03-06T15:57:37-05:00
New Revision: c17200033d057aa490fe5b68bb0c9d10cd9d67c9

URL: https://github.com/llvm/llvm-project/commit/c17200033d057aa490fe5b68bb0c9d10cd9d67c9
DIFF: https://github.com/llvm/llvm-project/commit/c17200033d057aa490fe5b68bb0c9d10cd9d67c9.diff

LOG: [ASan][Windows] Fixing Windows shadow memory address for arm64 (#184902)

This is a prerequisite for full ARM64 Windows ASan support. The runtime
interception changes needed to make ASan functional end-to-end on ARM64
Windows will be opened separately.

Motivated by https://github.com/microsoft/STL/pull/6095 (more
specifically [this reference to
clang-cl](https://github.com/microsoft/STL/pull/6095#:~:text=Not%20enabling%20GH_002030_asan_annotate_string%20and%20GH_002030_asan_annotate_vector%20yet%20due%20to%20Clang%20issues.))

The latest MSVC toolset includes ARM64 AddressSanitizer support. This
change adds AArch64 to the Windows 64-bit shadow mapping condition when
compiling with `-fsanitize=address` with `clang-cl`. Without this,
consumers on Windows who target ARM64 with `clang-cl -fsanitize=address`
and then link with `link.exe` will see this at runtime:

```text
ERROR: AddressSanitizer: access-violation on unknown address
...
```

since the shadow memory offset is not properly assigned. Windows ARM64
uses the same dynamic shadow allocation strategy as x64 via
`__asan_shadow_memory_dynamic_address`.

Added: 
    

Modified: 
    llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
    llvm/test/Instrumentation/AddressSanitizer/basic-msvc64.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index d4a1b7b7813d0..aaaa02c1f0a1c 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -576,7 +576,7 @@ static ShadowMapping getShadowMapping(const Triple &TargetTriple, int LongSize,
       else
         Mapping.Offset = (kSmallX86_64ShadowOffsetBase &
                           (kSmallX86_64ShadowOffsetAlignMask << Mapping.Scale));
-    } else if (IsWindows && IsX86_64) {
+    } else if (IsWindows && (IsX86_64 || IsAArch64)) {
       Mapping.Offset = kWindowsShadowOffset64;
     } else if (IsMIPS64)
       Mapping.Offset = kMIPS64_ShadowOffset64;

diff  --git a/llvm/test/Instrumentation/AddressSanitizer/basic-msvc64.ll b/llvm/test/Instrumentation/AddressSanitizer/basic-msvc64.ll
index 4e0424d1cbc24..4d0887ba39311 100644
--- a/llvm/test/Instrumentation/AddressSanitizer/basic-msvc64.ll
+++ b/llvm/test/Instrumentation/AddressSanitizer/basic-msvc64.ll
@@ -1,8 +1,8 @@
 ; Test basic address sanitizer instrumentation.
 ;
-; RUN: opt -passes=asan -S  < %s | FileCheck %s
+; RUN: opt -passes=asan -mtriple=x86_64-pc-windows-msvc -S < %s | FileCheck %s
+; RUN: opt -passes=asan -mtriple=aarch64-pc-windows-msvc -S < %s | FileCheck %s
 
-target triple = "x86_64-pc-windows-msvc"
 ; CHECK: @llvm.global_ctors = {{.*}}@asan.module_ctor
 
 define i32 @test_load(ptr %a) sanitize_address {


        


More information about the llvm-commits mailing list