[compiler-rt] r276107 - tsan: fix windows build

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 20 04:43:54 PDT 2016


Author: dvyukov
Date: Wed Jul 20 06:43:52 2016
New Revision: 276107

URL: http://llvm.org/viewvc/llvm-project?rev=276107&view=rev
Log:
tsan: fix windows build

Currently fails as:

gotsan.cc: In function 'void* __sanitizer::__libc_memalign(__sanitizer::uptr, __sanitizer::uptr)':
gotsan.cc:6194:50: error: 'posix_memalign' was not declared in this scope
   uptr error = posix_memalign(&p, alignment, size);

Windows does not provide posix_memalign.


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=276107&r1=276106&r2=276107&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc Wed Jul 20 06:43:52 2016
@@ -22,18 +22,22 @@ namespace __sanitizer {
 #if defined(SANITIZER_GO) || defined(SANITIZER_USE_MALLOC)
 # if SANITIZER_LINUX && !SANITIZER_ANDROID
 extern "C" void *__libc_malloc(uptr size);
+#  ifndef SANITIZER_GO
 extern "C" void *__libc_memalign(uptr alignment, uptr size);
+#  endif
 extern "C" void *__libc_realloc(void *ptr, uptr size);
 extern "C" void __libc_free(void *ptr);
 # else
 #  include <stdlib.h>
 #  define __libc_malloc malloc
+#  ifndef SANITIZER_GO
 static void *__libc_memalign(uptr alignment, uptr size) {
   void *p;
   uptr error = posix_memalign(&p, alignment, size);
   if (error) return nullptr;
   return p;
 }
+#  endif
 #  define __libc_realloc realloc
 #  define __libc_free free
 # endif
@@ -41,10 +45,20 @@ static void *__libc_memalign(uptr alignm
 static void *RawInternalAlloc(uptr size, InternalAllocatorCache *cache,
                               uptr alignment) {
   (void)cache;
+#ifndef SANITIZER_GO
   if (alignment == 0)
     return __libc_malloc(size);
   else
     return __libc_memalign(alignment, size);
+#else
+  // Windows does not provide __libc_memalign/posix_memalign. It provides
+  // __aligned_malloc, but the allocated blocks can't be passed to free,
+  // they need to be passed to __aligned_free. InternalAlloc interface does
+  // not account for such requirement. Alignemnt does not seem to be used
+  // anywhere in runtime, so just call __libc_malloc for now.
+  DCHECK_EQ(alignment, 0);
+  return __libc_malloc(size);
+#endif
 }
 
 static void *RawInternalRealloc(void *ptr, uptr size,




More information about the llvm-commits mailing list