diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp --- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -683,8 +683,10 @@ Array->setComdat(Comdat); Array->setSection(getSectionName(Section)); Array->setAlignment(Align(DL->getTypeStoreSize(Ty).getFixedSize())); - GlobalsToAppendToUsed.push_back(Array); - GlobalsToAppendToCompilerUsed.push_back(Array); + if (!Array->hasComdat()) { + GlobalsToAppendToUsed.push_back(Array); + GlobalsToAppendToCompilerUsed.push_back(Array); + } return Array; } diff --git a/llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-comdat.ll b/llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-comdat.ll --- a/llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-comdat.ll +++ b/llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-comdat.ll @@ -3,6 +3,7 @@ ; CHECK: @__sancov_gen_ = private global [1 x i32] zeroinitializer, section "__sancov_guards", comdat($foo), align 4{{$}} ; CHECK-NEXT: @__sancov_gen_.1 = private global [1 x i32] zeroinitializer, section "__sancov_guards", comdat($CallViaVptr), align 4{{$}} +; CHECK-NOT: @llvm.{{.*}}used = target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-unknown-linux-gnu" diff --git a/llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-nocomdat.ll b/llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-nocomdat.ll --- a/llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-nocomdat.ll +++ b/llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-nocomdat.ll @@ -3,6 +3,7 @@ ; CHECK: @__sancov_gen_ = private global [1 x i1] zeroinitializer, section "__DATA,__sancov_bools", align 1, !associated !0 ; CHECK-NEXT: @__sancov_gen_.1 = private global [1 x i1] zeroinitializer, section "__DATA,__sancov_bools", align 1, !associated !1 +; CHECK: @llvm.used = appending global [2 x i8*] [i8* bitcast ([1 x i1]* @__sancov_gen_ to i8*), i8* bitcast ([1 x i1]* @__sancov_gen_.1 to i8*)] target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-apple-darwin10.0.0"