[llvm] [BOLT] Support map other function entry address (PR #101466)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 1 03:01:16 PDT 2024
https://github.com/linsinan1995 created https://github.com/llvm/llvm-project/pull/101466
Allow BOLT to map the old address to a new binary address if the old address is the entry of the function.
>From 162bdd9f4d801843eefa7d420bd83c62a67426fd Mon Sep 17 00:00:00 2001
From: Sinan Lin <sinan.lin at linux.alibaba.com>
Date: Thu, 1 Aug 2024 17:51:04 +0800
Subject: [PATCH] [BOLT] Support map other function entry address
Allow BOLT to map old address to new binary address if the old
address is the other entry of the function.
---
bolt/lib/Rewrite/RewriteInstance.cpp | 8 ++++++++
bolt/test/X86/dynamic-relocs-on-entry.s | 25 +++++++++++++++++++++++++
2 files changed, 33 insertions(+)
create mode 100644 bolt/test/X86/dynamic-relocs-on-entry.s
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 9077869fe4955..e2273472c15de 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -5509,6 +5509,14 @@ uint64_t RewriteInstance::getNewFunctionOrDataAddress(uint64_t OldAddress) {
if (const BinaryFunction *BF =
BC->getBinaryFunctionContainingAddress(OldAddress)) {
if (BF->isEmitted()) {
+ // If OldAddress is the another entry point of
+ // the function, then BOLT could get the new address.
+ if (BF->isMultiEntry()) {
+ for (auto &BB : *BF)
+ if (BB.isEntryPoint() &&
+ (BF->getAddress() + BB.getOffset()) == OldAddress)
+ return BF->getOutputAddress() + BB.getOffset();
+ }
BC->errs() << "BOLT-ERROR: unable to get new address corresponding to "
"input address 0x"
<< Twine::utohexstr(OldAddress) << " in function " << *BF
diff --git a/bolt/test/X86/dynamic-relocs-on-entry.s b/bolt/test/X86/dynamic-relocs-on-entry.s
new file mode 100644
index 0000000000000..7f47955440dd4
--- /dev/null
+++ b/bolt/test/X86/dynamic-relocs-on-entry.s
@@ -0,0 +1,25 @@
+// This test examines whether BOLT can correctly update when
+// dynamic relocation points to other entry points of the
+// function.
+
+# RUN: %clang %cflags -fPIC -pie %s -o %t.exe -nostdlib -Wl,-q
+# RUN: llvm-bolt %t.exe -o %t.bolt | FileCheck %s
+
+ .text
+ .type chain, @function
+chain:
+ movq $1, %rax
+Lable:
+ ret
+ .size chain, .-chain
+ .type _start, @function
+ .global _start
+_start:
+ jmpq *.Lfoo(%rip)
+ ret
+ .size _start, .-_start
+ .data
+.Lfoo:
+ .quad Lable
+
+# CHECK-NOT: BOLT-ERROR
More information about the llvm-commits
mailing list