[DFSan] Add custom wrapper for _dl_get_tls_static_info.

Implementation is here:
https://code.woboq.org/userspace/glibc/elf/dl-tls.c.html#307

We use weak symbols to avoid linking issues with glibcs older than 2.27.

Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D93053
This commit is contained in:
Matt Morehouse 2020-12-10 11:02:42 -08:00
parent 00ffea77ad
commit 72fd47b93d
3 changed files with 32 additions and 0 deletions

View File

@ -461,6 +461,20 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_dl_iterate_phdr(
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) {

View File

@ -183,6 +183,7 @@ fun:uselocale=discard
# 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

View File

@ -809,6 +809,22 @@ void test_dl_iterate_phdr() {
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 @@ int main(void) {
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();