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 | 48a615fee78c3c262c60147a65dc6fff5fd6bb3b (patch) | |
tree | 0fd8434e7d0f2cab5d35de1655c352f9274d1de0 /lib/Transforms/Instrumentation/AddressSanitizer.cpp | |
parent | 70465616c29538e21e4dc3e0a70d8edb4b93bf5f (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173258 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Instrumentation/AddressSanitizer.cpp')
-rw-r--r-- | lib/Transforms/Instrumentation/AddressSanitizer.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 8b6d64d5ba..f4715f541a 100644 --- a/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/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( |