[all-commits] [llvm/llvm-project] abdccf: [sanitizer] Clear pending dlerror on thread exit b...
Vitaly Buka via All-commits
all-commits at lists.llvm.org
Sun Oct 4 13:46:30 PDT 2026
Branch: refs/heads/users/vitalybuka/spr/sanitizer-clear-pending-dlerror-on-thread-exit-before-unregistering
Home: https://github.com/llvm/llvm-project
Commit: abdccf38d311320eedd7c65b450b5c02c7f4f801
https://github.com/llvm/llvm-project/commit/abdccf38d311320eedd7c65b450b5c02c7f4f801
Author: Vitaly Buka <vitalybuka at google.com>
Date: 2026-10-04 (Sun, 04 Oct 2026)
Changed paths:
M compiler-rt/lib/asan/asan_thread.cpp
M compiler-rt/lib/hwasan/hwasan_linux.cpp
M compiler-rt/lib/lsan/lsan_thread.cpp
M compiler-rt/lib/sanitizer_common/sanitizer_dl.cpp
M compiler-rt/lib/sanitizer_common/sanitizer_dl.h
A compiler-rt/test/lsan/TestCases/Linux/detached_thread_dlsym.c
Log Message:
-----------
[sanitizer] Clear pending dlerror on thread exit before unregistering
Starting with glibc 2.34, failed dlfcn calls store a per-thread error
struct in TLS (__libc_dlerror_result) instead of a pthread_key_t, and
free it in __libc_thread_freeres() after all pthread TSD destructors
have completed.
Because ASan, LSan, and HWASan unregister the exiting thread in their
pthread TSD destructors during __nptl_deallocate_tsd(), LSan stops
scanning that thread's TLS before __libc_thread_freeres() frees
__libc_dlerror_result. If a leak check runs in that window (for example,
when the main thread exits while a detached worker thread is finishing)
and libc debug symbols are not installed to match the default *dlerror*
suppression on _dlerror_run, LSan reports a false positive leak from
dlsym/dlopen.
This manifests as flaky LSan leaks on `LLVM :: ExecutionEngine/JITLink/x86-64/`
tests on `sanitizer-*-linux-bootstrap-asan` and `sanitizer-x86_64-linux-fast`
buildbots, exposed after re-enabling `ExecutionEngine` tests under ASan in
https://github.com/llvm/llvm-zorg/pull/971 (reverting
https://github.com/llvm/llvm-zorg/pull/823; see #186534).
Call `if (dlerror()) dlerror();` before unregistering the exiting thread
so glibc frees its per-thread dlerror buffer while the thread is still
tracked.
Assisted-by: Gemini
Pull Request: https://github.com/llvm/llvm-project/pull/228930
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list