This fixes relocations against __profd_ symbols in discarded sections,
which is PR41380.
This is a sketch of the way things are supposed to work:
- IR is instrumented relatively early in pass pipeline with llvm.instrprof.increment intrinsic calls
- Inlining and optimization occurs
- 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.