Skip to content

Commit d5c516e

Browse files
kubamraceknikic
authored andcommitted
[asan] Use dynamic shadow memory position on Apple Silicon macOS
This is needed because macOS on Apple Silicon has some reserved pages inside the "regular" shadow memory location, and mapping over that location fails. Differential Revision: https://reviews.llvm.org/D82912
1 parent 8d78ad1 commit d5c516e

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

compiler-rt/lib/asan/asan_mapping.h

+2
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ static const u64 kMyriadCacheBitMask32 = 0x40000000ULL;
206206
#else
207207
# if SANITIZER_IOS
208208
# define SHADOW_OFFSET __asan_shadow_memory_dynamic_address
209+
# elif SANITIZER_MAC && defined(__aarch64__)
210+
# define SHADOW_OFFSET __asan_shadow_memory_dynamic_address
209211
# elif defined(__aarch64__)
210212
# define SHADOW_OFFSET kAArch64_ShadowOffset64
211213
# elif defined(__powerpc64__)

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ static ShadowMapping getShadowMapping(Triple &TargetTriple, int LongSize,
434434
bool IsKasan) {
435435
bool IsAndroid = TargetTriple.isAndroid();
436436
bool IsIOS = TargetTriple.isiOS() || TargetTriple.isWatchOS();
437+
bool IsMacOS = TargetTriple.isMacOSX();
437438
bool IsFreeBSD = TargetTriple.isOSFreeBSD();
438439
bool IsNetBSD = TargetTriple.isOSNetBSD();
439440
bool IsPS4CPU = TargetTriple.isPS4CPU();
@@ -510,6 +511,8 @@ static ShadowMapping getShadowMapping(Triple &TargetTriple, int LongSize,
510511
Mapping.Offset = kMIPS64_ShadowOffset64;
511512
else if (IsIOS)
512513
Mapping.Offset = kDynamicShadowSentinel;
514+
else if (IsMacOS && IsAArch64)
515+
Mapping.Offset = kDynamicShadowSentinel;
513516
else if (IsAArch64)
514517
Mapping.Offset = kAArch64_ShadowOffset64;
515518
else

llvm/test/Instrumentation/AddressSanitizer/dynamic-shadow-darwin.ll

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
; RUN: opt -asan -asan-module -mtriple=i386-apple-ios-simulator --data-layout="e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128" -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-DYNAMIC -DPTR_SIZE=32
99
; RUN: opt -asan -asan-module -mtriple=x86_64-apple-ios-simulator --data-layout="e-m:o-i64:64-f80:128-n8:16:32:64-S128" -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-DYNAMIC -DPTR_SIZE=64
1010
;
11-
; // macOS does not use dynamic shadow placement
11+
; // macOS does not use dynamic shadow placement on x86_64
1212
; RUN: opt -asan -asan-module -mtriple=x86_64-apple-macosx --data-layout="e-m:o-i64:64-f80:128-n8:16:32:64-S128" -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-NONDYNAMIC -DPTR_SIZE=64
13+
; // macOS does use dynamic shadow placement on arm64
14+
; RUN: opt -asan -asan-module -mtriple=arm64-apple-macosx --data-layout="e-m:o-i64:64-i128:128-n32:64-S128" -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-DYNAMIC -DPTR_SIZE=64
1315

1416
define i32 @test_load(i32* %a) sanitize_address {
1517
; First instrumentation in the function must be to load the dynamic shadow

0 commit comments

Comments
 (0)