diff options
author | Xinliang David Li <davidxl@google.com> | 2016-06-02 16:33:41 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-06-02 16:33:41 +0000 |
commit | 7008ce3f989105a667eab5f34f7ba6fcdc1ba3d8 (patch) | |
tree | 5e5101c906e152ec37571679fc7e6361377cf99e /llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp | |
parent | fd7ddf1479f1f401a8159d37e6058273f67b20c8 (diff) | |
download | llvm-7008ce3f989105a667eab5f34f7ba6fcdc1ba3d8.zip llvm-7008ce3f989105a667eab5f34f7ba6fcdc1ba3d8.tar.gz llvm-7008ce3f989105a667eab5f34f7ba6fcdc1ba3d8.tar.bz2 |
[profile] value profiling bug fix -- missing icall targets in profile-use
Inline virtual functions has linkeonceodr linkage (emitted in comdat on
supporting targets). If the vtable for the class is not emitted in the
defining module, function won't be address taken thus its address is not
recorded. At the mercy of the linker, if the per-func prf_data from this
module (in comdat) is picked at link time, we will lose mapping from
function address to its hash val. This leads to missing icall promotion.
The second test case (currently disabled) in compiler_rt (r271528):
instrprof-icall-prom.test demostrates the bug. The first profile-use
subtest is fine due to linker order difference.
With this change, no missing icall targets is found in instrumented clang's
raw profile.
llvm-svn: 271532
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp index d2f5b29..cf8f93d 100644 --- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -258,7 +258,13 @@ static inline bool shouldRecordFunctionAddr(Function *F) { if (F->hasLocalLinkage() && F->hasComdat()) return false; // Check uses of this function for other than direct calls or invokes to it. - return F->hasAddressTaken(); + // Inline virtual functions have linkeOnceODR linkage. When a key method + // exists, the vtable will only be emitted in the TU where the key method + // is defined. In a TU where vtable is not available, the function won't + // be 'addresstaken'. If its address is not recorded here, the profile counter + // comdat group with missing address may be picked by the linker leading + // to missing indirect call target info. + return F->hasAddressTaken() || (F->hasLinkOnceLinkage() && F->hasComdat()); } static inline bool needsComdatForCounter(Function &F, Module &M) { |