Skip to content

Commit a521cd8

Browse files
committed
[tsan] Use large address space mapping on Apple Silicon Macs
Differential Revision: https://reviews.llvm.org/D86377
1 parent 63fd366 commit a521cd8

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

compiler-rt/lib/tsan/rtl/tsan_platform.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,21 @@
2323

2424
namespace __tsan {
2525

26+
#if defined(__x86_64__)
27+
#define HAS_48_BIT_ADDRESS_SPACE 1
28+
#elif SANITIZER_IOSSIM // arm64 iOS simulators (order of #if matters)
29+
#define HAS_48_BIT_ADDRESS_SPACE 1
30+
#elif SANITIZER_IOS // arm64 iOS devices (order of #if matters)
31+
#define HAS_48_BIT_ADDRESS_SPACE 0
32+
#elif SANITIZER_MAC // arm64 macOS (order of #if matters)
33+
#define HAS_48_BIT_ADDRESS_SPACE 1
34+
#else
35+
#define HAS_48_BIT_ADDRESS_SPACE 0
36+
#endif
37+
2638
#if !SANITIZER_GO
2739

28-
#if defined(__x86_64__)
40+
#if HAS_48_BIT_ADDRESS_SPACE
2941
/*
3042
C/C++ on linux/x86_64 and freebsd/x86_64
3143
0000 0000 1000 - 0080 0000 0000: main binary and/or MAP_32BIT mappings (512GB)
@@ -146,7 +158,7 @@ struct Mapping {
146158
static const uptr kVdsoBeg = 0x7000000000000000ull;
147159
};
148160

149-
#elif defined(__aarch64__)
161+
#elif defined(__aarch64__) && !defined(__APPLE__)
150162
// AArch64 supports multiple VMA which leads to multiple address transformation
151163
// functions. To support these multiple VMAS transformations and mappings TSAN
152164
// runtime for AArch64 uses an external memory read (vmaSize) to select which
@@ -354,7 +366,7 @@ struct Mapping47 {
354366
#define TSAN_RUNTIME_VMA 1
355367
#endif
356368

357-
#elif SANITIZER_GO && !SANITIZER_WINDOWS && defined(__x86_64__)
369+
#elif SANITIZER_GO && !SANITIZER_WINDOWS && HAS_48_BIT_ADDRESS_SPACE
358370

359371
/* Go on linux, darwin and freebsd on x86_64
360372
0000 0000 1000 - 0000 1000 0000: executable

compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static void my_pthread_introspection_hook(unsigned int event, pthread_t thread,
234234
#endif
235235

236236
void InitializePlatformEarly() {
237-
#if !SANITIZER_GO && defined(__aarch64__)
237+
#if !SANITIZER_GO && !HAS_48_BIT_ADDRESS_SPACE
238238
uptr max_vm = GetMaxUserVirtualAddress() + 1;
239239
if (max_vm != Mapping::kHiAppMemEnd) {
240240
Printf("ThreadSanitizer: unsupported vm address limit %p, expected %p.\n",

compiler-rt/lib/tsan/rtl/tsan_platform_posix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void CheckAndProtect() {
9999
Die();
100100
}
101101

102-
#if defined(__aarch64__) && defined(__APPLE__)
102+
#if defined(__aarch64__) && !HAS_48_BIT_ADDRESS_SPACE
103103
ProtectRange(HeapMemEnd(), ShadowBeg());
104104
ProtectRange(ShadowEnd(), MetaShadowBeg());
105105
ProtectRange(MetaShadowEnd(), TraceMemBeg());

0 commit comments

Comments
 (0)