From ea365131a2ff539ab8b052f299b85375b22e522f Mon Sep 17 00:00:00 2001 From: Timur Iskhodzhanov Date: Mon, 21 May 2012 14:25:36 +0000 Subject: [PATCH] [ASan] Make for-Windows RTL compileable using Clang++ llvm-svn: 157188 --- compiler-rt/lib/asan/asan_allocator.cc | 18 +++++++++--------- compiler-rt/lib/asan/asan_internal.h | 23 ++++++++++++++++------- compiler-rt/lib/asan/asan_win.cc | 3 ++- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/compiler-rt/lib/asan/asan_allocator.cc b/compiler-rt/lib/asan/asan_allocator.cc index 59d66263a847..2c31c852e5ae 100644 --- a/compiler-rt/lib/asan/asan_allocator.cc +++ b/compiler-rt/lib/asan/asan_allocator.cc @@ -35,7 +35,7 @@ #include "asan_thread.h" #include "asan_thread_registry.h" -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__clang__) #include #endif @@ -64,16 +64,16 @@ static inline bool IsAligned(uintptr_t a, uintptr_t alignment) { 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 @@ static inline size_t RoundUpToPowerOfTwo(size_t size) { 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)); diff --git a/compiler-rt/lib/asan/asan_internal.h b/compiler-rt/lib/asan/asan_internal.h index df1814cf3b24..4478cdfd564b 100644 --- a/compiler-rt/lib/asan/asan_internal.h +++ b/compiler-rt/lib/asan/asan_internal.h @@ -21,6 +21,11 @@ #include // 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 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 kWordSizeInBits = 8 * kWordSize; 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 diff --git a/compiler-rt/lib/asan/asan_win.cc b/compiler-rt/lib/asan/asan_win.cc index 523f90df1f4b..801fee5adbb7 100644 --- a/compiler-rt/lib/asan/asan_win.cc +++ b/compiler-rt/lib/asan/asan_win.cc @@ -120,7 +120,7 @@ void AsanStackTrace::GetStackTrace(size_t max_s, uintptr_t pc, uintptr_t bp) { 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 Exit(int exitcode) { void Abort() { abort(); + _exit(-1); // abort is not NORETURN on Windows. } int Atexit(void (*function)(void)) { -- GitLab