[llvm-commits] [compiler-rt] r157188 - in /compiler-rt/trunk/lib/asan: asan_allocator.cc asan_internal.h asan_win.cc

Timur Iskhodzhanov timurrrr at google.com
Mon May 21 07:25:36 PDT 2012


Author: timurrrr
Date: Mon May 21 09:25:36 2012
New Revision: 157188

URL: http://llvm.org/viewvc/llvm-project?rev=157188&view=rev
Log:
[ASan] Make for-Windows RTL compileable using Clang++

Modified:
    compiler-rt/trunk/lib/asan/asan_allocator.cc
    compiler-rt/trunk/lib/asan/asan_internal.h
    compiler-rt/trunk/lib/asan/asan_win.cc

Modified: compiler-rt/trunk/lib/asan/asan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.cc?rev=157188&r1=157187&r2=157188&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator.cc Mon May 21 09:25:36 2012
@@ -35,7 +35,7 @@
 #include "asan_thread.h"
 #include "asan_thread_registry.h"
 
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(__clang__)
 #include <intrin.h>
 #endif
 
@@ -64,16 +64,16 @@
 
 static inline size_t Log2(size_t x) {
   CHECK(IsPowerOfTwo(x));
-#if defined(_WIN64)
+#if !defined(_WIN32) || defined(__clang__)
+  return __builtin_ctzl(x);
+#elif defined(_WIN64)
   unsigned long ret;  // NOLINT
   _BitScanForward64(&ret, x);
   return ret;
-#elif defined(_WIN32)
+#else
   unsigned long ret;  // NOLINT
   _BitScanForward(&ret, x);
   return ret;
-#else
-  return __builtin_ctzl(x);
 #endif
 }
 
@@ -82,12 +82,12 @@
   if (IsPowerOfTwo(size)) return size;
 
   unsigned long up;  // NOLINT
-#if defined(_WIN64)
+#if !defined(_WIN32) || defined(__clang__)
+  up = __WORDSIZE - 1 - __builtin_clzl(size);
+#elif defined(_WIN64)
   _BitScanReverse64(&up, size);
-#elif defined(_WIN32)
-  _BitScanReverse(&up, size);
 #else
-  up = __WORDSIZE - 1 - __builtin_clzl(size);
+  _BitScanReverse(&up, size);
 #endif
   CHECK(size < (1ULL << (up + 1)));
   CHECK(size > (1ULL << up));

Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=157188&r1=157187&r2=157188&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Mon May 21 09:25:36 2012
@@ -21,6 +21,11 @@
 #include <stddef.h>  // for size_t, uintptr_t, etc.
 
 #if defined(_WIN32)
+# if defined(__clang__)
+typedef int              intptr_t;
+typedef unsigned int     uintptr_t;
+# endif
+
 // There's no <stdint.h> in Visual Studio 9, so we have to define [u]int*_t.
 typedef unsigned __int8  uint8_t;
 typedef unsigned __int16 uint16_t;
@@ -289,25 +294,29 @@
 const size_t kPageSizeBits = 12;
 const size_t kPageSize = 1UL << kPageSizeBits;
 
-#ifndef _WIN32
-const size_t kMmapGranularity = kPageSize;
+#if !defined(_WIN32) || defined(__clang__)
 # define GET_CALLER_PC() (uintptr_t)__builtin_return_address(0)
 # define GET_CURRENT_FRAME() (uintptr_t)__builtin_frame_address(0)
-# define THREAD_CALLING_CONV
-typedef void* thread_return_t;
 #else
-const size_t kMmapGranularity = 1UL << 16;
 # define GET_CALLER_PC() (uintptr_t)_ReturnAddress()
 // CaptureStackBackTrace doesn't need to know BP on Windows.
 // FIXME: This macro is still used when printing error reports though it's not
 // clear if the BP value is needed in the ASan reports on Windows.
 # define GET_CURRENT_FRAME() (uintptr_t)0xDEADBEEF
+#endif
+
+#ifndef _WIN32
+const size_t kMmapGranularity = kPageSize;
+# define THREAD_CALLING_CONV
+typedef void* thread_return_t;
+#else
+const size_t kMmapGranularity = 1UL << 16;
 # define THREAD_CALLING_CONV __stdcall
 typedef DWORD thread_return_t;
 
 # ifndef ASAN_USE_EXTERNAL_SYMBOLIZER
-#  define ASAN_USE_EXTERNAL_SYMBOLIZER __asan::WinSymbolize
-bool WinSymbolize(const void *addr, char *out_buffer, int buffer_size);
+#  define ASAN_USE_EXTERNAL_SYMBOLIZER __asan_WinSymbolize
+bool __asan_WinSymbolize(const void *addr, char *out_buffer, int buffer_size);
 # endif
 #endif
 

Modified: compiler-rt/trunk/lib/asan/asan_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win.cc?rev=157188&r1=157187&r2=157188&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_win.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_win.cc Mon May 21 09:25:36 2012
@@ -120,7 +120,7 @@
     trace[i] = (uintptr_t)tmp[i + offset];
 }
 
-bool WinSymbolize(const void *addr, char *out_buffer, int buffer_size) {
+bool __asan_WinSymbolize(const void *addr, char *out_buffer, int buffer_size) {
   ScopedLock lock(&dbghelp_lock);
   if (!dbghelp_initialized) {
     SymSetOptions(SYMOPT_DEFERRED_LOADS |
@@ -301,6 +301,7 @@
 
 void Abort() {
   abort();
+  _exit(-1);  // abort is not NORETURN on Windows.
 }
 
 int Atexit(void (*function)(void)) {





More information about the llvm-commits mailing list