Skip to content

Commit

Permalink
[sanitizer-coverage] extend fsanitize-coverage=pc-table with flags fo…
Browse files Browse the repository at this point in the history
…r every PC

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311794 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
kcc committed Aug 25, 2017
1 parent 0588b41 commit df54667
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
33 changes: 20 additions & 13 deletions lib/Transforms/Instrumentation/SanitizerCoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,13 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
Ctor = CreateInitCallsForSections(M, SanCov8bitCountersInitName, Int8PtrTy,
SanCovCountersSectionName);
if (Ctor && Options.PCTable) {
auto SecStartEnd = CreateSecStartEnd(M, SanCovPCsSectionName, Int8PtrTy);
auto SecStartEnd = CreateSecStartEnd(M, SanCovPCsSectionName, IntptrPtrTy);
Function *InitFunction = declareSanitizerInitFunction(
M, SanCovPCsInitName, {Int8PtrTy, Int8PtrTy});
M, SanCovPCsInitName, {IntptrPtrTy, IntptrPtrTy});
IRBuilder<> IRBCtor(Ctor->getEntryBlock().getTerminator());
IRBCtor.CreateCall(InitFunction,
{IRB.CreatePointerCast(SecStartEnd.first, Int8PtrTy),
IRB.CreatePointerCast(SecStartEnd.second, Int8PtrTy)});
{IRB.CreatePointerCast(SecStartEnd.first, IntptrPtrTy),
IRB.CreatePointerCast(SecStartEnd.second, IntptrPtrTy)});
}
return true;
}
Expand Down Expand Up @@ -545,17 +545,24 @@ void SanitizerCoverageModule::CreatePCArray(Function &F,
ArrayRef<BasicBlock *> AllBlocks) {
size_t N = AllBlocks.size();
assert(N);
SmallVector<Constant *, 16> PCs;
SmallVector<Constant *, 32> PCs;
IRBuilder<> IRB(&*F.getEntryBlock().getFirstInsertionPt());
for (size_t i = 0; i < N; i++)
if (&F.getEntryBlock() == AllBlocks[i])
PCs.push_back((Constant *)IRB.CreatePointerCast(&F, Int8PtrTy));
else
PCs.push_back(BlockAddress::get(AllBlocks[i]));
FunctionPCsArray =
CreateFunctionLocalArrayInSection(N, F, Int8PtrTy, SanCovPCsSectionName);
for (size_t i = 0; i < N; i++) {
if (&F.getEntryBlock() == AllBlocks[i]) {
PCs.push_back((Constant *)IRB.CreatePointerCast(&F, IntptrPtrTy));
PCs.push_back((Constant *)IRB.CreateIntToPtr(
ConstantInt::get(IntptrTy, 1), IntptrPtrTy));
} else {
PCs.push_back((Constant *)IRB.CreatePointerCast(
BlockAddress::get(AllBlocks[i]), IntptrPtrTy));
PCs.push_back((Constant *)IRB.CreateIntToPtr(
ConstantInt::get(IntptrTy, 0), IntptrPtrTy));
}
}
FunctionPCsArray = CreateFunctionLocalArrayInSection(N * 2, F, IntptrPtrTy,
SanCovPCsSectionName);
FunctionPCsArray->setInitializer(
ConstantArray::get(ArrayType::get(Int8PtrTy, N), PCs));
ConstantArray::get(ArrayType::get(IntptrPtrTy, N * 2), PCs));
FunctionPCsArray->setConstant(true);

// We don't reference the PCs array in any of our runtime functions, so we
Expand Down
2 changes: 1 addition & 1 deletion test/Instrumentation/SanitizerCoverage/pc-table.ll
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ entry:
ret void
}

; CHECK: private constant [3 x i8*] [{{.*}}@foo{{.*}}blockaddress{{.*}}blockaddress{{.*}}], section "__sancov_pcs", align 8
; CHECK: private constant [6 x i64*] [{{.*}}@foo{{.*}}blockaddress{{.*}}blockaddress{{.*}}], section "__sancov_pcs", align 8
; CHECK: define internal void @sancov.module_ctor
; CHECK: call void @__sanitizer_cov
; CHECK: call void @__sanitizer_cov_pcs_init

0 comments on commit df54667

Please sign in to comment.