[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 20:35:56 +0000 (13:35 -0700)
commit39b3c41b65302a969fa5507402976a255a07c158
treed7f5267e8d54c61d5df4b8bc640e2983f2a05ff5
parent932ad9941deffeb540563973564514e4f8b3cb63
[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/counter_promo.ll
llvm/test/Transforms/PGOProfile/counter_promo_mexits.ll