Skip to content

Commit 21c24ae

Browse files
committed
[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
1 parent 4547861 commit 21c24ae

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

libcxx/src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ if (LIBCXX_ENABLE_SHARED)
198198
VERSION "${LIBCXX_ABI_VERSION}.0"
199199
SOVERSION "${LIBCXX_ABI_VERSION}"
200200
DEFINE_SYMBOL ""
201+
POSITION_INDEPENDENT_CODE ON
201202
)
202203
cxx_add_common_build_flags(cxx_shared)
203204
cxx_set_common_defines(cxx_shared)
@@ -272,6 +273,7 @@ if (LIBCXX_ENABLE_STATIC)
272273
COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
273274
LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
274275
OUTPUT_NAME "c++"
276+
POSITION_INDEPENDENT_CODE ON
275277
)
276278
cxx_add_common_build_flags(cxx_static)
277279
cxx_set_common_defines(cxx_static)

libcxxabi/src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ if (LIBCXXABI_ENABLE_SHARED)
191191
SOVERSION "1"
192192
VERSION "${LIBCXXABI_LIBRARY_VERSION}"
193193
DEFINE_SYMBOL ""
194+
POSITION_INDEPENDENT_CODE ON
194195
)
195196

196197
list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_shared")
@@ -243,6 +244,7 @@ if (LIBCXXABI_ENABLE_STATIC)
243244
COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
244245
LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}"
245246
OUTPUT_NAME "c++abi"
247+
POSITION_INDEPENDENT_CODE ON
246248
)
247249

248250
if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)

libunwind/src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ if (LIBUNWIND_ENABLE_SHARED)
141141
OUTPUT_NAME "unwind"
142142
VERSION "1.0"
143143
SOVERSION "1"
144+
POSITION_INDEPENDENT_CODE ON
144145
)
145146
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
146147
if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
@@ -166,6 +167,7 @@ if (LIBUNWIND_ENABLE_STATIC)
166167
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
167168
LINKER_LANGUAGE C
168169
OUTPUT_NAME "unwind"
170+
POSITION_INDEPENDENT_CODE ON
169171
)
170172

171173
if(LIBUNWIND_HIDE_SYMBOLS)

0 commit comments

Comments
 (0)