diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp --- a/compiler-rt/lib/dfsan/dfsan_custom.cpp +++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp @@ -461,6 +461,20 @@ return dl_iterate_phdr(dl_iterate_phdr_cb, &dipi); } +// This function is only available for glibc 2.27 or newer. Mark it weak so +// linking succeeds with older glibcs. +SANITIZER_WEAK_ATTRIBUTE void _dl_get_tls_static_info(size_t *sizep, + size_t *alignp); + +SANITIZER_INTERFACE_ATTRIBUTE void __dfsw__dl_get_tls_static_info( + size_t *sizep, size_t *alignp, dfsan_label sizep_label, + dfsan_label alignp_label) { + assert(_dl_get_tls_static_info); + _dl_get_tls_static_info(sizep, alignp); + dfsan_set_label(0, sizep, sizeof(*sizep)); + dfsan_set_label(0, alignp, sizeof(*alignp)); +} + SANITIZER_INTERFACE_ATTRIBUTE char *__dfsw_ctime_r(const time_t *timep, char *buf, dfsan_label timep_label, dfsan_label buf_label, dfsan_label *ret_label) { diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt --- a/compiler-rt/lib/dfsan/done_abilist.txt +++ b/compiler-rt/lib/dfsan/done_abilist.txt @@ -183,6 +183,7 @@ # Functions that produce output does not depend on the input (need to zero the # shadow manually). +fun:_dl_get_tls_static_info=custom fun:calloc=custom fun:clock_gettime=custom fun:dlopen=custom diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp --- a/compiler-rt/test/dfsan/custom.cpp +++ b/compiler-rt/test/dfsan/custom.cpp @@ -809,6 +809,22 @@ dl_iterate_phdr(dl_iterate_phdr_test_cb, (void *)3); } +// On glibc < 2.27, this symbol is not available. Mark it weak so we can skip +// testing in this case. +__attribute__((weak)) extern "C" void _dl_get_tls_static_info(size_t *sizep, + size_t *alignp); + +void test__dl_get_tls_static_info() { + if (!_dl_get_tls_static_info) + return; + size_t sizep = 0, alignp = 0; + dfsan_set_label(i_label, &sizep, sizeof(sizep)); + dfsan_set_label(i_label, &alignp, sizeof(alignp)); + _dl_get_tls_static_info(&sizep, &alignp); + ASSERT_ZERO_LABEL(sizep); + ASSERT_ZERO_LABEL(alignp); +} + void test_strrchr() { char str1[] = "str1str1"; dfsan_set_label(i_label, &str1[7], 1); @@ -1147,6 +1163,7 @@ assert(i_j_label != j_label); assert(i_j_label != k_label); + test__dl_get_tls_static_info(); test_bcmp(); test_calloc(); test_clock_gettime();