[asan/tsan] do not use __WORDSIZE macro, as it is glibc-private thing. Instead, define our own SANITIZER_WORDSIZE

llvm-svn: 168424
This commit is contained in:
Kostya Serebryany 2012-11-21 12:38:58 +00:00
parent aeed45cde0
commit 734f1eb5f4
16 changed files with 45 additions and 50 deletions

View File

@ -58,7 +58,7 @@ static const uptr kMallocSizeClassStepLog = 26;
static const uptr kMallocSizeClassStep = 1UL << kMallocSizeClassStepLog; static const uptr kMallocSizeClassStep = 1UL << kMallocSizeClassStepLog;
static const uptr kMaxAllowedMallocSize = static const uptr kMaxAllowedMallocSize =
(__WORDSIZE == 32) ? 3UL << 30 : 8UL << 30; (SANITIZER_WORDSIZE == 32) ? 3UL << 30 : 8UL << 30;
static inline bool IsAligned(uptr a, uptr alignment) { static inline bool IsAligned(uptr a, uptr alignment) {
return (a & (alignment - 1)) == 0; return (a & (alignment - 1)) == 0;
@ -85,7 +85,7 @@ static inline uptr RoundUpToPowerOfTwo(uptr size) {
unsigned long up; // NOLINT unsigned long up; // NOLINT
#if !defined(_WIN32) || defined(__clang__) #if !defined(_WIN32) || defined(__clang__)
up = __WORDSIZE - 1 - __builtin_clzl(size); up = SANITIZER_WORDSIZE - 1 - __builtin_clzl(size);
#elif defined(_WIN64) #elif defined(_WIN64)
_BitScanReverse64(&up, size); _BitScanReverse64(&up, size);
#else #else

View File

@ -42,7 +42,7 @@ namespace __asan {
void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) { void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
ucontext_t *ucontext = (ucontext_t*)context; ucontext_t *ucontext = (ucontext_t*)context;
# if __WORDSIZE == 64 # if SANITIZER_WORDSIZE == 64
*pc = ucontext->uc_mcontext->__ss.__rip; *pc = ucontext->uc_mcontext->__ss.__rip;
*bp = ucontext->uc_mcontext->__ss.__rbp; *bp = ucontext->uc_mcontext->__ss.__rbp;
*sp = ucontext->uc_mcontext->__ss.__rsp; *sp = ucontext->uc_mcontext->__ss.__rsp;
@ -50,7 +50,7 @@ void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
*pc = ucontext->uc_mcontext->__ss.__eip; *pc = ucontext->uc_mcontext->__ss.__eip;
*bp = ucontext->uc_mcontext->__ss.__ebp; *bp = ucontext->uc_mcontext->__ss.__ebp;
*sp = ucontext->uc_mcontext->__ss.__esp; *sp = ucontext->uc_mcontext->__ss.__esp;
# endif // __WORDSIZE # endif // SANITIZER_WORDSIZE
} }
int GetMacosVersion() { int GetMacosVersion() {
@ -179,7 +179,7 @@ void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp) {
// kHighMemBeg or kHighMemEnd. // kHighMemBeg or kHighMemEnd.
static void *island_allocator_pos = 0; static void *island_allocator_pos = 0;
#if __WORDSIZE == 32 #if SANITIZER_WORDSIZE == 32
# define kIslandEnd (0xffdf0000 - kPageSize) # define kIslandEnd (0xffdf0000 - kPageSize)
# define kIslandBeg (kIslandEnd - 256 * kPageSize) # define kIslandBeg (kIslandEnd - 256 * kPageSize)
#else #else

View File

@ -30,7 +30,7 @@ extern __attribute__((visibility("default"))) uptr __asan_mapping_offset;
# define SHADOW_OFFSET (0) # define SHADOW_OFFSET (0)
# else # else
# define SHADOW_SCALE (3) # define SHADOW_SCALE (3)
# if __WORDSIZE == 32 # if SANITIZER_WORDSIZE == 32
# define SHADOW_OFFSET (1 << 29) # define SHADOW_OFFSET (1 << 29)
# else # else
# if defined(__powerpc64__) # if defined(__powerpc64__)
@ -46,15 +46,15 @@ extern __attribute__((visibility("default"))) uptr __asan_mapping_offset;
#define MEM_TO_SHADOW(mem) (((mem) >> SHADOW_SCALE) | (SHADOW_OFFSET)) #define MEM_TO_SHADOW(mem) (((mem) >> SHADOW_SCALE) | (SHADOW_OFFSET))
#define SHADOW_TO_MEM(shadow) (((shadow) - SHADOW_OFFSET) << SHADOW_SCALE) #define SHADOW_TO_MEM(shadow) (((shadow) - SHADOW_OFFSET) << SHADOW_SCALE)
#if __WORDSIZE == 64 #if SANITIZER_WORDSIZE == 64
# if defined(__powerpc64__) # if defined(__powerpc64__)
static const uptr kHighMemEnd = 0x00000fffffffffffUL; static const uptr kHighMemEnd = 0x00000fffffffffffUL;
# else # else
static const uptr kHighMemEnd = 0x00007fffffffffffUL; static const uptr kHighMemEnd = 0x00007fffffffffffUL;
# endif # endif
#else // __WORDSIZE == 32 #else // SANITIZER_WORDSIZE == 32
static const uptr kHighMemEnd = 0xffffffff; static const uptr kHighMemEnd = 0xffffffff;
#endif // __WORDSIZE #endif // SANITIZER_WORDSIZE
#define kLowMemBeg 0 #define kLowMemBeg 0

View File

@ -44,7 +44,7 @@ void AppendToErrorMessageBuffer(const char *buffer) {
static void PrintBytes(const char *before, uptr *a) { static void PrintBytes(const char *before, uptr *a) {
u8 *bytes = (u8*)a; u8 *bytes = (u8*)a;
uptr byte_num = (__WORDSIZE) / 8; uptr byte_num = (SANITIZER_WORDSIZE) / 8;
Printf("%s%p:", before, (void*)a); Printf("%s%p:", before, (void*)a);
for (uptr i = 0; i < byte_num; i++) { for (uptr i = 0; i < byte_num; i++) {
Printf(" %x%x", bytes[i] >> 4, bytes[i] & 15); Printf(" %x%x", bytes[i] >> 4, bytes[i] & 15);

View File

@ -134,7 +134,7 @@ void InitializeFlags(Flags *f, const char *env) {
f->unmap_shadow_on_exit = false; f->unmap_shadow_on_exit = false;
f->abort_on_error = false; f->abort_on_error = false;
f->atexit = false; f->atexit = false;
f->disable_core = (__WORDSIZE == 64); f->disable_core = (SANITIZER_WORDSIZE == 64);
f->strip_path_prefix = ""; f->strip_path_prefix = "";
f->allow_reexec = true; f->allow_reexec = true;
f->print_full_thread_history = true; f->print_full_thread_history = true;

View File

@ -126,7 +126,7 @@ const char *AsanThread::GetFrameNameByAddr(uptr addr, uptr *offset) {
*offset = addr - bottom; *offset = addr - bottom;
return (const char *)((uptr*)bottom)[1]; return (const char *)((uptr*)bottom)[1];
} }
uptr aligned_addr = addr & ~(__WORDSIZE/8 - 1); // align addr. uptr aligned_addr = addr & ~(SANITIZER_WORDSIZE/8 - 1); // align addr.
u8 *shadow_ptr = (u8*)MemToShadow(aligned_addr); u8 *shadow_ptr = (u8*)MemToShadow(aligned_addr);
u8 *shadow_bottom = (u8*)MemToShadow(bottom); u8 *shadow_bottom = (u8*)MemToShadow(bottom);

View File

@ -118,7 +118,7 @@ TEST(AddressSanitizer, DISABLED_InternalPrintShadow) {
} }
static uptr pc_array[] = { static uptr pc_array[] = {
#if __WORDSIZE == 64 #if SANITIZER_WORDSIZE == 64
0x7effbf756068ULL, 0x7effbf756068ULL,
0x7effbf75e5abULL, 0x7effbf75e5abULL,
0x7effc0625b7cULL, 0x7effc0625b7cULL,
@ -164,7 +164,7 @@ static uptr pc_array[] = {
0x7effbcc3e726ULL, 0x7effbcc3e726ULL,
0x7effbcc40852ULL, 0x7effbcc40852ULL,
0x7effb681ec4dULL, 0x7effb681ec4dULL,
#endif // __WORDSIZE #endif // SANITIZER_WORDSIZE
0xB0B5E768, 0xB0B5E768,
0x7B682EC1, 0x7B682EC1,
0x367F9918, 0x367F9918,
@ -464,7 +464,7 @@ TEST(AddressSanitizerInterface, GetFreeBytesTest) {
// chunks to fulfill future requests. So, future requests will decrease // chunks to fulfill future requests. So, future requests will decrease
// the number of free bytes. Do this only on systems where there // the number of free bytes. Do this only on systems where there
// is enough memory for such assumptions. // is enough memory for such assumptions.
if (__WORDSIZE == 64 && !ASAN_LOW_MEMORY) { if (SANITIZER_WORDSIZE == 64 && !ASAN_LOW_MEMORY) {
static const size_t kNumOfChunks = 100; static const size_t kNumOfChunks = 100;
static const size_t kChunkSize = 100; static const size_t kChunkSize = 100;
char *chunks[kNumOfChunks]; char *chunks[kNumOfChunks];
@ -486,7 +486,8 @@ TEST(AddressSanitizerInterface, GetFreeBytesTest) {
static const size_t kManyThreadsMallocSizes[] = {5, 1UL<<10, 1UL<<20, 357}; static const size_t kManyThreadsMallocSizes[] = {5, 1UL<<10, 1UL<<20, 357};
static const size_t kManyThreadsIterations = 250; static const size_t kManyThreadsIterations = 250;
static const size_t kManyThreadsNumThreads = (__WORDSIZE == 32) ? 40 : 200; static const size_t kManyThreadsNumThreads =
(SANITIZER_WORDSIZE == 32) ? 40 : 200;
void *ManyThreadsWithStatsWorker(void *arg) { void *ManyThreadsWithStatsWorker(void *arg) {
(void)arg; (void)arg;
@ -693,7 +694,7 @@ TEST(AddressSanitizerInterface, GetOwnershipStressTest) {
std::vector<char *> pointers; std::vector<char *> pointers;
std::vector<size_t> sizes; std::vector<size_t> sizes;
const size_t kNumMallocs = const size_t kNumMallocs =
(__WORDSIZE <= 32 || ASAN_LOW_MEMORY) ? 1 << 10 : 1 << 14; (SANITIZER_WORDSIZE <= 32 || ASAN_LOW_MEMORY) ? 1 << 10 : 1 << 14;
for (size_t i = 0; i < kNumMallocs; i++) { for (size_t i = 0; i < kNumMallocs; i++) {
size_t size = i * 100 + 1; size_t size = i * 100 + 1;
pointers.push_back((char*)malloc(size)); pointers.push_back((char*)malloc(size));

View File

@ -344,7 +344,7 @@ TEST(AddressSanitizer, BitFieldNegativeTest) {
} }
TEST(AddressSanitizer, OutOfMemoryTest) { TEST(AddressSanitizer, OutOfMemoryTest) {
size_t size = __WORDSIZE == 64 ? (size_t)(1ULL << 48) : (0xf0000000); size_t size = SANITIZER_WORDSIZE == 64 ? (size_t)(1ULL << 48) : (0xf0000000);
EXPECT_EQ(0, realloc(0, size)); EXPECT_EQ(0, realloc(0, size));
EXPECT_EQ(0, realloc(0, ~Ident(0))); EXPECT_EQ(0, realloc(0, ~Ident(0)));
EXPECT_EQ(0, malloc(size)); EXPECT_EQ(0, malloc(size));
@ -448,9 +448,9 @@ TEST(AddressSanitizer, HugeMallocTest) {
// 32-bit Mac 10.7 gives even less (< 1G). // 32-bit Mac 10.7 gives even less (< 1G).
// (the libSystem malloc() allows allocating up to 2300 megabytes without // (the libSystem malloc() allows allocating up to 2300 megabytes without
// ASan). // ASan).
size_t n_megs = __WORDSIZE == 32 ? 500 : 4100; size_t n_megs = SANITIZER_WORDSIZE == 32 ? 500 : 4100;
#else #else
size_t n_megs = __WORDSIZE == 32 ? 2600 : 4100; size_t n_megs = SANITIZER_WORDSIZE == 32 ? 2600 : 4100;
#endif #endif
TestLargeMalloc(n_megs << 20); TestLargeMalloc(n_megs << 20);
} }
@ -479,7 +479,7 @@ void *ManyThreadsWorker(void *a) {
} }
TEST(AddressSanitizer, ManyThreadsTest) { TEST(AddressSanitizer, ManyThreadsTest) {
const size_t kNumThreads = __WORDSIZE == 32 ? 30 : 1000; const size_t kNumThreads = SANITIZER_WORDSIZE == 32 ? 30 : 1000;
pthread_t t[kNumThreads]; pthread_t t[kNumThreads];
for (size_t i = 0; i < kNumThreads; i++) { for (size_t i = 0; i < kNumThreads; i++) {
pthread_create(&t[i], 0, (void* (*)(void *x))ManyThreadsWorker, (void*)i); pthread_create(&t[i], 0, (void* (*)(void *x))ManyThreadsWorker, (void*)i);
@ -710,7 +710,7 @@ NOINLINE void ThrowFunc() {
TEST(AddressSanitizer, CxxExceptionTest) { TEST(AddressSanitizer, CxxExceptionTest) {
if (ASAN_UAR) return; if (ASAN_UAR) return;
// TODO(kcc): this test crashes on 32-bit for some reason... // TODO(kcc): this test crashes on 32-bit for some reason...
if (__WORDSIZE == 32) return; if (SANITIZER_WORDSIZE == 32) return;
try { try {
ThrowFunc(); ThrowFunc();
} catch(...) {} } catch(...) {}
@ -1632,7 +1632,7 @@ TEST(AddressSanitizer, ThreadedTest) {
#if ASAN_NEEDS_SEGV #if ASAN_NEEDS_SEGV
TEST(AddressSanitizer, ShadowGapTest) { TEST(AddressSanitizer, ShadowGapTest) {
#if __WORDSIZE == 32 #if SANITIZER_WORDSIZE == 32
char *addr = (char*)0x22000000; char *addr = (char*)0x22000000;
#else #else
char *addr = (char*)0x0000100000080000; char *addr = (char*)0x0000100000080000;
@ -1897,7 +1897,7 @@ TEST(AddressSanitizer, DISABLED_DemoOOBRightHigh) {
} }
TEST(AddressSanitizer, DISABLED_DemoOOM) { TEST(AddressSanitizer, DISABLED_DemoOOM) {
size_t size = __WORDSIZE == 64 ? (size_t)(1ULL << 40) : (0xf0000000); size_t size = SANITIZER_WORDSIZE == 64 ? (size_t)(1ULL << 40) : (0xf0000000);
printf("%p\n", malloc(size)); printf("%p\n", malloc(size));
} }

View File

@ -47,12 +47,10 @@ typedef __int64 int64_t;
# define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
#endif #endif
#ifndef __WORDSIZE
#if __LP64__ || defined(_WIN64) #if __LP64__ || defined(_WIN64)
#define __WORDSIZE 64 # define SANITIZER_WORDSIZE 64
#else #else
#define __WORDSIZE 32 # define SANITIZER_WORDSIZE 32
#endif
#endif #endif
// Make the compiler think that something is going on there. // Make the compiler think that something is going on there.

View File

@ -18,7 +18,7 @@
#define SANITIZER_ALLOCATOR_H #define SANITIZER_ALLOCATOR_H
#include "sanitizer_internal_defs.h" #include "sanitizer_internal_defs.h"
#if __WORDSIZE != 64 #if SANITIZER_WORDSIZE != 64
# error "sanitizer_allocator64.h can only be used on 64-bit platforms" # error "sanitizer_allocator64.h can only be used on 64-bit platforms"
#endif #endif

View File

@ -21,7 +21,7 @@
namespace __sanitizer { namespace __sanitizer {
// Constants. // Constants.
const uptr kWordSize = __WORDSIZE / 8; const uptr kWordSize = SANITIZER_WORDSIZE / 8;
const uptr kWordSizeInBits = 8 * kWordSize; const uptr kWordSizeInBits = 8 * kWordSize;
#if defined(__powerpc__) || defined(__powerpc64__) #if defined(__powerpc__) || defined(__powerpc64__)
// Current PPC64 kernels use 64K pages sizes, but they can be // Current PPC64 kernels use 64K pages sizes, but they can be
@ -187,7 +187,7 @@ INLINE int ToLower(int c) {
return (c >= 'A' && c <= 'Z') ? (c + 'a' - 'A') : c; return (c >= 'A' && c <= 'Z') ? (c + 'a' - 'A') : c;
} }
#if __WORDSIZE == 64 #if SANITIZER_WORDSIZE == 64
# define FIRST_32_SECOND_64(a, b) (b) # define FIRST_32_SECOND_64(a, b) (b)
#else #else
# define FIRST_32_SECOND_64(a, b) (a) # define FIRST_32_SECOND_64(a, b) (a)

View File

@ -63,15 +63,11 @@ typedef void* thread_return_t;
#endif // _WIN32 #endif // _WIN32
typedef thread_return_t (THREAD_CALLING_CONV *thread_callback_t)(void* arg); typedef thread_return_t (THREAD_CALLING_CONV *thread_callback_t)(void* arg);
// If __WORDSIZE was undefined by the platform, define it in terms of the #if __LP64__ || defined(_WIN64)
// compiler built-ins __LP64__ and _WIN64. # define SANITIZER_WORDSIZE 64
#ifndef __WORDSIZE #else
# if __LP64__ || defined(_WIN64) # define SANITIZER_WORDSIZE 32
# define __WORDSIZE 64 #endif
# else
# define __WORDSIZE 32
# endif
#endif // __WORDSIZE
// NOTE: Functions below must be defined in each run-time. // NOTE: Functions below must be defined in each run-time.
namespace __sanitizer { namespace __sanitizer {
@ -145,13 +141,13 @@ void NORETURN CheckFailed(const char *file, int line, const char *cond,
// have stdint.h (like in Visual Studio 9). // have stdint.h (like in Visual Studio 9).
#undef __INT64_C #undef __INT64_C
#undef __UINT64_C #undef __UINT64_C
#if __WORDSIZE == 64 #if SANITIZER_WORDSIZE == 64
# define __INT64_C(c) c ## L # define __INT64_C(c) c ## L
# define __UINT64_C(c) c ## UL # define __UINT64_C(c) c ## UL
#else #else
# define __INT64_C(c) c ## LL # define __INT64_C(c) c ## LL
# define __UINT64_C(c) c ## ULL # define __UINT64_C(c) c ## ULL
#endif // __WORDSIZE == 64 #endif // SANITIZER_WORDSIZE == 64
#undef INT32_MIN #undef INT32_MIN
#define INT32_MIN (-2147483647-1) #define INT32_MIN (-2147483647-1)
#undef INT32_MAX #undef INT32_MAX

View File

@ -32,9 +32,9 @@
#include <errno.h> #include <errno.h>
// Are we using 32-bit or 64-bit syscalls? // Are we using 32-bit or 64-bit syscalls?
// x32 (which defines __x86_64__) has __WORDSIZE == 32 // x32 (which defines __x86_64__) has SANITIZER_WORDSIZE == 32
// but it still needs to use 64-bit syscalls. // but it still needs to use 64-bit syscalls.
#if defined(__x86_64__) || __WORDSIZE == 64 #if defined(__x86_64__) || SANITIZER_WORDSIZE == 64
# define SANITIZER_LINUX_USES_64BIT_SYSCALLS 1 # define SANITIZER_LINUX_USES_64BIT_SYSCALLS 1
#else #else
# define SANITIZER_LINUX_USES_64BIT_SYSCALLS 0 # define SANITIZER_LINUX_USES_64BIT_SYSCALLS 0

View File

@ -19,7 +19,7 @@
#include "sanitizer_internal_defs.h" #include "sanitizer_internal_defs.h"
namespace __sanitizer { namespace __sanitizer {
#if (__WORDSIZE == 64) || defined(__APPLE__) #if (SANITIZER_WORDSIZE == 64) || defined(__APPLE__)
typedef uptr operator_new_ptr_type; typedef uptr operator_new_ptr_type;
#else #else
typedef u32 operator_new_ptr_type; typedef u32 operator_new_ptr_type;

View File

@ -87,7 +87,7 @@ static int AppendPointer(char **buff, const char *buff_end, u64 ptr_value) {
int result = 0; int result = 0;
result += AppendString(buff, buff_end, "0x"); result += AppendString(buff, buff_end, "0x");
result += AppendUnsigned(buff, buff_end, ptr_value, 16, result += AppendUnsigned(buff, buff_end, ptr_value, 16,
(__WORDSIZE == 64) ? 12 : 8); (SANITIZER_WORDSIZE == 64) ? 12 : 8);
return result; return result;
} }

View File

@ -156,7 +156,7 @@ void StackTrace::PopStackFrames(uptr count) {
// the previous one, we record a 31-bit offset instead of the full pc. // the previous one, we record a 31-bit offset instead of the full pc.
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
uptr StackTrace::CompressStack(StackTrace *stack, u32 *compressed, uptr size) { uptr StackTrace::CompressStack(StackTrace *stack, u32 *compressed, uptr size) {
#if __WORDSIZE == 32 #if SANITIZER_WORDSIZE == 32
// Don't compress, just copy. // Don't compress, just copy.
uptr res = 0; uptr res = 0;
for (uptr i = 0; i < stack->size && i < size; i++) { for (uptr i = 0; i < stack->size && i < size; i++) {
@ -197,7 +197,7 @@ uptr StackTrace::CompressStack(StackTrace *stack, u32 *compressed, uptr size) {
compressed[c_index] = 0; compressed[c_index] = 0;
if (c_index + 1 < size) if (c_index + 1 < size)
compressed[c_index + 1] = 0; compressed[c_index + 1] = 0;
#endif // __WORDSIZE #endif // SANITIZER_WORDSIZE
// debug-only code // debug-only code
#if 0 #if 0
@ -220,7 +220,7 @@ uptr StackTrace::CompressStack(StackTrace *stack, u32 *compressed, uptr size) {
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
void StackTrace::UncompressStack(StackTrace *stack, void StackTrace::UncompressStack(StackTrace *stack,
u32 *compressed, uptr size) { u32 *compressed, uptr size) {
#if __WORDSIZE == 32 #if SANITIZER_WORDSIZE == 32
// Don't uncompress, just copy. // Don't uncompress, just copy.
stack->size = 0; stack->size = 0;
for (uptr i = 0; i < size && i < kStackTraceMax; i++) { for (uptr i = 0; i < size && i < kStackTraceMax; i++) {
@ -255,7 +255,7 @@ void StackTrace::UncompressStack(StackTrace *stack,
stack->trace[stack->size++] = pc; stack->trace[stack->size++] = pc;
prev_pc = pc; prev_pc = pc;
} }
#endif // __WORDSIZE #endif // SANITIZER_WORDSIZE
} }
} // namespace __sanitizer } // namespace __sanitizer