[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:09:18 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: None (a-n-n-a-l-e-e)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/77218.diff


1 Files Affected:

- (modified) libcxx/src/CMakeLists.txt (+1-1) 


``````````diff
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)

``````````

</details>


https://github.com/llvm/llvm-project/pull/77218


More information about the libcxx-commits mailing list