[PATCH] D67579: [PGO] Use linkonce_odr linkage for __profd_ variables in comdat groups

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 15:42:38 PDT 2019


rnk created this revision.
rnk added reviewers: xur, hans.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

This fixes relocations against __profd_ symbols in discarded sections,
which is PR41380.

This is a sketch of the way things are supposed to work:

1. IR is instrumented relatively early in pass pipeline with llvm.instrprof.increment intrinsic calls
2. Inlining and optimization occurs
3. Intrinsics are lowered and __prof[cdv]_ globals are created

For C++ inline functions of all kinds (linkonce_odr &
available_externally mainly), instr profiling wants to deduplicate these
__profc_ and __profd_ globals. Otherwise the binary would be quite
large. For a popular inline function 'foo', it is expected that
__profc_foo will be referenced wherever foo is inlined, even if a
standalone body of 'foo' is omitted.

I made __profd_ and __profc_ comdat in r355044, but I chose to make
__profd_ internal. At the time, I was only dealing with coverage, and in
that case, none of the instrumentation needs to reference __profd_.
However, if you use PGO, then instrumentation passes add calls to
__llvm_profile_instrument_range which reference __profd_ globals. The
solution is to make these globals externally visible by using
linkonce_odr linkage for data as was done for counters.

This is safe because PGO adds a CFG hash to the names of the data and
counter globals, so if different TUs have different globals, they will
get different data and counter arrays.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67579

Files:
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/PR23499.ll
  llvm/test/Instrumentation/InstrProfiling/comdat.ll
  llvm/test/Instrumentation/InstrProfiling/linkage.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67579.220187.patch
Type: text/x-patch
Size: 6864 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190913/1f7632bf/attachment.bin>


More information about the llvm-commits mailing list