-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BOLT] Keep function which is directly called or has prologue #88244
Draft
yubingex007-a11y
wants to merge
4
commits into
llvm:main
Choose a base branch
from
yubingex007-a11y:keedcpf
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+73
−1
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can test this locally with the following command:git-clang-format --diff da5a86b53e7d6e7ff7407b16c2c869894493ee99 a846f4f3f4089c516a41db3b64d4cf750bd505ff -- bolt/include/bolt/Core/BinaryFunction.h bolt/include/bolt/Rewrite/RewriteInstance.h bolt/lib/Core/BinaryFunction.cpp bolt/lib/Rewrite/RewriteInstance.cpp View the diff from clang-format here.diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h
index cd6ded17e4..bd1460580e 100644
--- a/bolt/include/bolt/Core/BinaryFunction.h
+++ b/bolt/include/bolt/Core/BinaryFunction.h
@@ -208,7 +208,7 @@ public:
/// Mark injected functions
bool IsInjected = false;
- bool IsDirectCalled =false;
+ bool IsDirectCalled = false;
using LSDATypeTableTy = SmallVector<uint64_t, 0>;
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 2f7e6a8d36..0e7a19da93 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -1268,11 +1268,14 @@ Error BinaryFunction::disassemble() {
bool IsCall = MIB->isCall(Instruction);
const bool IsCondBranch = MIB->isConditionalBranch(Instruction);
MCSymbol *TargetSymbol = nullptr;
- if(IsCall) {
- if (BinaryFunction *TargetFunc = BC.getBinaryFunctionContainingAddress(TargetAddress)) {
+ if (IsCall) {
+ if (BinaryFunction *TargetFunc =
+ BC.getBinaryFunctionContainingAddress(TargetAddress)) {
// direct call here.
TargetFunc->IsDirectCalled = true;
- LLVM_DEBUG(dbgs() << "[Disasm] Find function which is directly called: 0x" << Twine::utohexstr(TargetFunc->getAddress()) << "\n");
+ LLVM_DEBUG(dbgs()
+ << "[Disasm] Find function which is directly called: 0x"
+ << Twine::utohexstr(TargetFunc->getAddress()) << "\n");
}
}
if (BC.MIB->isUnsupportedBranch(Instruction)) {
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index a0768ba870..7168804f8b 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -811,52 +811,65 @@ Error RewriteInstance::run() {
}
void RewriteInstance::keepDCPFunction() {
- BC->outs() << "keepDCPFunction!"<<"\n";
- for(auto &BFI : BC->getBinaryFunctions()) {
+ BC->outs() << "keepDCPFunction!" << "\n";
+ for (auto &BFI : BC->getBinaryFunctions()) {
BinaryFunction &BF = BFI.second;
- bool hasPrologue =false;
+ bool hasPrologue = false;
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
- // push %rbp
- // mov %rsp %rbp
- if (BF.getSize()>=4 && (char)IData[0] == '\x55' && (char)IData[1] == '\x48' && (char)IData[2] == '\x89' && (char)IData[3] == '\xe5') {
- LLVM_DEBUG(dbgs() << "[keepDCPFunction] Find function with prologue in: 0x" << Twine::utohexstr(BF.getAddress()) << "\n");
- hasPrologue =true;
- } else if (BF.getSize()>=4 && (char)IData[0] == '\xf3' && (char)IData[1] == '\x0f' && (char)IData[2] == '\x1e' && (char)IData[3] == '\xfa') {
- LLVM_DEBUG(dbgs() << "[keepDCPFunction] Find function with prologue in: 0x" << Twine::utohexstr(BF.getAddress()) << "\n");
- hasPrologue= true;
+ // BC->outs() << "Potential Function Entry Point: 0x" <<
+ // Twine::utohexstr(IData[0]) << "\n"; Check for common function prologue
+ // patterns push %rbp mov %rsp %rbp
+ if (BF.getSize() >= 4 && (char)IData[0] == '\x55' &&
+ (char)IData[1] == '\x48' && (char)IData[2] == '\x89' &&
+ (char)IData[3] == '\xe5') {
+ LLVM_DEBUG(
+ dbgs() << "[keepDCPFunction] Find function with prologue in: 0x"
+ << Twine::utohexstr(BF.getAddress()) << "\n");
+ hasPrologue = true;
+ } else if (BF.getSize() >= 4 && (char)IData[0] == '\xf3' &&
+ (char)IData[1] == '\x0f' && (char)IData[2] == '\x1e' &&
+ (char)IData[3] == '\xfa') {
+ LLVM_DEBUG(
+ dbgs() << "[keepDCPFunction] Find function with prologue in: 0x"
+ << Twine::utohexstr(BF.getAddress()) << "\n");
+ hasPrologue = true;
} else {
hasPrologue = false;
}
- LLVM_DEBUG(
- if(BF.IsDirectCalled) dbgs() << "[keepDCPFunction] Find function which is directly called: 0x" << Twine::utohexstr(BF.getAddress()) << "\n"
- );
- if(!BF.IsDirectCalled && !hasPrologue )
+ LLVM_DEBUG(if (BF.IsDirectCalled) dbgs()
+ << "[keepDCPFunction] Find function which is directly called: 0x"
+ << Twine::utohexstr(BF.getAddress()) << "\n");
+ if (!BF.IsDirectCalled && !hasPrologue)
BF.setIgnored();
}
}
void RewriteInstance::keepPrologueFunction() {
- BC->outs() << "keepPrologueFunction!"<<"\n";
- for(auto &BFI : BC->getBinaryFunctions()) {
+ 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
- // push %rbp
- // mov %rsp %rbp
- if (BF.getSize()>=4 && (char)IData[0] == '\x55' && (char)IData[1] == '\x48' && (char)IData[2] == '\x89' && (char)IData[3] == '\xe5') {
- LLVM_DEBUG(dbgs() << "[keepPrologueFunction] Find function with prologue in: 0x" << Twine::utohexstr(BF.getAddress()) << "\n");
- } else if (BF.getSize()>=4 && (char)IData[0] == '\xf3' && (char)IData[1] == '\x0f' && (char)IData[2] == '\x1e' && (char)IData[3] == '\xfa') {
- LLVM_DEBUG(dbgs() << "[keepPrologueFunction] Find function with prologue in: 0x" << Twine::utohexstr(BF.getAddress()) << "\n");
+ // BC->outs() << "Potential Function Entry Point: 0x" <<
+ // Twine::utohexstr(IData[0]) << "\n"; Check for common function prologue
+ // patterns push %rbp mov %rsp %rbp
+ if (BF.getSize() >= 4 && (char)IData[0] == '\x55' &&
+ (char)IData[1] == '\x48' && (char)IData[2] == '\x89' &&
+ (char)IData[3] == '\xe5') {
+ LLVM_DEBUG(
+ dbgs() << "[keepPrologueFunction] Find function with prologue in: 0x"
+ << Twine::utohexstr(BF.getAddress()) << "\n");
+ } else if (BF.getSize() >= 4 && (char)IData[0] == '\xf3' &&
+ (char)IData[1] == '\x0f' && (char)IData[2] == '\x1e' &&
+ (char)IData[3] == '\xfa') {
+ LLVM_DEBUG(
+ dbgs() << "[keepPrologueFunction] Find function with prologue in: 0x"
+ << Twine::utohexstr(BF.getAddress()) << "\n");
} else {
BF.setIgnored();
}
-
}
}
|
yubingex007-a11y
changed the title
Keep function which is directly called or has prologue
[BOLT] Keep function which is directly called or has prologue
Apr 10, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.