From: Louis Dionne Date: Tue, 15 Jun 2021 22:47:38 +0000 (-0400) Subject: [runtimes] Always build libc++, libc++abi and libunwind with -fPIC X-Git-Tag: llvmorg-14-init~77 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=21c24ae9029a1fcd1c76b61b1c48b81b5c66c606;p=platform%2Fupstream%2Fllvm.git [runtimes] Always build libc++, libc++abi and libunwind with -fPIC 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, which instead makes the decision of whether to build with -fPIC or not to the build script that drives the runtimes' build. Fixes http://llvm.org/PR43604. Differential Revision: https://reviews.llvm.org/D104328 --- diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt index 87b71f7..f8c4d3e 100644 --- a/libcxx/src/CMakeLists.txt +++ b/libcxx/src/CMakeLists.txt @@ -198,6 +198,7 @@ if (LIBCXX_ENABLE_SHARED) 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 @@ if (LIBCXX_ENABLE_STATIC) 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) diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt index 889d751..f07d433 100644 --- a/libcxxabi/src/CMakeLists.txt +++ b/libcxxabi/src/CMakeLists.txt @@ -191,6 +191,7 @@ if (LIBCXXABI_ENABLE_SHARED) SOVERSION "1" VERSION "${LIBCXXABI_LIBRARY_VERSION}" DEFINE_SYMBOL "" + POSITION_INDEPENDENT_CODE ON ) list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_shared") @@ -243,6 +244,7 @@ if (LIBCXXABI_ENABLE_STATIC) COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}" LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}" OUTPUT_NAME "c++abi" + POSITION_INDEPENDENT_CODE ON ) if(LIBCXXABI_HERMETIC_STATIC_LIBRARY) diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt index 05d3e59..093804f 100644 --- a/libunwind/src/CMakeLists.txt +++ b/libunwind/src/CMakeLists.txt @@ -141,6 +141,7 @@ if (LIBUNWIND_ENABLE_SHARED) OUTPUT_NAME "unwind" VERSION "1.0" SOVERSION "1" + POSITION_INDEPENDENT_CODE ON ) list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared") if (LIBUNWIND_INSTALL_SHARED_LIBRARY) @@ -166,6 +167,7 @@ if (LIBUNWIND_ENABLE_STATIC) LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}" LINKER_LANGUAGE C OUTPUT_NAME "unwind" + POSITION_INDEPENDENT_CODE ON ) if(LIBUNWIND_HIDE_SYMBOLS)