Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcxx: set LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS for system-libcxxabi on APPLE #77218

Merged
merged 1 commit into from Jan 11, 2024
Merged

libcxx: set LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS for system-libcxxabi on APPLE #77218

merged 1 commit into from Jan 11, 2024

Conversation

ghost
Copy link

@ghost ghost commented Jan 7, 2024

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:

  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.

NixOS/nixpkgs#269548

@ghost ghost self-requested a review as a code owner January 7, 2024 02:08
Copy link

github-actions bot commented Jan 7, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 7, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 7, 2024

@llvm/pr-subscribers-libcxx

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

Changes

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:

  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 $&lt;TARGET_NAME_IF_EXISTS:cxxabi-reexports&gt;)
  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 --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)

@ldionne ldionne self-assigned this Jan 10, 2024
Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense, good catch.

@ghost
Copy link
Author

ghost commented Jan 11, 2024

build failure seems unrelated as target was:

 Ubuntu clang version 18.0.0 (++20231120042147+3494c555c93c-1~exp1~20231120042257.1318)
 Target: x86_64-pc-linux-gnu

and not apple.

@ldionne
Copy link
Member

ldionne commented Jan 11, 2024

Yeah, I am merging this since all the Apple testing passed. Thanks!

@ldionne ldionne merged commit b3981ed into llvm:main Jan 11, 2024
18 of 19 checks passed
@ghost ghost deleted the darwin-system-libcxxabi-link branch January 11, 2024 22:08
veprbl pushed a commit to NixOS/nixpkgs that referenced this pull request Jan 12, 2024
This change applies the upstream PR
llvm/llvm-project#77218 so the same link flags
on darwin are used as when LIBCXX_CXX_ABI=libcxxabi. Specifically, this
adds
"-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/notweak.exp"
which prevents libcxx from segfaulting on darwin
github-actions bot pushed a commit to NixOS/nixpkgs that referenced this pull request Jan 12, 2024
This change applies the upstream PR
llvm/llvm-project#77218 so the same link flags
on darwin are used as when LIBCXX_CXX_ABI=libcxxabi. Specifically, this
adds
"-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/notweak.exp"
which prevents libcxx from segfaulting on darwin

(cherry picked from commit 7b62547)
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
…stem-libcxxabi (llvm#77218)

When using LIBCXX_CXX_ABI=system-libcxxabi on Apple platforms, we would not
re-export the libc++abi symbols unlike when LIBCXX_CXX_ABI=libcxxabi. This
was caused by overly strict string matching in CMake.

NixOS/nixpkgs#269548
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants