From: Leonard Chan Date: Wed, 4 Sep 2019 20:30:29 +0000 (+0000) Subject: [NewPM][Sancov] Make Sancov a Module Pass instead of 2 Passes X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c6ee3dacaccb1f818db5d8b9a6169d2d116e7aa;p=clang [NewPM][Sancov] Make Sancov a Module Pass instead of 2 Passes This patch merges the sancov module and funciton passes into one module pass. The reason for this is because we ran into an out of memory error when attempting to run asan fuzzer on some protobufs (pc.cc files). I traced the OOM error to the destructor of SanitizerCoverage where we only call appendTo[Compiler]Used which calls appendToUsedList. I'm not sure where precisely in appendToUsedList causes the OOM, but I am able to confirm that it's calling this function *repeatedly* that causes the OOM. (I hacked sancov a bit such that I can still create and destroy a new sancov on every function run, but only call appendToUsedList after all functions in the module have finished. This passes, but when I make it such that appendToUsedList is called on every sancov destruction, we hit OOM.) I don't think the OOM is from just adding to the SmallSet and SmallVector inside appendToUsedList since in either case for a given module, they'll have the same max size. I suspect that when the existing llvm.compiler.used global is erased, the memory behind it isn't freed. I could be wrong on this though. This patch works around the OOM issue by just calling appendToUsedList at the end of every module run instead of function run. The same amount of constants still get added to llvm.compiler.used, abd we make the pass usage and logic simpler by not having any inter-pass dependencies. Differential Revision: https://reviews.llvm.org/D66988 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370971 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 2932fb0fe8..caa65e2cee 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -224,7 +224,6 @@ static void addSanitizerCoveragePass(const PassManagerBuilder &Builder, const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); auto Opts = getSancovOptsFromCGOpts(CGOpts); PM.add(createModuleSanitizerCoverageLegacyPassPass(Opts)); - PM.add(createSanitizerCoverageLegacyPassPass(Opts)); } // Check if ASan should use GC-friendly instrumentation for globals. @@ -1159,11 +1158,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( [SancovOpts](ModulePassManager &MPM) { MPM.addPass(ModuleSanitizerCoveragePass(SancovOpts)); }); - PB.registerOptimizerLastEPCallback( - [SancovOpts](FunctionPassManager &FPM, - PassBuilder::OptimizationLevel Level) { - FPM.addPass(SanitizerCoveragePass(SancovOpts)); - }); } // Register callbacks to schedule sanitizer passes at the appropriate part of @@ -1249,8 +1243,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( CodeGenOpts.SanitizeCoverageTraceCmp) { auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts); MPM.addPass(ModuleSanitizerCoveragePass(SancovOpts)); - MPM.addPass(createModuleToFunctionPassAdaptor( - SanitizerCoveragePass(SancovOpts))); } addSanitizersAtO0(MPM, TargetTriple, LangOpts, CodeGenOpts);