[llvm-commits] [ASan] Make for-Windows RTL compileable using Clang++ (issue 6214063)
timurrrr at google.com
timurrrr at google.com
Mon May 21 06:56:12 PDT 2012
Reviewers: kcc1,
Message:
Hi Kostya,
Can you please review this small patch?
Please note it might not be compileable with the upstream trunk version
but works fine for me when compiled with a slightly patches Clang [the
patches pending review & cleanup].
--
Timur
Description:
Make ASan/RTL compileable using Clang++ on Windows
Please review this at http://codereview.appspot.com/6214063/
Affected files:
M lib/asan/asan_allocator.cc
M lib/asan/asan_internal.h
M lib/asan/asan_win.cc
Index: lib/asan/asan_allocator.cc
diff --git a/lib/asan/asan_allocator.cc b/lib/asan/asan_allocator.cc
index
59d66263a8470d29c67ce121c673bbbe44e65d87..2c31c852e5aedc6233909eb97e9d12ecbe1389f9
100644
--- a/lib/asan/asan_allocator.cc
+++ b/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 <intrin.h>
#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));
Index: lib/asan/asan_internal.h
diff --git a/lib/asan/asan_internal.h b/lib/asan/asan_internal.h
index
df1814cf3b2410d423c70b8280a94f4535921a56..4478cdfd564b0ee1f9e6fe76ab0c0026b8c98bd8
100644
--- a/lib/asan/asan_internal.h
+++ b/lib/asan/asan_internal.h
@@ -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 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
Index: lib/asan/asan_win.cc
diff --git a/lib/asan/asan_win.cc b/lib/asan/asan_win.cc
index
523f90df1f4b53df4efdd8518b14ec598b553f14..801fee5adbb7bc1a3dd2ceace8698e98838874bd
100644
--- a/lib/asan/asan_win.cc
+++ b/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)) {
More information about the llvm-commits
mailing list