Backport macOS ARM64 ASAN dynamic shadow offset from LLVM 12+ LLVM 10's AddressSanitizer pass uses the Linux ARM64 static shadow offset (0x1000000000) for ALL ARM64 targets, including macOS ARM64. However, macOS ARM64 requires a dynamic shadow offset because the ASAN runtime maps shadow memory at a different address (0x7000020000). This mismatch causes JIT-compiled shader code to compute wrong shadow addresses, hitting protected memory and crashing with SIGBUS (KERN_PROTECTION_FAILURE). Backport the fix from LLVM 12+ which adds an IsMacOS && IsAArch64 check to use kDynamicShadowSentinel (dynamic shadow offset) on macOS ARM64, matching what the ASAN runtime expects. LLVM change: https://github.com/llvm/llvm-project/commit/176a6e7abe33d58a65ce9cfac15fe320962e7b6e Bug: 493957482 Change-Id: I4d48bc41f89728d508d1937a1d767ea5a1576e6b Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/77208 Reviewed-by: Shahbaz Youssefi <syoussefi@google.com> Reviewed-by: Geoff Lang <geofflang@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@google.com> Tested-by: Shahbaz Youssefi <syoussefi@google.com>
diff --git a/third_party/llvm-10.0/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/third_party/llvm-10.0/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 79c1194..8199d5d 100644 --- a/third_party/llvm-10.0/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/third_party/llvm-10.0/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -427,6 +427,7 @@ bool IsKasan) { bool IsAndroid = TargetTriple.isAndroid(); bool IsIOS = TargetTriple.isiOS() || TargetTriple.isWatchOS(); + bool IsMacOS = TargetTriple.isMacOSX(); bool IsFreeBSD = TargetTriple.isOSFreeBSD(); bool IsNetBSD = TargetTriple.isOSNetBSD(); bool IsPS4CPU = TargetTriple.isPS4CPU(); @@ -503,6 +504,8 @@ Mapping.Offset = kMIPS64_ShadowOffset64; else if (IsIOS) Mapping.Offset = kDynamicShadowSentinel; + else if (IsMacOS && IsAArch64) + Mapping.Offset = kDynamicShadowSentinel; else if (IsAArch64) Mapping.Offset = kAArch64_ShadowOffset64; else