[libcxx-commits] [libcxx] [libcxxabi] [llvm] [runtimes] Unify exception and RTTI configuration for the runtimes (PR #165296)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Oct 27 12:00:28 PDT 2025
https://github.com/ldionne created https://github.com/llvm/llvm-project/pull/165296
This patch introduces a unified mechanism for configuring whether exceptions and RTTI are enabled across the runtimes. It does that by introducing new options named RUNTIMES_ENABLE_{EXCEPTIONS,RTTI} and providing a CMake interface target that can be used by various runtime targets (cxx_shared, cxx_static, etc) to get the relevant flags.
This patch aims to create a precedent and an example that can be followed to unify other similar configuration options across the runtimes.
There are still the following open questions:
- Does it make sense at all to have a unified option for all the runtimes? For example, is it desirable to be able to build libc++ without exception support, but libc++abi with exception support?
- How should we deal with options where one of the runtimes does not allow configuring an option? For example, libunwind currently doesn't allow configuring whether exceptions are enabled: they are always enabled. If libunwind links against the interface target for language-level flags and RUNTIMES_ENABLE_EXCEPTIONS=OFF is used, that won't work.
- Where should we document these new unified options? Should we create a documentation page for all of the runtimes?
>From 987ed32b009a580918f89ac519091288f186e858 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 27 Oct 2025 11:46:52 -0700
Subject: [PATCH] [runtimes] Unify exception and RTTI configuration for the
runtimes
This patch introduces a unified mechanism for configuring whether
exceptions and RTTI are enabled across the runtimes. It does that
by introducing new options named RUNTIMES_ENABLE_{EXCEPTIONS,RTTI}
and providing a CMake interface target that can be used by various
runtime targets (cxx_shared, cxx_static, etc) to get the relevant
flags.
This patch aims to create a precedent and an example that can be
followed to unify other similar configuration options across the
runtimes.
There are still the following open questions:
- Does it make sense at all to have a unified option for all the
runtimes? For example, is it desirable to be able to build libc++
without exception support, but libc++abi with exception support?
- How should we deal with options where one of the runtimes does not
allow configuring an option? For example, libunwind currently doesn't
allow configuring whether exceptions are enabled: they are always
enabled. If libunwind links against the interface target for
language-level flags and RUNTIMES_ENABLE_EXCEPTIONS=OFF is used,
that won't work.
- Where should we document these new unified options? Should we create
a documentation page for all of the runtimes?
---
libcxx/CMakeLists.txt | 40 ++--------------
libcxx/cmake/caches/AMDGPU.cmake | 7 +--
libcxx/cmake/caches/Armv7M-picolibc.cmake | 5 +-
.../caches/Armv7Thumb-no-exceptions.cmake | 3 +-
.../caches/Armv8Thumb-no-exceptions.cmake | 3 +-
.../cmake/caches/Generic-no-exceptions.cmake | 3 +-
libcxx/cmake/caches/Generic-no-rtti.cmake | 6 +--
libcxx/cmake/caches/NVPTX.cmake | 7 +--
libcxx/docs/Modules.rst | 7 +--
libcxx/docs/VendorDocumentation.rst | 13 +-----
libcxx/lib/abi/CMakeLists.txt | 2 +-
libcxx/modules/CMakeLists.txt.in | 10 +---
libcxx/test/CMakeLists.txt | 4 +-
libcxx/utils/ci/run-buildbot | 10 ++--
libcxxabi/CMakeLists.txt | 16 -------
libcxxabi/src/CMakeLists.txt | 4 +-
libcxxabi/test/CMakeLists.txt | 2 +-
runtimes/CMakeLists.txt | 3 ++
runtimes/cmake/Modules/HandleFlags.cmake | 6 +++
runtimes/cmake/Modules/LanguageFlags.cmake | 46 +++++++++++++++++++
20 files changed, 86 insertions(+), 111 deletions(-)
create mode 100644 runtimes/cmake/Modules/LanguageFlags.cmake
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index a119850cd808e..f91010591efd0 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -47,10 +47,6 @@ include(HandleCompilerRT)
# Basic options ---------------------------------------------------------------
option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON)
-option(LIBCXX_ENABLE_EXCEPTIONS "Enable exceptions in the built library." ON)
-option(LIBCXX_ENABLE_RTTI
- "Use runtime type information.
- This option may only be set to OFF when LIBCXX_ENABLE_EXCEPTIONS=OFF." ON)
option(LIBCXX_ENABLE_FILESYSTEM
"Whether to include support for parts of the library that rely on a filesystem being
available on the platform. This includes things like most parts of <filesystem> and
@@ -164,8 +160,8 @@ if (WIN32 OR MINGW OR ANDROID OR "${CMAKE_SYSTEM_NAME}" MATCHES "AIX"
OR NOT LIBCXX_ENABLE_THREADS
OR NOT LIBCXX_ENABLE_FILESYSTEM
OR NOT LIBCXX_ENABLE_RANDOM_DEVICE
- OR NOT LIBCXX_ENABLE_EXCEPTIONS
- OR NOT LIBCXX_ENABLE_RTTI)
+ OR NOT RUNTIMES_ENABLE_EXCEPTIONS
+ OR NOT RUNTIMES_ENABLE_RTTI)
set(_include_benchmarks OFF)
else()
set(_include_benchmarks ON)
@@ -358,12 +354,6 @@ if (LIBCXX_HAS_PTHREAD_API)
endif()
endif()
-if (NOT LIBCXX_ENABLE_RTTI AND LIBCXX_ENABLE_EXCEPTIONS)
- message(FATAL_ERROR "Libc++ cannot be built with exceptions enabled but RTTI"
- " disabled, since that configuration is broken. See"
- " https://llvm.org/PR66117 for details.")
-endif()
-
if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
if (APPLE)
message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets")
@@ -540,29 +530,6 @@ function(cxx_add_basic_build_flags target)
target_compile_options(${target} PUBLIC "${LIBCXX_ADDITIONAL_COMPILE_FLAGS}")
endfunction()
-# Exception flags =============================================================
-function(cxx_add_exception_flags target)
- if (LIBCXX_ENABLE_EXCEPTIONS)
- # Catches C++ exceptions only and tells the compiler to assume that extern C
- # functions never throw a C++ exception.
- target_add_compile_flags_if_supported(${target} PUBLIC -EHsc)
- else()
- target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-)
- target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions)
- endif()
-endfunction()
-
-# RTTI flags ==================================================================
-function(cxx_add_rtti_flags target)
- if (NOT LIBCXX_ENABLE_RTTI)
- if (MSVC)
- target_add_compile_flags_if_supported(${target} PUBLIC -GR-)
- else()
- target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti)
- endif()
- endif()
-endfunction()
-
# Modules flags ===============================================================
# FIXME The libc++ sources are fundamentally non-modular. They need special
# versions of the headers in order to provide C++03 and legacy ABI definitions.
@@ -817,11 +784,10 @@ function(cxx_add_common_build_flags target)
cxx_add_basic_build_flags(${target})
cxx_add_warning_flags(${target} ${LIBCXX_ENABLE_WERROR} ${LIBCXX_ENABLE_PEDANTIC})
cxx_add_windows_flags(${target})
- cxx_add_exception_flags(${target})
- cxx_add_rtti_flags(${target})
cxx_add_module_flags(${target})
cxx_link_system_libraries(${target})
target_link_libraries(${target} PRIVATE cxx-sanitizer-flags)
+ target_link_libraries(${target} PRIVATE runtimes-language-flags)
endfunction()
#===============================================================================
diff --git a/libcxx/cmake/caches/AMDGPU.cmake b/libcxx/cmake/caches/AMDGPU.cmake
index 5d09a1db8da44..c188788f5dd66 100644
--- a/libcxx/cmake/caches/AMDGPU.cmake
+++ b/libcxx/cmake/caches/AMDGPU.cmake
@@ -1,12 +1,14 @@
+# Configuration options for all the runtimes
+set(RUNTIMES_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+set(RUNTIMES_ENABLE_RTTI OFF CACHE BOOL "")
+
# Configuration options for libcxx.
set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
-set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
set(LIBCXX_ENABLE_LOCALIZATION ON CACHE BOOL "")
set(LIBCXX_ENABLE_MONOTONIC_CLOCK ON CACHE BOOL "")
set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
set(LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
-set(LIBCXX_ENABLE_RTTI OFF CACHE BOOL "")
set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
set(LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
@@ -21,7 +23,6 @@ set(RUNTIMES_USE_LIBC "llvm-libc" CACHE STRING "")
# Configuration options for libcxxabi.
set(LIBCXXABI_BAREMETAL ON CACHE BOOL "")
-set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
diff --git a/libcxx/cmake/caches/Armv7M-picolibc.cmake b/libcxx/cmake/caches/Armv7M-picolibc.cmake
index 9df71fba2cadd..75825ad117da5 100644
--- a/libcxx/cmake/caches/Armv7M-picolibc.cmake
+++ b/libcxx/cmake/caches/Armv7M-picolibc.cmake
@@ -6,6 +6,8 @@ set(CMAKE_C_FLAGS "-mfloat-abi=soft" CACHE STRING "")
set(CMAKE_SYSTEM_NAME Generic CACHE STRING "")
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE STRING "")
set(LLVM_USE_LINKER "lld" CACHE STRING "")
+set(RUNTIMES_ENABLE_EXCEPTIONS ON CACHE BOOL "")
+set(RUNTIMES_ENABLE_RTTI ON CACHE BOOL "")
set(COMPILER_RT_BAREMETAL_BUILD ON CACHE BOOL "")
set(COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_PROFILE OFF CACHE BOOL "")
@@ -14,17 +16,14 @@ set(COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
set(COMPILER_RT_DEFAULT_TARGET_ONLY ON CACHE BOOL "")
set(LIBCXXABI_BAREMETAL ON CACHE BOOL "")
set(LIBCXXABI_ENABLE_ASSERTIONS OFF CACHE BOOL "")
-set(LIBCXXABI_ENABLE_EXCEPTIONS ON CACHE BOOL "")
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
set(LIBCXXABI_ENABLE_STATIC ON CACHE BOOL "")
set(LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
set(LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
-set(LIBCXX_ENABLE_EXCEPTIONS ON CACHE BOOL "")
set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE STRING "")
set(LIBCXX_ENABLE_MONOTONIC_CLOCK OFF CACHE BOOL "")
set(LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
-set(LIBCXX_ENABLE_RTTI ON CACHE BOOL "")
set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
set(LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
set(LIBCXX_ENABLE_THREADS OFF CACHE BOOL "")
diff --git a/libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake b/libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake
index 5ddfa15d77a49..4a059c0a1efb5 100644
--- a/libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake
+++ b/libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake
@@ -1,7 +1,6 @@
set(CMAKE_CXX_COMPILER_TARGET "armv7l-linux-gnueabihf" CACHE STRING "")
set(CMAKE_CXX_FLAGS "-mthumb" CACHE STRING "")
set(CMAKE_C_FLAGS "-mthumb" CACHE STRING "")
-set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
-set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+set(RUNTIMES_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
set(LIBCXX_TEST_PARAMS "enable_modules=clang" CACHE STRING "")
set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
diff --git a/libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake b/libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake
index b0a53484961e4..1c06ff7c8fbfa 100644
--- a/libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake
+++ b/libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake
@@ -1,7 +1,6 @@
set(CMAKE_CXX_COMPILER_TARGET "armv8l-linux-gnueabihf" CACHE STRING "")
set(CMAKE_CXX_FLAGS "-mthumb" CACHE STRING "")
set(CMAKE_C_FLAGS "-mthumb" CACHE STRING "")
-set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
-set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+set(RUNTIMES_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
set(LIBCXX_TEST_PARAMS "enable_modules=clang" CACHE STRING "")
set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
diff --git a/libcxx/cmake/caches/Generic-no-exceptions.cmake b/libcxx/cmake/caches/Generic-no-exceptions.cmake
index c5b2ffd0a36c8..e357bd2ea345b 100644
--- a/libcxx/cmake/caches/Generic-no-exceptions.cmake
+++ b/libcxx/cmake/caches/Generic-no-exceptions.cmake
@@ -1,5 +1,4 @@
-set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
-set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+set(RUNTIMES_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
# Speed up the CI
set(LIBCXX_TEST_PARAMS "enable_modules=clang" CACHE STRING "")
diff --git a/libcxx/cmake/caches/Generic-no-rtti.cmake b/libcxx/cmake/caches/Generic-no-rtti.cmake
index d080360fe76d7..dd9b876615a7c 100644
--- a/libcxx/cmake/caches/Generic-no-rtti.cmake
+++ b/libcxx/cmake/caches/Generic-no-rtti.cmake
@@ -1,7 +1,5 @@
-set(LIBCXX_ENABLE_RTTI OFF CACHE BOOL "")
-set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
-set(LIBCXXABI_ENABLE_RTTI OFF CACHE BOOL "")
-set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+set(RUNTIMES_ENABLE_RTTI OFF CACHE BOOL "")
+set(RUNTIMES_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
# Speed up the CI
set(LIBCXX_TEST_PARAMS "enable_modules=clang" CACHE STRING "")
diff --git a/libcxx/cmake/caches/NVPTX.cmake b/libcxx/cmake/caches/NVPTX.cmake
index 46fa6e7a1be08..f57904f1ff79c 100644
--- a/libcxx/cmake/caches/NVPTX.cmake
+++ b/libcxx/cmake/caches/NVPTX.cmake
@@ -1,12 +1,14 @@
+# Configuration options for the runtimes.
+set(RUNTIMES_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+set(RUNTIMES_ENABLE_RTTI OFF CACHE BOOL "")
+
# Configuration options for libcxx.
set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
-set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
set(LIBCXX_ENABLE_LOCALIZATION ON CACHE BOOL "")
set(LIBCXX_ENABLE_MONOTONIC_CLOCK ON CACHE BOOL "")
set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
set(LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
-set(LIBCXX_ENABLE_RTTI OFF CACHE BOOL "")
set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
set(LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
@@ -21,7 +23,6 @@ set(RUNTIMES_USE_LIBC "llvm-libc" CACHE STRING "")
# Configuration options for libcxxabi.
set(LIBCXXABI_BAREMETAL ON CACHE BOOL "")
-set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
diff --git a/libcxx/docs/Modules.rst b/libcxx/docs/Modules.rst
index c8f3e6194fd84..68f0386df6ae2 100644
--- a/libcxx/docs/Modules.rst
+++ b/libcxx/docs/Modules.rst
@@ -48,15 +48,10 @@ What works
* ``LIBCXX_ENABLE_FILESYSTEM``
* ``LIBCXX_ENABLE_RANDOM_DEVICE``
* ``LIBCXX_ENABLE_UNICODE``
- * ``LIBCXX_ENABLE_EXCEPTIONS`` [#note-no-windows]_
+ * ``RUNTIMES_ENABLE_EXCEPTIONS``
* A C++20 based extension
-.. note::
-
- .. [#note-no-windows] This configuration will probably not work on Windows
- due to hard-coded compilation flags.
-
Some of the current limitations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/libcxx/docs/VendorDocumentation.rst b/libcxx/docs/VendorDocumentation.rst
index 7eba598909a74..0ea66b25a0000 100644
--- a/libcxx/docs/VendorDocumentation.rst
+++ b/libcxx/docs/VendorDocumentation.rst
@@ -227,18 +227,7 @@ General purpose options
Additional libraries libc++ is linked to which can be provided in cache.
-.. option:: LIBCXX_ENABLE_EXCEPTIONS:BOOL
-
- **Default**: ``ON``
-
- Build libc++ with exception support.
-
-.. option:: LIBCXX_ENABLE_RTTI:BOOL
-
- **Default**: ``ON``
-
- Build libc++ with run time type information.
- This option may only be set to OFF when LIBCXX_ENABLE_EXCEPTIONS=OFF.
+.. TODO: Where should we document the runtimes build options?
.. option:: LIBCXX_INCLUDE_TESTS:BOOL
diff --git a/libcxx/lib/abi/CMakeLists.txt b/libcxx/lib/abi/CMakeLists.txt
index 8f277aad2dcd5..d848df424d5ba 100644
--- a/libcxx/lib/abi/CMakeLists.txt
+++ b/libcxx/lib/abi/CMakeLists.txt
@@ -53,7 +53,7 @@ cxx_abi_list_identifier(abi_list_identifier
"${LIBCXX_CXX_ABI}"
"${LIBCXX_ABI_VERSION}"
"${LIBCXX_ABI_UNSTABLE}"
- "${LIBCXX_ENABLE_EXCEPTIONS}"
+ "${RUNTIMES_ENABLE_EXCEPTIONS}"
"${LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS}"
)
diff --git a/libcxx/modules/CMakeLists.txt.in b/libcxx/modules/CMakeLists.txt.in
index 9fef16e9cefde..421f9dcd00669 100644
--- a/libcxx/modules/CMakeLists.txt.in
+++ b/libcxx/modules/CMakeLists.txt.in
@@ -43,10 +43,6 @@ target_sources(std
target_include_directories(std SYSTEM PUBLIC @LIBCXX_CONFIGURED_INCLUDE_DIRS@)
-if (NOT @LIBCXX_ENABLE_EXCEPTIONS@)
- target_compile_options(std PUBLIC -fno-exceptions)
-endif()
-
target_compile_options(std
PUBLIC
-nostdinc++
@@ -58,7 +54,7 @@ target_compile_options(std
-Wno-reserved-user-defined-literal
)
target_link_options(std PUBLIC -nostdlib++ -Wl,-rpath, at LIBCXX_LIBRARY_DIR@ -L at LIBCXX_LIBRARY_DIR@)
-target_link_libraries(std c++)
+target_link_libraries(std c++ runtimes-language-flags)
set_target_properties(std
PROPERTIES
OUTPUT_NAME "c++std"
@@ -74,10 +70,6 @@ target_sources(std.compat
target_include_directories(std.compat SYSTEM PUBLIC @LIBCXX_CONFIGURED_INCLUDE_DIRS@)
-if (NOT @LIBCXX_ENABLE_EXCEPTIONS@)
- target_compile_options(std.compat PUBLIC -fno-exceptions)
-endif()
-
target_compile_options(std.compat
PUBLIC
-nostdinc++
diff --git a/libcxx/test/CMakeLists.txt b/libcxx/test/CMakeLists.txt
index f4e577aed57de..ba5086e41eb33 100644
--- a/libcxx/test/CMakeLists.txt
+++ b/libcxx/test/CMakeLists.txt
@@ -70,11 +70,11 @@ else()
set(_libcxx_benchmark_mode "no")
endif()
-if (NOT LIBCXX_ENABLE_EXCEPTIONS)
+if (NOT RUNTIMES_ENABLE_EXCEPTIONS)
serialize_lit_param(SERIALIZED_LIT_PARAMS enable_exceptions False)
endif()
-if (NOT LIBCXX_ENABLE_RTTI)
+if (NOT RUNTIMES_ENABLE_RTTI)
serialize_lit_param(SERIALIZED_LIT_PARAMS enable_rtti False)
endif()
diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index 57ecf1e49dbf2..352f7f8160314 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -617,8 +617,7 @@ aarch64)
aarch64-no-exceptions)
clean
generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/AArch64.cmake" \
- -DLIBCXX_ENABLE_EXCEPTIONS=OFF \
- -DLIBCXXABI_ENABLE_EXCEPTIONS=OFF
+ -DRUNTIMES_ENABLE_EXCEPTIONS=OFF
check-runtimes
;;
# Aka Armv8 32 bit
@@ -650,10 +649,9 @@ armv7m-picolibc)
armv7m-picolibc-no-exceptions)
test-armv7m-picolibc \
-C "${MONOREPO_ROOT}/libcxx/cmake/caches/Armv7M-picolibc.cmake" \
- -DLIBCXXABI_ENABLE_EXCEPTIONS=OFF \
- -DLIBCXXABI_ENABLE_STATIC_UNWINDER=OFF \
- -DLIBCXX_ENABLE_EXCEPTIONS=OFF \
- -DLIBCXX_ENABLE_RTTI=OFF
+ -DRUNTIMES_ENABLE_EXCEPTIONS=OFF \
+ -DRUNTIMES_ENABLE_RTTI=OFF \
+ -DLIBCXXABI_ENABLE_STATIC_UNWINDER=OFF
;;
clang-cl-dll)
clean
diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index 3dabd87b9c587..055df81a60856 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -46,9 +46,6 @@ include(CMakeDependentOption)
include(HandleCompilerRT)
# Define options.
-option(LIBCXXABI_ENABLE_EXCEPTIONS
- "Provide support for exceptions in the runtime.
- When disabled, libc++abi does not support stack unwinding and other exceptions-related features." ON)
option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
@@ -325,19 +322,6 @@ add_definitions(-D_LIBCPP_BUILDING_LIBRARY)
# Get feature flags.
add_compile_flags_if_supported(-fstrict-aliasing)
-# Exceptions
-if (LIBCXXABI_ENABLE_EXCEPTIONS)
- # Catches C++ exceptions only and tells the compiler to assume that extern C
- # functions never throw a C++ exception.
- add_compile_flags_if_supported(-EHsc)
- # Do we really need to be run through the C compiler ?
- add_c_compile_flags_if_supported(-funwind-tables)
-else()
- add_compile_flags_if_supported(-fno-exceptions)
- add_compile_flags_if_supported(-EHs-)
- add_compile_flags_if_supported(-EHa-)
-endif()
-
# Assert
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
if (LIBCXXABI_ENABLE_ASSERTIONS)
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index 38a54b16278a7..b5a6920f51962 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -25,7 +25,7 @@ if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
)
endif()
-if (LIBCXXABI_ENABLE_EXCEPTIONS)
+if (RUNTIMES_ENABLE_EXCEPTIONS)
list(APPEND LIBCXXABI_SOURCES
cxa_exception.cpp
cxa_personality.cpp
@@ -258,7 +258,7 @@ endif()
# whether the exception runtime machinery is provided.
reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/std-exceptions.exp")
-if (LIBCXXABI_ENABLE_EXCEPTIONS)
+if (RUNTIMES_ENABLE_EXCEPTIONS)
reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/itanium-exceptions.exp")
if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "^(armv6|armv7|armv7s)$")
diff --git a/libcxxabi/test/CMakeLists.txt b/libcxxabi/test/CMakeLists.txt
index 9eabfb08240b6..dcab5ba42ae56 100644
--- a/libcxxabi/test/CMakeLists.txt
+++ b/libcxxabi/test/CMakeLists.txt
@@ -66,7 +66,7 @@ set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to pick
serialize_lit_string_param(SERIALIZED_LIT_PARAMS compiler "${CMAKE_CXX_COMPILER}")
-if (NOT LIBCXXABI_ENABLE_EXCEPTIONS)
+if (NOT RUNTIMES_ENABLE_EXCEPTIONS)
serialize_lit_param(SERIALIZED_LIT_PARAMS enable_exceptions False)
endif()
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index d3280a5867dec..ca29141a2d647 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -33,6 +33,9 @@ list(INSERT CMAKE_MODULE_PATH 0
"${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake/modules"
)
+# Include options to configure the runtime projects
+include(cmake/Modules/LanguageFlags.cmake)
+
# We order libraries to mirror roughly how they are layered, except that compiler-rt can depend
# on libc++, so we put it after.
set(LLVM_DEFAULT_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;libclc;openmp;offload")
diff --git a/runtimes/cmake/Modules/HandleFlags.cmake b/runtimes/cmake/Modules/HandleFlags.cmake
index 1c744a0aa0ae7..148260013a9cd 100644
--- a/runtimes/cmake/Modules/HandleFlags.cmake
+++ b/runtimes/cmake/Modules/HandleFlags.cmake
@@ -1,3 +1,9 @@
+#
+# This file defines legacy functions to detect and set compiler flags
+# used throughout the runtimes. Please move away from using these
+# functions in favour of using interface targets (see for example
+# LanguageFlags.cmake).
+#
include(CheckCXXCompilerFlag)
diff --git a/runtimes/cmake/Modules/LanguageFlags.cmake b/runtimes/cmake/Modules/LanguageFlags.cmake
new file mode 100644
index 0000000000000..62060c4063d87
--- /dev/null
+++ b/runtimes/cmake/Modules/LanguageFlags.cmake
@@ -0,0 +1,46 @@
+#
+# Configure CMake flags related to C++ language.
+#
+# This file defines an interface target named `runtimes-language-flags` which
+# can be linked against to get the language-related flags configured here.
+#
+
+add_library(runtimes-language-flags INTERFACE)
+
+# Exceptions
+option(RUNTIMES_ENABLE_EXCEPTIONS
+ "Whether to enable exceptions (-fexceptions) when building the runtimes.
+ This also controls whether the runtimes provide support for exceptions,
+ for example stack unwinding and other exceptions-related features."
+ ON)
+if (RUNTIMES_ENABLE_EXCEPTIONS)
+ if (MSVC)
+ # Catches C++ exceptions only and tells the compiler to assume that extern C
+ # functions never throw a C++ exception.
+ target_compile_options(runtimes-language-flags INTERFACE "-EHsc")
+ endif()
+else()
+ if (MSVC)
+ target_compile_options(runtimes-language-flags INTERFACE "-EHs-" "-EHa-")
+ else()
+ target_compile_options(runtimes-language-flags INTERFACE "-fno-exceptions")
+ endif()
+endif()
+
+# RTTI
+option(RUNTIMES_ENABLE_RTTI
+ "Whether to enable runtime type information (-frtti) when building the runtimes.
+ Note that building the runtimes with support for exceptions requires RTTI to
+ be enabled."
+ ON)
+if (NOT RUNTIMES_ENABLE_RTTI AND RUNTIMES_ENABLE_EXCEPTIONS)
+ message(FATAL_ERROR "The runtimes cannot be built with exceptions enabled but RTTI disabled, since "
+ "that configuration is broken. See https://llvm.org/PR66117 for details.")
+endif()
+if (NOT RUNTIMES_ENABLE_RTTI)
+ if (MSVC)
+ target_compile_options(runtimes-language-flags INTERFACE -GR-)
+ else()
+ target_compile_options(runtimes-language-flags INTERFACE "-fno-rtti")
+ endif()
+endif()
More information about the libcxx-commits
mailing list