GlobalVariable *GuardArray;
GlobalVariable *EightBitCounterArray;
+ bool HasSancovGuardsSection;
SanitizerCoverageOptions Options;
};
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);
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(
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);