From df54667cf480f24a11ea545fa2eb9b4ec6cdae4f Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Fri, 25 Aug 2017 19:29:47 +0000 Subject: [PATCH] [sanitizer-coverage] extend fsanitize-coverage=pc-table with flags for every PC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311794 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Instrumentation/SanitizerCoverage.cpp | 33 +++++++++++-------- .../SanitizerCoverage/pc-table.ll | 2 +- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/lib/Transforms/Instrumentation/SanitizerCoverage.cpp index fdf265143fd..870784dc483 100644 --- a/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ b/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -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; } @@ -545,17 +545,24 @@ void SanitizerCoverageModule::CreatePCArray(Function &F, ArrayRef AllBlocks) { size_t N = AllBlocks.size(); assert(N); - SmallVector PCs; + SmallVector 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 diff --git a/test/Instrumentation/SanitizerCoverage/pc-table.ll b/test/Instrumentation/SanitizerCoverage/pc-table.ll index 84d2fc4bdd8..7b9b2fa85b9 100644 --- a/test/Instrumentation/SanitizerCoverage/pc-table.ll +++ b/test/Instrumentation/SanitizerCoverage/pc-table.ll @@ -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 -- 2.50.1