[InstrProfiling] Use !associated metadata for counters, data and values
authorPetr Hosek <phosek@google.com>
Sat, 13 Jul 2019 21:02:07 +0000 (14:02 -0700)
committerPetr Hosek <phosek@google.com>
Mon, 8 Jun 2020 22:07:43 +0000 (15:07 -0700)
commit603d58b5e49c76e4a2e5bf1450b71b100a3396ba
tree523992f71fa28d43da2fc210696eb5cfbad9b25c
parentba10bedf5631eda3a17df428c88451c754633d23
[InstrProfiling] Use !associated metadata for counters, data and values

The !associated metadata may be attached to a global object declaration
with a single argument that references another global object. This
metadata prevents discarding of the global object in linker GC unless
the referenced object is also discarded.

Furthermore, when a function symbol is discarded by the linker, setting
up !associated metadata allows linker to discard counters, data and
values associated with that function symbol. This is not possible today
because there's metadata to guide the linker. This approach is also used
by other instrumentations like sanitizers.

Note that !associated metadata is only supported by ELF, it does not have
any effect on non-ELF targets.

Differential Revision: https://reviews.llvm.org/D76802
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
compiler-rt/test/profile/instrprof-gc-sections.c [new file with mode: 0644]
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/test/Instrumentation/InstrProfiling/associated.ll [new file with mode: 0644]
llvm/test/Transforms/PGOProfile/associated.ll [new file with mode: 0644]
llvm/test/Transforms/PGOProfile/counter_promo.ll
llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll