Skip to content

Commit 7b8f153

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 b21fa18 commit 7b8f153

19 files changed

+252
-241
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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# cmake -G Ninja ^
2222
# -DTOOLCHAIN_TARGET_TRIPLE=aarch64-unknown-linux-gnu ^
2323
# -DTOOLCHAIN_TARGET_SYSROOTFS=<path-to-develop-arm-linux-root-fs> ^
24-
# -DTOOLCHAIN_SHARED_LIBS=OFF ^
24+
# -DTOOLCHAIN_SHARED_LIBS=OFF ^
2525
# -DCMAKE_INSTALL_PREFIX=../install ^
2626
# -DCMAKE_CXX_FLAGS="-D__OPTIMIZE__" ^
2727
# -DREMOTE_TEST_HOST="<hostname>" ^
@@ -205,7 +205,7 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CXX_LIBRARY
205205
# The compiler-rt tests disable the clang configuration files during the execution by setting CLANG_NO_DEFAULT_CONFIG=1
206206
# and drops out the --sysroot from there. Provide it explicity via the test flags here if target sysroot has been specified.
207207
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_TEST_COMPILER_CFLAGS "--stdlib=libc++ ${sysroot_flags}" CACHE STRING "")
208-
208+
209209
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
210210
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
211211

@@ -218,10 +218,12 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED
218218
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
219219
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
220220
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION ${LIBCXX_ABI_VERSION} CACHE STRING "")
221-
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI "libcxxabi" CACHE STRING "") #!!!
221+
if (TOOLCHAIN_USE_STATIC_LIBS)
222+
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI "merged-libcxxabi" CACHE STRING "")
223+
else()
224+
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI "libcxxabi" CACHE STRING "")
225+
endif()
222226
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
223-
# Merge libc++ and libc++abi libraries into the single libc++ library file.
224-
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ${TOOLCHAIN_USE_STATIC_LIBS} CACHE BOOL "")
225227
# Forcely disable the libc++ benchmarks on Windows build hosts
226228
# (current benchmark test configuration does not support the cross builds there).
227229
if (WIN32)

