[libcxx-commits] [libcxx] libcxx: set LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS for system-libcxxabi on APPLE (PR #77218)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jan 6 18:08:38 PST 2024


https://github.com/a-n-n-a-l-e-e created https://github.com/llvm/llvm-project/pull/77218

when building with using `system-libcxxabi` with an out of tree libcxxabi still need to link with the flags when `LIBCXX_CXX_ABI` is set to `libcxxabi` otherwise `libcxx` will segfault on older versions of macos, eg: big sur, when multiple libc++ libraries are linked, or one linked and other dlopened.

the extra link flags that get added are:
```cmake
  if (LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS)
    target_link_libraries(cxx_shared PRIVATE
      "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++unexp.exp"
      "-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++abi.exp"
      "-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/notweak.exp"
      "-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/weak.exp")

    target_link_libraries(cxx_shared PRIVATE $<TARGET_NAME_IF_EXISTS:cxxabi-reexports>)
  endif()
```

and  `"-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/notweak.exp"` is the one that prevents segfaults, as symbols will not be resolved from the wrong library.

>From c5b89b29ee6e3c444a355fd1cf733ce7ab2e316a Mon Sep 17 00:00:00 2001
From: annalee <150648636+a-n-n-a-l-e-e at users.noreply.github.com>
Date: Sun, 7 Jan 2024 02:02:28 +0000
Subject: [PATCH] libcxx: set LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS for
 system-libcxxabi

---
 libcxx/src/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 329964a001363b..cdf0be87250df5 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -229,7 +229,7 @@ if (LIBCXX_ENABLE_SHARED)
   # Maybe re-export symbols from libc++abi
   # In particular, we don't re-export the symbols if libc++abi is merged statically
   # into libc++ because in that case there's no dylib to re-export from.
-  if (APPLE AND LIBCXX_CXX_ABI STREQUAL "libcxxabi"
+  if (APPLE AND LIBCXX_CXX_ABI MATCHES "libcxxabi$"
             AND NOT DEFINED LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS
             AND NOT LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY)
     set(LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS ON)



More information about the libcxx-commits mailing list