[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:50:40 PDT 2018
morehouse updated this revision to Diff 164951.
morehouse added a comment.
- Rebase
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
@@ -571,8 +571,28 @@
auto Array = new GlobalVariable(
*CurModule, ArrayTy, false, GlobalVariable::PrivateLinkage,
Constant::getNullValue(ArrayTy), "__sancov_gen_");
- if (auto Comdat = F.getComdat())
+ if (auto Comdat = F.getComdat()) {
Array->setComdat(Comdat);
+ } 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() ? CurModule->getModuleIdentifier() : ModuleId;
+ }
+ Comdat = CurModule->getOrInsertComdat(Name);
+ // Make this IMAGE_COMDAT_SELECT_NODUPLICATES on COFF. Also upgrade private
+ // linkage to internal linkage so that a symbol table entry is emitted. This
+ // is necessary in order to create the comdat group.
+ if (TargetTriple.isOSBinFormatCOFF()) {
+ Comdat->setSelectionKind(Comdat::NoDuplicates);
+ if (F.hasPrivateLinkage())
+ F.setLinkage(GlobalValue::InternalLinkage);
+ }
+ F.setComdat(Comdat);
+ Array->setComdat(Comdat);
+ }
Array->setSection(getSectionName(Section));
Array->setAlignment(Ty->isPointerTy() ? DL->getPointerSize()
: Ty->getPrimitiveSizeInBits() / 8);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51902.164951.patch
Type: text/x-patch
Size: 1616 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180911/740638bd/attachment.bin>
More information about the llvm-commits
mailing list