clang/cmake/caches/Fuchsia-stage2.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ if(APPLE)
8181
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
8282
set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
8383
set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
84-
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
84+
set(LIBCXX_CXX_ABI "merged-libcxxabi" CACHE STRING "")
8585
set(LIBCXX_HARDENING_MODE "none" CACHE STRING "")
8686
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
8787
set(RUNTIMES_CMAKE_ARGS "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13;-DCMAKE_OSX_ARCHITECTURES=arm64|x86_64" CACHE STRING "")
@@ -178,9 +178,9 @@ foreach(target aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unkn
178178
set(RUNTIMES_${target}_LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
179179
set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
180180
set(RUNTIMES_${target}_LIBCXXABI_INSTALL_LIBRARY OFF CACHE BOOL "")
181+
set(RUNTIMES_${target}_LIBCXX_CXX_ABI "merged-libcxxabi" CACHE STRING "")
181182
set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
182183
set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
183-
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
184184
set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
185185
set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
186186
set(RUNTIMES_${target}_SANITIZER_CXX_ABI "libc++" CACHE STRING "")
@@ -242,10 +242,10 @@ if(FUCHSIA_SDK)
242242
set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
243243
set(RUNTIMES_${target}_LIBCXXABI_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")
244244
set(RUNTIMES_${target}_LIBCXXABI_INSTALL_STATIC_LIBRARY OFF CACHE BOOL "")
245+
set(RUNTIMES_${target}_LIBCXX_ABILIB_FOR_STATIC "merged-libcxxabi" CACHE STRING "")
246+
set(RUNTIMES_${target}_LIBCXX_ABILIB_FOR_SHARED "shared-libcxxabi" CACHE STRING "")
245247
set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
246-
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
247248
set(RUNTIMES_${target}_LIBCXX_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")
248-
set(RUNTIMES_${target}_LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY OFF CACHE BOOL "")
249249
set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
250250
set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
251251
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
@@ -108,6 +108,7 @@ endif()
108108

109109
if(WIN32)
110110
set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
111+
set(LIBCXX_CXX_ABI "merged-libcxxabi" CACHE STRING "")
111112
set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
112113
set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
113114
set(BUILTINS_CMAKE_ARGS -DCMAKE_SYSTEM_NAME=Windows CACHE STRING "")
@@ -124,7 +125,6 @@ else()
124125
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
125126
set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
126127
set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
127-
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
128128
set(LIBCXX_HARDENING_MODE "none" CACHE STRING "")
129129
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
130130
set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
@@ -154,8 +154,8 @@ if(BOOTSTRAP_CMAKE_SYSTEM_NAME)
154154
set(RUNTIMES_${target}_LIBCXXABI_INSTALL_LIBRARY OFF CACHE BOOL "")
155155
set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
156156
set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
157-
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
158157
set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
158+
set(RUNTIMES_${target}_LIBCXX_CXX_ABI "merged-libcxxabi" CACHE STRING "")
159159
set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
160160
set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
161161
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
@@ -697,12 +697,11 @@ macro(add_custom_libcxx name prefix)
697697
-DLIBCXXABI_ENABLE_SHARED=OFF
698698
-DLIBCXXABI_HERMETIC_STATIC_LIBRARY=ON
699699
-DLIBCXXABI_INCLUDE_TESTS=OFF
700-
-DLIBCXX_CXX_ABI=libcxxabi
700+
-DLIBCXX_CXX_ABI="merged-libcxxabi"
701701
-DLIBCXX_ENABLE_SHARED=OFF
702702
-DLIBCXX_HERMETIC_STATIC_LIBRARY=ON
703703
-DLIBCXX_INCLUDE_BENCHMARKS=OFF
704704
-DLIBCXX_INCLUDE_TESTS=OFF
705-
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON
706705
-DLLVM_INCLUDE_TESTS=OFF
707706
-DLLVM_INCLUDE_DOCS=OFF
708707
${LIBCXX_CMAKE_ARGS}

libcxx/CMakeLists.txt

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,22 @@ else()
241241
endif()
242242

243243
set(LIBCXX_SUPPORTED_ABI_LIBRARIES none libcxxabi system-libcxxabi libcxxrt libstdc++ libsupc++ vcruntime)
244-
set(LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}" CACHE STRING "Specify C++ ABI library to use. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
245-
if (NOT "${LIBCXX_CXX_ABI}" IN_LIST LIBCXX_SUPPORTED_ABI_LIBRARIES)
246-
message(FATAL_ERROR "Unsupported C++ ABI library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.")
247-
endif()
248-
244+
set(LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}" CACHE STRING
245+
"Specify the C++ ABI library to use for the shared and the static libc++ libraries. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}.
246+
This CMake option also supports \"consumption specifiers\", which specify how the selected ABI library should be consumed by
247+
libc++. The supported specifiers are:
248+
- `shared`: The selected ABI library should be used as a shared library.
249+
- `static`: The selected ABI library should be used as a static library.
250+
- `merged`: The selected ABI library should be a static library whose object files will be merged directly into the produced libc++ library.
251+
252+
A consumption specifier is provided by appending it to the name of the library, such as `LIBCXX_CXX_ABI=merged-libcxxabi`.
253+
If no consumption specifier is provided, the libc++ shared library will default to using a shared ABI library, and the
254+
libc++ static library will default to using a static ABI library.")
255+
set(LIBCXX_ABILIB_FOR_SHARED "${LIBCXX_CXX_ABI}" CACHE STRING "C++ ABI library to use for the shared libc++ library.")
256+
set(LIBCXX_ABILIB_FOR_STATIC "${LIBCXX_CXX_ABI}" CACHE STRING "C++ ABI library to use for the static libc++ library.")
257+
258+
#############################
259+
# TODO: Remove these options in LLVM 21.
249260
option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY
250261
"Use a static copy of the ABI library when linking libc++.
251262
This option cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT." OFF)
@@ -258,17 +269,34 @@ option(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
258269
"Statically link the ABI library to shared library"
259270
${LIBCXX_ENABLE_STATIC_ABI_LIBRARY})
260271

272+
if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY OR LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY OR LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY)
273+
message(WARNING "The LIBCXX_ENABLE_STATIC_ABI_LIBRARY, LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY and "
274+
"LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY options have been deprecated in favor of "
275+
"using LIBCXX_CXX_ABI=merged-libcxxabi. This will become an error in LLVM 21.")
276+
endif()
277+
if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY)
278+
set(LIBCXX_ABILIB_FOR_STATIC "merged-libcxxabi" CACHE STRING "" FORCE)
279+
endif()
280+
if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY)
281+
set(LIBCXX_ABILIB_FOR_SHARED "merged-libcxxabi" CACHE STRING "" FORCE)
282+
endif()
283+
#############################
284+
261285
# Generate and install a linker script inplace of libc++.so. The linker script
262286
# will link libc++ to the correct ABI library. This option is on by default
263-
# on UNIX platforms other than Apple, and on the Fuchsia platform unless we
264-
# statically link libc++abi inside libc++.so, we don't build libc++.so at all
265-
# or we don't have any ABI library.
266-
if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
267-
OR NOT LIBCXX_ENABLE_SHARED
268-
OR LIBCXX_CXX_ABI STREQUAL "none")
269-
set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
270-
elseif((UNIX OR FUCHSIA) AND NOT APPLE)
271-
set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON)
287+
# on UNIX platforms other than Apple unless we are linking the ABI library as
288+
# an object library. This option is also disabled when the ABI library is not
289+
# specified or is specified to be "none".
290+
if(LIBCXX_ENABLE_SHARED)
291+
if ((UNIX OR FUCHSIA) AND NOT APPLE)
292+
if (LIBCXX_ABILIB_FOR_SHARED STREQUAL "merged-libcxxabi" OR LIBCXX_ABILIB_FOR_SHARED STREQUAL "none")
293+
set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
294+
else()
295+
set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON)
296+
endif()
297+
else()
298+
set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
299+
endif()
272300
else()
273301
set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF)
274302
endif()
@@ -382,12 +410,6 @@ if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
382410
endif()
383411
endif()
384412

385-
if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
386-
message(FATAL_ERROR "Conflicting options given.
387-
LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY cannot be specified with
388-
LIBCXX_ENABLE_ABI_LINKER_SCRIPT")
389-
endif()
390-
391413
if (LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT)
392414
message(FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified.")
393415
endif ()
@@ -484,10 +506,6 @@ include(config-ix)
484506
#===============================================================================
485507
# Setup Compiler Flags
486508
#===============================================================================
487-
488-
include(HandleLibC) # Setup the C library flags
489-
include(HandleLibCXXABI) # Setup the ABI library flags
490-
491509
# FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
492510
# Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
493511
# so they don't get transformed into -Wno and -errors respectively.
@@ -820,7 +838,7 @@ if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED)
820838
config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
821839
endif()
822840

823-
if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
841+
if (WIN32 AND LIBCXX_CXX_ABI STREQUAL "merged-libcxxabi")
824842
# If linking libcxxabi statically into libcxx, skip the dllimport attributes
825843
# on symbols we refer to from libcxxabi.
826844
add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS)

0 commit comments

Comments
 (0)