diff --git a/src/coreclr/src/pal/src/CMakeLists.txt b/src/coreclr/src/pal/src/CMakeLists.txt index ecb660f2c537e..9828d304333d4 100644 --- a/src/coreclr/src/pal/src/CMakeLists.txt +++ b/src/coreclr/src/pal/src/CMakeLists.txt @@ -228,26 +228,38 @@ endif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) if(CMAKE_SYSTEM_NAME STREQUAL Linux) if(PAL_CMAKE_PLATFORM_ARCH_ARM) - target_link_libraries(coreclrpal - unwind-arm - ) + find_library(UNWIND_ARCH NAMES unwind-arm) endif() if(PAL_CMAKE_PLATFORM_ARCH_AMD64) - target_link_libraries(coreclrpal - unwind-x86_64 - ) + find_library(UNWIND_ARCH NAMES unwind-x86_64) endif() + find_library(UNWIND NAMES unwind) + find_library(UNWIND_GENERIC NAMES unwind-generic) + target_link_libraries(coreclrpal gcc_s pthread rt dl - unwind - unwind-generic uuid ) + + if(UNWIND STREQUAL UNWIND-NOTFOUND) + message(FATAL_ERROR "Cannot find libunwind. Try installing libunwind8-dev and libunwind8.") + endif(UNWIND STREQUAL UNWIND-NOTFOUND) + + target_link_libraries(coreclrpal ${UNWIND}) + + if(NOT UNWIND_GENERIC STREQUAL UNWIND_GENERIC-NOTFOUND) + target_link_libraries(coreclrpal ${UNWIND_GENERIC}) + endif(NOT UNWIND_GENERIC STREQUAL UNWIND_GENERIC-NOTFOUND) + + if(NOT UNWIND_ARCH STREQUAL UNWIND_ARCH-NOTFOUND) + target_link_libraries(coreclrpal ${UNWIND_ARCH}) + endif(NOT UNWIND_ARCH STREQUAL UNWIND_ARCH-NOTFOUND) + endif(CMAKE_SYSTEM_NAME STREQUAL Linux) if(CMAKE_SYSTEM_NAME STREQUAL NetBSD) diff --git a/src/coreclr/src/pal/src/configure.cmake b/src/coreclr/src/pal/src/configure.cmake index 8e5eb307f7381..beac67318fbd7 100644 --- a/src/coreclr/src/pal/src/configure.cmake +++ b/src/coreclr/src/pal/src/configure.cmake @@ -75,6 +75,8 @@ check_function_exists(directio HAVE_DIRECTIO) check_function_exists(semget HAS_SYSV_SEMAPHORES) check_function_exists(pthread_mutex_init HAS_PTHREAD_MUTEXES) check_function_exists(ttrace HAVE_TTRACE) +check_function_exists(unw_get_save_loc HAVE_UNW_GET_SAVE_LOC) +check_function_exists(unw_get_accessors HAVE_UNW_GET_ACCESSORS) check_struct_has_member ("struct stat" st_atimespec "sys/types.h;sys/stat.h" HAVE_STAT_TIMESPEC) check_struct_has_member ("struct stat" st_atimensec "sys/types.h;sys/stat.h" HAVE_STAT_NSEC) diff --git a/src/coreclr/src/pal/src/exception/seh-unwind.cpp b/src/coreclr/src/pal/src/exception/seh-unwind.cpp index fb2c32449cfd4..5d3b353494f58 100644 --- a/src/coreclr/src/pal/src/exception/seh-unwind.cpp +++ b/src/coreclr/src/pal/src/exception/seh-unwind.cpp @@ -157,10 +157,7 @@ static void UnwindContextToWinContext(unw_cursor_t *cursor, CONTEXT *winContext) static void GetContextPointer(unw_cursor_t *cursor, unw_context_t *unwContext, int reg, SIZE_T **contextPointer) { -#if defined(__APPLE__) - // Returning NULL indicates that we don't have context pointers available - *contextPointer = NULL; -#else +#if defined(HAVE_UNW_GET_SAVE_LOC) unw_save_loc_t saveLoc; unw_get_save_loc(cursor, reg, &saveLoc); if (saveLoc.type == UNW_SLT_MEMORY) @@ -170,6 +167,9 @@ static void GetContextPointer(unw_cursor_t *cursor, unw_context_t *unwContext, i if (unwContext == NULL || (pLoc < (SIZE_T *)unwContext) || ((SIZE_T *)(unwContext + 1) <= pLoc)) *contextPointer = (SIZE_T *)saveLoc.u.addr; } +#else + // Returning NULL indicates that we don't have context pointers available + *contextPointer = NULL; #endif } @@ -302,7 +302,7 @@ BOOL PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextP // These methods are only used on the AMD64 build #ifdef _AMD64_ -#ifdef __LINUX__ +#ifdef HAVE_UNW_GET_ACCESSORS static struct LibunwindCallbacksInfoType { @@ -528,7 +528,7 @@ BOOL PAL_VirtualUnwindOutOfProc(CONTEXT *context, } return result; } -#else // __LINUX__ +#else // HAVE_UNW_GET_ACCESSORS BOOL PAL_VirtualUnwindOutOfProc(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextPointers, @@ -539,7 +539,7 @@ BOOL PAL_VirtualUnwindOutOfProc(CONTEXT *context, return FALSE; } -#endif // !__LINUX__ +#endif // !HAVE_UNW_GET_ACCESSORS #endif // _AMD64_ /*++