diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp @@ -606,12 +606,22 @@ return result; } +// This corresponds to Triple::getMacOSXVersion() in the Clang driver. static MacosVersion GetMacosAlignedVersionInternal() { u16 kernel_major = GetDarwinKernelVersion().major; - const u16 version_offset = 4; - CHECK_GE(kernel_major, version_offset); - u16 macos_major = kernel_major - version_offset; - return MacosVersion(10, macos_major); + // Darwin 0-3 -> unsupported + // Darwin 4-19 -> macOS 10.x + // Darwin 20+ -> macOS 11+ + CHECK_GE(kernel_major, 4); + u16 major, minor; + if (kernel_major < 20) { + major = 10; + minor = kernel_major - 4; + } else { + major = 11 + kernel_major - 20; + minor = 0; + } + return MacosVersion(major, minor); } static_assert(sizeof(MacosVersion) == sizeof(atomic_uint32_t::Type), diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_mac_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_mac_test.cpp --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_mac_test.cpp +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_mac_test.cpp @@ -24,8 +24,12 @@ TEST(SanitizerMac, GetMacosAlignedVersion) { MacosVersion vers = GetMacosAlignedVersion(); - EXPECT_EQ(vers.major, 10); - EXPECT_EQ(vers.minor, GetDarwinKernelVersion().major - 4); + u16 kernel_major = GetDarwinKernelVersion().major; + bool macos_11 = (kernel_major >= 20); + u16 expected_major = macos_11 ? (kernel_major - 9) : 10; + u16 expected_minor = macos_11 ? 0 : (kernel_major - 4); + EXPECT_EQ(vers.major, expected_major); + EXPECT_EQ(vers.minor, expected_minor); } void ParseVersion(const char *vers, u16 *major, u16 *minor);