Skip to content

Commit 987ed32

Browse files
committed
[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?
1 parent 535197f commit 987ed32

20 files changed

+86
-111
lines changed

libcxx/CMakeLists.txt

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ include(HandleCompilerRT)
4747
# Basic options ---------------------------------------------------------------
4848
option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
4949
option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON)
50-
option(LIBCXX_ENABLE_EXCEPTIONS "Enable exceptions in the built library." ON)
51-
option(LIBCXX_ENABLE_RTTI
52-
"Use runtime type information.
53-
This option may only be set to OFF when LIBCXX_ENABLE_EXCEPTIONS=OFF." ON)
5450
option(LIBCXX_ENABLE_FILESYSTEM
5551
"Whether to include support for parts of the library that rely on a filesystem being
5652
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"
164160
OR NOT LIBCXX_ENABLE_THREADS
165161
OR NOT LIBCXX_ENABLE_FILESYSTEM
166162
OR NOT LIBCXX_ENABLE_RANDOM_DEVICE
167-
OR NOT LIBCXX_ENABLE_EXCEPTIONS
168-
OR NOT LIBCXX_ENABLE_RTTI)
163+
OR NOT RUNTIMES_ENABLE_EXCEPTIONS
164+
OR NOT RUNTIMES_ENABLE_RTTI)
169165
set(_include_benchmarks OFF)
170166
else()
171167
set(_include_benchmarks ON)
@@ -358,12 +354,6 @@ if (LIBCXX_HAS_PTHREAD_API)
358354
endif()
359355
endif()
360356

361-
if (NOT LIBCXX_ENABLE_RTTI AND LIBCXX_ENABLE_EXCEPTIONS)
362-
message(FATAL_ERROR "Libc++ cannot be built with exceptions enabled but RTTI"
363-
" disabled, since that configuration is broken. See"
364-
" https://llvm.org/PR66117 for details.")
365-
endif()
366-
367357
if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
368358
if (APPLE)
369359
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)
540530
target_compile_options(${target} PUBLIC "${LIBCXX_ADDITIONAL_COMPILE_FLAGS}")
541531
endfunction()
542532

543-
# Exception flags =============================================================
544-
function(cxx_add_exception_flags target)
545-
if (LIBCXX_ENABLE_EXCEPTIONS)
546-
# Catches C++ exceptions only and tells the compiler to assume that extern C
547-
# functions never throw a C++ exception.
548-
target_add_compile_flags_if_supported(${target} PUBLIC -EHsc)
549-
else()
550-
target_add_compile_flags_if_supported(${target} PUBLIC -EHs- -EHa-)
551-
target_add_compile_flags_if_supported(${target} PUBLIC -fno-exceptions)
552-
endif()
553-
endfunction()
554-
555-
# RTTI flags ==================================================================
556-
function(cxx_add_rtti_flags target)
557-
if (NOT LIBCXX_ENABLE_RTTI)
558-
if (MSVC)
559-
target_add_compile_flags_if_supported(${target} PUBLIC -GR-)
560-
else()
561-
target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti)
562-
endif()
563-
endif()
564-
endfunction()
565-
566533
# Modules flags ===============================================================
567534
# FIXME The libc++ sources are fundamentally non-modular. They need special
568535
# 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)
817784
cxx_add_basic_build_flags(${target})
818785
cxx_add_warning_flags(${target} ${LIBCXX_ENABLE_WERROR} ${LIBCXX_ENABLE_PEDANTIC})
819786
cxx_add_windows_flags(${target})
820-
cxx_add_exception_flags(${target})
821-
cxx_add_rtti_flags(${target})
822787
cxx_add_module_flags(${target})
823788
cxx_link_system_libraries(${target})
824789
target_link_libraries(${target} PRIVATE cxx-sanitizer-flags)
790+
target_link_libraries(${target} PRIVATE runtimes-language-flags)
825791
endfunction()
826792

827793
#===============================================================================

