[PATCH] D87777: [ASAN] Properly deal with musttail calls in ASAN
Xun Li via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 16 10:33:33 PDT 2020
lxfind updated this revision to Diff 292265.
lxfind added a comment.
comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87777/new/
https://reviews.llvm.org/D87777
Files:
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
@@ -556,6 +556,22 @@
}
}
+// For a ret instruction followed by a musttail call, we cannot insert anything
+// in between. Instead we use the musttail call instruction as the insertion
+// point.
+static Instruction *adjustForMusttailCall(Instruction *I) {
+ ReturnInst *RI = dyn_cast<ReturnInst>(I);
+ if (!RI)
+ return I;
+ Instruction *Prev = RI->getPrevNode();
+ if (BitCastInst *BCI = dyn_cast_or_null<BitCastInst>(Prev))
+ Prev = BCI->getPrevNode();
+ if (CallInst *CI = dyn_cast_or_null<CallInst>(Prev))
+ if (CI->isMustTailCall())
+ return CI;
+ return RI;
+}
+
namespace {
/// Module analysis for getting various metadata about the module.
@@ -999,10 +1015,11 @@
// Unpoison dynamic allocas redzones.
void unpoisonDynamicAllocas() {
- for (auto &Ret : RetVec)
- unpoisonDynamicAllocasBeforeInst(Ret, DynamicAllocaLayout);
+ for (Instruction *Ret : RetVec)
+ unpoisonDynamicAllocasBeforeInst(adjustForMusttailCall(Ret),
+ DynamicAllocaLayout);
- for (auto &StackRestoreInst : StackRestoreVec)
+ for (Instruction *StackRestoreInst : StackRestoreVec)
unpoisonDynamicAllocasBeforeInst(StackRestoreInst,
StackRestoreInst->getOperand(0));
}
@@ -3303,8 +3320,9 @@
SmallVector<uint8_t, 64> ShadowAfterReturn;
// (Un)poison the stack before all ret instructions.
- for (auto Ret : RetVec) {
- IRBuilder<> IRBRet(Ret);
+ for (Instruction *Ret : RetVec) {
+ Instruction *Adjusted = adjustForMusttailCall(Ret);
+ IRBuilder<> IRBRet(Adjusted);
// Mark the current frame as retired.
IRBRet.CreateStore(ConstantInt::get(IntptrTy, kRetiredStackFrameMagic),
BasePlus0);
@@ -3323,7 +3341,7 @@
Value *Cmp =
IRBRet.CreateICmpNE(FakeStack, Constant::getNullValue(IntptrTy));
Instruction *ThenTerm, *ElseTerm;
- SplitBlockAndInsertIfThenElse(Cmp, Ret, &ThenTerm, &ElseTerm);
+ SplitBlockAndInsertIfThenElse(Cmp, Adjusted, &ThenTerm, &ElseTerm);
IRBuilder<> IRBPoison(ThenTerm);
if (StackMallocIdx <= 4) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87777.292265.patch
Type: text/x-patch
Size: 2399 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200916/83f32954/attachment.bin>
More information about the llvm-commits
mailing list