LSan musl TSD root - #122
Open
thevar1able wants to merge 2 commits into
Open
Conversation
LeakSanitizer treats allocations reachable from a thread's TLS range as live. On glibc GetTls extends the range over the TCB, covering the inline pthread_setspecific slots (pthread::specific_1stblock). musl stores the slots in a separate array at the top of the thread mapping, above the static TLS block, so allocations referenced only through pthread_setspecific of running threads - e.g. libc++'s per-thread __thread_struct of any thread alive at exit - were reported as leaks. Extend the musl branch of GetTls over the slot array. The bounds come from __pthread_current_tsd_range, a helper added to the ClickHouse musl fork; the reference is weak, so builds against other libcs are unaffected.
The previous commit blindly merged the static TLS range with the TSD
array range returned by __pthread_current_tsd_range. That is only valid
for pthread_create'd threads, where the TSD array sits at the top of the
same thread mapping as static TLS. For the main thread the slots are a
static array (__pthread_tsd_main) in the executable's .bss, while its
static TLS is a separate anonymous mmap - merging the two produced a
huge range covering unmapped memory, and the LeakSanitizer StopTheWorld
tracer crashed with SIGSEGV while scanning it at process exit
("Tracer caught signal 11" followed by SIGABRT).
Extend the range only when the TSD array sits at most a page above the
detected TLS block (the per-thread-mapping case). The main thread's
__pthread_tsd_main is already scanned as a global root.
Validated with an ASan-instrumented protoc run 100 times: 71/100
crashed in the exit-time leak check without this fix, 0/100 with it.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
ClickHouse/ClickHouse#113486