@@ -77,8 +77,6 @@ static const char *const SanCovCountersSectionName = "sancov_cntrs";
77
77
static const char *const SanCovPCsSectionName = " sancov_pcs" ;
78
78
79
79
static const char *const SanCovLowestStackName = " __sancov_lowest_stack" ;
80
- static const char *const SanCovLowestStackTLSWrapperName =
81
- " _ZTW21__sancov_lowest_stack" ;
82
80
83
81
static cl::opt<int > ClCoverageLevel (
84
82
" sanitizer-coverage-level" ,
@@ -229,7 +227,6 @@ class SanitizerCoverageModule : public ModulePass {
229
227
Function *SanCovTraceDivFunction[2 ];
230
228
Function *SanCovTraceGepFunction;
231
229
Function *SanCovTraceSwitchFunction;
232
- Function *SanCovLowestStackTLSWrapper;
233
230
GlobalVariable *SanCovLowestStack;
234
231
InlineAsm *EmptyAsm;
235
232
Type *IntptrTy, *IntptrPtrTy, *Int64Ty, *Int64PtrTy, *Int32Ty, *Int32PtrTy,
@@ -351,20 +348,11 @@ bool SanitizerCoverageModule::runOnModule(Module &M) {
351
348
352
349
Constant *SanCovLowestStackConstant =
353
350
M.getOrInsertGlobal (SanCovLowestStackName, IntptrTy);
354
- SanCovLowestStackTLSWrapper =
355
- checkSanitizerInterfaceFunction (M.getOrInsertFunction (
356
- SanCovLowestStackTLSWrapperName, IntptrTy->getPointerTo ()));
357
- if (Options.StackDepth ) {
358
- assert (isa<GlobalVariable>(SanCovLowestStackConstant));
359
- SanCovLowestStack = cast<GlobalVariable>(SanCovLowestStackConstant);
360
- if (!SanCovLowestStack->isDeclaration ()) {
361
- // Check that the user has correctly defined:
362
- // thread_local uintptr_t __sancov_lowest_stack
363
- // and initialize it.
364
- assert (SanCovLowestStack->isThreadLocal ());
365
- SanCovLowestStack->setInitializer (Constant::getAllOnesValue (IntptrTy));
366
- }
367
- }
351
+ SanCovLowestStack = cast<GlobalVariable>(SanCovLowestStackConstant);
352
+ SanCovLowestStack->setThreadLocalMode (
353
+ GlobalValue::ThreadLocalMode::InitialExecTLSModel);
354
+ if (Options.StackDepth && !SanCovLowestStack->isDeclaration ())
355
+ SanCovLowestStack->setInitializer (Constant::getAllOnesValue (IntptrTy));
368
356
369
357
// Make sure smaller parameters are zero-extended to i64 as required by the
370
358
// x86_64 ABI.
@@ -484,9 +472,6 @@ bool SanitizerCoverageModule::runOnFunction(Function &F) {
484
472
if (F.getName () == " __local_stdio_printf_options" ||
485
473
F.getName () == " __local_stdio_scanf_options" )
486
474
return false ;
487
- // Avoid infinite recursion by not instrumenting stack depth TLS wrapper
488
- if (F.getName () == SanCovLowestStackTLSWrapperName)
489
- return false ;
490
475
// Don't instrument functions using SEH for now. Splitting basic blocks like
491
476
// we do for coverage breaks WinEHPrepare.
492
477
// FIXME: Remove this when SEH no longer uses landingpad pattern matching.
@@ -771,12 +756,11 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
771
756
auto FrameAddrPtr =
772
757
IRB.CreateCall (GetFrameAddr, {Constant::getNullValue (Int32Ty)});
773
758
auto FrameAddrInt = IRB.CreatePtrToInt (FrameAddrPtr, IntptrTy);
774
- auto LowestStackPtr = IRB.CreateCall (SanCovLowestStackTLSWrapper);
775
- auto LowestStack = IRB.CreateLoad (LowestStackPtr);
759
+ auto LowestStack = IRB.CreateLoad (SanCovLowestStack);
776
760
auto IsStackLower = IRB.CreateICmpULT (FrameAddrInt, LowestStack);
777
761
auto ThenTerm = SplitBlockAndInsertIfThen (IsStackLower, &*IP, false );
778
762
IRBuilder<> ThenIRB (ThenTerm);
779
- ThenIRB.CreateStore (FrameAddrInt, LowestStackPtr );
763
+ ThenIRB.CreateStore (FrameAddrInt, SanCovLowestStack );
780
764
}
781
765
}
782
766
0 commit comments