Skip to content

Commit a57278b

Browse files
committed
[libc++] Replace LIBCXX_ENABLE_STATIC_ABI_LIBRARY & friends by a new LIBCXX_CXX_ABI choice
Instead of having complicated options like LIBCXX_ENABLE_STATIC_ABI_LIBRARY and LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY, introduce a more general mechanism to select the ABI library used by libc++. The new mechanism allows specifying the ABI library for the static libc++ and the shared libc++ separately, and allows selecting a "merged" flavor of libc++ for both the in-tree libc++abi and any external static ABI library. As an example, one can now specify arbitrary combinations like -DLIBCXX_ABILIB_FOR_SHARED="shared-libcxxabi" -DLIBCXX_ABILIB_FOR_STATIC="merged-libcxxabi" which would have been impossible or very brittle in the past. In theory, one can even select an entirely different ABI library for the static and the shared libc++ (e.g. libc++abi vs libsupc++), although supporting that is not a primary goal of this patch but merely a result of the general mechanism. Closes #77655 Fixes #57759 Differential Revision: https://reviews.llvm.org/D125683
1 parent a2ba438 commit a57278b

File tree

18 files changed

+216
-230
lines changed

18 files changed

+216
-230
lines changed

clang/cmake/caches/Android.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
2121
list(APPEND EXTRA_ARGS -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=${LIBCXX_ENABLE_ABI_LINKER_SCRIPT})
2222
endif()
2323

24-
if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
25-
list(APPEND EXTRA_ARGS -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
24+
if (LIBCXX_CXX_ABI)
25+
list(APPEND EXTRA_ARGS -DLIBCXX_CXX_ABI=${LIBCXX_CXX_ABI})
2626
endif()
2727

2828
if (LLVM_BUILD_EXTERNAL_COMPILER_RT)

clang/cmake/caches/CrossWinToARMLinux.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,8 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED
215215
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
216216
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
217217
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION ${LIBCXX_ABI_VERSION} CACHE STRING "")
218-
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI "libcxxabi" CACHE STRING "") #!!!
218+
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI "merged-libcxxabi" CACHE STRING "") #!!!
219219
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
220-
# Merge libc++ and libc++abi libraries into the single libc++ library file.
221-
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
222220

223221
# Avoid searching for the python3 interpreter during the runtimes configuration for the cross builds.
224222
# It starts searching the python3 package using the target's sysroot path, that usually is not compatible with the build host.

