]> granicus.if.org Git - llvm/commitdiff
[sanitizer-coverage] add comdat to coverage guards if needed
authorKostya Serebryany <kcc@google.com>
Tue, 20 Sep 2016 00:16:54 +0000 (00:16 +0000)
committerKostya Serebryany <kcc@google.com>
Tue, 20 Sep 2016 00:16:54 +0000 (00:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281952 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/SanitizerCoverage.cpp
test/Instrumentation/SanitizerCoverage/tracing-comdat.ll [new file with mode: 0644]

index a2755adc7fac201c6c8d6071d6faa2f04b5bdc2c..9e1ff1cd6d21a21f75f019de69b2dbefb0dc20fb 100644 (file)
@@ -669,6 +669,8 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
     auto GuardVar = new GlobalVariable(
         *F.getParent(), Int64Ty, false, GlobalVariable::LinkOnceODRLinkage,
         Constant::getNullValue(Int64Ty), "__sancov_guard." + F.getName());
+    if (auto Comdat = F.getComdat())
+      GuardVar->setComdat(Comdat);
     // TODO: add debug into to GuardVar.
     GuardVar->setSection(SanCovTracePCGuardSection);
     auto GuardPtr = IRB.CreatePointerCast(GuardVar, IntptrPtrTy);
diff --git a/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll b/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
new file mode 100644 (file)
index 0000000..f718af5
--- /dev/null
@@ -0,0 +1,13 @@
+; Test that the coverage guards have proper comdat
+; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S | FileCheck %s
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+$Foo = comdat any
+; Function Attrs: uwtable
+define linkonce_odr void @Foo() comdat {
+entry:
+  ret void
+}
+
+; CHECK: @__sancov_guard.Foo = linkonce_odr global i64 0, section "__sancov_guards", comdat($Foo)
+