Skip to content

Commit 8f90e69

Browse files
authored
[runtimes] Use LLVM libunwind from libc++abi by default (#77687)
I recently came across LIBCXXABI_USE_LLVM_UNWINDER and was surprised to notice it was disabled by default. Since we build libunwind by default and ship it in the LLVM toolchain, it would seem to make sense that libc++ and libc++abi rely on libunwind for unwinding instead of using the system-provided unwinding library (if any). Most importantly, using the system unwinder implies that libc++abi is ABI compatible with that system unwinder, which is not necessarily the case. Hence, it makes a lot more sense to instead default to using the known-to-be-compatible LLVM unwinder, and let vendors manually select a different unwinder if desired. As a follow-up change, we should probably apply the same default to compiler-rt. Differential Revision: https://reviews.llvm.org/D150897 Fixes #77662 rdar://120801778
1 parent 3b3ee1f commit 8f90e69

19 files changed

+16
-18
lines changed

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ jobs:
163163
'generic-no-rtti',
164164
'generic-optimized-speed',
165165
'generic-static',
166-
'generic-with_llvm_unwinder',
167166
# TODO Find a better place for the benchmark and bootstrapping builds to live. They're either very expensive
168167
# or don't provide much value since the benchmark run results are too noise on the bots.
169168
'benchmarks',

libcxx/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
274274
libc++abi. Doing otherwise is an ODR violation." OFF)
275275
# Build libc++abi with libunwind. We need this option to determine whether to
276276
# link with libunwind or libgcc_s while running the test cases.
277-
option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
277+
option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." ON)
278278

279279
# Target options --------------------------------------------------------------
280280
option(LIBCXX_BUILD_32_BITS "Build 32 bit multilib libc++. This option is not supported anymore when building the runtimes. Please specify a full triple instead." ${LLVM_BUILD_32_BITS})

libcxx/cmake/caches/AArch64.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
21
set(CMAKE_CXX_COMPILER_TARGET "aarch64-linux-gnu" CACHE STRING "")

libcxx/cmake/caches/AIX.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ set(LIBCXX_ENABLE_STATIC OFF CACHE BOOL "")
1313
set(LIBCXXABI_ENABLE_SHARED ON CACHE BOOL "")
1414
set(LIBCXXABI_ENABLE_STATIC OFF CACHE BOOL "")
1515
set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
16-
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
1716
set(LIBUNWIND_ENABLE_SHARED ON CACHE BOOL "")
1817
set(LIBUNWIND_ENABLE_STATIC OFF CACHE BOOL "")

libcxx/cmake/caches/AndroidNDK.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
2222
set(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY ON CACHE BOOL "")
2323
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
2424

25+
# Android uses its own unwinder library
26+
set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "")
27+
2528
# Clang links libc++ by default, but it doesn't exist yet. The libc++ CMake
2629
# files specify -nostdlib++ to avoid this problem, but CMake's default "compiler
2730
# works" testing doesn't pass that flag, so force those tests to pass.

libcxx/cmake/caches/Apple.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set(LIBCXXABI_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")
1414

1515
set(LIBCXXABI_ENABLE_ASSERTIONS OFF CACHE BOOL "")
1616
set(LIBCXXABI_ENABLE_FORGIVING_DYNAMIC_CAST ON CACHE BOOL "")
17+
set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "") # libunwind is built separately
1718

1819
set(LIBCXX_TEST_CONFIG "apple-libc++-shared.cfg.in" CACHE STRING "")
1920
set(LIBCXXABI_TEST_CONFIG "apple-libc++abi-shared.cfg.in" CACHE STRING "")

libcxx/cmake/caches/Armv7Arm.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
21
set(CMAKE_CXX_COMPILER_TARGET "armv7l-linux-gnueabihf" CACHE STRING "")
32
set(CMAKE_CXX_FLAGS "-marm" CACHE STRING "")
43
set(CMAKE_C_FLAGS "-marm" CACHE STRING "")

