Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[runtimes] Use LLVM libunwind from libc++abi by default #77687

Merged
merged 4 commits into from
Jan 11, 2024

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Jan 10, 2024

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

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.

Differential Revision: https://reviews.llvm.org/D150897
Fixes llvm#77662
rdar://120801778
@ldionne ldionne requested review from a team as code owners January 10, 2024 21:08
@llvmbot llvmbot added compiler-rt libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. libc++abi libc++abi C++ Runtime Library. Not libc++. github:workflow labels Jan 10, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 10, 2024

@llvm/pr-subscribers-libcxxabi

@llvm/pr-subscribers-github-workflow

Author: Louis Dionne (ldionne)

Changes

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.

Differential Revision: https://reviews.llvm.org/D150897
Fixes #77662
rdar://120801778


Full diff: https://github.com/llvm/llvm-project/pull/77687.diff

19 Files Affected:

  • (modified) .github/workflows/libcxx-build-and-test.yaml (-1)
  • (modified) compiler-rt/CMakeLists.txt (+1-1)
  • (modified) libcxx/CMakeLists.txt (+1-1)
  • (modified) libcxx/cmake/caches/AArch64.cmake (-1)
  • (modified) libcxx/cmake/caches/AIX.cmake (-1)
  • (modified) libcxx/cmake/caches/Apple.cmake (+1)
  • (modified) libcxx/cmake/caches/Armv7Arm.cmake (-1)
  • (modified) libcxx/cmake/caches/Armv7M-picolibc.cmake (-1)
  • (modified) libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake (-1)
  • (modified) libcxx/cmake/caches/Armv8Arm.cmake (-1)
  • (modified) libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake (-1)
  • (modified) libcxx/cmake/caches/Generic-merged.cmake (-1)
  • (modified) libcxx/cmake/caches/Generic-msan.cmake (+1)
  • (modified) libcxx/cmake/caches/Generic-tsan.cmake (+1)
  • (modified) libcxx/cmake/caches/MinGW.cmake (-1)
  • (modified) libcxx/docs/BuildingLibcxx.rst (+1-1)
  • (modified) libcxx/docs/ReleaseNotes/18.rst (+7)
  • (modified) libcxx/utils/ci/run-buildbot (-5)
  • (modified) libcxxabi/CMakeLists.txt (+1-1)
diff --git a/.github/workflows/libcxx-build-and-test.yaml b/.github/workflows/libcxx-build-and-test.yaml
index 985790a0ee2361..1666a687aa5d04 100644
--- a/.github/workflows/libcxx-build-and-test.yaml
+++ b/.github/workflows/libcxx-build-and-test.yaml
@@ -163,7 +163,6 @@ jobs:
           'generic-no-rtti',
           'generic-optimized-speed',
           'generic-static',
-          'generic-with_llvm_unwinder',
           # TODO Find a better place for the benchmark and bootstrapping builds to live. They're either very expensive
           # or don't provide much value since the benchmark run results are too noise on the bots.
           'benchmarks',
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index bbb4e8d7c333e4..ff6e4347b80b39 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -229,7 +229,7 @@ set(CXXLIBS none default libstdc++ libc++)
 set_property(CACHE SANITIZER_TEST_CXX PROPERTY STRINGS ;${CXXLIBS})
 handle_default_cxx_lib(SANITIZER_TEST_CXX)
 
-option(COMPILER_RT_USE_LLVM_UNWINDER "Use the LLVM unwinder." OFF)
+option(COMPILER_RT_USE_LLVM_UNWINDER "Use the LLVM unwinder." ON)
 cmake_dependent_option(COMPILER_RT_ENABLE_STATIC_UNWINDER
   "Statically link the LLVM unwinder." OFF
   "COMPILER_RT_USE_LLVM_UNWINDER" OFF)
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 75cb63222da35c..cf197d8c224143 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -274,7 +274,7 @@ option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
    libc++abi. Doing otherwise is an ODR violation." OFF)
 # Build libc++abi with libunwind. We need this option to determine whether to
 # link with libunwind or libgcc_s while running the test cases.
-option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
+option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." ON)
 
 # Target options --------------------------------------------------------------
 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})
