Reland [pgo] Avoid introducing relocations by using private alias
authorPaul Kirth <paulkirth@google.com>
Wed, 18 Jan 2023 21:54:21 +0000 (21:54 +0000)
committerPaul Kirth <paulkirth@google.com>
Wed, 18 Jan 2023 23:56:35 +0000 (23:56 +0000)
commitda5a8d14b8cc6cea16ee0929413c0672b47c93d9
tree9d568df559109d6196ef6bf5ffe987834e93ec5b
parent9545580447fc02176e91d24e04f82c8f688129e1
Reland [pgo] Avoid introducing relocations by using private alias

In many cases, we can use an alias to avoid a symbolic relocations,
instead of using the public, interposable symbol. When the instrumented
function is in a COMDAT, we can use a hidden alias, and still avoid
references to discarded sections.

Previous versions of this patch allowed the compiler to name the
generated alias, but that would only be valid when the functions were
local. Since the alias may be used across TUs we use a more
deterministic naming convention, and add a ".local" suffix to the alias
name just as we do for relative vtables aliases.

https://reviews.llvm.org/rG20894a478da224bdd69c91a22a5175b28bc08ed9
removed an incorrect assertion on Mach-O which caused assertion failures in LLD.

We addressed the link errors under ThinLTO + PGO + CFI by being more
selective about which comdat functions can be given aliases.
Specifically, we now do not emit an alias in the case of a comdat
function with hidden visibility, since the alias would have the same
linkage and visibility, giving no benefit over using the symbol
directly. This also prevents LowerTypeTest from incorrectly updating the
dangling alias after GlobalOpt replaces uses, and introducing a
duplicate symbol.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D137982
compiler-rt/test/profile/instrprof-discarded-comdat.cpp [new file with mode: 0644]
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/test/Transforms/PGOProfile/comdat.ll
llvm/test/Transforms/PGOProfile/profdata_priv_alias.ll [new file with mode: 0644]