Skip to content

LSan musl TSD root - #122

Open
thevar1able wants to merge 2 commits into
ClickHouse/release-22.xfrom
lsan-musl-tsd-root
Open

LSan musl TSD root#122
thevar1able wants to merge 2 commits into
ClickHouse/release-22.xfrom
lsan-musl-tsd-root

Conversation

@thevar1able

@thevar1able thevar1able commented Aug 5, 2026

Copy link
Copy Markdown
Member

thevar1able and others added 2 commits August 5, 2026 14:33
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant