[InstrProfiling] No runtime hook for unused funcs
authorGulfem Savrun Yeniceri <gulfem@google.com>
Fri, 26 Aug 2022 16:38:44 +0000 (16:38 +0000)
committerGulfem Savrun Yeniceri <gulfem@google.com>
Fri, 16 Sep 2022 02:05:09 +0000 (02:05 +0000)
commitd6aed77f0d19664be48d531552692520ae2a6f1a
treea95bff2c3e1f4a989b2f085a8188412cdddf16db
parent3eca0b395ff07d0428f4179e33a6ae295e608f47
[InstrProfiling] No runtime hook for unused funcs

This is a reland of https://reviews.llvm.org/D122336.
Original patch caused a problem in collecting coverage in
Fuchsia because it was returning early without putting unused
function names into __llvm_prf_names section. This patch
fixes that issue.

The original commit message is as the following:
CoverageMappingModuleGen generates a coverage mapping record
even for unused functions with internal linkage, e.g.
static int foo() { return 100; }
Clang frontend eliminates such functions, but InstrProfiling pass
still emits runtime hook since there is a coverage record.
Fuchsia uses runtime counter relocation, and pulling in profile
runtime for unused functions causes a linker error:
undefined hidden symbol: __llvm_profile_counter_bias.
Since https://reviews.llvm.org/D98061, we do not hook profile
runtime for the binaries that none of its translation units
have been instrumented in Fuchsia. This patch extends that for
the instrumented binaries that consist of only unused functions.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D122336
clang/test/CoverageMapping/unused_function_no_runtime_hook.cpp [new file with mode: 0644]
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp