forked from OSchip/llvm-project
[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:
parent
f721e0582b
commit
bed3e1a99b
|
@ -606,12 +606,22 @@ HandleSignalMode GetHandleSignalMode(int signum) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This corresponds to Triple::getMacOSXVersion() in the Clang driver.
|
||||||
static MacosVersion GetMacosAlignedVersionInternal() {
|
static MacosVersion GetMacosAlignedVersionInternal() {
|
||||||
u16 kernel_major = GetDarwinKernelVersion().major;
|
u16 kernel_major = GetDarwinKernelVersion().major;
|
||||||
const u16 version_offset = 4;
|
// Darwin 0-3 -> unsupported
|
||||||
CHECK_GE(kernel_major, version_offset);
|
// Darwin 4-19 -> macOS 10.x
|
||||||
u16 macos_major = kernel_major - version_offset;
|
// Darwin 20+ -> macOS 11+
|
||||||
return MacosVersion(10, macos_major);
|
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),
|
static_assert(sizeof(MacosVersion) == sizeof(atomic_uint32_t::Type),
|
||||||
|
|
|
@ -24,8 +24,12 @@ namespace __sanitizer {
|
||||||
|
|
||||||
TEST(SanitizerMac, GetMacosAlignedVersion) {
|
TEST(SanitizerMac, GetMacosAlignedVersion) {
|
||||||
MacosVersion vers = GetMacosAlignedVersion();
|
MacosVersion vers = GetMacosAlignedVersion();
|
||||||
EXPECT_EQ(vers.major, 10);
|
u16 kernel_major = GetDarwinKernelVersion().major;
|
||||||
EXPECT_EQ(vers.minor, GetDarwinKernelVersion().major - 4);
|
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);
|
void ParseVersion(const char *vers, u16 *major, u16 *minor);
|
||||||
|
|
Loading…
Reference in New Issue