llvm-project/compiler-rt/lib
Fangrui Song ec575e3b0a [sanitizer] Simplify GetTls with dl_iterate_phdr on Linux
This was reverted by f176803ef1 due to
Ubuntu 16.04 x86-64 glibc 2.23 problems.
This commit additionally calls `__tls_get_addr({modid,0})` to work around the
dlpi_tls_data==NULL issues for glibc<2.25
(https://sourceware.org/bugzilla/show_bug.cgi?id=19826)

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 blocks. 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.

This simplification enables D99566 for TLS Variant I architectures.

See https://reviews.llvm.org/D93972#2480556 for analysis on GetTls usage
across various sanitizers.

Differential Revision: https://reviews.llvm.org/D98926
2021-04-04 15:35:53 -07:00
..
BlocksRuntime
asan [sanitizer] Simplify GetTls with dl_iterate_phdr on Linux 2021-04-04 15:35:53 -07:00
builtins [builtins] Build for arm64_32 for watchOS (Darwin) 2021-04-01 17:16:18 -07:00
cfi [sanitizers] Remove unneeded MaybeCall*DefaultOptions() and nullptr checks 2020-09-08 10:12:05 -07:00
crt [RISCV][crt] support building without init_array 2020-12-01 17:17:50 +03:00
dfsan [dfsan] Set sigemptyset's return label to be 0 2021-03-31 21:07:44 +00:00
fuzzer Tweak SimpleFastHash 2021-04-01 23:26:03 -07:00
gwp_asan [GWP-ASan] Change sys/cdefs.h to features.h 2021-02-17 20:03:16 -08:00
hwasan [sanitizer] Simplify GetTls with dl_iterate_phdr on Linux 2021-04-04 15:35:53 -07:00
interception [sanitizer] Define SANITIZER_GLIBC to refine SANITIZER_LINUX feature detection and support musl 2021-01-06 10:55:40 -08:00
lsan [sanitizer] Simplify GetTls with dl_iterate_phdr on Linux 2021-04-04 15:35:53 -07:00
memprof [sanitizer] Simplify GetTls with dl_iterate_phdr on Linux 2021-04-04 15:35:53 -07:00
msan [sanitizer] Simplify GetTls with dl_iterate_phdr on Linux 2021-04-04 15:35:53 -07:00
profile [gcov] Delete ancient MSVC workaround 2021-03-12 15:10:12 -08:00
safestack compiler-rt: Rename .cc file in lib/{interception/tests,safestack} to .cpp 2019-08-01 13:56:52 +00:00
sanitizer_common [sanitizer] Simplify GetTls with dl_iterate_phdr on Linux 2021-04-04 15:35:53 -07:00
scudo [NFC][scudo] Restore !UseQuarantine check in tests 2021-04-03 23:52:06 -07:00
stats compiler-rt: Rename .cc file in lib/{dfsan,stats,ubsan_minimal} to .cpp 2019-08-01 12:41:23 +00:00
tsan [sanitizer] Simplify GetTls with dl_iterate_phdr on Linux 2021-04-04 15:35:53 -07:00
ubsan [sanitizer] Remove max_len parameter from InternalScopedString 2021-03-17 16:57:09 -07:00
ubsan_minimal [compiler-rt] Suppress -Wunused-result due to ::write when _FORTIFY_SOURCE>0 in glibc 2020-10-12 09:57:12 -07:00
xray [XRay][compiler-rt][x86_64] Fix CFI directives in assembly trampolines 2021-03-06 10:38:27 -08:00
CMakeLists.txt [MemProf] Decouple memprof build from COMPILER_RT_BUILD_SANITIZERS 2020-10-26 13:52:50 -07:00