diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt --- a/libunwind/CMakeLists.txt +++ b/libunwind/CMakeLists.txt @@ -131,6 +131,7 @@ option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) option(LIBUNWIND_ENABLE_SHARED "Build libunwind as a shared library." ON) option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON) +option(LIBUNWIND_ENABLE_PIC "Build position-independent code, even in the static library." ON) option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF) option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF) option(LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON) diff --git a/libunwind/docs/BuildingLibunwind.rst b/libunwind/docs/BuildingLibunwind.rst --- a/libunwind/docs/BuildingLibunwind.rst +++ b/libunwind/docs/BuildingLibunwind.rst @@ -130,6 +130,12 @@ Build libunwind as a static archive. +.. option:: LIBUNWIND_ENABLE_PIC:BOOL + + **Default**: ``ON`` + + Build position-independent code, even in the static library. + .. option:: LIBUNWIND_ENABLE_CROSS_UNWINDING:BOOL **Default**: ``OFF`` diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt --- a/libunwind/src/CMakeLists.txt +++ b/libunwind/src/CMakeLists.txt @@ -126,6 +126,9 @@ else() target_compile_options(unwind_shared PRIVATE -fno-rtti) endif() + if(LIBUNWIND_ENABLE_PIC) + set_target_properties(unwind_shared PROPERTIES POSITION_INDEPENDENT_CODE ON) + endif() if(COMMAND llvm_setup_rpath) llvm_setup_rpath(unwind_shared) endif() @@ -154,6 +157,9 @@ else() target_compile_options(unwind_static PRIVATE -fno-rtti) endif() + if(LIBUNWIND_ENABLE_PIC) + set_target_properties(unwind_static PROPERTIES POSITION_INDEPENDENT_CODE ON) + endif() target_link_libraries(unwind_static PRIVATE ${LIBUNWIND_LIBRARIES}) set_target_properties(unwind_static PROPERTIES CXX_EXTENSIONS OFF