Index: compiler-rt/test/fuzzer/windows-opt-ref.test =================================================================== --- /dev/null +++ compiler-rt/test/fuzzer/windows-opt-ref.test @@ -0,0 +1,9 @@ +REQUIRES: windows +// Verify that the linker eliminating unreferenced functions (/OPT:REF) does not +// strip sancov module constructor. +RUN: %cpp_compiler %S/SimpleCmpTest.cpp -o %t-SimpleCmpTest /link /OPT:REF + +RUN: not %run %t-SimpleCmpTest -seed=1 -runs=100000000 2>&1 | FileCheck %s + +CHECK-NOT: ERROR: no interesting inputs were found. Is the code instrumented for coverage? Exiting. +CHECK: BINGO Index: llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -288,8 +288,11 @@ 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 will + // be stripped if linker strips unreferenced functions (ie: when linker flag + // "/OPT:REF" is used). CtorFunc->setComdat(M.getOrInsertComdat(SanCovModuleCtorName)); appendToGlobalCtors(M, CtorFunc, SanCtorAndDtorPriority, CtorFunc); } else {