[InstrProfiling] Use external weak reference for bias variable
authorPetr Hosek <phosek@google.com>
Wed, 30 Jun 2021 07:19:04 +0000 (00:19 -0700)
committerPetr Hosek <phosek@google.com>
Thu, 1 Jul 2021 22:25:31 +0000 (15:25 -0700)
commit33a7b4d9d8e6a113108aa71ed78ca32a83c68523
tree56eb4c520a9e75641e2ddc961c009f31dc6ba091
parent14d64be6e54a23e1a20216b6a42ae2ce5926d2ed
[InstrProfiling] Use external weak reference for bias variable

We need the compiler generated variable to override the weak symbol of
the same name inside the profile runtime, but using LinkOnceODRLinkage
results in weak symbol being emitted which leads to an issue where the
linker might choose either of the weak symbols potentially disabling the
runtime counter relocation.

This change replaces the use of weak definition inside the runtime with
an external weak reference to address the issue. We also place the
compiler generated symbol inside a COMDAT group so dead definition can
be garbage collected by the linker.

Differential Revision: https://reviews.llvm.org/D105176
compiler-rt/lib/profile/CMakeLists.txt
compiler-rt/lib/profile/InstrProfiling.h
compiler-rt/lib/profile/InstrProfilingBiasVar.c [deleted file]
compiler-rt/lib/profile/InstrProfilingFile.c
compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/test/Instrumentation/InstrProfiling/runtime-counter-relocation.ll