[PATCH] D19515: [PGO] Prohibit the recording the function address if it's internal and COMDAT.

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 25 17:20:06 PDT 2016


xur created this revision.
xur added reviewers: davidxl, betulb.
xur added subscribers: llvm-commits, xur.

For COMDAT functions, to remove the duplicate counters, we create a "__profv_*" COMDAT group for the profile data objects, so that only one set of profile data objects will be emitted in the final object.

This works fine until the we have the value profiling. In indirect-call value profile we record the function address to be used in the runtime. This is problematic for COMDAT functions with internal linkage (we do create such function, like global initializer). If we record the address of such function, We will create a reference to internal symbols in COMDAT. This violates the standard.

One can use the following two .ll files to reproduce the issue:
---- a.ll ----
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

$_Z3foov = comdat any

@fp1 = global i32 ()* @_Z3foov, align 8

define internal i32 @_Z3foov() comdat {
entry:
  ret i32 1
}
---- end of b.ll ----

---- b.ll ----
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

$_Z3foov = comdat any

@fp2 = global i32 ()* @_Z3foov, align 8

define internal i32 @_Z3foov() comdat {
entry:
  ret i32 1
}
---- end of b.ll ----

clang a.ll -c && clang b.ll -c && clang a.o b.o

We have the following warning:
"warning: relocation refers to discarded section"

This patch prohibits the recording the function address if it's internal and COMDAT.

http://reviews.llvm.org/D19515

Files:
  lib/Transforms/Instrumentation/InstrProfiling.cpp

Index: lib/Transforms/Instrumentation/InstrProfiling.cpp
===================================================================
--- lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -233,6 +233,9 @@
 }
 
 static inline bool shouldRecordFunctionAddr(Function *F) {
+  // Prohibit the recording the function address if it's internal and COMDAT.
+  if (F->hasLocalLinkage() && F->hasComdat())
+    return false;
   // Check the linkage
   if (!F->hasLinkOnceLinkage() && !F->hasLocalLinkage() &&
       !F->hasAvailableExternallyLinkage())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19515.54950.patch
Type: text/x-patch
Size: 591 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160426/c53cdae9/attachment.bin>


More information about the llvm-commits mailing list