diff options
| author | Diego Novillo <dnovillo@google.com> | 2015-05-27 16:44:47 +0000 |
|---|---|---|
| committer | Diego Novillo <dnovillo@google.com> | 2015-05-27 16:44:47 +0000 |
| commit | 98b4cf8fcaf391794de17bb10bea1ec03bc0133a (patch) | |
| tree | 5444f281aa748683188c2b5439355f66ef999b37 /llvm/lib | |
| parent | dead71a829036ef5dc3b05d4a0c2185472cf68fc (diff) | |
| download | bcm5719-llvm-98b4cf8fcaf391794de17bb10bea1ec03bc0133a.tar.gz bcm5719-llvm-98b4cf8fcaf391794de17bb10bea1ec03bc0133a.zip | |
Fix PR 23499 - Avoid multiple profile counters for functions in comdat sections.
Counter symbols created for linkonce functions are not discarded by ELF
linkers unless the symbols are placed in the same comdat section as its
associated function.
llvm-svn: 238335
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp index 0718ddcb6ec..610ff52ba9d 100644 --- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -203,6 +203,7 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) { uint64_t NumCounters = Inc->getNumCounters()->getZExtValue(); LLVMContext &Ctx = M->getContext(); ArrayType *CounterTy = ArrayType::get(Type::getInt64Ty(Ctx), NumCounters); + Function *Fn = Inc->getParent()->getParent(); // Create the counters variable. auto *Counters = new GlobalVariable(*M, CounterTy, false, Name->getLinkage(), @@ -211,6 +212,10 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) { Counters->setVisibility(Name->getVisibility()); Counters->setSection(getCountersSection()); Counters->setAlignment(8); + // Place the counters in the same comdat section as its parent function. + // Otherwise, we may get multiple counters for the same function in certain + // cases. + Counters->setComdat(Fn->getComdat()); RegionCounters[Inc->getName()] = Counters; @@ -235,6 +240,7 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) { Data->setVisibility(Name->getVisibility()); Data->setSection(getDataSection()); Data->setAlignment(8); + Data->setComdat(Fn->getComdat()); // Mark the data variable as used so that it isn't stripped out. UsedVars.push_back(Data); |

