From 8b0f2fff6e080c053e4fd94d44a694768b8c156e Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 5 Aug 2015 05:35:26 -0700 Subject: [PATCH 78/84] Apply split-layout-llvm.patch https://llvm.org/bugs/show_bug.cgi?id=24155 --- lib/Transforms/Instrumentation/MemorySanitizer.cpp | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp index 286a563..2ab8bfc 100644 --- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -194,6 +194,12 @@ static cl::opt ClCheckConstantShadow("msan-check-constant-shadow", static const char *const kMsanModuleCtorName = "msan.module_ctor"; static const char *const kMsanInitName = "__msan_init"; +static cl::opt ClSplitLayout( + "msan-split-layout", cl::desc( + "use experimental memory layout compatible with " + "non-pie and non-aslr execution"), + cl::Hidden, cl::init(true)); + namespace { // Memory map parameters used in application-to-shadow address calculation. @@ -228,6 +234,13 @@ static const MemoryMapParams Linux_X86_64_MemoryMapParams = { 0x200000000000, // OriginBase }; +static const MemoryMapParams Linux_X86_64_Split_MemoryMapParams = { + 0, // AndMask (not used) + 0x500000000000, // XorMask + 0, // ShadowBase (not used) + 0x100000000000, // OriginBase +}; + // mips64 Linux static const MemoryMapParams Linux_MIPS64_MemoryMapParams = { 0x004000000000, // AndMask @@ -483,7 +496,8 @@ bool MemorySanitizer::doInitialization(Module &M) { case Triple::Linux: switch (TargetTriple.getArch()) { case Triple::x86_64: - MapParams = Linux_X86_MemoryMapParams.bits64; + MapParams = ClSplitLayout ? &Linux_X86_64_Split_MemoryMapParams + : Linux_X86_MemoryMapParams.bits64; break; case Triple::x86: MapParams = Linux_X86_MemoryMapParams.bits32; @@ -893,16 +907,17 @@ struct MemorySanitizerVisitor : public InstVisitor { /// /// Offset = (Addr & ~AndMask) ^ XorMask Value *getShadowPtrOffset(Value *Addr, IRBuilder<> &IRB) { + Value *OffsetLong = IRB.CreatePointerCast(Addr, MS.IntptrTy); + uint64_t AndMask = MS.MapParams->AndMask; - assert(AndMask != 0 && "AndMask shall be specified"); - Value *OffsetLong = - IRB.CreateAnd(IRB.CreatePointerCast(Addr, MS.IntptrTy), - ConstantInt::get(MS.IntptrTy, ~AndMask)); + if (AndMask) + OffsetLong = + IRB.CreateAnd(OffsetLong, ConstantInt::get(MS.IntptrTy, ~AndMask)); uint64_t XorMask = MS.MapParams->XorMask; - if (XorMask != 0) - OffsetLong = IRB.CreateXor(OffsetLong, - ConstantInt::get(MS.IntptrTy, XorMask)); + if (XorMask) + OffsetLong = + IRB.CreateXor(OffsetLong, ConstantInt::get(MS.IntptrTy, XorMask)); return OffsetLong; } -- 2.6.4