summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2019-05-16 23:54:41 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2019-05-16 23:54:41 +0000
commit7f281b2c06b19a64a2d630df02ccbf23526e6728 (patch)
tree47ead30fb2abc4adf27e32292a308f510d173680 /llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
parent627e383ce559a24848eeff8852a95d44805b3d36 (diff)
downloadbcm5719-llvm-7f281b2c06b19a64a2d630df02ccbf23526e6728.tar.gz
bcm5719-llvm-7f281b2c06b19a64a2d630df02ccbf23526e6728.zip
HWASan exception support.
Summary: Adds a call to __hwasan_handle_vfork(SP) at each landingpad entry. Reusing __hwasan_handle_vfork instead of introducing a new runtime call in order to be ABI-compatible with old runtime library. Reviewers: pcc Subscribers: kubamracek, hiraditya, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D61968 llvm-svn: 360959
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp')
-rw-r--r--llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index 56db746565b..abbe5801de1 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -157,6 +157,11 @@ static cl::opt<bool>
cl::desc("instrument memory intrinsics"),
cl::Hidden, cl::init(true));
+static cl::opt<bool>
+ ClInstrumentLandingPads("hwasan-instrument-landing-pads",
+ cl::desc("instrument landing pads"), cl::Hidden,
+ cl::init(true));
+
static cl::opt<bool> ClInlineAllChecks("hwasan-inline-all-checks",
cl::desc("inline all checks"),
cl::Hidden, cl::init(false));
@@ -202,6 +207,7 @@ public:
Value *untagPointer(IRBuilder<> &IRB, Value *PtrLong);
bool instrumentStack(SmallVectorImpl<AllocaInst *> &Allocas,
SmallVectorImpl<Instruction *> &RetVec, Value *StackTag);
+ bool instrumentLandingPads(SmallVectorImpl<Instruction *> &RetVec);
Value *getNextTagWithCall(IRBuilder<> &IRB);
Value *getStackBaseTag(IRBuilder<> &IRB);
Value *getAllocaTag(IRBuilder<> &IRB, Value *StackTag, AllocaInst *AI,
@@ -216,6 +222,7 @@ private:
std::string CurModuleUniqueId;
Triple TargetTriple;
FunctionCallee HWAsanMemmove, HWAsanMemcpy, HWAsanMemset;
+ FunctionCallee HWAsanHandleVfork;
// Frame description is a way to pass names/sizes of local variables
// to the run-time w/o adding extra executable code in every function.
@@ -440,6 +447,9 @@ void HWAddressSanitizer::initializeCallbacks(Module &M) {
IRB.getInt8PtrTy(), IRB.getInt8PtrTy(),
IRB.getInt32Ty(), IntptrTy);
+ HWAsanHandleVfork =
+ M.getOrInsertFunction("__hwasan_handle_vfork", IRB.getVoidTy(), IntptrTy);
+
HwasanThreadEnterFunc =
M.getOrInsertFunction("__hwasan_thread_enter", IRB.getVoidTy());
}
@@ -955,6 +965,23 @@ Value *HWAddressSanitizer::emitPrologue(IRBuilder<> &IRB,
return ShadowBase;
}
+bool HWAddressSanitizer::instrumentLandingPads(
+ SmallVectorImpl<Instruction *> &LandingPadVec) {
+ Module *M = LandingPadVec[0]->getModule();
+ Function *ReadRegister =
+ Intrinsic::getDeclaration(M, Intrinsic::read_register, IntptrTy);
+ const char *RegName =
+ (TargetTriple.getArch() == Triple::x86_64) ? "rsp" : "sp";
+ MDNode *MD = MDNode::get(*C, {MDString::get(*C, RegName)});
+ Value *Args[] = {MetadataAsValue::get(*C, MD)};
+
+ for (auto *LP : LandingPadVec) {
+ IRBuilder<> IRB(LP->getNextNode());
+ IRB.CreateCall(HWAsanHandleVfork, {IRB.CreateCall(ReadRegister, Args)});
+ }
+ return true;
+}
+
bool HWAddressSanitizer::instrumentStack(
SmallVectorImpl<AllocaInst *> &Allocas,
SmallVectorImpl<Instruction *> &RetVec, Value *StackTag) {
@@ -1023,6 +1050,7 @@ bool HWAddressSanitizer::sanitizeFunction(Function &F) {
SmallVector<Instruction*, 16> ToInstrument;
SmallVector<AllocaInst*, 8> AllocasToInstrument;
SmallVector<Instruction*, 8> RetVec;
+ SmallVector<Instruction*, 8> LandingPadVec;
for (auto &BB : F) {
for (auto &Inst : BB) {
if (ClInstrumentStack)
@@ -1041,6 +1069,9 @@ bool HWAddressSanitizer::sanitizeFunction(Function &F) {
isa<CleanupReturnInst>(Inst))
RetVec.push_back(&Inst);
+ if (ClInstrumentLandingPads && isa<LandingPadInst>(Inst))
+ LandingPadVec.push_back(&Inst);
+
Value *MaybeMask = nullptr;
bool IsWrite;
unsigned Alignment;
@@ -1052,13 +1083,17 @@ bool HWAddressSanitizer::sanitizeFunction(Function &F) {
}
}
+ initializeCallbacks(*F.getParent());
+
+ if (!LandingPadVec.empty())
+ instrumentLandingPads(LandingPadVec);
+
if (AllocasToInstrument.empty() && ToInstrument.empty())
return false;
if (ClCreateFrameDescriptions && !AllocasToInstrument.empty())
createFrameGlobal(F, createFrameString(AllocasToInstrument));
- initializeCallbacks(*F.getParent());
assert(!LocalDynamicShadow);
OpenPOWER on IntegriCloud