[llvm] [BOLT][WIP] Always treat function entry as code (PR #160161)

Maksim Panchenko via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 22 11:06:57 PDT 2025


https://github.com/maksfb created https://github.com/llvm/llvm-project/pull/160161

If an address has both, a data marker "$d" and a function entry point associated with it, treat it as code.

>From ec10c71b9a8ee85781f71cee3c0280752961a599 Mon Sep 17 00:00:00 2001
From: Maksim Panchenko <maks at fb.com>
Date: Mon, 22 Sep 2025 11:01:37 -0700
Subject: [PATCH] [BOLT][WIP] Always treat function entry as code

If an address has both, a data marker "$d" and a function entry point
associated with it, treat it as code.
---
 bolt/lib/Rewrite/RewriteInstance.cpp     |  3 ---
 bolt/test/AArch64/function-data-marker.s | 25 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 bolt/test/AArch64/function-data-marker.s

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index a6e4dbc9c192f..014fa43f82867 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -917,9 +917,6 @@ void RewriteInstance::discoverFileObjects() {
     bool IsData = false;
     uint64_t LastAddr = 0;
     for (const auto &SymInfo : SortedSymbols) {
-      if (LastAddr == SymInfo.Address) // don't repeat markers
-        continue;
-
       MarkerSymType MarkerType = BC->getMarkerType(SymInfo.Symbol);
 
       // Treat ST_Function as code.
diff --git a/bolt/test/AArch64/function-data-marker.s b/bolt/test/AArch64/function-data-marker.s
new file mode 100644
index 0000000000000..35e31e9fc1731
--- /dev/null
+++ b/bolt/test/AArch64/function-data-marker.s
@@ -0,0 +1,25 @@
+## TODO
+
+# RUN: %clang %cflags %s -o %t.exe -nostdlib -fuse-ld=lld -Wl,-q
+# RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg --print-only=foo 2>&1 | FileCheck %s
+
+# BOLT-WARNING: function symbol foo lacks code marker
+
+.text
+.balign 4
+
+.global _start
+.type _start, %function
+_start:
+  bl foo
+  ret
+.size _start, .-_start
+
+## Data marker is emitted immediately before the function.
+.global foo
+.type foo, %function
+$d:
+foo:
+  ret
+.size foo, .-foo
+



More information about the llvm-commits mailing list