clang/cmake/caches/Fuchsia-stage2.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ if(APPLE)
8383
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
8484
set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
8585
set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
86-
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
86+
set(LIBCXX_CXX_ABI "merged-libcxxabi" CACHE STRING "")
8787
set(LIBCXX_HARDENING_MODE "none" CACHE STRING "")
8888
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
8989
set(RUNTIMES_CMAKE_ARGS "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13;-DCMAKE_OSX_ARCHITECTURES=arm64|x86_64" CACHE STRING "")
@@ -180,9 +180,9 @@ foreach(target aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unkn
180180
set(RUNTIMES_${target}_LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
181181
set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
182182
set(RUNTIMES_${target}_LIBCXXABI_INSTALL_LIBRARY OFF CACHE BOOL "")
183+
set(RUNTIMES_${target}_LIBCXX_CXX_ABI "merged-libcxxabi" CACHE STRING "")
183184
set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
184185
set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
185-
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
186186
set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
187187
set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
188188
set(RUNTIMES_${target}_SANITIZER_CXX_ABI "libc++" CACHE STRING "")
@@ -244,10 +244,10 @@ if(FUCHSIA_SDK)
244244
set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
245245
set(RUNTIMES_${target}_LIBCXXABI_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")
246246
set(RUNTIMES_${target}_LIBCXXABI_INSTALL_STATIC_LIBRARY OFF CACHE BOOL "")
247+
set(RUNTIMES_${target}_LIBCXX_ABILIB_FOR_STATIC "merged-libcxxabi" CACHE STRING "")
248+
set(RUNTIMES_${target}_LIBCXX_ABILIB_FOR_SHARED "shared-libcxxabi" CACHE STRING "")
247249
set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
248-
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
249250
set(RUNTIMES_${target}_LIBCXX_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")
250-
set(RUNTIMES_${target}_LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY OFF CACHE BOOL "")
251251
set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
252252
set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
253253
set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")

clang/cmake/caches/Fuchsia.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ endif()
109109

110110
if(WIN32)
111111
set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
112+
set(LIBCXX_CXX_ABI "merged-libcxxabi" CACHE STRING "")
112113
set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
113114
set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
114115
set(BUILTINS_CMAKE_ARGS -DCMAKE_SYSTEM_NAME=Windows CACHE STRING "")
@@ -125,7 +126,6 @@ else()
125126
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
126127
set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
127128
set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
128-
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
129129
set(LIBCXX_HARDENING_MODE "none" CACHE STRING "")
130130
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
131131
set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
@@ -155,8 +155,8 @@ if(BOOTSTRAP_CMAKE_SYSTEM_NAME)
155155
set(RUNTIMES_${target}_LIBCXXABI_INSTALL_LIBRARY OFF CACHE BOOL "")
156156
set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
157157
set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
158-
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
159158
set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
159+
set(RUNTIMES_${target}_LIBCXX_CXX_ABI "merged-libcxxabi" CACHE STRING "")
160160
set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
161161
set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
162162
set(RUNTIMES_${target}_SANITIZER_CXX_ABI "libc++" CACHE STRING "")

compiler-rt/cmake/Modules/AddCompilerRT.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,12 +696,11 @@ macro(add_custom_libcxx name prefix)
696696
-DLIBCXXABI_ENABLE_SHARED=OFF
697697
-DLIBCXXABI_HERMETIC_STATIC_LIBRARY=ON
698698
-DLIBCXXABI_INCLUDE_TESTS=OFF
699-
-DLIBCXX_CXX_ABI=libcxxabi
699+
-DLIBCXX_CXX_ABI="merged-libcxxabi"
700700
-DLIBCXX_ENABLE_SHARED=OFF
701701
-DLIBCXX_HERMETIC_STATIC_LIBRARY=ON
702702
-DLIBCXX_INCLUDE_BENCHMARKS=OFF
703703
-DLIBCXX_INCLUDE_TESTS=OFF
704-
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON
705704
${LIBCXX_CMAKE_ARGS}
706705
INSTALL_COMMAND ""
707706
STEP_TARGETS configure build

libcxx/CMakeLists.txt

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,22 @@ else()
230230
endif()
231231

232232
set(LIBCXX_SUPPORTED_ABI_LIBRARIES none libcxxabi system-libcxxabi libcxxrt libstdc++ libsupc++ vcruntime)
233-
set(LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}" CACHE STRING "Specify C++ ABI library to use. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
234-
if (NOT "${LIBCXX_CXX_ABI}" IN_LIST LIBCXX_SUPPORTED_ABI_LIBRARIES)
235-
message(FATAL_ERROR "Unsupported C++ ABI library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
236-
endif()
237-
233+
set(LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}" CACHE STRING
234+
"Specify the C++ ABI library to use for the shared and the static libc++ libraries. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.
235+
This CMake option also supports \"consumption specifiers\", which specify how the selected ABI library should be consumed by
236+
libc++. The supported specifiers are:
237+
- `shared`: The selected ABI library should be used as a shared library.
238+
- `static`: The selected ABI library should be used as a static library.
239+
- `merged`: The selected ABI library should be a static library whose object files will be merged directly into the produced libc++ library.
240+
241+
A consumption specifier is provided by appending it to the name of the library, such as `LIBCXX_CXX_ABI=merged-libcxxabi`.
242+
If no consumption specifier is provided, the libc++ shared library will default to using a shared ABI library, and the
243+
libc++ static library will default to using a static ABI library.")
244+
set(LIBCXX_ABILIB_FOR_SHARED "${LIBCXX_CXX_ABI}" CACHE STRING "C++ ABI library to use for the shared libc++ library.")
245+
set(LIBCXX_ABILIB_FOR_STATIC "${LIBCXX_CXX_ABI}" CACHE STRING "C++ ABI library to use for the static libc++ library.")
246+
247+
#############################
248+
# TODO: Remove these options in LLVM 21.
238249
option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY
239250
"Use a static copy of the ABI library when linking libc++.
240251
This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF)
@@ -247,17 +258,34 @@ option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
247258
"Statically link the ABI library to shared library"
248259
${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
249260

261+
if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY OR LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY OR LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY)
262+
message(WARNING "The LIBCXX_ENABLE_STATIC_ABI_LIBRARY, LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY and "
263+
"LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY options have been deprecated in favor of "
264+
"using LIBCXX_CXX_ABI=merged-libcxxabi. This will become an error in LLVM 21.")
265+
endif()
266+
if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY)
267+
set(LIBCXX_ABILIB_FOR_STATIC "merged-libcxxabi" CACHE STRING "" FORCE)
268+
endif()
269+
if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY)
270+
set(LIBCXX_ABILIB_FOR_SHARED "merged-libcxxabi" CACHE STRING "" FORCE)
271+
endif()
272+
#############################
273+
250274
# Generate and install a linker script inplace of libc++.so. The linker script
251275
# will link libc++ to the correct ABI library. This option is on by default
252-
# on UNIX platforms other than Apple, and on the Fuchsia platform unless we
253-
# statically link libc++abi inside libc++.so, we don't build libc++.so at all
254-
# or we don't have any ABI library.
255-
if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
256-
OR NOT LIBCXX_ENABLE_SHARED
257-
OR LIBCXX_CXX_ABI STREQUAL "none")
258-
set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
259-
elseif((UNIX OR FUCHSIA) AND NOT APPLE)
260-
set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON)
276+
# on UNIX platforms other than Apple unless we are linking the ABI library as
277+
# an object library. This option is also disabled when the ABI library is not
278+
# specified or is specified to be "none".
279+
if(LIBCXX_ENABLE_SHARED)
280+
if ((UNIX OR FUCHSIA) AND NOT APPLE)
281+
if (LIBCXX_ABILIB_FOR_SHARED STREQUAL "merged-libcxxabi" OR LIBCXX_ABILIB_FOR_SHARED STREQUAL "none")
282+
set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
283+
else()
284+
set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON)
285+
endif()
286+
else()
287+
set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
288+
endif()
261289
else()
262290
set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
263291
endif()
@@ -379,12 +407,6 @@ if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
379407
endif()
380408
endif()
381409

382-
if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
383-
message(FATAL_ERROR "Conflicting options given.
384-
LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY cannot be specified with
385-
LIBCXX_ENABLE_ABI_LINKER_SCRIPT")
386-
endif()
387-
388410
if (LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT)
389411
message(FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified.")
390412
endif ()
@@ -481,10 +503,6 @@ include(config-ix)
481503
#===============================================================================
482504
# Setup Compiler Flags
483505
#===============================================================================
484-
485-
include(HandleLibC) # Setup the C library flags
486-
include(HandleLibCXXABI) # Setup the ABI library flags
487-
488506
# FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
489507
# Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
490508
# so they don't get transformed into -Wno and -errors respectively.
@@ -815,7 +833,7 @@ if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED)
815833
config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
816834
endif()
817835

818-
if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
836+
if (WIN32 AND LIBCXX_CXX_ABI STREQUAL "merged-libcxxabi")
819837
# If linking libcxxabi statically into libcxx, skip the dllimport attributes
820838
# on symbols we refer to from libcxxabi.
821839
add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)

0 commit comments

Comments
 (0)