[llvm-commits] [PATCH] AddressSanitizer: handle llvm.lifetime intrinsics (LLVM part)

Kostya Serebryany kcc at google.com
Wed Nov 28 22:57:11 PST 2012


  How about a different algorithm?

  1. collect all llvm.lifetime.end with
    a. constant size
    b. second parameter that looks like asan_grand_alloca+const_offset
  2. insert __asan_poison_stack_memory after every such llvm.lifetime.end
  3. unpoison the entire asan_grand_alloca at the end with a single call
   This will need to play nicely with use-after-return, which in fact poisones the entire asan_grand_alloca


================
Comment at: lib/Transforms/Instrumentation/AddressSanitizer.cpp:1225
@@ -1139,1 +1224,3 @@
     PoisonStack(ArrayRef<AllocaInst*>(AllocaVec), IRBRet, ShadowBase, false);
+    // Unpoison all local variables poisoned in llvm.lifetime analysis.
+    unpoisonAllocas(PoisonedAlloca, IRBRet);
----------------
Alexey Samsonov wrote:
> Kostya Serebryany wrote:
> > Why? 
> > Don't we unpoison these things twice? 
> No, we _poison_ stuff at llvm.lifetime.end and should unpoison it back here.
ok

================
Comment at: lib/Transforms/Instrumentation/AddressSanitizer.cpp:1057
@@ +1056,3 @@
+// (4) store the maximal value of %size argument for each %alloca
+//     to make sure we unpoison all the poisoned memory at function exit.
+void AddressSanitizer::handleValueLifetime(Value *V, Value *Origin,
----------------
I am still not getting this. 
Why would any alloca be mentioned in multiple llvm.lifetime.start?
Does this happen? 

================
Comment at: lib/Transforms/Instrumentation/AddressSanitizer.cpp:1055
@@ +1054,3 @@
+// (3) if %size is constant, unpoison underlying shadow memory
+//     for llvm.lifetime.start and poison it for llvm.lifetime.end.
+// (4) store the maximal value of %size argument for each %alloca
----------------
Do we actually need to unpoison on llvm.lifetime.start ? 
Isn't the memory unpoisoned already? 

================
Comment at: lib/Transforms/Instrumentation/AddressSanitizer.cpp:1192
@@ -1105,4 +1191,3 @@
     assert((AlignedSize % RedzoneSize()) == 0);
-    AI->replaceAllUsesWith(
-        IRB.CreateIntToPtr(
+    Value *NewAllocaPtr = IRB.CreateIntToPtr(
             IRB.CreateAdd(LocalStackBase, ConstantInt::get(IntptrTy, Pos)),
----------------
The name is confusing. This is not Alloca any more. 



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



More information about the llvm-commits mailing list