Reapply [compiler-rt] Check for and use -lunwind when linking with -nodefaultlibs (#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.
This commit is contained in:
Martin Storsjö 2023-10-05 11:41:11 +03:00 committed by GitHub
parent 26bb22b0c8
commit 7c5e4e5fa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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_GetRegionStart "" 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.