[libcxx-commits] [PATCH] D77370: [libunwind] Add LIBUNWIND_ENABLE_PIC

Raul Tambre via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 3 01:02:30 PDT 2020


tambre created this revision.
tambre added reviewers: mstorsjo, phosek, compnerd.
Herald added subscribers: libcxx-commits, llvm-commits, mgorny.
Herald added projects: LLVM, libunwind.
Herald added a reviewer: libunwind.

This is allows statically linking libunwind in standalone libc++abi builds. See also D77296 <https://reviews.llvm.org/D77296>.
Default to OFF for now to keep the same behaviour as before.
GN builds already enable PIC unconditionally for shared libraries.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77370

Files:
  libunwind/CMakeLists.txt
  libunwind/docs/BuildingLibunwind.rst
  libunwind/src/CMakeLists.txt


Index: libunwind/src/CMakeLists.txt
===================================================================
--- libunwind/src/CMakeLists.txt
+++ 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
Index: libunwind/docs/BuildingLibunwind.rst
===================================================================
--- libunwind/docs/BuildingLibunwind.rst
+++ libunwind/docs/BuildingLibunwind.rst
@@ -130,6 +130,12 @@
 
   Build libunwind as a static archive.
 
+.. option:: LIBUNWIND_ENABLE_PIC:BOOL
+
+  **Default**: ``OFF``
+
+  Build position-independent code, even in the static library.
+
 .. option:: LIBUNWIND_ENABLE_CROSS_UNWINDING:BOOL
 
   **Default**: ``OFF``
Index: libunwind/CMakeLists.txt
===================================================================
--- libunwind/CMakeLists.txt
+++ 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." OFF)
 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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77370.254717.patch
Type: text/x-patch
Size: 2073 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200403/08b1701b/attachment.bin>


More information about the libcxx-commits mailing list