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. llvm-svn: 149130
This commit is contained in:
parent
13d95d5e5a
commit
f519564d7c
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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(); \
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue