Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
Show First 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | PreservedAnalyses ModuleSanitizerCoveragePass::run(Module &M, | ||||
if (ModuleSancov.instrumentModule(M, DTCallback, PDTCallback)) | if (ModuleSancov.instrumentModule(M, DTCallback, PDTCallback)) | ||||
return PreservedAnalyses::none(); | return PreservedAnalyses::none(); | ||||
return PreservedAnalyses::all(); | return PreservedAnalyses::all(); | ||||
} | } | ||||
std::pair<Value *, Value *> | std::pair<Value *, Value *> | ||||
ModuleSanitizerCoverage::CreateSecStartEnd(Module &M, const char *Section, | ModuleSanitizerCoverage::CreateSecStartEnd(Module &M, const char *Section, | ||||
Type *Ty) { | Type *Ty) { | ||||
GlobalVariable *SecStart = | GlobalVariable *SecStart = new GlobalVariable( | ||||
new GlobalVariable(M, Ty, false, GlobalVariable::ExternalLinkage, nullptr, | M, Ty->getPointerElementType(), false, GlobalVariable::ExternalLinkage, | ||||
getSectionStart(Section)); | nullptr, getSectionStart(Section)); | ||||
SecStart->setVisibility(GlobalValue::HiddenVisibility); | SecStart->setVisibility(GlobalValue::HiddenVisibility); | ||||
GlobalVariable *SecEnd = | GlobalVariable *SecEnd = new GlobalVariable( | ||||
new GlobalVariable(M, Ty, false, GlobalVariable::ExternalLinkage, | M, Ty->getPointerElementType(), false, GlobalVariable::ExternalLinkage, | ||||
nullptr, getSectionEnd(Section)); | nullptr, getSectionEnd(Section)); | ||||
SecEnd->setVisibility(GlobalValue::HiddenVisibility); | SecEnd->setVisibility(GlobalValue::HiddenVisibility); | ||||
IRBuilder<> IRB(M.getContext()); | IRBuilder<> IRB(M.getContext()); | ||||
Value *SecEndPtr = IRB.CreatePointerCast(SecEnd, Ty); | |||||
if (!TargetTriple.isOSBinFormatCOFF()) | if (!TargetTriple.isOSBinFormatCOFF()) | ||||
return std::make_pair(IRB.CreatePointerCast(SecStart, Ty), SecEndPtr); | return std::make_pair(SecStart, SecEnd); | ||||
// Account for the fact that on windows-msvc __start_* symbols actually | // Account for the fact that on windows-msvc __start_* symbols actually | ||||
// point to a uint64_t before the start of the array. | // point to a uint64_t before the start of the array. | ||||
auto SecStartI8Ptr = IRB.CreatePointerCast(SecStart, Int8PtrTy); | auto SecStartI8Ptr = IRB.CreatePointerCast(SecStart, Int8PtrTy); | ||||
auto GEP = IRB.CreateGEP(Int8Ty, SecStartI8Ptr, | auto GEP = IRB.CreateGEP(Int8Ty, SecStartI8Ptr, | ||||
ConstantInt::get(IntptrTy, sizeof(uint64_t))); | ConstantInt::get(IntptrTy, sizeof(uint64_t))); | ||||
return std::make_pair(IRB.CreatePointerCast(GEP, Ty), SecEndPtr); | return std::make_pair(IRB.CreatePointerCast(GEP, Ty), SecEnd); | ||||
} | } | ||||
Function *ModuleSanitizerCoverage::CreateInitCallsForSections( | Function *ModuleSanitizerCoverage::CreateInitCallsForSections( | ||||
Module &M, const char *CtorName, const char *InitFunctionName, Type *Ty, | Module &M, const char *CtorName, const char *InitFunctionName, Type *Ty, | ||||
const char *Section) { | const char *Section) { | ||||
auto SecStartEnd = CreateSecStartEnd(M, Section, Ty); | auto SecStartEnd = CreateSecStartEnd(M, Section, Ty); | ||||
auto SecStart = SecStartEnd.first; | auto SecStart = SecStartEnd.first; | ||||
auto SecEnd = SecStartEnd.second; | auto SecEnd = SecStartEnd.second; | ||||
▲ Show 20 Lines • Show All 647 Lines • Show Last 20 Lines |