AddressSanitizer: Replace __attribute__ with macro (for Win compatibility). Patch by timurrrr@google.com
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@149686 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/asan/asan_interceptors.cc b/lib/asan/asan_interceptors.cc
index d5476b5..2cf290f 100644
--- a/lib/asan/asan_interceptors.cc
+++ b/lib/asan/asan_interceptors.cc
@@ -94,8 +94,7 @@
// Instruments read/write access to a single byte in memory.
// On error calls __asan_report_error, which aborts the program.
-__attribute__((noinline))
-static void AccessAddress(uintptr_t address, bool isWrite) {
+static NOINLINE void AccessAddress(uintptr_t address, bool isWrite) {
if (__asan_address_is_poisoned((void*)address)) {
GET_BP_PC_SP;
__asan_report_error(pc, bp, sp, address, isWrite, /* access_size */ 1);
@@ -433,9 +432,9 @@
return result;
}
-#ifndef __APPLE__
+#ifdef __linux__
INTERCEPTOR(void*, index, const char *string, int c)
- __attribute__((alias(WRAPPER_NAME(strchr))));
+ ALIAS(WRAPPER_NAME(strchr));
#else
DEFINE_REAL(void*, index, const char *string, int c);
#endif
diff --git a/lib/asan/asan_internal.h b/lib/asan/asan_internal.h
index 65c825e..713f17c 100644
--- a/lib/asan/asan_internal.h
+++ b/lib/asan/asan_internal.h
@@ -30,9 +30,21 @@
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef __int64 int64_t;
-#else
+
+# define ALIAS(x) // TODO(timurrrr): do we need this on Windows?
+# define ALIGNED(x) __declspec(align(x))
+# define NOINLINE __declspec(noinline)
+
+# define ASAN_INTERFACE_ATTRIBUTE // TODO(timurrrr): do we need this on Win?
+#else // defined(_WIN32)
# include <stdint.h> // for __WORDSIZE
-#endif // _WIN32
+
+# define ALIAS(x) __attribute__((alias(x)))
+# define ALIGNED(x) __attribute__((aligned(x)))
+# define NOINLINE __attribute__((noinline))
+
+# define ASAN_INTERFACE_ATTRIBUTE __attribute__((visibility("default")))
+#endif // defined(_WIN32)
// If __WORDSIZE was undefined by the platform, define it in terms of the
// compiler built-ins __LP64__ and _WIN64.
diff --git a/lib/asan/asan_malloc_linux.cc b/lib/asan/asan_malloc_linux.cc
index 4547041..faa3dfb 100644
--- a/lib/asan/asan_malloc_linux.cc
+++ b/lib/asan/asan_malloc_linux.cc
@@ -31,7 +31,7 @@
void* (*memalign)(size_t alignment, size_t bytes);
};
-const MallocDebug asan_malloc_dispatch __attribute__((aligned(32))) = {
+const MallocDebug asan_malloc_dispatch ALIGNED(32) = {
malloc, free, calloc, realloc, memalign
};
@@ -96,7 +96,7 @@
}
INTERCEPTOR(void*, __libc_memalign, size_t align, size_t s)
- __attribute__((alias("memalign")));
+ ALIAS("memalign");
INTERCEPTOR(size_t, malloc_usable_size, void *ptr) {
GET_STACK_TRACE_HERE_FOR_MALLOC;
diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc
index b40bc41..333b516 100644
--- a/lib/asan/asan_rtl.cc
+++ b/lib/asan/asan_rtl.cc
@@ -187,8 +187,7 @@
return true;
}
-__attribute__((noinline))
-static void DescribeAddress(uintptr_t addr, uintptr_t access_size) {
+static NOINLINE void DescribeAddress(uintptr_t addr, uintptr_t access_size) {
// Check if this is a global.
if (DescribeAddrIfGlobal(addr))
return;
@@ -203,8 +202,8 @@
// -------------------------- Run-time entry ------------------- {{{1
// exported functions
#define ASAN_REPORT_ERROR(type, is_write, size) \
-extern "C" void __asan_report_ ## type ## size(uintptr_t addr) \
- __attribute__((visibility("default"))) __attribute__((noinline)); \
+NOINLINE ASAN_INTERFACE_ATTRIBUTE \
+extern "C" void __asan_report_ ## type ## size(uintptr_t addr); \
extern "C" void __asan_report_ ## type ## size(uintptr_t addr) { \
GET_BP_PC_SP; \
__asan_report_error(pc, bp, sp, addr, is_write, size); \