Skip to content

Commit 6b286d9

Browse files
committed
[InstrProfiling] Use nobits as __llvm_prf_cnts section type in ELF
This can reduce the binary size because counters will no longer occupy space in the binary, instead they will be allocated by dynamic linker. Differential Revision: https://reviews.llvm.org/D97110
1 parent 77056fe commit 6b286d9

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,10 @@ static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K) {
440440
Name == ".llvmbc" || Name == ".llvmcmd")
441441
return SectionKind::getMetadata();
442442

443+
if (Name == getInstrProfSectionName(IPSK_cnts, Triple::ELF,
444+
/*AddSegmentInfo=*/false))
445+
return SectionKind::getBSS();
446+
443447
if (Name.empty() || Name[0] != '.') return K;
444448

445449
// Default implementation based on some magic section names.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
;; Ensure that SHT_NOBITS section type is set for __llvm_prf_cnts in ELF.
2+
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
3+
4+
@__profc_foo = hidden global [1 x i64] zeroinitializer, section "__llvm_prf_cnts", align 8
5+
6+
define void @foo() {
7+
%pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_foo, i64 0, i64 0), align 4
8+
%1 = add i64 %pgocount, 1
9+
store i64 %1, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_foo, i64 0, i64 0), align 4
10+
ret void
11+
}
12+
13+
declare void @llvm.instrprof.increment(i8*, i64, i32, i32)
14+
15+
; CHECK: .section __llvm_prf_cnts,"aw",@nobits

0 commit comments

Comments
 (0)