[libcxxabi] Always link against libzircon for Fuchsia targets (#115910)
When using LTO, the deplibs mechanism is insufficient to ensure that
libzircon is always brought into the link prior to LTO code generation.
The general problem is discussed in depth in
https://github.com/llvm/llvm-project/issues/56070
To work around this, we can just provide libzircon as a link input.
GitOrigin-RevId: fac9fcd55245479d040dde3f5e9f4e169c30a0ec
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 84fe278..21dda44 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -75,6 +75,12 @@
add_library_flags_if(LIBCXXABI_HAS_C_LIB c)
endif()
+if (FUCHSIA)
+ # TODO: Use CMAKE_LINK_LIBRARY_USING_FEATURE once our minimum CMake is at least 3.24
+ # https://cmake.org/cmake/help/latest/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.html
+ add_link_flags("-Wl,--push-state,--as-needed,-lzircon,--pop-state")
+endif()
+
if (NOT LIBCXXABI_USE_COMPILER_RT)
add_library_flags_if(LIBCXXABI_HAS_GCC_LIB gcc)
endif()