[all-commits] [llvm/llvm-project] 9be8f8: [sanitizer] Simplify GetTls with dl_iterate_phdr
Fangrui Song via All-commits
all-commits at lists.llvm.org
Thu Mar 25 21:55:43 PDT 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 9be8f8b34d9b150cd1811e3556fe9d0cd735ae29
https://github.com/llvm/llvm-project/commit/9be8f8b34d9b150cd1811e3556fe9d0cd735ae29
Author: Fangrui Song <i at maskray.me>
Date: 2021-03-25 (Thu, 25 Mar 2021)
Changed paths:
M compiler-rt/lib/asan/asan_rtl.cpp
M compiler-rt/lib/asan/asan_thread.cpp
M compiler-rt/lib/hwasan/hwasan.cpp
M compiler-rt/lib/lsan/lsan.cpp
M compiler-rt/lib/memprof/memprof_rtl.cpp
M compiler-rt/lib/msan/msan.cpp
M compiler-rt/lib/sanitizer_common/sanitizer_common.h
M compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp
M compiler-rt/lib/sanitizer_common/sanitizer_linux.h
M compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
M compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
M compiler-rt/lib/sanitizer_common/sanitizer_rtems.cpp
M compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
M compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp
M compiler-rt/lib/sanitizer_common/tests/sanitizer_linux_test.cpp
M compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
Log Message:
-----------
[sanitizer] Simplify GetTls with dl_iterate_phdr
GetTls is the range of
* thread control block and optional TLS_PRE_TCB_SIZE
* static TLS blocks plus static TLS surplus
On glibc, lsan requires the range to include
`pthread::{specific_1stblock,specific}` so that allocations only referenced by
`pthread_setspecific` can be scanned.
This patch uses `dl_iterate_phdr` to collect TLS ranges. Find the one
with `dlpi_tls_modid==1` as one of the initially loaded module, then find
consecutive ranges. The boundaries give us addr and size.
This allows us to drop the glibc internal `_dl_get_tls_static_info` and
`InitTlsSize` entirely. Use the simplified method with non-Android Linux for
now, but in theory this can be used with *BSD and potentially other ELF OSes.
In the future, we can move `ThreadDescriptorSize` code to lsan (and consider
intercepting `pthread_setspecific`) to avoid hacks in generic code.
See https://reviews.llvm.org/D93972#2480556 for analysis on GetTls usage
across various sanitizers.
Differential Revision: https://reviews.llvm.org/D98926
More information about the All-commits
mailing list