[llvm-branch-commits] [libunwind] release/22.x: [libunwind] Fix building on OpenBSD / FreeBSD aarch64 (#188397) (PR #188580)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Mar 27 01:46:32 PDT 2026
https://github.com/dyung updated https://github.com/llvm/llvm-project/pull/188580
>From 4592b0b6388d105ea9b688759c1810ad519fded3 Mon Sep 17 00:00:00 2001
From: Brad Smith <brad at comstyle.com>
Date: Wed, 25 Mar 2026 15:39:08 -0400
Subject: [PATCH] [libunwind] Fix building on OpenBSD / FreeBSD aarch64
(#188397)
Just checking for the header presence of sys/auxv.h breaks the
build on OpenBSD / FreeBSD. Make use of elf_aux_info().
(cherry picked from commit 588451c160c34b888ced1c3d9263d361df22f757)
---
libunwind/CMakeLists.txt | 10 ++++++++++
libunwind/src/Registers.hpp | 17 +++++++++++++----
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index fbef71f3f7446..9679d2b684ff2 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -336,6 +336,16 @@ if (RUNTIMES_EXECUTE_ONLY_CODE)
add_compile_definitions(_LIBUNWIND_EXECUTE_ONLY_CODE)
endif()
+check_symbol_exists(getauxval "sys/auxv.h" HAVE_GETAUXVAL)
+if (HAVE_GETAUXVAL)
+ add_definitions(-D_LIBUNWIND_HAVE_GETAUXVAL)
+endif()
+
+check_symbol_exists(elf_aux_info "sys/auxv.h" HAVE_ELF_AUX_INFO)
+if (HAVE_ELF_AUX_INFO)
+ add_definitions(-D_LIBUNWIND_HAVE_ELF_AUX_INFO)
+endif()
+
add_custom_target(unwind-test-depends
COMMENT "Build dependencies required to run the libunwind test suite.")
diff --git a/libunwind/src/Registers.hpp b/libunwind/src/Registers.hpp
index 474b17461bf77..88c2d3b4e8c9b 100644
--- a/libunwind/src/Registers.hpp
+++ b/libunwind/src/Registers.hpp
@@ -20,9 +20,8 @@
#include "libunwind_ext.h"
#include "shadow_stack_unwind.h"
-#if __has_include(<sys/auxv.h>)
+#if defined(_LIBUNWIND_HAVE_GETAUXVAL) || defined(_LIBUNWIND_HAVE_ELF_AUX_INFO)
#include <sys/auxv.h>
-#define HAVE_SYS_AUXV_H
#endif
namespace libunwind {
@@ -1941,15 +1940,25 @@ class _LIBUNWIND_HIDDEN Registers_arm64 {
_LIBUNWIND_ABORT("SME ZA disable failed");
}
+#if defined(_LIBUNWIND_HAVE_GETAUXVAL)
static bool checkHasSME() {
-#if defined(HAVE_SYS_AUXV_H)
constexpr int hwcap2_sme = (1 << 23);
unsigned long hwcap2 = getauxval(AT_HWCAP2);
return (hwcap2 & hwcap2_sme) != 0;
-#endif
+ }
+#elif defined(_LIBUNWIND_HAVE_ELF_AUX_INFO)
+ static bool checkHasSME() {
+ constexpr int hwcap2_sme = (1 << 23);
+ unsigned long hwcap2 = 0;
+ elf_aux_info(AT_HWCAP2, &hwcap2, sizeof(hwcap2));
+ return (hwcap2 & hwcap2_sme) != 0;
+ }
+#else
+ static bool checkHasSME() {
// TODO: Support other platforms.
return false;
}
+#endif
struct GPRs {
uint64_t __x[29] = {}; // x0-x28
More information about the llvm-branch-commits
mailing list