Skip to content

Commit

Permalink
Detect libunwind features allowing LLVMs libunwind to be used
Browse files Browse the repository at this point in the history
Commit migrated from dotnet/coreclr@c068030
  • Loading branch information
benpye committed Feb 5, 2016
1 parent 0108b9e commit 5a2478f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
28 changes: 20 additions & 8 deletions src/coreclr/src/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/src/pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions src/coreclr/src/pal/src/exception/seh-unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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,
Expand All @@ -539,7 +539,7 @@ BOOL PAL_VirtualUnwindOutOfProc(CONTEXT *context,
return FALSE;
}

#endif // !__LINUX__
#endif // !HAVE_UNW_GET_ACCESSORS
#endif // _AMD64_

/*++
Expand Down

0 comments on commit 5a2478f

Please sign in to comment.