[compiler-rt] r252162 - [tsan] Fix the memcpy interceptor to be memmove compatible on OS X

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 5 06:03:26 PST 2015


Author: kuba.brecka
Date: Thu Nov  5 08:03:26 2015
New Revision: 252162

URL: http://llvm.org/viewvc/llvm-project?rev=252162&view=rev
Log:
[tsan] Fix the memcpy interceptor to be memmove compatible on OS X

On OS X, memcpy and memmove are actually aliases of the same implementation, which means the interceptor of memcpy is also invoked when memmove is called. The current implementation of the interceptor uses `internal_memcpy` to perform the actual memory operation, which can produce an incorrect result when memmove semantics are expected. Let's call `internal_memmove` instead.

Differential Revision: http://reviews.llvm.org/D14336


Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=252162&r1=252161&r2=252162&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Thu Nov  5 08:03:26 2015
@@ -626,7 +626,10 @@ TSAN_INTERCEPTOR(void*, memcpy, void *ds
     MemoryAccessRange(thr, pc, (uptr)dst, size, true);
     MemoryAccessRange(thr, pc, (uptr)src, size, false);
   }
-  return internal_memcpy(dst, src, size);
+  // On OS X, calling internal_memcpy here will cause memory corruptions,
+  // because memcpy and memmove are actually aliases of the same implementation.
+  // We need to use internal_memmove here.
+  return internal_memmove(dst, src, size);
 }
 
 TSAN_INTERCEPTOR(void*, memmove, void *dst, void *src, uptr n) {




More information about the llvm-commits mailing list