[compiler-rt] 50dd545 - [DFSan] Add bcmp wrapper.
Matt Morehouse via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 17 09:24:08 PDT 2020
Author: Matt Morehouse
Date: 2020-09-17T09:23:49-07:00
New Revision: 50dd545b00ed72a9ed2031cb5eb9bf26dd5af0c0
URL: https://github.com/llvm/llvm-project/commit/50dd545b00ed72a9ed2031cb5eb9bf26dd5af0c0
DIFF: https://github.com/llvm/llvm-project/commit/50dd545b00ed72a9ed2031cb5eb9bf26dd5af0c0.diff
LOG: [DFSan] Add bcmp wrapper.
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D87801
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 eb26bea188ae..77b93f81f349 100644
--- a/compiler-rt/lib/dfsan/dfsan_custom.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp
@@ -95,18 +95,9 @@ SANITIZER_INTERFACE_ATTRIBUTE char *__dfsw_strchr(const char *s, int c,
}
}
-DECLARE_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_memcmp, uptr caller_pc,
- const void *s1, const void *s2, size_t n,
- dfsan_label s1_label, dfsan_label s2_label,
- dfsan_label n_label)
-
-SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_memcmp(const void *s1, const void *s2,
- size_t n, dfsan_label s1_label,
- dfsan_label s2_label,
- dfsan_label n_label,
- dfsan_label *ret_label) {
- CALL_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_memcmp, GET_CALLER_PC(), s1, s2, n,
- s1_label, s2_label, n_label);
+static int dfsan_memcmp_bcmp(const void *s1, const void *s2, size_t n,
+ dfsan_label s1_label, dfsan_label s2_label,
+ dfsan_label n_label, dfsan_label *ret_label) {
const char *cs1 = (const char *) s1, *cs2 = (const char *) s2;
for (size_t i = 0; i != n; ++i) {
if (cs1[i] != cs2[i]) {
@@ -129,6 +120,29 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_memcmp(const void *s1, const void *s2,
return 0;
}
+DECLARE_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_memcmp, uptr caller_pc,
+ const void *s1, const void *s2, size_t n,
+ dfsan_label s1_label, dfsan_label s2_label,
+ dfsan_label n_label)
+
+SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_memcmp(const void *s1, const void *s2,
+ size_t n, dfsan_label s1_label,
+ dfsan_label s2_label,
+ dfsan_label n_label,
+ dfsan_label *ret_label) {
+ CALL_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_memcmp, GET_CALLER_PC(), s1, s2, n,
+ s1_label, s2_label, n_label);
+ return dfsan_memcmp_bcmp(s1, s2, n, s1_label, s2_label, n_label, ret_label);
+}
+
+SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_bcmp(const void *s1, const void *s2,
+ size_t n, dfsan_label s1_label,
+ dfsan_label s2_label,
+ dfsan_label n_label,
+ dfsan_label *ret_label) {
+ return dfsan_memcmp_bcmp(s1, s2, n, s1_label, s2_label, n_label, ret_label);
+}
+
DECLARE_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_strcmp, uptr caller_pc,
const char *s1, const char *s2,
dfsan_label s1_label, dfsan_label s2_label)
diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt
index 52f3ff5ef239..85255f7c9026 100644
--- a/compiler-rt/lib/dfsan/done_abilist.txt
+++ b/compiler-rt/lib/dfsan/done_abilist.txt
@@ -183,6 +183,7 @@ fun:strtoull=custom
# Functions that produce an output that is computed from the input, but is not
# necessarily data dependent.
+fun:bcmp=custom
fun:memchr=custom
fun:memcmp=custom
fun:strcasecmp=custom
diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp
index 7802f88f2c24..6d5e06a7799d 100644
--- a/compiler-rt/test/dfsan/custom.cpp
+++ b/compiler-rt/test/dfsan/custom.cpp
@@ -17,12 +17,13 @@
#include <pwd.h>
#include <sched.h>
#include <signal.h>
-#include <stdio.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/select.h>
+#include <strings.h>
#include <sys/resource.h>
+#include <sys/select.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
@@ -86,6 +87,24 @@ void test_memcmp() {
#endif
}
+void test_bcmp() {
+ char str1[] = "str1", str2[] = "str2";
+ dfsan_set_label(i_label, &str1[3], 1);
+ dfsan_set_label(j_label, &str2[3], 1);
+
+ int rv = bcmp(str1, str2, sizeof(str1));
+ assert(rv != 0);
+#ifdef STRICT_DATA_DEPENDENCIES
+ ASSERT_ZERO_LABEL(rv);
+#else
+ ASSERT_LABEL(rv, i_j_label);
+#endif
+
+ rv = bcmp(str1, str2, sizeof(str1) - 2);
+ assert(rv == 0);
+ ASSERT_ZERO_LABEL(rv);
+}
+
void test_memcpy() {
char str1[] = "str1";
char str2[sizeof(str1)];
@@ -967,6 +986,7 @@ int main(void) {
assert(i_j_label != j_label);
assert(i_j_label != k_label);
+ test_bcmp();
test_calloc();
test_clock_gettime();
test_ctime_r();
More information about the llvm-commits
mailing list