[llvm-branch-commits] [compiler-rt] 72fd47b - [DFSan] Add custom wrapper for _dl_get_tls_static_info.
Matt Morehouse via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Dec 10 11:07:43 PST 2020
Author: Matt Morehouse
Date: 2020-12-10T11:03:28-08:00
New Revision: 72fd47b93d1165f7e4499a5c2b4241dae7ce82ae
URL: https://github.com/llvm/llvm-project/commit/72fd47b93d1165f7e4499a5c2b4241dae7ce82ae
DIFF: https://github.com/llvm/llvm-project/commit/72fd47b93d1165f7e4499a5c2b4241dae7ce82ae.diff
LOG: [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
Added:
Modified:
compiler-rt/lib/dfsan/dfsan_custom.cpp
compiler-rt/lib/dfsan/done_abilist.txt
compiler-rt/test/dfsan/custom.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp
index b43f978d8a2c..3b8c46d642a4 100644
--- a/compiler-rt/lib/dfsan/dfsan_custom.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp
@@ -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) {
diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt
index b8cfa3b9941b..f4d0950e65dc 100644
--- a/compiler-rt/lib/dfsan/done_abilist.txt
+++ b/compiler-rt/lib/dfsan/done_abilist.txt
@@ -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
diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp
index a03f33f769af..3098616c0e50 100644
--- a/compiler-rt/test/dfsan/custom.cpp
+++ b/compiler-rt/test/dfsan/custom.cpp
@@ -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();
More information about the llvm-branch-commits
mailing list