@@ -138,24 +138,6 @@ static cl::opt<bool> ClUse8bitCounters("sanitizer-coverage-8bit-counters",
138
138
cl::desc (" Experimental 8-bit counters" ),
139
139
cl::Hidden, cl::init(false ));
140
140
141
- static StringRef getSanCovTracePCGuardSection (const Module &M) {
142
- return Triple (M.getTargetTriple ()).isOSBinFormatMachO ()
143
- ? " __DATA,__sancov_guards"
144
- : " __sancov_guards" ;
145
- }
146
-
147
- static StringRef getSanCovTracePCGuardSectionStart (const Module &M) {
148
- return Triple (M.getTargetTriple ()).isOSBinFormatMachO ()
149
- ? " \1 section$start$__DATA$__sancov_guards"
150
- : " __start___sancov_guards" ;
151
- }
152
-
153
- static StringRef getSanCovTracePCGuardSectionEnd (const Module &M) {
154
- return Triple (M.getTargetTriple ()).isOSBinFormatMachO ()
155
- ? " \1 section$end$__DATA$__sancov_guards"
156
- : " __stop___sancov_guards" ;
157
- }
158
-
159
141
namespace {
160
142
161
143
SanitizerCoverageOptions getOptions (int LegacyCoverageLevel) {
@@ -233,6 +215,9 @@ class SanitizerCoverageModule : public ModulePass {
233
215
SanCovWithCheckFunction->getNumUses () + SanCovTraceBB->getNumUses () +
234
216
SanCovTraceEnter->getNumUses ();
235
217
}
218
+ StringRef getSanCovTracePCGuardSection () const ;
219
+ StringRef getSanCovTracePCGuardSectionStart () const ;
220
+ StringRef getSanCovTracePCGuardSectionEnd () const ;
236
221
Function *SanCovFunction;
237
222
Function *SanCovWithCheckFunction;
238
223
Function *SanCovIndirCallFunction, *SanCovTracePCIndir;
@@ -244,6 +229,7 @@ class SanitizerCoverageModule : public ModulePass {
244
229
InlineAsm *EmptyAsm;
245
230
Type *IntptrTy, *IntptrPtrTy, *Int64Ty, *Int64PtrTy, *Int32Ty, *Int32PtrTy;
246
231
Module *CurModule;
232
+ Triple TargetTriple;
247
233
LLVMContext *C;
248
234
const DataLayout *DL;
249
235
@@ -263,6 +249,7 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
263
249
C = &(M.getContext ());
264
250
DL = &M.getDataLayout ();
265
251
CurModule = &M;
252
+ TargetTriple = Triple (M.getTargetTriple ());
266
253
HasSancovGuardsSection = false ;
267
254
IntptrTy = Type::getIntNTy (*C, DL->getPointerSizeInBits ());
268
255
IntptrPtrTy = PointerType::getUnqual (IntptrTy);
@@ -382,11 +369,11 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
382
369
Function *CtorFunc;
383
370
GlobalVariable *SecStart = new GlobalVariable (
384
371
M, Int32PtrTy, false , GlobalVariable::ExternalLinkage, nullptr ,
385
- getSanCovTracePCGuardSectionStart (*CurModule ));
372
+ getSanCovTracePCGuardSectionStart ());
386
373
SecStart->setVisibility (GlobalValue::HiddenVisibility);
387
374
GlobalVariable *SecEnd = new GlobalVariable (
388
375
M, Int32PtrTy, false , GlobalVariable::ExternalLinkage, nullptr ,
389
- getSanCovTracePCGuardSectionEnd (*CurModule ));
376
+ getSanCovTracePCGuardSectionEnd ());
390
377
SecEnd->setVisibility (GlobalValue::HiddenVisibility);
391
378
392
379
std::tie (CtorFunc, std::ignore) = createSanitizerCtorAndInitFunctions (
@@ -534,7 +521,7 @@ void SanitizerCoverageModule::CreateFunctionGuardArray(size_t NumGuards,
534
521
Constant::getNullValue (ArrayOfInt32Ty), " __sancov_gen_" );
535
522
if (auto Comdat = F.getComdat ())
536
523
FunctionGuardArray->setComdat (Comdat);
537
- FunctionGuardArray->setSection (getSanCovTracePCGuardSection (*CurModule ));
524
+ FunctionGuardArray->setSection (getSanCovTracePCGuardSection ());
538
525
}
539
526
540
527
bool SanitizerCoverageModule::InjectCoverage (Function &F,
@@ -772,6 +759,27 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
772
759
}
773
760
}
774
761
762
+ StringRef SanitizerCoverageModule::getSanCovTracePCGuardSection () const {
763
+ if (TargetTriple.getObjectFormat () == Triple::COFF)
764
+ return " .SCOV$M" ;
765
+ if (TargetTriple.isOSBinFormatMachO ())
766
+ return " __DATA,__sancov_guards" ;
767
+ return " __sancov_guards" ;
768
+ }
769
+
770
+ StringRef SanitizerCoverageModule::getSanCovTracePCGuardSectionStart () const {
771
+ if (TargetTriple.isOSBinFormatMachO ())
772
+ return " \1 section$start$__DATA$__sancov_guards" ;
773
+ return " __start___sancov_guards" ;
774
+ }
775
+
776
+ StringRef SanitizerCoverageModule::getSanCovTracePCGuardSectionEnd () const {
777
+ if (TargetTriple.isOSBinFormatMachO ())
778
+ return " \1 section$end$__DATA$__sancov_guards" ;
779
+ return " __stop___sancov_guards" ;
780
+ }
781
+
782
+
775
783
char SanitizerCoverageModule::ID = 0 ;
776
784
INITIALIZE_PASS_BEGIN (SanitizerCoverageModule, " sancov" ,
777
785
" SanitizerCoverage: TODO."
0 commit comments