From 37b8e099d4b551715be0a597b2e5718f8c79ed3e Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Mon, 22 Sep 2025 15:55:48 -0700 Subject: [PATCH] [clang][fatlto] Only run sanitzer passes in prelink pipelines FatLTO will run the sanitizer callbaks on both the pre and post link pipelines, meaning they will run twice. These passes usually have a check to prevent doing the wrong thing, but that shouldn't be relied upon, since we know these will always run as part of the prelink pipelines under FatLTO. Fixes #159629 --- clang/lib/CodeGen/BackendUtil.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 106363fa83e2b..3ebe04e958ec4 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -700,7 +700,12 @@ static void addSanitizers(const Triple &TargetTriple, const CodeGenOptions &CodeGenOpts, const LangOptions &LangOpts, PassBuilder &PB) { auto SanitizersCallback = [&](ModulePassManager &MPM, OptimizationLevel Level, - ThinOrFullLTOPhase) { + ThinOrFullLTOPhase phase) { + // FatLTO pipelines already added these to the prelink pipeline. + if (CodeGenOpts.FatLTO && + (CodeGenOpts.PrepareForThinLTO || CodeGenOpts.PrepareForLTO) && + ThinOrFullLTOPhase::None != phase) + return; if (CodeGenOpts.hasSanitizeCoverage()) { auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts); MPM.addPass(SanitizerCoveragePass(