[sancov] using comdat only when it is enabled

Differential Revision: https://reviews.llvm.org/D29733

llvm-svn: 294529
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index 76e5f8b..8f7ac9c 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -382,9 +382,13 @@
           {IRB.CreatePointerCast(SecStart, Int32PtrTy),
             IRB.CreatePointerCast(SecEnd, Int32PtrTy)});
 
-      // Use comdat to dedup CtorFunc.
-      CtorFunc->setComdat(M.getOrInsertComdat(SanCovModuleCtorName));
-      appendToGlobalCtors(M, CtorFunc, SanCtorAndDtorPriority, CtorFunc);
+      if (TargetTriple.supportsCOMDAT()) {
+        // Use comdat to dedup CtorFunc.
+        CtorFunc->setComdat(M.getOrInsertComdat(SanCovModuleCtorName));
+        appendToGlobalCtors(M, CtorFunc, SanCtorAndDtorPriority, CtorFunc);
+      } else {
+        appendToGlobalCtors(M, CtorFunc, SanCtorAndDtorPriority);
+      }
     }
   } else if (!Options.TracePC) {
     Function *CtorFunc;