[libunwind] [libunwind] Use -nostdlib++ when linking libunwind (PR #75646)

Louis Dionne via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 18 08:33:21 PST 2023


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/75646

>From c5ff17c24afba4b44e45894452c733fef0183fb0 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Fri, 15 Dec 2023 14:14:44 -0500
Subject: [PATCH 1/2] [libunwind] Use -nostdlib++ when linking libunwind

We shouldn't need to link against libc++ or libc++abi when building
libunwind, since that would otherwise be a circular dependency.
---
 libunwind/src/CMakeLists.txt | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index abb019b88ebabd..c0e60f29a3db25 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -66,20 +66,21 @@ set(LIBUNWIND_SOURCES
     ${LIBUNWIND_ASM_SOURCES})
 
 # Generate library list.
-if (LIBUNWIND_USE_COMPILER_RT)
-  add_library_flags("${LIBUNWIND_BUILTINS_LIBRARY}")
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+  add_link_flags_if_supported(-nostdlib++)
 else()
-  add_library_flags_if(LIBUNWIND_HAS_GCC_S_LIB gcc_s)
-  add_library_flags_if(LIBUNWIND_HAS_GCC_LIB gcc)
-endif()
-if (NOT APPLE) # On Apple platforms, we don't need to link explicitly against system libraries
+  if (LIBUNWIND_USE_COMPILER_RT)
+    add_library_flags("${LIBUNWIND_BUILTINS_LIBRARY}")
+  else()
+    add_library_flags_if(LIBUNWIND_HAS_GCC_S_LIB gcc_s)
+    add_library_flags_if(LIBUNWIND_HAS_GCC_LIB gcc)
+  endif()
   add_library_flags_if(LIBUNWIND_HAS_C_LIB c)
   add_library_flags_if(LIBUNWIND_HAS_DL_LIB dl)
+endif()
 
-  if (LIBUNWIND_ENABLE_THREADS)
+if (LIBUNWIND_ENABLE_THREADS AND NOT APPLE)
     add_library_flags_if(LIBUNWIND_HAS_PTHREAD_LIB pthread)
-    add_compile_flags_if(LIBUNWIND_WEAK_PTHREAD_LIB -DLIBUNWIND_USE_WEAK_PTHREAD=1)
-  endif()
 endif()
 
 if (LIBUNWIND_ENABLE_THREADS)

>From 8ab12655791d3cade2511e4ad860b3dc16e7319b Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 18 Dec 2023 11:33:11 -0500
Subject: [PATCH 2/2] Link against libdl on non-Apple platforms

---
 libunwind/src/CMakeLists.txt | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index c0e60f29a3db25..570824260465d6 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -76,6 +76,9 @@ else()
     add_library_flags_if(LIBUNWIND_HAS_GCC_LIB gcc)
   endif()
   add_library_flags_if(LIBUNWIND_HAS_C_LIB c)
+endif()
+
+if (NOT APPLE)
   add_library_flags_if(LIBUNWIND_HAS_DL_LIB dl)
 endif()
 



More information about the cfe-commits mailing list