diff --git a/libcxx/cmake/caches/AArch64.cmake b/libcxx/cmake/caches/AArch64.cmake
index fa802d3de63f04..d813273584b0f0 100644
--- a/libcxx/cmake/caches/AArch64.cmake
+++ b/libcxx/cmake/caches/AArch64.cmake
@@ -1,2 +1 @@
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 set(CMAKE_CXX_COMPILER_TARGET "aarch64-linux-gnu" CACHE STRING "")
diff --git a/libcxx/cmake/caches/AIX.cmake b/libcxx/cmake/caches/AIX.cmake
index 31d9a2d4b72751..c01aa5b14df065 100644
--- a/libcxx/cmake/caches/AIX.cmake
+++ b/libcxx/cmake/caches/AIX.cmake
@@ -13,6 +13,5 @@ set(LIBCXX_ENABLE_STATIC OFF CACHE BOOL "")
 set(LIBCXXABI_ENABLE_SHARED ON CACHE BOOL "")
 set(LIBCXXABI_ENABLE_STATIC OFF CACHE BOOL "")
 set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 set(LIBUNWIND_ENABLE_SHARED ON CACHE BOOL "")
 set(LIBUNWIND_ENABLE_STATIC OFF CACHE BOOL "")
diff --git a/libcxx/cmake/caches/Apple.cmake b/libcxx/cmake/caches/Apple.cmake
index 804eccd3a5dc5e..cec13c08acf107 100644
--- a/libcxx/cmake/caches/Apple.cmake
+++ b/libcxx/cmake/caches/Apple.cmake
@@ -14,6 +14,7 @@ set(LIBCXXABI_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")
 
 set(LIBCXXABI_ENABLE_ASSERTIONS OFF CACHE BOOL "")
 set(LIBCXXABI_ENABLE_FORGIVING_DYNAMIC_CAST ON CACHE BOOL "")
+set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "") # libunwind is built separately
 
 set(LIBCXX_TEST_CONFIG "apple-libc++-shared.cfg.in" CACHE STRING "")
 set(LIBCXXABI_TEST_CONFIG "apple-libc++abi-shared.cfg.in" CACHE STRING "")
diff --git a/libcxx/cmake/caches/Armv7Arm.cmake b/libcxx/cmake/caches/Armv7Arm.cmake
index 4d18d08fefcd22..e60d43f33dde7f 100644
--- a/libcxx/cmake/caches/Armv7Arm.cmake
+++ b/libcxx/cmake/caches/Armv7Arm.cmake
@@ -1,4 +1,3 @@
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 set(CMAKE_CXX_COMPILER_TARGET "armv7l-linux-gnueabihf" CACHE STRING "")
 set(CMAKE_CXX_FLAGS "-marm" CACHE STRING "")
 set(CMAKE_C_FLAGS "-marm" CACHE STRING "")
diff --git a/libcxx/cmake/caches/Armv7M-picolibc.cmake b/libcxx/cmake/caches/Armv7M-picolibc.cmake
index 3ab80b960ed44a..b5f9089308d22e 100644
--- a/libcxx/cmake/caches/Armv7M-picolibc.cmake
+++ b/libcxx/cmake/caches/Armv7M-picolibc.cmake
@@ -19,7 +19,6 @@ 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(LIBCXXABI_USE_LLVM_UNWINDER 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 "")
diff --git a/libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake b/libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake
index 71173af106b637..70b619f8ec31f3 100644
--- a/libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake
+++ b/libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake
@@ -1,4 +1,3 @@
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 set(CMAKE_CXX_COMPILER_TARGET "armv7l-linux-gnueabihf" CACHE STRING "")
 set(CMAKE_CXX_FLAGS "-mthumb" CACHE STRING "")
 set(CMAKE_C_FLAGS "-mthumb" CACHE STRING "")
diff --git a/libcxx/cmake/caches/Armv8Arm.cmake b/libcxx/cmake/caches/Armv8Arm.cmake
index 5055582fdafc0d..a2894716035304 100644
--- a/libcxx/cmake/caches/Armv8Arm.cmake
+++ b/libcxx/cmake/caches/Armv8Arm.cmake
@@ -1,4 +1,3 @@
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 set(CMAKE_CXX_COMPILER_TARGET "armv8l-linux-gnueabihf" CACHE STRING "")
 set(CMAKE_CXX_FLAGS "-marm" CACHE STRING "")
 set(CMAKE_C_FLAGS "-marm" CACHE STRING "")
diff --git a/libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake b/libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake
index 316edd31490665..b4c7dfca279cd3 100644
--- a/libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake
+++ b/libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake
@@ -1,4 +1,3 @@
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 set(CMAKE_CXX_COMPILER_TARGET "armv8l-linux-gnueabihf" CACHE STRING "")
 set(CMAKE_CXX_FLAGS "-mthumb" CACHE STRING "")
 set(CMAKE_C_FLAGS "-mthumb" CACHE STRING "")