libcxx/cmake/caches/AMDGPU.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
# Configuration options for all the runtimes
2+
set(RUNTIMES_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
3+
set(RUNTIMES_ENABLE_RTTI OFF CACHE BOOL "")
4+
15
# Configuration options for libcxx.
26
set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
3-
set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
47
set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
58
set(LIBCXX_ENABLE_LOCALIZATION ON CACHE BOOL "")
69
set(LIBCXX_ENABLE_MONOTONIC_CLOCK ON CACHE BOOL "")
710
set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
811
set(LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
9-
set(LIBCXX_ENABLE_RTTI OFF CACHE BOOL "")
1012
set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
1113
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
1214
set(LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
@@ -21,7 +23,6 @@ set(RUNTIMES_USE_LIBC "llvm-libc" CACHE STRING "")
2123

2224
# Configuration options for libcxxabi.
2325
set(LIBCXXABI_BAREMETAL ON CACHE BOOL "")
24-
set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
2526
set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
2627
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
2728
set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")

libcxx/cmake/caches/Armv7M-picolibc.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ set(CMAKE_C_FLAGS "-mfloat-abi=soft" CACHE STRING "")
66
set(CMAKE_SYSTEM_NAME Generic CACHE STRING "")
77
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE STRING "")
88
set(LLVM_USE_LINKER "lld" CACHE STRING "")
9+
set(RUNTIMES_ENABLE_EXCEPTIONS ON CACHE BOOL "")
10+
set(RUNTIMES_ENABLE_RTTI ON CACHE BOOL "")
911
set(COMPILER_RT_BAREMETAL_BUILD ON CACHE BOOL "")
1012
set(COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "")
1113
set(COMPILER_RT_BUILD_PROFILE OFF CACHE BOOL "")
@@ -14,17 +16,14 @@ set(COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
1416
set(COMPILER_RT_DEFAULT_TARGET_ONLY ON CACHE BOOL "")
1517
set(LIBCXXABI_BAREMETAL ON CACHE BOOL "")
1618
set(LIBCXXABI_ENABLE_ASSERTIONS OFF CACHE BOOL "")
17-
set(LIBCXXABI_ENABLE_EXCEPTIONS ON CACHE BOOL "")
1819
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
1920
set(LIBCXXABI_ENABLE_STATIC ON CACHE BOOL "")
2021
set(LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
2122
set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
2223
set(LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
23-
set(LIBCXX_ENABLE_EXCEPTIONS ON CACHE BOOL "")
2424
set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE STRING "")
2525
set(LIBCXX_ENABLE_MONOTONIC_CLOCK OFF CACHE BOOL "")
2626
set(LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
27-
set(LIBCXX_ENABLE_RTTI ON CACHE BOOL "")
2827
set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
2928
set(LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
3029
set(LIBCXX_ENABLE_THREADS OFF CACHE BOOL "")
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
set(CMAKE_CXX_COMPILER_TARGET "armv7l-linux-gnueabihf" CACHE STRING "")
22
set(CMAKE_CXX_FLAGS "-mthumb" CACHE STRING "")
33
set(CMAKE_C_FLAGS "-mthumb" CACHE STRING "")
4-
set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
5-
set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
4+
set(RUNTIMES_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
65
set(LIBCXX_TEST_PARAMS "enable_modules=clang" CACHE STRING "")
76
set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
set(CMAKE_CXX_COMPILER_TARGET "armv8l-linux-gnueabihf" CACHE STRING "")
22
set(CMAKE_CXX_FLAGS "-mthumb" CACHE STRING "")
33
set(CMAKE_C_FLAGS "-mthumb" CACHE STRING "")
4-
set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
5-
set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
4+
set(RUNTIMES_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
65
set(LIBCXX_TEST_PARAMS "enable_modules=clang" CACHE STRING "")
76
set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")

libcxx/cmake/caches/Generic-no-exceptions.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
2-
set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
1+
set(RUNTIMES_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
32

43
# Speed up the CI
54
set(LIBCXX_TEST_PARAMS "enable_modules=clang" CACHE STRING "")

libcxx/cmake/caches/Generic-no-rtti.cmake

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
set(LIBCXX_ENABLE_RTTI OFF CACHE BOOL "")
2-
set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
3-
set(LIBCXXABI_ENABLE_RTTI OFF CACHE BOOL "")
4-
set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
1+
set(RUNTIMES_ENABLE_RTTI OFF CACHE BOOL "")
2+
set(RUNTIMES_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
53

64
# Speed up the CI
75
set(LIBCXX_TEST_PARAMS "enable_modules=clang" CACHE STRING "")

libcxx/cmake/caches/NVPTX.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
# Configuration options for the runtimes.
2+
set(RUNTIMES_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
3+
set(RUNTIMES_ENABLE_RTTI OFF CACHE BOOL "")
4+
15
# Configuration options for libcxx.
26
set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
3-
set(LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
47
set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
58
set(LIBCXX_ENABLE_LOCALIZATION ON CACHE BOOL "")
69
set(LIBCXX_ENABLE_MONOTONIC_CLOCK ON CACHE BOOL "")
710
set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
811
set(LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
9-
set(LIBCXX_ENABLE_RTTI OFF CACHE BOOL "")
1012
set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
1113
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
1214
set(LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
@@ -21,7 +23,6 @@ set(RUNTIMES_USE_LIBC "llvm-libc" CACHE STRING "")
2123

2224
# Configuration options for libcxxabi.
2325
set(LIBCXXABI_BAREMETAL ON CACHE BOOL "")
24-
set(LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
2526
set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
2627
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
2728
set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")

libcxx/docs/Modules.rst

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,10 @@ What works
4848
* ``LIBCXX_ENABLE_FILESYSTEM``
4949
* ``LIBCXX_ENABLE_RANDOM_DEVICE``
5050
* ``LIBCXX_ENABLE_UNICODE``
51-
* ``LIBCXX_ENABLE_EXCEPTIONS`` [#note-no-windows]_
51+
* ``RUNTIMES_ENABLE_EXCEPTIONS``
5252

5353
* A C++20 based extension
5454

55-
.. note::
56-
57-
.. [#note-no-windows] This configuration will probably not work on Windows
58-
due to hard-coded compilation flags.
59-
6055
Some of the current limitations
6156
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6257

libcxx/docs/VendorDocumentation.rst

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,7 @@ General purpose options
227227

228228
Additional libraries libc++ is linked to which can be provided in cache.
229229

230-
.. option:: LIBCXX_ENABLE_EXCEPTIONS:BOOL
231-
232-
**Default**: ``ON``
233-
234-
Build libc++ with exception support.
235-
236-
.. option:: LIBCXX_ENABLE_RTTI:BOOL
237-
238-
**Default**: ``ON``
239-
240-
Build libc++ with run time type information.
241-
This option may only be set to OFF when LIBCXX_ENABLE_EXCEPTIONS=OFF.
230+
.. TODO: Where should we document the runtimes build options?
242231
243232
.. option:: LIBCXX_INCLUDE_TESTS:BOOL
244233

0 commit comments

Comments
 (0)