[llvm-commits] [compiler-rt] r158261 - /compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc

Alexey Samsonov samsonov at google.com
Sat Jun 9 02:21:44 PDT 2012


Author: samsonov
Date: Sat Jun  9 04:21:44 2012
New Revision: 158261

URL: http://llvm.org/viewvc/llvm-project?rev=158261&view=rev
Log:
[Sanitizer] Use __libc_malloc/__libc_free instead of malloc/free inside internal allocator on Linux (important for TSan)

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc?rev=158261&r1=158260&r2=158261&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc Sat Jun  9 04:21:44 2012
@@ -15,14 +15,23 @@
 
 // FIXME: We should probably use more low-level allocator that would
 // mmap some pages and split them into chunks to fulfill requests.
-#include <stdlib.h>
+#ifdef __linux__
+extern "C" void *__libc_malloc(__sanitizer::uptr size);
+extern "C" void __libc_free(void *ptr);
+# define LIBC_MALLOC __libc_malloc
+# define LIBC_FREE __libc_free
+#else  // __linux__
+# include <stdlib.h>
+# define LIBC_MALLOC malloc
+# define LIBC_FREE free
+#endif  // __linux__
 
 namespace __sanitizer {
 
 static const u64 kInternalAllocBlockMagic = 0x7A6CB03ABCEBC042ull;
 
 void *InternalAlloc(uptr size) {
-  void *p = malloc(size + sizeof(u64));
+  void *p = LIBC_MALLOC(size + sizeof(u64));
   ((u64*)p)[0] = kInternalAllocBlockMagic;
   return (char*)p + sizeof(u64);
 }
@@ -32,7 +41,7 @@
   addr = (char*)addr - sizeof(u64);
   CHECK_EQ(((u64*)addr)[0], kInternalAllocBlockMagic);
   ((u64*)addr)[0] = 0;
-  free(addr);
+  LIBC_FREE(addr);
 }
 
 }  // namespace __sanitizer





More information about the llvm-commits mailing list