From: Peter Collingbourne Date: Wed, 17 Jul 2019 21:45:19 +0000 (+0000) Subject: hwasan: Initialize the pass only once. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=982f868518e35cef58b1c4e84448c46da20e7880;p=clang hwasan: Initialize the pass only once. This will let us instrument globals during initialization. This required making the new PM pass a module pass, which should still provide access to analyses via the ModuleAnalysisManager. Differential Revision: https://reviews.llvm.org/D64843 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366379 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 40a529c319..497652e85b 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -967,17 +967,6 @@ static void addSanitizersAtO0(ModulePassManager &MPM, if (LangOpts.Sanitize.has(SanitizerKind::Thread)) { MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); } - - if (LangOpts.Sanitize.has(SanitizerKind::HWAddress)) { - bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::HWAddress); - MPM.addPass(createModuleToFunctionPassAdaptor( - HWAddressSanitizerPass(/*CompileKernel=*/false, Recover))); - } - - if (LangOpts.Sanitize.has(SanitizerKind::KernelHWAddress)) { - MPM.addPass(createModuleToFunctionPassAdaptor( - HWAddressSanitizerPass(/*CompileKernel=*/true, /*Recover=*/true))); - } } /// A clean version of `EmitAssembly` that uses the new pass manager. @@ -1176,23 +1165,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( UseOdrIndicator)); }); } - if (LangOpts.Sanitize.has(SanitizerKind::HWAddress)) { - bool Recover = - CodeGenOpts.SanitizeRecover.has(SanitizerKind::HWAddress); - PB.registerOptimizerLastEPCallback( - [Recover](FunctionPassManager &FPM, - PassBuilder::OptimizationLevel Level) { - FPM.addPass(HWAddressSanitizerPass( - /*CompileKernel=*/false, Recover)); - }); - } - if (LangOpts.Sanitize.has(SanitizerKind::KernelHWAddress)) { - PB.registerOptimizerLastEPCallback( - [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { - FPM.addPass(HWAddressSanitizerPass( - /*CompileKernel=*/true, /*Recover=*/true)); - }); - } if (Optional Options = getGCOVOptions(CodeGenOpts)) PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) { MPM.addPass(GCOVProfilerPass(*Options)); @@ -1219,6 +1191,16 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( } } + if (LangOpts.Sanitize.has(SanitizerKind::HWAddress)) { + bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::HWAddress); + MPM.addPass(HWAddressSanitizerPass( + /*CompileKernel=*/false, Recover)); + } + if (LangOpts.Sanitize.has(SanitizerKind::KernelHWAddress)) { + MPM.addPass(HWAddressSanitizerPass( + /*CompileKernel=*/true, /*Recover=*/true)); + } + if (CodeGenOpts.OptimizationLevel == 0) addSanitizersAtO0(MPM, TargetTriple, LangOpts, CodeGenOpts); }