diff --git a/libcxx/cmake/caches/Generic-merged.cmake b/libcxx/cmake/caches/Generic-merged.cmake
index b2e02f73105557..7ebb8026236ddf 100644
--- a/libcxx/cmake/caches/Generic-merged.cmake
+++ b/libcxx/cmake/caches/Generic-merged.cmake
@@ -5,7 +5,6 @@ set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
 set(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY ON CACHE BOOL "")
 
 set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 set(LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
 set(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY ON CACHE BOOL "")
 
diff --git a/libcxx/cmake/caches/Generic-msan.cmake b/libcxx/cmake/caches/Generic-msan.cmake
index 7c948f51642dd4..9e50255fe4ff6b 100644
--- a/libcxx/cmake/caches/Generic-msan.cmake
+++ b/libcxx/cmake/caches/Generic-msan.cmake
@@ -1 +1,2 @@
 set(LLVM_USE_SANITIZER "MemoryWithOrigins" CACHE STRING "")
+set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "") # MSAN is compiled against the system unwinder, which leads to false positives
diff --git a/libcxx/cmake/caches/Generic-tsan.cmake b/libcxx/cmake/caches/Generic-tsan.cmake
index a4b599e3e5094b..c42c1bb8e72221 100644
--- a/libcxx/cmake/caches/Generic-tsan.cmake
+++ b/libcxx/cmake/caches/Generic-tsan.cmake
@@ -1 +1,2 @@
 set(LLVM_USE_SANITIZER "Thread" CACHE STRING "")
+set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "") # TSAN is compiled against the system unwinder, which leads to false positives
diff --git a/libcxx/cmake/caches/MinGW.cmake b/libcxx/cmake/caches/MinGW.cmake
index a5927096d8ff96..09e6ea5c1bab20 100644
--- a/libcxx/cmake/caches/MinGW.cmake
+++ b/libcxx/cmake/caches/MinGW.cmake
@@ -1,5 +1,4 @@
 set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 
 set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
 set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
diff --git a/libcxx/docs/BuildingLibcxx.rst b/libcxx/docs/BuildingLibcxx.rst
index 0b4d4205286512..f2304c9796b540 100644
--- a/libcxx/docs/BuildingLibcxx.rst
+++ b/libcxx/docs/BuildingLibcxx.rst
@@ -337,7 +337,7 @@ ABI Library Specific Options
 
 .. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL
 
-  **Default**: ``OFF``
+  **Default**: ``ON``
 
   Build and use the LLVM unwinder. Note: This option can only be used when
   libc++abi is the C++ ABI library used.
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index 5df6242e52317a..478e87f8888332 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -191,3 +191,10 @@ Build System Changes
   passing ``-Dexecutor=...`` to ``llvm-lit``. Alternatively, this flag can be made persistent in the generated test
   configuration file by passing ``-DLIBCXX_TEST_PARAMS=executor=...``. This also applies to the ``LIBUWIND_EXECTOR``
   and ``LIBCXXABI_EXECUTOR`` CMake variables. LLVM 19 will completely remove support for the ``*_EXECUTOR`` variables.
+
+- ``LIBCXXABI_USE_LLVM_UNWINDER`` and ``COMPILER_RT_USE_LLVM_UNWINDER`` switched defaults from ``OFF`` to ``ON``.
+  This means that by default, libc++abi and compiler-rt will link against the LLVM provided ``libunwind`` library
+  instead of the system-provided unwinding library. If you are building the LLVM runtimes with the goal of shipping
+  them so that they can interoperate with other system-provided libraries that might be using a different unwinding
+  library (such as ``libgcc_s``), you should pass ``LIBCXXABI_USE_LLVM_UNWINDER=OFF`` and ``COMPILER_RT_USE_LLVM_UNWINDER=OFF``
+  to make sure the system-provided unwinding library is used by the LLVM runtimes.
diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index ed2bc2a14f17d6..0ff028743bc1a3 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -439,11 +439,6 @@ generic-hardening-mode-debug)
     check-runtimes
     check-abi-list
 ;;
-generic-with_llvm_unwinder)
-    clean
-    generate-cmake -DLIBCXXABI_USE_LLVM_UNWINDER=ON
-    check-runtimes
-;;
 #
 # Module builds
 #
diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index efe830bd2ad665..c62b05bf2feafc 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -46,7 +46,7 @@ option(LIBCXXABI_ENABLE_EXCEPTIONS
 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)
-option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
+option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." ON)
 option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF)
 option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
 option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON)

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 10, 2024

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

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.

