[libunwind] [libunwind] Add SME detection for Apple platforms (PR #193630)
Brad Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon May 4 19:20:23 PDT 2026
https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/193630
>From 914bd3a7d0b09f8b7727d9a7b274452a0cea58d6 Mon Sep 17 00:00:00 2001
From: Brad Smith <brad at comstyle.com>
Date: Wed, 22 Apr 2026 19:59:10 -0400
Subject: [PATCH] [libunwind] Add SME detection for Apple platforms
Copy SME detection sysctl code from ZA test. Also fix a
logic issue in the original code while being reviewed.
---
libunwind/src/Registers.hpp | 13 ++++++++++++-
libunwind/test/aarch64_za_unwind.pass.cpp | 2 +-
2 files changed, 13 insertions(+), 2 deletions(-)
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