[PATCH] Introduce two command-line flags for the instrumentation pass to control whether the labels of pointers should be ignored in load and store instructions

Peter Collingbourne peter at pcc.me.uk
Fri Nov 15 16:08:35 PST 2013


pcc added you to the CC list for the revision "Introduce two command-line flags for the instrumentation pass to control whether the labels of pointers should be ignored in load and store instructions".

Hi pcc,

The new command line flags are -dfsan-ignore-pointer-label-on-store and -dfsan-ignore-pointer-label-on-load. Their default value matches the current labelling scheme. 

Additionally, the function __dfsan_union_load is marked as pure (i.e., readnone). 

http://llvm-reviews.chandlerc.com/D2187

Files:
  lib/Transforms/Instrumentation/DataFlowSanitizer.cpp

Index: lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -96,6 +96,20 @@
     cl::desc("Use the argument ABI rather than the TLS ABI"),
     cl::Hidden);
 
+// Controls whether the pass ignores the labels of pointers in load
+// instructions.
+static cl::opt<bool> ClIgnorePointerLabelOnLoad(
+    "dfsan-ignore-pointer-label-on-load",
+    cl::desc("Ignore the label of the pointer when loading data from memory."),
+    cl::Hidden, cl::init(false));
+
+// Controls whether the pass ignores the labels of pointers in stores
+// instructions.
+static cl::opt<bool> ClIgnorePointerLabelOnStore(
+    "dfsan-ignore-pointer-label-on-store",
+    cl::desc("Ignore the label of the pointer when storing data in memory."),
+    cl::Hidden, cl::init(true));
+
 static cl::opt<bool> ClDebugNonzeroLabels(
     "dfsan-debug-nonzero-labels",
     cl::desc("Insert calls to __dfsan_nonzero_label on observing a parameter, "
@@ -505,6 +519,7 @@
   DFSanUnionLoadFn =
       Mod->getOrInsertFunction("__dfsan_union_load", DFSanUnionLoadFnTy);
   if (Function *F = dyn_cast<Function>(DFSanUnionLoadFn)) {
+    F->addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
     F->addAttribute(AttributeSet::ReturnIndex, Attribute::ZExt);
   }
   DFSanUnimplementedFn =
@@ -978,14 +993,15 @@
     Align = 1;
   }
   IRBuilder<> IRB(&LI);
-  Value *LoadedShadow =
-      DFSF.loadShadow(LI.getPointerOperand(), Size, Align, &LI);
-  Value *PtrShadow = DFSF.getShadow(LI.getPointerOperand());
-  Value *CombinedShadow = DFSF.DFS.combineShadows(LoadedShadow, PtrShadow, &LI);
-  if (CombinedShadow != DFSF.DFS.ZeroShadow)
-    DFSF.NonZeroChecks.insert(CombinedShadow);
-
-  DFSF.setShadow(&LI, CombinedShadow);
+  Value *Shadow = DFSF.loadShadow(LI.getPointerOperand(), Size, Align, &LI);
+  if (!ClIgnorePointerLabelOnLoad) {
+    Value *PtrShadow = DFSF.getShadow(LI.getPointerOperand());
+    Shadow = DFSF.DFS.combineShadows(Shadow, PtrShadow, &LI);
+  }
+  if (Shadow != DFSF.DFS.ZeroShadow)
+    DFSF.NonZeroChecks.insert(Shadow);
+
+  DFSF.setShadow(&LI, Shadow);
 }
 
 void DFSanFunction::storeShadow(Value *Addr, uint64_t Size, uint64_t Align,
@@ -1050,8 +1066,13 @@
   } else {
     Align = 1;
   }
-  DFSF.storeShadow(SI.getPointerOperand(), Size, Align,
-                   DFSF.getShadow(SI.getValueOperand()), &SI);
+
+  Value* Shadow = DFSF.getShadow(SI.getValueOperand());
+  if (!ClIgnorePointerLabelOnStore) {
+    Value *PtrShadow = DFSF.getShadow(SI.getPointerOperand());
+    Shadow = DFSF.DFS.combineShadows(Shadow, PtrShadow, &SI);
+  }
+  DFSF.storeShadow(SI.getPointerOperand(), Size, Align, Shadow, &SI);
 }
 
 void DFSanVisitor::visitBinaryOperator(BinaryOperator &BO) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2187.1.patch
Type: text/x-patch
Size: 2874 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131115/751ebfdc/attachment.bin>


More information about the llvm-commits mailing list