[libcxx-commits] [PATCH] D104328: [libc++] Always build libc++ and libc++abi with -fPIC

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 15 15:51:18 PDT 2021


ldionne created this revision.
ldionne added a reviewer: chandlerc.
Herald added a subscriber: mgorny.
ldionne requested review of this revision.
Herald added projects: libc++, libc++abi.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
Herald added a reviewer: libc++abi.

Building the libraries with -fPIC ensures that we can link an executable
against the static libraries with -fPIE. Furthermore, there is apparently
basically no downside to building the libraries with position independent
code, since modern toolchains are sufficiently clever.

This commit enforces that we always build the runtime libraries with -fPIC.
This is another take on D104327 <https://reviews.llvm.org/D104327>, which instead makes the decision of whether
to build with -fPIC or not to the build script that drives libc++'s build.

Fixes http://llvm.org/PR43604.

TODO: Add a test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104328

Files:
  libcxx/src/CMakeLists.txt
  libcxxabi/src/CMakeLists.txt


Index: libcxxabi/src/CMakeLists.txt
===================================================================
--- libcxxabi/src/CMakeLists.txt
+++ libcxxabi/src/CMakeLists.txt
@@ -199,7 +199,9 @@
                           VERSION
                             "${LIBCXXABI_LIBRARY_VERSION}"
                           DEFINE_SYMBOL
-                            "")
+                            ""
+                          POSITION_INDEPENDENT_CODE
+                            ON)
 
   list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_shared")
   if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
@@ -256,7 +258,9 @@
                           LINK_FLAGS
                             "${LIBCXXABI_LINK_FLAGS}"
                           OUTPUT_NAME
-                            "c++abi")
+                            "c++abi"
+                          POSITION_INDEPENDENT_CODE
+                            ON)
 
   if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
     append_flags_if_supported(CXXABI_STATIC_LIBRARY_FLAGS -fvisibility=hidden)
Index: libcxx/src/CMakeLists.txt
===================================================================
--- libcxx/src/CMakeLists.txt
+++ libcxx/src/CMakeLists.txt
@@ -198,6 +198,7 @@
       VERSION       "${LIBCXX_ABI_VERSION}.0"
       SOVERSION     "${LIBCXX_ABI_VERSION}"
       DEFINE_SYMBOL ""
+      POSITION_INDEPENDENT_CODE ON
   )
   cxx_add_common_build_flags(cxx_shared)
   cxx_set_common_defines(cxx_shared)
@@ -272,6 +273,7 @@
       COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
       LINK_FLAGS    "${LIBCXX_LINK_FLAGS}"
       OUTPUT_NAME   "c++"
+      POSITION_INDEPENDENT_CODE ON
   )
   cxx_add_common_build_flags(cxx_static)
   cxx_set_common_defines(cxx_static)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104328.352276.patch
Type: text/x-patch
Size: 1691 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210615/533d8962/attachment.bin>


More information about the libcxx-commits mailing list