Repository navigation
🐛 Statically link libc++ on macOS for LLVM 22+ - #57
Merged
Merged
Conversation
Upstream libc++ headers expect a libc++ library of the same version, but Apple's system libc++ lags behind: LLVM 23 programs fail to link on macOS 26 (missing vtable for std::__bad_variant_access_with_msg). Linking the bundled libc++ dynamically instead put two libc++ copies in any ASan process, since the ASan runtime uses the system libc++. For LLVM 22+, link the package's libc++.a and libc++abi.a statically on every macOS version, with -Wl,-no_exported_symbols so dyld doesn't merge the executable's weak libc++ symbols with the system copy. Add demos/libcxx-runtime, which CI builds and runs under ASan on native builds, to catch both failures.
kammce
force-pushed
the
macos-static-libcxx
branch
from
October 12, 2026 02:08
f976ee7 to
3c6737e
Compare
kammce
marked this pull request as ready for review
October 12, 2026 02:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upstream libc++ headers expect a libc++ library of the same version, but Apple's system libc++ lags behind upstream:
Undefined symbols: vtable for std::__bad_variant_access_with_msg).bad-free in std::locale::~locale).For LLVM 22+, this links the package's
libc++.aandlibc++abi.astatically on every macOS version, so every program uses the libc++ that matches its headers. It also exposes libc++ to link-time analysis.-Wl,-no_exported_symbolsis also needed: without it, dyld merges the executable's weak libc++ symbols with the system libc++ that ASan loads, and the samelocalebad-free comes back (reproduced withscatter_span's tests). LLVM 20/21 keep using the system libc++.demos/libcxx-runtimeis built and run under ASan on native LLVM 22+ CI jobs. It throwsbad_variant_accessand exercises locales, and it aborts without-no_exported_symbols.Tested locally on macOS 27: the demo and
scatter_span's ASan tests pass, and binaries have no libc++ dylib dependency.Verified in CI with LLVM 23 on macOS 15, 26 and 27: the toolchain builds and the libc++ runtime check passes on all three.