Differential Revision: https://reviews.llvm.org/D150897
Fixes #77662
rdar://120801778


Full diff: https://github.com/llvm/llvm-project/pull/77687.diff

19 Files Affected:

  • (modified) .github/workflows/libcxx-build-and-test.yaml (-1)
  • (modified) compiler-rt/CMakeLists.txt (+1-1)
  • (modified) libcxx/CMakeLists.txt (+1-1)
  • (modified) libcxx/cmake/caches/AArch64.cmake (-1)
  • (modified) libcxx/cmake/caches/AIX.cmake (-1)
  • (modified) libcxx/cmake/caches/Apple.cmake (+1)
  • (modified) libcxx/cmake/caches/Armv7Arm.cmake (-1)
  • (modified) libcxx/cmake/caches/Armv7M-picolibc.cmake (-1)
  • (modified) libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake (-1)
  • (modified) libcxx/cmake/caches/Armv8Arm.cmake (-1)
  • (modified) libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake (-1)
  • (modified) libcxx/cmake/caches/Generic-merged.cmake (-1)
  • (modified) libcxx/cmake/caches/Generic-msan.cmake (+1)
  • (modified) libcxx/cmake/caches/Generic-tsan.cmake (+1)
  • (modified) libcxx/cmake/caches/MinGW.cmake (-1)
  • (modified) libcxx/docs/BuildingLibcxx.rst (+1-1)
  • (modified) libcxx/docs/ReleaseNotes/18.rst (+7)
  • (modified) libcxx/utils/ci/run-buildbot (-5)
  • (modified) libcxxabi/CMakeLists.txt (+1-1)
diff --git a/.github/workflows/libcxx-build-and-test.yaml b/.github/workflows/libcxx-build-and-test.yaml
index 985790a0ee2361..1666a687aa5d04 100644
--- a/.github/workflows/libcxx-build-and-test.yaml
+++ b/.github/workflows/libcxx-build-and-test.yaml
@@ -163,7 +163,6 @@ jobs:
           'generic-no-rtti',
           'generic-optimized-speed',
           'generic-static',
-          'generic-with_llvm_unwinder',
           # TODO Find a better place for the benchmark and bootstrapping builds to live. They're either very expensive
           # or don't provide much value since the benchmark run results are too noise on the bots.
           'benchmarks',
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index bbb4e8d7c333e4..ff6e4347b80b39 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -229,7 +229,7 @@ set(CXXLIBS none default libstdc++ libc++)
 set_property(CACHE SANITIZER_TEST_CXX PROPERTY STRINGS ;${CXXLIBS})
 handle_default_cxx_lib(SANITIZER_TEST_CXX)
 
-option(COMPILER_RT_USE_LLVM_UNWINDER "Use the LLVM unwinder." OFF)
+option(COMPILER_RT_USE_LLVM_UNWINDER "Use the LLVM unwinder." ON)
 cmake_dependent_option(COMPILER_RT_ENABLE_STATIC_UNWINDER
   "Statically link the LLVM unwinder." OFF
   "COMPILER_RT_USE_LLVM_UNWINDER" OFF)
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 75cb63222da35c..cf197d8c224143 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -274,7 +274,7 @@ option(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
    libc++abi. Doing otherwise is an ODR violation." OFF)
 # Build libc++abi with libunwind. We need this option to determine whether to
 # link with libunwind or libgcc_s while running the test cases.
-option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
+option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." ON)
 
 # Target options --------------------------------------------------------------
 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})
diff --git a/libcxx/cmake/caches/AArch64.cmake b/libcxx/cmake/caches/AArch64.cmake
index fa802d3de63f04..d813273584b0f0 100644
--- a/libcxx/cmake/caches/AArch64.cmake
+++ b/libcxx/cmake/caches/AArch64.cmake
@@ -1,2 +1 @@
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 set(CMAKE_CXX_COMPILER_TARGET "aarch64-linux-gnu" CACHE STRING "")
diff --git a/libcxx/cmake/caches/AIX.cmake b/libcxx/cmake/caches/AIX.cmake
index 31d9a2d4b72751..c01aa5b14df065 100644
--- a/libcxx/cmake/caches/AIX.cmake
+++ b/libcxx/cmake/caches/AIX.cmake
@@ -13,6 +13,5 @@ set(LIBCXX_ENABLE_STATIC OFF CACHE BOOL "")
 set(LIBCXXABI_ENABLE_SHARED ON CACHE BOOL "")
 set(LIBCXXABI_ENABLE_STATIC OFF CACHE BOOL "")
 set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 set(LIBUNWIND_ENABLE_SHARED ON CACHE BOOL "")
 set(LIBUNWIND_ENABLE_STATIC OFF CACHE BOOL "")
diff --git a/libcxx/cmake/caches/Apple.cmake b/libcxx/cmake/caches/Apple.cmake
index 804eccd3a5dc5e..cec13c08acf107 100644
--- a/libcxx/cmake/caches/Apple.cmake
+++ b/libcxx/cmake/caches/Apple.cmake
@@ -14,6 +14,7 @@ set(LIBCXXABI_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")
 
 set(LIBCXXABI_ENABLE_ASSERTIONS OFF CACHE BOOL "")
 set(LIBCXXABI_ENABLE_FORGIVING_DYNAMIC_CAST ON CACHE BOOL "")
+set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "") # libunwind is built separately
 
 set(LIBCXX_TEST_CONFIG "apple-libc++-shared.cfg.in" CACHE STRING "")
 set(LIBCXXABI_TEST_CONFIG "apple-libc++abi-shared.cfg.in" CACHE STRING "")
diff --git a/libcxx/cmake/caches/Armv7Arm.cmake b/libcxx/cmake/caches/Armv7Arm.cmake
index 4d18d08fefcd22..e60d43f33dde7f 100644
--- a/libcxx/cmake/caches/Armv7Arm.cmake
+++ b/libcxx/cmake/caches/Armv7Arm.cmake
@@ -1,4 +1,3 @@
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 set(CMAKE_CXX_COMPILER_TARGET "armv7l-linux-gnueabihf" CACHE STRING "")
 set(CMAKE_CXX_FLAGS "-marm" CACHE STRING "")
 set(CMAKE_C_FLAGS "-marm" CACHE STRING "")
diff --git a/libcxx/cmake/caches/Armv7M-picolibc.cmake b/libcxx/cmake/caches/Armv7M-picolibc.cmake
index 3ab80b960ed44a..b5f9089308d22e 100644
--- a/libcxx/cmake/caches/Armv7M-picolibc.cmake
+++ b/libcxx/cmake/caches/Armv7M-picolibc.cmake
@@ -19,7 +19,6 @@ 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(LIBCXXABI_USE_LLVM_UNWINDER 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 "")
diff --git a/libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake b/libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake
index 71173af106b637..70b619f8ec31f3 100644
--- a/libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake
+++ b/libcxx/cmake/caches/Armv7Thumb-no-exceptions.cmake
@@ -1,4 +1,3 @@
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 set(CMAKE_CXX_COMPILER_TARGET "armv7l-linux-gnueabihf" CACHE STRING "")
 set(CMAKE_CXX_FLAGS "-mthumb" CACHE STRING "")
 set(CMAKE_C_FLAGS "-mthumb" CACHE STRING "")
diff --git a/libcxx/cmake/caches/Armv8Arm.cmake b/libcxx/cmake/caches/Armv8Arm.cmake
index 5055582fdafc0d..a2894716035304 100644
--- a/libcxx/cmake/caches/Armv8Arm.cmake
+++ b/libcxx/cmake/caches/Armv8Arm.cmake
@@ -1,4 +1,3 @@
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 set(CMAKE_CXX_COMPILER_TARGET "armv8l-linux-gnueabihf" CACHE STRING "")
 set(CMAKE_CXX_FLAGS "-marm" CACHE STRING "")
 set(CMAKE_C_FLAGS "-marm" CACHE STRING "")
diff --git a/libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake b/libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake
index 316edd31490665..b4c7dfca279cd3 100644
--- a/libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake
+++ b/libcxx/cmake/caches/Armv8Thumb-no-exceptions.cmake
@@ -1,4 +1,3 @@
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 set(CMAKE_CXX_COMPILER_TARGET "armv8l-linux-gnueabihf" CACHE STRING "")
 set(CMAKE_CXX_FLAGS "-mthumb" CACHE STRING "")
 set(CMAKE_C_FLAGS "-mthumb" CACHE STRING "")
