[llvm] [bolt] keep only function with prologue (PR #87520)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 9 00:00:32 PDT 2024
https://github.com/wangqingintel updated https://github.com/llvm/llvm-project/pull/87520
>From a30b2a0fe477c945093d41c6f2681e3b749b10f3 Mon Sep 17 00:00:00 2001
From: Bing1 Yu <bing1.yu at intel.com>
Date: Thu, 4 Apr 2024 00:43:56 +0800
Subject: [PATCH] [bolt] keep only function with prologue
---
bolt/include/bolt/Rewrite/RewriteInstance.h | 2 ++
bolt/lib/Rewrite/RewriteInstance.cpp | 19 +++++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/bolt/include/bolt/Rewrite/RewriteInstance.h b/bolt/include/bolt/Rewrite/RewriteInstance.h
index 826677cd63b22b1..677224624e462e2 100644
--- a/bolt/include/bolt/Rewrite/RewriteInstance.h
+++ b/bolt/include/bolt/Rewrite/RewriteInstance.h
@@ -97,6 +97,8 @@ class RewriteInstance {
/// from meta data in the file.
void discoverFileObjects();
+ void keepPrologueFunction();
+
/// Check whether we should use DT_FINI or DT_FINI_ARRAY for instrumentation.
/// DT_FINI is preferred; DT_FINI_ARRAY is only used when no DT_FINI entry was
/// found.
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 0c8ee0d417233bb..8830911314d276e 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -738,6 +738,7 @@ Error RewriteInstance::run() {
return E;
adjustCommandLineOptions();
discoverFileObjects();
+ keepPrologueFunction();
if (opts::Instrument && !BC->IsStaticExecutable)
if (Error E = discoverRtFiniAddress())
@@ -807,6 +808,24 @@ Error RewriteInstance::run() {
return Error::success();
}
+void RewriteInstance::keepPrologueFunction() {
+ BC->outs() << "keepPrologueFunction!"<<"\n";
+ for(auto &BFI : BC->getBinaryFunctions()) {
+ BinaryFunction &BF = BFI.second;
+ ErrorOr<ArrayRef<uint8_t>> ErrorOrFunctionData = BF.getData();
+ assert(ErrorOrFunctionData && "function data is not available");
+ ArrayRef<uint8_t> IData = *ErrorOrFunctionData;
+ BC->outs() << "Potential Function Entry Point: 0x" << Twine::utohexstr(IData[0]) << "\n";
+ // Check for common function prologue patterns
+ if ((char)IData[0] == '\x55' && (char)IData[1] == '\x48' && (char)IData[2] == '\x89' && (char)IData[3] == '\xe5') {
+ BC->outs() << "Potential Function Entry Point: 0x" << Twine::utohexstr(BF.getAddress()) << "\n";
+ } else {
+ BF.setIgnored();
+ }
+
+ }
+}
+
void RewriteInstance::discoverFileObjects() {
NamedRegionTimer T("discoverFileObjects", "discover file objects",
TimerGroupName, TimerGroupDesc, opts::TimeRewrite);
More information about the llvm-commits
mailing list