[llvm] Avoid merging instrumentation profiler globals (PR #172835)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 18 03:13:53 PST 2025
https://github.com/eleviant created https://github.com/llvm/llvm-project/pull/172835
The global-merge pass attempts to merge instumentation profiler counters, e.g __profc_foo and __profc_bar, which results in their corresponding __llvm_prf_cnts sections being merged into a single one and moved out from a comdat group, which originally gropus __llvm_prf_cnts and __llvm_prf_data sections. This, in turn, results in __llvm_prf_data becoming an orphaned section, which is garbage-collected when --gc-sections linker flag is used.
>From 5fc8f44728321ec15e14fcfa85d3f7206e766745 Mon Sep 17 00:00:00 2001
From: Evgeny Leviant <eleviant at accesssoftek.com>
Date: Thu, 18 Dec 2025 12:04:43 +0100
Subject: [PATCH] Avoid merging instrumentation profiler globals
The global-merge pass attempts to merge instumentation profiler counters,
e.g __profc_foo and __profc_bar, which results in their corresponding
__llvm_prf_cnts sections being merged into a single one and moved out
from a comdat group, which originally gropus __llvm_prf_cnts and
__llvm_prf_data sections. This, in turn, results in __llvm_prf_data
becoming an orphaned section, which is garbage-collected when
--gc-sections linker flag is used.
---
llvm/lib/CodeGen/GlobalMerge.cpp | 3 +++
.../CodeGen/AArch64/global-merge-profile-sections.ll | 11 +++++++++++
2 files changed, 14 insertions(+)
create mode 100644 llvm/test/CodeGen/AArch64/global-merge-profile-sections.ll
diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp
index b8b0d4d612742..a5c95fa95adca 100644
--- a/llvm/lib/CodeGen/GlobalMerge.cpp
+++ b/llvm/lib/CodeGen/GlobalMerge.cpp
@@ -717,6 +717,9 @@ bool GlobalMergeImpl::run(Module &M) {
GV.getName().starts_with(".llvm.") || Section == "llvm.metadata")
continue;
+ if (Section.starts_with("__llvm_prf"))
+ continue;
+
// Ignore all "required" globals:
if (isMustKeepGlobalVariable(&GV))
continue;
diff --git a/llvm/test/CodeGen/AArch64/global-merge-profile-sections.ll b/llvm/test/CodeGen/AArch64/global-merge-profile-sections.ll
new file mode 100644
index 0000000000000..7108d82ddaa2e
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/global-merge-profile-sections.ll
@@ -0,0 +1,11 @@
+; RUN: llc -mtriple=aarch64-linux-gnu -aarch64-enable-global-merge -global-merge-group-by-use=false < %s | FileCheck %s
+; CHECK-NOT: _MergedGlobals
+
+$__profc_begin = comdat nodeduplicate
+$__profc_end = comdat nodeduplicate
+
+ at __profc_begin = private global [2 x i64] zeroinitializer, section "__llvm_prf_cnts", comdat, align 8
+ at __profd_begin = private global { i64, i64, i64, i64, ptr, ptr, i32, [3 x i16], i32 } { i64 -1301828029439649651, i64 172590168, i64 sub (i64 ptrtoint (ptr @__profc_begin to i64), i64 ptrtoint (ptr @__profd_begin to i64)), i64 0, ptr null, ptr null, i32 2, [3 x i16] zeroinitializer, i32 0 }, section "__llvm_prf_data", comdat($__profc_begin), align 8
+ at __profc_end = private global [2 x i64] zeroinitializer, section "__llvm_prf_cnts", comdat, align 8
+ at __profd_end = private global { i64, i64, i64, i64, ptr, ptr, i32, [3 x i16], i32 } { i64 3274037854792712831, i64 172590168, i64 sub (i64 ptrtoint (ptr @__profc_end to i64), i64 ptrtoint (ptr @__profd_end to i64)), i64 0, ptr null, ptr null, i32 2, [3 x i16] zeroinitializer, i32 0 }, section "__llvm_prf_data", comdat($__profc_end), align 8
+
More information about the llvm-commits
mailing list