Index: llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -288,8 +288,10 @@ M, SanCovModuleCtorName, InitFunctionName, {Ty, Ty}, {SecStartPtr, IRB.CreatePointerCast(SecEnd, Ty)}); - if (TargetTriple.supportsCOMDAT()) { - // Use comdat to dedup CtorFunc. + if (TargetTriple.supportsCOMDAT()&& + TargetTriple.getObjectFormat() != Triple::COFF) { + // Use comdat to dedup CtorFunc. Don't do it for COFF files since it breaks + // the linker flag: "/OPT:REF". CtorFunc->setComdat(M.getOrInsertComdat(SanCovModuleCtorName)); appendToGlobalCtors(M, CtorFunc, SanCtorAndDtorPriority, CtorFunc); } else {