43#define DEBUG_TYPE "sancov"
72 "sancov.module_ctor_trace_pc_guard";
74 "sancov.module_ctor_8bit_counters";
97 "sanitizer-coverage-level",
98 cl::desc(
"Sanitizer Coverage. 0: none, 1: entry block, 2: all blocks, "
99 "3: all blocks and critical edges"),
106 "sanitizer-coverage-trace-pc-entry-exit",
110 cl::desc(
"pc tracing with a guard"),
120 cl::desc(
"create a static PC table"),
125 cl::desc(
"increments 8-bit counter for every edge"),
130 cl::desc(
"do not emit module ctors for global counters"),
135 cl::desc(
"sets a boolean flag for every edge"),
140 cl::desc(
"Tracing of CMP and similar instructions"),
144 cl::desc(
"Tracing of DIV instructions"),
148 cl::desc(
"Tracing of load instructions"),
152 cl::desc(
"Tracing of store instructions"),
156 cl::desc(
"Tracing of GEP instructions"),
161 cl::desc(
"Reduce the number of instrumented blocks"),
165 cl::desc(
"max stack depth tracing"),
169 "sanitizer-coverage-stack-depth-callback-min",
170 cl::desc(
"max stack depth tracing should use callback and only when "
171 "stack depth more than specified"),
179 "sanitizer-coverage-gated-trace-callbacks",
180 cl::desc(
"Gate the invocation of the tracing callbacks on a global variable"
181 ". Currently only supported for trace-pc-guard and trace-cmp."),
188 switch (LegacyCoverageLevel) {
225 Options.StackDepthCallbackMin = std::max(
Options.StackDepthCallbackMin,
238class ModuleSanitizerCoverage {
240 using DomTreeCallback = function_ref<
const DominatorTree &(
Function &
F)>;
241 using PostDomTreeCallback =
242 function_ref<
const PostDominatorTree &(
Function &
F)>;
244 ModuleSanitizerCoverage(
Module &M, DomTreeCallback DTCallback,
245 PostDomTreeCallback PDTCallback,
246 const SanitizerCoverageOptions &Options,
247 const SpecialCaseList *Allowlist,
248 const SpecialCaseList *Blocklist)
249 : M(M), DTCallback(DTCallback), PDTCallback(PDTCallback),
250 Options(Options), Allowlist(Allowlist), Blocklist(Blocklist) {}
252 bool instrumentModule();
255 void createFunctionControlFlow(Function &
F);
256 void instrumentFunction(Function &
F);
257 void InjectCoverageForIndirectCalls(Function &
F,
260 Value *&FunctionGateCmp);
261 void InjectTraceForDiv(Function &
F,
263 void InjectTraceForGep(Function &
F,
267 void InjectTraceForExits(Function &
F);
268 void InjectTraceForSwitch(Function &
F,
270 Value *&FunctionGateCmp);
272 Value *&FunctionGateCmp,
bool IsLeafFunc);
273 GlobalVariable *CreateFunctionLocalArrayInSection(
size_t NumElements,
274 Function &
F,
Type *Ty,
275 const char *Section);
281 void InjectCoverageAtBlock(Function &
F, BasicBlock &BB,
size_t Idx,
282 Value *&FunctionGateCmp,
bool IsLeafFunc);
283 Function *CreateInitCallsForSections(
Module &M,
const char *CtorName,
284 const char *InitFunctionName,
Type *Ty,
285 const char *Section);
286 std::pair<Value *, Value *> CreateSecStartEnd(
Module &M,
const char *Section,
290 std::string getSectionStart(
const std::string &Section)
const;
291 std::string getSectionEnd(
const std::string &Section)
const;
294 DomTreeCallback DTCallback;
295 PostDomTreeCallback PDTCallback;
297 FunctionCallee SanCovStackDepthCallback;
298 FunctionCallee SanCovTracePCIndir;
299 FunctionCallee SanCovTracePC, SanCovTracePCGuard;
300 FunctionCallee SanCovTracePCEntry, SanCovTracePCExit;
301 std::array<FunctionCallee, 4> SanCovTraceCmpFunction;
302 std::array<FunctionCallee, 4> SanCovTraceConstCmpFunction;
303 std::array<FunctionCallee, 5> SanCovLoadFunction;
304 std::array<FunctionCallee, 5> SanCovStoreFunction;
305 std::array<FunctionCallee, 2> SanCovTraceDivFunction;
306 FunctionCallee SanCovTraceGepFunction;
307 FunctionCallee SanCovTraceSwitchFunction;
308 GlobalVariable *SanCovLowestStack;
309 GlobalVariable *SanCovCallbackGate;
310 Type *PtrTy, *IntptrTy, *Int64Ty, *Int32Ty, *Int16Ty, *Int8Ty, *Int1Ty;
314 const DataLayout *DL;
316 GlobalVariable *FunctionGuardArray;
317 GlobalVariable *Function8bitCounterArray;
318 GlobalVariable *FunctionBoolArray;
319 GlobalVariable *FunctionPCsArray;
320 GlobalVariable *FunctionCFsArray;
324 SanitizerCoverageOptions Options;
326 const SpecialCaseList *Allowlist;
327 const SpecialCaseList *Blocklist;
333 const std::vector<std::string> &AllowlistFiles,
334 const std::vector<std::string> &BlocklistFiles)
336 VFS(VFS ?
std::
move(VFS) :
vfs::getRealFileSystem()) {
337 if (AllowlistFiles.size() > 0)
339 if (BlocklistFiles.size() > 0)
352 ModuleSanitizerCoverage ModuleSancov(M, DTCallback, PDTCallback,
353 OverrideFromCL(Options), Allowlist.get(),
355 if (!ModuleSancov.instrumentModule())
366std::pair<Value *, Value *>
367ModuleSanitizerCoverage::CreateSecStartEnd(
Module &M,
const char *Section,
377 getSectionStart(Section));
380 getSectionEnd(Section));
383 if (!TargetTriple.isOSBinFormatCOFF())
384 return std::make_pair(SecStart, SecEnd);
389 IRB.CreatePtrAdd(SecStart, ConstantInt::get(IntptrTy,
sizeof(
uint64_t)));
390 return std::make_pair(
GEP, SecEnd);
393Function *ModuleSanitizerCoverage::CreateInitCallsForSections(
394 Module &M,
const char *CtorName,
const char *InitFunctionName,
Type *Ty,
395 const char *Section) {
398 auto SecStartEnd = CreateSecStartEnd(M, Section, Ty);
399 auto SecStart = SecStartEnd.first;
400 auto SecEnd = SecStartEnd.second;
403 M, CtorName, InitFunctionName, {PtrTy, PtrTy}, {SecStart, SecEnd});
406 if (TargetTriple.supportsCOMDAT()) {
408 CtorFunc->
setComdat(
M.getOrInsertComdat(CtorName));
414 if (TargetTriple.isOSBinFormatCOFF()) {
426bool ModuleSanitizerCoverage::instrumentModule() {
430 !Allowlist->inSection(
"coverage",
"src",
M.getSourceFileName()))
433 Blocklist->inSection(
"coverage",
"src",
M.getSourceFileName()))
435 C = &(
M.getContext());
436 DL = &
M.getDataLayout();
438 TargetTriple =
M.getTargetTriple();
439 FunctionGuardArray =
nullptr;
440 Function8bitCounterArray =
nullptr;
441 FunctionBoolArray =
nullptr;
442 FunctionPCsArray =
nullptr;
443 FunctionCFsArray =
nullptr;
448 Int64Ty = IRB.getInt64Ty();
450 Int16Ty = IRB.getInt16Ty();
451 Int8Ty = IRB.getInt8Ty();
452 Int1Ty = IRB.getInt1Ty();
458 AttributeList SanCovTraceCmpZeroExtAL;
459 SanCovTraceCmpZeroExtAL =
460 SanCovTraceCmpZeroExtAL.addParamAttribute(*
C, 0, Attribute::ZExt);
461 SanCovTraceCmpZeroExtAL =
462 SanCovTraceCmpZeroExtAL.addParamAttribute(*
C, 1, Attribute::ZExt);
464 SanCovTraceCmpFunction[0] =
466 IRB.getInt8Ty(), IRB.getInt8Ty());
467 SanCovTraceCmpFunction[1] =
469 IRB.getInt16Ty(), IRB.getInt16Ty());
470 SanCovTraceCmpFunction[2] =
472 IRB.getInt32Ty(), IRB.getInt32Ty());
473 SanCovTraceCmpFunction[3] =
476 SanCovTraceConstCmpFunction[0] =
M.getOrInsertFunction(
478 SanCovTraceConstCmpFunction[1] =
M.getOrInsertFunction(
480 SanCovTraceConstCmpFunction[2] =
M.getOrInsertFunction(
482 SanCovTraceConstCmpFunction[3] =
486 SanCovLoadFunction[0] =
M.getOrInsertFunction(
SanCovLoad1, VoidTy, PtrTy);
487 SanCovLoadFunction[1] =
M.getOrInsertFunction(
SanCovLoad2, VoidTy, PtrTy);
488 SanCovLoadFunction[2] =
M.getOrInsertFunction(
SanCovLoad4, VoidTy, PtrTy);
489 SanCovLoadFunction[3] =
M.getOrInsertFunction(
SanCovLoad8, VoidTy, PtrTy);
490 SanCovLoadFunction[4] =
M.getOrInsertFunction(
SanCovLoad16, VoidTy, PtrTy);
492 SanCovStoreFunction[0] =
M.getOrInsertFunction(
SanCovStore1, VoidTy, PtrTy);
493 SanCovStoreFunction[1] =
M.getOrInsertFunction(
SanCovStore2, VoidTy, PtrTy);
494 SanCovStoreFunction[2] =
M.getOrInsertFunction(
SanCovStore4, VoidTy, PtrTy);
495 SanCovStoreFunction[3] =
M.getOrInsertFunction(
SanCovStore8, VoidTy, PtrTy);
496 SanCovStoreFunction[4] =
M.getOrInsertFunction(
SanCovStore16, VoidTy, PtrTy);
500 AL =
AL.addParamAttribute(*
C, 0, Attribute::ZExt);
501 SanCovTraceDivFunction[0] =
504 SanCovTraceDivFunction[1] =
506 SanCovTraceGepFunction =
508 SanCovTraceSwitchFunction =
512 if (SanCovLowestStack->getValueType() != IntptrTy) {
514 "' should not be declared by the user");
517 SanCovLowestStack->setThreadLocalMode(
519 if (
Options.StackDepth && !SanCovLowestStack->isDeclaration())
525 "' is only supported with trace-pc-guard or trace-cmp");
531 SanCovCallbackGate->setSection(
545 SanCovStackDepthCallback =
549 instrumentFunction(
F);
553 if (FunctionGuardArray)
557 if (Function8bitCounterArray)
561 if (FunctionBoolArray) {
571 IRBCtor.CreateCall(InitFunction, {SecStartEnd.first, SecStartEnd.second});
574 if (Ctor &&
Options.CollectControlFlow) {
579 IRBCtor.CreateCall(InitFunction, {SecStartEnd.first, SecStartEnd.second});
625 if (
Options.NoPrune || &
F.getEntryBlock() == BB)
629 &
F.getEntryBlock() != BB)
668void ModuleSanitizerCoverage::instrumentFunction(
Function &
F) {
671 if (
F.getName().contains(
".module_ctor"))
673 if (
F.getName().starts_with(
"__sanitizer_"))
680 if (
F.getName() ==
"__local_stdio_printf_options" ||
681 F.getName() ==
"__local_stdio_scanf_options")
688 if (
F.hasPersonalityFn() &&
691 if (Allowlist && !Allowlist->inSection(
"coverage",
"fun",
F.getName()))
693 if (Blocklist && Blocklist->inSection(
"coverage",
"fun",
F.getName()))
696 if (
F.hasFnAttribute(Attribute::Naked))
698 if (
F.hasFnAttribute(Attribute::NoSanitizeCoverage))
700 if (
F.hasFnAttribute(Attribute::DisableSanitizerInstrumentation))
717 bool IsLeafFunc =
true;
722 for (
auto &Inst : BB) {
737 if (BO->getOpcode() == Instruction::SDiv ||
738 BO->getOpcode() == Instruction::UDiv)
756 if (
Options.CollectControlFlow)
757 createFunctionControlFlow(
F);
759 Value *FunctionGateCmp =
nullptr;
760 InjectCoverage(
F, BlocksToInstrument, FunctionGateCmp, IsLeafFunc);
761 InjectCoverageForIndirectCalls(
F, IndirCalls);
762 InjectTraceForCmp(
F, CmpTraceTargets, FunctionGateCmp);
763 InjectTraceForSwitch(
F, SwitchTraceTargets, FunctionGateCmp);
764 InjectTraceForDiv(
F, DivTraceTargets);
765 InjectTraceForGep(
F, GepTraceTargets);
766 InjectTraceForLoadsAndStores(
F, Loads, Stores);
769 InjectTraceForExits(
F);
772GlobalVariable *ModuleSanitizerCoverage::CreateFunctionLocalArrayInSection(
773 size_t NumElements,
Function &
F,
Type *Ty,
const char *Section) {
779 if (TargetTriple.supportsCOMDAT() &&
780 (
F.hasComdat() || TargetTriple.isOSBinFormatELF() || !
F.isInterposable()))
784 Array->setAlignment(
Align(
DL->getTypeStoreSize(Ty).getFixedValue()));
795 if (
Array->hasComdat())
796 GlobalsToAppendToCompilerUsed.push_back(Array);
798 GlobalsToAppendToUsed.push_back(Array);
804ModuleSanitizerCoverage::CreatePCArray(
Function &
F,
806 size_t N = AllBlocks.
size();
809 IRBuilder<> IRB(&*
F.getEntryBlock().getFirstInsertionPt());
810 for (
size_t i = 0; i <
N; i++) {
811 if (&
F.getEntryBlock() == AllBlocks[i]) {
814 (
Constant *)IRB.CreateIntToPtr(ConstantInt::get(IntptrTy, 1), PtrTy));
823 PCArray->setInitializer(
825 PCArray->setConstant(
true);
830void ModuleSanitizerCoverage::CreateFunctionLocalArrays(
833 FunctionGuardArray = CreateFunctionLocalArrayInSection(
836 if (
Options.Inline8bitCounters)
837 Function8bitCounterArray = CreateFunctionLocalArrayInSection(
840 FunctionBoolArray = CreateFunctionLocalArrayInSection(
844 FunctionPCsArray = CreatePCArray(
F, AllBlocks);
847Value *ModuleSanitizerCoverage::CreateFunctionLocalGateCmp(
IRBuilder<> &IRB) {
849 Load->setNoSanitizeMetadata();
851 Cmp->setName(
"sancov gate cmp");
856 Value *&FunctionGateCmp,
858 if (!FunctionGateCmp) {
864 FunctionGateCmp = CreateFunctionLocalGateCmp(EntryIRB);
873bool ModuleSanitizerCoverage::InjectCoverage(
Function &
F,
875 Value *&FunctionGateCmp,
877 if (AllBlocks.
empty())
879 CreateFunctionLocalArrays(
F, AllBlocks);
880 for (
size_t i = 0,
N = AllBlocks.
size(); i <
N; i++)
881 InjectCoverageAtBlock(
F, *AllBlocks[i], i, FunctionGateCmp, IsLeafFunc);
893void ModuleSanitizerCoverage::InjectCoverageForIndirectCalls(
895 if (IndirCalls.
empty())
899 for (
auto *
I : IndirCalls) {
913void ModuleSanitizerCoverage::InjectTraceForSwitch(
915 Value *&FunctionGateCmp) {
916 for (
auto *
I : SwitchTraceTargets) {
921 if (
Cond->getType()->getScalarSizeInBits() >
922 Int64Ty->getScalarSizeInBits())
924 Initializers.
push_back(ConstantInt::get(Int64Ty,
SI->getNumCases()));
926 ConstantInt::get(Int64Ty,
Cond->getType()->getScalarSizeInBits()));
927 if (
Cond->getType()->getScalarSizeInBits() <
928 Int64Ty->getScalarSizeInBits())
930 for (
auto It :
SI->cases()) {
932 if (
C->getType()->getScalarSizeInBits() < 64)
933 C = ConstantInt::get(
C->getContext(),
C->getValue().zext(64));
945 "__sancov_gen_cov_switch_values");
947 auto GateBranch = CreateGateBranch(
F, FunctionGateCmp,
I);
949 GateIRB.CreateCall(SanCovTraceSwitchFunction, {
Cond, GV});
957void ModuleSanitizerCoverage::InjectTraceForDiv(
959 for (
auto *BO : DivTraceTargets) {
961 Value *A1 = BO->getOperand(1);
971 IRB.
CreateCall(SanCovTraceDivFunction[CallbackIdx],
976void ModuleSanitizerCoverage::InjectTraceForGep(
978 for (
auto *
GEP : GepTraceTargets) {
980 for (
Use &Idx :
GEP->indices())
987void ModuleSanitizerCoverage::InjectTraceForLoadsAndStores(
989 auto CallbackIdx = [&](
Type *ElementTy) ->
int {
990 uint64_t
TypeSize =
DL->getTypeStoreSizeInBits(ElementTy);
998 for (
auto *LI : Loads) {
1000 auto Ptr = LI->getPointerOperand();
1001 int Idx = CallbackIdx(LI->getType());
1004 IRB.
CreateCall(SanCovLoadFunction[Idx], Ptr);
1006 for (
auto *
SI : Stores) {
1008 auto Ptr =
SI->getPointerOperand();
1009 int Idx = CallbackIdx(
SI->getValueOperand()->getType());
1012 IRB.
CreateCall(SanCovStoreFunction[Idx], Ptr);
1016void ModuleSanitizerCoverage::InjectTraceForExits(
Function &
F) {
1020 AtExit->CreateCall(SanCovTracePCExit, {})
1025void ModuleSanitizerCoverage::InjectTraceForCmp(
1027 Value *&FunctionGateCmp) {
1028 for (
auto *
I : CmpTraceTargets) {
1031 Value *A0 = ICMP->getOperand(0);
1032 Value *A1 = ICMP->getOperand(1);
1036 int CallbackIdx =
TypeSize == 8 ? 0
1041 if (CallbackIdx < 0)
1044 auto CallbackFunc = SanCovTraceCmpFunction[CallbackIdx];
1048 if (FirstIsConst && SecondIsConst)
1051 if (FirstIsConst || SecondIsConst) {
1052 CallbackFunc = SanCovTraceConstCmpFunction[CallbackIdx];
1059 auto GateBranch = CreateGateBranch(
F, FunctionGateCmp,
I);
1061 GateIRB.CreateCall(CallbackFunc, {GateIRB.CreateIntCast(A0, Ty,
true),
1062 GateIRB.CreateIntCast(A1, Ty,
true)});
1073 Value *&FunctionGateCmp,
1076 bool IsEntryBB = &BB == &
F.getEntryBlock();
1079 if (
auto SP =
F.getSubprogram())
1090 if (
Options.TracePC || (IsEntryBB &&
Options.TracePCEntryExit)) {
1092 ? SanCovTracePCEntry
1099 FunctionGuardArray->getValueType(), FunctionGuardArray, 0, Idx);
1102 auto GateBranch = CreateGateBranch(
F, FunctionGateCmp,
I);
1104 GateIRB.CreateCall(SanCovTracePCGuard, GuardPtr)->setCannotMerge();
1109 if (
Options.Inline8bitCounters) {
1111 Function8bitCounterArray->getValueType(), Function8bitCounterArray,
1112 {ConstantInt::get(IntptrTy, 0), ConstantInt::get(IntptrTy, Idx)});
1114 auto Inc = IRB.
CreateAdd(Load, ConstantInt::get(Int8Ty, 1));
1116 Load->setNoSanitizeMetadata();
1117 Store->setNoSanitizeMetadata();
1121 FunctionBoolArray->getValueType(), FunctionBoolArray,
1122 {ConstantInt::get(IntptrTy, 0), ConstantInt::get(IntptrTy, Idx)});
1130 Store->setDebugLoc(EntryLoc);
1131 Load->setNoSanitizeMetadata();
1132 Store->setNoSanitizeMetadata();
1134 if (
Options.StackDepth && IsEntryBB && !IsLeafFunc) {
1138 if (
Options.StackDepthCallbackMin) {
1140 int EstimatedStackSize = 0;
1142 bool HasDynamicAlloc =
false;
1149 for (
auto &
I : BB) {
1155 if (
auto AllocaSize = AI->getAllocationSize(
DL)) {
1156 if (AllocaSize->isFixed())
1157 EstimatedStackSize += AllocaSize->getFixedValue();
1159 HasDynamicAlloc =
true;
1161 HasDynamicAlloc =
true;
1166 if (HasDynamicAlloc ||
1167 EstimatedStackSize >=
Options.StackDepthCallbackMin) {
1178 Intrinsic::frameaddress, IRB.
getPtrTy(
DL.getAllocaAddrSpace()),
1179 {Constant::getNullValue(Int32Ty)});
1181 auto LowestStack = IRB.
CreateLoad(IntptrTy, SanCovLowestStack);
1182 auto IsStackLower = IRB.
CreateICmpULT(FrameAddrInt, LowestStack);
1184 IsStackLower, &*IP,
false,
1187 auto Store = ThenIRB.CreateStore(FrameAddrInt, SanCovLowestStack);
1189 Store->setDebugLoc(EntryLoc);
1190 LowestStack->setNoSanitizeMetadata();
1191 Store->setNoSanitizeMetadata();
1197ModuleSanitizerCoverage::getSectionName(
const std::string &Section)
const {
1198 if (TargetTriple.isOSBinFormatCOFF()) {
1207 if (TargetTriple.isOSBinFormatMachO())
1213ModuleSanitizerCoverage::getSectionStart(
const std::string &Section)
const {
1214 if (TargetTriple.isOSBinFormatMachO())
1215 return "\1section$start$__DATA$__" +
Section;
1216 return "__start___" +
Section;
1220ModuleSanitizerCoverage::getSectionEnd(
const std::string &Section)
const {
1221 if (TargetTriple.isOSBinFormatMachO())
1222 return "\1section$end$__DATA$__" +
Section;
1226void ModuleSanitizerCoverage::createFunctionControlFlow(
Function &
F) {
1228 IRBuilder<> IRB(&*
F.getEntryBlock().getFirstInsertionPt());
1230 for (
auto &BB :
F) {
1232 if (&BB == &
F.getEntryBlock())
1239 assert(SuccBB != &
F.getEntryBlock());
1246 for (
auto &Inst : BB) {
1254 if (CalledF && !CalledF->isIntrinsic())
1263 FunctionCFsArray = CreateFunctionLocalArrayInSection(CFs.
size(),
F, PtrTy,
1265 FunctionCFsArray->setInitializer(
1267 FunctionCFsArray->setConstant(
true);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This is the interface for a simple mod/ref and alias analysis over globals.
Module.h This file contains the declarations for the Module class.
Machine Check Debug Module
static cl::opt< bool > SplitAllCriticalEdges("phi-elim-split-all-critical-edges", cl::init(false), cl::Hidden, cl::desc("Split all critical edges during " "PHI elimination"))
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
const SmallVectorImpl< MachineOperand > & Cond
static cl::opt< bool > ClLoadTracing("sanitizer-coverage-trace-loads", cl::desc("Tracing of load instructions"), cl::Hidden)
const char SanCovCFsSectionName[]
static bool isFullPostDominator(const BasicBlock *BB, const PostDominatorTree &PDT)
static cl::opt< int > ClCoverageLevel("sanitizer-coverage-level", cl::desc("Sanitizer Coverage. 0: none, 1: entry block, 2: all blocks, " "3: all blocks and critical edges"), cl::Hidden)
static cl::opt< bool > ClSancovDropCtors("sanitizer-coverage-drop-ctors", cl::desc("do not emit module ctors for global counters"), cl::Hidden)
static cl::opt< bool > ClStackDepth("sanitizer-coverage-stack-depth", cl::desc("max stack depth tracing"), cl::Hidden)
static cl::opt< bool > ClTracePCEntryExit("sanitizer-coverage-trace-pc-entry-exit", cl::desc("pc tracing with separate entry/exit callbacks"), cl::Hidden)
static cl::opt< bool > ClInlineBoolFlag("sanitizer-coverage-inline-bool-flag", cl::desc("sets a boolean flag for every edge"), cl::Hidden)
const char SanCovTraceConstCmp4[]
const char SanCovBoolFlagSectionName[]
const char SanCov8bitCountersInitName[]
const char SanCovTracePCEntryName[]
const char SanCovTraceSwitchName[]
const char SanCovTraceCmp1[]
const char SanCovModuleCtorTracePcGuardName[]
const char SanCovCountersSectionName[]
static cl::opt< bool > ClCreatePCTable("sanitizer-coverage-pc-table", cl::desc("create a static PC table"), cl::Hidden)
const char SanCovPCsInitName[]
const char SanCovTracePCGuardName[]
static cl::opt< int > ClStackDepthCallbackMin("sanitizer-coverage-stack-depth-callback-min", cl::desc("max stack depth tracing should use callback and only when " "stack depth more than specified"), cl::Hidden)
const char SanCovModuleCtor8bitCountersName[]
const char SanCovTracePCGuardInitName[]
static cl::opt< bool > ClCollectCF("sanitizer-coverage-control-flow", cl::desc("collect control flow for each function"), cl::Hidden)
const char SanCovTraceDiv4[]
static const uint64_t SanCtorAndDtorPriority
const char SanCovBoolFlagInitName[]
static cl::opt< bool > ClGatedCallbacks("sanitizer-coverage-gated-trace-callbacks", cl::desc("Gate the invocation of the tracing callbacks on a global variable" ". Currently only supported for trace-pc-guard and trace-cmp."), cl::Hidden, cl::init(false))
const char SanCovTraceGep[]
const char SanCovLoad16[]
const char SanCovTraceConstCmp8[]
const char SanCovGuardsSectionName[]
const char SanCovStore1[]
const char SanCovTraceConstCmp2[]
const char SanCovTraceConstCmp1[]
static bool IsBackEdge(BasicBlock *From, BasicBlock *To, const DominatorTree &DT)
static cl::opt< bool > ClStoreTracing("sanitizer-coverage-trace-stores", cl::desc("Tracing of store instructions"), cl::Hidden)
const char SanCovCallbackGateName[]
static cl::opt< bool > ClTracePCGuard("sanitizer-coverage-trace-pc-guard", cl::desc("pc tracing with a guard"), cl::Hidden)
const char SanCovTraceDiv8[]
static cl::opt< bool > ClGEPTracing("sanitizer-coverage-trace-geps", cl::desc("Tracing of GEP instructions"), cl::Hidden)
const char SanCovStackDepthCallbackName[]
const char SanCovCFsInitName[]
static cl::opt< bool > ClTracePC("sanitizer-coverage-trace-pc", cl::desc("Experimental pc tracing"), cl::Hidden)
const char SanCovStore2[]
static cl::opt< bool > ClPruneBlocks("sanitizer-coverage-prune-blocks", cl::desc("Reduce the number of instrumented blocks"), cl::Hidden, cl::init(true))
const char SanCovPCsSectionName[]
const char SanCovTracePCExitName[]
static bool isFullDominator(const BasicBlock *BB, const DominatorTree &DT)
static cl::opt< bool > ClCMPTracing("sanitizer-coverage-trace-compares", cl::desc("Tracing of CMP and similar instructions"), cl::Hidden)
const char SanCovTraceCmp8[]
const char SanCovCallbackGateSectionName[]
const char SanCovStore16[]
static bool IsInterestingCmp(ICmpInst *CMP, const DominatorTree &DT, const SanitizerCoverageOptions &Options)
static cl::opt< bool > ClDIVTracing("sanitizer-coverage-trace-divs", cl::desc("Tracing of DIV instructions"), cl::Hidden)
static cl::opt< bool > ClInline8bitCounters("sanitizer-coverage-inline-8bit-counters", cl::desc("increments 8-bit counter for every edge"), cl::Hidden)
static bool shouldInstrumentBlock(const Function &F, const BasicBlock *BB, const DominatorTree &DT, const PostDominatorTree &PDT, const SanitizerCoverageOptions &Options)
const char SanCovModuleCtorBoolFlagName[]
const char SanCovTraceCmp2[]
const char SanCovStore8[]
const char SanCovTracePCName[]
const char SanCovStore4[]
const char SanCovTraceCmp4[]
const char SanCovLowestStackName[]
const char SanCovTracePCIndirName[]
This file defines the SmallVector class.
Defines the virtual file system interface vfs::FileSystem.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
Class to represent array types.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
LLVM Basic Block Representation.
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
LLVM_ABI const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
LLVM_ABI const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
InstListType::iterator iterator
Instruction iterators...
LLVM_ABI InstListType::const_iterator getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode, a debug intrinsic,...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
static LLVM_ABI BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
LLVM_ABI bool isIndirectCall() const
Return true if the callsite is an indirect call.
Value * getCalledOperand() const
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
This is the shared class of boolean and integer constants.
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
This is an important base class in LLVM.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
EscapeEnumerator - This is a little algorithm to find all escape points from a function so that "fina...
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
const BasicBlock & getEntryBlock() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
LLVM_ABI void setComdat(Comdat *C)
void setLinkage(LinkageTypes LT)
@ HiddenVisibility
The GV is hidden.
void setVisibility(VisibilityTypes V)
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
Analysis pass providing a never-invalidated alias analysis result.
This instruction compares its operands according to the predicate given to the constructor.
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
void SetCurrentDebugLocation(DebugLoc L)
Set location information used by debugging information.
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
LLVM_ABI CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
LLVMContext & getContext() const
Value * CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name="")
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg != 0.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Value * CreateIsNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg == 0.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
An instruction for reading from memory.
LLVM_ABI MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight, bool IsExpected=false)
Return metadata containing two branch weights.
LLVM_ABI MDNode * createUnlikelyBranchWeights()
Return metadata containing two branch weights, with significant bias towards false destination.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
A Module instance is used to store all the information related to an LLVM module.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Analysis pass which computes a PostDominatorTree.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
LLVM_ABI bool dominates(const Instruction *I1, const Instruction *I2) const
Return true if I1 dominates I2.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & abandon()
Mark an analysis as abandoned.
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
LLVM_ABI SanitizerCoveragePass(SanitizerCoverageOptions Options=SanitizerCoverageOptions(), IntrusiveRefCntPtr< vfs::FileSystem > VFS=nullptr, const std::vector< std::string > &AllowlistFiles={}, const std::vector< std::string > &BlocklistFiles={})
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static LLVM_ABI std::unique_ptr< SpecialCaseList > createOrDie(const std::vector< std::string > &Paths, llvm::vfs::FileSystem &FS)
Parses the special case list entries from files.
An instruction for storing to memory.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
bool hasOneUse() const
Return true if there is exactly one use of this value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
static constexpr const StringLiteral & getSectionName(DebugSectionKind SectionKind)
Return the name of the section.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
FunctionAddr VTableAddr Value
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
bool succ_empty(const Instruction *I)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
FunctionAddr VTableAddr uintptr_t uintptr_t Int32Ty
auto successors(const MachineBasicBlock *BB)
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
LLVM_ABI FunctionCallee declareSanitizerInitFunction(Module &M, StringRef InitName, ArrayRef< Type * > InitArgTypes, bool Weak=false)
LLVM_ABI std::pair< Function *, FunctionCallee > createSanitizerCtorAndInitFunctions(Module &M, StringRef CtorName, StringRef InitName, ArrayRef< Type * > InitArgTypes, ArrayRef< Value * > InitArgs, StringRef VersionCheckName=StringRef(), bool Weak=false)
Creates sanitizer constructor function, and calls sanitizer's init function from it.
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI Comdat * getOrCreateFunctionComdat(Function &F, Triple &T)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
LLVM_ABI void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
FunctionAddr VTableAddr Next
ArrayRef(const T &OneElt) -> ArrayRef< T >
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void appendToGlobalCtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Append F to the list of global ctors of module M with the given Priority.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto predecessors(const MachineBasicBlock *BB)
bool pred_empty(const BasicBlock *BB)
LLVM_ABI BasicBlock::iterator PrepareToSplitEntryBlock(BasicBlock &BB, BasicBlock::iterator IP)
Instrumentation passes often insert conditional checks into entry blocks.
LLVM_ABI Instruction * SplitBlockAndInsertIfThen(Value *Cond, BasicBlock::iterator SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
LLVM_ABI void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Implement std::hash so that hash_code can be used in STL containers.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Option class for critical edge splitting.
static void ensureDebugInfo(IRBuilder<> &IRB, const Function &F)
enum llvm::SanitizerCoverageOptions::Type CoverageType