[libcxx-commits] [PATCH] D112126: [libunwind] Try to add -unwindlib=none while configuring and building libunwind
Martin Storsjö via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 20 01:52:05 PDT 2021
mstorsjo created this revision.
mstorsjo added reviewers: phosek, hvdijk, ldionne.
Herald added a subscriber: mgorny.
Herald added a project: libunwind.
Herald added a reviewer: libunwind.
mstorsjo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
If Clang is set up to link directly against libunwind (via the
-unwindlib option, or the corresponding builtin default option),
configuring libunwind will fail while bootstrapping (before the
initial libunwind is built), because every cmake test will
fail due to -lunwind not being found, and linking the shared library
will fail similarly.
Prior to 5f9be2c3e37c0428ba56876dd84af04b8d9d8915 <https://reviews.llvm.org/rG5f9be2c3e37c0428ba56876dd84af04b8d9d8915>, the build used
-nodefaultlibs, which skipped both potential C++ standard libraries
and the unwind library, but since that version, -nostdlib++ is
preferred, which omits the C++ standard library, but not any potential
unwind libraries.
Check if -unwindlib=none is supported, and add it in that case.
Using check_c_compiler_flag on its own doesn't work, because that only
adds the tested flag to the compilation command, and if -lunwind is
missing, the linking step would still fail - instead try adding it
to CMAKE_REQUIRED_FLAGS and restore the variable if it doesn't work.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D112126
Files:
libunwind/cmake/config-ix.cmake
libunwind/src/CMakeLists.txt
Index: libunwind/src/CMakeLists.txt
===================================================================
--- libunwind/src/CMakeLists.txt
+++ libunwind/src/CMakeLists.txt
@@ -83,6 +83,7 @@
endif()
# Setup flags.
+add_link_flags_if(LIBUNWIND_SUPPORTS_UNWINDLIB_NONE_FLAG -unwindlib=none)
if (LIBUNWIND_SUPPORTS_NOSTDLIBXX_FLAG)
add_link_flags_if_supported(-nostdlib++)
else()
Index: libunwind/cmake/config-ix.cmake
===================================================================
--- libunwind/cmake/config-ix.cmake
+++ libunwind/cmake/config-ix.cmake
@@ -16,6 +16,25 @@
endif ()
endif()
+# The compiler driver may be implicitly trying to link against libunwind,
+# which obviously might not work when building libunwind itself. Try to
+# check if -unwindlib=none is supported, and use that if possible.
+#
+# However, a plain check_c_compiler_flag(-unwindlib=none) would also fail, as
+# the tested flag is only added to the compilation command (letting the
+# compiler error out if it is unsupported), but not included in the linking
+# command (which still fails due to implicitly trying to link against the
+# possibly missing libunwind). Therefore, we must add it directly to
+# CMAKE_REQUIRED_FLAGS (which is included both when compiling and linking),
+# then do a dummy test with check_c_compiler_flag, and revert the change to
+# CMAKE_REQUIRED_FLAGS if it didn't work out.
+set(CMAKE_REQUIRED_FLAGS_ORIG "${CMAKE_REQUIRED_FLAGS}")
+set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -unwindlib=none")
+check_c_compiler_flag("" LIBUNWIND_SUPPORTS_UNWINDLIB_NONE_FLAG)
+if (NOT LIBUNWIND_SUPPORTS_UNWINDLIB_NONE_FLAG)
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS_ORIG}")
+endif()
+
# libunwind is using -nostdlib++ at the link step when available,
# otherwise -nodefaultlibs is used. We want all our checks to also
# use one of these options, otherwise we may end up with an inconsistency between
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112126.380875.patch
Type: text/x-patch
Size: 1929 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211020/efcdab51/attachment.bin>
More information about the libcxx-commits
mailing list