From fac9fcd55245479d040dde3f5e9f4e169c30a0ec Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Mon, 9 Dec 2024 09:19:51 -0800 Subject: [PATCH] [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. --- libcxxabi/src/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt index 84fe2784bec5..21dda44e0997 100644 --- a/libcxxabi/src/CMakeLists.txt +++ b/libcxxabi/src/CMakeLists.txt @@ -75,6 +75,12 @@ if (NOT APPLE) # On Apple platforms, we always use -nostdlib++ so we don't need 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()