[llvm-branch-commits] [libunwind] 4592b0b - [libunwind] Fix building on OpenBSD / FreeBSD aarch64 (#188397)

Douglas Yung via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Mar 27 11:55:00 PDT 2026


Author: Brad Smith
Date: 2026-03-27T08:46:19Z
New Revision: 4592b0b6388d105ea9b688759c1810ad519fded3

URL: https://github.com/llvm/llvm-project/commit/4592b0b6388d105ea9b688759c1810ad519fded3
DIFF: https://github.com/llvm/llvm-project/commit/4592b0b6388d105ea9b688759c1810ad519fded3.diff

LOG: [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)

Added: 
    

Modified: 
    libunwind/CMakeLists.txt
    libunwind/src/Registers.hpp

Removed: 
    


################################################################################
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