Skip to content

Commit c7f91e2

Browse files
committed
[InstrProfiling] No runtime hook for unused funcs
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 pulls in profile runtime 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 389dc94, 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. Differential Revision: https://reviews.llvm.org/D122336
1 parent b867f5c commit c7f91e2

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang -target x86_64-unknown-fuchsia -fprofile-instr-generate -fcoverage-mapping -emit-llvm -S %s -o - | FileCheck %s
2+
3+
// CHECK-NOT: @__llvm_profile_runtime
4+
static int f0() {
5+
return 100;
6+
}

llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,16 +558,18 @@ bool InstrProfiling::run(
558558
TT = Triple(M.getTargetTriple());
559559

560560
bool MadeChange = false;
561-
562-
// Emit the runtime hook even if no counters are present.
563-
if (needsRuntimeHookUnconditionally(TT))
561+
bool NeedsRuntimeHook = needsRuntimeHookUnconditionally(TT);
562+
if (NeedsRuntimeHook)
564563
MadeChange = emitRuntimeHook();
565564

566565
// Improve compile time by avoiding linear scans when there is no work.
567566
GlobalVariable *CoverageNamesVar =
568567
M.getNamedGlobal(getCoverageUnusedNamesVarName());
569-
if (!containsProfilingIntrinsics(M) && !CoverageNamesVar)
570-
return MadeChange;
568+
if (!containsProfilingIntrinsics(M)) {
569+
if (!CoverageNamesVar || !NeedsRuntimeHook) {
570+
return MadeChange;
571+
}
572+
}
571573

572574
// We did not know how many value sites there would be inside
573575
// the instrumented function. This is counting the number of instrumented

0 commit comments

Comments
 (0)