Use the new macOS sysctl names when available At the time, there was no documentation (or I just couldn't find it) on the correct sysctl names to query CPU features on Apple aarch64 platforms, so it was unclear what the relationship was between "hw.optional.arm.FEAT_SHA512" and "hw.optional.armv8_2_sha512". There is documentation now: https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics However, the documented names weren't available in macOS 11, and some Arm Macs did ship with macOS 11. So query both names for macOS 11 compat and in case some future version of macOS removes the old names. Change-Id: I671d47576721b4c172feeb2e3f138c6bc55e39d6 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/54445 Auto-Submit: David Benjamin <davidben@google.com> Commit-Queue: Bob Beck <bbe@google.com> Reviewed-by: Bob Beck <bbe@google.com>
diff --git a/crypto/cpu_aarch64_apple.c b/crypto/cpu_aarch64_apple.c index 6699ff7..f6c7173 100644 --- a/crypto/cpu_aarch64_apple.c +++ b/crypto/cpu_aarch64_apple.c
@@ -58,13 +58,15 @@ OPENSSL_armcap_P = ARMV7_NEON | ARMV8_AES | ARMV8_PMULL | ARMV8_SHA1 | ARMV8_SHA256; - // macOS has sysctls named both like "hw.optional.arm.FEAT_SHA512" and like - // "hw.optional.armv8_2_sha512". There does not appear to be documentation on - // which to use. The "armv8_2_sha512" style omits statically-available - // features, while the "FEAT_SHA512" style includes them. However, the - // "FEAT_SHA512" style was added in macOS 12, so we use the older style for - // better compatibility and handle static features above. - if (has_hw_feature("hw.optional.armv8_2_sha512")) { + // See Apple's documentation for sysctl names: + // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics + // + // The new feature names, e.g. "hw.optional.arm.FEAT_SHA512", are only + // available in macOS 12. For compatibility with macOS 11, we also support + // the old names. The old names don't have values for features like FEAT_AES, + // so instead we detect them statically above. + if (has_hw_feature("hw.optional.arm.FEAT_SHA512") || + has_hw_feature("hw.optional.armv8_2_sha512")) { OPENSSL_armcap_P |= ARMV8_SHA512; } }