diff options
author | Kostya Serebryany <kcc@google.com> | 2013-01-23 12:54:55 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2013-01-23 12:54:55 +0000 |
commit | 4766fe6f10ba99add6f8237c49072a4a766beeff (patch) | |
tree | d7c20de0412433b1a6649b139f2bff745126242d /llvm/lib/Transforms | |
parent | 43b6548ce0d89c81dcd6f9cab93963daebaf7dba (diff) | |
download | bcm5719-llvm-4766fe6f10ba99add6f8237c49072a4a766beeff.tar.gz bcm5719-llvm-4766fe6f10ba99add6f8237c49072a4a766beeff.zip |
[asan] use ADD instead of OR when applying shadow offset of PowerPC. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55975 for details
llvm-svn: 173258
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 8b6d64d5ba0..f4715f541a3 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -53,6 +53,7 @@ using namespace llvm; static const uint64_t kDefaultShadowScale = 3; static const uint64_t kDefaultShadowOffset32 = 1ULL << 29; static const uint64_t kDefaultShadowOffset64 = 1ULL << 44; +static const uint64_t kPPC64_ShadowOffset64 = 1ULL << 41; static const size_t kMaxStackMallocSize = 1 << 16; // 64K static const uintptr_t kCurrentStackFrameMagic = 0x41B58AB3; @@ -186,21 +187,29 @@ class SetOfDynamicallyInitializedGlobals { }; /// This struct defines the shadow mapping using the rule: -/// shadow = (mem >> Scale) + Offset. +/// shadow = (mem >> Scale) ADD-or-OR Offset. struct ShadowMapping { int Scale; uint64_t Offset; + bool OrShadowOffset; }; static ShadowMapping getShadowMapping(const Module &M, int LongSize, bool ZeroBaseShadow) { llvm::Triple TargetTriple(M.getTargetTriple()); bool IsAndroid = TargetTriple.getEnvironment() == llvm::Triple::Android; + bool IsPPC64 = TargetTriple.getArch() == llvm::Triple::ppc64; ShadowMapping Mapping; + // OR-ing shadow offset if more efficient (at least on x86), + // but on ppc64 we have to use add since the shadow offset is not neccesary + // 1/8-th of the address space. + Mapping.OrShadowOffset = !IsPPC64; + Mapping.Offset = (IsAndroid || ZeroBaseShadow) ? 0 : - (LongSize == 32 ? kDefaultShadowOffset32 : kDefaultShadowOffset64); + (LongSize == 32 ? kDefaultShadowOffset32 : + IsPPC64 ? kPPC64_ShadowOffset64 : kDefaultShadowOffset64); if (ClMappingOffsetLog >= 0) { // Zero offset log is the special case. Mapping.Offset = (ClMappingOffsetLog == 0) ? 0 : 1ULL << ClMappingOffsetLog; @@ -520,8 +529,10 @@ Value *AddressSanitizer::memToShadow(Value *Shadow, IRBuilder<> &IRB) { if (Mapping.Offset == 0) return Shadow; // (Shadow >> scale) | offset - return IRB.CreateOr(Shadow, ConstantInt::get(IntptrTy, - Mapping.Offset)); + if (Mapping.OrShadowOffset) + return IRB.CreateOr(Shadow, ConstantInt::get(IntptrTy, Mapping.Offset)); + else + return IRB.CreateAdd(Shadow, ConstantInt::get(IntptrTy, Mapping.Offset)); } void AddressSanitizer::instrumentMemIntrinsicParam( |