[PATCH] D23801: [EfficiencySanitizer] Adds shadow memory parameters for 40-bit virtual memory address.

Sagar Thakur via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 23 06:18:11 PDT 2016


slthakur created this revision.
slthakur added reviewers: aizatsky, bruening.
slthakur added subscribers: jaydeep, mohit.bhakkad, llvm-commits.
slthakur set the repository for this revision to rL LLVM.
slthakur added a project: Sanitizers.

Adding 40-bit shadow memory parameters because MIPS64 uses 40-bit virtual memory addresses.

Repository:
  rL LLVM

https://reviews.llvm.org/D23801

Files:
  lib/Transforms/Instrumentation/EfficiencySanitizer.cpp

Index: lib/Transforms/Instrumentation/EfficiencySanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/EfficiencySanitizer.cpp
+++ lib/Transforms/Instrumentation/EfficiencySanitizer.cpp
@@ -99,12 +99,26 @@
 // FIXME: Try to place these shadow constants, the names of the __esan_*
 // interface functions, and the ToolType enum into a header shared between
 // llvm and compiler-rt.
-static const uint64_t ShadowMask = 0x00000fffffffffffull;
-static const uint64_t ShadowOffs[3] = { // Indexed by scale
+struct ShadowMemoryParams
+{
+  uint64_t ShadowMask;
+  uint64_t ShadowOffs[3];
+} ShadowParams;
+
+static const ShadowMemoryParams ShadowParams48 = { 
+  0x00000fffffffffffull,
   0x0000130000000000ull,
   0x0000220000000000ull,
   0x0000440000000000ull,
 };
+
+static const ShadowMemoryParams ShadowParams40 = { 
+  0x0fffffffffull,
+  0x1300000000ull,
+  0x2200000000ull,
+  0x4400000000ull,
+};
+
 // This array is indexed by the ToolType enum.
 static const int ShadowScale[] = {
   0, // ESAN_None.
@@ -528,6 +542,20 @@
 }
 
 bool EfficiencySanitizer::initOnModule(Module &M) {
+
+  Triple TargetTriple(M.getTargetTriple());
+  switch (TargetTriple.getArch()) {
+    case Triple::x86_64:
+      ShadowParams = ShadowParams48;
+      break;
+    case Triple::mips64:
+    case Triple::mips64el:
+      ShadowParams = ShadowParams40;
+      break;
+    default:
+      report_fatal_error("unsupported architecture");
+  }
+
   Ctx = &M.getContext();
   const DataLayout &DL = M.getDataLayout();
   IRBuilder<> IRB(M.getContext());
@@ -559,13 +587,13 @@
 
 Value *EfficiencySanitizer::appToShadow(Value *Shadow, IRBuilder<> &IRB) {
   // Shadow = ((App & Mask) + Offs) >> Scale
-  Shadow = IRB.CreateAnd(Shadow, ConstantInt::get(IntptrTy, ShadowMask));
+  Shadow = IRB.CreateAnd(Shadow, ConstantInt::get(IntptrTy, ShadowParams.ShadowMask));
   uint64_t Offs;
   int Scale = ShadowScale[Options.ToolType];
   if (Scale <= 2)
-    Offs = ShadowOffs[Scale];
+    Offs = ShadowParams.ShadowOffs[Scale];
   else
-    Offs = ShadowOffs[0] << Scale;
+    Offs = ShadowParams.ShadowOffs[0] << Scale;
   Shadow = IRB.CreateAdd(Shadow, ConstantInt::get(IntptrTy, Offs));
   if (Scale > 0)
     Shadow = IRB.CreateLShr(Shadow, Scale);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23801.68978.patch
Type: text/x-patch
Size: 2292 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160823/830f4f40/attachment.bin>


More information about the llvm-commits mailing list