mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-25 05:22:04 +00:00
[msan] Remove indirect call wrapping code.
This functionality was only used in MSanDR, which is deprecated. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222889 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -187,18 +187,6 @@ static cl::opt<int> ClInstrumentationWithCallThreshold(
|
||||
"inline checks (-1 means never use callbacks)."),
|
||||
cl::Hidden, cl::init(3500));
|
||||
|
||||
// Experimental. Wraps all indirect calls in the instrumented code with
|
||||
// a call to the given function. This is needed to assist the dynamic
|
||||
// helper tool (MSanDR) to regain control on transition between instrumented and
|
||||
// non-instrumented code.
|
||||
static cl::opt<std::string> ClWrapIndirectCalls("msan-wrap-indirect-calls",
|
||||
cl::desc("Wrap indirect calls with a given function"),
|
||||
cl::Hidden);
|
||||
|
||||
static cl::opt<bool> ClWrapIndirectCallsFast("msan-wrap-indirect-calls-fast",
|
||||
cl::desc("Do not wrap indirect calls with target in the same module"),
|
||||
cl::Hidden, cl::init(true));
|
||||
|
||||
// This is an experiment to enable handling of cases where shadow is a non-zero
|
||||
// compile-time constant. For some unexplainable reason they were silently
|
||||
// ignored in the instrumentation.
|
||||
@@ -219,8 +207,7 @@ class MemorySanitizer : public FunctionPass {
|
||||
: FunctionPass(ID),
|
||||
TrackOrigins(std::max(TrackOrigins, (int)ClTrackOrigins)),
|
||||
DL(nullptr),
|
||||
WarningFn(nullptr),
|
||||
WrapIndirectCalls(!ClWrapIndirectCalls.empty()) {}
|
||||
WarningFn(nullptr) {}
|
||||
const char *getPassName() const override { return "MemorySanitizer"; }
|
||||
bool runOnFunction(Function &F) override;
|
||||
bool doInitialization(Module &M) override;
|
||||
@@ -254,9 +241,6 @@ class MemorySanitizer : public FunctionPass {
|
||||
/// function.
|
||||
GlobalVariable *OriginTLS;
|
||||
|
||||
GlobalVariable *MsandrModuleStart;
|
||||
GlobalVariable *MsandrModuleEnd;
|
||||
|
||||
/// \brief The run-time callback to print a warning.
|
||||
Value *WarningFn;
|
||||
// These arrays are indexed by log2(AccessSize).
|
||||
@@ -287,12 +271,6 @@ class MemorySanitizer : public FunctionPass {
|
||||
/// \brief An empty volatile inline asm that prevents callback merge.
|
||||
InlineAsm *EmptyAsm;
|
||||
|
||||
bool WrapIndirectCalls;
|
||||
/// \brief Run-time wrapper for indirect calls.
|
||||
Value *IndirectCallWrapperFn;
|
||||
// Argument and return type of IndirectCallWrapperFn: void (*f)(void).
|
||||
Type *AnyFunctionPtrTy;
|
||||
|
||||
friend struct MemorySanitizerVisitor;
|
||||
friend struct VarArgAMD64Helper;
|
||||
};
|
||||
@@ -400,24 +378,6 @@ void MemorySanitizer::initializeCallbacks(Module &M) {
|
||||
EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false),
|
||||
StringRef(""), StringRef(""),
|
||||
/*hasSideEffects=*/true);
|
||||
|
||||
if (WrapIndirectCalls) {
|
||||
AnyFunctionPtrTy =
|
||||
PointerType::getUnqual(FunctionType::get(IRB.getVoidTy(), false));
|
||||
IndirectCallWrapperFn = M.getOrInsertFunction(
|
||||
ClWrapIndirectCalls, AnyFunctionPtrTy, AnyFunctionPtrTy, nullptr);
|
||||
}
|
||||
|
||||
if (WrapIndirectCalls && ClWrapIndirectCallsFast) {
|
||||
MsandrModuleStart = new GlobalVariable(
|
||||
M, IRB.getInt32Ty(), false, GlobalValue::ExternalLinkage,
|
||||
nullptr, "__executable_start");
|
||||
MsandrModuleStart->setVisibility(GlobalVariable::HiddenVisibility);
|
||||
MsandrModuleEnd = new GlobalVariable(
|
||||
M, IRB.getInt32Ty(), false, GlobalValue::ExternalLinkage,
|
||||
nullptr, "_end");
|
||||
MsandrModuleEnd->setVisibility(GlobalVariable::HiddenVisibility);
|
||||
}
|
||||
}
|
||||
|
||||
/// \brief Module-level initialization.
|
||||
@@ -537,7 +497,6 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
||||
};
|
||||
SmallVector<ShadowOriginAndInsertPoint, 16> InstrumentationList;
|
||||
SmallVector<Instruction*, 16> StoreList;
|
||||
SmallVector<CallSite, 16> IndirectCallList;
|
||||
|
||||
MemorySanitizerVisitor(Function &F, MemorySanitizer &MS)
|
||||
: F(F), MS(MS), VAHelper(CreateVarArgHelper(F, MS, *this)) {
|
||||
@@ -669,47 +628,6 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
||||
DEBUG(dbgs() << "DONE:\n" << F);
|
||||
}
|
||||
|
||||
void materializeIndirectCalls() {
|
||||
for (auto &CS : IndirectCallList) {
|
||||
Instruction *I = CS.getInstruction();
|
||||
BasicBlock *B = I->getParent();
|
||||
IRBuilder<> IRB(I);
|
||||
Value *Fn0 = CS.getCalledValue();
|
||||
Value *Fn = IRB.CreateBitCast(Fn0, MS.AnyFunctionPtrTy);
|
||||
|
||||
if (ClWrapIndirectCallsFast) {
|
||||
// Check that call target is inside this module limits.
|
||||
Value *Start =
|
||||
IRB.CreateBitCast(MS.MsandrModuleStart, MS.AnyFunctionPtrTy);
|
||||
Value *End = IRB.CreateBitCast(MS.MsandrModuleEnd, MS.AnyFunctionPtrTy);
|
||||
|
||||
Value *NotInThisModule = IRB.CreateOr(IRB.CreateICmpULT(Fn, Start),
|
||||
IRB.CreateICmpUGE(Fn, End));
|
||||
|
||||
PHINode *NewFnPhi =
|
||||
IRB.CreatePHI(Fn0->getType(), 2, "msandr.indirect_target");
|
||||
|
||||
Instruction *CheckTerm = SplitBlockAndInsertIfThen(
|
||||
NotInThisModule, NewFnPhi,
|
||||
/* Unreachable */ false, MS.ColdCallWeights);
|
||||
|
||||
IRB.SetInsertPoint(CheckTerm);
|
||||
// Slow path: call wrapper function to possibly transform the call
|
||||
// target.
|
||||
Value *NewFn = IRB.CreateBitCast(
|
||||
IRB.CreateCall(MS.IndirectCallWrapperFn, Fn), Fn0->getType());
|
||||
|
||||
NewFnPhi->addIncoming(Fn0, B);
|
||||
NewFnPhi->addIncoming(NewFn, dyn_cast<Instruction>(NewFn)->getParent());
|
||||
CS.setCalledFunction(NewFnPhi);
|
||||
} else {
|
||||
Value *NewFn = IRB.CreateBitCast(
|
||||
IRB.CreateCall(MS.IndirectCallWrapperFn, Fn), Fn0->getType());
|
||||
CS.setCalledFunction(NewFn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// \brief Add MemorySanitizer instrumentation to a function.
|
||||
bool runOnFunction() {
|
||||
MS.initializeCallbacks(*F.getParent());
|
||||
@@ -752,9 +670,6 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
||||
// Insert shadow value checks.
|
||||
materializeChecks(InstrumentWithCalls);
|
||||
|
||||
// Wrap indirect calls.
|
||||
materializeIndirectCalls();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2337,9 +2252,6 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
|
||||
}
|
||||
IRBuilder<> IRB(&I);
|
||||
|
||||
if (MS.WrapIndirectCalls && !CS.getCalledFunction())
|
||||
IndirectCallList.push_back(CS);
|
||||
|
||||
unsigned ArgOffset = 0;
|
||||
DEBUG(dbgs() << " CallSite: " << I << "\n");
|
||||
for (CallSite::arg_iterator ArgIt = CS.arg_begin(), End = CS.arg_end();
|
||||
|
||||
Reference in New Issue
Block a user