diff --git a/src/coreclr/nativeaot/Runtime/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/CMakeLists.txt index e59b411316ee2e..794ce51637a284 100644 --- a/src/coreclr/nativeaot/Runtime/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/CMakeLists.txt @@ -181,6 +181,17 @@ else() # Compile unwinding only for the current compilation target architecture add_definitions(-D_LIBUNWIND_IS_NATIVE_ONLY) + include(CheckSymbolExists) + 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() + if(CLR_CMAKE_TARGET_HAIKU) add_definitions(-DPT_GNU_EH_FRAME=PT_EH_FRAME) endif() diff --git a/src/native/external/llvm-libunwind-version.txt b/src/native/external/llvm-libunwind-version.txt index 8d9b9e900e6bcb..060e788248fa0b 100644 --- a/src/native/external/llvm-libunwind-version.txt +++ b/src/native/external/llvm-libunwind-version.txt @@ -3,3 +3,4 @@ https://github.com/llvm/llvm-project/releases/tag/llvmorg-22.1.1 Apply https://github.com/dotnet/runtime/commit/35b7d59fa1075ab0fefb921393409806a821d8ed Apply https://github.com/dotnet/runtime/commit/be5f98fb6702704afbaf705dce0b54d55479c6f1 +Apply https://github.com/llvm/llvm-project/commit/588451c160c34b888ced1c3d9263d361df22f757 diff --git a/src/native/external/llvm-libunwind/CMakeLists.txt b/src/native/external/llvm-libunwind/CMakeLists.txt index fbef71f3f74467..9679d2b684ff20 100644 --- a/src/native/external/llvm-libunwind/CMakeLists.txt +++ b/src/native/external/llvm-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/src/native/external/llvm-libunwind/src/Registers.hpp b/src/native/external/llvm-libunwind/src/Registers.hpp index 7d7afca8e9e1d2..47a6e0d06947a6 100644 --- a/src/native/external/llvm-libunwind/src/Registers.hpp +++ b/src/native/external/llvm-libunwind/src/Registers.hpp @@ -20,9 +20,8 @@ #include "libunwind_ext.h" #include "shadow_stack_unwind.h" -#if __has_include() +#if defined(_LIBUNWIND_HAVE_GETAUXVAL) || defined(_LIBUNWIND_HAVE_ELF_AUX_INFO) #include -#define HAVE_SYS_AUXV_H #endif namespace libunwind { @@ -2084,15 +2083,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