[compiler-rt] [compiler-rt] Check for and use -lunwind when linking with -nodefaultlibs (PR #65912)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 10 14:26:43 PDT 2023


https://github.com/mstorsjo created https://github.com/llvm/llvm-project/pull/65912:

If libc++ is available and should be used as the ubsan C++ ABI library, the check for libc++ might fail if libc++ is a static library, as the -nodefaultlibs flag inhibits a potential compiler default -lunwind.

Just like the -nodefaultlibs configuration tests for and manually adds a bunch of compiler default libraries, look for -lunwind too.

>From 1530cbcd04b80cfc42a0a4f0d96cea67cdb47fbc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Mon, 11 Sep 2023 00:22:55 +0300
Subject: [PATCH] [compiler-rt] Check for and use -lunwind when linking with
 -nodefaultlibs

If libc++ is available and should be used as the ubsan C++ ABI
library, the check for libc++ might fail if libc++ is a static
library, as the -nodefaultlibs flag inhibits a potential compiler
default -lunwind.

Just like the -nodefaultlibs configuration tests for and manually
adds a bunch of compiler default libraries, look for -lunwind too.
---
 compiler-rt/cmake/config-ix.cmake | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 09a9b62ce4cd37b..8a5b2792661da9d 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -63,6 +63,12 @@ if (C_SUPPORTS_NODEFAULTLIBS_FLAG)
                         moldname mingwex msvcrt)
     list(APPEND CMAKE_REQUIRED_LIBRARIES ${MINGW_LIBRARIES})
   endif()
+  check_library_exists(unwind _Unwind_RaiseException "" COMPILER_RT_HAS_LIBUNWIND)
+  if (COMPILER_RT_HAS_LIBUNWIND)
+    # If we're omitting default libraries, we might need to manually link in libunwind.
+    # This can affect whether we detect a statically linked libc++ correctly.
+    list(APPEND CMAKE_REQUIRED_LIBRARIES unwind)
+  endif()
 endif ()
 
 # CodeGen options.



More information about the llvm-commits mailing list