Index: lib/Transforms/Instrumentation/SanitizerCoverage.cpp =================================================================== --- lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -78,7 +78,10 @@ static const char *const SanCovModuleCtorName = "sancov.module_ctor"; static const uint64_t SanCtorAndDtorPriority = 2; -static const char *const SanCovTracePCGuardSection = "__sancov_guards"; +static const char *const SanCovTracePCGuardSectionStart = + "__start___sancov_guards"; +static const char *const SanCovTracePCGuardSectionStop = + "__stop___sancov_guards"; static const char *const SanCovTracePCGuardName = "__sanitizer_cov_trace_pc_guard"; static const char *const SanCovTracePCGuardInitName = @@ -216,6 +219,7 @@ SanCovWithCheckFunction->getNumUses() + SanCovTraceBB->getNumUses() + SanCovTraceEnter->getNumUses(); } + StringRef getSanCovTracePCGuardSection() const; Function *SanCovFunction; Function *SanCovWithCheckFunction; Function *SanCovIndirCallFunction, *SanCovTracePCIndir; @@ -227,6 +231,7 @@ InlineAsm *EmptyAsm; Type *IntptrTy, *IntptrPtrTy, *Int64Ty, *Int64PtrTy, *Int32Ty, *Int32PtrTy; Module *CurModule; + Triple TargetTriple; LLVMContext *C; const DataLayout *DL; @@ -246,6 +251,7 @@ C = &(M.getContext()); DL = &M.getDataLayout(); CurModule = &M; + TargetTriple = Triple(M.getTargetTriple()); HasSancovGuardsSection = false; IntptrTy = Type::getIntNTy(*C, DL->getPointerSizeInBits()); IntptrPtrTy = PointerType::getUnqual(IntptrTy); @@ -363,20 +369,20 @@ if (Options.TracePCGuard) { 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, Int32PtrTy, false, - GlobalVariable::ExternalLinkage, nullptr, - Prefix[i] + SectionName); - Bounds[i]->setVisibility(GlobalValue::HiddenVisibility); - } + GlobalVariable *SectionStart, *SectionStop; + SectionStart = new GlobalVariable(M, Int32PtrTy, false, + GlobalVariable::ExternalLinkage, nullptr, + SanCovTracePCGuardSectionStart); + SectionStart->setVisibility(GlobalValue::HiddenVisibility); + SectionStop = new GlobalVariable(M, Int32PtrTy, false, + GlobalVariable::ExternalLinkage, nullptr, + SanCovTracePCGuardSectionStop); + SectionStop->setVisibility(GlobalValue::HiddenVisibility); std::tie(CtorFunc, std::ignore) = createSanitizerCtorAndInitFunctions( M, SanCovModuleCtorName, SanCovTracePCGuardInitName, {Int32PtrTy, Int32PtrTy}, - {IRB.CreatePointerCast(Bounds[0], Int32PtrTy), - IRB.CreatePointerCast(Bounds[1], Int32PtrTy)}); + {IRB.CreatePointerCast(SectionStart, Int32PtrTy), + IRB.CreatePointerCast(SectionStop, Int32PtrTy)}); appendToGlobalCtors(M, CtorFunc, SanCtorAndDtorPriority); } @@ -517,7 +523,7 @@ Constant::getNullValue(ArrayOfInt32Ty), "__sancov_gen_"); if (auto Comdat = F.getComdat()) FunctionGuardArray->setComdat(Comdat); - FunctionGuardArray->setSection(SanCovTracePCGuardSection); + FunctionGuardArray->setSection(getSanCovTracePCGuardSection()); } bool SanitizerCoverageModule::InjectCoverage(Function &F, @@ -755,6 +761,12 @@ } } +StringRef SanitizerCoverageModule::getSanCovTracePCGuardSection() const { + if (TargetTriple.getObjectFormat() == Triple::COFF) + return ".SCOV$M"; + return "__sancov_guards"; +} + char SanitizerCoverageModule::ID = 0; INITIALIZE_PASS_BEGIN(SanitizerCoverageModule, "sancov", "SanitizerCoverage: TODO."