diff --git a/libcxx/cmake/caches/Generic-merged.cmake b/libcxx/cmake/caches/Generic-merged.cmake
index b2e02f73105557..7ebb8026236ddf 100644
--- a/libcxx/cmake/caches/Generic-merged.cmake
+++ b/libcxx/cmake/caches/Generic-merged.cmake
@@ -5,7 +5,6 @@ set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
 set(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY ON CACHE BOOL "")
 
 set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 set(LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
 set(LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY ON CACHE BOOL "")
 
diff --git a/libcxx/cmake/caches/Generic-msan.cmake b/libcxx/cmake/caches/Generic-msan.cmake
index 7c948f51642dd4..9e50255fe4ff6b 100644
--- a/libcxx/cmake/caches/Generic-msan.cmake
+++ b/libcxx/cmake/caches/Generic-msan.cmake
@@ -1 +1,2 @@
 set(LLVM_USE_SANITIZER "MemoryWithOrigins" CACHE STRING "")
+set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "") # MSAN is compiled against the system unwinder, which leads to false positives
diff --git a/libcxx/cmake/caches/Generic-tsan.cmake b/libcxx/cmake/caches/Generic-tsan.cmake
index a4b599e3e5094b..c42c1bb8e72221 100644
--- a/libcxx/cmake/caches/Generic-tsan.cmake
+++ b/libcxx/cmake/caches/Generic-tsan.cmake
@@ -1 +1,2 @@
 set(LLVM_USE_SANITIZER "Thread" CACHE STRING "")
+set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "") # TSAN is compiled against the system unwinder, which leads to false positives
diff --git a/libcxx/cmake/caches/MinGW.cmake b/libcxx/cmake/caches/MinGW.cmake
index a5927096d8ff96..09e6ea5c1bab20 100644
--- a/libcxx/cmake/caches/MinGW.cmake
+++ b/libcxx/cmake/caches/MinGW.cmake
@@ -1,5 +1,4 @@
 set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
-set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
 
 set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
 set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
diff --git a/libcxx/docs/BuildingLibcxx.rst b/libcxx/docs/BuildingLibcxx.rst
index 0b4d4205286512..f2304c9796b540 100644
--- a/libcxx/docs/BuildingLibcxx.rst
+++ b/libcxx/docs/BuildingLibcxx.rst
@@ -337,7 +337,7 @@ ABI Library Specific Options
 
 .. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL
 
-  **Default**: ``OFF``
+  **Default**: ``ON``
 
   Build and use the LLVM unwinder. Note: This option can only be used when
   libc++abi is the C++ ABI library used.
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index 5df6242e52317a..478e87f8888332 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -191,3 +191,10 @@ Build System Changes
   passing ``-Dexecutor=...`` to ``llvm-lit``. Alternatively, this flag can be made persistent in the generated test
   configuration file by passing ``-DLIBCXX_TEST_PARAMS=executor=...``. This also applies to the ``LIBUWIND_EXECTOR``
   and ``LIBCXXABI_EXECUTOR`` CMake variables. LLVM 19 will completely remove support for the ``*_EXECUTOR`` variables.
+
+- ``LIBCXXABI_USE_LLVM_UNWINDER`` and ``COMPILER_RT_USE_LLVM_UNWINDER`` switched defaults from ``OFF`` to ``ON``.
+  This means that by default, libc++abi and compiler-rt will link against the LLVM provided ``libunwind`` library
+  instead of the system-provided unwinding library. If you are building the LLVM runtimes with the goal of shipping
+  them so that they can interoperate with other system-provided libraries that might be using a different unwinding
+  library (such as ``libgcc_s``), you should pass ``LIBCXXABI_USE_LLVM_UNWINDER=OFF`` and ``COMPILER_RT_USE_LLVM_UNWINDER=OFF``
+  to make sure the system-provided unwinding library is used by the LLVM runtimes.
diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index ed2bc2a14f17d6..0ff028743bc1a3 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -439,11 +439,6 @@ generic-hardening-mode-debug)
     check-runtimes
     check-abi-list
 ;;
-generic-with_llvm_unwinder)
-    clean
-    generate-cmake -DLIBCXXABI_USE_LLVM_UNWINDER=ON
-    check-runtimes
-;;
 #
 # Module builds
 #
diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index efe830bd2ad665..c62b05bf2feafc 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -46,7 +46,7 @@ option(LIBCXXABI_ENABLE_EXCEPTIONS
 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)
-option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
+option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." ON)
 option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF)
 option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
 option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON)

@ldionne ldionne changed the title [runtimes] Use LLVM libunwind from libc++abi and compiler-rt by default [runtimes] Use LLVM libunwind from libc++abi by default Jan 10, 2024
Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a simplified version of https://reviews.llvm.org/D150897 that does not remove redundant LIBCXXABI_USE_LLVM_UNWINDER ON. LGTM but I think some docs/ changes are needed.

edit: This change now includes all of https://reviews.llvm.org/D150897 . LGTM!

@ldionne ldionne merged commit 8f90e69 into llvm:main Jan 11, 2024
44 checks passed
@ldionne ldionne deleted the review/use-llvm-unwinder-by-default branch January 11, 2024 15:13
@ldionne
Copy link
Member Author

ldionne commented Jan 11, 2024

@vitalybuka This seems to have broken the ASAN and HWASAN builds here:
https://lab.llvm.org/buildbot/#/builders/236/builds/8629/steps/8/logs/stdio
https://lab.llvm.org/buildbot/#/builders/168/builds/17965/steps/8/logs/stdio

My understanding is that we'd now need to either explicitly say LIBCXXABI_USE_LLVM_UNWINDER=OFF or we'd need to change to -DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi;libunwind' here in buildbot_functions.sh.

Edit: See llvm/llvm-zorg#96

@vitalybuka
Copy link
Collaborator

@vitalybuka This seems to have broken the ASAN and HWASAN builds here: https://lab.llvm.org/buildbot/#/builders/236/builds/8629/steps/8/logs/stdio https://lab.llvm.org/buildbot/#/builders/168/builds/17965/steps/8/logs/stdio

My understanding is that we'd now need to either explicitly say LIBCXXABI_USE_LLVM_UNWINDER=OFF or we'd need to change to -DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi;libunwind' here in buildbot_functions.sh.

Edit: See llvm/llvm-zorg#96

Thanks for the patch, I will followup and recover buildbots

@@ -22,6 +22,9 @@ set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
set(LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY ON CACHE BOOL "")
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")

# Android uses its own unwinder library
set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. The Android runtime unwinder is also LLVM libunwind; is there any harm in building and using our own instead of the NDK's? CC @rprichard

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Android NDK currently sources all of libunwind, libc++abi, and libc++ from the same LLVM commit, so maybe it's better to build the unwinder library at the same time as libc++.

OTOH, Android's libc.so exports libunwind's EH API as of API 30 (Android 11), so eventually the NDK might be using an unwinder that's from a much older LLVM commit. It'll be a long time before the NDK targets API 30 as a minimum.

IIRC, when I last looked at the Linux libc++ CI tests (i.e. non-Android), the LLVM libunwind was built in the same runtimes CMake invocation as libc++, but the result wasn't actually used or tested. When I set up Android CI testing, I initially had it build libunwind as part of the CI testing, but I wanted the result to resemble what the NDK actually ships, which required a separate step for libunwind (and patching the result into a new resource dir) (see https://reviews.llvm.org/D139147?id=549856, search for "Build libunwind.a"). This patching was dropped in favor of using a libunwind.a from an Android Clang build.

@vitalybuka
Copy link
Collaborator

@ldionne @MaskRay
Any ideas what does this mean https://lab.llvm.org/buildbot/#/builders/85/builds/21530

@MaskRay
Copy link
Member

MaskRay commented Jan 11, 2024

@ldionne @MaskRay Any ideas what does this mean lab.llvm.org/buildbot/#/builders/85/builds/21530

This looks like a fatal runtime error for the test test/ExecutionEngine/MCJIT/Output/eh.ll related to OrcJIT. It seems unrelated to compiler-rt/lib/orc/elfnix_platform.cpp. I think it is perhaps related to existing OrcJIT instability, happened to be uncovered by this CMake change.

GTEST_OUTPUT=json:/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/unittests/Interpreter/ExceptionTests/./ClangReplInterpreterExceptionTests-Clang-Unit-2380782-0-1.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=1 GTEST_SHARD_INDEX=0 /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/unittests/Interpreter/ExceptionTests/./ClangReplInterpreterExceptionTests
--
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from InterpreterTest
[ RUN      ] InterpreterTest.CatchException
libunwind: __unw_add_dynamic_fde: bad fde: FDE is really a CIE
libc++abi: terminating due to uncaught exception of type custom_exception
 #0 0x000055c0558128ce llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13
 #1 0x000055c05580f716 llvm::sys::RunSignalHandlers() /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Signals.cpp:106:18
 #2 0x000055c05581333f SignalHandler(int) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #3 0x00007fac4963c460 (/lib/x86_64-linux-gnu/libc.so.6+0x3c460)
 #4 0x00007fac4969152b pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9152b)
 #5 0x00007fac4963c3b6 raise (/lib/x86_64-linux-gnu/libc.so.6+0x3c3b6)
 #6 0x00007fac4962287c abort (/lib/x86_64-linux-gnu/libc.so.6+0x2287c)
 #7 0x00007fac499d0edb abort_message /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/libcxxabi/src/abort_message.cpp:78:5
 #8 0x00007fac499a43c6 demangling_terminate_handler() /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/libcxxabi/src/cxa_default_handlers.cpp:77:9
 #9 0x00007fac499cf812 std::__terminate(void (*)()) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/libcxxabi/src/cxa_handlers.cpp:61:9
