Repository navigation
fix(tls): keep libflare_tls mapped after its last dlclose on macOS - #45
Merged
Merged
Conversation
03aac93 moved the shim's error buffer from thread_local to a pthread key. dyld never unloads an image with thread-local variables, and that had been keeping libflare_tls mapped. Without them the last dlclose unmaps it while OpenSSL and the key's destructor still point into it, and the next call crashes. On macOS every fork-based test in tests/tls/test_tls.mojo segfaults (exit 139) right after its server handle drops; with one extra dlopen held for the run, all 17 pass. Linux links with -z nodelete, which macOS's linker does not have. The shim now takes a RTLD_NODELETE reference to itself from a constructor, the portable spelling of the same thing, which also covers recipe.yaml's build (it never passed -z nodelete). -ldl for older glibc sysroots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KxW5zazz1MvVNCxeZzQBRL
Owner
|
Great! Thanks. |
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.
Since 03aac93 ("keep the OpenSSL shim free of thread-local storage"), every fork-based test in
tests/tls/test_tls.mojosegfaults on macOS. The first istest_tls_connect_valid_cert_succeeds, and the process exits with 139.Cause:
thread_localerror buffer was keepinglibflare_tlsmapped.dlclose(when_TlsTestServer/TlsStreamdrop theirOwnedDLHandle) really unmaps the shim.build.shlinks with-z nodelete, which macOS's linker doesn't have.Evidence, on
8fe83c5e, Mojo 1.2.0, osx-arm64:test_tls.mojocrashes inlibKGENCompilerRTSharedright after the first test's server handle drops.dlopen(libflare_tls)for the whole run: 17/17 pass, which isolates the unload as the cause.Fix:
openssl_wrapper.cpptakes anRTLD_NOLOAD | RTLD_NODELETEreference to its own image, found throughdladdr. That's the portable spelling of-z nodelete.recipe.yaml's build, which never passed-z nodelete, so the conda package was unloadable on Linux too.-ldlis added to both builds for older glibc sysroots.__tls_get_addrwin is kept.