summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-09-27 01:08:33 +0000
committerKostya Serebryany <kcc@google.com>2016-09-27 01:08:33 +0000
commit186d61801c024f8b4c204dd4df6fafb50ef798ed (patch)
tree5221af51be62f79cd53bcf38665f4285fcef0fe4 /llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
parent4088571c51f108d42e9239e15673b32165fa16e9 (diff)
downloadbcm5719-llvm-186d61801c024f8b4c204dd4df6fafb50ef798ed.tar.gz
bcm5719-llvm-186d61801c024f8b4c204dd4df6fafb50ef798ed.zip
[sanitizer-coverage] don't emit the CTOR function if nothing has been instrumented
llvm-svn: 282465
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp')
-rw-r--r--llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp38
1 files changed, 21 insertions, 17 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index 9e1ff1cd6d2..4a1a75518b0 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -230,6 +230,7 @@ private:
GlobalVariable *GuardArray;
GlobalVariable *EightBitCounterArray;
+ bool HasSancovGuardsSection;
SanitizerCoverageOptions Options;
};
@@ -242,6 +243,7 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
C = &(M.getContext());
DL = &M.getDataLayout();
CurModule = &M;
+ HasSancovGuardsSection = false;
IntptrTy = Type::getIntNTy(*C, DL->getPointerSizeInBits());
IntptrPtrTy = PointerType::getUnqual(IntptrTy);
Type *VoidTy = Type::getVoidTy(*C);
@@ -351,24 +353,25 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
new GlobalVariable(M, ModNameStrConst->getType(), true,
GlobalValue::PrivateLinkage, ModNameStrConst);
if (Options.TracePCGuard) {
- Function *CtorFunc;
- std::string SectionName(SanCovTracePCGuardSection);
- GlobalVariable *Bounds[2];
- const char *Prefix[2] = {"__start_", "__stop_"};
- for (int i = 0; i < 2; i++) {
- Bounds[i] = new GlobalVariable(M, IntptrPtrTy, false,
- GlobalVariable::ExternalLinkage, nullptr,
- Prefix[i] + SectionName);
- Bounds[i]->setVisibility(GlobalValue::HiddenVisibility);
- }
- std::tie(CtorFunc, std::ignore) = createSanitizerCtorAndInitFunctions(
- M, SanCovModuleCtorName, SanCovTracePCGuardInitName,
- {IntptrPtrTy, IntptrPtrTy},
- {IRB.CreatePointerCast(Bounds[0], IntptrPtrTy),
- IRB.CreatePointerCast(Bounds[1], IntptrPtrTy)});
-
- appendToGlobalCtors(M, CtorFunc, SanCtorAndDtorPriority);
+ if (HasSancovGuardsSection) {
+ Function *CtorFunc;
+ std::string SectionName(SanCovTracePCGuardSection);
+ GlobalVariable *Bounds[2];
+ const char *Prefix[2] = {"__start_", "__stop_"};
+ for (int i = 0; i < 2; i++) {
+ Bounds[i] = new GlobalVariable(M, IntptrPtrTy, false,
+ GlobalVariable::ExternalLinkage, nullptr,
+ Prefix[i] + SectionName);
+ Bounds[i]->setVisibility(GlobalValue::HiddenVisibility);
+ }
+ std::tie(CtorFunc, std::ignore) = createSanitizerCtorAndInitFunctions(
+ M, SanCovModuleCtorName, SanCovTracePCGuardInitName,
+ {IntptrPtrTy, IntptrPtrTy},
+ {IRB.CreatePointerCast(Bounds[0], IntptrPtrTy),
+ IRB.CreatePointerCast(Bounds[1], IntptrPtrTy)});
+ appendToGlobalCtors(M, CtorFunc, SanCtorAndDtorPriority);
+ }
} else if (!Options.TracePC) {
Function *CtorFunc;
std::tie(CtorFunc, std::ignore) = createSanitizerCtorAndInitFunctions(
@@ -673,6 +676,7 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
GuardVar->setComdat(Comdat);
// TODO: add debug into to GuardVar.
GuardVar->setSection(SanCovTracePCGuardSection);
+ HasSancovGuardsSection = true;
auto GuardPtr = IRB.CreatePointerCast(GuardVar, IntptrPtrTy);
if (!UseCalls) {
auto GuardLoad = IRB.CreateLoad(GuardPtr);
OpenPOWER on IntegriCloud