[libunwind] 94b475d - [libunwind] Add SME detection for Apple platforms (#193630)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 4 19:25:38 PDT 2026
Author: Brad Smith
Date: 2026-05-05T02:25:33Z
New Revision: 94b475dae69cecf8f80a0936a7510be1c6fdbead
URL: https://github.com/llvm/llvm-project/commit/94b475dae69cecf8f80a0936a7510be1c6fdbead
DIFF: https://github.com/llvm/llvm-project/commit/94b475dae69cecf8f80a0936a7510be1c6fdbead.diff
LOG: [libunwind] Add SME detection for Apple platforms (#193630)
Copy SME detection sysctl code from ZA test. Also fix a
logic issue in the original code while being reviewed.
Added:
Modified:
libunwind/src/Registers.hpp
libunwind/test/aarch64_za_unwind.pass.cpp
Removed:
################################################################################
diff --git a/libunwind/src/Registers.hpp b/libunwind/src/Registers.hpp
index a7684e2624e75..c88422a6d5f4f 100644
--- a/libunwind/src/Registers.hpp
+++ b/libunwind/src/Registers.hpp
@@ -20,6 +20,9 @@
#include "libunwind_ext.h"
#include "shadow_stack_unwind.h"
+#if defined(__APPLE__)
+#include <sys/sysctl.h>
+#endif
#if defined(_LIBUNWIND_HAVE_GETAUXVAL) || defined(_LIBUNWIND_HAVE_ELF_AUX_INFO)
#include <sys/auxv.h>
#endif
@@ -1940,7 +1943,15 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
_LIBUNWIND_ABORT("SME ZA disable failed");
}
-#if defined(_LIBUNWIND_HAVE_GETAUXVAL)
+#if defined(__APPLE__)
+ static bool checkHasSME() {
+ int has_sme = 0;
+ size_t size = sizeof(has_sme);
+ if (sysctlbyname("hw.optional.arm.FEAT_SME", &has_sme, &size, NULL, 0))
+ return false;
+ return has_sme != 0;
+ }
+#elif defined(_LIBUNWIND_HAVE_GETAUXVAL)
static bool checkHasSME() {
constexpr int hwcap2_sme = (1 << 23);
unsigned long hwcap2 = getauxval(AT_HWCAP2);
diff --git a/libunwind/test/aarch64_za_unwind.pass.cpp b/libunwind/test/aarch64_za_unwind.pass.cpp
index 84be24d7d2c0a..36536860c1a96 100644
--- a/libunwind/test/aarch64_za_unwind.pass.cpp
+++ b/libunwind/test/aarch64_za_unwind.pass.cpp
@@ -29,7 +29,7 @@
static bool checkHasSME() {
int has_sme = 0;
size_t size = sizeof(has_sme);
- if (!sysctlbyname("hw.optional.arm.FEAT_SME", &has_sme, &size, NULL, 0))
+ if (sysctlbyname("hw.optional.arm.FEAT_SME", &has_sme, &size, NULL, 0))
return false;
return has_sme != 0;
}
More information about the cfe-commits
mailing list