Skip to content

Commit

Permalink
Revert "[sanitizer-coverage] one more flavor of coverage: -fsanitize-…
Browse files Browse the repository at this point in the history
…coverage=inline-8bit-counters. Experimental so far, not documenting yet."

This reverts commit r304630, as it broke ARM/AArch64 bots for 2 days.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304698 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rengolin committed Jun 5, 2017
1 parent ca0adcb commit 3b482e4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 57 deletions.
1 change: 0 additions & 1 deletion include/llvm/Transforms/Instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ struct SanitizerCoverageOptions {
bool Use8bitCounters = false;
bool TracePC = false;
bool TracePCGuard = false;
bool Inline8bitCounters = false;
bool NoPrune = false;

SanitizerCoverageOptions() = default;
Expand Down
52 changes: 9 additions & 43 deletions lib/Transforms/Instrumentation/SanitizerCoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,23 @@ static const char *const SanCovTracePCGuardName =
"__sanitizer_cov_trace_pc_guard";
static const char *const SanCovTracePCGuardInitName =
"__sanitizer_cov_trace_pc_guard_init";
static const char *const SanCov8bitCountersInitName =
"__sanitizer_cov_8bit_counters_init";

static const char *const SanCovGuardsSectionName = "sancov_guards";
static const char *const SanCovCountersSectionName = "sancov_counters";

static cl::opt<int> ClCoverageLevel(
"sanitizer-coverage-level",
cl::desc("Sanitizer Coverage. 0: none, 1: entry block, 2: all blocks, "
"3: all blocks and critical edges"),
cl::Hidden, cl::init(0));

static cl::opt<bool> ClTracePC("sanitizer-coverage-trace-pc",
cl::desc("Experimental pc tracing"), cl::Hidden,
cl::init(false));
static cl::opt<bool> ClExperimentalTracePC("sanitizer-coverage-trace-pc",
cl::desc("Experimental pc tracing"),
cl::Hidden, cl::init(false));

static cl::opt<bool> ClTracePCGuard("sanitizer-coverage-trace-pc-guard",
cl::desc("pc tracing with a guard"),
cl::Hidden, cl::init(false));

static cl::opt<bool> ClInline8bitCounters("sanitizer-coverage-inline-8bit-counters",
cl::desc("increments 8-bit counter for every edge"),
cl::Hidden, cl::init(false));

static cl::opt<bool>
ClCMPTracing("sanitizer-coverage-trace-compares",
cl::desc("Tracing of CMP and similar instructions"),
Expand Down Expand Up @@ -132,10 +125,9 @@ SanitizerCoverageOptions OverrideFromCL(SanitizerCoverageOptions Options) {
Options.TraceCmp |= ClCMPTracing;
Options.TraceDiv |= ClDIVTracing;
Options.TraceGep |= ClGEPTracing;
Options.TracePC |= ClTracePC;
Options.TracePC |= ClExperimentalTracePC;
Options.TracePCGuard |= ClTracePCGuard;
Options.Inline8bitCounters |= ClInline8bitCounters;
if (!Options.TracePCGuard && !Options.TracePC && !Options.Inline8bitCounters)
if (!Options.TracePCGuard && !Options.TracePC)
Options.TracePCGuard = true; // TracePCGuard is default.
Options.NoPrune |= !ClPruneBlocks;
return Options;
Expand Down Expand Up @@ -177,11 +169,6 @@ class SanitizerCoverageModule : public ModulePass {
void CreateInitCallForSection(Module &M, const char *InitFunctionName,
Type *Ty, const std::string &Section);

void SetNoSanitizeMetadata(Instruction *I) {
I->setMetadata(I->getModule()->getMDKindID("nosanitize"),
MDNode::get(*C, None));
}

std::string getSectionName(const std::string &Section) const;
std::string getSectionStart(const std::string &Section) const;
std::string getSectionEnd(const std::string &Section) const;
Expand All @@ -192,15 +179,13 @@ class SanitizerCoverageModule : public ModulePass {
Function *SanCovTraceGepFunction;
Function *SanCovTraceSwitchFunction;
InlineAsm *EmptyAsm;
Type *IntptrTy, *IntptrPtrTy, *Int64Ty, *Int64PtrTy, *Int32Ty, *Int32PtrTy,
*Int8Ty, *Int8PtrTy;
Type *IntptrTy, *IntptrPtrTy, *Int64Ty, *Int64PtrTy, *Int32Ty, *Int32PtrTy;
Module *CurModule;
Triple TargetTriple;
LLVMContext *C;
const DataLayout *DL;

GlobalVariable *FunctionGuardArray; // for trace-pc-guard.
GlobalVariable *Function8bitCounterArray; // for inline-8bit-counters.

SanitizerCoverageOptions Options;
};
Expand Down Expand Up @@ -242,17 +227,14 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
CurModule = &M;
TargetTriple = Triple(M.getTargetTriple());
FunctionGuardArray = nullptr;
Function8bitCounterArray = nullptr;
IntptrTy = Type::getIntNTy(*C, DL->getPointerSizeInBits());
IntptrPtrTy = PointerType::getUnqual(IntptrTy);
Type *VoidTy = Type::getVoidTy(*C);
IRBuilder<> IRB(*C);
Int64PtrTy = PointerType::getUnqual(IRB.getInt64Ty());
Int32PtrTy = PointerType::getUnqual(IRB.getInt32Ty());
Int8PtrTy = PointerType::getUnqual(IRB.getInt8Ty());
Int64Ty = IRB.getInt64Ty();
Int32Ty = IRB.getInt32Ty();
Int8Ty = IRB.getInt8Ty();

SanCovTracePCIndir = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(SanCovTracePCIndirName, VoidTy, IntptrTy));
Expand Down Expand Up @@ -298,9 +280,6 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
if (FunctionGuardArray)
CreateInitCallForSection(M, SanCovTracePCGuardInitName, Int32PtrTy,
SanCovGuardsSectionName);
if (Function8bitCounterArray)
CreateInitCallForSection(M, SanCov8bitCountersInitName, Int8PtrTy,
SanCovCountersSectionName);

return true;
}
Expand Down Expand Up @@ -441,9 +420,6 @@ void SanitizerCoverageModule::CreateFunctionLocalArrays(size_t NumGuards,
if (Options.TracePCGuard)
FunctionGuardArray = CreateFunctionLocalArrayInSection(
NumGuards, F, Int32Ty, SanCovGuardsSectionName);
if (Options.Inline8bitCounters)
Function8bitCounterArray = CreateFunctionLocalArrayInSection(
NumGuards, F, Int8Ty, SanCovCountersSectionName);
}

bool SanitizerCoverageModule::InjectCoverage(Function &F,
Expand Down Expand Up @@ -476,7 +452,7 @@ void SanitizerCoverageModule::InjectCoverageForIndirectCalls(
Function &F, ArrayRef<Instruction *> IndirCalls) {
if (IndirCalls.empty())
return;
assert(Options.TracePC || Options.TracePCGuard || Options.Inline8bitCounters);
assert(Options.TracePC || Options.TracePCGuard);
for (auto I : IndirCalls) {
IRBuilder<> IRB(I);
CallSite CS(I);
Expand Down Expand Up @@ -604,25 +580,15 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
if (Options.TracePC) {
IRB.CreateCall(SanCovTracePC); // gets the PC using GET_CALLER_PC.
IRB.CreateCall(EmptyAsm, {}); // Avoids callback merge.
}
if (Options.TracePCGuard) {
} else {
assert(Options.TracePCGuard);
auto GuardPtr = IRB.CreateIntToPtr(
IRB.CreateAdd(IRB.CreatePointerCast(FunctionGuardArray, IntptrTy),
ConstantInt::get(IntptrTy, Idx * 4)),
Int32PtrTy);
IRB.CreateCall(SanCovTracePCGuard, GuardPtr);
IRB.CreateCall(EmptyAsm, {}); // Avoids callback merge.
}
if (Options.Inline8bitCounters) {
auto CounterPtr = IRB.CreateGEP(
Function8bitCounterArray,
{ConstantInt::get(IntptrTy, 0), ConstantInt::get(IntptrTy, Idx)});
auto Load = IRB.CreateLoad(CounterPtr);
auto Inc = IRB.CreateAdd(Load, ConstantInt::get(Int8Ty, 1));
auto Store = IRB.CreateStore(Inc, CounterPtr);
SetNoSanitizeMetadata(Load);
SetNoSanitizeMetadata(Store);
}
}

std::string
Expand Down
13 changes: 0 additions & 13 deletions test/Instrumentation/SanitizerCoverage/inline-8bit-counters.ll

This file was deleted.

0 comments on commit 3b482e4

Please sign in to comment.