Skip to content

Commit

Permalink
[sanitizer-coverage] remove stale code
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300769 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
kcc committed Apr 19, 2017
1 parent 47ba2c1 commit 06c0527
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 101 deletions.
70 changes: 4 additions & 66 deletions lib/Transforms/Instrumentation/SanitizerCoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ static const char *const SanCovTracePCIndirName =
"__sanitizer_cov_trace_pc_indir";
static const char *const SanCovTraceEnterName =
"__sanitizer_cov_trace_func_enter";
static const char *const SanCovTraceBBName =
"__sanitizer_cov_trace_basic_block";
static const char *const SanCovTracePCName = "__sanitizer_cov_trace_pc";
static const char *const SanCovTraceCmp1 = "__sanitizer_cov_trace_cmp1";
static const char *const SanCovTraceCmp2 = "__sanitizer_cov_trace_cmp2";
Expand Down Expand Up @@ -96,12 +94,6 @@ static cl::opt<unsigned> ClCoverageBlockThreshold(
" more than this number of blocks."),
cl::Hidden, cl::init(0));

static cl::opt<bool>
ClExperimentalTracing("sanitizer-coverage-experimental-tracing",
cl::desc("Experimental basic-block tracing: insert "
"callbacks at every basic block"),
cl::Hidden, cl::init(false));

static cl::opt<bool> ClExperimentalTracePC("sanitizer-coverage-trace-pc",
cl::desc("Experimental pc tracing"),
cl::Hidden, cl::init(false));
Expand All @@ -128,16 +120,6 @@ static cl::opt<bool>
cl::desc("Reduce the number of instrumented blocks"),
cl::Hidden, cl::init(true));

// Experimental 8-bit counters used as an additional search heuristic during
// coverage-guided fuzzing.
// The counters are not thread-friendly:
// - contention on these counters may cause significant slowdown;
// - the counter updates are racy and the results may be inaccurate.
// They are also inaccurate due to 8-bit integer overflow.
static cl::opt<bool> ClUse8bitCounters("sanitizer-coverage-8bit-counters",
cl::desc("Experimental 8-bit counters"),
cl::Hidden, cl::init(false));

namespace {

SanitizerCoverageOptions getOptions(int LegacyCoverageLevel) {
Expand Down Expand Up @@ -168,11 +150,9 @@ SanitizerCoverageOptions OverrideFromCL(SanitizerCoverageOptions Options) {
SanitizerCoverageOptions CLOpts = getOptions(ClCoverageLevel);
Options.CoverageType = std::max(Options.CoverageType, CLOpts.CoverageType);
Options.IndirectCalls |= CLOpts.IndirectCalls;
Options.TraceBB |= ClExperimentalTracing;
Options.TraceCmp |= ClCMPTracing;
Options.TraceDiv |= ClDIVTracing;
Options.TraceGep |= ClGEPTracing;
Options.Use8bitCounters |= ClUse8bitCounters;
Options.TracePC |= ClExperimentalTracePC;
Options.TracePCGuard |= ClTracePCGuard;
return Options;
Expand Down Expand Up @@ -212,16 +192,15 @@ class SanitizerCoverageModule : public ModulePass {
bool UseCalls);
unsigned NumberOfInstrumentedBlocks() {
return SanCovFunction->getNumUses() +
SanCovWithCheckFunction->getNumUses() + SanCovTraceBB->getNumUses() +
SanCovTraceEnter->getNumUses();
SanCovWithCheckFunction->getNumUses();
}
StringRef getSanCovTracePCGuardSection() const;
StringRef getSanCovTracePCGuardSectionStart() const;
StringRef getSanCovTracePCGuardSectionEnd() const;
Function *SanCovFunction;
Function *SanCovWithCheckFunction;
Function *SanCovIndirCallFunction, *SanCovTracePCIndir;
Function *SanCovTraceEnter, *SanCovTraceBB, *SanCovTracePC, *SanCovTracePCGuard;
Function *SanCovTracePC, *SanCovTracePCGuard;
Function *SanCovTraceCmpFunction[4];
Function *SanCovTraceDivFunction[2];
Function *SanCovTraceGepFunction;
Expand All @@ -235,7 +214,6 @@ class SanitizerCoverageModule : public ModulePass {

GlobalVariable *GuardArray;
GlobalVariable *FunctionGuardArray; // for trace-pc-guard.
GlobalVariable *EightBitCounterArray;
bool HasSancovGuardsSection;

SanitizerCoverageOptions Options;
Expand Down Expand Up @@ -305,10 +283,6 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
M.getOrInsertFunction(SanCovTracePCName, VoidTy));
SanCovTracePCGuard = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
SanCovTracePCGuardName, VoidTy, Int32PtrTy));
SanCovTraceEnter = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(SanCovTraceEnterName, VoidTy, Int32PtrTy));
SanCovTraceBB = checkSanitizerInterfaceFunction(
M.getOrInsertFunction(SanCovTraceBBName, VoidTy, Int32PtrTy));

// At this point we create a dummy array of guards because we don't
// know how many elements we will need.
Expand All @@ -319,10 +293,6 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
GuardArray =
new GlobalVariable(M, Int32Ty, false, GlobalValue::ExternalLinkage,
nullptr, "__sancov_gen_cov_tmp");
if (Options.Use8bitCounters)
EightBitCounterArray =
new GlobalVariable(M, Int8Ty, false, GlobalVariable::ExternalLinkage,
nullptr, "__sancov_gen_cov_tmp");

for (auto &F : M)
runOnFunction(F);
Expand All @@ -344,20 +314,6 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
GuardArray->eraseFromParent();
}

GlobalVariable *RealEightBitCounterArray;
if (Options.Use8bitCounters) {
// Make sure the array is 16-aligned.
static const int CounterAlignment = 16;
Type *Int8ArrayNTy = ArrayType::get(Int8Ty, alignTo(N, CounterAlignment));
RealEightBitCounterArray = new GlobalVariable(
M, Int8ArrayNTy, false, GlobalValue::PrivateLinkage,
Constant::getNullValue(Int8ArrayNTy), "__sancov_gen_cov_counter");
RealEightBitCounterArray->setAlignment(CounterAlignment);
EightBitCounterArray->replaceAllUsesWith(
IRB.CreatePointerCast(RealEightBitCounterArray, Int8PtrTy));
EightBitCounterArray->eraseFromParent();
}

// Create variable for module (compilation unit) name
Constant *ModNameStrConst =
ConstantDataArray::getString(M.getContext(), M.getName(), true);
Expand Down Expand Up @@ -396,10 +352,7 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
M, SanCovModuleCtorName, SanCovModuleInitName,
{Int32PtrTy, IntptrTy, Int8PtrTy, Int8PtrTy},
{IRB.CreatePointerCast(RealGuardArray, Int32PtrTy),
ConstantInt::get(IntptrTy, N),
Options.Use8bitCounters
? IRB.CreatePointerCast(RealEightBitCounterArray, Int8PtrTy)
: Constant::getNullValue(Int8PtrTy),
ConstantInt::get(IntptrTy, N), Constant::getNullValue(Int8PtrTy),
IRB.CreatePointerCast(ModuleName, Int8PtrTy)});

appendToGlobalCtors(M, CtorFunc, SanCtorAndDtorPriority);
Expand Down Expand Up @@ -735,9 +688,7 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
IRB.CreatePointerCast(GuardArray, IntptrTy),
ConstantInt::get(IntptrTy, (1 + NumberOfInstrumentedBlocks()) * 4));
GuardP = IRB.CreateIntToPtr(GuardP, Int32PtrTy);
if (Options.TraceBB) {
IRB.CreateCall(IsEntryBB ? SanCovTraceEnter : SanCovTraceBB, GuardP);
} else if (UseCalls) {
if (UseCalls) {
IRB.CreateCall(SanCovWithCheckFunction, GuardP);
} else {
LoadInst *Load = IRB.CreateLoad(GuardP);
Expand All @@ -755,19 +706,6 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
IRB.CreateCall(EmptyAsm, {}); // Avoids callback merge.
}
}

if (Options.Use8bitCounters) {
IRB.SetInsertPoint(&*IP);
Value *P = IRB.CreateAdd(
IRB.CreatePointerCast(EightBitCounterArray, IntptrTy),
ConstantInt::get(IntptrTy, NumberOfInstrumentedBlocks() - 1));
P = IRB.CreateIntToPtr(P, IRB.getInt8PtrTy());
LoadInst *LI = IRB.CreateLoad(P);
Value *Inc = IRB.CreateAdd(LI, ConstantInt::get(IRB.getInt8Ty(), 1));
StoreInst *SI = IRB.CreateStore(Inc, P);
SetNoSanitizeMetadata(LI);
SetNoSanitizeMetadata(SI);
}
}