libcxx/cmake/caches/Armv7M-picolibc.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ set(LIBCXXABI_ENABLE_STATIC ON CACHE BOOL "")
1919
set(LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
2020
set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
2121
set(LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
22-
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
2322
set(LIBCXX_ENABLE_EXCEPTIONS ON CACHE BOOL "")
2423
set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE STRING "")
2524
set(LIBCXX_ENABLE_MONOTONIC_CLOCK OFF CACHE BOOL "")

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
21
set(CMAKE_CXX_COMPILER_TARGET "armv7l-linux-gnueabihf" CACHE STRING "")
32
set(CMAKE_CXX_FLAGS "-mthumb" CACHE STRING "")
43
set(CMAKE_C_FLAGS "-mthumb" CACHE STRING "")

libcxx/cmake/caches/Armv8Arm.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
21
set(CMAKE_CXX_COMPILER_TARGET "armv8l-linux-gnueabihf" CACHE STRING "")
32
set(CMAKE_CXX_FLAGS "-marm" CACHE STRING "")
43
set(CMAKE_C_FLAGS "-marm" CACHE STRING "")

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
21
set(CMAKE_CXX_COMPILER_TARGET "armv8l-linux-gnueabihf" CACHE STRING "")
32
set(CMAKE_CXX_FLAGS "-mthumb" CACHE STRING "")
43
set(CMAKE_C_FLAGS "-mthumb" CACHE STRING "")

libcxx/cmake/caches/Generic-merged.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
55
set(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY ON CACHE BOOL "")
66

77
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
8-
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
98
set(LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
109
set(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY ON CACHE BOOL "")
1110

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
set(LLVM_USE_SANITIZER "MemoryWithOrigins" CACHE STRING "")
2+
set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "") # MSAN is compiled against the system unwinder, which leads to false positives
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
set(LLVM_USE_SANITIZER "Thread" CACHE STRING "")
2+
set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "") # TSAN is compiled against the system unwinder, which leads to false positives

libcxx/cmake/caches/MinGW.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
2-
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
32

43
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
54
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")

libcxx/docs/BuildingLibcxx.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ ABI Library Specific Options
337337

338338
.. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL
339339

340-
**Default**: ``OFF``
340+
**Default**: ``ON``
341341

342342
Build and use the LLVM unwinder. Note: This option can only be used when
343343
libc++abi is the C++ ABI library used.

libcxx/docs/ReleaseNotes/18.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,10 @@ Build System Changes
191191
passing ``-Dexecutor=...`` to ``llvm-lit``. Alternatively, this flag can be made persistent in the generated test
192192
configuration file by passing ``-DLIBCXX_TEST_PARAMS=executor=...``. This also applies to the ``LIBUWIND_EXECTOR``
193193
and ``LIBCXXABI_EXECUTOR`` CMake variables. LLVM 19 will completely remove support for the ``*_EXECUTOR`` variables.
194+
195+
- ``LIBCXXABI_USE_LLVM_UNWINDER`` and ``COMPILER_RT_USE_LLVM_UNWINDER`` switched defaults from ``OFF`` to ``ON``.
196+
This means that by default, libc++abi and compiler-rt will link against the LLVM provided ``libunwind`` library
197+
instead of the system-provided unwinding library. If you are building the LLVM runtimes with the goal of shipping
198+
them so that they can interoperate with other system-provided libraries that might be using a different unwinding
199+
library (such as ``libgcc_s``), you should pass ``LIBCXXABI_USE_LLVM_UNWINDER=OFF`` and ``COMPILER_RT_USE_LLVM_UNWINDER=OFF``
200+
to make sure the system-provided unwinding library is used by the LLVM runtimes.

libcxx/utils/ci/run-buildbot

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,6 @@ generic-hardening-mode-debug)
439439
check-runtimes
440440
check-abi-list
441441
;;
442-
generic-with_llvm_unwinder)
443-
clean
444-
generate-cmake -DLIBCXXABI_USE_LLVM_UNWINDER=ON
445-
check-runtimes
446-
;;
447442
#
448443
# Module builds
449444
#

libcxxabi/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ option(LIBCXXABI_ENABLE_EXCEPTIONS
4646
option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
4747
option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
4848
option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
49-
option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
49+
option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." ON)
5050
option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF)
5151
option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
5252
option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON)

0 commit comments

Comments
 (0)