Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 86f87db

Browse files
committed
Merge pull request #3045 from benpye/allow-llvm-unwind
Detect libunwind features allowing LLVMs libunwind to be used
2 parents 6fcefb3 + c068030 commit 86f87db

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

src/pal/src/CMakeLists.txt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,26 +228,38 @@ endif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
228228

229229
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
230230
if(PAL_CMAKE_PLATFORM_ARCH_ARM)
231-
target_link_libraries(coreclrpal
232-
unwind-arm
233-
)
231+
find_library(UNWIND_ARCH NAMES unwind-arm)
234232
endif()
235233

236234
if(PAL_CMAKE_PLATFORM_ARCH_AMD64)
237-
target_link_libraries(coreclrpal
238-
unwind-x86_64
239-
)
235+
find_library(UNWIND_ARCH NAMES unwind-x86_64)
240236
endif()
241237

238+
find_library(UNWIND NAMES unwind)
239+
find_library(UNWIND_GENERIC NAMES unwind-generic)
240+
242241
target_link_libraries(coreclrpal
243242
gcc_s
244243
pthread
245244
rt
246245
dl
247-
unwind
248-
unwind-generic
249246
uuid
250247
)
248+
249+
if(UNWIND STREQUAL UNWIND-NOTFOUND)
250+
message(FATAL_ERROR "Cannot find libunwind. Try installing libunwind8-dev and libunwind8.")
251+
endif(UNWIND STREQUAL UNWIND-NOTFOUND)
252+
253+
target_link_libraries(coreclrpal ${UNWIND})
254+
255+
if(NOT UNWIND_GENERIC STREQUAL UNWIND_GENERIC-NOTFOUND)
256+
target_link_libraries(coreclrpal ${UNWIND_GENERIC})
257+
endif(NOT UNWIND_GENERIC STREQUAL UNWIND_GENERIC-NOTFOUND)
258+
259+
if(NOT UNWIND_ARCH STREQUAL UNWIND_ARCH-NOTFOUND)
260+
target_link_libraries(coreclrpal ${UNWIND_ARCH})
261+
endif(NOT UNWIND_ARCH STREQUAL UNWIND_ARCH-NOTFOUND)
262+
251263
endif(CMAKE_SYSTEM_NAME STREQUAL Linux)
252264

253265
if(CMAKE_SYSTEM_NAME STREQUAL NetBSD)

src/pal/src/configure.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ check_function_exists(directio HAVE_DIRECTIO)
7575
check_function_exists(semget HAS_SYSV_SEMAPHORES)
7676
check_function_exists(pthread_mutex_init HAS_PTHREAD_MUTEXES)
7777
check_function_exists(ttrace HAVE_TTRACE)
78+
check_function_exists(unw_get_save_loc HAVE_UNW_GET_SAVE_LOC)
79+
check_function_exists(unw_get_accessors HAVE_UNW_GET_ACCESSORS)
7880

7981
check_struct_has_member ("struct stat" st_atimespec "sys/types.h;sys/stat.h" HAVE_STAT_TIMESPEC)
8082
check_struct_has_member ("struct stat" st_atimensec "sys/types.h;sys/stat.h" HAVE_STAT_NSEC)

src/pal/src/exception/seh-unwind.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,7 @@ static void UnwindContextToWinContext(unw_cursor_t *cursor, CONTEXT *winContext)
157157

158158
static void GetContextPointer(unw_cursor_t *cursor, unw_context_t *unwContext, int reg, SIZE_T **contextPointer)
159159
{
160-
#if defined(__APPLE__)
161-
// Returning NULL indicates that we don't have context pointers available
162-
*contextPointer = NULL;
163-
#else
160+
#if defined(HAVE_UNW_GET_SAVE_LOC)
164161
unw_save_loc_t saveLoc;
165162
unw_get_save_loc(cursor, reg, &saveLoc);
166163
if (saveLoc.type == UNW_SLT_MEMORY)
@@ -170,6 +167,9 @@ static void GetContextPointer(unw_cursor_t *cursor, unw_context_t *unwContext, i
170167
if (unwContext == NULL || (pLoc < (SIZE_T *)unwContext) || ((SIZE_T *)(unwContext + 1) <= pLoc))
171168
*contextPointer = (SIZE_T *)saveLoc.u.addr;
172169
}
170+
#else
171+
// Returning NULL indicates that we don't have context pointers available
172+
*contextPointer = NULL;
173173
#endif
174174
}
175175

@@ -302,7 +302,7 @@ BOOL PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextP
302302

303303
// These methods are only used on the AMD64 build
304304
#ifdef _AMD64_
305-
#ifdef __LINUX__
305+
#ifdef HAVE_UNW_GET_ACCESSORS
306306

307307
static struct LibunwindCallbacksInfoType
308308
{
@@ -528,7 +528,7 @@ BOOL PAL_VirtualUnwindOutOfProc(CONTEXT *context,
528528
}
529529
return result;
530530
}
531-
#else // __LINUX__
531+
#else // HAVE_UNW_GET_ACCESSORS
532532

533533
BOOL PAL_VirtualUnwindOutOfProc(CONTEXT *context,
534534
KNONVOLATILE_CONTEXT_POINTERS *contextPointers,
@@ -539,7 +539,7 @@ BOOL PAL_VirtualUnwindOutOfProc(CONTEXT *context,
539539
return FALSE;
540540
}
541541

542-
#endif // !__LINUX__
542+
#endif // !HAVE_UNW_GET_ACCESSORS
543543
#endif // _AMD64_
544544

545545
/*++

0 commit comments

Comments
 (0)