Skip to content

[20210107] Cherry-pick 8a8fa09: [tsan] Use large address space mapping on Apple Silicon Macs #2637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions compiler-rt/lib/tsan/rtl/tsan_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,21 @@

namespace __tsan {

#if defined(__x86_64__)
#define HAS_48_BIT_ADDRESS_SPACE 1
#elif SANITIZER_IOSSIM // arm64 iOS simulators (order of #if matters)
#define HAS_48_BIT_ADDRESS_SPACE 1
#elif SANITIZER_IOS // arm64 iOS devices (order of #if matters)
#define HAS_48_BIT_ADDRESS_SPACE 0
#elif SANITIZER_MAC // arm64 macOS (order of #if matters)
#define HAS_48_BIT_ADDRESS_SPACE 1
#else
#define HAS_48_BIT_ADDRESS_SPACE 0
#endif

#if !SANITIZER_GO

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

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

#elif SANITIZER_GO && !SANITIZER_WINDOWS && defined(__x86_64__)
#elif SANITIZER_GO && !SANITIZER_WINDOWS && HAS_48_BIT_ADDRESS_SPACE

/* Go on linux, darwin and freebsd on x86_64
0000 0000 1000 - 0000 1000 0000: executable
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ static void my_pthread_introspection_hook(unsigned int event, pthread_t thread,
#endif

void InitializePlatformEarly() {
#if !SANITIZER_GO && defined(__aarch64__)
#if !SANITIZER_GO && !HAS_48_BIT_ADDRESS_SPACE
uptr max_vm = GetMaxUserVirtualAddress() + 1;
if (max_vm != Mapping::kHiAppMemEnd) {
Printf("ThreadSanitizer: unsupported vm address limit %p, expected %p.\n",
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/tsan/rtl/tsan_platform_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void CheckAndProtect() {
Die();
}

#if defined(__aarch64__) && defined(__APPLE__)
#if defined(__aarch64__) && !HAS_48_BIT_ADDRESS_SPACE
ProtectRange(HeapMemEnd(), ShadowBeg());
ProtectRange(ShadowEnd(), MetaShadowBeg());
ProtectRange(MetaShadowEnd(), TraceMemBeg());
Expand Down