[compiler-rt] Reapply [compiler-rt] Check for and use -lunwind when linking with -nodefaultlibs (PR #66584)
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 16 12:58:18 PDT 2023
https://github.com/mstorsjo created https://github.com/llvm/llvm-project/pull/66584
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.
This is a reland of #65912.
>From 11cd99a265c7cbf1f5c9cdf9eea02547ccae6a23 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Fri, 15 Sep 2023 11:49:45 +0300
Subject: [PATCH] Reapply [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.
This is a reland of #65912.
---
compiler-rt/cmake/config-ix.cmake | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 09a9b62ce4cd37b..c43b52762919a0b 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -63,6 +63,16 @@ if (C_SUPPORTS_NODEFAULTLIBS_FLAG)
moldname mingwex msvcrt)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${MINGW_LIBRARIES})
endif()
+ if (NOT TARGET unwind)
+ # Don't check for a library named unwind, if there's a target with that name within
+ # the same build.
+ 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()
endif ()
# CodeGen options.
More information about the llvm-commits
mailing list