StringRef SanitizerCoverageModule::getSanCovTracePCGuardSection() const {
Expand Down
20 changes: 0 additions & 20 deletions test/Instrumentation/SanitizerCoverage/coverage.ll
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-block-threshold=10 -S | FileCheck %s --check-prefix=CHECK3
; RUN: opt < %s -sancov -sanitizer-coverage-level=4 -S | FileCheck %s --check-prefix=CHECK4
; RUN: opt < %s -sancov -sanitizer-coverage-level=4 -sanitizer-coverage-trace-pc -S | FileCheck %s --check-prefix=CHECK_TRACE_PC
; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-8bit-counters=1 -S | FileCheck %s --check-prefix=CHECK-8BIT

; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=10 \
; RUN: -S | FileCheck %s --check-prefix=CHECK2
Expand Down Expand Up @@ -81,25 +80,6 @@ entry:
; CHECK3-NOT: call void @__sanitizer_cov
; CHECK3: ret void

; test -sanitizer-coverage-8bit-counters=1
; CHECK-8BIT-LABEL: define void @foo

; CHECK-8BIT: [[V11:%[0-9]*]] = load i8{{.*}}!nosanitize
; CHECK-8BIT: [[V12:%[0-9]*]] = add i8 [[V11]], 1
; CHECK-8BIT: store i8 [[V12]]{{.*}}!nosanitize
; CHECK-8BIT: [[V21:%[0-9]*]] = load i8{{.*}}!nosanitize
; CHECK-8BIT: [[V22:%[0-9]*]] = add i8 [[V21]], 1
; CHECK-8BIT: store i8 [[V22]]{{.*}}!nosanitize
; CHECK-8BIT: [[V31:%[0-9]*]] = load i8{{.*}}!nosanitize
; CHECK-8BIT: [[V32:%[0-9]*]] = add i8 [[V31]], 1
; CHECK-8BIT: store i8 [[V32]]{{.*}}!nosanitize
; CHECK-8BIT: [[V41:%[0-9]*]] = load i8{{.*}}!nosanitize
; CHECK-8BIT: [[V42:%[0-9]*]] = add i8 [[V41]], 1
; CHECK-8BIT: store i8 [[V42]]{{.*}}!nosanitize

; CHECK-8BIT: ret void


%struct.StructWithVptr = type { i32 (...)** }

define void @CallViaVptr(%struct.StructWithVptr* %foo) uwtable sanitize_address {
Expand Down
15 changes: 0 additions & 15 deletions test/Instrumentation/SanitizerCoverage/tracing.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
; Test -sanitizer-coverage-experimental-tracing
; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-experimental-tracing -S | FileCheck %s --check-prefix=CHECK1
; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-experimental-tracing -S | FileCheck %s --check-prefix=CHECK3
; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc -S | FileCheck %s --check-prefix=CHECK_PC
; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard -S | FileCheck %s --check-prefix=CHECK_PC_GUARD
; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard -S -mtriple=x86_64-apple-macosx | FileCheck %s --check-prefix=CHECK_PC_GUARD_DARWIN
Expand All @@ -20,19 +18,6 @@ entry:
ret void
}

; CHECK1-LABEL: define void @foo
; CHECK1: call void @__sanitizer_cov_trace_func_enter
; CHECK1: call void @__sanitizer_cov_trace_basic_block
; CHECK1-NOT: call void @__sanitizer_cov_trace_basic_block
; CHECK1: ret void

; CHECK3-LABEL: define void @foo
; CHECK3: call void @__sanitizer_cov_trace_func_enter
; CHECK3: call void @__sanitizer_cov_trace_basic_block
; CHECK3: call void @__sanitizer_cov_trace_basic_block
; CHECK3-NOT: call void @__sanitizer_cov_trace_basic_block
; CHECK3: ret void

; CHECK_PC-LABEL: define void @foo
; CHECK_PC: call void @__sanitizer_cov_trace_pc
; CHECK_PC: call void @__sanitizer_cov_trace_pc
Expand Down

0 comments on commit 06c0527

Please sign in to comment.