From 6b286d93f7ec8518c685a302269e44b06a0a24f3 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Fri, 19 Feb 2021 21:41:45 -0800 Subject: [PATCH] [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 --- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 4 ++++ llvm/test/Instrumentation/InstrProfiling/X86/nobits.ll | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 llvm/test/Instrumentation/InstrProfiling/X86/nobits.ll diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 2530fdc..c1383ba 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -440,6 +440,10 @@ static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K) { Name == ".llvmbc" || Name == ".llvmcmd") return SectionKind::getMetadata(); + if (Name == getInstrProfSectionName(IPSK_cnts, Triple::ELF, + /*AddSegmentInfo=*/false)) + return SectionKind::getBSS(); + if (Name.empty() || Name[0] != '.') return K; // Default implementation based on some magic section names. diff --git a/llvm/test/Instrumentation/InstrProfiling/X86/nobits.ll b/llvm/test/Instrumentation/InstrProfiling/X86/nobits.ll new file mode 100644 index 0000000..d8cbc76 --- /dev/null +++ b/llvm/test/Instrumentation/InstrProfiling/X86/nobits.ll @@ -0,0 +1,15 @@ +;; Ensure that SHT_NOBITS section type is set for __llvm_prf_cnts in ELF. +; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s + +@__profc_foo = hidden global [1 x i64] zeroinitializer, section "__llvm_prf_cnts", align 8 + +define void @foo() { + %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_foo, i64 0, i64 0), align 4 + %1 = add i64 %pgocount, 1 + store i64 %1, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_foo, i64 0, i64 0), align 4 + ret void +} + +declare void @llvm.instrprof.increment(i8*, i64, i32, i32) + +; CHECK: .section __llvm_prf_cnts,"aw",@nobits -- 2.7.4