[PATCH] D108323: [asan] Added -inline-small-callbacks LLVM flag, which would force inline code for 8 and 16 byte data types when otherwise a callback would have been used.

Kirill Stoimenov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 18 12:42:08 PDT 2021


kstoimenov created this revision.
kstoimenov added a reviewer: vitalybuka.
Herald added a subscriber: hiraditya.
kstoimenov requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

The reason to inline the 8 and 16 byte access checks is that the code for those is smaller than the 1, 2 and 4 byte checks. This allows to have a balanced, middle ground setting between size and speed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108323

Files:
  clang/test/CodeGen/asan-use-callbacks.cpp
  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
@@ -306,6 +306,11 @@
     cl::desc("Realign stack to the value of this flag (power of two)"),
     cl::Hidden, cl::init(32));
 
+static cl::opt<bool> ClInlineSmallCallbacks(
+    "asan-inline-small-callbacks",
+    cl::desc("Inline callbacks for 8 and 16 byte types."), cl::Hidden,
+    cl::init(false));
+
 static cl::opt<int> ClInstrumentationWithCallsThreshold(
     "asan-instrumentation-with-call-threshold",
     cl::desc(
@@ -1741,6 +1746,10 @@
   Value *AddrLong = IRB.CreatePointerCast(Addr, IntptrTy);
   size_t AccessSizeIndex = TypeSizeToSizeIndex(TypeSize);
 
+  if (ClInlineSmallCallbacks && AccessSizeIndex > 2) {
+    UseCalls = false;
+  }
+
   if (UseCalls) {
     if (Exp == 0)
       IRB.CreateCall(AsanMemoryAccessCallback[IsWrite][0][AccessSizeIndex],
Index: clang/test/CodeGen/asan-use-callbacks.cpp
===================================================================
--- clang/test/CodeGen/asan-use-callbacks.cpp
+++ clang/test/CodeGen/asan-use-callbacks.cpp
@@ -4,10 +4,14 @@
 // RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - \
 // RUN:     -fsanitize=address %s -fsanitize-address-outline-instrumentation \
 // RUN:     | FileCheck %s --check-prefixes=CHECK-OUTLINE
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - \
+// RUN:     -fsanitize=address %s -fsanitize-address-outline-instrumentation \
+// RUN:     -mllvm -asan-inline-small-callbacks \
+// RUN:     | FileCheck %s --check-prefixes=CHECK-NO-OUTLINE
 
-// CHECK-NO-OUTLINE-NOT: call{{.*}}@__asan_load4
-// CHECK-OUTLINE: call{{.*}}@__asan_load4
+// CHECK-NO-OUTLINE-NOT: call{{.*}}@__asan_load8
+// CHECK-OUTLINE: call{{.*}}@__asan_load8
 
-int deref(int *p) {
+long deref(long *p) {
   return *p;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108323.367304.patch
Type: text/x-patch
Size: 1962 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210818/ed26d41d/attachment-0001.bin>


More information about the cfe-commits mailing list