vitalybuka created this revision. Herald added subscribers: steven_wu, hiraditya, inglorion. vitalybuka requested review of this revision. Herald added projects: clang, LLVM. Herald added subscribers: llvm-commits, cfe-commits.
Clang needs to register sanitizer at OptimizerLastEPCallback. Nowever those callbacs are executed on the ThinLTOPostLink and we had no way to configure that. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D96456 Files: clang/lib/CodeGen/BackendUtil.cpp llvm/include/llvm/LTO/Config.h llvm/lib/LTO/LTOBackend.cpp Index: llvm/lib/LTO/LTOBackend.cpp =================================================================== --- llvm/lib/LTO/LTOBackend.cpp +++ llvm/lib/LTO/LTOBackend.cpp @@ -324,6 +324,9 @@ PB.registerLoopAnalyses(LAM); PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); + if (Conf.OptPassBuilderHook) + Conf.OptPassBuilderHook(PB); + ModulePassManager MPM; // Always verify the input. Index: llvm/include/llvm/LTO/Config.h =================================================================== --- llvm/include/llvm/LTO/Config.h +++ llvm/include/llvm/LTO/Config.h @@ -50,6 +50,8 @@ std::vector<std::string> PassPlugins; /// For adding passes that run right before codegen. std::function<void(legacy::PassManager &)> PreCodeGenPassesHook; + /// For adding passes that run by opt. + std::function<void(PassBuilder &)> OptPassBuilderHook; Optional<Reloc::Model> RelocModel = Reloc::PIC_; Optional<CodeModel::Model> CodeModel = None; CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default; Index: clang/lib/CodeGen/BackendUtil.cpp =================================================================== --- clang/lib/CodeGen/BackendUtil.cpp +++ clang/lib/CodeGen/BackendUtil.cpp @@ -1544,6 +1544,10 @@ Conf.CGFileType = getCodeGenFileType(Action); break; } + Triple TargetTriple(M->getTargetTriple()); + Conf.OptPassBuilderHook = [&](PassBuilder &PB) { + addSanitizers(TargetTriple, CGOpts, LOpts, PB); + }; if (Error E = thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
Index: llvm/lib/LTO/LTOBackend.cpp =================================================================== --- llvm/lib/LTO/LTOBackend.cpp +++ llvm/lib/LTO/LTOBackend.cpp @@ -324,6 +324,9 @@ PB.registerLoopAnalyses(LAM); PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); + if (Conf.OptPassBuilderHook) + Conf.OptPassBuilderHook(PB); + ModulePassManager MPM; // Always verify the input. Index: llvm/include/llvm/LTO/Config.h =================================================================== --- llvm/include/llvm/LTO/Config.h +++ llvm/include/llvm/LTO/Config.h @@ -50,6 +50,8 @@ std::vector<std::string> PassPlugins; /// For adding passes that run right before codegen. std::function<void(legacy::PassManager &)> PreCodeGenPassesHook; + /// For adding passes that run by opt. + std::function<void(PassBuilder &)> OptPassBuilderHook; Optional<Reloc::Model> RelocModel = Reloc::PIC_; Optional<CodeModel::Model> CodeModel = None; CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default; Index: clang/lib/CodeGen/BackendUtil.cpp =================================================================== --- clang/lib/CodeGen/BackendUtil.cpp +++ clang/lib/CodeGen/BackendUtil.cpp @@ -1544,6 +1544,10 @@ Conf.CGFileType = getCodeGenFileType(Action); break; } + Triple TargetTriple(M->getTargetTriple()); + Conf.OptPassBuilderHook = [&](PassBuilder &PB) { + addSanitizers(TargetTriple, CGOpts, LOpts, PB); + }; if (Error E = thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList, ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits