[PATCH] D51902: [SanitizerCoverage] Create comdat for global arrays.

Matt Morehouse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 11 12:44:54 PDT 2018


morehouse updated this revision to Diff 164950.
morehouse added a comment.

- Only set comdats for ELF.
- Fallback to using module ID when getUniqueModuleId fails.


https://reviews.llvm.org/D51902

Files:
  llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp


Index: llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -219,11 +219,6 @@
                    MDNode::get(*C, None));
   }
 
-  std::string UniqueSuffix() {
-    static size_t Count = 0;
-    return "_sancov" + std::to_string(Count++);
-  }
-
   std::string getSectionName(const std::string &Section) const;
   std::string getSectionStart(const std::string &Section) const;
   std::string getSectionEnd(const std::string &Section) const;
@@ -578,13 +573,13 @@
       Constant::getNullValue(ArrayTy), "__sancov_gen_");
   if (auto Comdat = F.getComdat()) {
     Array->setComdat(Comdat);
-  } else {
+  } else if (TargetTriple.isOSBinFormatELF()) {
     // TODO: Refactor into a helper function and use it in ASan.
     assert(F.hasName());
     std::string Name = F.getName();
     if (F.hasLocalLinkage()) {
       std::string ModuleId = getUniqueModuleId(CurModule);
-      Name += ModuleId.empty() ? UniqueSuffix() : ModuleId;
+      Name += ModuleId.empty() ? CurModule->getModuleIdentifier() : ModuleId;
     }
     Comdat = CurModule->getOrInsertComdat(Name);
     // Make this IMAGE_COMDAT_SELECT_NODUPLICATES on COFF. Also upgrade private


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51902.164950.patch
Type: text/x-patch
Size: 1351 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180911/5e78e78e/attachment.bin>


More information about the llvm-commits mailing list