diff options
author | Alexander Potapenko <glider@google.com> | 2012-01-27 15:15:04 +0000 |
---|---|---|
committer | Alexander Potapenko <glider@google.com> | 2012-01-27 15:15:04 +0000 |
commit | 6f0452914ec76c786eb865983793bc03b00fc7b6 (patch) | |
tree | c9436071c73edb5be08daf3dafc3734faeab984d /lib/asan | |
parent | c8365231004cb1d956aba4164c89ea1398eadd6b (diff) | |
download | compiler-rt-6f0452914ec76c786eb865983793bc03b00fc7b6.tar.gz compiler-rt-6f0452914ec76c786eb865983793bc03b00fc7b6.tar.bz2 compiler-rt-6f0452914ec76c786eb865983793bc03b00fc7b6.tar.xz |
Make compiler-rt/trunk/lib/asan compileable with Visual Studio 2008 on Windows.
Patch by Timur Iskhodzhanov (timurrrr@google.com)
To test:
$ cl /c *.c*
in the asan directory.
The code fails to link if you omit the "/c" part but that's one of the
next steps,
as well as a few TODO's I've put into the Windows-specific code.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@149130 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/asan')
-rw-r--r-- | lib/asan/asan_allocator.cc | 31 | ||||
-rw-r--r-- | lib/asan/asan_interceptors.cc | 19 | ||||
-rw-r--r-- | lib/asan/asan_interceptors.h | 5 | ||||
-rw-r--r-- | lib/asan/asan_interface.h | 5 | ||||
-rw-r--r-- | lib/asan/asan_internal.h | 33 | ||||
-rw-r--r-- | lib/asan/asan_printf.cc | 5 | ||||
-rw-r--r-- | lib/asan/asan_rtl.cc | 8 |
7 files changed, 100 insertions, 6 deletions
diff --git a/lib/asan/asan_allocator.cc b/lib/asan/asan_allocator.cc index 2ce859c4..35d83521 100644 --- a/lib/asan/asan_allocator.cc +++ b/lib/asan/asan_allocator.cc @@ -59,15 +59,44 @@ static inline bool IsAligned(uintptr_t a, uintptr_t alignment) { return (a & (alignment - 1)) == 0; } +#ifdef _WIN32 +#include <intrin.h> +#endif + static inline size_t Log2(size_t x) { CHECK(IsPowerOfTwo(x)); +#if defined(_WIN64) + unsigned long ret; // NOLINT + _BitScanForward64(&ret, x); + return ret; +#elif defined(_WIN32) + unsigned long ret; // NOLINT + _BitScanForward(&ret, x); + return ret; +#else return __builtin_ctzl(x); +#endif +} + +static inline size_t clz(size_t x) { +#if defined(_WIN64) + unsigned long ret; // NOLINT + _BitScanReverse64(&ret, x); + return ret; +#elif defined(_WIN32) + unsigned long ret; // NOLINT + _BitScanReverse(&ret, x); + return ret; +#else + return __builtin_clzl(x); +#endif } static inline size_t RoundUpToPowerOfTwo(size_t size) { CHECK(size); if (IsPowerOfTwo(size)) return size; - size_t up = __WORDSIZE - __builtin_clzl(size); + + size_t up = __WORDSIZE - clz(size); CHECK(size < (1ULL << up)); CHECK(size > (1ULL << (up - 1))); return 1UL << up; diff --git a/lib/asan/asan_interceptors.cc b/lib/asan/asan_interceptors.cc index 9695728c..227d3f50 100644 --- a/lib/asan/asan_interceptors.cc +++ b/lib/asan/asan_interceptors.cc @@ -24,9 +24,11 @@ #include <new> #include <ctype.h> -#include <dlfcn.h> +#ifndef _WIN32 +#include <dlfcn.h> #include <pthread.h> +#endif // To replace weak system functions on Linux we just need to declare functions // with same names in our library and then obtain the real function pointers @@ -41,7 +43,7 @@ // After interception, the calls to system functions will be substituted by // calls to our interceptors. We store pointers to system function f() // in __asan::real_f(). -#ifdef __APPLE__ +#if defined(__APPLE__) // Include the declarations of the original functions. #include <string.h> #include <strings.h> @@ -71,6 +73,17 @@ #define INTERCEPT_FUNCTION_IF_EXISTS(func) \ OVERRIDE_FUNCTION_IF_EXISTS(func, WRAP(func)) +#elif defined(_WIN32) +// TODO(timurrrr): change these macros once we decide how to intercept +// functions on Windows. +#define WRAPPER_NAME(x) #x + +#define INTERCEPT_FUNCTION(func) \ + do { } while (0) + +#define INTERCEPT_FUNCTION_IF_EXISTS(func) \ + do { } while (0) + #else // __linux__ #define WRAPPER_NAME(x) #x @@ -287,6 +300,7 @@ static void *asan_thread_start(void *arg) { return t->ThreadStart(); } +#ifndef _WIN32 extern "C" #ifndef __APPLE__ __attribute__((visibility("default"))) @@ -318,6 +332,7 @@ int WRAP(sigaction)(int signum, const void *act, void *oldact) { } return 0; } +#endif // _WIN32 static void UnpoisonStackFromHereToTop() { diff --git a/lib/asan/asan_interceptors.h b/lib/asan/asan_interceptors.h index 7f9e812e..483bb48e 100644 --- a/lib/asan/asan_interceptors.h +++ b/lib/asan/asan_interceptors.h @@ -16,7 +16,10 @@ #include "asan_internal.h" -#ifdef __APPLE__ +#if defined(__APPLE__) +# define WRAP(x) wrap_##x +#elif defined(_WIN32) +// TODO(timurrrr): we're likely to use something else later on Windows. # define WRAP(x) wrap_##x #else # define WRAP(x) x diff --git a/lib/asan/asan_interface.h b/lib/asan/asan_interface.h index 287916bd..3a613f60 100644 --- a/lib/asan/asan_interface.h +++ b/lib/asan/asan_interface.h @@ -15,7 +15,12 @@ #ifndef ASAN_INTERFACE_H #define ASAN_INTERFACE_H +#if !defined(_WIN32) #include <stdint.h> // for __WORDSIZE +#else +// The __attribute__ keyword is not understood by Visual Studio. +#define __attribute__(x) +#endif #include <stdlib.h> // for size_t // This header should NOT include any other headers from ASan runtime. diff --git a/lib/asan/asan_internal.h b/lib/asan/asan_internal.h index e361c26e..5be5186f 100644 --- a/lib/asan/asan_internal.h +++ b/lib/asan/asan_internal.h @@ -14,12 +14,35 @@ #ifndef ASAN_INTERNAL_H #define ASAN_INTERNAL_H -#if !defined(__linux__) && !defined(__APPLE__) +#if !defined(__linux__) && !defined(__APPLE__) && !defined(_WIN32) # error "This operating system is not supported by AddressSanitizer" #endif +#include <stdlib.h> // for size_t, uintptr_t, etc. + +#if !defined(_WIN32) #include <stdint.h> // for __WORDSIZE -#include <stdlib.h> // for size_t +#else +// 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; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; +typedef __int8 int8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; + +// Visual Studio does not define ssize_t. +#ifdef _WIN64 +typedef int64_t ssize_t; +#define __WORDSIZE 64 +#else +typedef int32_t ssize_t; +#define __WORDSIZE 32 +#endif + +#endif // _WIN32 // If __WORDSIZE was undefined by the platform, define it in terms of the // compiler built-in __LP64__. @@ -185,8 +208,14 @@ const size_t kWordSizeInBits = 8 * kWordSize; const size_t kPageSizeBits = 12; const size_t kPageSize = 1UL << kPageSizeBits; +#ifndef _WIN32 #define GET_CALLER_PC() (uintptr_t)__builtin_return_address(0) #define GET_CURRENT_FRAME() (uintptr_t)__builtin_frame_address(0) +#else +// TODO(timurrrr): implement. +#define GET_CALLER_PC() (uintptr_t)0 +#define GET_CURRENT_FRAME() (uintptr_t)0 +#endif #define GET_BP_PC_SP \ uintptr_t bp = GET_CURRENT_FRAME(); \ diff --git a/lib/asan/asan_printf.cc b/lib/asan/asan_printf.cc index c833d214..665256e1 100644 --- a/lib/asan/asan_printf.cc +++ b/lib/asan/asan_printf.cc @@ -180,11 +180,16 @@ void Report(const char *format, ...) { } int SScanf(const char *str, const char *format, ...) { +#ifndef _WIN32 va_list args; va_start(args, format); int res = vsscanf(str, format, args); va_end(args); return res; +#else + UNIMPLEMENTED(); + return -1; +#endif } } // namespace __asan diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc index 774cb25a..5a0da376 100644 --- a/lib/asan/asan_rtl.cc +++ b/lib/asan/asan_rtl.cc @@ -245,6 +245,14 @@ static void force_interface_symbols() { } // -------------------------- Init ------------------- {{{1 +#if defined(_WIN32) +// atoll is not defined on Windows. +int64_t atoll(const char *str) { + UNIMPLEMENTED(); + return -1; +} +#endif + static int64_t IntFlagValue(const char *flags, const char *flag, int64_t default_val) { if (!flags) return default_val; |