[InstrProfiling] Generate runtime hook for Fuchsia
authorPetr Hosek <phosek@google.com>
Tue, 10 Aug 2021 18:03:07 +0000 (11:03 -0700)
committerPetr Hosek <phosek@google.com>
Wed, 11 Aug 2021 06:21:15 +0000 (23:21 -0700)
commit389dc94d4be7a75c243528981a25260c1c7a6103
tree4334423371777ea597c767c53ef367b0657cfcdc
parentc0c1c3cf93ec089887944027ebfa95da03f8040b
[InstrProfiling] Generate runtime hook for Fuchsia

When none of the translation units in the binary have been instrumented
we shouldn't need to link the profile runtime. However, because we pass
-u__llvm_profile_runtime on Linux and Fuchsia, the runtime would still
be pulled in and incur some overhead. On Fuchsia which uses runtime
counter relocation, it also means that we cannot reference the bias
variable unconditionally.

This change modifies the InstrProfiling pass to pull in the profile
runtime only when needed by declaring the __llvm_profile_runtime symbol
in the translation unit only when needed. For now we restrict this only
for Fuchsia, but this can be later expanded to other platforms. This
approach was already used prior to 9a041a75221ca, but we changed it
to always generate the __llvm_profile_runtime due to a TAPI limitation,
but that limitation may no longer apply, and it certainly doesn't apply
on platforms like Fuchsia.

Differential Revision: https://reviews.llvm.org/D98061
clang/docs/UsersManual.rst
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/lib/Driver/ToolChains/Fuchsia.h
clang/test/Driver/fuchsia.c
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/test/Instrumentation/InstrProfiling/profiling.ll