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

Commit 77dd212

Browse files
omajidjanvorli
authored andcommitted
Optionally support using the system-installed libunwind (#17164)
This allows coreclr to link against a system-installed libunwind instead of using the copy included with the coreclr sources. The default is still to use the bundled version, except on macOS, where we always use the system-installed version. Many Linux distributions prefer to avoid bundled libraries as much as possible. For their reasons, please see: - https://fedoraproject.org/wiki/Bundled_Libraries - https://wiki.debian.org/UpstreamGuide#No_inclusion_of_third_party_code - https://wiki.gentoo.org/wiki/Why_not_bundle_dependencies
1 parent 091466a commit 77dd212

File tree

2 files changed

+57
-10
lines changed

2 files changed

+57
-10
lines changed

src/pal/src/CMakeLists.txt

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
cmake_minimum_required(VERSION 2.8.12.2)
22

3+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
4+
# On OSX, we use the libunwind that's part of the OS
5+
set(CLR_CMAKE_USE_SYSTEM_LIBUNWIND 1)
6+
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
7+
38
include_directories(SYSTEM /usr/local/include)
4-
include_directories(libunwind/include)
59

610
add_compile_options(-fPIC)
711

8-
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
12+
if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
13+
include_directories(libunwind/include)
914
add_subdirectory(libunwind)
10-
endif(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
15+
endif(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
1116

1217
include(configure.cmake)
1318

@@ -240,10 +245,9 @@ set(SOURCES
240245
thread/tls.cpp
241246
)
242247

243-
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
244-
# On OSX, we use the libunwind that's part of the OS
248+
if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
245249
set(LIBUNWIND_OBJECTS $<TARGET_OBJECTS:libunwind>)
246-
endif(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
250+
endif(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
247251

248252
add_library(coreclrpal
249253
STATIC
@@ -267,10 +271,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
267271
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
268272

269273
if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
274+
if(CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
275+
find_library(UNWIND unwind)
276+
endif()
270277
find_library(INTL intl)
271278
target_link_libraries(coreclrpal
272279
pthread
273280
rt
281+
${UNWIND}
274282
${INTL}
275283
)
276284
endif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
@@ -303,7 +311,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
303311
${LZMA})
304312
endif()
305313

306-
307314
if(CLR_MAKE_PLATFORM_ANDROID)
308315
find_library(ANDROID_SUPPORT NAMES android-support)
309316
find_library(ANDROID_GLOB NAMES android-glob)
@@ -326,20 +333,56 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
326333
dl
327334
)
328335

329-
330336
if(NOT INTL STREQUAL INTL-NOTFOUND)
331337
target_link_libraries(coreclrpal ${INTL})
332338
endif(NOT INTL STREQUAL INTL-NOTFOUND)
333339

340+
if(CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
341+
if(PAL_CMAKE_PLATFORM_ARCH_ARM)
342+
find_library(UNWIND_ARCH NAMES unwind-arm)
343+
endif()
344+
345+
if(PAL_CMAKE_PLATFORM_ARCH_ARM64)
346+
find_library(UNWIND_ARCH NAMES unwind-aarch64)
347+
endif()
348+
349+
if(PAL_CMAKE_PLATFORM_ARCH_AMD64)
350+
find_library(UNWIND_ARCH NAMES unwind-x86_64)
351+
endif()
352+
353+
if(NOT UNWIND_ARCH STREQUAL UNWIND_ARCH-NOTFOUND)
354+
target_link_libraries(coreclrpal ${UNWIND_ARCH})
355+
endif()
356+
357+
find_library(UNWIND_GENERIC NAMES unwind-generic)
358+
359+
if(NOT UNWIND_GENERIC STREQUAL UNWIND_GENERIC-NOTFOUND)
360+
target_link_libraries(coreclrpal ${UNWIND_GENERIC})
361+
endif()
362+
363+
find_library(UNWIND NAMES unwind)
364+
365+
if(UNWIND STREQUAL UNWIND-NOTFOUND)
366+
message(FATAL_ERROR "Cannot find libunwind. Try installing libunwind8-dev or libunwind-devel.")
367+
endif()
368+
369+
target_link_libraries(coreclrpal ${UNWIND})
370+
371+
endif(CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
372+
334373
endif(CMAKE_SYSTEM_NAME STREQUAL Linux)
335374

336375
if(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
376+
if (CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
377+
find_library(UNWIND unwind)
378+
endif()
337379
add_definitions(-D_KMEMUSER)
338380
find_library(INTL intl)
339381
find_library(KVM kvm)
340382
target_link_libraries(coreclrpal
341383
pthread
342384
rt
385+
${UNWIND}
343386
${INTL}
344387
${KVM}
345388
)

src/pal/src/configure.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,9 @@ int main()
978978
set(SYNCHMGR_SUSPENSION_SAFE_CONDITION_SIGNALING 1)
979979
set(ERROR_FUNC_FOR_GLOB_HAS_FIXED_PARAMS 1)
980980

981-
list(INSERT CMAKE_REQUIRED_INCLUDES 0 ${CMAKE_CURRENT_SOURCE_DIR}/libunwind/include ${CMAKE_CURRENT_BINARY_DIR}/libunwind/include)
981+
if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
982+
list(INSERT CMAKE_REQUIRED_INCLUDES 0 ${CMAKE_CURRENT_SOURCE_DIR}/libunwind/include ${CMAKE_CURRENT_BINARY_DIR}/libunwind/include)
983+
endif()
982984

983985
check_c_source_compiles("
984986
#include <libunwind.h>
@@ -991,7 +993,9 @@ int main(int argc, char **argv)
991993
return 0;
992994
}" UNWIND_CONTEXT_IS_UCONTEXT_T)
993995

994-
list(REMOVE_AT CMAKE_REQUIRED_INCLUDES 0 1)
996+
if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
997+
list(REMOVE_AT CMAKE_REQUIRED_INCLUDES 0 1)
998+
endif()
995999

9961000
check_cxx_source_compiles("
9971001
#include <sys/param.h>

0 commit comments

Comments
 (0)