[compiler-rt] r191899 - tsan: fix false positive in localtime()
Dmitry Vyukov
dvyukov at google.com
Thu Oct 3 07:12:09 PDT 2013
Author: dvyukov
Date: Thu Oct 3 09:12:09 2013
New Revision: 191899
URL: http://llvm.org/viewvc/llvm-project?rev=191899&view=rev
Log:
tsan: fix false positive in localtime()
Modified:
compiler-rt/trunk/lib/msan/msan_interceptors.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=191899&r1=191898&r2=191899&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Thu Oct 3 09:12:09 2013
@@ -1126,6 +1126,8 @@ struct MSanInterceptorContext {
__msan_unpoison(ptr, size)
#define COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, size) \
CHECK_UNPOISONED_CTX(ctx, ptr, size)
+#define COMMON_INTERCEPTOR_INITIALIZE_RANGE(ctx, ptr, size) \
+ __msan_unpoison(ptr, size)
#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...) \
if (msan_init_is_running) return REAL(func)(__VA_ARGS__); \
MSanInterceptorContext msan_ctx = {IsInInterceptorScope()}; \
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=191899&r1=191898&r2=191899&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu Oct 3 09:12:09 2013
@@ -15,6 +15,7 @@
// COMMON_INTERCEPTOR_ENTER
// COMMON_INTERCEPTOR_READ_RANGE
// COMMON_INTERCEPTOR_WRITE_RANGE
+// COMMON_INTERCEPTOR_INITIALIZE_RANGE
// COMMON_INTERCEPTOR_FD_ACQUIRE
// COMMON_INTERCEPTOR_FD_RELEASE
// COMMON_INTERCEPTOR_SET_THREAD_NAME
@@ -28,6 +29,10 @@
#define va_copy(dst, src) ((dst) = (src))
#endif // _WIN32
+#ifndef COMMON_INTERCEPTOR_INITIALIZE_RANGE
+# define COMMON_INTERCEPTOR_INITIALIZE_RANGE(ctx, p, size)
+#endif
+
#if SANITIZER_INTERCEPT_STRCMP
static inline int CharCmpX(unsigned char c1, unsigned char c2) {
return (c1 == c2) ? 0 : (c1 < c2) ? -1 : 1;
@@ -405,9 +410,12 @@ INTERCEPTOR(unsigned long, time, unsigne
#if SANITIZER_INTERCEPT_LOCALTIME_AND_FRIENDS
static void unpoison_tm(void *ctx, __sanitizer_tm *tm) {
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, tm, sizeof(*tm));
- if (tm->tm_zone)
- COMMON_INTERCEPTOR_WRITE_RANGE(ctx, tm->tm_zone,
- REAL(strlen(tm->tm_zone)) + 1);
+ if (tm->tm_zone) {
+ // Can not use COMMON_INTERCEPTOR_WRITE_RANGE here, because tm->tm_zone
+ // can point to shared memory and tsan would report a data race.
+ COMMON_INTERCEPTOR_INITIALIZE_RANGE(ctx, tm->tm_zone,
+ REAL(strlen(tm->tm_zone)) + 1);
+ }
}
INTERCEPTOR(__sanitizer_tm *, localtime, unsigned long *timep) {
More information about the llvm-commits
mailing list