From 374d9b71d9ebcf24b54a79b550aa9b1d9d5d7d78 Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Wed, 25 Sep 2024 01:43:44 +0300 Subject: [PATCH 1/2] Add build-time check for unwind proc_info_in_range --- src/coreclr/pal/src/config.h.in | 1 + src/coreclr/pal/src/configure.cmake | 1 + src/coreclr/pal/src/exception/remote-unwind.cpp | 13 ++++++++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/coreclr/pal/src/config.h.in b/src/coreclr/pal/src/config.h.in index 52405d4c91286a..2a554a20e1841d 100644 --- a/src/coreclr/pal/src/config.h.in +++ b/src/coreclr/pal/src/config.h.in @@ -83,6 +83,7 @@ #cmakedefine01 HAVE_BROKEN_FIFO_SELECT #cmakedefine01 HAVE_BROKEN_FIFO_KEVENT #cmakedefine01 UNWIND_CONTEXT_IS_UCONTEXT_T +#cmakedefine01 HAVE_GET_PROC_INFO_IN_RANGE #cmakedefine01 HAVE_SCHED_GET_PRIORITY #cmakedefine01 HAVE_WORKING_GETTIMEOFDAY #cmakedefine01 HAVE_WORKING_CLOCK_GETTIME diff --git a/src/coreclr/pal/src/configure.cmake b/src/coreclr/pal/src/configure.cmake index 0cc20e3e427b6f..6b7ec85cac40a7 100644 --- a/src/coreclr/pal/src/configure.cmake +++ b/src/coreclr/pal/src/configure.cmake @@ -624,6 +624,7 @@ int main(int argc, char **argv) check_symbol_exists(unw_get_save_loc libunwind.h HAVE_UNW_GET_SAVE_LOC) check_symbol_exists(unw_get_accessors libunwind.h HAVE_UNW_GET_ACCESSORS) +check_symbol_exists(unw_get_proc_info_in_range libunwind.h HAVE_GET_PROC_INFO_IN_RANGE) check_cxx_source_compiles(" #include diff --git a/src/coreclr/pal/src/exception/remote-unwind.cpp b/src/coreclr/pal/src/exception/remote-unwind.cpp index 05cba618a10222..94b8ca0ac8490e 100644 --- a/src/coreclr/pal/src/exception/remote-unwind.cpp +++ b/src/coreclr/pal/src/exception/remote-unwind.cpp @@ -1684,7 +1684,7 @@ StepWithCompactEncodingArm64(const libunwindInfo* info, compact_unwind_encoding_ if (!ReadCompactEncodingRegisterPair(info, &addr, &context->Lr, &context->Fp)) { return false; } - // Strip pointer authentication bits + // Strip pointer authentication bits context->Lr &= MACOS_ARM64_POINTER_AUTH_MASK; } else @@ -2328,7 +2328,12 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pip, int nee } } -#ifdef FEATURE_USE_SYSTEM_LIBUNWIND +#if HAVE_GET_PROC_INFO_IN_RANGE + return unw_get_proc_info_in_range(start_ip, end_ip, ehFrameHdrAddr, ehFrameHdrLen, exidxFrameHdrAddr, exidxFrameHdrLen, as, ip, pip, need_unwind_info, arg); +#else // HAVE_GET_PROC_INFO_IN_RANGE + // This branch is executed when using llvm-libunwind (macOS and similar platforms) + // or HP-libunwind version 1.6 and earlier. + if (ehFrameHdrAddr == 0) { ASSERT("ELF: No PT_GNU_EH_FRAME program header\n"); return -UNW_EINVAL; @@ -2400,9 +2405,7 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pip, int nee } info->FunctionStart = pip->start_ip; return UNW_ESUCCESS; -#else - return unw_get_proc_info_in_range(start_ip, end_ip, ehFrameHdrAddr, ehFrameHdrLen, exidxFrameHdrAddr, exidxFrameHdrLen, as, ip, pip, need_unwind_info, arg); -#endif // FEATURE_USE_SYSTEM_LIBUNWIND +#endif // HAVE_GET_PROC_INFO_IN_RANGE #endif // __APPLE__ } From 5890b79c80bfab964c691e9dfadd327205af9499 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:22:09 +0300 Subject: [PATCH 2/2] Fix windows build --- src/coreclr/pal/src/exception/remote-unwind.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/coreclr/pal/src/exception/remote-unwind.cpp b/src/coreclr/pal/src/exception/remote-unwind.cpp index 94b8ca0ac8490e..aec8822ceb45f2 100644 --- a/src/coreclr/pal/src/exception/remote-unwind.cpp +++ b/src/coreclr/pal/src/exception/remote-unwind.cpp @@ -2328,9 +2328,10 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pip, int nee } } -#if HAVE_GET_PROC_INFO_IN_RANGE +#if HAVE_GET_PROC_INFO_IN_RANGE || !defined(HOST_UNIX) return unw_get_proc_info_in_range(start_ip, end_ip, ehFrameHdrAddr, ehFrameHdrLen, exidxFrameHdrAddr, exidxFrameHdrLen, as, ip, pip, need_unwind_info, arg); -#else // HAVE_GET_PROC_INFO_IN_RANGE +#else // HAVE_GET_PROC_INFO_IN_RANGE || !defined(HOST_UNIX) + // This branch is executed when using llvm-libunwind (macOS and similar platforms) // or HP-libunwind version 1.6 and earlier. @@ -2405,7 +2406,7 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pip, int nee } info->FunctionStart = pip->start_ip; return UNW_ESUCCESS; -#endif // HAVE_GET_PROC_INFO_IN_RANGE +#endif // HAVE_GET_PROC_INFO_IN_RANGE || !defined(HOST_UNIX) #endif // __APPLE__ }