#10 0x00007fac499d9ba7 __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/libcxxabi/src/cxa_exception.cpp:152:5
#11 0x00007fac499d9761 cxa_exception_from_thrown_object /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/libcxxabi/src/cxa_exception.cpp:45:57
#12 0x00007fac499d9761 __cxa_throw /b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/libcxxabi/src/cxa_exception.cpp:264:41
#13 0x00007fac49cc40f9 

vitalybuka added a commit to llvm/llvm-zorg that referenced this pull request Jan 12, 2024
llvm/llvm-project#77687 enabled libunwind, but
not all tests pass with sanitizers.

So disable libunwind to investigate.
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Jan 12, 2024
Revert "[runtimes] Use LLVM libunwind from libc++abi by default (llvm#77687)"

Change-Id: I20ac6cae4f6d4469a0c0de4157a3faf5463d1752
@vitalybuka
Copy link
Collaborator

vitalybuka commented Jan 12, 2024

@petrhosek @ldionne
would it be better detect libunwind in LLVM_ENABLE_RUNTIMES?

Asking because we have similar thing in compiler-rt, e.g. for lld, and I am not sure which approach is better:
There are trade offs:

  1. checking LLVM_ENABLE_RUNTIMES simplify end user experience
  2. forcing default ON simplifies cmake files and avoids unexpected use of system lib

searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Jan 13, 2024
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 llvm#77662
rdar://120801778

Change-Id: Id2a0483ca5b032faec2d5c81753aea9a08695b4f
melpon added a commit to melpon/wandbox-builder that referenced this pull request Jan 13, 2024
@mgorny
Copy link
Member

mgorny commented Jan 13, 2024

FTR, this breaks standalone builds against installed LLVM's libunwind since unwind_shared target doesn't exist. However, as long as I can pass -DLIBCXXABI_USE_LLVM_UNWINDER=OFF that just does the right thing, it's fine with me.

@cor3ntin
Copy link
Contributor

FYI, This affects compiler explorer builds (trunk no longer builds)

cor3ntin added a commit to cor3ntin/clang-builder that referenced this pull request Jan 15, 2024
cor3ntin added a commit to cor3ntin/clang-builder that referenced this pull request Jan 15, 2024
libunwind is required to build libc++ as of
llvm/llvm-project#77687 (comment)

It was already used for numbered versions, but not trunk.

I also  updated my branch and left everything else alone as I did not know whether they use version of clang that can build libunwind
OfekShilon pushed a commit to compiler-explorer/clang-builder that referenced this pull request Jan 15, 2024
libunwind is required to build libc++ as of
llvm/llvm-project#77687 (comment)

It was already used for numbered versions, but not trunk.

I also  updated my branch and left everything else alone as I did not know whether they use version of clang that can build libunwind
@ldionne
Copy link
Member Author

ldionne commented Jan 15, 2024

@petrhosek @ldionne would it be better detect libunwind in LLVM_ENABLE_RUNTIMES?

I added a check in CMake here: #77991. The error message should now be clearer than previously.

@petrhosek
Copy link
Member

@petrhosek @ldionne would it be better detect libunwind in LLVM_ENABLE_RUNTIMES?

Asking because we have similar thing in compiler-rt, e.g. for lld, and I am not sure which approach is better: There are trade offs:

  1. checking LLVM_ENABLE_RUNTIMES simplify end user experience
  2. forcing default ON simplifies cmake files and avoids unexpected use of system lib

That would be my preference, specifically I'd set the default for LIBCXXABI_USE_LLVM_UNWINDER based on whether libunwind is present in LLVM_ENABLE_RUNTIMES (but still let user override it).

@ldionne
Copy link
Member Author

ldionne commented Jan 16, 2024

That means that based on whether LLVM_ENABLE_RUNTIMES=libunwind happens to be set or not, you'd use a fundamentally different unwinding library which implies a different ABI. It's convenient, but isn't that too subtle?

@mordante
Copy link
Member

FYI I think this change broke the documentation CI builder. Fixed in 7e909d5

justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
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 llvm#77662
rdar://120801778
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-rt github:workflow libc++abi libc++abi C++ Runtime Library. Not libc++. libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[D150897] [runtimes] Use LLVM libunwind from libc++abi and compiler-rt by default
10 participants