summaryrefslogtreecommitdiff
path: root/bolt
diff options
context:
space:
mode:
authorAmir Ayupov <aaupov@fb.com>2025-10-09 15:24:37 -0700
committerGitHub <noreply@github.com>2025-10-09 15:24:37 -0700
commitab897ae2e08646e7c60fb61d71df5616950beb66 (patch)
tree4add04e4a67ea97d81d082aa4fb9d84b9c1a43d8 /bolt
parent06cffb72cc2d8e610ae45d0c0a14c92d8b5626b0 (diff)
[BOLT] Support fragment symbol mapped to the parent address (#162727)
Observed in GCC-produced binary. Emit a warning for the user. Test Plan: added bolt/test/X86/fragment-alias.s
Diffstat (limited to 'bolt')
-rw-r--r--bolt/lib/Rewrite/RewriteInstance.cpp6
-rw-r--r--bolt/test/X86/fragment-alias.s13
2 files changed, 19 insertions, 0 deletions
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index dad67175ad41..a0e79957edc0 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1514,6 +1514,12 @@ void RewriteInstance::registerFragments() {
}
if (BD) {
BinaryFunction *BF = BC->getFunctionForSymbol(BD->getSymbol());
+ if (BF == &Function) {
+ BC->errs()
+ << "BOLT-WARNING: fragment maps to the same function as parent: "
+ << Function << '\n';
+ continue;
+ }
if (BF) {
BC->registerFragment(Function, *BF);
continue;
diff --git a/bolt/test/X86/fragment-alias.s b/bolt/test/X86/fragment-alias.s
new file mode 100644
index 000000000000..3392dd564f41
--- /dev/null
+++ b/bolt/test/X86/fragment-alias.s
@@ -0,0 +1,13 @@
+## This test reproduces the issue where a fragment has the same address as
+## parent function.
+# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.o
+# RUN: %clang %cflags %t.o -o %t
+# RUN: llvm-bolt %t -o %t.out 2>&1 | FileCheck %s
+# CHECK: BOLT-WARNING: fragment maps to the same function as parent: main/1(*2)
+.type main, @function
+.type main.cold, @function
+main.cold:
+main:
+ ret
+.size main, .-main
+.size main.cold, .-main.cold