[PATCH] D108377: [asan] Implemented flag to emit intrinsics to optimize ASan callbacks.

Kirill Stoimenov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 20 13:00:25 PDT 2021


kstoimenov updated this revision to Diff 367873.
kstoimenov added a comment.

Moved files from the parent patch which didn't belong there.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108377/new/

https://reviews.llvm.org/D108377

Files:
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp


Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -348,6 +348,10 @@
 static cl::opt<bool> ClOpt("asan-opt", cl::desc("Optimize instrumentation"),
                            cl::Hidden, cl::init(true));
 
+static cl::opt<bool> ClOptimizeCallbacks("asan-optimize-callbacks",
+                                         cl::desc("Optimize callbacks"),
+                                         cl::Hidden, cl::init(false));
+
 static cl::opt<bool> ClOptSameTemp(
     "asan-opt-same-temp", cl::desc("Instrument the same temp just once"),
     cl::Hidden, cl::init(true));
@@ -634,6 +638,7 @@
     C = &(M.getContext());
     LongSize = M.getDataLayout().getPointerSizeInBits();
     IntptrTy = Type::getIntNTy(*C, LongSize);
+    Int8PtrTy = Type::getInt8PtrTy(*C);
     TargetTriple = Triple(M.getTargetTriple());
 
     Mapping = getShadowMapping(TargetTriple, LongSize, this->CompileKernel);
@@ -724,6 +729,7 @@
   bool UseAfterScope;
   AsanDetectStackUseAfterReturnMode UseAfterReturn;
   Type *IntptrTy;
+  Type *Int8PtrTy;
   ShadowMapping Mapping;
   FunctionCallee AsanHandleNoReturnFunc;
   FunctionCallee AsanPtrCmpFunction, AsanPtrSubFunction;
@@ -1745,27 +1751,14 @@
   IRBuilder<> IRB(InsertBefore);
   Value *AddrLong = IRB.CreatePointerCast(Addr, IntptrTy);
   size_t AccessSizeIndex = TypeSizeToSizeIndex(TypeSize);
-  const int32_t AccessInfo =
-      (CompileKernel << ASanAccessInfo::CompileKernelShift) +
-      (IsWrite << ASanAccessInfo::IsWriteShift) +
-      (AccessSizeIndex << ASanAccessInfo::AccessSizeShift);
-
 
   if (UseCalls) {
-    if (ClOptimizeCallbacks) {
-      Value *Ptr8 = IRB.CreatePointerCast(Addr, Int8PtrTy);
-      Module *M = IRB.GetInsertBlock()->getParent()->getParent();
-      IRB.CreateCall(
-          Intrinsic::getDeclaration(M, Intrinsic::asan_check_memaccess),
-          {Ptr8, ConstantInt::get(IRB.getInt32Ty(), AccessInfo)});
-    } else {
-      if (Exp == 0)
-        IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][0][AccessSizeIndex],
-                       AddrLong);
-      else
-        IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][1][AccessSizeIndex],
-                       {AddrLong, ConstantInt::get(IRB.getInt32Ty(), Exp)});
-    }
+    if (Exp == 0)
+      IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][0][AccessSizeIndex],
+                     AddrLong);
+    else
+      IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][1][AccessSizeIndex],
+                     {AddrLong, ConstantInt::get(IRB.getInt32Ty(), Exp)});
     return;
   }
 
Index: llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
===================================================================
--- llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
+++ llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
@@ -155,17 +155,6 @@
     bool UseOdrIndicator = true,
     AsanDtorKind DestructorKind = AsanDtorKind::Global);
 
-namespace ASanAccessInfo {
-
-// Bit field positions for accessinfo parameter to llvm.asan.check.memaccess.
-enum {
-  CompileKernelShift = 0, // 1 bit
-  AccessSizeShift = 1, // 4 bits
-  IsWriteShift = 5, // 1 bit
-};
-
-} // namespace ASanAccessInfo
-
 } // namespace llvm
 
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108377.367873.patch
Type: text/x-patch
Size: 3403 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210820/a488584e/attachment.bin>


More information about the llvm-commits mailing list