[Sanitizer] Update macOS version checking

Support macOS 11 in our runtime version checking code and update
`GetMacosAlignedVersionInternal()` accordingly.  This follows the
implementation of `Triple::getMacOSXVersion()` in the Clang driver.

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D82918
This commit is contained in:
Julian Lettner 2020-06-30 13:19:25 -07:00
parent f721e0582b
commit bed3e1a99b
2 changed files with 20 additions and 6 deletions

View File

@ -606,12 +606,22 @@ HandleSignalMode GetHandleSignalMode(int signum) {
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),

View File

@ -24,8 +24,12 @@ namespace __sanitizer {
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);